mirror of
https://github.com/antonioribeiro/google2fa.git
synced 2026-04-24 23:55:55 +03:00
[GH-ISSUE #226] Issue with Invalid characters in base32 string message when using valid base32 string #97
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/google2fa#97
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @brandonobrien on GitHub (May 9, 2025).
Original GitHub issue: https://github.com/antonioribeiro/google2fa/issues/226
I'm trying to migrate from
sonata-project/google-authenticatorsince it's been abandoned for a while. I have thousands of 2fa codes set up that are based on an md5 hash + 2fa salt environment value. These are then converted to base32 and used for creating the QR code as well as validating the 6 digit pin.The issue I'm running into is
verifyKeyis throwing anInvalidCharactersExceptioneven though the string is valid. I wrote a test script and verified the string is valid through several different means. I'll include as much information as I can, including the test script I wrote, that proves this issue.pragmarx/google2fa v8.0.3(added as"pragmarx/google2fa": "^8.0"in mycomposer.jsonfile8.3.1MEYGGZRYGQYGMZRRMNRDCYJVGYZDQY3CGU4TEYJSGQ2TKM3EGMZUYOCMKE2EESSLIJBVQQSNHAYVEUZYGNJVKQKPK5AVKOBZJJJEKM2RJFCDQNRXHFMQ====The expected output would be:
verifyKeyshould process the secret without throwing anInvalidCharactersException, and then return false (because 123456 is a dummy code).I've run this code both inside and outside of my Laravel framework and receive the same error message, so it doesn't seem to be some kind of conflict with a constant being overwritten.
If I generate a secret directly with
$google2fa->generateSecretKey()and then run$google2fa->verifyKey()with that secret, it works exactly as expected. It's just an issue with valid base32 codes that were generated using the old code. Obviously I can't switch to this project if I'm unable to have the old codes work.Any ideas what may be causing this or any additional information you need from me?
@rimas-kudelis commented on GitHub (May 27, 2025):
@brandonobrien , you're passing
$secretto the validator, but you're testing your assumptions with$secretWithoutPadding. I believe padding is exactly what causes the issue, because if you look at the code of this library, it never removes any padding, and=is not an acceptable character for base32.And if you drop padding, this key will still fail due to unacceptable key length. You might want to look into generating keys that don't have these issues at least in future (and maybe migrating affected users to "valid" keys as well).
I'm in the same boat as you, tasked with a migration from
sonata-project/google-authenticator, but if you look at the code of that library, it's both very minimalistic and yet surprisingly clean. If you want to keep your current 2FA keys, you might consider retaining that dependency on the abandoned package, or looking at its forks/compatible packages (there are some, but the ones I checked were hardly any better code-wise), or even adopting its code as classes in your own project. However, you pay some attention to the fact that that library generates links to a third-party service when asked to generate a QR code URL. If you're using that functionality, you're essentially trusting that third party with all TOTPs of your users (as well as sending their usernames to it). I'm replacing that bit with local generation viaendroid/qr-code[-bundle]and returning data URIs of these generated images instead,