pub struct U2fManager { /* private fields */ }Expand description
Manager for U2F registration and authentication flows.
Implementations§
Source§impl U2fManager
impl U2fManager
Sourcepub fn new(app_id: &str) -> Result<Self>
pub fn new(app_id: &str) -> Result<Self>
Create a new U2F manager for the given application ID.
The app_id should be the application’s origin (e.g., https://example.com).
Sourcepub fn generate_registration_challenge(&self) -> Result<U2fRegistrationRequest>
pub fn generate_registration_challenge(&self) -> Result<U2fRegistrationRequest>
Generate a registration challenge for a new U2F device.
Sourcepub fn verify_registration(
&mut self,
user_id: &str,
request: &U2fRegistrationRequest,
response: &U2fRegistrationResponse,
) -> Result<U2fRegistration>
pub fn verify_registration( &mut self, user_id: &str, request: &U2fRegistrationRequest, response: &U2fRegistrationResponse, ) -> Result<U2fRegistration>
Verify a U2F registration response and store the credential.
Per the U2F spec, the registration response contains:
- 1 byte: reserved (0x05)
- 65 bytes: user public key (uncompressed P-256)
- 1 byte: key handle length
- N bytes: key handle
- remaining: attestation certificate + signature
§Example
ⓘ
let request = authenticator.generate_registration_challenge()?;
// … user interacts with the U2F device …
let registration = authenticator.verify_registration("user1", &request, &response)?;Sourcepub fn generate_sign_challenge(
&self,
user_id: &str,
) -> Result<Vec<U2fSignRequest>>
pub fn generate_sign_challenge( &self, user_id: &str, ) -> Result<Vec<U2fSignRequest>>
Generate an authentication challenge for a registered user.
Sourcepub fn verify_authentication(
&self,
user_id: &str,
request: &U2fSignRequest,
response: &U2fSignResponse,
) -> Result<u32>
pub fn verify_authentication( &self, user_id: &str, request: &U2fSignRequest, response: &U2fSignResponse, ) -> Result<u32>
Verify a U2F authentication response.
The signature data contains:
- 1 byte: user presence
- 4 bytes: counter (big-endian)
- remaining: ECDSA signature
Sourcepub fn get_registrations(&self, user_id: &str) -> Option<&Vec<U2fRegistration>>
pub fn get_registrations(&self, user_id: &str) -> Option<&Vec<U2fRegistration>>
Get all registrations for a user.
Sourcepub fn remove_registration(&mut self, user_id: &str, key_handle: &[u8]) -> bool
pub fn remove_registration(&mut self, user_id: &str, key_handle: &[u8]) -> bool
Remove a specific key handle registration.
Auto Trait Implementations§
impl Freeze for U2fManager
impl RefUnwindSafe for U2fManager
impl Send for U2fManager
impl Sync for U2fManager
impl Unpin for U2fManager
impl UnsafeUnpin for U2fManager
impl UnwindSafe for U2fManager
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more