Skip to content

Commit

Permalink
pin_info_hash: use serde-byte-array
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Mar 4, 2024
1 parent 079edd8 commit b9c797a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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"]
Expand All @@ -47,6 +48,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"] }
Expand All @@ -57,6 +59,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 = "4846817d9cd44604121680a19d46f3264973a3ce" }
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" }
Expand Down
21 changes: 21 additions & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ pub struct PersistentState {
key_encryption_key: Option<KeyId>,
key_wrapping_key: Option<KeyId>,
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.
Expand Down Expand Up @@ -515,3 +516,23 @@ impl RuntimeState {
}
}
}

#[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();
}
}

0 comments on commit b9c797a

Please sign in to comment.