From d813aac248bcbccdcd87343d06ee463dc12f069d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Wed, 31 Jan 2024 14:57:47 +0100 Subject: [PATCH] pin_info_hash: use serde-byte-array --- Cargo.toml | 4 ++++ src/state.rs | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 1270ab7..ca9bba2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ trussed-staging = { version = "0.1.0", default-features = false, optional = true apdu-dispatch = { version = "0.1", optional = true } ctaphid-dispatch = { version = "0.1", optional = true } iso7816 = { version = "0.1", optional = true } +serde-byte-array = "0.1.2" [features] dispatch = ["apdu-dispatch", "ctaphid-dispatch", "iso7816"] @@ -46,6 +47,7 @@ log-error = [] [dev-dependencies] env_logger = "0.11.0" +hex-literal = "0.4.1" # quickcheck = "1" rand = "0.8.4" trussed = { version = "0.1", features = ["virt"] } @@ -56,6 +58,7 @@ usbd-ctaphid = "0.1.0" features = ["dispatch"] [patch.crates-io] +cbor-smol = { git = "https://github.com/sosthene-nitrokey/cbor-smol.git", rev = "94ee8c28edf9248b402aa4335c1dee157995197b"} ctap-types = { git = "https://github.com/trussed-dev/ctap-types.git", rev = "7d4ad69e64ad308944c012aef5b9cfd7654d9be8" } ctaphid-dispatch = { git = "https://github.com/trussed-dev/ctaphid-dispatch.git", rev = "57cb3317878a8593847595319aa03ef17c29ec5b" } apdu-dispatch = { git = "https://github.com/trussed-dev/apdu-dispatch.git", rev = "915fc237103fcecc29d0f0b73391f19abf6576de" } @@ -64,3 +67,4 @@ trussed-staging = { git = "https://github.com/trussed-dev/trussed-staging", rev serde-indexed = { git = "https://github.com/sosthene-nitrokey/serde-indexed.git", rev = "5005d23cb4ee8622e62188ea0f9466146f851f0d" } trussed-usbip = { git = "https://github.com/Nitrokey/pc-usbip-runner.git", tag = "v0.0.1-nitrokey.1" } usbd-ctaphid = { git = "https://github.com/Nitrokey/usbd-ctaphid.git", tag = "v0.1.0-nitrokey.2" } +cbor-smol = { path = "../cbor-smol" } diff --git a/src/state.rs b/src/state.rs index 7b524aa..af05287 100644 --- a/src/state.rs +++ b/src/state.rs @@ -263,6 +263,7 @@ pub struct PersistentState { key_encryption_key: Option, key_wrapping_key: Option, consecutive_pin_mismatches: u8, + #[serde(with = "serde_byte_array")] pin_hash: Option<[u8; 16]>, // Ideally, we'd dogfood a "Monotonic Counter" from trussed. // TODO: Add per-key counters for resident keys. @@ -592,3 +593,23 @@ impl RuntimeState { Ok(shared_secret) } } + +#[cfg(test)] +mod tests { + use super::*; + use hex_literal::hex; + + #[test] + fn deser() { + let _state: PersistentState = trussed::cbor_deserialize(&hex!( + " + a5726b65795f656e6372797074696f6e5f6b657950b19a5a2845e5ec71e3 + 2a1b890892376c706b65795f7772617070696e675f6b6579f6781a636f6e + 73656375746976655f70696e5f6d69736d617463686573006870696e5f68 + 6173689018ef1879187c1881181818f0182d18fb186418960718dd185d18 + 3f188c18766974696d657374616d7009 + " + )) + .unwrap(); + } +}