[team] Team vaults: member keys, member slots (kind 6), policies per environment, the canonical sign.request, approval statements, policy proofs; cosign and Tauri updater envelopes; v0.18.0
This commit is contained in:
@@ -18,6 +18,12 @@ pub const SLOT_SINGLE: u8 = 4;
|
||||
/// The recovery key's slot (core 0.17.0; docs/FACTORS.md, "The recovery key").
|
||||
pub const SLOT_RECOVERY: u8 = 5;
|
||||
pub const RECOVERY_ID_LEN: usize = 4;
|
||||
/// A team vault's member slot (core 0.18.0; docs/TEAM.md): the team key sealed to one member.
|
||||
pub const SLOT_MEMBER: u8 = 6;
|
||||
/// team id (16) ‖ member id (16) ‖ epoch (4) ‖ sealed team key (108).
|
||||
pub const MEMBER_SLOT_LEN: usize = 16 + 16 + 4 + 108;
|
||||
/// A team has at most this many members.
|
||||
pub const MAX_MEMBER_SLOTS: usize = 32;
|
||||
const KDF_ARGON2ID: u8 = 1;
|
||||
pub const SALT_LEN: usize = 32;
|
||||
pub const ID_LEN: usize = 16;
|
||||
@@ -289,6 +295,38 @@ impl RecoverySlot {
|
||||
}
|
||||
}
|
||||
|
||||
/// A team vault's member slot (kind 6): the box carries its own binding (its context names team, epoch and member).
|
||||
#[derive(Clone)]
|
||||
pub struct MemberSlot {
|
||||
pub team: [u8; ID_LEN],
|
||||
pub member: [u8; ID_LEN],
|
||||
pub epoch: u32,
|
||||
pub sealed: Vec<u8>,
|
||||
}
|
||||
|
||||
impl MemberSlot {
|
||||
pub fn raw(&self) -> RawSlot {
|
||||
let mut p = Vec::with_capacity(MEMBER_SLOT_LEN);
|
||||
p.extend_from_slice(&self.team);
|
||||
p.extend_from_slice(&self.member);
|
||||
p.extend_from_slice(&self.epoch.to_le_bytes());
|
||||
p.extend_from_slice(&self.sealed);
|
||||
RawSlot { kind: SLOT_MEMBER, payload: p }
|
||||
}
|
||||
|
||||
pub fn parse(payload: &[u8]) -> Result<Self, Error> {
|
||||
if payload.len() != MEMBER_SLOT_LEN {
|
||||
return Err(Error::Malformed);
|
||||
}
|
||||
Ok(MemberSlot {
|
||||
team: payload[..16].try_into().unwrap(),
|
||||
member: payload[16..32].try_into().unwrap(),
|
||||
epoch: u32::from_le_bytes(payload[32..36].try_into().unwrap()),
|
||||
sealed: payload[36..].to_vec(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Header {
|
||||
pub version: u16,
|
||||
pub slots: Vec<RawSlot>,
|
||||
@@ -348,6 +386,9 @@ impl Header {
|
||||
|
||||
/// Structural rules of a v2 header (docs/FACTORS.md, "Limits a reader enforces").
|
||||
fn check_v2(&self) -> Result<(), Error> {
|
||||
if self.slots.iter().any(|s| s.kind == SLOT_MEMBER) {
|
||||
return self.check_team();
|
||||
}
|
||||
let mut ids = Vec::new();
|
||||
for s in self.slots.iter().filter(|s| s.kind == SLOT_FACTOR) {
|
||||
ids.push(FactorSlot::parse(&s.payload)?.id);
|
||||
@@ -398,6 +439,31 @@ impl Header {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A team vault (docs/TEAM.md): 1 ..= 32 member slots and nothing else, one team id and epoch, distinct members.
|
||||
fn check_team(&self) -> Result<(), Error> {
|
||||
if self.slots.len() > MAX_MEMBER_SLOTS || self.slots.iter().any(|s| s.kind != SLOT_MEMBER) {
|
||||
return Err(Error::Malformed);
|
||||
}
|
||||
let slots = self.slots.iter().map(|s| MemberSlot::parse(&s.payload)).collect::<Result<Vec<_>, _>>()?;
|
||||
let first = &slots[0];
|
||||
let mut members: Vec<[u8; ID_LEN]> = Vec::with_capacity(slots.len());
|
||||
for s in &slots {
|
||||
if s.team != first.team || s.epoch != first.epoch || members.contains(&s.member) {
|
||||
return Err(Error::Malformed);
|
||||
}
|
||||
members.push(s.member);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn is_team(&self) -> bool {
|
||||
self.slots.iter().any(|s| s.kind == SLOT_MEMBER)
|
||||
}
|
||||
|
||||
pub fn member_slots(&self) -> Vec<MemberSlot> {
|
||||
self.slots.iter().filter(|s| s.kind == SLOT_MEMBER).filter_map(|s| MemberSlot::parse(&s.payload).ok()).collect()
|
||||
}
|
||||
|
||||
pub fn factor_slots(&self) -> Vec<FactorSlot> {
|
||||
self.slots.iter().filter(|s| s.kind == SLOT_FACTOR).filter_map(|s| FactorSlot::parse(&s.payload).ok()).collect()
|
||||
}
|
||||
|
||||
@@ -27,11 +27,16 @@ mod save;
|
||||
mod secret;
|
||||
pub mod security;
|
||||
pub mod signing;
|
||||
pub mod team;
|
||||
|
||||
pub use item::{Attachment, Field, HISTORY_LIMIT, HistoryEntry, Item, ItemType, new_id, now_ms};
|
||||
pub use recovery::RecoveryKey;
|
||||
pub use save::{CrashPoint, save_atomic, save_atomic_crashing};
|
||||
pub use secret::{SecretBytes, SecretString};
|
||||
pub use team::{
|
||||
KnownTeam, NewSigner, NewTarget, Removal, RemovedMember, SignerView, TargetView, TeamAction, TeamAuditEntry,
|
||||
TeamMember, TeamView,
|
||||
};
|
||||
|
||||
use crypto::KEY_LEN;
|
||||
use format::{
|
||||
@@ -97,6 +102,15 @@ pub enum Error {
|
||||
Security(&'static str),
|
||||
#[error("signing keys: {0}")]
|
||||
Signing(String),
|
||||
/// A team vault operation was refused (docs/TEAM.md); names why, never a value.
|
||||
#[error("team: {0}")]
|
||||
Team(String),
|
||||
#[error("this is not a team vault")]
|
||||
NotATeam,
|
||||
#[error("this member key does not open this team vault: not a member, or removed")]
|
||||
NotAMember,
|
||||
#[error("this team vault is older than the one this member has seen, or another team's under the same id")]
|
||||
TeamRollback,
|
||||
#[error("{0}")]
|
||||
Io(#[from] std::io::Error),
|
||||
}
|
||||
@@ -295,6 +309,14 @@ struct Body {
|
||||
provision: Option<provision::ProvisionJson>,
|
||||
#[serde(default)]
|
||||
security: Option<security::State>,
|
||||
/// `"team"` for a team vault (core 0.18.0, docs/TEAM.md).
|
||||
#[serde(default)]
|
||||
kind: Option<String>,
|
||||
#[serde(default)]
|
||||
team: Option<team::TeamJson>,
|
||||
/// A person's member key (core 0.18.0).
|
||||
#[serde(default)]
|
||||
member: Option<team::MemberJson>,
|
||||
}
|
||||
|
||||
/// What `to_bytes` serializes: borrows the items instead of cloning every secret.
|
||||
@@ -312,6 +334,12 @@ struct BodyRef<'a> {
|
||||
provision: Option<provision::ProvisionJson>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
security: Option<security::State>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
kind: Option<&'static str>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
team: Option<team::TeamJson>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
member: Option<team::MemberJson>,
|
||||
}
|
||||
|
||||
/// An unlocked vault: the vault key and the decrypted items, both wiped on drop.
|
||||
@@ -332,6 +360,10 @@ pub struct Vault {
|
||||
provision: Vec<provision::ProvisionEntry>,
|
||||
/// The security level's Setup window, the checklist and their audit (docs/FORMAT.md).
|
||||
security: security::State,
|
||||
/// A team vault's own state (docs/TEAM.md); `None` for every other vault.
|
||||
team: Option<team::TeamState>,
|
||||
/// A person's member key and the teams it has opened (docs/TEAM.md); never in a team vault.
|
||||
member: Option<team::MemberState>,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Vault {
|
||||
@@ -419,6 +451,24 @@ fn unwrap_factor(header: &Header, u: &Unlock) -> Result<FactorRec, Error> {
|
||||
}
|
||||
|
||||
impl Vault {
|
||||
/// An empty version-2 vault with `key` and no slots yet: a team vault writes its member slots itself.
|
||||
pub(crate) fn empty_v2(key: Zeroizing<[u8; KEY_LEN]>) -> Vault {
|
||||
Vault {
|
||||
key,
|
||||
version: VERSION_2,
|
||||
slots: Vec::new(),
|
||||
items: Vec::new(),
|
||||
factors: Vec::new(),
|
||||
kdf_new: KdfParams::DEFAULT,
|
||||
identity: None,
|
||||
signing: signing::Store::default(),
|
||||
provision: Vec::new(),
|
||||
security: security::State::default(),
|
||||
team: None,
|
||||
member: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// A new, empty version-1 vault with a fresh random vault key wrapped by `password`.
|
||||
pub fn create(password: &SecretString, kdf: KdfParams) -> Result<Vault, Error> {
|
||||
let key = crypto::random_key();
|
||||
@@ -434,6 +484,8 @@ impl Vault {
|
||||
signing: signing::Store::default(),
|
||||
provision: Vec::new(),
|
||||
security: security::State::default(),
|
||||
team: None,
|
||||
member: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -453,6 +505,8 @@ impl Vault {
|
||||
signing: signing::Store::default(),
|
||||
provision: Vec::new(),
|
||||
security: security::State::default(),
|
||||
team: None,
|
||||
member: None,
|
||||
};
|
||||
v.add_factor(a, label_a)?;
|
||||
v.add_factor(b, label_b)?;
|
||||
@@ -488,6 +542,8 @@ impl Vault {
|
||||
signing: signing::Store::default(),
|
||||
provision: Vec::new(),
|
||||
security: security::State::default(),
|
||||
team: None,
|
||||
member: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -614,6 +670,17 @@ impl Vault {
|
||||
None => signing::Store::default(),
|
||||
};
|
||||
let security = security::State::from_json(body.security).ok_or(Error::Corrupted)?;
|
||||
// A team vault (member slots) has a team body and nothing of a person's; every other vault has none.
|
||||
let team = match (header.is_team(), body.kind.as_deref(), body.team) {
|
||||
(true, Some("team"), Some(j)) => Some(team::TeamState::from_json(j).ok_or(Error::Corrupted)?),
|
||||
(false, None, None) => None,
|
||||
_ => return Err(Error::Corrupted),
|
||||
};
|
||||
let member = match body.member {
|
||||
Some(_) if team.is_some() => return Err(Error::Corrupted),
|
||||
Some(j) => Some(team::MemberState::from_json(j).ok_or(Error::Corrupted)?),
|
||||
None => None,
|
||||
};
|
||||
Ok(Vault {
|
||||
key,
|
||||
version: header.version,
|
||||
@@ -625,6 +692,8 @@ impl Vault {
|
||||
signing,
|
||||
provision: provision::from_json(body.provision),
|
||||
security,
|
||||
team,
|
||||
member,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -662,6 +731,9 @@ impl Vault {
|
||||
signing: self.signing.json(),
|
||||
provision: provision::json(&self.provision),
|
||||
security: self.security.json(),
|
||||
kind: self.team.is_some().then_some("team"),
|
||||
team: self.team.as_ref().map(team::TeamState::json),
|
||||
member: self.member.as_ref().map(team::MemberState::json),
|
||||
};
|
||||
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);
|
||||
|
||||
@@ -51,6 +51,8 @@ pub enum KeyKind {
|
||||
CodeSigning,
|
||||
/// An Android app's signing key (core 0.14.0): RSA-4096 and a self-signed certificate; signs `apk` only.
|
||||
Android,
|
||||
/// A team's cosign key (core 0.18.0, docs/TEAM.md): ECDSA P-256; signs `cosign` only, in a team vault only.
|
||||
EcdsaP256,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@@ -64,6 +66,12 @@ pub enum SignKind {
|
||||
/// APK Signature Scheme v2/v3: 1 to 4 SHA-512 digests, signed with RSA PKCS#1 v1.5, by an Android key only
|
||||
/// (core 0.14.0).
|
||||
Apk,
|
||||
/// Tauri's updater: minisign over a BLAKE2b-512 digest, wrapped in base64 (core 0.18.0, team vaults only).
|
||||
#[serde(rename = "tauri-updater")]
|
||||
TauriUpdater,
|
||||
/// A cosign container image signature: ECDSA P-256 over the simple-signing payload (core 0.18.0, team vaults
|
||||
/// only).
|
||||
Cosign,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@@ -153,6 +161,18 @@ pub struct AuditEntry {
|
||||
/// The request's run id (core 0.12.0), when it had a well-formed one.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub run: Option<String>,
|
||||
/// A team vault's entry (core 0.18.0, docs/TEAM.md): the member whose Custos signed or refused.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub by: Option<String>,
|
||||
/// The environment the request was for.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub env: Option<String>,
|
||||
/// The request hash (hex).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub request: Option<String>,
|
||||
/// The members whose approvals counted.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub approvers: Vec<String>,
|
||||
}
|
||||
|
||||
/// A standing approval (core 0.16.0, docs/SIGNING.md): what Mark allowed for good, when, and how often it was used.
|
||||
@@ -212,26 +232,29 @@ pub struct KeyView {
|
||||
/// The certificate (DER), for root, code-signing and Android keys.
|
||||
pub cert: Option<Vec<u8>>,
|
||||
pub issuer: Option<String>,
|
||||
/// The `cosign.pub` PEM, for ECDSA P-256 keys (core 0.18.0).
|
||||
pub public_pem: Option<String>,
|
||||
}
|
||||
|
||||
enum Secret {
|
||||
pub(crate) enum Secret {
|
||||
Ed25519(Ed25519Secret),
|
||||
Rsa(RsaSecret),
|
||||
P256(custos_sign::P256Secret),
|
||||
}
|
||||
|
||||
struct Key {
|
||||
id: String,
|
||||
kind: KeyKind,
|
||||
role: Role,
|
||||
name: String,
|
||||
secret: Secret,
|
||||
public: Option<[u8; 32]>,
|
||||
key_id: Option<[u8; 8]>,
|
||||
cert: Option<Vec<u8>>,
|
||||
issuer: Option<String>,
|
||||
created: i64,
|
||||
pipelines: Vec<String>,
|
||||
repos: Vec<String>,
|
||||
pub(crate) struct Key {
|
||||
pub(crate) id: String,
|
||||
pub(crate) kind: KeyKind,
|
||||
pub(crate) role: Role,
|
||||
pub(crate) name: String,
|
||||
pub(crate) secret: Secret,
|
||||
pub(crate) public: Option<[u8; 32]>,
|
||||
pub(crate) key_id: Option<[u8; 8]>,
|
||||
pub(crate) cert: Option<Vec<u8>>,
|
||||
pub(crate) issuer: Option<String>,
|
||||
pub(crate) created: i64,
|
||||
pub(crate) pipelines: Vec<String>,
|
||||
pub(crate) repos: Vec<String>,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Key {
|
||||
@@ -243,8 +266,8 @@ impl fmt::Debug for Key {
|
||||
/// The keys and the log, in the vault.
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct Store {
|
||||
keys: Vec<Key>,
|
||||
audit: Vec<AuditEntry>,
|
||||
pub(crate) keys: Vec<Key>,
|
||||
pub(crate) audit: Vec<AuditEntry>,
|
||||
standing: Vec<StandingRule>,
|
||||
}
|
||||
|
||||
@@ -321,6 +344,10 @@ impl Store {
|
||||
KeyKind::RootCa | KeyKind::CodeSigning | KeyKind::Android => {
|
||||
Secret::Rsa(RsaSecret::from_pkcs8_der(k.secret.expose().to_vec()).ok()?)
|
||||
}
|
||||
KeyKind::EcdsaP256 => {
|
||||
let scalar: [u8; 32] = k.secret.expose().try_into().ok()?;
|
||||
Secret::P256(custos_sign::P256Secret::from_bytes(scalar).ok()?)
|
||||
}
|
||||
};
|
||||
let public = match &k.public {
|
||||
Some(p) => Some(unb64(p)?.try_into().ok()?),
|
||||
@@ -380,6 +407,7 @@ impl Store {
|
||||
secret: SecretBytes::new(match &k.secret {
|
||||
Secret::Ed25519(s) => s.expose().to_vec(),
|
||||
Secret::Rsa(s) => s.expose().to_vec(),
|
||||
Secret::P256(s) => s.expose().to_vec(),
|
||||
}),
|
||||
public: k.public.map(|p| b64(&p)),
|
||||
key_id: k.key_id.map(|i| hex(&i)),
|
||||
@@ -393,13 +421,13 @@ impl Store {
|
||||
Some(StoreJson { keys, audit: self.audit.clone(), standing: self.standing.clone() })
|
||||
}
|
||||
|
||||
fn get(&self, id: &str) -> Option<&Key> {
|
||||
pub(crate) fn get(&self, id: &str) -> Option<&Key> {
|
||||
self.keys.iter().find(|k| k.id == id)
|
||||
}
|
||||
}
|
||||
|
||||
/// Unix seconds from the vault's milliseconds, as minisign and approvals count them.
|
||||
fn seconds(now_ms: i64) -> u64 {
|
||||
pub(crate) fn seconds(now_ms: i64) -> u64 {
|
||||
(now_ms.max(0) / 1000) as u64
|
||||
}
|
||||
|
||||
@@ -450,6 +478,8 @@ fn kind_word(kind: SignKind) -> &'static str {
|
||||
SignKind::Authenticode => "authenticode",
|
||||
SignKind::Approval => "approval",
|
||||
SignKind::Apk => "apk",
|
||||
SignKind::TauriUpdater => "tauri-updater",
|
||||
SignKind::Cosign => "cosign",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -665,6 +695,10 @@ impl Vault {
|
||||
},
|
||||
cert: k.cert.clone(),
|
||||
issuer: k.issuer.clone(),
|
||||
public_pem: match &k.secret {
|
||||
Secret::P256(s) => s.public_pem().ok(),
|
||||
_ => None,
|
||||
},
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -925,6 +959,10 @@ impl Vault {
|
||||
signature,
|
||||
reason,
|
||||
run,
|
||||
by: None,
|
||||
env: None,
|
||||
request: None,
|
||||
approvers: Vec::new(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1156,6 +1194,7 @@ mod tests {
|
||||
.map(|k| match &k.secret {
|
||||
Secret::Ed25519(s) => s.expose().to_vec(),
|
||||
Secret::Rsa(s) => s.expose().to_vec(),
|
||||
Secret::P256(s) => s.expose().to_vec(),
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(secrets.len(), 9, "the release set with domi-approve, the test set, two Android keys");
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user