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

Add Steam algorithm behind 'steam' feature #47

Merged
merged 6 commits into from
Jan 6, 2023

Conversation

timvisee
Copy link
Contributor

@timvisee timvisee commented Jan 2, 2023

This implements Algorithm::Steam behind the steam feature flag.

Fixes #45

Note that this is somewhat dirty, but keeps the API stability intact. Notably:

  • Adds steam feature (disabled by default)
  • Adds Algorithm::Steam variant
  • Disables RFC assertions in TOTP::new() if algorithm is Steam
  • TOTP::generate() uses Steam alphabet for token if Steam algorithm is used
  • TOTP::from_url() parses Steam URLs if the steam path is detected.

I've tested this successfully with my personal Steam token.

I'm not sure if this is good enough to be merged, but I figured this to be a good start.

@constantoine
Copy link
Owner

One of the main reason I was thinking of using an API similar to Rfc6238 (for defaults) is that in case of steam algorithm, periods and digits do not make much sense, as they're always the same

@timvisee
Copy link
Contributor Author

timvisee commented Jan 3, 2023

A Steam struct you mean. That can definitely be added.

This would still require a Algorithm::Steam variant (or alternatively a new TOTP property) because it uses a different token alphabet. Along with these changes in TOTP::from_url() to parse otpauth://steam URIs.

@constantoine
Copy link
Owner

constantoine commented Jan 3, 2023

The work on algorithm is fine as is, yes!

It's just that instanciating it from New would be awkward, hence a Steam struct, or more simply having a custom_providers.rs file which would contain, gated behind a feature for each provider, a impl block for TOTP with stuff like new_steam and new_battlenet, which would call the new_unchecked variant under the hood?

This would mean merging #46 and then rebasing

Edit: Because having a struct for each custom provider would actually be way too much copy/pasted code, and would probably hurt readability

@timvisee
Copy link
Contributor Author

timvisee commented Jan 3, 2023

Alright! I'll work on these new_ functions once possible.

I agree, that adding struct for this would add a lot of boilerplate.

@constantoine
Copy link
Owner

Thanks a lot! :)

@constantoine
Copy link
Owner

Now that I think about it, the get_url function should be mindful of the algo, as in the steam case, we need to use /steam/ instead of /totp/

@timvisee
Copy link
Contributor Author

timvisee commented Jan 3, 2023

Now that I think about it, the get_url function should be mindful of the algo, as in the steam case, we need to use /steam/ instead of /totp/

Right. This is already handled in

https://github.com/timvisee/totp-rs/blob/9d506d4ae19cb28a269ae4e56f2f23bb14684622/src/lib.rs#L453-L460

and

https://github.com/timvisee/totp-rs/blob/9d506d4ae19cb28a269ae4e56f2f23bb14684622/src/lib.rs#L480-L492

@timvisee
Copy link
Contributor Author

timvisee commented Jan 4, 2023

This is now rebased on the latest master.

A TOTP::new_steam() method is added in custom_providers.rs and generating a Steam TOTP URL now works correctly.

Currently, it detects otpauth://steam/ as Steam TOTP. It appears that some authenticators use otpauth://totp/?issuer=Steam instead, which is likely why this didn't work.

@constantoine Are you fine with me implementing ?issuer=Steam to be parsed as Algorithm::Steam?

@constantoine
Copy link
Owner

As long as it's gated behind the Steam feature, I think it's acceptable, yes

@timvisee
Copy link
Contributor Author

timvisee commented Jan 4, 2023

Implemented. This is ready for review.

src/lib.rs Show resolved Hide resolved
Comment on lines +518 to +522
#[cfg(feature = "steam")]
Some(Host::Domain("steam")) => {
algorithm = Algorithm::Steam;
digits = 5;
}
Copy link
Owner

Choose a reason for hiding this comment

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

I feel like you only need to set the algo, not the digits

Copy link
Contributor Author

@timvisee timvisee Jan 4, 2023

Choose a reason for hiding this comment

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

It seems like some otpauth URLs don't set the number of digits at all for Steam. That means we must set it explicitly somewhere.

Not setting this would cause problems, such as incorrect otpauth URL generation.

Better ways to implement this would require breaking API changes, I think.

Copy link
Owner

Choose a reason for hiding this comment

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

I see. Should we then ignore the digit parameter, should it be present? Just like we ignore algorithm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is an option. But that will still generate invalid otpauth URLs, as it will have ?digit=6. We can implement an exception there but I don't think that is better.

Copy link
Owner

@constantoine constantoine left a comment

Choose a reason for hiding this comment

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

I'll add some tests and benchmark some stuff on my end, but this PR is ready :)

I'll ping you when the release is published on cargo

@timvisee
Copy link
Contributor Author

timvisee commented Jan 5, 2023

Fantastic! Thanks for your help.

@constantoine constantoine merged commit d5b94dc into constantoine:master Jan 6, 2023
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.

question - how to support steam?
2 participants