Skip to content

Commit

Permalink
Fixed base64 error for challenge decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
LucFauvel committed Aug 21, 2024
1 parent c79240e commit 5843d50
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/oath/hotp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl OtpAuth for HOTPContext {
.ok_or_else(|| "Otpauth uri is malformed, missing parameters".to_string())
.and_then(|param_it| {
let mut secret = Vec::<u8>::new();
let mut counter = std::u64::MAX;
let mut counter = u64::MAX;
let mut alg = OTP_DEFAULT_ALG_VALUE;
let mut digits = OTP_DEFAULT_DIGITS_VALUE;

Expand Down Expand Up @@ -226,7 +226,7 @@ impl OtpAuth for HOTPContext {
}
}

if secret.is_empty() || counter == std::u64::MAX {
if secret.is_empty() || counter == u64::MAX {
return Err("Otpauth uri is malformed".to_string());
}

Expand Down
6 changes: 5 additions & 1 deletion src/webauthn/authenticator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ impl WebauthnAuthenticator {
let (attestation_object, private_key_response, der) =
Self::generate_attestation_object(alg, aaguid, &credential_id, rp_id, attestation_flags)?;

let challenge = base64::decode(credential_creation_options.challenge)?;
let challenge = match base64::decode(credential_creation_options.challenge.as_str()) {
Ok(challenge) => challenge,
Err(_) => base64::decode_config(credential_creation_options.challenge, URL_SAFE_NO_PAD)?,
};

let collected_client_data = CollectedClientData {
request_type: WEBAUTHN_REQUEST_TYPE_CREATE.to_owned(),
challenge: base64::encode_config(challenge, URL_SAFE_NO_PAD),
Expand Down

0 comments on commit 5843d50

Please sign in to comment.