Managed to authenticate user using Webauthn

This commit is contained in:
2022-04-23 20:17:49 +02:00
parent 05d3bee328
commit 9e345895ff
4 changed files with 54 additions and 4 deletions

View File

@ -3,7 +3,7 @@ use std::sync::Arc;
use actix_web::web;
use webauthn_rs::{AuthenticationState, RegistrationState, Webauthn, WebauthnConfig};
use webauthn_rs::proto::{CreationChallengeResponse, Credential, RegisterPublicKeyCredential, RequestChallengeResponse};
use webauthn_rs::proto::{CreationChallengeResponse, Credential, PublicKeyCredential, RegisterPublicKeyCredential, RequestChallengeResponse};
use crate::constants::APP_NAME;
use crate::data::app_config::AppConfig;
@ -45,6 +45,7 @@ pub struct RegisterKeyRequest {
struct RegisterKeyOpaqueData {
registration_state: RegistrationState,
user_id: UserID,
// TODO : add time
}
pub struct AuthRequest {
@ -56,6 +57,7 @@ pub struct AuthRequest {
struct AuthStateOpaqueData {
authentication_state: AuthenticationState,
user_id: UserID,
// TODO : add time
}
@ -123,4 +125,17 @@ impl WebAuthManager {
login_challenge,
})
}
pub fn finish_authentication(&self, user_id: &UserID, opaque_state: &str,
pub_cred: &PublicKeyCredential) -> Res {
let state: AuthStateOpaqueData = self.crypto_wrapper.decrypt(opaque_state)?;
if &state.user_id != user_id {
return Err(Box::new(
std::io::Error::new(ErrorKind::Other, "Invalid user for pubkey!")));
}
self.core.authenticate_credential(pub_cred, &state.authentication_state)?;
Ok(())
}
}