[vault] Identity: restore from the 24 words, revocation signing for revoked keys only, the backup secret (docs/IDENTITY.md; v0.10.0)
This commit is contained in:
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"
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
+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