Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COSE key deserialization assumes map order #7

Closed
robin-nitrokey opened this issue Feb 16, 2023 · 1 comment · Fixed by Nitrokey/ctap-types#2
Closed

COSE key deserialization assumes map order #7

robin-nitrokey opened this issue Feb 16, 2023 · 1 comment · Fixed by Nitrokey/ctap-types#2

Comments

@robin-nitrokey
Copy link
Member

The Deserialize implementations for the types in the cose module assume a specific order of the elements of the map.

Minimal example:

const DATA: &str = "a42001215820babc05993673d3d9745712333373cc6da964b4814d0cd666ce97c5ffef8befa522582029ebc161c05e3ba0f702a4cf1df30aca224ae3cf7b9478f4a811726976908ef00102";

use ciborium::de::from_reader;
use ctap_types::cose::EcdhEsHkdf256PublicKey;

fn main() {
    let data = hex::decode(DATA).unwrap();
    println!("{:?}", from_reader::<EcdhEsHkdf256PublicKey, _>(data.as_slice()));
}

Expected:

Ok(_)

Actual:

Err(Semantic(None, "missing field `kty`"))

Side note: Why are the traits implemented manually and not derived?

robin-nitrokey added a commit to robin-nitrokey/ctap-types that referenced this issue Feb 16, 2023
Previously, COSE keys could only be deserialized if the map entries were
in the correct order.  With this patch, the deserialization is made more
robust (and also more concise) by introducing a helper struct,
RawPublicKey, that is used as an intermediate step during the
deserialization.

Fixes: trussed-dev#7
@nickray
Copy link
Member

nickray commented Mar 8, 2023

Same comment as in #8, CTAP2 canonical CBOR encoding form is required by the standard. Although the implementation may or may not be wrong for specific types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants