Skip to content

Commit 8ac81b8

Browse files
Allow unknown CBOR fields (ref #66) (#110)
* Part fixes #66 for unknown CBOR structures decoded via DeserializeIndexed from serde-indexed. * Remaining to allow unknown enum variants, to be fixed in a later PR. Depends on trussed-dev/serde-indexed#19.
1 parent 19e4945 commit 8ac81b8

24 files changed

+428
-163
lines changed

Cargo.lock

Lines changed: 55 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libwebauthn/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ futures = "0.3.5"
2929
tokio = { version = "1.45", features = ["full"] }
3030
serde = "1.0.110"
3131
serde_cbor = "0.11.2"
32-
serde-indexed = "0.1.1"
32+
serde-indexed = "0.2.0"
3333
serde_derive = "1.0.123"
3434
serde_repr = "0.1.6"
3535
serde_bytes = "0.11.5"

libwebauthn/src/fido.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::{
1212
};
1313
use tracing::{error, warn};
1414

15+
use crate::proto::ctap2::cbor;
1516
use crate::{
1617
proto::{
1718
ctap2::{Ctap2PublicKeyCredentialDescriptor, Ctap2PublicKeyCredentialType},
@@ -95,7 +96,10 @@ where
9596
// signCount | 4
9697
// attestedCredentialData | variable
9798
// extensions | variable
98-
let mut res = self.rp_id_hash.to_vec();
99+
let mut res = cbor::to_vec(&self.rp_id_hash).map_err(|e| {
100+
error!("Failed to create AuthenticatorData output vec at rp_id_hash: {e:?}");
101+
Error::Platform(e.into())
102+
})?;
99103
res.push(self.flags.bits());
100104
res.write_u32::<BigEndian>(self.signature_count)
101105
.map_err(|e| {
@@ -120,10 +124,11 @@ where
120124
})?;
121125
res.extend(&att_data.credential_id);
122126
let cose_encoded_public_key =
123-
serde_cbor::to_vec(&att_data.credential_public_key)
127+
cbor::to_vec(&att_data.credential_public_key)
124128
.map_err(|e| {
125129
error!(
126-
"Failed to create AuthenticatorData output vec at attested_credential.credential_public_key: {e:?}"
130+
%e,
131+
"Failed to create AuthenticatorData output vec at attested_credential.credential_public_key"
127132
);
128133
Error::Platform(PlatformError::InvalidDeviceResponse)
129134
})?;
@@ -132,8 +137,8 @@ where
132137

133138
if self.extensions.is_some() || self.flags.contains(AuthenticatorDataFlags::EXTENSION_DATA)
134139
{
135-
res.extend(serde_cbor::to_vec(&self.extensions).map_err(|e| {
136-
error!("Failed to create AuthenticatorData output vec at extensions: {e:?}");
140+
res.extend(cbor::to_vec(&self.extensions).map_err(|e| {
141+
error!(%e, "Failed to create AuthenticatorData output vec at extensions");
137142
Error::Platform(PlatformError::InvalidDeviceResponse)
138143
})?);
139144
}
@@ -215,9 +220,8 @@ impl<'de, T: DeserializeOwned> Deserialize<'de> for AuthenticatorData<T> {
215220
let mut credential_id = vec![0u8; credential_id_len];
216221
cursor.read_exact(&mut credential_id).unwrap(); // We checked the length
217222

218-
let mut deserializer = serde_cbor::Deserializer::from_reader(&mut cursor);
219223
let credential_public_key: PublicKey =
220-
Deserialize::deserialize(&mut deserializer).map_err(DesError::custom)?;
224+
cbor::from_reader(&mut cursor).map_err(DesError::custom)?;
221225

222226
attested_credential = Some(AttestedCredentialData {
223227
aaguid,
@@ -228,7 +232,7 @@ impl<'de, T: DeserializeOwned> Deserialize<'de> for AuthenticatorData<T> {
228232

229233
let extensions: Option<T> =
230234
if flags.contains(AuthenticatorDataFlags::EXTENSION_DATA) {
231-
serde_cbor::from_reader(&mut cursor).map_err(DesError::custom)?
235+
cbor::from_reader(&mut cursor).map_err(DesError::custom)?
232236
} else {
233237
Default::default()
234238
};

libwebauthn/src/management/authenticator_config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::proto::ctap2::cbor;
12
use crate::proto::ctap2::Ctap2ClientPinRequest;
23
pub use crate::transport::error::{CtapError, Error};
34
use crate::transport::Channel;
@@ -14,7 +15,6 @@ use crate::{
1415
};
1516
use async_trait::async_trait;
1617
use serde_bytes::ByteBuf;
17-
use serde_cbor::ser::to_vec;
1818
use std::time::Duration;
1919
use tracing::info;
2020

@@ -173,7 +173,7 @@ impl Ctap2UserVerifiableRequest for Ctap2AuthenticatorConfigRequest {
173173
data.push(0x0D);
174174
data.push(self.subcommand as u8);
175175
if self.subcommand == Ctap2AuthenticatorConfigCommand::SetMinPINLength {
176-
data.extend(to_vec(&self.subcommand_params).unwrap());
176+
data.extend(cbor::to_vec(&self.subcommand_params).unwrap());
177177
}
178178
let uv_auth_param = uv_proto.authenticate(uv_auth_token, &data);
179179
self.protocol = Some(uv_proto.version());

0 commit comments

Comments
 (0)