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