Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(RP204-) getCodeFromTimeStamp() returns incorrect code #2

Closed
Devnol opened this issue May 16, 2021 · 3 comments
Closed

(RP204-) getCodeFromTimeStamp() returns incorrect code #2

Devnol opened this issue May 16, 2021 · 3 comments

Comments

@Devnol
Copy link
Contributor

Devnol commented May 16, 2021

MCU: RP2040
Compiler: arm-none-eabi-gcc
Compiler host machine: macOS

I have converted the base32 string provided by the 2fa server to hex using the Base32 (RFC 3548, RFC 4648) algorithm and provided it as hmacKey[] to the TOTP constructor.

I have also set the timezone to UTC+3 since it's summer and I'm in Greece using setTimezone(3), but the unix timestamp provided by the RP2040 RTC is already corrected to UTC±0. Is that how I'm supposed to do it?

Anyway, the provided timestamp from the RTC is correct but the generated token is invalid.
Any ideas?

@Netthaw
Copy link
Owner

Netthaw commented May 16, 2021

If timestamp on both side (2FA Server and RP2040) are based from UTC±0. It no need to use setTimezone.

TOTP(hmacKey, 10, 30);                                     // Secret key, Key length, Timestep (30s)

// setTimezone(0);                                         // Set timezone UTC
uint32_t newCode = getCodeFromTimestamp(1557414000);       // Timestamp Now

@Devnol
Copy link
Contributor Author

Devnol commented May 16, 2021

Oh ok so that basically does correction if the user hasn't done so beforehand. Thanks a lot I'll try it when I get home. Also you should probably make that a bit clearer in the README, as well as the fact that the string provided by most apps is base32 and needs to be upcased and decoded, because I initially thought it was ascii and converted it like that which obviously didn't work.
Btw congrats and thanks a lot for helping out even 2 years after this library was completed!

@Netthaw
Copy link
Owner

Netthaw commented May 16, 2021

Thank you very much for your comment. I will update Readme clearly!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants