[core] Tests: RFC 6238/4226 vectors, otpauth parsing, Wi-Fi escaping, device key wrap
This commit is contained in:
@@ -202,3 +202,27 @@ fn no_secret_in_debug_or_display() {
|
||||
// Non-secret fields stay readable in Debug, which is what makes it useful.
|
||||
assert!(format!("{item:?}").contains("Example"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn device_wrap_opens_the_same_vault_and_nothing_else() {
|
||||
// Windows Hello gives the desktop app a signature; the core turns it into a key wrap.
|
||||
let v = sample_vault("pw");
|
||||
let bytes = v.to_bytes().unwrap();
|
||||
let material = b"signature bytes from the device key";
|
||||
let blob = v.wrap_for_device(material).unwrap();
|
||||
assert_ne!(v.wrap_for_device(material).unwrap(), blob, "fresh salt and nonce each time");
|
||||
|
||||
let back = Vault::open_with_device(&bytes, &blob, material).unwrap();
|
||||
assert_eq!(back.items(), v.items());
|
||||
|
||||
assert!(matches!(Vault::open_with_device(&bytes, &blob, b"other signature"), Err(Error::DeviceKeyRejected)));
|
||||
for i in 0..blob.len() {
|
||||
let mut t = blob.clone();
|
||||
t[i] ^= 1;
|
||||
assert!(Vault::open_with_device(&bytes, &t, material).is_err(), "blob byte {i}");
|
||||
}
|
||||
// A blob made for another vault does not open this one.
|
||||
let other = sample_vault("pw").wrap_for_device(material).unwrap();
|
||||
assert!(Vault::open_with_device(&bytes, &other, material).is_err());
|
||||
assert!(!format!("{:?}", Error::DeviceKeyRejected).contains("signature"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user