Skip to main content

ic_auth_protocol_types/
claims.rs

1//! Passive schema-2 fields. Construction does not establish canonicality or trust.
2
3use crate::{AuthRole, Principal, ScopeLabel};
4
5/// Exactly 32 identity bytes; every byte pattern is permitted.
6#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
7pub struct CanonicalId([u8; 32]);
8
9impl CanonicalId {
10    /// Preserve an identity's bytes without assigning authority to their source.
11    #[must_use]
12    pub const fn from_bytes(bytes: [u8; 32]) -> Self {
13        Self(bytes)
14    }
15
16    /// Borrow the exact signed representation.
17    #[must_use]
18    pub const fn as_bytes(&self) -> &[u8; 32] {
19        &self.0
20    }
21}
22
23/// Claimed network/application context, compared later with protected enrollment.
24#[derive(Clone, Copy, Debug, Eq, PartialEq)]
25pub struct AudienceId {
26    /// Claimed network identity.
27    pub canonical_network_id: CanonicalId,
28    /// Claimed application identity, retaining the existing protocol field name.
29    pub fleet_id: CanonicalId,
30}
31
32/// A claimed mechanism, never permission to select a verifier or enroll a key.
33#[derive(Clone, Copy, Debug, Eq, PartialEq)]
34pub enum PortableMechanism {
35    /// Root-delegated certified issuer proof (signed tag 0).
36    Certified,
37    /// Independently enrolled Ed25519 issuer key (signed tag 1).
38    Ed25519,
39}
40
41/// Syntactically valid labels whose counts, order and authority remain unchecked.
42#[derive(Clone, Debug, Eq, PartialEq)]
43pub struct DelegatedRoleGrant {
44    /// Role to which these scopes apply; roles must not be combined implicitly.
45    pub target: AuthRole,
46    /// Claimed scope labels in their supplied order.
47    pub scopes: Vec<ScopeLabel>,
48}
49
50/// Unauthenticated schema-2 credential fields.
51///
52/// The codec checks structure, not signature validity, time relationships,
53/// enrollment, caller binding, revocation or permission. Even a successfully
54/// decoded value cannot authorize a session.
55#[derive(Clone, Debug, Eq, PartialEq)]
56pub struct PortableClaims {
57    /// Mechanism committed by the signed bytes.
58    pub mechanism: PortableMechanism,
59    /// Claimed receiving network and application.
60    pub audience: AudienceId,
61    /// Claimed issuer; verification must match protected enrollment.
62    pub issuer: Principal,
63    /// Claimed key-binding identity, not key material or authority.
64    pub key_binding_id: [u8; 32],
65    /// Raw browser Ed25519 key; possession and caller binding are not checked here.
66    pub browser_public_key: [u8; 32],
67    /// Issuer-qualified subject; canonical claims exclude the anonymous principal.
68    pub account_subject: Principal,
69    /// Issuer-assigned slot, canonically bounded to 0–7.
70    pub device_slot: u8,
71    /// Nonzero slot generation, unchanged by renewal.
72    pub device_generation: u64,
73    /// Original login start, in nanoseconds.
74    pub login_started_at_ns: u64,
75    /// Original absolute login deadline, in nanoseconds.
76    pub login_deadline_ns: u64,
77    /// Credential issuance time, in nanoseconds.
78    pub issued_at_ns: u64,
79    /// Exclusive fresh-admission expiry, distinct from the session lease.
80    pub admission_expires_at_ns: u64,
81    /// Credential nonce; all-zero bytes remain valid structural input.
82    pub nonce: [u8; 16],
83    /// Signed grants in strict role/scope order; never normalize them on decode.
84    pub grants: Vec<DelegatedRoleGrant>,
85}