Google Authenticator on Apple devices, some secrets are not valid

We have included two-factor authentication in one of our applications using Google Authenticator. Something really strange happened in QA. Although I managed to fix it, I'm not quite sure why the fix works.

For our shared secret, we assigned a GUID to the user when they begin to configure TFA. The GUID receives the base-32 encoding and places it in the URL, which is converted into a QR code and verified by the user using the phone:

 otpauth://totp/myapp_user?secret=g5swmnddhbtggllbgi3dsljumi3tallbmuytgljtg5sdgnbxmy2dgyjwmy======

And everything works well for all the non-ios machines we tried. On ios alone, it throws a really strange error when trying to scan a barcode most of the time:

Invalid barcode

The barcode '[same as above]' is not a valid authentication token barcode.

It complies with Google / RFC 4226 minimum secret requirement (128 bit), Base32 encoded correctly, etc. Why is this failing? A typical reason for this message is a space in the URL, but it is not.

If I add a little seed at the beginning of the tutorial, everything will work fine:

otpauth://totp/myapp_user?secret=nfygq33omvzxky3lom3ggmzyha2tgnjnmu4gezbngqzdgyrnhbtdqzrnmeywimrwmjsgknzymi3a

This is essentially the difference between:

 secret = enc.Encode32(Encoding.ASCII.GetBytes("iphonesucks" + Guid.NewGuid().ToString()));  // Works

 secret = enc.Encode(Encoding.ASCII.GetBytes(Guid.NewGuid().ToString())); // Fails

 newAuthUrl = string.Format("otpauth://totp/myapp_user?secret={0}", secret);

I have two crazy theories about why this might work:

  • The ios port requires more than 128 bits. My comment / seed is enough to pounce on this limit, no matter what happens ... except that I actually gave it more than 128 bits, since it was a guid-as string.

  • After decoding Base32, the ios application recognizes the secret string as guid and does something else with it.

, . - ? .

+4
2

, . , Google Authenticator = IPhone, Android.

base32 8 10 . === . , = , base32:

pad (=) BASE32; BASE32 40-

, . , , = .

.

+4

URI: ? Otpauth://TOTP/: alice@google.com = JBSWY3DPEHPK3PXP & =

URI "" " ", .

PS. Google Authenticatior .

0

All Articles