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

Implement fido2/webauthn second-factor auth #116

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

quexten
Copy link
Contributor

@quexten quexten commented Apr 25, 2023

This PR implements support for Yubikeys and other Fido2 (Webauthn) tokens as a second factor.

It is currently tested and working with Vaultwarden and a Yubikey 5C, but still needs cleanup / testing.

Fixes #7. Might also make #76 redundant, since newer Yubikeys support Fido2.

@quexten quexten changed the title Implement prototype webauthn second-factor auth Implement fido2/webauthn second-factor auth Apr 25, 2023
@quexten
Copy link
Contributor Author

quexten commented Apr 25, 2023

@ambroisie For some reason I received your comments on this PR via email but don't see them in GitHub. Anyways, I removed the unecessary cloning code in the last commit, it was left over from when I tried a different Fido2 library, and I hadn't gotten around to cleaning it up yet.

@ambroisie
Copy link

@quexten yes, upon closer inspection I realized that the code was just scaffolding, hence why I deleted my comments.

@quexten quexten force-pushed the feature/webauthn-token branch from 037a2e3 to 0ebb4cc Compare April 26, 2023 23:38
@quexten
Copy link
Contributor Author

quexten commented Apr 26, 2023

I cleaned up the PR a bit now. I had to make this an optional feature (compiled with cargo build --features=webauthn) because the webauthn-rs library requires openssl.

Other than that I'm fairly happy with the state the PR is in right now for a first version.

One more improvement that could be made would be to only read the pin when needed. I haven't yet debugged why, but for some reason webauthn-rs always wants the pin, even when Firefox does not require the pin at all for Bitwarden. That way we could remove the code handling the token pin. But maybe that's for a follow-up PR.

@quexten quexten marked this pull request as ready for review April 26, 2023 23:56

[features]
# Enables webauthn 2-FA authenticaton, but requires openssl
webauthn = ["dep:webauthn-rs", "dep:webauthn-rs-proto", "dep:webauthn-authenticator-rs"]

Choose a reason for hiding this comment

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

Missing newline at the end of the file.

Comment on lines +59 to +61
webauthn-authenticator-rs = { version="0.5.0-dev", git = "https://github.com/kanidm/webauthn-rs.git", url = "./webauthn-authenticator-rs/", features = ["usb"], optional = true }
webauthn-rs-proto = { version="0.5.0-dev", git = "https://github.com/kanidm/webauthn-rs.git", url = "./webauthn-rs-protocol/", optional = true }
webauthn-rs = { version="0.5.0-dev", git = "https://github.com/kanidm/webauthn-rs.git", optional = true }

Choose a reason for hiding this comment

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

Is there a big difference between this version and the one currently released on crates.io (0.4.8)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, Fido2 (CTAP2) was only implemented after 0.4.8. I would like to switch this to the non-dev package as soon as it is released upstream, but without the dev package this PR does not work.

Comment on lines +44 to +46
let out = serde_json::to_string(&result.unwrap())?
.replace("\"appid\":null,\"hmac_get_secret\":null", "\"appid\":false")
.replace("clientDataJSON", "clientDataJson");

Choose a reason for hiding this comment

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

This looks quite brittle.

An alternative approach would be to create a wrapper struct which serializes the fields in the way the API expects them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, agreed, your proposed solution makes sense. I'll change it to that.

@doy
Copy link
Owner

doy commented May 13, 2023

thanks for this! i'll probably hold off on this until the webauthn crates are actually on crates.io to avoid having to deal with git revisions. i'd also like for this to be an optional feature, because this does seem to pull in a bunch of dependencies that are going to be annoying to build on some platforms. feel free to poke me once those things are in place and i'll look things over more closely (i've been a bit busy the past few weeks).

@jess-sol
Copy link

Now that webauthn-rs is on crates.io, is there interest in resurrecting this PR?

@quexten
Copy link
Contributor Author

quexten commented Nov 11, 2023

Now that webauthn-rs is on crates.io, is there interest in resurrecting this PR?

As far as I can see, the version on crates.rs is 0.4.8, which is still behind the required 0.5.0. Currently the pr uses 0.5.0-dev, which - while it is on crates.io - is a pre-release, so not sure if that should already be included.

Regardless, due to time constraints, I can't currently work on the PR though might at a future date. Aside from that, anyone who needs it right now can of course take over the PR.

@mochaaP
Copy link

mochaaP commented Apr 21, 2024

webauthn.rs needs a reimplementation with kanidm/webauthn-rs@5a49ab5 in place

@freswa
Copy link

freswa commented Aug 5, 2024

webauthn-rs has been updated to 0.5.0 on crates.io. Jfyi

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.

TODO error during login - YubiKey
6 participants