[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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user