diff --git a/crates/bitwarden/src/vault/totp.rs b/crates/bitwarden/src/vault/totp.rs index 4adbe4dac..9bc92229b 100644 --- a/crates/bitwarden/src/vault/totp.rs +++ b/crates/bitwarden/src/vault/totp.rs @@ -129,7 +129,7 @@ impl FromStr for Totp { fn from_str(key: &str) -> Result { fn decode_secret(secret: &str) -> Result> { BASE32 - .decode(secret.as_bytes()) + .decode(secret.to_uppercase().as_bytes()) .map_err(|_| "Unable to decode secret".into()) } @@ -230,6 +230,20 @@ mod tests { assert_eq!(response.period, 30); } + #[test] + fn test_lowercase_secret() { + let key = "wqiq25brkzycjvyp".to_string(); + let time = Some( + DateTime::parse_from_rfc3339("2023-01-01T00:00:00.000Z") + .unwrap() + .with_timezone(&Utc), + ); + let response = generate_totp(key, time).unwrap(); + + assert_eq!(response.code, "194506".to_string()); + assert_eq!(response.period, 30); + } + #[test] fn test_generate_otpauth() { let key = "otpauth://totp/test-account?secret=WQIQ25BRKZYCJVYP".to_string();