Advertisement
Xeriars

Get token for Authy

Jul 26th, 2020 (edited)
1,507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* base32 / /
  2.  Copyright (c) 2011, Chris Umbel
  3.  Permission is hereby granted, free of charge, to any person obtaining a copy
  4.  of this software and associated documentation files (the "Software"), to deal
  5.  in the Software without restriction, including without limitation the rights
  6.  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7.  copies of the Software, and to permit persons to whom the Software is
  8.  furnished to do so, subject to the following conditions:
  9.  The above copyright notice and this permission notice shall be included in
  10.  all copies or substantial portions of the Software.
  11.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12.  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13.  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14.  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15.  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16.  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17.  THE SOFTWARE.
  18.  */
  19.  
  20. var charTable = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'
  21. function quintetCount (buff) {
  22.   var quintets = Math.floor(buff.length / 5)
  23.   return buff.length % 5 === 0 ? quintets : quintets + 1
  24. }
  25.  
  26. const encode = function (plain) {
  27.   var i = 0
  28.   var j = 0
  29.   var shiftIndex = 0
  30.   var digit = 0
  31.   var encoded = new Array(quintetCount(plain) * 8)
  32.   /* byte by byte isn't as pretty as quintet by quintet but tests a bit faster. will have to revisit. */
  33.   while (i < plain.length) {
  34.     var current = plain[i]; if (shiftIndex > 3) {
  35.       digit = current & (0xff >> shiftIndex)
  36.       shiftIndex = (shiftIndex + 5) % 8
  37.       digit = (digit << shiftIndex) | ((i + 1 < plain.length) ? plain[i + 1] : 0) >> (8 - shiftIndex)
  38.       i++
  39.     } else {
  40.       digit = (current >> (8 - (shiftIndex + 5))) & 0x1f
  41.       shiftIndex = (shiftIndex + 5) % 8
  42.       if (shiftIndex === 0) i++
  43.     }
  44.     encoded[j] = charTable.charCodeAt(digit); j++
  45.   }
  46.   for (i = j; i < encoded.length; i++) {
  47.     encoded[i] = 0x3d // '='.charCodeAt(0)
  48.   }
  49.   return encoded.join('')
  50. }
  51. /* base32 end */
  52.  
  53. var hexToInt = function (str) {
  54.   var result = []
  55.   for (var i = 0; i < str.length; i += 2) {
  56.     result.push(parseInt(str.substr(i, 2), 16))
  57.   }
  58.   return result
  59. }
  60. function hexToB32 (str) {
  61.   return encode(hexToInt(str))
  62. }
  63.  
  64. const getTotps = function () {
  65.   var totps = []
  66.   console.warn("Here's your Authy tokens:")
  67.   appManager.getModel().forEach(function (i) {
  68.     var secret = (i.markedForDeletion === false || !i.secretSeed) ? i.decryptedSeed : hexToB32(i.secretSeed)
  69.     console.group(i.name)
  70.     console.log('TOTP Secret: ' + secret)
  71.     totps.push({
  72.       name: i.name,
  73.       secret: secret
  74.     })
  75.     console.groupEnd()
  76.   })
  77.   console.log(JSON.stringify(totps))
  78.   return totps
  79. }
  80. getTotps()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement