8000 Support reading base32 encoded OTP secret by pedroigor · Pull Request #21117 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Support reading base32 encoded OTP secret - #21117

Merged
pedroigor merged 1 commit into
keycloak:mainfrom
pedroigor:issue-9434
Jun 22, 2023
Merged

pedroigor merged 1 commit into
keycloak:mainfrom
pedroigor:issue-9434

Conversation

@pedroigor
@pedroigor pedroigor commented Jun 20, 2023 •
Copy link
Copy Markdown
Contributor

Closes #9434
Closes #11561

  • Introduces a secretEncoding metadata to the credential metadata to force the server to properly decode secrets before validating/generating OTPs.
  • Adds support for Base32 (b32) secret encoding
  • Not sure how to document it as it does not provide the best UX. Users are forced to manually update the database to set the encoding.
  • It should work if creating users/credentials via Admin REST API

mposolda
mposolda previously approved these changes Jun 21, 2023
mposolda
mposolda previously approved these changes Jun 21, 2023
@pedroigor
pedroigor merged commit eb5edb3 into keycloak:main Jun 22, 2023
@dalbani
dalbani commented Jun 22, 2023
Copy link
Copy Markdown
Contributor

Thanks a lot @pedroigor, you've made my organization's migration to Keycloak much easier 👍

@pedroigor
pedroigor deleted the issue-9434 branch June 27, 2023 00:27
@namsudtho
namsudtho commented Aug 2, 2024 •
Copy link
Copy Markdown

@pedroigor I added secret key base32 to table:credential and it didn't work. Or is there a need for any special additional formats?

image

@angelomelonas
angelomelonas commented Aug 23, 2024 •
Copy link
Copy Markdown

@namsudtho I think you need to also specify the encoding when adding a BASE32 encoded OTP:

OTPCredentialModel otpCredentialModel = OTPCredentialModel.createTOTP(
        otpSecret, // TOTP Secret
        6, // Digits
        30, // Period
        "HmacSHA1", // Algorithm
        OTPCredentialModel.SecretEncoding.BASE32.name() // Encoding
);

@namsudtho
Copy link
Copy Markdown

@angelomelonas @pedroigor Can you please advise me if my organization is using base32 encoded secret otp?

@angelomelonas
Copy link
Copy Markdown

@namsudtho the secret value itself you add in Keycloak should not be encoded in base32 (like you have done in row 1 in the screenshot above). The value in row 2 should work. However, when you are adding the value, you need to specify the encoding as in my code snippet above (using the OTPCredentialModel.createTOTP() method). This will result in the following credential_data value:
{"subType":"totp","digits":6,"counter":0,"period":30,"algorithm":"HmacSHA1","secretEncoding":"BASE32"}

I think that last part might be what is missing from your row 2 credential_data value: "secretEncoding":"BASE32"

@namsudtho
Copy link
Copy Markdown

@angelomelonas Thank you very much. You know, it took me a long time to find a solution for this.

@angelomelonas
Copy link
Copy Markdown

@namsudtho you are very welcome!

@HimanshiNagpal02
Copy link
Copy Markdown

@angelomelonas I'm migrating TOTP secret from firebase to Keycloak. Credential table look like this
Screenshot 2024-09-26 at 5 17 38 PM

I have added the secret data and secret encoding in credentials data. But, it is not validating the code during authentication process. Am I missing something? Can you help please?

Screenshot 2024-09-26 at 5 28 48 PM

@angelomelonas
Copy link
Copy Markdown

@HimanshiNagpal02 how did you add the secret to Keycloak? If you did it via the Keycloak Admin Client, be sure to set the type like this:

otpCredentialModel.setType(OTPCredentialModel.TYPE);

instead of this:

otpCredentialModel.setType(OTPCredentialModel.TOTP);

@HimanshiNagpal02
Copy link
Copy Markdown

@angelomelonas It worked. Thanks much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non ASCII characters in TOTP secret not supported in 2FA configurations OTP base32 decode improvements

6 participants

0