[seal] Sealed boxes and key import: custos-seal (X25519 + XChaCha20-Poly1305, match code, at-rest sealing), custos_keys::import, Vault::factor_ids; v0.5.0
This commit is contained in:
@@ -479,6 +479,16 @@ impl Vault {
|
||||
Ok(header.factor_slots().iter().filter_map(|s| FactorKind::from_code(s.kind)).collect())
|
||||
}
|
||||
|
||||
/// The factors a vault file has, from its header (no key needed): id (32 hex digits) and type. The app
|
||||
/// asks the TOTP service and paired devices for a factor by this id.
|
||||
pub fn factor_ids(bytes: &[u8]) -> Result<Vec<(String, FactorKind)>, Error> {
|
||||
let (header, _) = Header::parse(bytes)?;
|
||||
if header.version == VERSION {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
Ok(header.factor_slots().iter().filter_map(|s| Some((hex(&s.id), FactorKind::from_code(s.kind)?))).collect())
|
||||
}
|
||||
|
||||
pub fn is_machine_store(bytes: &[u8]) -> Result<bool, Error> {
|
||||
Ok(Header::parse(bytes)?.0.is_machine_store())
|
||||
}
|
||||
|
||||
@@ -132,6 +132,11 @@ fn a_v1_vault_upgrades_and_its_password_alone_stops_working() {
|
||||
let new = v.to_bytes().unwrap();
|
||||
assert_eq!(Vault::version_of(&new).unwrap(), 2);
|
||||
assert_eq!(Vault::factor_kinds(&new).unwrap(), [FactorKind::Password, FactorKind::Device]);
|
||||
// The header names each factor by the id the unlocked vault lists; a v1 file has none.
|
||||
let ids = Vault::factor_ids(&new).unwrap();
|
||||
let listed: Vec<(String, FactorKind)> = v.factors().into_iter().map(|f| (f.id, f.kind)).collect();
|
||||
assert_eq!(ids, listed);
|
||||
assert!(Vault::factor_ids(&old).unwrap().is_empty());
|
||||
assert!(matches!(Vault::open(&new, &p), Err(Error::NeedTwoFactors)));
|
||||
let back = open(&new, Unlock::Password(&p), Unlock::Material(FactorKind::Device, &DEVICE)).unwrap();
|
||||
assert_eq!(back.items().len(), 1);
|
||||
|
||||
Reference in New Issue
Block a user