Skip to content

Commit 5211667

Browse files
authored
Prevent panic in bitwarden-fido crate (#346)
## 🎟️ Tracking - ## 📔 Objective ``` Fido2CredentialFullView { credential_id: "", key_type: "", key_algorithm: "", key_curve: "", key_value: "", rp_id: "", user_handle: None, user_name: None, counter: "", rp_name: None, user_display_name: None, discoverable: "", creation_date: 1970-01-01T00:00:00Z, } ``` will result in the expect to panic the SDK. This PR instead maps to a newly created error. ## ⏰ Reminders before review - Contributor guidelines followed - All formatters and local linters executed and passed - Written new unit and / or integration tests where applicable - Protected functional changes with optionality (feature flags) - Used internationalization (i18n) for all UI strings - CI builds passed - Communicated to DevOps any deployment requirements - Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team ## 🦮 Reviewer guidelines <!-- Suggested interactions but feel free to use (or not) as you desire! --> - 👍 (`:+1:`) or similar for great changes - 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info - ❓ (`:question:`) for questions - 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion - 🎨 (`:art:`) for suggestions / improvements - ❌ (`:x:`) or ⚠️ (`:warning:`) for more significant problems or concerns needing attention - 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or indications of technical debt - ⛏ (`:pick:`) for minor or nitpick changes
1 parent f2bc708 commit 5211667

File tree

1 file changed

+7
-1
lines changed
  • crates/bitwarden-fido/src

1 file changed

+7
-1
lines changed

crates/bitwarden-fido/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ pub enum Fido2Error {
9191

9292
#[error("No Fido2 credentials found")]
9393
NoFido2CredentialsFound,
94+
95+
#[error("Invalid counter")]
96+
InvalidCounter,
9497
}
9598

9699
impl TryFrom<CipherViewContainer> for Passkey {
@@ -107,7 +110,10 @@ impl TryFrom<CipherViewContainer> for Passkey {
107110
}
108111

109112
fn try_from_credential_full_view(value: Fido2CredentialFullView) -> Result<Passkey, Fido2Error> {
110-
let counter: u32 = value.counter.parse().expect("Invalid counter");
113+
let counter: u32 = value
114+
.counter
115+
.parse()
116+
.map_err(|_| Fido2Error::InvalidCounter)?;
111117
let counter = (counter != 0).then_some(counter);
112118
let key_value = URL_SAFE_NO_PAD.decode(value.key_value)?;
113119
let user_handle = value

0 commit comments

Comments
 (0)