mirror of
https://github.com/antonioribeiro/google2fa.git
synced 2026-04-25 16:15:49 +03:00
[PR #126] [MERGED] Support for sha256 & sha512 HMAC Algorithms #631
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#631
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?
📋 Pull Request Information
Original PR: https://github.com/antonioribeiro/google2fa/pull/126
Author: @wells
Created: 9/20/2019
Status: ✅ Merged
Merged: 9/23/2019
Merged by: @antonioribeiro
Base:
master← Head:support-sha256-sha512📝 Commits (4)
e74d4cfUpdate Constants.phpc1bb594Update Google2FA.php5900d71Update QRCode.php82e6afeUpdate Google2FATest.php📊 Changes
4 files changed (+396 additions, -13 deletions)
View changed files
📝
src/Google2FA.php(+45 -5)📝
src/Support/Constants.php(+15 -0)📝
src/Support/QRCode.php(+6 -0)📝
tests/Google2FATest.php(+330 -8)📄 Description
According to RFC6238 (https://tools.ietf.org/html/rfc6238), TOTP should be able to support SHA256 and SHA512 HMAC algorithms, in addition to SHA1.
To start off, I added the
&algorithm=SHA1query parameter to the end of OTP URL ingetQRCodeUrl(). This allows QR codes from the package to specify which algorithm to use with HMAC hashing.In my initial tests, I was unable to get SHA256 and SHA512 to validate until I found a mistake in the
oathTruncate()function. I updated the offset line to match what was in the RFC. Once I did that, all 3 algorithms worked as expected.See page 13 of RFC6238 within the
generateTOTP()function:What I changed in the
oathTruncate()function of this package:That one line was the only thing in the way of supporting SHA256 and SHA512. I have added the necessary tests to confirm that these alternate hashing algorithms do in fact work.
Note: This package still defaults to SHA1, to avoid any breaking changes for existing usage.
It also would appear that most authenticator apps ONLY support SHA1 HMAC hashing. Let's hope this eventually changes.
Authenticator apps tested:
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.