Compare commits
4 Commits
06410ab3be
...
v0.10.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e386e8113 | |||
| 92ab8a0d63 | |||
| bf661a7338 | |||
| 510d5eecd1 |
@@ -51,3 +51,7 @@ On the dev machine set `CARGO_HOME=F:\C-Drive-Migration\future-caches\cargo` (C:
|
||||
first, then a test, then the code.
|
||||
- Branch → PR on Gitea (token in `$GITEA_TOKEN`, never echoed) → self-review in the PR body → merge `--no-ff`
|
||||
→ push → `git rev-parse HEAD origin/main` → tag `vX.Y.Z` (the private app pins tags).
|
||||
|
||||
## Known traps
|
||||
- `cargo fmt --all` reformats files that are not rustfmt-clean on `main` (custos-keys, custos-seal, custos-wasm and
|
||||
some tests): run `rustfmt --edition 2024 <file>` on the files you changed, so a PR carries no unrelated churn.
|
||||
|
||||
Generated
+10
-10
@@ -329,7 +329,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "custos-gen"
|
||||
version = "0.9.0"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"custos-vault",
|
||||
"data-encoding",
|
||||
@@ -341,7 +341,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "custos-kdbx"
|
||||
version = "0.9.0"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"argon2",
|
||||
@@ -362,7 +362,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "custos-keys"
|
||||
version = "0.9.0"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"custos-vault",
|
||||
"ed25519-dalek",
|
||||
@@ -375,11 +375,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "custos-qr"
|
||||
version = "0.9.0"
|
||||
version = "0.10.0"
|
||||
|
||||
[[package]]
|
||||
name = "custos-seal"
|
||||
version = "0.9.0"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"chacha20poly1305",
|
||||
"hkdf",
|
||||
@@ -392,7 +392,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "custos-share"
|
||||
version = "0.9.0"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"argon2",
|
||||
"chacha20poly1305",
|
||||
@@ -409,7 +409,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "custos-sign"
|
||||
version = "0.9.0"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"blake2 0.10.6",
|
||||
"data-encoding",
|
||||
@@ -426,7 +426,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "custos-totp"
|
||||
version = "0.9.0"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"custos-vault",
|
||||
"data-encoding",
|
||||
@@ -439,7 +439,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "custos-vault"
|
||||
version = "0.9.0"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"argon2",
|
||||
"bip39",
|
||||
@@ -463,7 +463,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "custos-wasm"
|
||||
version = "0.9.0"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"custos-qr",
|
||||
"custos-seal",
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ resolver = "3"
|
||||
members = ["crates/*"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.9.0"
|
||||
version = "0.10.0"
|
||||
edition = "2024"
|
||||
license = "MPL-2.0"
|
||||
repository = "https://gitea.marek-novak.cz/mnovak/CustosPublic"
|
||||
|
||||
@@ -84,11 +84,9 @@ pub fn generate(alg: Algorithm, comment: &str) -> Result<KeyPair, KeyError> {
|
||||
/// An OpenSSH key keeps its own comment unless it has none.
|
||||
pub fn import(text: &str, comment: &str) -> Result<KeyPair, KeyError> {
|
||||
// Pasted or read from a Windows file: CRLF line ends.
|
||||
let text = text.replace(
|
||||
"
|
||||
let text = text.replace("
|
||||
", "
|
||||
",
|
||||
);
|
||||
");
|
||||
let text = text.trim();
|
||||
let has = |label: &str| text.contains(&format!("-----BEGIN {label}-----"));
|
||||
if has("ENCRYPTED PRIVATE KEY") || text.contains("Proc-Type: 4,ENCRYPTED") {
|
||||
@@ -101,9 +99,7 @@ pub fn import(text: &str, comment: &str) -> Result<KeyPair, KeyError> {
|
||||
}
|
||||
let comment = if key.comment().is_empty() { comment.to_owned() } else { key.comment().to_owned() };
|
||||
return match key.key_data() {
|
||||
KeypairData::Ed25519(k) => {
|
||||
from_ed25519(ed25519_dalek::SigningKey::from_bytes(&k.private.to_bytes()), &comment)
|
||||
}
|
||||
KeypairData::Ed25519(k) => from_ed25519(ed25519_dalek::SigningKey::from_bytes(&k.private.to_bytes()), &comment),
|
||||
KeypairData::Ecdsa(EcdsaKeypair::NistP256 { private, .. }) => {
|
||||
from_p256(p256::SecretKey::from_slice(private.as_slice()).map_err(|_| KeyError::Invalid)?, &comment)
|
||||
}
|
||||
@@ -139,13 +135,8 @@ pub fn import(text: &str, comment: &str) -> Result<KeyPair, KeyError> {
|
||||
/// rebuilt from its components here.
|
||||
fn rsa_from_openssh(k: &RsaKeypair) -> Result<rsa::RsaPrivateKey, KeyError> {
|
||||
let n = |m: &ssh_key::Mpint| rsa::BigUint::try_from(m).map_err(|_| KeyError::Invalid);
|
||||
let sk = rsa::RsaPrivateKey::from_components(
|
||||
n(&k.public.n)?,
|
||||
n(&k.public.e)?,
|
||||
n(&k.private.d)?,
|
||||
vec![n(&k.private.p)?, n(&k.private.q)?],
|
||||
)
|
||||
.map_err(|_| KeyError::Invalid)?;
|
||||
let sk = rsa::RsaPrivateKey::from_components(n(&k.public.n)?, n(&k.public.e)?, n(&k.private.d)?, vec![n(&k.private.p)?, n(&k.private.q)?])
|
||||
.map_err(|_| KeyError::Invalid)?;
|
||||
sk.validate().map_err(|_| KeyError::Invalid)?;
|
||||
Ok(sk)
|
||||
}
|
||||
@@ -178,13 +169,7 @@ fn from_rsa(sk: rsa::RsaPrivateKey, comment: &str) -> Result<KeyPair, KeyError>
|
||||
assemble(&format!("rsa-{bits}"), KeypairData::Rsa(enc(RsaKeypair::try_from(sk))?), private_pem, public_pem, comment)
|
||||
}
|
||||
|
||||
fn assemble(
|
||||
algorithm: &str,
|
||||
data: KeypairData,
|
||||
private_pem: String,
|
||||
public_pem: String,
|
||||
comment: &str,
|
||||
) -> Result<KeyPair, KeyError> {
|
||||
fn assemble(algorithm: &str, data: KeypairData, private_pem: String, public_pem: String, comment: &str) -> Result<KeyPair, KeyError> {
|
||||
let private = enc(PrivateKey::new(data, comment))?;
|
||||
let public = private.public_key();
|
||||
Ok(KeyPair {
|
||||
|
||||
@@ -87,8 +87,7 @@ fn every_private_key_format_imports_to_the_same_key() {
|
||||
for text in inputs {
|
||||
// Surrounding whitespace (a paste, a file with CRLF line ends) does not matter.
|
||||
let pasted = format!("\r\n {}\r\n", text.replace('\n', "\r\n"));
|
||||
let i = custos_keys::import(&pasted, "deploy")
|
||||
.unwrap_or_else(|e| panic!("{alg:?} {}: {e:?}", text.lines().next().unwrap()));
|
||||
let i = custos_keys::import(&pasted, "deploy").unwrap_or_else(|e| panic!("{alg:?} {}: {e:?}", text.lines().next().unwrap()));
|
||||
assert_eq!((i.algorithm.as_str(), i.fingerprint.as_str()), (alg.name(), k.fingerprint.as_str()), "{alg:?}");
|
||||
assert_eq!(i.public_pem, k.public_pem);
|
||||
}
|
||||
|
||||
@@ -52,9 +52,7 @@ fn random<const N: usize>() -> Zeroizing<[u8; N]> {
|
||||
|
||||
fn derive(ikm: &[u8], salt: &[u8], info: &[&[u8]]) -> Zeroizing<[u8; 32]> {
|
||||
let mut k = Zeroizing::new([0u8; 32]);
|
||||
hkdf::Hkdf::<Sha256>::new(Some(salt), ikm)
|
||||
.expand(&info.concat(), k.as_mut())
|
||||
.expect("32 bytes is a valid HKDF length");
|
||||
hkdf::Hkdf::<Sha256>::new(Some(salt), ikm).expand(&info.concat(), k.as_mut()).expect("32 bytes is a valid HKDF length");
|
||||
k
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! The Domi identity's root key (docs/IDENTITY.md). It lives in the vault body and never leaves it: nothing
|
||||
//! here or on [`Vault`] returns it, and the vault signs nothing with it but subkey certificates.
|
||||
//! here or on [`Vault`] returns it, and the vault signs nothing with it but subkey certificates and
|
||||
//! revocations of keys the person revoked. It derives each app's backup secret from it.
|
||||
//!
|
||||
//! Creating it is a typestate, so the mnemonic is always shown before the root exists:
|
||||
//!
|
||||
@@ -46,6 +47,13 @@ use zeroize::Zeroizing;
|
||||
/// The root signs `CERT_DOMAIN ‖ tbs`, and only a `tbs` that starts with `CERT_MAGIC ‖ its public key`.
|
||||
const CERT_DOMAIN: &[u8] = b"tessera cert v1\0";
|
||||
const CERT_MAGIC: &[u8] = b"TSC1";
|
||||
/// And `REVOKE_DOMAIN ‖ tbs`, only for a `tbs` that starts with `REVOKE_MAGIC ‖ its public key ‖ a key the
|
||||
/// person revoked ‖ that key's revoked_at` (Fundamentum docs/TESSERA.md §12).
|
||||
const REVOKE_DOMAIN: &[u8] = b"tessera revoke v1\0";
|
||||
const REVOKE_MAGIC: &[u8] = b"TRV1";
|
||||
/// magic 4, root 32, subkey 32, revoked_at 8, part 2, parts 2, count 4.
|
||||
const REVOKE_HEADER: usize = 84;
|
||||
const BACKUP_SALT: &[u8] = b"tessera backup v1";
|
||||
const WORDS: usize = 24;
|
||||
|
||||
/// Step 1: fresh entropy. Nothing is derived from it until the words have been shown.
|
||||
@@ -111,6 +119,26 @@ impl Enrollment {
|
||||
display(&words);
|
||||
Shown { entropy: self.entropy, challenge: random_challenge() }
|
||||
}
|
||||
|
||||
/// Restores an identity from its whole phrase, typed back (docs/IDENTITY.md, "Restoring it"): all 24
|
||||
/// words prove more than three. Any case, any spacing. Anything that is not 24 English BIP39 words with a
|
||||
/// valid checksum is [`Error::NotAMnemonic`], which names no word.
|
||||
pub fn restore(phrase: &str) -> Result<Confirmed, Error> {
|
||||
// Room for lowercasing without a reallocation that would leave a copy behind.
|
||||
let mut joined = Zeroizing::new(String::with_capacity(phrase.len() * 3 + 1));
|
||||
for (i, w) in phrase.split_whitespace().enumerate() {
|
||||
if i > 0 {
|
||||
joined.push(' ');
|
||||
}
|
||||
joined.extend(w.chars().flat_map(char::to_lowercase));
|
||||
}
|
||||
if joined.split(' ').count() != WORDS {
|
||||
return Err(Error::NotAMnemonic);
|
||||
}
|
||||
let m =
|
||||
bip39::Mnemonic::parse_in_normalized(bip39::Language::English, &joined).map_err(|_| Error::NotAMnemonic)?;
|
||||
Ok(Confirmed { secret: crypto::domi_root_secret(&m) })
|
||||
}
|
||||
}
|
||||
|
||||
impl Shown {
|
||||
@@ -165,7 +193,7 @@ impl fmt::Debug for Confirmed {
|
||||
}
|
||||
|
||||
/// A cert the vault signed, for display (docs/IDENTITY.md). A record, not a trust list.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Issued {
|
||||
/// `app` or `device`.
|
||||
pub kind: String,
|
||||
@@ -180,6 +208,12 @@ pub struct Issued {
|
||||
pub not_after: u64,
|
||||
/// Unix milliseconds.
|
||||
pub issued: i64,
|
||||
/// Unix seconds: when the person revoked the key (core 0.10.0).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub revoked_at: Option<u64>,
|
||||
/// The signed `TRV1` statements, base64url, once an app sent the events to keep.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub revocation: Vec<String>,
|
||||
}
|
||||
|
||||
/// The identity in an unlocked vault.
|
||||
@@ -212,6 +246,45 @@ impl Root {
|
||||
Ok(crypto::ed25519_sign(&self.secret, &msg))
|
||||
}
|
||||
|
||||
pub(crate) fn sign_revocation(&self, tbs: &[u8]) -> Result<[u8; 64], Error> {
|
||||
let names_me = tbs.len() >= REVOKE_HEADER && &tbs[..4] == REVOKE_MAGIC && tbs[4..36] == self.public;
|
||||
if !names_me {
|
||||
return Err(Error::NotARevocation);
|
||||
}
|
||||
let subkey = data_encoding::BASE64URL_NOPAD.encode(&tbs[36..68]);
|
||||
let at = u64::from_be_bytes(tbs[68..76].try_into().expect("8 bytes"));
|
||||
if !self.issued.iter().any(|i| i.subkey == subkey && i.revoked_at == Some(at)) {
|
||||
return Err(Error::NotARevocation);
|
||||
}
|
||||
let msg = Zeroizing::new([REVOKE_DOMAIN, tbs].concat());
|
||||
Ok(crypto::ed25519_sign(&self.secret, &msg))
|
||||
}
|
||||
|
||||
/// Marks every cert of `subkey` revoked; keeps the earliest time if one was marked before.
|
||||
pub(crate) fn mark_revoked(&mut self, subkey: &str, at: u64) -> Result<u64, Error> {
|
||||
let mut certs = self.issued.iter().filter(|i| i.subkey == subkey).peekable();
|
||||
if certs.peek().is_none() {
|
||||
return Err(Error::UnknownKey);
|
||||
}
|
||||
let at = certs.filter_map(|i| i.revoked_at).min().unwrap_or(at);
|
||||
self.issued.iter_mut().filter(|i| i.subkey == subkey).for_each(|i| i.revoked_at = Some(at));
|
||||
Ok(at)
|
||||
}
|
||||
|
||||
pub(crate) fn record_revocation(&mut self, subkey: &str, statements: Vec<String>) -> Result<(), Error> {
|
||||
let mut certs = self.issued.iter_mut().filter(|i| i.subkey == subkey).peekable();
|
||||
if certs.peek().is_none() {
|
||||
return Err(Error::UnknownKey);
|
||||
}
|
||||
certs.for_each(|i| i.revocation = statements.clone());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// `HKDF-SHA256(salt "tessera backup v1", ikm = root secret, info = app id)` (docs/IDENTITY.md).
|
||||
pub(crate) fn backup_secret(&self, app_id: &str) -> Zeroizing<[u8; KEY_LEN]> {
|
||||
crypto::hkdf(self.secret.as_ref(), BACKUP_SALT, app_id.as_bytes())
|
||||
}
|
||||
|
||||
pub(crate) fn json(&self) -> RootJson {
|
||||
RootJson {
|
||||
root: SecretString::new(hex(self.secret.as_ref())),
|
||||
|
||||
@@ -71,6 +71,12 @@ pub enum Error {
|
||||
NotACert,
|
||||
#[error("those words are not the ones in the recovery phrase")]
|
||||
WrongWords,
|
||||
#[error("these are not the 24 words of a recovery phrase: check each word and their order")]
|
||||
NotAMnemonic,
|
||||
#[error("the Domi identity signs a revocation only for a key revoked in Custos, at the time it was revoked")]
|
||||
NotARevocation,
|
||||
#[error("the Domi identity did not certify this key")]
|
||||
UnknownKey,
|
||||
#[error("this vault already has {0} signing keys")]
|
||||
SigningExists(&'static str),
|
||||
#[error("signing keys: {0}")]
|
||||
@@ -828,4 +834,27 @@ impl Vault {
|
||||
self.identity.as_mut().ok_or(Error::NoIdentity)?.issued.push(issued);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The person revoked the key `subkey` (base64url): marks every cert of it. Returns the revocation time in
|
||||
/// effect, the earlier one if it was marked before. The caller saves the vault.
|
||||
pub fn domi_mark_revoked(&mut self, subkey: &str, revoked_at: u64) -> Result<u64, Error> {
|
||||
self.identity.as_mut().ok_or(Error::NoIdentity)?.mark_revoked(subkey, revoked_at)
|
||||
}
|
||||
|
||||
/// Ed25519 with the root over `"tessera revoke v1\0" ‖ tbs`, for a `tbs` that starts with `TRV1`, this
|
||||
/// root's public key, a key marked revoked and its `revoked_at` ([`Error::NotARevocation`] otherwise).
|
||||
pub fn domi_sign_revocation(&self, tbs: &[u8]) -> Result<[u8; 64], Error> {
|
||||
self.identity.as_ref().ok_or(Error::NoIdentity)?.sign_revocation(tbs)
|
||||
}
|
||||
|
||||
/// Keeps the signed statements (base64url `TRV1`) with every cert of `subkey`. The caller saves the vault.
|
||||
pub fn domi_record_revocation(&mut self, subkey: &str, statements: Vec<String>) -> Result<(), Error> {
|
||||
self.identity.as_mut().ok_or(Error::NoIdentity)?.record_revocation(subkey, statements)
|
||||
}
|
||||
|
||||
/// The backup secret of the app `app_id` (docs/IDENTITY.md): derived from the root, handed to that app
|
||||
/// only. The caller checks `app_id` (a-z, 0-9, `-`) and the app's right to it.
|
||||
pub fn domi_backup_secret(&self, app_id: &str) -> Result<Zeroizing<[u8; 32]>, Error> {
|
||||
Ok(self.identity.as_ref().ok_or(Error::NoIdentity)?.backup_secret(app_id))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,9 +86,7 @@ fn a_factor_is_added_and_removed_without_the_others() {
|
||||
// Only the new factor's material is needed: its pairs come from the factor keys in the body.
|
||||
let phone = v.add_factor(Unlock::Material(FactorKind::Approval, &PHONE), "Phone").unwrap();
|
||||
let bytes = v.to_bytes().unwrap();
|
||||
let mut v =
|
||||
open(&bytes, Unlock::Material(FactorKind::Approval, &PHONE), Unlock::Material(FactorKind::Device, &DEVICE))
|
||||
.unwrap();
|
||||
let mut v = open(&bytes, Unlock::Material(FactorKind::Approval, &PHONE), Unlock::Material(FactorKind::Device, &DEVICE)).unwrap();
|
||||
let kinds: Vec<_> = v.factors().iter().map(|f| f.kind).collect();
|
||||
assert_eq!(kinds, [FactorKind::Password, FactorKind::Device, FactorKind::Approval]);
|
||||
// A lost device: drop its factor; the other two still open, the device no longer helps.
|
||||
@@ -110,8 +108,7 @@ fn a_forgotten_password_is_replaced_with_two_other_factors() {
|
||||
let mut v = two_factor_vault();
|
||||
v.add_factor(Unlock::Material(FactorKind::Totp, &TOTP), "TOTP backup").unwrap();
|
||||
let bytes = v.to_bytes().unwrap();
|
||||
let mut v =
|
||||
open(&bytes, Unlock::Material(FactorKind::Device, &DEVICE), Unlock::Material(FactorKind::Totp, &TOTP)).unwrap();
|
||||
let mut v = open(&bytes, Unlock::Material(FactorKind::Device, &DEVICE), Unlock::Material(FactorKind::Totp, &TOTP)).unwrap();
|
||||
v.change_password(&pw("New9-Password4"), FAST).unwrap();
|
||||
let bytes2 = v.to_bytes().unwrap();
|
||||
let dev = || Unlock::Material(FactorKind::Device, &DEVICE);
|
||||
@@ -171,14 +168,7 @@ fn a_machine_store_opens_with_its_device_key_alone() {
|
||||
let user = two_factor_vault().to_bytes().unwrap();
|
||||
assert!(!Vault::is_machine_store(&user).unwrap());
|
||||
assert!(matches!(Vault::open_machine_store(&user, &DEVICE), Err(Error::NeedTwoFactors)));
|
||||
assert!(
|
||||
Vault::open_with(
|
||||
&bytes,
|
||||
Unlock::Material(FactorKind::Device, &STORE),
|
||||
Unlock::Material(FactorKind::Device, &STORE)
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
assert!(Vault::open_with(&bytes, Unlock::Material(FactorKind::Device, &STORE), Unlock::Material(FactorKind::Device, &STORE)).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -188,20 +178,10 @@ fn limits_are_enforced() {
|
||||
v.add_factor(Unlock::Material(FactorKind::Device, &[100 + i; 32]), "extra").unwrap();
|
||||
}
|
||||
assert_eq!(v.factors().len(), 8);
|
||||
assert!(matches!(
|
||||
v.add_factor(Unlock::Material(FactorKind::Device, &[1; 32]), "ninth"),
|
||||
Err(Error::TooManyFactors)
|
||||
));
|
||||
assert!(matches!(v.add_factor(Unlock::Material(FactorKind::Device, &[1; 32]), "ninth"), Err(Error::TooManyFactors)));
|
||||
// Every pair still opens with 8 factors (8 factor slots + 28 pair slots).
|
||||
let bytes = v.to_bytes().unwrap();
|
||||
assert!(
|
||||
open(
|
||||
&bytes,
|
||||
Unlock::Material(FactorKind::Device, &[100; 32]),
|
||||
Unlock::Material(FactorKind::Device, &[105; 32])
|
||||
)
|
||||
.is_ok()
|
||||
);
|
||||
assert!(open(&bytes, Unlock::Material(FactorKind::Device, &[100; 32]), Unlock::Material(FactorKind::Device, &[105; 32])).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -210,10 +190,7 @@ fn no_factor_material_in_debug_output() {
|
||||
let u = Unlock::Material(FactorKind::Device, &secret);
|
||||
let p = pw("Orbit7-Fable3");
|
||||
let printed = format!("{u:?} {:?}", Unlock::Password(&p));
|
||||
assert!(
|
||||
!printed.contains("171") && !printed.to_lowercase().contains("ab, ab") && !printed.contains("Orbit7"),
|
||||
"{printed}"
|
||||
);
|
||||
assert!(!printed.contains("171") && !printed.to_lowercase().contains("ab, ab") && !printed.contains("Orbit7"), "{printed}");
|
||||
let v = two_factor_vault();
|
||||
let printed = format!("{v:?} {:?}", v.factors());
|
||||
for f in v.factors() {
|
||||
@@ -230,8 +207,7 @@ fn the_key_pair_item_type_round_trips() {
|
||||
k.set("private-key", "-----BEGIN PRIVATE KEY-----\n…", 5);
|
||||
v.add(k);
|
||||
let bytes = v.to_bytes().unwrap();
|
||||
let back =
|
||||
open(&bytes, Unlock::Password(&pw("Orbit7-Fable3")), Unlock::Material(FactorKind::Device, &DEVICE)).unwrap();
|
||||
let back = open(&bytes, Unlock::Password(&pw("Orbit7-Fable3")), Unlock::Material(FactorKind::Device, &DEVICE)).unwrap();
|
||||
let item = back.items().iter().find(|i| i.kind == ItemType::KeyPair).unwrap();
|
||||
assert!(item.fields.iter().any(|f| f.name == "private-key" && f.secret));
|
||||
}
|
||||
|
||||
@@ -128,6 +128,8 @@ fn the_identity_survives_saving_in_both_versions() {
|
||||
not_before: 1,
|
||||
not_after: 2,
|
||||
issued: 3,
|
||||
revoked_at: Some(4),
|
||||
revocation: vec!["VFJWMQ".into()],
|
||||
};
|
||||
// Version 1.
|
||||
let mut v = vault();
|
||||
@@ -165,8 +167,176 @@ fn a_record_needs_an_identity() {
|
||||
not_before: 0,
|
||||
not_after: 1,
|
||||
issued: 0,
|
||||
..Issued::default()
|
||||
};
|
||||
assert!(matches!(v.domi_record(i), Err(Error::NoIdentity)));
|
||||
assert!(matches!(v.domi_mark_revoked("x", 1), Err(Error::NoIdentity)));
|
||||
assert!(matches!(v.domi_backup_secret("fiscus"), Err(Error::NoIdentity)));
|
||||
}
|
||||
|
||||
// ---- v1.1: restoring, revoking, the backup secret (docs/IDENTITY.md) ----
|
||||
|
||||
const ZERO_PHRASE: &str = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon \
|
||||
abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon \
|
||||
abandon art";
|
||||
const REVOKE_DOMAIN: &[u8] = b"tessera revoke v1\0";
|
||||
const SUBKEY_9: &str = "CQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQk"; // [9; 32]
|
||||
|
||||
#[test]
|
||||
fn the_24_words_restore_the_same_root() {
|
||||
let mut v = vault();
|
||||
Enrollment::restore(ZERO_PHRASE).unwrap().import(&mut v).unwrap();
|
||||
assert_eq!(v.domi_root_public().unwrap().to_vec(), b64url(ROOT_PUB_ZERO));
|
||||
// Any case, any spacing, as long as the words are right.
|
||||
let mut w = vault();
|
||||
let messy = format!(" {}\n", ZERO_PHRASE.to_uppercase().replace(' ', " \t"));
|
||||
Enrollment::restore(&messy).unwrap().import(&mut w).unwrap();
|
||||
assert_eq!(w.domi_root_public(), v.domi_root_public());
|
||||
// And from words that were shown: the same root as enrolling.
|
||||
let mut e = vault();
|
||||
let words = enrol(&mut e, [42; 32]);
|
||||
let mut r = vault();
|
||||
Enrollment::restore(&words.join(" ")).unwrap().import(&mut r).unwrap();
|
||||
assert_eq!(r.domi_root_public(), e.domi_root_public());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wrong_phrase_restores_nothing_and_names_no_word() {
|
||||
let bad_checksum = ZERO_PHRASE.replace("art", "abandon");
|
||||
let short = "abandon ".repeat(11) + "about";
|
||||
let typo = ZERO_PHRASE.replacen("abandon", "abandn", 1);
|
||||
for phrase in [bad_checksum.as_str(), short.as_str(), typo.as_str(), "", "art"] {
|
||||
let e = Enrollment::restore(phrase).map(|_| ()).unwrap_err();
|
||||
assert!(matches!(e, Error::NotAMnemonic), "{phrase}");
|
||||
let shown = format!("{e} {e:?}");
|
||||
assert!(!shown.contains("abandon") && !shown.contains("art "), "{shown}");
|
||||
}
|
||||
// Into a vault that has one already: refused, the old one stays.
|
||||
let mut v = vault();
|
||||
enrol(&mut v, [5; 32]);
|
||||
let before = v.domi_root_public();
|
||||
assert!(matches!(Enrollment::restore(ZERO_PHRASE).unwrap().import(&mut v), Err(Error::IdentityExists)));
|
||||
assert_eq!(v.domi_root_public(), before);
|
||||
}
|
||||
|
||||
/// A revocation's to-be-signed bytes as tessera makes them: TRV1 ‖ root ‖ subkey ‖ revoked_at ‖ part ‖
|
||||
/// parts ‖ count ‖ hashes.
|
||||
fn trv1(root: &[u8; 32], subkey: &[u8; 32], revoked_at: u64) -> Vec<u8> {
|
||||
let mut t = b"TRV1".to_vec();
|
||||
t.extend_from_slice(root);
|
||||
t.extend_from_slice(subkey);
|
||||
t.extend_from_slice(&revoked_at.to_be_bytes());
|
||||
t.extend_from_slice(&0u16.to_be_bytes());
|
||||
t.extend_from_slice(&1u16.to_be_bytes());
|
||||
t.extend_from_slice(&1u32.to_be_bytes());
|
||||
t.extend_from_slice(&[7; 32]);
|
||||
t
|
||||
}
|
||||
|
||||
fn issued_to(subkey: &str, app_id: &str) -> Issued {
|
||||
Issued {
|
||||
kind: "app".into(),
|
||||
app_id: app_id.into(),
|
||||
purpose: "sync".into(),
|
||||
subkey: subkey.into(),
|
||||
label: "fiscus.exe".into(),
|
||||
not_before: 1,
|
||||
not_after: 2,
|
||||
issued: 3,
|
||||
..Issued::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_root_signs_a_revocation_only_for_a_key_the_person_revoked() {
|
||||
let mut v = vault();
|
||||
enrol(&mut v, [0; 32]);
|
||||
let root = v.domi_root_public().unwrap();
|
||||
v.domi_record(issued_to(SUBKEY_9, "fiscus")).unwrap();
|
||||
// Issued, but not revoked yet: refused.
|
||||
let t = trv1(&root, &[9; 32], 1000);
|
||||
assert!(matches!(v.domi_sign_revocation(&t), Err(Error::NotARevocation)));
|
||||
// An unknown key cannot be marked.
|
||||
assert!(matches!(v.domi_mark_revoked("CgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgo", 1000), Err(Error::UnknownKey)));
|
||||
|
||||
// A renewal issued a second cert for the same key: marking covers both, and the first time stays.
|
||||
v.domi_record(issued_to(SUBKEY_9, "fiscus")).unwrap();
|
||||
assert_eq!(v.domi_mark_revoked(SUBKEY_9, 1000).unwrap(), 1000);
|
||||
assert_eq!(v.domi_mark_revoked(SUBKEY_9, 2000).unwrap(), 1000, "the first revocation time stays");
|
||||
assert!(v.domi_issued().iter().all(|i| i.revoked_at == Some(1000)));
|
||||
|
||||
let sig = v.domi_sign_revocation(&t).unwrap();
|
||||
let vk = VerifyingKey::from_bytes(&root).unwrap();
|
||||
vk.verify_strict(&[REVOKE_DOMAIN, &t].concat(), &Signature::from_bytes(&sig)).unwrap();
|
||||
assert!(
|
||||
vk.verify_strict(&[CERT_DOMAIN, &t].concat(), &Signature::from_bytes(&sig)).is_err(),
|
||||
"not a cert signature"
|
||||
);
|
||||
|
||||
// Another time, another key, another root, a cert, garbage, the bare prefix: refused.
|
||||
for bad in [
|
||||
trv1(&root, &[9; 32], 999),
|
||||
trv1(&root, &[10; 32], 1000),
|
||||
trv1(&[1; 32], &[9; 32], 1000),
|
||||
tbs(&root),
|
||||
b"pay 100 CZK to mallory".to_vec(),
|
||||
t[..76].to_vec(),
|
||||
] {
|
||||
assert!(matches!(v.domi_sign_revocation(&bad), Err(Error::NotARevocation)), "{bad:?}");
|
||||
}
|
||||
// And the cert signer never signs a revocation.
|
||||
assert!(matches!(v.domi_sign_cert(&t), Err(Error::NotACert)));
|
||||
|
||||
// The statements are kept with every cert of the key, and survive a save.
|
||||
v.domi_record_revocation(SUBKEY_9, vec!["first".into(), "second".into()]).unwrap();
|
||||
assert!(matches!(
|
||||
v.domi_record_revocation("CgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgo", vec![]),
|
||||
Err(Error::UnknownKey)
|
||||
));
|
||||
let back = Vault::open(&v.to_bytes().unwrap(), &SecretString::from("pw")).unwrap();
|
||||
assert!(back.domi_issued().iter().all(|i| i.revoked_at == Some(1000) && i.revocation == ["first", "second"]));
|
||||
assert_eq!(back.domi_sign_revocation(&t).unwrap(), sig);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_cert_without_a_revocation_is_saved_as_before() {
|
||||
let mut v = vault();
|
||||
enrol(&mut v, [0; 32]);
|
||||
v.domi_record(issued_to(SUBKEY_9, "fiscus")).unwrap();
|
||||
let json = serde_json::to_string(&v.domi_issued()[0]).unwrap();
|
||||
assert!(!json.contains("revoked_at") && !json.contains("revocation"), "{json}");
|
||||
// And a record from core 0.7.0, without the two members, reads.
|
||||
let old: Issued = serde_json::from_str(
|
||||
r#"{"kind":"app","app_id":"fiscus","purpose":"sync","subkey":"x","label":"l","not_before":1,"not_after":2,"issued":3}"#,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!((old.revoked_at, old.revocation.len()), (None, 0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_backup_secret_matches_fundamentum() {
|
||||
use chacha20poly1305::aead::{Aead, KeyInit, Payload};
|
||||
let mut v = vault();
|
||||
enrol(&mut v, [0; 32]);
|
||||
let secret = v.domi_backup_secret("fiscus").unwrap();
|
||||
let expand = |info: &[u8]| {
|
||||
let mut out = [0u8; 32];
|
||||
hkdf::Hkdf::<sha2::Sha256>::from_prk(secret.as_ref()).unwrap().expand(info, &mut out).unwrap();
|
||||
out
|
||||
};
|
||||
// Fundamentum docs/TESSERA.md §12.
|
||||
assert_eq!(expand(b"mailbox").to_vec(), b64url("IygCOrh-ibO6-KY5AXQ9Prl2SyPWQIyZZ-anffcbMCU"));
|
||||
let key = expand(b"seal");
|
||||
let tag = chacha20poly1305::XChaCha20Poly1305::new_from_slice(&key)
|
||||
.unwrap()
|
||||
.encrypt(&chacha20poly1305::XNonce::try_from(&[0u8; 24][..]).unwrap(), Payload { msg: b"", aad: b"" })
|
||||
.unwrap();
|
||||
assert_eq!(tag, b64url("ci_JRbtsx5prR83KT9Y7LA"));
|
||||
// One per app, the same from the restored words.
|
||||
assert_ne!(*v.domi_backup_secret("calenda").unwrap(), *secret);
|
||||
let mut r = vault();
|
||||
Enrollment::restore(ZERO_PHRASE).unwrap().import(&mut r).unwrap();
|
||||
assert_eq!(*r.domi_backup_secret("fiscus").unwrap(), *secret);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -206,13 +376,19 @@ fn the_identity_surface_is_locked() {
|
||||
"identity.rs: pub fn challenge(&self) -> [usize; 3]",
|
||||
"identity.rs: pub fn confirm(self, words: &[&str; 3]) -> Result<Confirmed, (Shown, Error)>",
|
||||
"identity.rs: pub fn import(self, vault: &mut Vault) -> Result<[u8; 32], Error>",
|
||||
"identity.rs: pub fn restore(phrase: &str) -> Result<Confirmed, Error>",
|
||||
"identity.rs: pub fn show(self, display: impl FnOnce(&[&str])) -> Shown",
|
||||
"identity.rs: pub fn with_entropy(entropy: [u8; 32]) -> Enrollment",
|
||||
// The app's own backup secret, derived: by design (docs/IDENTITY.md), never the root.
|
||||
"lib.rs: pub fn domi_backup_secret(&self, app_id: &str) -> Result<Zeroizing<[u8; 32]>, Error>",
|
||||
"lib.rs: pub fn domi_created(&self) -> Option<i64>",
|
||||
"lib.rs: pub fn domi_issued(&self) -> &[identity::Issued]",
|
||||
"lib.rs: pub fn domi_mark_revoked(&mut self, subkey: &str, revoked_at: u64) -> Result<u64, Error>",
|
||||
"lib.rs: pub fn domi_record(&mut self, issued: identity::Issued) -> Result<(), Error>",
|
||||
"lib.rs: pub fn domi_record_revocation(&mut self, subkey: &str, statements: Vec<String>) -> Result<(), Error>",
|
||||
"lib.rs: pub fn domi_root_public(&self) -> Option<[u8; 32]>",
|
||||
"lib.rs: pub fn domi_sign_cert(&self, tbs: &[u8]) -> Result<[u8; 64], Error>",
|
||||
"lib.rs: pub fn domi_sign_revocation(&self, tbs: &[u8]) -> Result<[u8; 64], Error>",
|
||||
];
|
||||
want.sort();
|
||||
assert_eq!(got, want, "review the identity surface: it must never return the root secret");
|
||||
|
||||
@@ -48,21 +48,11 @@ const PHONE_APPROVAL: &[u8] = b"custos phone approval v1";
|
||||
#[derive(Deserialize)]
|
||||
#[serde(tag = "kind", rename_all = "snake_case", rename_all_fields = "camelCase")]
|
||||
enum FactorIn {
|
||||
Password {
|
||||
password: SecretString,
|
||||
},
|
||||
Password { password: SecretString },
|
||||
/// A factor service's or a device's answer, sealed to a key from `recipient` (`pub`) for `context`.
|
||||
Sealed {
|
||||
factor: FactorKind,
|
||||
r#pub: String,
|
||||
sealed: String,
|
||||
context: String,
|
||||
},
|
||||
Sealed { factor: FactorKind, r#pub: String, sealed: String, context: String },
|
||||
/// Material the page holds itself: a passkey's PRF output (base64).
|
||||
Material {
|
||||
factor: FactorKind,
|
||||
material: SecretString,
|
||||
},
|
||||
Material { factor: FactorKind, material: SecretString },
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -436,12 +426,8 @@ pub fn handle(request: &[u8]) -> Value {
|
||||
}
|
||||
Request::DomiPair { r#pub, id, label, device } => {
|
||||
let device_ok = data_encoding::BASE64URL_NOPAD.decode(device.as_bytes()).is_ok_and(|d| d.len() == 32);
|
||||
let id_ok = !id.is_empty()
|
||||
&& id.len() <= 64
|
||||
&& id.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_');
|
||||
let (Some(public), true, true) = (b64(&r#pub), device_ok, id_ok) else {
|
||||
return err("A malformed request.");
|
||||
};
|
||||
let id_ok = !id.is_empty() && id.len() <= 64 && id.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_');
|
||||
let (Some(public), true, true) = (b64(&r#pub), device_ok, id_ok) else { return err("A malformed request.") };
|
||||
let label: String = label.trim().chars().filter(|c| !c.is_control()).take(40).collect();
|
||||
let plain = json!({ "label": label, "device": device }).to_string();
|
||||
match custos_seal::seal(&public, format!("domi-pair:{id}").as_bytes(), plain.as_bytes()) {
|
||||
|
||||
@@ -17,14 +17,8 @@ fn call(v: Value) -> Value {
|
||||
/// A version-2 vault: the master password and a TOTP factor with `totp` as its material.
|
||||
fn vault(totp: &[u8]) -> Vault {
|
||||
let pw = SecretString::from(PASSWORD);
|
||||
let mut v = Vault::create_with(
|
||||
Unlock::Password(&pw),
|
||||
"Master password",
|
||||
Unlock::Material(FactorKind::Totp, totp),
|
||||
"TOTP",
|
||||
FAST,
|
||||
)
|
||||
.unwrap();
|
||||
let mut v = Vault::create_with(Unlock::Password(&pw), "Master password", Unlock::Material(FactorKind::Totp, totp), "TOTP", FAST)
|
||||
.unwrap();
|
||||
let mut login = Item::new(ItemType::WebLogin, "GitHub", 0);
|
||||
login.set("password", SECRET, 0);
|
||||
v.add(login);
|
||||
@@ -59,8 +53,7 @@ fn open_with_password_and_a_sealed_totp_release() {
|
||||
assert_eq!(me["match"], custos_seal::match_code(&public));
|
||||
// What the factor service sends back after a valid code.
|
||||
let sealed = BASE64.encode(&custos_seal::seal(&public, context.as_bytes(), &material).unwrap());
|
||||
let sealed_in =
|
||||
|ctx: &str| json!({ "kind": "sealed", "factor": "totp", "pub": me["pub"], "sealed": sealed, "context": ctx });
|
||||
let sealed_in = |ctx: &str| json!({ "kind": "sealed", "factor": "totp", "pub": me["pub"], "sealed": sealed, "context": ctx });
|
||||
let password = json!({ "kind": "password", "password": PASSWORD });
|
||||
|
||||
// Only the right context opens it.
|
||||
@@ -98,9 +91,7 @@ fn a_phone_pairs_then_opens_and_approves() {
|
||||
// The PC waits with a one-time key; the phone seals its pairing to it.
|
||||
let pc = Recipient::generate();
|
||||
let context = "pair:abc";
|
||||
let r = call(
|
||||
json!({ "op": "phone_enrol", "pub": BASE64.encode(&pc.public()), "context": context, "label": "Phone", "prf": prf64 }),
|
||||
);
|
||||
let r = call(json!({ "op": "phone_enrol", "pub": BASE64.encode(&pc.public()), "context": context, "label": "Phone", "prf": prf64 }));
|
||||
assert_eq!(r["ok"], true, "{r}");
|
||||
let sealed = BASE64.decode(r["sealed"].as_str().unwrap().as_bytes()).unwrap();
|
||||
assert_eq!(r["code"], custos_seal::sender_code(&sealed).unwrap(), "the PC checks the code the phone shows");
|
||||
@@ -114,8 +105,7 @@ fn a_phone_pairs_then_opens_and_approves() {
|
||||
|
||||
// The PC adds both factors.
|
||||
let passkey_id = v.add_factor(Unlock::Material(FactorKind::Passkey, &prf), "Phone passkey").unwrap();
|
||||
let approval_id =
|
||||
v.add_factor_apart(Unlock::Material(FactorKind::Approval, &approval), "Phone", &[&passkey_id]).unwrap();
|
||||
let approval_id = v.add_factor_apart(Unlock::Material(FactorKind::Approval, &approval), "Phone", &[&passkey_id]).unwrap();
|
||||
let file = b64(&v);
|
||||
|
||||
// The phone opens it with its passkey and the master password.
|
||||
@@ -140,18 +130,13 @@ fn a_phone_pairs_then_opens_and_approves() {
|
||||
let req_pub = BASE64.encode(&requester.public());
|
||||
assert_eq!(call(json!({ "op": "match_code", "pub": req_pub }))["match"], requester.match_code());
|
||||
let ctx = format!("approval:{approval_id}:r1");
|
||||
let wrong_key = call(
|
||||
json!({ "op": "phone_approve", "wrapped": wrapped, "prf": BASE64.encode(&[8u8; 32]), "pub": req_pub, "context": ctx }),
|
||||
);
|
||||
let wrong_key = call(json!({ "op": "phone_approve", "wrapped": wrapped, "prf": BASE64.encode(&[8u8; 32]), "pub": req_pub, "context": ctx }));
|
||||
assert_eq!(wrong_key["ok"], false);
|
||||
let r = call(json!({ "op": "phone_approve", "wrapped": wrapped, "prf": prf64, "pub": req_pub, "context": ctx }));
|
||||
let sealed = BASE64.decode(r["sealed"].as_str().unwrap().as_bytes()).unwrap();
|
||||
let m = requester.open(&sealed, ctx.as_bytes()).unwrap();
|
||||
let pw = SecretString::from(PASSWORD);
|
||||
assert!(
|
||||
Vault::open_with(&v.to_bytes().unwrap(), Unlock::Password(&pw), Unlock::Material(FactorKind::Approval, &m))
|
||||
.is_ok()
|
||||
);
|
||||
assert!(Vault::open_with(&v.to_bytes().unwrap(), Unlock::Password(&pw), Unlock::Material(FactorKind::Approval, &m)).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -159,9 +144,7 @@ fn a_phone_pairs_as_a_domi_device() {
|
||||
// The PC waits with a one-time key; the phone seals its device public key and label to it.
|
||||
let pc = Recipient::generate();
|
||||
let device = data_encoding::BASE64URL_NOPAD.encode(&[5u8; 32]);
|
||||
let r = call(
|
||||
json!({ "op": "domi_pair", "pub": BASE64.encode(&pc.public()), "id": "abc_-1", "label": " Pixel\n", "device": device }),
|
||||
);
|
||||
let r = call(json!({ "op": "domi_pair", "pub": BASE64.encode(&pc.public()), "id": "abc_-1", "label": " Pixel\n", "device": device }));
|
||||
assert_eq!(r["ok"], true, "{r}");
|
||||
let sealed = BASE64.decode(r["sealed"].as_str().unwrap().as_bytes()).unwrap();
|
||||
assert_eq!(r["code"], custos_seal::sender_code(&sealed).unwrap());
|
||||
@@ -170,16 +153,6 @@ fn a_phone_pairs_as_a_domi_device() {
|
||||
assert_eq!(plain, json!({ "label": "Pixel", "device": device }));
|
||||
// Malformed: a device key of the wrong length, an id that would change the context.
|
||||
let short = data_encoding::BASE64URL_NOPAD.encode(&[5u8; 31]);
|
||||
assert_eq!(
|
||||
call(
|
||||
json!({ "op": "domi_pair", "pub": BASE64.encode(&pc.public()), "id": "abc", "label": "x", "device": short })
|
||||
)["ok"],
|
||||
false
|
||||
);
|
||||
assert_eq!(
|
||||
call(
|
||||
json!({ "op": "domi_pair", "pub": BASE64.encode(&pc.public()), "id": "a:b", "label": "x", "device": device })
|
||||
)["ok"],
|
||||
false
|
||||
);
|
||||
assert_eq!(call(json!({ "op": "domi_pair", "pub": BASE64.encode(&pc.public()), "id": "abc", "label": "x", "device": short }))["ok"], false);
|
||||
assert_eq!(call(json!({ "op": "domi_pair", "pub": BASE64.encode(&pc.public()), "id": "a:b", "label": "x", "device": device }))["ok"], false);
|
||||
}
|
||||
|
||||
+2
-1
@@ -119,7 +119,8 @@ UTF-8 JSON, held in zeroizing buffers while being encrypted or parsed:
|
||||
- `fields` is an ordered list; a name may repeat (several `url`s). Unknown names are kept as custom fields.
|
||||
- `history` keeps the previous value of a secret field each time it changes (newest last, at most 20 per item).
|
||||
- Readers ignore JSON members they do not know, so later versions can add them.
|
||||
- `identity` (optional, core 0.7.0): the Domi identity's root key and the certs it issued (docs/IDENTITY.md).
|
||||
- `identity` (optional, core 0.7.0): the Domi identity's root key and the certs it issued (docs/IDENTITY.md);
|
||||
since core 0.10.0 a cert may carry `revoked_at` and `revocation`.
|
||||
An older Custos drops it when it saves, so every Custos that saves the vault must be 0.7.0 or later.
|
||||
- `folder` (optional item member, core 0.8.0): a list of folder names, outermost first (a KeePass group path,
|
||||
docs/KDBX.md). Absent or empty = no folder.
|
||||
|
||||
+34
-5
@@ -2,7 +2,7 @@
|
||||
|
||||
Every Domi app gets its own subkey, certified by **one root Ed25519 key per person**. The root key lives in
|
||||
the vault and never leaves it: no function of this crate returns it, and the vault signs nothing with it but
|
||||
subkey certificates. The certificate format, the match code and verification are in Fundamentum
|
||||
subkey certificates and revocations of keys the person revoked. The certificate format, the match code and verification are in Fundamentum
|
||||
(`crates/tessera`, `docs/TESSERA.md`); this page is the vault side.
|
||||
|
||||
## Creating it: the order is mandatory
|
||||
@@ -31,6 +31,12 @@ is `Clone` or `Serialize`; each prints `[redacted]`.
|
||||
Test vector: entropy `00` × 32 → `abandon` × 23 + `art` → root public key
|
||||
`vCrwX9p44un1ftQLgJtuaVQ0qPWbFfzNjgrlDkL4TKs` (base64url). Fundamentum pins the same value.
|
||||
|
||||
### Restoring it from the 24 words (core 0.10.0)
|
||||
`Enrollment::restore(phrase)` takes the whole phrase, typed back, and gives a `Confirmed`: the person typed
|
||||
all 24 words, which proves more than three. The words are checked against the BIP39 English list and its
|
||||
checksum (any case, any spacing between them); anything else is `Error::NotAMnemonic`, which names no word.
|
||||
The same words give the same root, so every app and every group trusts it again.
|
||||
|
||||
## In the vault file
|
||||
|
||||
A body member next to `items` (docs/FORMAT.md, "Body"); old vaults without it open as before:
|
||||
@@ -42,13 +48,19 @@ A body member next to `items` (docs/FORMAT.md, "Body"); old vaults without it op
|
||||
"created": 1793000000000,
|
||||
"issued": [
|
||||
{ "kind": "app", "app_id": "fiscus", "purpose": "sync", "subkey": "<base64url>", "label": "fiscus.exe",
|
||||
"not_before": 1793000000, "not_after": 1824536000, "issued": 1793000000000 }
|
||||
"not_before": 1793000000, "not_after": 1824536000, "issued": 1793000000000,
|
||||
"revoked_at": 1795000000, "revocation": ["<base64url TRV1>"] }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
- `issued` records each cert the vault signed, for *Domi identity → apps and devices*. It is a record, not
|
||||
a trust list: revocation is v1.1.
|
||||
a trust list.
|
||||
- `revoked_at` (Unix seconds, core 0.10.0) is set when the person revokes the key; `revocation` holds the
|
||||
signed statements once they exist. Both are left out until then. A renewed key has several certs: all of
|
||||
them are marked.
|
||||
- **A Custos older than core 0.10.0 drops `revoked_at` and `revocation` when it saves the vault**, so a
|
||||
revocation in progress would have to be started again.
|
||||
- **An older Custos drops the member when it saves the vault** (it ignores members it does not know). Every
|
||||
Custos that saves this vault must run core 0.7.0 or later. The mnemonic recovers the root either way.
|
||||
|
||||
@@ -59,9 +71,26 @@ A body member next to `items` (docs/FORMAT.md, "Body"); old vaults without it op
|
||||
| `Vault::domi_root_public()` | the root public key, if there is an identity |
|
||||
| `Vault::domi_sign_cert(tbs)` | Ed25519 over `"tessera cert v1\0" ‖ tbs`. Refuses a `tbs` that does not start with `TSC1` followed by this root's public key |
|
||||
| `Vault::domi_issued()`, `domi_record(issued)` | the record of issued certs |
|
||||
| `Vault::domi_mark_revoked(subkey, at)` | the person revoked this key: marks every cert of it, returns the time in effect (the first one, if it was marked before) |
|
||||
| `Vault::domi_sign_revocation(tbs)` | Ed25519 over `"tessera revoke v1\0" ‖ tbs`. Refuses a `tbs` that does not start with `TRV1`, this root's public key, a key marked revoked and that key's `revoked_at` |
|
||||
| `Vault::domi_record_revocation(subkey, statements)` | keeps the signed statements with the key's certs |
|
||||
| `Vault::domi_backup_secret(app_id)` | the app's backup secret (below) |
|
||||
|
||||
The prefix check means the vault is not a general signing oracle: whatever the app hands it, the result
|
||||
can only ever verify as a certificate naming this root.
|
||||
The prefix checks mean the vault is not a general signing oracle: whatever the app hands it, the result
|
||||
can only ever verify as a certificate naming this root, or as a revocation of a key the person revoked, at
|
||||
the time they did. The two domains differ, so neither can pass for the other. Statement format: Fundamentum
|
||||
docs/TESSERA.md §12.
|
||||
|
||||
### The backup secret (core 0.10.0)
|
||||
```
|
||||
backup secret = HKDF-SHA256(salt = "tessera backup v1", ikm = the root secret, info = app id)
|
||||
```
|
||||
Custos hands an app its own (Domi pipe `backup_key`, behind the app's namespace grant); the app seals its
|
||||
backup with it and names its backup mailbox from it (Fundamentum docs/TESSERA.md §12). It comes back from
|
||||
the 24 words alone. The caller passes a valid app id (a-z, 0-9, `-`). Test vector, shared with Fundamentum:
|
||||
the zero-entropy root, app `fiscus` → `HKDF-Expand(secret, "mailbox")` =
|
||||
`IygCOrh-ibO6-KY5AXQ9Prl2SyPWQIyZZ-anffcbMCU`, and XChaCha20-Poly1305 with
|
||||
`HKDF-Expand(secret, "seal")`, a zero nonce and empty input = `ci_JRbtsx5prR83KT9Y7LA` (the tag).
|
||||
|
||||
## What it does not protect
|
||||
|
||||
|
||||
Reference in New Issue
Block a user