Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 23a8878f32 | |||
| 37634f0d26 | |||
| 76a94b0d11 | |||
| 4e386e8113 | |||
| 92ab8a0d63 |
Generated
+10
-10
@@ -329,7 +329,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-gen"
|
name = "custos-gen"
|
||||||
version = "0.9.0"
|
version = "0.11.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"custos-vault",
|
"custos-vault",
|
||||||
"data-encoding",
|
"data-encoding",
|
||||||
@@ -341,7 +341,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-kdbx"
|
name = "custos-kdbx"
|
||||||
version = "0.9.0"
|
version = "0.11.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes",
|
"aes",
|
||||||
"argon2",
|
"argon2",
|
||||||
@@ -362,7 +362,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-keys"
|
name = "custos-keys"
|
||||||
version = "0.9.0"
|
version = "0.11.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"custos-vault",
|
"custos-vault",
|
||||||
"ed25519-dalek",
|
"ed25519-dalek",
|
||||||
@@ -375,11 +375,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-qr"
|
name = "custos-qr"
|
||||||
version = "0.9.0"
|
version = "0.11.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-seal"
|
name = "custos-seal"
|
||||||
version = "0.9.0"
|
version = "0.11.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chacha20poly1305",
|
"chacha20poly1305",
|
||||||
"hkdf",
|
"hkdf",
|
||||||
@@ -392,7 +392,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-share"
|
name = "custos-share"
|
||||||
version = "0.9.0"
|
version = "0.11.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argon2",
|
"argon2",
|
||||||
"chacha20poly1305",
|
"chacha20poly1305",
|
||||||
@@ -409,7 +409,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-sign"
|
name = "custos-sign"
|
||||||
version = "0.9.0"
|
version = "0.11.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"blake2 0.10.6",
|
"blake2 0.10.6",
|
||||||
"data-encoding",
|
"data-encoding",
|
||||||
@@ -426,7 +426,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-totp"
|
name = "custos-totp"
|
||||||
version = "0.9.0"
|
version = "0.11.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"custos-vault",
|
"custos-vault",
|
||||||
"data-encoding",
|
"data-encoding",
|
||||||
@@ -439,7 +439,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-vault"
|
name = "custos-vault"
|
||||||
version = "0.9.0"
|
version = "0.11.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argon2",
|
"argon2",
|
||||||
"bip39",
|
"bip39",
|
||||||
@@ -463,7 +463,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-wasm"
|
name = "custos-wasm"
|
||||||
version = "0.9.0"
|
version = "0.11.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"custos-qr",
|
"custos-qr",
|
||||||
"custos-seal",
|
"custos-seal",
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ resolver = "3"
|
|||||||
members = ["crates/*"]
|
members = ["crates/*"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.9.0"
|
version = "0.11.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
repository = "https://gitea.marek-novak.cz/mnovak/CustosPublic"
|
repository = "https://gitea.marek-novak.cz/mnovak/CustosPublic"
|
||||||
|
|||||||
@@ -52,7 +52,9 @@ fn random<const N: usize>() -> Zeroizing<[u8; N]> {
|
|||||||
|
|
||||||
fn derive(ikm: &[u8], salt: &[u8], info: &[&[u8]]) -> Zeroizing<[u8; 32]> {
|
fn derive(ikm: &[u8], salt: &[u8], info: &[&[u8]]) -> Zeroizing<[u8; 32]> {
|
||||||
let mut k = Zeroizing::new([0u8; 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
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,8 +66,8 @@ fn xnonce(n: &[u8]) -> XNonce {
|
|||||||
XNonce::try_from(n).expect("24-byte nonce")
|
XNonce::try_from(n).expect("24-byte nonce")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The one-time key pair of a device waiting for a secret. Its secret half never leaves memory and is
|
/// The one-time key pair of a device waiting for a secret. Its secret half is wiped on drop and leaves
|
||||||
/// wiped on drop.
|
/// memory only through `secret_bytes`, for a caller that keeps a long-lived key (`from_secret`).
|
||||||
pub struct Recipient {
|
pub struct Recipient {
|
||||||
secret: StaticSecret,
|
secret: StaticSecret,
|
||||||
public: [u8; 32],
|
public: [u8; 32],
|
||||||
@@ -78,6 +80,30 @@ impl Recipient {
|
|||||||
Recipient { secret, public }
|
Recipient { secret, public }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A long-lived key the caller kept (docs/SEAL.md, "A kept key"): the PC's Provisio sealing key, stored
|
||||||
|
/// DPAPI-sealed and restored at start. Refuses a secret everyone knows: one that clamps to zero (a
|
||||||
|
/// wiped or never-filled buffer), and, as `seal` does for a public key, one whose shared secrets would
|
||||||
|
/// not be contributory.
|
||||||
|
pub fn from_secret(secret: Zeroizing<[u8; 32]>) -> Result<Recipient, SealError> {
|
||||||
|
let secret = StaticSecret::from(*secret);
|
||||||
|
let public = PublicKey::from(&secret).to_bytes();
|
||||||
|
let zero = PublicKey::from(&StaticSecret::from([0u8; 32])).to_bytes();
|
||||||
|
if public == zero {
|
||||||
|
return Err(SealError::BadKey);
|
||||||
|
}
|
||||||
|
let probe = StaticSecret::from(*random::<32>());
|
||||||
|
if !probe.diffie_hellman(&PublicKey::from(public)).was_contributory() {
|
||||||
|
return Err(SealError::BadKey);
|
||||||
|
}
|
||||||
|
Ok(Recipient { secret, public })
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The secret half, for a caller that keeps this key (sealed with DPAPI or the like) instead of
|
||||||
|
/// dropping it after one box. One-time keys never call this.
|
||||||
|
pub fn secret_bytes(&self) -> Zeroizing<[u8; 32]> {
|
||||||
|
Zeroizing::new(self.secret.to_bytes())
|
||||||
|
}
|
||||||
|
|
||||||
/// What the device sends: 32 bytes.
|
/// What the device sends: 32 bytes.
|
||||||
pub fn public(&self) -> [u8; 32] {
|
pub fn public(&self) -> [u8; 32] {
|
||||||
self.public
|
self.public
|
||||||
@@ -109,7 +135,7 @@ impl Recipient {
|
|||||||
|
|
||||||
impl std::fmt::Debug for Recipient {
|
impl std::fmt::Debug for Recipient {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "Recipient {{ match_code: {} }}", self.match_code())
|
write!(f, "Recipient {{ match_code: {}, secret: [redacted] }}", self.match_code())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,3 +72,47 @@ fn at_rest_seals_open_with_the_same_key_and_context_only() {
|
|||||||
assert_eq!(open_at_rest(&key, b"totp:f2", &b), Err(SealError::Rejected));
|
assert_eq!(open_at_rest(&key, b"totp:f2", &b), Err(SealError::Rejected));
|
||||||
assert_eq!(open_at_rest(&key, b"totp:f1", b"CSR1"), Err(SealError::Malformed));
|
assert_eq!(open_at_rest(&key, b"totp:f1", b"CSR1"), Err(SealError::Malformed));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_kept_recipient_comes_back_from_its_secret() {
|
||||||
|
// The PC keeps its Provisio sealing key (DPAPI-sealed) and restores it at the next start.
|
||||||
|
let r = Recipient::generate();
|
||||||
|
let kept = r.secret_bytes();
|
||||||
|
let back = Recipient::from_secret(kept).unwrap();
|
||||||
|
assert_eq!(back.public(), r.public());
|
||||||
|
assert_eq!(back.match_code(), r.match_code());
|
||||||
|
assert_eq!(back.secret_bytes().as_slice(), r.secret_bytes().as_slice());
|
||||||
|
// A box sealed to the original opens with the restored key, for its purpose only.
|
||||||
|
let ctx = b"provision-offer:vault:fabrica/gitea-read-token";
|
||||||
|
let b = seal(&r.public(), ctx, b"gitea token").unwrap();
|
||||||
|
assert_eq!(back.open(&b, ctx).unwrap().as_slice(), b"gitea token");
|
||||||
|
assert_eq!(back.open(&b, b"provision-offer:vault:fabrica/other"), Err(SealError::Rejected));
|
||||||
|
// Another kept key does not open it.
|
||||||
|
let other = Recipient::from_secret(Recipient::generate().secret_bytes()).unwrap();
|
||||||
|
assert_eq!(other.open(&b, ctx), Err(SealError::Rejected));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_known_secret_is_refused() {
|
||||||
|
// All zeros (a wiped or never-filled buffer) is a key everyone knows, and so is anything that clamps to it.
|
||||||
|
assert_eq!(Recipient::from_secret(zeroize::Zeroizing::new([0u8; 32])).unwrap_err(), SealError::BadKey);
|
||||||
|
let mut clamps_to_zero = [0u8; 32];
|
||||||
|
clamps_to_zero[0] = 0b0000_0111;
|
||||||
|
clamps_to_zero[31] = 0b1000_0000;
|
||||||
|
assert_eq!(Recipient::from_secret(zeroize::Zeroizing::new(clamps_to_zero)).unwrap_err(), SealError::BadKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_kept_recipient_prints_redacted() {
|
||||||
|
let r = Recipient::generate();
|
||||||
|
let secret = r.secret_bytes();
|
||||||
|
let back = Recipient::from_secret(secret.clone()).unwrap();
|
||||||
|
for shown in [format!("{r:?}"), format!("{back:?}"), format!("{back:#?}")] {
|
||||||
|
assert!(shown.contains("[redacted]"), "{shown}");
|
||||||
|
assert!(!shown.contains(&format!("{:?}", *secret)));
|
||||||
|
assert!(!shown.contains(&format!("{:?}", &secret[..8])));
|
||||||
|
let hex: String = secret.iter().map(|b| format!("{b:02x}")).collect();
|
||||||
|
assert!(!shown.contains(&hex[..16]));
|
||||||
|
assert!(!shown.contains(&format!("{:?}", back.public())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
//! The Domi identity's root key (docs/IDENTITY.md). It lives in the vault body and never leaves it: nothing
|
//! 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:
|
//! 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`.
|
/// 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_DOMAIN: &[u8] = b"tessera cert v1\0";
|
||||||
const CERT_MAGIC: &[u8] = b"TSC1";
|
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;
|
const WORDS: usize = 24;
|
||||||
|
|
||||||
/// Step 1: fresh entropy. Nothing is derived from it until the words have been shown.
|
/// Step 1: fresh entropy. Nothing is derived from it until the words have been shown.
|
||||||
@@ -111,6 +119,26 @@ impl Enrollment {
|
|||||||
display(&words);
|
display(&words);
|
||||||
Shown { entropy: self.entropy, challenge: random_challenge() }
|
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 {
|
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.
|
/// 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 {
|
pub struct Issued {
|
||||||
/// `app` or `device`.
|
/// `app` or `device`.
|
||||||
pub kind: String,
|
pub kind: String,
|
||||||
@@ -180,6 +208,12 @@ pub struct Issued {
|
|||||||
pub not_after: u64,
|
pub not_after: u64,
|
||||||
/// Unix milliseconds.
|
/// Unix milliseconds.
|
||||||
pub issued: i64,
|
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.
|
/// The identity in an unlocked vault.
|
||||||
@@ -212,6 +246,45 @@ impl Root {
|
|||||||
Ok(crypto::ed25519_sign(&self.secret, &msg))
|
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 {
|
pub(crate) fn json(&self) -> RootJson {
|
||||||
RootJson {
|
RootJson {
|
||||||
root: SecretString::new(hex(self.secret.as_ref())),
|
root: SecretString::new(hex(self.secret.as_ref())),
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ mod device;
|
|||||||
mod format;
|
mod format;
|
||||||
pub mod identity;
|
pub mod identity;
|
||||||
mod item;
|
mod item;
|
||||||
|
pub mod provision;
|
||||||
mod save;
|
mod save;
|
||||||
mod secret;
|
mod secret;
|
||||||
pub mod signing;
|
pub mod signing;
|
||||||
@@ -71,8 +72,17 @@ pub enum Error {
|
|||||||
NotACert,
|
NotACert,
|
||||||
#[error("those words are not the ones in the recovery phrase")]
|
#[error("those words are not the ones in the recovery phrase")]
|
||||||
WrongWords,
|
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")]
|
#[error("this vault already has {0} signing keys")]
|
||||||
SigningExists(&'static str),
|
SigningExists(&'static str),
|
||||||
|
/// Names the member that does not fit (docs/FORMAT.md), never its value.
|
||||||
|
#[error("provision audit: {0}")]
|
||||||
|
Provision(&'static str),
|
||||||
#[error("signing keys: {0}")]
|
#[error("signing keys: {0}")]
|
||||||
Signing(String),
|
Signing(String),
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
@@ -268,6 +278,8 @@ struct Body {
|
|||||||
identity: Option<identity::RootJson>,
|
identity: Option<identity::RootJson>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
signing: Option<signing::StoreJson>,
|
signing: Option<signing::StoreJson>,
|
||||||
|
#[serde(default)]
|
||||||
|
provision: Option<provision::ProvisionJson>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// What `to_bytes` serializes: borrows the items instead of cloning every secret.
|
/// What `to_bytes` serializes: borrows the items instead of cloning every secret.
|
||||||
@@ -281,6 +293,8 @@ struct BodyRef<'a> {
|
|||||||
identity: Option<identity::RootJson>,
|
identity: Option<identity::RootJson>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
signing: Option<signing::StoreJson>,
|
signing: Option<signing::StoreJson>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
provision: Option<provision::ProvisionJson>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An unlocked vault: the vault key and the decrypted items, both wiped on drop.
|
/// An unlocked vault: the vault key and the decrypted items, both wiped on drop.
|
||||||
@@ -297,6 +311,8 @@ pub struct Vault {
|
|||||||
identity: Option<identity::Root>,
|
identity: Option<identity::Root>,
|
||||||
/// Signing keys and their audit log (docs/SIGNING.md); no key is ever handed out.
|
/// Signing keys and their audit log (docs/SIGNING.md); no key is ever handed out.
|
||||||
signing: signing::Store,
|
signing: signing::Store,
|
||||||
|
/// The Provisio audit (docs/FORMAT.md), oldest first.
|
||||||
|
provision: Vec<provision::ProvisionEntry>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Vault {
|
impl fmt::Debug for Vault {
|
||||||
@@ -397,6 +413,7 @@ impl Vault {
|
|||||||
kdf_new: kdf,
|
kdf_new: kdf,
|
||||||
identity: None,
|
identity: None,
|
||||||
signing: signing::Store::default(),
|
signing: signing::Store::default(),
|
||||||
|
provision: Vec::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,6 +431,7 @@ impl Vault {
|
|||||||
kdf_new: kdf,
|
kdf_new: kdf,
|
||||||
identity: None,
|
identity: None,
|
||||||
signing: signing::Store::default(),
|
signing: signing::Store::default(),
|
||||||
|
provision: Vec::new(),
|
||||||
};
|
};
|
||||||
v.add_factor(a, label_a)?;
|
v.add_factor(a, label_a)?;
|
||||||
v.add_factor(b, label_b)?;
|
v.add_factor(b, label_b)?;
|
||||||
@@ -447,6 +465,7 @@ impl Vault {
|
|||||||
kdf_new: KdfParams::DEFAULT,
|
kdf_new: KdfParams::DEFAULT,
|
||||||
identity: None,
|
identity: None,
|
||||||
signing: signing::Store::default(),
|
signing: signing::Store::default(),
|
||||||
|
provision: Vec::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -581,6 +600,7 @@ impl Vault {
|
|||||||
kdf_new,
|
kdf_new,
|
||||||
identity,
|
identity,
|
||||||
signing,
|
signing,
|
||||||
|
provision: provision::from_json(body.provision),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -616,6 +636,7 @@ impl Vault {
|
|||||||
factors: self.factors.iter().map(FactorRec::json).collect(),
|
factors: self.factors.iter().map(FactorRec::json).collect(),
|
||||||
identity: self.identity.as_ref().map(identity::Root::json),
|
identity: self.identity.as_ref().map(identity::Root::json),
|
||||||
signing: self.signing.json(),
|
signing: self.signing.json(),
|
||||||
|
provision: provision::json(&self.provision),
|
||||||
};
|
};
|
||||||
serde_json::to_writer(&mut *json, &body).map_err(|e| Error::Io(std::io::Error::other(e.to_string())))?;
|
serde_json::to_writer(&mut *json, &body).map_err(|e| Error::Io(std::io::Error::other(e.to_string())))?;
|
||||||
let sealed = crypto::seal(&self.key, &body_nonce, &json, &out);
|
let sealed = crypto::seal(&self.key, &body_nonce, &json, &out);
|
||||||
@@ -828,4 +849,27 @@ impl Vault {
|
|||||||
self.identity.as_mut().ok_or(Error::NoIdentity)?.issued.push(issued);
|
self.identity.as_mut().ok_or(Error::NoIdentity)?.issued.push(issued);
|
||||||
Ok(())
|
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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,218 @@
|
|||||||
|
//! The Provisio audit (docs/FORMAT.md, "The provision audit"): the vault body member `provision`, beside
|
||||||
|
//! signing's audit. One entry per outcome of a server's ask or offer. An entry holds no secret: every member is
|
||||||
|
//! something the server sent in the clear through the mailbox, or the match code of a public key.
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::{Error, Vault};
|
||||||
|
|
||||||
|
/// The log keeps the newest this many entries.
|
||||||
|
pub const AUDIT_LIMIT: usize = 5_000;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
|
pub enum Direction {
|
||||||
|
/// The server asked Custos for a secret (or asked it to make one).
|
||||||
|
Ask,
|
||||||
|
/// The server offered a secret it made.
|
||||||
|
Offer,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
|
pub enum Store {
|
||||||
|
/// A Domi-ref item in the vault.
|
||||||
|
Vault,
|
||||||
|
/// The local Claude Code store.
|
||||||
|
Claude,
|
||||||
|
/// The cloud Claude Code store.
|
||||||
|
Cloud,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "kebab-case")]
|
||||||
|
pub enum Outcome {
|
||||||
|
/// Ask: Mark approved; the item's value was sealed to the request.
|
||||||
|
Approved,
|
||||||
|
/// Ask with `--generate`: Custos made the item, stored it and sealed it to the request.
|
||||||
|
Generated,
|
||||||
|
/// Offer: Mark accepted; the value was stored.
|
||||||
|
Accepted,
|
||||||
|
/// Mark refused on the card.
|
||||||
|
Refused,
|
||||||
|
/// Outside the scope: refused before a card, or again when storing.
|
||||||
|
OutOfScope,
|
||||||
|
/// An offer's box did not match the offer (item, store, kind or code key), or did not open.
|
||||||
|
Invalid,
|
||||||
|
/// Nobody answered within five minutes.
|
||||||
|
Expired,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One audit entry. Append-only: nothing edits or removes one.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct ProvisionEntry {
|
||||||
|
/// Unix milliseconds.
|
||||||
|
pub at: i64,
|
||||||
|
pub direction: Direction,
|
||||||
|
/// The name the factor service gave the server.
|
||||||
|
pub host: String,
|
||||||
|
pub item: String,
|
||||||
|
pub store: Store,
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
pub run: Option<String>,
|
||||||
|
/// An offer's label (`--kind`), or an ask's `--generate` recipe.
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
pub kind: Option<String>,
|
||||||
|
/// The match code both screens showed: six digits.
|
||||||
|
pub code: String,
|
||||||
|
pub outcome: Outcome,
|
||||||
|
/// An accepted offer replaced an existing item.
|
||||||
|
#[serde(default)]
|
||||||
|
pub replaced: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The body member: `{"audit": [...]}`.
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub(crate) struct ProvisionJson {
|
||||||
|
#[serde(default)]
|
||||||
|
audit: Vec<ProvisionEntry>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The log as the vault keeps it, oldest first.
|
||||||
|
pub(crate) fn from_json(j: Option<ProvisionJson>) -> Vec<ProvisionEntry> {
|
||||||
|
let mut audit = j.map(|j| j.audit).unwrap_or_default();
|
||||||
|
trim(&mut audit);
|
||||||
|
audit
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Absent while the log is empty, so a vault without entries is written exactly as before.
|
||||||
|
pub(crate) fn json(audit: &[ProvisionEntry]) -> Option<ProvisionJson> {
|
||||||
|
(!audit.is_empty()).then(|| ProvisionJson { audit: audit.to_vec() })
|
||||||
|
}
|
||||||
|
|
||||||
|
fn trim(audit: &mut Vec<ProvisionEntry>) {
|
||||||
|
if audit.len() > AUDIT_LIMIT {
|
||||||
|
audit.drain(..audit.len() - AUDIT_LIMIT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `^[a-z0-9][a-z0-9._-]{0,63}(/[a-z0-9][a-z0-9._-]{0,63}){0,3}$`, as the factor service checks an item.
|
||||||
|
fn item_ok(item: &str) -> bool {
|
||||||
|
let parts: Vec<&str> = item.split('/').collect();
|
||||||
|
parts.len() <= 4
|
||||||
|
&& parts.iter().all(|p| {
|
||||||
|
let b = p.as_bytes();
|
||||||
|
(1..=64).contains(&b.len())
|
||||||
|
&& (b[0].is_ascii_lowercase() || b[0].is_ascii_digit())
|
||||||
|
&& b.iter().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || b"._-".contains(c))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ProvisionEntry {
|
||||||
|
/// Whether every member fits docs/FORMAT.md. The error names the member, never its value.
|
||||||
|
pub fn check(&self) -> Result<(), Error> {
|
||||||
|
let host = self.host.as_bytes();
|
||||||
|
if !(1..=253).contains(&host.len()) || !host.iter().all(|c| c.is_ascii_alphanumeric() || b".-".contains(c)) {
|
||||||
|
return Err(Error::Provision("the host is not a host name"));
|
||||||
|
}
|
||||||
|
if !item_ok(&self.item) {
|
||||||
|
return Err(Error::Provision("the item is not an item name"));
|
||||||
|
}
|
||||||
|
if let Some(run) = &self.run {
|
||||||
|
let r = run.as_bytes();
|
||||||
|
if !(1..=64).contains(&r.len()) || !r.iter().all(|c| c.is_ascii_alphanumeric() || b"._-".contains(c)) {
|
||||||
|
return Err(Error::Provision("the run is not a run id"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(kind) = &self.kind
|
||||||
|
&& (kind.chars().count() > 200 || kind.chars().any(char::is_control))
|
||||||
|
{
|
||||||
|
return Err(Error::Provision("the kind is longer than 200 characters or has control characters"));
|
||||||
|
}
|
||||||
|
if self.code.len() != 6 || !self.code.bytes().all(|c| c.is_ascii_digit()) {
|
||||||
|
return Err(Error::Provision("the match code is not six digits"));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Vault {
|
||||||
|
/// Records one outcome, after `ProvisionEntry::check`. Beyond `AUDIT_LIMIT` entries the oldest goes. The
|
||||||
|
/// caller saves.
|
||||||
|
pub fn provision_record(&mut self, entry: ProvisionEntry) -> Result<(), Error> {
|
||||||
|
entry.check()?;
|
||||||
|
self.provision.push(entry);
|
||||||
|
trim(&mut self.provision);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Every outcome, oldest first (newest last).
|
||||||
|
pub fn provision_audit(&self) -> &[ProvisionEntry] {
|
||||||
|
&self.provision
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
//! An older reader still opens a vault with the member. It lives here because only the crate can decrypt the
|
||||||
|
//! body and parse it the way core 0.10.0 did.
|
||||||
|
use super::*;
|
||||||
|
use crate::format::Header;
|
||||||
|
use crate::{FactorJson, Item, ItemType, KdfParams, SecretString, crypto, identity, signing};
|
||||||
|
|
||||||
|
/// The body as core 0.10.0 parsed it (src/lib.rs `Body` at v0.10.0): no `provision`.
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
|
struct BodyV0_10 {
|
||||||
|
format: u32,
|
||||||
|
items: Vec<Item>,
|
||||||
|
#[serde(default)]
|
||||||
|
factors: Vec<FactorJson>,
|
||||||
|
#[serde(default)]
|
||||||
|
identity: Option<identity::RootJson>,
|
||||||
|
#[serde(default)]
|
||||||
|
signing: Option<signing::StoreJson>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn body_json(v: &Vault) -> String {
|
||||||
|
let bytes = v.to_bytes().unwrap();
|
||||||
|
let (header, at) = Header::parse(&bytes).unwrap();
|
||||||
|
let json = crypto::open(&v.key, &header.body_nonce, &bytes[at..], &bytes[..at]).unwrap();
|
||||||
|
String::from_utf8(json.to_vec()).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn entry() -> ProvisionEntry {
|
||||||
|
ProvisionEntry {
|
||||||
|
at: 1_793_750_000_000,
|
||||||
|
direction: Direction::Offer,
|
||||||
|
host: "nixos-vm".into(),
|
||||||
|
item: "arca/gitea-read-token".into(),
|
||||||
|
store: Store::Vault,
|
||||||
|
run: None,
|
||||||
|
kind: Some("Gitea token, read:repository".into()),
|
||||||
|
code: "684361".into(),
|
||||||
|
outcome: Outcome::Accepted,
|
||||||
|
replaced: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn an_older_reader_opens_a_vault_with_the_provision_audit() {
|
||||||
|
let mut v =
|
||||||
|
Vault::create(&SecretString::from("pw"), KdfParams { m_cost_kib: 64, t_cost: 1, p_cost: 1 }).unwrap();
|
||||||
|
v.add(Item::new(ItemType::SecureNote, "kept", 1));
|
||||||
|
// Without entries the body has no trace of the member, so it is byte-for-byte what 0.10.0 wrote.
|
||||||
|
assert!(!body_json(&v).contains("provision"));
|
||||||
|
|
||||||
|
v.provision_record(entry()).unwrap();
|
||||||
|
let json = body_json(&v);
|
||||||
|
assert!(json.contains(r#""provision":{"audit":[{"#), "{json}");
|
||||||
|
// Core 0.10.0's parser takes it and keeps everything it knows.
|
||||||
|
let old: BodyV0_10 = serde_json::from_str(&json).unwrap();
|
||||||
|
assert_eq!(old.format, 1);
|
||||||
|
assert_eq!(old.items.len(), 1);
|
||||||
|
assert_eq!(old.items[0].title, "kept");
|
||||||
|
assert!(old.identity.is_none() && old.signing.is_none());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -128,6 +128,8 @@ fn the_identity_survives_saving_in_both_versions() {
|
|||||||
not_before: 1,
|
not_before: 1,
|
||||||
not_after: 2,
|
not_after: 2,
|
||||||
issued: 3,
|
issued: 3,
|
||||||
|
revoked_at: Some(4),
|
||||||
|
revocation: vec!["VFJWMQ".into()],
|
||||||
};
|
};
|
||||||
// Version 1.
|
// Version 1.
|
||||||
let mut v = vault();
|
let mut v = vault();
|
||||||
@@ -165,8 +167,176 @@ fn a_record_needs_an_identity() {
|
|||||||
not_before: 0,
|
not_before: 0,
|
||||||
not_after: 1,
|
not_after: 1,
|
||||||
issued: 0,
|
issued: 0,
|
||||||
|
..Issued::default()
|
||||||
};
|
};
|
||||||
assert!(matches!(v.domi_record(i), Err(Error::NoIdentity)));
|
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]
|
#[test]
|
||||||
@@ -206,13 +376,19 @@ fn the_identity_surface_is_locked() {
|
|||||||
"identity.rs: pub fn challenge(&self) -> [usize; 3]",
|
"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 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 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 show(self, display: impl FnOnce(&[&str])) -> Shown",
|
||||||
"identity.rs: pub fn with_entropy(entropy: [u8; 32]) -> Enrollment",
|
"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_created(&self) -> Option<i64>",
|
||||||
"lib.rs: pub fn domi_issued(&self) -> &[identity::Issued]",
|
"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(&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_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_cert(&self, tbs: &[u8]) -> Result<[u8; 64], Error>",
|
||||||
|
"lib.rs: pub fn domi_sign_revocation(&self, tbs: &[u8]) -> Result<[u8; 64], Error>",
|
||||||
];
|
];
|
||||||
want.sort();
|
want.sort();
|
||||||
assert_eq!(got, want, "review the identity surface: it must never return the root secret");
|
assert_eq!(got, want, "review the identity surface: it must never return the root secret");
|
||||||
|
|||||||
@@ -0,0 +1,158 @@
|
|||||||
|
//! Mandatory tests for the Provisio audit (docs/FORMAT.md, "The provision audit"): it survives a reopen, takes
|
||||||
|
//! only entries that fit, is append-only and bounded, and has no member that could hold a secret. That an older
|
||||||
|
//! reader still opens such a vault is a unit test in src/provision.rs, which can see the decrypted body.
|
||||||
|
|
||||||
|
use custos_vault::provision::{AUDIT_LIMIT, Direction, Outcome, ProvisionEntry, Store};
|
||||||
|
use custos_vault::{Error, KdfParams, SecretString, Vault};
|
||||||
|
|
||||||
|
const FAST: KdfParams = KdfParams { m_cost_kib: 64, t_cost: 1, p_cost: 1 };
|
||||||
|
const NOW: i64 = 1_793_750_000_000;
|
||||||
|
|
||||||
|
/// One way to spoil an entry.
|
||||||
|
type Change = Box<dyn Fn(&mut ProvisionEntry)>;
|
||||||
|
|
||||||
|
fn entry(i: i64, outcome: Outcome) -> ProvisionEntry {
|
||||||
|
ProvisionEntry {
|
||||||
|
at: NOW + i,
|
||||||
|
direction: Direction::Offer,
|
||||||
|
host: "nixos-vm".into(),
|
||||||
|
item: "fabrica/gitea-read-token".into(),
|
||||||
|
store: Store::Vault,
|
||||||
|
run: Some("deploy-7".into()),
|
||||||
|
kind: Some("Gitea token, read:repository".into()),
|
||||||
|
code: "684361".into(),
|
||||||
|
outcome,
|
||||||
|
replaced: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_provision_audit_records_every_outcome_and_survives_a_reopen() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let path = dir.path().join("v.custos");
|
||||||
|
let mut v = Vault::create(&SecretString::from("pw"), FAST).unwrap();
|
||||||
|
assert!(v.provision_audit().is_empty());
|
||||||
|
let all = [
|
||||||
|
Outcome::Approved,
|
||||||
|
Outcome::Generated,
|
||||||
|
Outcome::Accepted,
|
||||||
|
Outcome::Refused,
|
||||||
|
Outcome::OutOfScope,
|
||||||
|
Outcome::Invalid,
|
||||||
|
Outcome::Expired,
|
||||||
|
];
|
||||||
|
for (i, o) in all.iter().enumerate() {
|
||||||
|
let mut e = entry(i as i64, *o);
|
||||||
|
if i % 2 == 0 {
|
||||||
|
e.direction = Direction::Ask;
|
||||||
|
e.store = Store::Vault;
|
||||||
|
e.kind = None;
|
||||||
|
e.run = None;
|
||||||
|
} else {
|
||||||
|
e.store = if i % 3 == 0 { Store::Claude } else { Store::Cloud };
|
||||||
|
e.item = "fabrica-hub-token".into();
|
||||||
|
}
|
||||||
|
e.replaced = *o == Outcome::Accepted;
|
||||||
|
v.provision_record(e).unwrap();
|
||||||
|
}
|
||||||
|
v.save(&path).unwrap();
|
||||||
|
|
||||||
|
let back = Vault::open_file(&path, &SecretString::from("pw")).unwrap();
|
||||||
|
let audit: &[ProvisionEntry] = back.provision_audit();
|
||||||
|
assert_eq!(audit, v.provision_audit());
|
||||||
|
assert_eq!(audit.iter().map(|e| e.outcome).collect::<Vec<_>>(), all);
|
||||||
|
// Newest last.
|
||||||
|
assert!(audit.windows(2).all(|w| w[0].at < w[1].at));
|
||||||
|
assert_eq!(audit[0].direction, Direction::Ask);
|
||||||
|
assert_eq!(audit[1].store, Store::Cloud);
|
||||||
|
assert_eq!(audit[3].store, Store::Claude);
|
||||||
|
assert!(audit[2].replaced && !audit[1].replaced);
|
||||||
|
// The signing audit is a separate log and stays empty.
|
||||||
|
assert!(back.signing_audit().is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn entries_that_do_not_fit_are_refused_and_not_stored() {
|
||||||
|
let mut v = Vault::create(&SecretString::from("pw"), FAST).unwrap();
|
||||||
|
v.provision_record(entry(0, Outcome::Approved)).unwrap();
|
||||||
|
let secretish = "ghp_s3cr3tV4lu3ThatMustNeverBeInAnError";
|
||||||
|
let bad: Vec<Change> = vec![
|
||||||
|
Box::new(|e| e.code = "68436".into()),
|
||||||
|
Box::new(|e| e.code = "68436a".into()),
|
||||||
|
Box::new(|e| e.code = "6843611".into()),
|
||||||
|
Box::new(|e| e.item = "Arca/x".into()),
|
||||||
|
Box::new(|e| e.item = "../x".into()),
|
||||||
|
Box::new(|e| e.item = "a/b/c/d/e".into()),
|
||||||
|
Box::new(|e| e.item = String::new()),
|
||||||
|
Box::new(|e| e.item = format!("arca/{}", "x".repeat(65))),
|
||||||
|
Box::new(|e| e.run = Some(String::new())),
|
||||||
|
Box::new(|e| e.run = Some("run 1".into())),
|
||||||
|
Box::new(|e| e.run = Some("r".repeat(65))),
|
||||||
|
Box::new(|e| e.host = String::new()),
|
||||||
|
Box::new(|e| e.host = "nixos vm".into()),
|
||||||
|
Box::new(|e| e.host = "h".repeat(254)),
|
||||||
|
Box::new(|e| e.kind = Some("x".repeat(201))),
|
||||||
|
Box::new(move |e| e.kind = Some(format!("token\n{secretish}"))),
|
||||||
|
];
|
||||||
|
for (i, change) in bad.iter().enumerate() {
|
||||||
|
let mut e = entry(1, Outcome::Accepted);
|
||||||
|
change(&mut e);
|
||||||
|
let err = v.provision_record(e).unwrap_err();
|
||||||
|
assert!(matches!(err, Error::Provision(_)), "case {i}: {err:?}");
|
||||||
|
assert!(!format!("{err}{err:?}").contains(secretish), "case {i}: an error repeats a value");
|
||||||
|
}
|
||||||
|
assert_eq!(v.provision_audit(), [entry(0, Outcome::Approved)]);
|
||||||
|
// The limits themselves fit.
|
||||||
|
let mut e = entry(2, Outcome::Accepted);
|
||||||
|
e.item = format!("a{0}/b{0}/c{0}/d{0}", "x".repeat(63));
|
||||||
|
e.run = Some("R".repeat(64));
|
||||||
|
e.host = "h".repeat(253);
|
||||||
|
e.kind = Some("k".repeat(200));
|
||||||
|
v.provision_record(e).unwrap();
|
||||||
|
assert_eq!(v.provision_audit().len(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_audit_is_append_only_and_keeps_the_newest_entries() {
|
||||||
|
let mut v = Vault::create(&SecretString::from("pw"), FAST).unwrap();
|
||||||
|
v.provision_record(entry(0, Outcome::Refused)).unwrap();
|
||||||
|
let before = v.provision_audit().to_vec();
|
||||||
|
v.provision_record(entry(1, Outcome::Accepted)).unwrap();
|
||||||
|
// Recording appends; what was there is unchanged.
|
||||||
|
assert_eq!(&v.provision_audit()[..1], before.as_slice());
|
||||||
|
assert_eq!(v.provision_audit()[1], entry(1, Outcome::Accepted));
|
||||||
|
|
||||||
|
assert_eq!(AUDIT_LIMIT, 5_000);
|
||||||
|
for i in 2..(AUDIT_LIMIT as i64 + 3) {
|
||||||
|
v.provision_record(entry(i, Outcome::Expired)).unwrap();
|
||||||
|
}
|
||||||
|
let audit = v.provision_audit();
|
||||||
|
assert_eq!(audit.len(), AUDIT_LIMIT);
|
||||||
|
// The three oldest went; the newest is last.
|
||||||
|
assert_eq!(audit[0].at, NOW + 3);
|
||||||
|
assert_eq!(audit.last().unwrap().at, NOW + AUDIT_LIMIT as i64 + 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn an_entry_has_no_member_that_could_hold_a_secret() {
|
||||||
|
// Every member, with every option set: the JSON has exactly these names and nothing like a value.
|
||||||
|
let mut e = entry(0, Outcome::Accepted);
|
||||||
|
e.replaced = true;
|
||||||
|
let json: serde_json::Value = serde_json::to_value(&e).unwrap();
|
||||||
|
let mut names: Vec<&str> = json.as_object().unwrap().keys().map(String::as_str).collect();
|
||||||
|
names.sort();
|
||||||
|
assert_eq!(names, ["at", "code", "direction", "host", "item", "kind", "outcome", "replaced", "run", "store"]);
|
||||||
|
for v in json.as_object().unwrap().values() {
|
||||||
|
assert!(!v.is_object() && !v.is_array(), "no nested member to hide a value in");
|
||||||
|
}
|
||||||
|
assert_eq!(
|
||||||
|
serde_json::to_string(&e).unwrap(),
|
||||||
|
r#"{"at":1793750000000,"direction":"offer","host":"nixos-vm","item":"fabrica/gitea-read-token","store":"vault","run":"deploy-7","kind":"Gitea token, read:repository","code":"684361","outcome":"accepted","replaced":true}"#
|
||||||
|
);
|
||||||
|
// The options are left out when absent; the outcomes are spelled as docs/FORMAT.md says.
|
||||||
|
let mut e = entry(0, Outcome::OutOfScope);
|
||||||
|
e.run = None;
|
||||||
|
e.kind = None;
|
||||||
|
let s = serde_json::to_string(&e).unwrap();
|
||||||
|
assert!(!s.contains("\"run\"") && !s.contains("\"kind\"") && s.contains("\"out-of-scope\""), "{s}");
|
||||||
|
}
|
||||||
+38
-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.
|
- `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).
|
- `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.
|
- 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.
|
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,
|
- `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.
|
docs/KDBX.md). Absent or empty = no folder.
|
||||||
@@ -128,6 +129,42 @@ UTF-8 JSON, held in zeroizing buffers while being encrypted or parsed:
|
|||||||
An older Custos drops `folder` and `attachments` when it saves.
|
An older Custos drops `folder` and `attachments` when it saves.
|
||||||
- `signing` (optional, core 0.9.0): signing keys for releases and the audit log of every signing request
|
- `signing` (optional, core 0.9.0): signing keys for releases and the audit log of every signing request
|
||||||
(docs/SIGNING.md). An older Custos drops it when it saves, so every Custos that saves the vault must be 0.9.0 or later.
|
(docs/SIGNING.md). An older Custos drops it when it saves, so every Custos that saves the vault must be 0.9.0 or later.
|
||||||
|
- `provision` (optional, core 0.11.0): the Provisio audit, every outcome of a server's *ask* or *offer* (the app's
|
||||||
|
docs/10_provisio.md). An older Custos ignores it when it reads and drops it when it saves, so every Custos that
|
||||||
|
saves the vault must be 0.11.0 or later. See "The provision audit" below.
|
||||||
|
|
||||||
|
### The provision audit (core 0.11.0)
|
||||||
|
|
||||||
|
```json
|
||||||
|
"provision": {
|
||||||
|
"audit": [
|
||||||
|
{ "at": 1793750100000, "direction": "offer", "host": "nixos-vm", "item": "fabrica/gitea-read-token",
|
||||||
|
"store": "vault", "run": "deploy-7", "kind": "Gitea token, read:repository", "code": "684361",
|
||||||
|
"outcome": "accepted", "replaced": true }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
| Member | |
|
||||||
|
| :-- | :-- |
|
||||||
|
| `at` | Unix milliseconds |
|
||||||
|
| `direction` | `ask` (the server asked for a secret) or `offer` (the server offered one) |
|
||||||
|
| `host` | the name the factor service gave, 1–253 characters `[A-Za-z0-9.-]` |
|
||||||
|
| `item` | `^[a-z0-9][a-z0-9._-]{0,63}(/[a-z0-9][a-z0-9._-]{0,63}){0,3}$`, as the factor service checks it |
|
||||||
|
| `store` | `vault`, `claude` or `cloud` |
|
||||||
|
| `run` | optional, `[A-Za-z0-9._-]{1,64}` |
|
||||||
|
| `kind` | optional, at most 200 characters, no control characters (an offer's label; an ask's `--generate` recipe) |
|
||||||
|
| `code` | the match code: six ASCII digits |
|
||||||
|
| `outcome` | `approved`, `generated`, `accepted`, `refused`, `out-of-scope`, `invalid` or `expired` |
|
||||||
|
| `replaced` | `true` when an accepted offer replaced an existing item |
|
||||||
|
|
||||||
|
- **No value, ever.** There is no member that holds a secret: every member is something the server sent in the
|
||||||
|
clear through the mailbox (host, item, store, run, kind) or derives from a public key (`code`). A recorded
|
||||||
|
entry is checked against the table above; an entry that does not fit is refused, not stored.
|
||||||
|
- **Append-only.** The API records an entry and lists them (oldest first); nothing edits or removes one, except
|
||||||
|
that the log keeps the newest 5 000 entries and drops the oldest beyond that.
|
||||||
|
- Readers ignore members of an entry they do not know. A file whose `provision` has an `outcome`, `direction` or
|
||||||
|
`store` this core does not know does not open (`Corrupted`), as for `signing`.
|
||||||
|
|
||||||
### Item types and their fields (v1)
|
### Item types and their fields (v1)
|
||||||
|
|
||||||
|
|||||||
+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
|
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
|
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.
|
(`crates/tessera`, `docs/TESSERA.md`); this page is the vault side.
|
||||||
|
|
||||||
## Creating it: the order is mandatory
|
## 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
|
Test vector: entropy `00` × 32 → `abandon` × 23 + `art` → root public key
|
||||||
`vCrwX9p44un1ftQLgJtuaVQ0qPWbFfzNjgrlDkL4TKs` (base64url). Fundamentum pins the same value.
|
`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
|
## In the vault file
|
||||||
|
|
||||||
A body member next to `items` (docs/FORMAT.md, "Body"); old vaults without it open as before:
|
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,
|
"created": 1793000000000,
|
||||||
"issued": [
|
"issued": [
|
||||||
{ "kind": "app", "app_id": "fiscus", "purpose": "sync", "subkey": "<base64url>", "label": "fiscus.exe",
|
{ "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
|
- `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
|
- **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.
|
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_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_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_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
|
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.
|
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
|
## What it does not protect
|
||||||
|
|
||||||
|
|||||||
+23
-2
@@ -20,8 +20,29 @@ aad "CSL1" ‖ E ‖ context
|
|||||||
A box opens only with the context it was sealed for, so a box for one request does not work as another.
|
A box opens only with the context it was sealed for, so a box for one request does not work as another.
|
||||||
- **A low-order public key is refused** on both sides: the shared secret must be contributory.
|
- **A low-order public key is refused** on both sides: the shared secret must be contributory.
|
||||||
- **Plaintext limit:** 32 KiB.
|
- **Plaintext limit:** 32 KiB.
|
||||||
- **The recipient's secret half** lives only in memory, as `x25519_dalek::StaticSecret` with `zeroize`,
|
- **The recipient's secret half** lives in memory as `x25519_dalek::StaticSecret` with `zeroize`, and is
|
||||||
and is wiped on drop. Nothing writes it to disk.
|
wiped on drop. One-time keys (`Recipient::generate`) are the default and nothing writes them to disk.
|
||||||
|
|
||||||
|
### A kept key (core 0.11.0)
|
||||||
|
|
||||||
|
The recipient's secret may now be kept by the caller, for one purpose: the PC's Provisio sealing key
|
||||||
|
(docs/10_provisio.md in the app), the key the server seals **offers** to. Custos makes it once with
|
||||||
|
`Recipient::generate`, keeps `Recipient::secret_bytes()` DPAPI-sealed in `<data>actors\provision.key`, and
|
||||||
|
restores it with `Recipient::from_secret` at every start. Everything else (approvals, pairing, a Provisio *ask*)
|
||||||
|
still uses a fresh one-time key per request.
|
||||||
|
|
||||||
|
```
|
||||||
|
Recipient::from_secret(Zeroizing<[u8; 32]>) -> Result<Recipient, SealError> // BadKey for a known key
|
||||||
|
Recipient::secret_bytes(&self) -> Zeroizing<[u8; 32]> // only for a key that is kept
|
||||||
|
```
|
||||||
|
|
||||||
|
- `from_secret` refuses (`BadKey`) a secret that X25519 clamps to zero (all zeros: a wiped or never-filled
|
||||||
|
buffer) and, as for public keys, one whose shared secrets would not be contributory.
|
||||||
|
- A kept key opens every box ever sealed to it, so the **context** carries the binding: an offer is sealed for
|
||||||
|
`provision-offer:<store>:<item>`, and the PC checks the plaintext's item, store, kind and code key against the
|
||||||
|
offer before it shows a card. The mailbox refuses an offer whose ephemeral key it has seen (replay).
|
||||||
|
- `secret_bytes` hands out the secret in a `Zeroizing` buffer. It goes to the caller's sealed storage and
|
||||||
|
nowhere else: never a log, a message or a file in the clear. `Debug` of a `Recipient` prints `[redacted]`.
|
||||||
|
|
||||||
## The match code
|
## The match code
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user