Skip to content

Add methods for creating TOTP/HOTP from raw bytes and from base32-encoded strings - #2

Merged
messense merged 3 commits into
messense:masterfrom
jbg:secret_bytes
Aug 23, 2019
Merged

Add methods for creating TOTP/HOTP from raw bytes and from base32-encoded strings#2
messense merged 3 commits into
messense:masterfrom
jbg:secret_bytes

Conversation

@jbg

@jbg jbg commented Aug 7, 2019

Copy link
Copy Markdown
Contributor

Currently the crate only accepts secrets in the form of Strings, which are valid UTF-8 by definition. The UTF-8 bytes of the string are then taken directly as the OTP secret. This is an unnecessary restriction on the possible secrets and significantly reduces the entropy in the resulting secret.

I added new methods for creating TOTP and HOTP from raw bytes and from base32-encoded strings.

Given the security shortcomings of the existing approach, I would also suggest that a release including these changes deprecate or remove the current new method and include a strong recommendation in the documentation/README to move to the from_bytes/from_base32 methods.

I used Option<T> as the return type for the from_base32 methods in order to keep these changes self-contained, but it might be worth adding an error type and using Result instead.

Comment thread src/hotp.rs
false
}

pub fn base32_secret(&self) -> String {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a pub(crate)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this method is quite useful for users of the crate. You can create the secret using securely-generated random bytes, and then you can get the base32 secret which is the standard format (other than QR codes) for giving the secret to users.

Comment thread src/hotp.rs
@messense
messense merged commit f4d4779 into messense:master Aug 23, 2019
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

Successfully merging this pull request may close these issues.

2 participants