//! Custos Domi ยท teams (docs/TEAM.md, core 0.18.0): the pure parts of team vaults and team signing. //! //! - [`member`]: a person's member key (X25519 to receive the team key, Ed25519 to sign approvals), the member id, //! the join code, and sealing the team key to a member; //! - [`policy`]: one rule per environment, its canonical text, and [`policy::evaluate`]; //! - [`request`]: the canonical `sign.request` and `target.request`, their hash and match code; //! - [`statement`]: a member's signed approval of one request; //! - [`proof`]: the team identity's policy proof, and checking it; //! - [`reply`]: what goes back to Fabrica, sealed; [`target`]: a released target credential; //! - [`external`]: the interface an external signer (a hardware token, a cloud signing service) is reached through. //! //! No I/O, no clock: every check takes `now` from the caller. Secrets print as `[redacted]`. pub mod canon; pub mod external; pub mod member; pub mod policy; pub mod proof; pub mod reply; pub mod request; pub mod statement; pub mod target; pub use member::{MemberKey, MemberPublic, TeamIdentity}; pub use policy::{EnvRule, Evaluation, KeyRole, Policy, RosterMember, Verdict, evaluate}; pub use proof::{Proof, Verified, verify_proof}; pub use request::{Format, SignRequest, TargetRequest}; pub use statement::Statement; /// How far ahead a request may expire: 25 hours, as deploy approvals (SIGNING.md). pub const MAX_AHEAD_SECS: u64 = 25 * 3600; /// How long a signed request's hash is remembered against replay: longer than any request lives. pub const SEEN_SECS: u64 = 48 * 3600; /// The most members a team has (member slots in one file). pub const MAX_MEMBERS: usize = 32; /// Why something is refused. None of them carries a key, a credential or a signature. #[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)] pub enum TeamError { #[error("not in canonical form: {0}")] NotCanonical(&'static str), #[error("{0}")] Invalid(&'static str), #[error("the request has expired")] Expired, #[error("the match code is not this request's: someone else's request may be waiting, refuse it")] WrongMatch, #[error("this request was already answered: a replay is refused")] Replayed, #[error("the request is for another team")] WrongTeam, #[error("not a member of this team")] NotAMember, #[error("a signature does not verify")] BadSignature, #[error("the policy has no rule for this environment")] UnknownEnv, #[error("the policy cannot be met: {0}")] Unsatisfiable(&'static str), #[error("the policy needs {0} more approval(s)")] NeedMore(u8), #[error("this member may not approve this request: {0}")] NotEligible(&'static str), #[error("the key cannot be read")] BadKey, } pub(crate) fn hex(b: &[u8]) -> String { data_encoding::HEXLOWER.encode(b) } pub(crate) fn unhex(s: &str) -> Option<[u8; N]> { let v = data_encoding::HEXLOWER.decode(s.as_bytes()).ok()?; v.try_into().ok() } pub(crate) fn b64(b: &[u8]) -> String { data_encoding::BASE64.encode(b) } pub(crate) fn unb64(s: &str) -> Option> { data_encoding::BASE64.decode(s.as_bytes()).ok() } pub(crate) fn sha256(b: &[u8]) -> [u8; 32] { use sha2::Digest; sha2::Sha256::digest(b).into() } /// 32 lower-case hex digits: a team, member or request id. pub fn id_ok(s: &str) -> bool { s.len() == 32 && s.bytes().all(|c| c.is_ascii_digit() || (b'a'..=b'f').contains(&c)) } /// A random 16-byte id, hex. pub fn new_id() -> String { let mut b = [0u8; 16]; rand::Rng::fill_bytes(&mut rand::rand_core::UnwrapErr(rand::rngs::SysRng), &mut b); hex(&b) }