Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fboender/3dbba77f84239ecfb8009e3ada5cf60c to your computer and use it in GitHub Desktop.
Save fboender/3dbba77f84239ecfb8009e3ada5cf60c to your computer and use it in GitHub Desktop.

Revisions

  1. @Ingramz Ingramz revised this gist Nov 16, 2015. 1 changed file with 23 additions and 1 deletion.
    24 changes: 23 additions & 1 deletion AuthyToOtherAuthenticator.md
    Original file line number Diff line number Diff line change
    @@ -38,6 +38,28 @@ This method has only one gotcha - if you want add a new service that relies on A
    6. Chrome developer tools with Console selected should open. If it didn't, go to Console tab.
    7. Paste following and press enter:
    ```js
    /* 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) {
    @@ -75,7 +97,7 @@ encode = function(plain) {

    return encoded.join('');
    };

    /* base32 end */
    function hexToInt(str) {
    var result = [];
    for (var i = 0; i < str.length; i += 2) {
  2. @Ingramz Ingramz revised this gist Nov 15, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion AuthyToOtherAuthenticator.md
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ Known not to work:

    ### Ok, that's nice, but I want to get rid of Authy now

    This method has only one gotcha - if you want add a new service that relies on Authy, you will need to run Authy again. I am assuming you know how to use Authy and have some services added already. You can probably get rid of Authy on your phone and log in to Authy on your Chrome app using SMS or keep it permanently disabled under your extensions once you have logged in.
    This method has only one gotcha - if you want add a new service that relies on Authy, you will need to run Authy again. I am assuming you know how to use Authy and have some services added already. You can probably get rid of Authy on your phone and log in to Authy on your Chrome app using SMS or keep it permanently disabled under your extensions once you have logged in. In that case set a master password for Authy, stay secure.

    1. Install [Authy from Chrome Web Store](https://chrome.google.com/webstore/detail/authy/gaedmjdfmmahhbjefcbgaolhhanlaolb?hl=en)
    2. Open Authy and log in, so you can see the codes being generated for you
  3. @Ingramz Ingramz revised this gist Nov 15, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion AuthyToOtherAuthenticator.md
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ I had to adapt the code a little and you can see the result below, but here's wh
    * The password validity period is 10 seconds (instead of usual 30). Authy shows 20 seconds, but that means a slightly different thing. Don't substitute this period longer in your Authenticator.
    * Authy's secret keys are in hex already, so they need to be turned back to base32 for working QR codes

    So as long as you have an authenticator which can do longer passwords than 6 characters and do custom time periods, then congratulations, you can use the following method. If you are not sure, scan this code with your authenticator to test. Don't forget to delete it afterwards.
    So as long as you have an authenticator which can do longer passwords than 6 characters and do custom time periods, then congratulations, you can use the following method. If you are not sure, scan this code with your authenticator to test. Don't forget to delete it afterwards. The code should have 7 digits and should change every 10 seconds.

    ![](https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/PLEASE_DELETE_ME%3Fsecret%3DDEADBEEFDEADBEEF%26digits%3D7%26period%3D10)

  4. @Ingramz Ingramz revised this gist Nov 15, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion AuthyToOtherAuthenticator.md
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ Known to work:

    Known not to work:
    * 1Password for Windows (doesn't support other digit counts and timeouts yet)
    * Authy (doesn't support other timeouts than 30s, the irony!)
    * Authy for iOS (doesn't support other timeouts than 30s, the irony!)

    ### Ok, that's nice, but I want to get rid of Authy now

  5. @Ingramz Ingramz revised this gist Nov 15, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions AuthyToOtherAuthenticator.md
    Original file line number Diff line number Diff line change
    @@ -24,6 +24,7 @@ Known to work:

    Known not to work:
    * 1Password for Windows (doesn't support other digit counts and timeouts yet)
    * Authy (doesn't support other timeouts than 30s, the irony!)

    ### Ok, that's nice, but I want to get rid of Authy now

  6. @Ingramz Ingramz revised this gist Nov 15, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion AuthyToOtherAuthenticator.md
    Original file line number Diff line number Diff line change
    @@ -36,7 +36,7 @@ This method has only one gotcha - if you want add a new service that relies on A
    5. Find Authy from the list and then click on `main.html`
    6. Chrome developer tools with Console selected should open. If it didn't, go to Console tab.
    7. Paste following and press enter:
    ```js
    ```js
    var charTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";

    function quintetCount(buff) {
  7. @Ingramz Ingramz revised this gist Nov 15, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion AuthyToOtherAuthenticator.md
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ Known not to work:
    This method has only one gotcha - if you want add a new service that relies on Authy, you will need to run Authy again. I am assuming you know how to use Authy and have some services added already. You can probably get rid of Authy on your phone and log in to Authy on your Chrome app using SMS or keep it permanently disabled under your extensions once you have logged in.

    1. Install [Authy from Chrome Web Store](https://chrome.google.com/webstore/detail/authy/gaedmjdfmmahhbjefcbgaolhhanlaolb?hl=en)
    2. Open Authy for once and log in, so you can see the codes being generated for you
    2. Open Authy and log in, so you can see the codes being generated for you
    3. Go to Extensions page in your browser (`chrome://extensions/` or Menu -> More tools -> Extensions)
    4. Tick developer mode in top right corner
    5. Find Authy from the list and then click on `main.html`
  8. @Ingramz Ingramz created this gist Nov 15, 2015.
    119 changes: 119 additions & 0 deletions AuthyToOtherAuthenticator.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,119 @@
    # Generating Authy passwords on other authenticators
    --------

    There is an increasing count of applications which use [Authy](https://www.authy.com/) for two-factor authentication. However many users who aren't using Authy, have their own authenticator setup up already and do not wish to use two applications for generating passwords.

    Since I use 1Password for all of my password storing/generating needs, I was looking for a solution to use Authy passwords on that. I couldn't find any completely working solutions, however I stumbled upon [a gist by Brian Hartvigsen](https://gist.github.com/tresni/83b9181588c7393f6853). His post had a neat code with it to generate QR codes (beware, through Google) for you to use on your favorite authenticator.

    His method is to extract the secret keys using Authy's Google Chrome app via Developer Tools. If this was not possible, I guess people would be reverse engineering the Android app or something like that. But when I tried that code, nothing appeared on the screen. My guess is that Brian used the code to extract the keys that weren't necessarily tied to Authy.

    I had to adapt the code a little and you can see the result below, but here's what I discovered about Authy's method:
    * They use the exact same algorithm to generate passwords as Google Authenticator and similar (TOTP)
    * The passwords are one digit longer - 7 digits (usually they're 6, with exceptions), but if you've looked at one of the Authy generated passwords already, you probably noticed it too
    * The password validity period is 10 seconds (instead of usual 30). Authy shows 20 seconds, but that means a slightly different thing. Don't substitute this period longer in your Authenticator.
    * Authy's secret keys are in hex already, so they need to be turned back to base32 for working QR codes

    So as long as you have an authenticator which can do longer passwords than 6 characters and do custom time periods, then congratulations, you can use the following method. If you are not sure, scan this code with your authenticator to test. Don't forget to delete it afterwards.

    ![](https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/PLEASE_DELETE_ME%3Fsecret%3DDEADBEEFDEADBEEF%26digits%3D7%26period%3D10)

    Known to work:
    * 1Password for OS X
    * 1Password for iOS
    * Google Authenticator

    Known not to work:
    * 1Password for Windows (doesn't support other digit counts and timeouts yet)

    ### Ok, that's nice, but I want to get rid of Authy now

    This method has only one gotcha - if you want add a new service that relies on Authy, you will need to run Authy again. I am assuming you know how to use Authy and have some services added already. You can probably get rid of Authy on your phone and log in to Authy on your Chrome app using SMS or keep it permanently disabled under your extensions once you have logged in.

    1. Install [Authy from Chrome Web Store](https://chrome.google.com/webstore/detail/authy/gaedmjdfmmahhbjefcbgaolhhanlaolb?hl=en)
    2. Open Authy for once and log in, so you can see the codes being generated for you
    3. Go to Extensions page in your browser (`chrome://extensions/` or Menu -> More tools -> Extensions)
    4. Tick developer mode in top right corner
    5. Find Authy from the list and then click on `main.html`
    6. Chrome developer tools with Console selected should open. If it didn't, go to Console tab.
    7. Paste following and press enter:
    ```js
    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.charAt(digit);
    j++;
    }

    return encoded.join('');
    };

    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));
    }

    window.open('data:text/html;charset=utf-8,' + encodeURIComponent('<!DOCTYPE html>'+ '<html lang="en">'+ '<head><title>Embedded Window</title></head>'+ '<body>' +
    jQuery(require("models/apps/app_manager").get().getDecryptedApps()).map(function (ndx, elem) {
    if (!elem.secretSeed) { return }
    var name = elem.name || elem.originalName
    return "<h1><img src='" +
    require('models/assets/asset_manager').get().assetAccounts[elem.assetsGroup].menuItemUrl +
    "'>" + name + "</h1><h2>" + hexToB32(elem.secretSeed) + "</h2>" +
    "<img src='https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/" + encodeURI(name) + "%3Fsecret%3D" + hexToB32(elem.secretSeed) + "%26digits%3D7%26period%3D10'/>"
    }).toArray().join("<br>")
    + '</body>'+ '</html>' ) );
    ```
    8. A page should open with QR codes for all of your entries, scan them in!
    9. Close opened window and developer tools.
    10. Disable Authy app on Chrome or remove it
    11. Disable Developer mode


    ### Resources used for getting correct codes

    * [Brian's gist](https://gist.github.com/tresni/83b9181588c7393f6853)
    * [JavaScript implementation of base32 encoding by Chris Umbel, et al.](https://github.com/chrisumbel/thirty-two/blob/master/lib/thirty-two/thirty-two.js)
    * [Google Authenticator URI format](https://github.com/google/google-authenticator/wiki/Key-Uri-Format)

    ### Other notes

    * I am not responsible for your actions.
    * I am sure someone has already discovered everything I wrote before, but I couldn't find anything written about it in detail, I didn't invent anything new here
    * The code is a horrible hack, it works for what it does and that's the important bit, improvements are welcome
    * If anyone from Authy reads this - security shouldn't rely on obfuscation or hiding of any sort and should take advantage of freedom of choice where possible. I love the idea of the keys being tied to ones phone number and making this system easy to use for everyone, but please make these URI-s exportable to other applications if users wish to do so - it's possible as demonstrated above and you probably know it. Transparency is what makes this system secure. If you don't wish to do that, then please don't break this method of acquiring keys.