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 Jan 31, 2024
1 parent b0c72d3 commit d813aac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"] }
Expand All @@ -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" }
Expand All @@ -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" }
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 @@ -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();
}
}

0 comments on commit d813aac

Please sign in to comment.