Created
March 19, 2019 15:17
-
-
Save rossja/a96c0459106f8d0f9f3952ff1ab3d73b to your computer and use it in GitHub Desktop.
JSON export of TOTP keys from Authy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
// JSON export of TOTP keys from Authy | |
// based on the scripts and comments at <https://gist.github.com/gboudreau/94bb0c11a6209c82418d01a59d958c93> | |
// Last tested: 2019-03-19 | |
// ----------------------------------------------------------- | |
// Tested on: | |
// - Chrome version 72.0.3626.121 (Official Build) (64-bit) | |
// - Authy version 2.6.0 | |
// ----------------------------------------------------------- | |
// Directions: | |
// 1. Start the Authy Chrome App | |
// 2. Unlock Authy with your password | |
// 3. Select all this code, and press Ctrl-C to copy the script into your clipboard. | |
// 4. In your Chrome browser, click on the menu dots in the top right corner, and select: More tools >> Extensions | |
// 5. Scroll down to the bottom of the Extensions page, and look for the Authy Chrome App (NOTE: you must use the APP, not the Extension!) | |
// 6. Click on the Details button. This will open up the Authy Chrome App extension page. | |
// 7. Under the Inspect views section, you should see two hyperlinks: background page and main.html. Click on the main.html hyperlink. | |
// 8. This will open up the Chrome DevTools window for main.html. There should be a Console window across the bottom 1/3 of the DevTools window. | |
// 9. Click your cursor in the Console window next to the ">". | |
// 10. Press Ctrl-V to paste the script into the Console. | |
// 11. Copy the JSON results (you may have a "Copy" button if the results are sufficiently long) | |
// 12. Back this file up, it contains all your TOTP secrets, and links to QR codes (generated via Google) you can scan | |
*/ | |
/* base32 */ | |
/* | |
Copyright (c) 2011, Chris Umbel | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in | |
all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
THE SOFTWARE. | |
*/ | |
var charTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; | |
function quintetCount(buff) { | |
var quintets = Math.floor(buff.length / 5); | |
return buff.length % 5 === 0 ? quintets : quintets + 1; | |
} | |
encode = function(plain) { | |
var i = 0; | |
var j = 0; | |
var shiftIndex = 0; | |
var digit = 0; | |
var encoded = new Array(quintetCount(plain) * 8); | |
/* byte by byte isn't as pretty as quintet by quintet but tests a bit faster. will have to revisit. */ | |
while(i < plain.length) { | |
var current = plain[i]; | |
if(shiftIndex > 3) { | |
digit = current & (0xff >> shiftIndex); | |
shiftIndex = (shiftIndex + 5) % 8; | |
digit = (digit << shiftIndex) | ((i + 1 < plain.length) ? | |
plain[i + 1] : 0) >> (8 - shiftIndex); | |
i++; | |
} else { | |
digit = (current >> (8 - (shiftIndex + 5))) & 0x1f; | |
shiftIndex = (shiftIndex + 5) % 8; | |
if(shiftIndex === 0) i++; | |
} | |
encoded[j] = charTable.charCodeAt(digit); | |
j++; | |
} | |
for(i = j; i < encoded.length; i++) { | |
encoded[i] = 0x3d; //'='.charCodeAt(0) | |
} | |
return encoded.join(''); | |
}; | |
/* base32 end */ | |
function hexToInt(str) { | |
var result = []; | |
for (var i = 0; i < str.length; i += 2) { | |
result.push(parseInt(str.substr(i, 2), 16)); | |
} | |
return result; | |
} | |
function hexToB32(str) { | |
return encode(hexToInt(str)); | |
} | |
getTotps = function() { | |
var totps = []; | |
console.warn("Here's your Authy tokens:"); | |
appManager.getModel().forEach(function(i) { | |
var secret = (i.markedForDeletion === false || !i.secretSeed) ? i.decryptedSeed : hexToB32(i.secretSeed); | |
var totp_uri = 'otpauth://totp/' + encodeURIComponent(i.name) + '?secret=' + secret + '&issuer=' + i.accountType + '&digits=' + i.digits + '&period=10'; | |
console.group(i.name); | |
console.log('TOTP URI: ' + totp_uri); | |
var qr_code = 'https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=' + encodeURIComponent(totp_uri); | |
console.log('QR code: ' + qr_code); | |
totps.push({ | |
name: i.name, | |
totpURI: totp_uri, | |
qrCode: qr_code | |
}) | |
console.groupEnd(); | |
}); | |
console.log(JSON.stringify(totps)); | |
return totps; | |
} | |
getTotps() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment