2FA Backup - from Authy¶
I use Authy for 2FA, which is great for syncing the codes across multiple devices, with the caveat that you need to trust their cloud synch mechanism. However they have no export function, which led me to trawl the 'net for a solution, and I came across the following:
@gboudreau, @puddly, and @nmurthy - Thanks for creating these scripts! I got everything to work.
I have put together updated instructions to get your Authy secret keys and QR codes:
- Start the Authy Chrome App
- Unlock Authy with your password
- Go to @nmurthy 's updated script github page. Select all the code, and press Ctrl-C to copy the getTotps.js script into your clipboard.
- In your Chrome browser, click on the menu dots in the top right corner, and select: More tools >> Extensions
- Scroll down to the bottom of the Extensions page, and look for the Authy 2.6.0 Chrome App (ID: gaedmjdfmmahhbjefcbgaolhhanlaolb).
- Click on the Details button. This will open up the Authy Chrome App extension page.
- Under the Inspect views section, you should see two hyperlinks: background page and main.html. Click on the main.html hyperlink.
- 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.
- Click your cursor in the Console window next to the ">".
- Press Ctrl-P to paste the getTotps.js script into the Console.
- In the Console window, press Enter
- In the Console window, type getTotps() and then press Enter
- You should now see each of your Authy keys listed in the Console window. The secret key value is after the secret= and before the & in the TOTP URI value. The QR code hyperlink will display a QR code that you can scan in Authy (or other) authenticator application.
Thanks again ... JazzTech
LINKS:
This is the code referred to in the above:
/* 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;
}
LINK: https://gist.github.com/nmurthy/a5e7107671cf04529ac5f3a7471f2357