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