Skip to content

Commit 6a8e588

Browse files
fix(u2f): replace production assert! in U2F register response upgrade
`RegisterResponse::try_upgrade` asserts that the canonical CBOR encoding of the synthesized COSE P-256 key is exactly 77 bytes. The 77-byte assumption holds for current `cosey 0.3` output, but is implementation-defined: a future `cosey` revision adding an optional field (e.g., `kid`) would round-trip to a slightly different size and panic the host process. The recent panic-removal pass (commit 5df814b) missed this site because `clippy::panic` does not lint `assert!`. Replace the assertion with a typed length check that returns `Error::Platform(PlatformError::CryptoError(...))` on mismatch.
1 parent 82e5acf commit 6a8e588

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

libwebauthn/src/ops/u2f.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,18 @@ impl UpgradableResponse<MakeCredentialResponse, MakeCredentialRequest> for Regis
8989
y: y.into(),
9090
});
9191
let cose_encoded_public_key = cbor::to_vec(&cose_public_key)?;
92-
assert!(cose_encoded_public_key.len() == 77);
92+
// Canonical CBOR encoding of the COSE P-256 key is 77 bytes for the
93+
// fields we set; return a typed error if a future encoder change
94+
// produces a different length rather than `assert!`-panicking.
95+
if cose_encoded_public_key.len() != 77 {
96+
error!(
97+
len = cose_encoded_public_key.len(),
98+
"COSE-encoded P-256 public key is not 77 bytes"
99+
);
100+
return Err(Error::Platform(PlatformError::CryptoError(
101+
"unexpected COSE-encoded public key length".into(),
102+
)));
103+
}
93104

94105
// Let attestedCredData be a byte string with following structure:
95106
//

0 commit comments

Comments
 (0)