15 ms·
How does Google Authenticator work?
- deleted 5y ago[deleted]
- akerl_ 5y agoThis article is overall a nice breakdown of how TOTP/HOTP function. My only concern is that it seems to connect the “counter” (time in the case of TOTP) with salting. Salting of passwords is targeted towards a totally different problem. The HMAC functions here don’t take a salt, they take a secret and what the RFC calls a “moving factor”. It exists intentionally to allow the resulting calculation to change over time in unpredictable (to an attacker) ways.
- LeoPanthera 5y agoGoogle Authenticator is an implementation of the catchily-named "Time-based One-Time Password" or TOTP. https://en.wikipedia.org/wiki/Time-based_One-Time_Password https://en.wikipedia.org/wiki/Time-based_One-Time_Password It is not the only one, any time a site asks you to add a "Google Authenticator" code you can use any TOTP app. 1Password has the functionality built in, for example.
- akerl_ 5y agoThe author seems to address this directly: > But here we’re focusing on apps like Google Authenticator that use something called TOTP algorithm. > What we want to achieve is understand how apps like Google Authenticator (or any other TOTP app) are solving that?
- ocdtrekkie 5y agoIt's truly and deeply frustrating to me how many sites and services push "Google Authenticator" branding instead of specifying that it's TOTP or that literally any good 2FA app will work. It's almost to that "Google" = "search" level, but for a more niche aspect.
- loloquwowndueo 5y agoBack in the day it was the best-known and most reliably available cross-platform (iOS, android) code generator - so many sites just assume it as a de facto standard. It also reduces support burden to tell people this is the officially supported code generator, that way you don’t need to struggle understanding why a random app might be having trouble with codes. These days it’s much less of an issue as there are many more clients - the IdP I manage now mentions authy, tofu and 1password as also supported.
- tinus_hn 5y agoAlso Google Authenticator does not allow you to include your codes in your backup, even when it’s encrypted. So due to Google Authenticator, losing your 2fa codes is an expected problem and many companies allow you to reset it by simply calling them. It sounds really secure but it really is not.
- nanidin 5y agoGoogle Authenticator has a feature to allow export of all saved codes into one QR code for re-import into Google Authenticator running on another device. I printed a copy of my export QR code for use in case my device is lost or stolen.
- greggman3 5y agoThanks! I hadn't seen that feature. Just checked it out. It shows multiple QR codes (in my case 2 QR codes which contain 11 TOTPs total) that you can scan from another device running Google Authenticator to transfer to codes. I guess I can screenshot those QR goes to back up (scary)
- animex 5y agoIn Fortune 1000 land, Microsoft Authenticator rules the land. I love it because most have implemented notification push-authentication with biometric verification. Some sites will use that in lieu of any password at all. The worst is when separate apps & companies roll their own authenticator app.
- willis936 5y agoYou can even convert TOTP from 2FA into 1.5ish FA by using a password manager that stores the TOTP secret and generates the TOTP key from it.
- Godel_unicode 5y agoAn adversary still has to get the manager DB and the key to unlock it (your password manager DB is encrypted with a key, right?).
- willis936 5y agoWhat's the point of using a key? That doesn't add a second factor of authentication. Something you have and something else you have is 1FA. A password with more than 200 bits of entropy seems reasonable.
- maxerickson 5y agoThey key doesn't particularly increase the security of the authentication, but it helps a bit if you lose control of the device the db is stored on.
- willis936 5y agoYeah but a key without a second factor (something you know) is still better than a key. Just make sure your password isn't brute forceable.
- Godel_unicode 5y agoFirstly, while that's technically correct according to the CISSP, it's obviously not actually correct. Two different things I have can absolutely be two factors as long as they are not susceptible to the same method of compromise. 1+1=2. Secondly, many password vaults refer to the master password you use to unlock it as the key. Thirdly, many security keys require a pin or similar to be used.
- tshaddox 5y agoI use 1Password for all of my MFA codes on the web. It's extremely convenient to have them synced across all my devices, but I can't help but think that having my passwords and my MFA private keys stored in the same place almost entirely defeats the purpose of multi-factor authentication.
- easton 5y agoThere is still a little bit of a point, as it guarantees the password came out of 1Password and wasn't from somewhere else. If someone screencapped your password out of 1Password, it wouldn't of use unless they could get into your vault somehow.
- jeromegv 5y agoIf your passwords are leaked in a data leak, they still wouldn't get your 2FA. So I wouldn't say it entirely defeats the purpose of 2FA.
- deleted 5y ago[deleted]
- tialaramex 5y agoDepending on the leak, the secret that drives TOTP could also be in the same database table (or a nearby one). This means anybody with that secret can trivially run the TOTP algorithm and get the correct six digit code for any time present or future. If you care about MFA that can survive leaks, you want WebAuthn. As with phishing this known problem was considered in the design of WebAuthn and so your WebAuthn credentials aren't designed to need to be secret. In fact here you go, here are WebAuthn credentials for a vanity system I own, copied out of its authentication database: ID: AXnUJ920FfJlRjZtocN+9Bc9IP6gvsBiWA3GfJxckh3nQ/KekQ6xB2byfI2GM7IcGS2MpzxZs6IHmAxvgAcE/Mw= Public key: pQECAyYgASFYIFf0iDSfNpYNA5Br9zXSIUH69BqyvFcgbqy6tWC8rsLwIlggCDqury9UOzI1DnOFyE3aYwaBLvP0NyNez98v0TcieKs= That's all the backend needs to check I'm really me, and yet it's also completely useless to an attacker, they can't even use it to compare across sites and "unmask" me.
- 5y ago
- kaladin-jasnah 5y agoHave to chime in but my favourite authenticator is andOTP. Seems to be FOSS as well since it's on F-Droid[0] and I hear it has good support from migration from one phone/ROM to another. [0] https://f-droid.org/en/packages/org.shadowice.flocke.andotp/ https://f-droid.org/en/packages/org.shadowice.flocke.andotp/
- teekert 5y agoAndOTP is really nice. It is the one thing I miss on iOS. On iOS there does not seem to be any totp apps that can just export their db as an encrypted file (or unencrypted if you so choose). So in Apple land I’m stuck with MS Authenticator, coincidentally my only app that needs iCloud (I really want it backed up).
- commoner 5y agoRaivo is an iOS TOTP authenticator that is open source and supports exports. Hopefully, this is what you're looking for: https://apps.apple.com/us/app/raivo-otp/id1459042137 https://apps.apple.com/us/app/raivo-otp/id1459042137 https://github.com/raivo-otp/ios-application https://github.com/raivo-otp/ios-application
- AnonC 5y agoTo add something about this app, I know that people understand “open source” to mean different things. In the case of Raivo, the app is a “source available” one. It’s not FOSS. The license [1] says: > Modification, duplication or distribution of this Service (in source and binary forms) for any purpose is strictly prohibited. [1]: https://github.com/raivo-otp/ios-application/blob/master/LICENSE.md https://github.com/raivo-otp/ios-application/blob/master/LIC...
- commoner 5y agoYou're 100% right. Raivo is source-available, but not free (libre) or open source. I found it through a forum post and neglected to check the license.
- judge2020 5y agoUnfortunately, Stripe does this currently: https://i.judge.sh/youthful/Derpy/chrome_TIDNqlcRvI.png https://i.judge.sh/youthful/Derpy/chrome_TIDNqlcRvI.png
- jvanderbot 5y agoYou can use oathtool if you'd like to "do it yourself". I usually just keep (encrypted with Pass) my secret keys for Authenticators, and execute a one line alias: oathtool -b --totp `pass show <X>` ... for <X> in github, gmail, blizzard, whatever ... This way, you can have a backup in case your phone gets lost, and easily port between phones.
- stevekemp 5y agoIf you're using pass already you could use their OTP plugin: https://github.com/tadfisher/pass-otp https://github.com/tadfisher/pass-otp That gives you "pass otp github.com", etc. You can also export the QRcode, and do similar things. I put together a simple distribution of pass with a couple of plugins I use, including otp, which is easy to setup - just clone beneath `/opt/pass`: https://github.com/skx/pass https://github.com/skx/pass
- jvanderbot 5y agoGreat tip thanks!
- werid 5y agoat one point i used a python script to provide a totp response to google when using youtube-dl (before logging in became broken and had to switch to cookies) import onetimepass as otp my_secret = '' my_token = otp.get_totp(my_secret) print my_token
- jillesvangurp 5y agoIt's really easy to integrate into websites as well. I did so a few years ago. The TOTP algorithm is just a few lines of code. I adapted this implementation https://github.com/j256/two-factor-auth https://github.com/j256/two-factor-auth at the time. There are similar libraries available for lots of languages. You need a library like that and a way to convert an otp:// url into a QR code, for which there are many libaries as well. The rest is just implementing a sane UX around this. Storing the user's TOTP secret server side is a bit tricky. I suspect a plain text field in a database is quite common for this; which of course would be disastrous if that database were ever stolen. Secret stores don't scale for this as they tend to be designed for just a handful of secrets. We ended up encrypting these totp secrets using a key from our secret store.
- seanwilson 5y agoYou know in Authy (Google Authenticator is similar here?) when there's only 10 seconds or so left to type in the current code so you wait for the next one to appear? Could it not show the next code instead if there wasn't much time left and the app you're authenticating with could accept the current or next code? Feels like an obvious annoyance that's fixable.
- anchpop 5y agoI’ve thought about that too. It should always show two codes (the current one and the previous one), and websites should accept both. Then when you open the app, you can always start typing the most recent one and have at least the whole interval to type it in
- pgalvin 5y agoThis is mostly a non-issue - services usually accept the current, previous and next TOTP code to account for devices having a slightly incorrect clock. I’ve never had an Android device that keeps its clock in sync, for example, so they had to address this.
- b3morales 5y agoThe server sides are typically set up with some flexibility to account for the latency and avoid this UX issue. They will have a window to accept the previous/next code even after the new becomes active. To avoid replays, though, this should be reset once a code is accepted: only subsequent codes should be accepted afterwards. So when code N is the "correct" code, any of N-1, N, or N+1 will be accepted. But if N is entered, only N+1 and onwards should be accepted for later attempts.
- kccqzy 5y agoServers generally have no problem accepting an expired code, if the code is only expired for a few seconds.
- deleted 5y ago[deleted]
- pmlamotte 5y ago
- Donckele 5y agoThis could be a stupid question, why not just use the first few characters from the hash of the secret and the timestamp?
- duskwuff 5y agoThat's pretty close to what they're doing, with some small changes (using HMAC, measuring the time in 30-second intervals, and generating a numeric code).
- Jtsummers 5y agoOne of the requirements for HOTP (which TOTP is based on) was that the code should be numeric for phone entry or similarly constrained entry mechanisms. > R4 - The value displayed on the token MUST be easily read and entered by the user: This requires the HOTP value to be of reasonable length. The HOTP value must be at least a 6-digit value. It is also desirable that the HOTP value be 'numeric only' so that it can be easily entered on restricted devices such as phones. See R4 at https://datatracker.ietf.org/doc/html/rfc4226 https://datatracker.ietf.org/doc/html/rfc4226 (split across pages 4 and 5).
- cbdumas 5y agoWith that scheme an attacker who gets access to a code (no matter how old) can then generate their own going forward. The hash function here means that even if someone obtains a code they can't generate other codes.
- TimWolla 5y agoOne reason might be that those characters would include letters. A digits-only code is much easier to type, e.g. using a restricted keypad, such as a phone.
- tshaddox 5y agoDon't all hashes start out as numbers anyway, before they get encoded as alphanumeric strings?
- jjeaff 5y ago
- loloquwowndueo 5y agoThere’s even a program called oathtool which you can use to generate TOTP and HOTP (counter-based and much more prone to skew) codes. You just need the random seed that’s generated when you create a device. I’m not sure how easy it is to extract from the qrcode that web services generate, though. Some identity providers will show the raw random seed.
- Jtsummers 5y agohttps://github.com/google/google-authenticator/wiki/Key-Uri-Format https://github.com/google/google-authenticator/wiki/Key-Uri-... That's the format that gets encoded into the QR code. If you can decode the QR code you can get the secret key easily.
- jmcphers 5y agoIt's pretty easy to extract! zbarimg -q -raw <png> will do it. http://manpages.ubuntu.com/manpages/bionic/man1/zbarimg.1.html http://manpages.ubuntu.com/manpages/bionic/man1/zbarimg.1.ht...
- hannob 5y agoAFAIR there isn't much to "extract", you simply use any application that can decode the QR code and you get the key which is encoded as a sequence of letters and numbers.
- composer 5y agooathtool -w1 --base32 --totp $secret Add a space before the command depending on your shell. Some shells will keep your secret out of history logs.
- sleavey 5y agoI found this part interesting: > Notice that when the key is, say, 40 bytes long, it’s padded with zeros to make it 64 bytes long. So the actual entropy of that key is equivalent to the 40-byte long key. But if the key is longer than 64 bytes, it’s effectively being shortened to 20 bytes. So its entropy is lower. If you want to maximize the complexity of the key, and you’re the one choosing the key, go for something around, but never more than, 64 bytes. Perhaps that's why some sites have a maximum character limit for passwords. (Although I suspect many are just doing it wrong.)
- wyager 5y agoThere is no sound technical or security justification for having a maximum character limit, up to some obscenely long limit to prevent the user wasting server resources by submitting giant forms. Also, no one should be using raw HMAC to do password checking. At the very least use something like PBKDF2.
- trinovantes 5y agoAt this point, I just automatically assume any website that has a maximum character limit and weird character restrictions is storing the password in plaintext
- jaywalk 5y agoSometimes the character restrictions are due to overly aggressive web application firewalls.
- tdumitrescu 5y agoSetting a reasonable limit closes off a potential DoS vector. That's why our security team had us add a limit. (Sure, in practice rate limiting should also be in place, defense in depth.)
- codegeek 5y agoOne really good TOTP app for desktops is Authy [0] from Twilio. Some people are not aware that it exists and you don't need an app on your phone for TOTP. Authy works from your desktop as well. [0] https://authy.com/download/ https://authy.com/download/ (scroll down to see Desktop version for download)
- robertlagrant 5y agoInteresting! I didn't know that. Pretty handy for corporate stuff - keep the 2FA on the work computer.
- banana_giraffe 5y agoOn the topic of TOTP apps, I like "OTP Auth" for iOS devices. It's fairly simple, and offers an Apple Watch client that works well.
- jcims 5y agoYou can also roll your own with https://github.com/pyauth/pyotp https://github.com/pyauth/pyotp
- codetrotter 5y ago> roll your own Libraries for a couple of other languages: https://crates.io/search?q=4226 https://crates.io/search?q=4226 https://pkg.go.dev/search?q=4226 https://pkg.go.dev/search?q=4226
- tyingq 5y ago
- jrm4 5y agoGood stuff. One pernicious "lie through technology" that is out there is that TOTP et al are something special that must be done through some sort of secret or proprietary app or worse, hardware key device. Nothing wrong with having these as an option -- but e.g. recently my workplace mandated using Duo (the 2FA thing, not google) for our 2FA stuff -- which doesn't let you keep your own generating keys. It's literally the only 2FA thing I have that won't let you do this, and its infuriating because I use oathtool for all the others. And this is at a university -- so effectively this means you must have a modern cell phone with a particular app or buy a dongle or you can't do school.
- thaumasiotes 5y ago> One pernicious "lie through technology" that is out there is that TOTP et al are something special that must be done through some sort of secret or proprietary app or worse, hardware key device. It's a lie, but you only have a second factor if it's true. Your Duo is attempting to deliver what it promises, where Google Authenticator doesn't even make the attempt. You can extract the secret directly from the app, though, if you have the option to use it as an app.
- jrm4 5y agoI'm trying to parse your second sentence, and I think I somewhat agree in a technical sense, but I think it would be fairer to say, Duo forces a second factor on you, whereas Google gives you the option; and in the long run it's better to not babysit people through a "lie." Last sentence? Serious question. Can you? I was just presuming that you can't; i.e. if I were to build a freedom-reducing proprietary solution like this, I'd keep the the key on my home servers and only deliver the 6 digit codes?
- jrm4 5y agoOh heck, found the answer, apparently so? Cool. https://github.com/puddly/android-otp-extractor https://github.com/puddly/android-otp-extractor
- zaphirplane 5y agoI wonder why credit card issuers haven’t gotten on that idea. Whenever I use my credit card I have to enter a onetime /time based amount based pin. Rather than the system of anyone that knows my card number can charge whatever amount they like for however long they want
- deleted 5y ago[deleted]
- karmicthreat 5y agoI like using Yubico Authenticator. I have a primary and backup Yubikey and I copy the TOTP secret to both. Its also nice that the secret is kept on the key rather than my phone.
- Unklejoe 5y agoDoes Google itself support TOTP with Google Authenticator? When I try to enable 2FA, the only options seem to be a text, call, security key (I’m guessing this is FIDO?), and “get a notification on your device”.
- McTossOut 5y agoDepends on the day
- knorker 5y agoHow does this article not link to the specs, aka the RFCs?
- nick_name 5y ago# python3 -m pip install pyotp SECRET='JBSWY3DPEHPK3PXP' python3 -c "import pyotp; print(pyotp.TOTP('${SECRET}').now())"
- tedk-42 5y agoI built this to generate OTP codes via CLI https://github.com/edify42/otp-codegen https://github.com/edify42/otp-codegen
- bondolo 5y agoDoes the password strategy really just truncate passwords over 64 characters? I don't use them often but since text passwords typically have low number of significant bits per character I have always assumed that the input string was hashed to a fixed length password that would increase in quality until the randomness of the text approached random bytes. My current secure passphrase is a paragraph that I have memorized from a book, about 250 characters, but I only type it a couple of times per month. Disappointing if 190 or so characters of this typing is indeed wasted effort and that at least 8 bytes or more (1-3 bits per character) of entropy is wasted per password because text doesn't use all 8 bits.
- mullingitover 5y ago> How does Google Authenticator work? Really poorly. Not only my experience, also the prevailing sentiment in app store reviews, where it has a sub-2.5 star rating. Up until pretty recently you couldn't even back up your passcodes, so it was extremely risky to use it. Use Authy, there is clearly a lot more effort put into that app.
- tim333 5y agoA non techy friend of mine had some bad issues in that she had it on an iPhone, switched to a new iPhone copying everything over via icloud as one usually does and then finding Google Auth didn't copy the auth codes over or warn you that it won't, and hence was locked out of various accounts.
- js2 5y agoThere’s also a tool that converts Symantec VIP Access tokens to standard TOTP tokens: https://github.com/dlenski/python-vipaccess https://github.com/dlenski/python-vipaccess
- janfromdaito 5y agoNot a big fan of a Google Authentcator myself, and didnt want to stay with Authy as well, thus I started working on my own authenticator, which is web-ased: https://www.daito.io/ https://www.daito.io/ The main differentiator is that this a web-based authenticator, not an app-based one. The main goal being a fully separate service (thus full separation of concerns) from a password manager. It's not ready for prime time yet, but if you are interested to test it, please reach out.
- lazyant 5y agohttps://www.trustedreviews.com/news/google-ignored-a-key-vulnerability-in-its-authenticator-app-for-years-4015077 https://www.trustedreviews.com/news/google-ignored-a-key-vul...