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 25, 2024
1 parent 7db98dd commit bc842bd
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-chunked = { version = "0.1.0", optional = true }
apdu-dispatch = { version = "0.1", optional = true }
ctaphid-dispatch = { version = "0.1", optional = true }
iso7816 = { version = "0.1", optional = true }
serde_bytes = { version = "0.11.14", default-features = false }

[features]
dispatch = ["apdu-dispatch", "ctaphid-dispatch", "iso7816"]
Expand All @@ -51,6 +52,7 @@ delog = { version = "0.1.6", features = ["std-log"] }
env_logger = "0.11.0"
interchange = "0.3.0"
log = "0.4.21"
hex-literal = "0.4.1"
# quickcheck = "1"
rand = "0.8.4"
serde_cbor = { version = "0.11.0", features = ["std"] }
Expand All @@ -64,6 +66,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 @@ -262,6 +262,7 @@ pub struct PersistentState {
key_encryption_key: Option<KeyId>,
key_wrapping_key: Option<KeyId>,
consecutive_pin_mismatches: u8,
#[serde(with = "serde_bytes")]
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 @@ -516,3 +517,23 @@ impl RuntimeState {
self.pin_protocol = Some(PinProtocolState::new(trussed));
}
}

#[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 bc842bd

Please sign in to comment.