ic_auth_protocol_types/proof.rs
1//! Passive application authentication proof contracts.
2//! Adapted from Canic; see docs/design/canic-source-review.md.
3
4use super::{DelegatedRoleGrant, DelegationAudience};
5use crate::Principal;
6use serde::{Deserialize, Serialize};
7
8//
9// RootProof
10//
11
12/// Unverified root-authority proof; trusted root keys come from host enrollment.
13#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
14pub enum RootProof {
15 /// Chain-key signature over a batch containing the issuer's delegation leaf.
16 IcChainKeyBatchSignatureV1(IcChainKeyBatchSignatureProofV1),
17}
18
19//
20// IcCanisterSignatureProofV1
21//
22
23/// IC canister-signature material, checked against the delegated issuer binding.
24#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
25pub struct IcCanisterSignatureProofV1 {
26 /// CBOR signature envelope containing the certificate and signature witness.
27 pub signature_cbor: Vec<u8>,
28 /// DER-encoded canister-signature public key; submission does not enroll trust.
29 pub public_key_der: Vec<u8>,
30}
31
32//
33// ChainKeyAlgorithm
34//
35
36/// Supported root chain-key signature algorithm.
37#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
38pub enum ChainKeyAlgorithm {
39 /// ECDSA over secp256k1, subject to Auth's canonical signature policy.
40 EcdsaSecp256k1,
41}
42
43//
44// ChainKeyKeyId
45//
46
47/// Chain-key identifier within the separately selected algorithm and network.
48#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
49pub struct ChainKeyKeyId {
50 /// Network key name, which must match independently enrolled root policy.
51 pub name: String,
52}
53
54//
55// IcChainKeyBatchSignatureProofV1
56//
57
58/// Signed batch and Merkle inclusion proof for one issuer's delegation.
59#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
60pub struct IcChainKeyBatchSignatureProofV1 {
61 /// Signed batch metadata binding the tree root and authority epochs.
62 pub header: ChainKeyBatchHeaderV1,
63 /// Issuer delegation leaf whose canonical hash is proven in the batch.
64 pub delegation_cert: ChainKeyDelegationCertV1,
65 /// Sibling path from the issuer leaf to the signed tree root.
66 pub issuer_witness: ChainKeyBatchWitnessV1,
67 /// Root signature and submitted key metadata, checked against enrollment.
68 pub signature: ChainKeyRootSignatureV1,
69}
70
71//
72// ChainKeyBatchHeaderV1
73//
74
75/// Canonically signed batch header; all identities and epochs remain untrusted
76/// until matched against the host's protected root policy.
77#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
78pub struct ChainKeyBatchHeaderV1 {
79 /// Schema discriminator for the batch's canonical encoding.
80 pub schema_version: u16,
81 /// Claimed root authority canister, compared with protected enrollment.
82 pub root_canister_id: Principal,
83 /// Root-assigned identifier distinguishing this batch.
84 pub batch_id: [u8; 32],
85 /// Proof generation, subject to the host's minimum accepted epoch.
86 pub proof_epoch: u64,
87 /// Registry generation, subject to the host's minimum accepted epoch.
88 pub registry_epoch: u64,
89 /// Digest binding this batch to the root's registry snapshot.
90 pub registry_hash: [u8; 32],
91 /// Merkle root against which issuer inclusion is verified.
92 pub tree_root: [u8; 32],
93 /// Validity start in nanoseconds, checked with explicit host skew policy.
94 pub not_before_ns: u64,
95 /// Exclusive batch expiry in nanoseconds.
96 pub expires_at_ns: u64,
97 /// Signature algorithm that must match the enrolled root key.
98 pub algorithm: ChainKeyAlgorithm,
99 /// Network key identifier that must match enrollment and signature metadata.
100 pub key_id: ChainKeyKeyId,
101 /// Canonical digest of the root signature's derivation path.
102 pub derivation_path_hash: [u8; 32],
103 /// Root key generation, checked against the enrolled version and lower bound.
104 pub key_version: u64,
105}
106
107//
108// ChainKeyDelegationCertV1
109//
110
111/// Issuer authority committed as a leaf in a root-signed batch. This delegates
112/// application credential authority, not IC ingress identity or resource ownership.
113#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
114pub struct ChainKeyDelegationCertV1 {
115 /// Root authority that delegates the issuer's permissions.
116 pub root_canister_id: Principal,
117 /// Canister authorized to produce the delegated issuer proofs.
118 pub issuer_canister_id: Principal,
119 /// Proof generation bound to the containing batch.
120 pub proof_epoch: u64,
121 /// Permitted issuer proof algorithm.
122 pub issuer_proof_algorithm: IssuerProofAlgorithm,
123 /// Canonical digest of the issuer proof binding.
124 pub issuer_proof_binding_hash: [u8; 32],
125 /// Key material binding that issuer proofs must satisfy.
126 pub issuer_proof_binding: IssuerProofBinding,
127 /// Maximum credential lifetime delegated to this issuer, in nanoseconds.
128 pub max_token_ttl_ns: u64,
129 /// Audience for which the delegated grants may be used.
130 pub audience: DelegationAudience,
131 /// Upper bound on role/scope authority the issuer may grant.
132 pub grants: Vec<DelegatedRoleGrant>,
133 /// Delegation validity start in nanoseconds.
134 pub not_before_ns: u64,
135 /// Exclusive delegation expiry in nanoseconds.
136 pub expires_at_ns: u64,
137 /// Registry generation bound to the containing batch.
138 pub registry_epoch: u64,
139 /// Registry snapshot digest bound to the containing batch.
140 pub registry_hash: [u8; 32],
141}
142
143//
144// ChainKeyRootSignatureV1
145//
146
147/// Root signature with submitted key metadata. The public key is never a trust
148/// anchor by itself; verification compares it with independently enrolled policy.
149#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
150pub struct ChainKeyRootSignatureV1 {
151 /// Signature algorithm, also bound by the signed batch header.
152 pub algorithm: ChainKeyAlgorithm,
153 /// Network key identifier, also bound by the signed batch header.
154 pub key_id: ChainKeyKeyId,
155 /// Ordered derivation components whose canonical hash must match enrollment.
156 pub derivation_path: Vec<Vec<u8>>,
157 /// SEC1-encoded secp256k1 public key, compared with the enrolled key.
158 pub public_key: Vec<u8>,
159 /// Root signature bytes over the canonical batch header digest.
160 pub signature: Vec<u8>,
161}
162
163//
164// ChainKeyBatchWitnessV1
165//
166
167/// Ordered Merkle inclusion path; verification bounds its length before hashing.
168#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
169pub struct ChainKeyBatchWitnessV1 {
170 /// Sibling hashes in leaf-to-root order.
171 pub steps: Vec<ChainKeyBatchWitnessStepV1>,
172}
173
174//
175// ChainKeyBatchWitnessStepV1
176//
177
178/// Position of a sibling relative to the running Merkle hash.
179#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
180pub enum ChainKeyBatchWitnessStepV1 {
181 /// Hash the sibling on the left of the current subtree.
182 LeftSibling([u8; 32]),
183 /// Hash the sibling on the right of the current subtree.
184 RightSibling([u8; 32]),
185}
186
187//
188// IssuerProofAlgorithm
189//
190
191/// Proof mechanism a root delegation permits the issuer to use.
192#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
193pub enum IssuerProofAlgorithm {
194 /// IC canister signature checked with its certified signature witness.
195 IcCanisterSignatureV1,
196}
197
198//
199// IssuerProofBinding
200//
201
202/// Delegated key binding; the corresponding issuer identity is carried separately.
203#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
204pub enum IssuerProofBinding {
205 /// Bind the issuer's canister-signature key to a particular seed digest.
206 IcCanisterSignatureV1 {
207 /// Expected hash of the seed extracted from the canister-signature key.
208 seed_hash: [u8; 32],
209 },
210}
211
212//
213// DelegationCert
214//
215
216/// Application-facing delegation certificate checked against the root proof.
217/// Its issue time is consistency metadata, not independently root-signed authority.
218#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
219pub struct DelegationCert {
220 /// Root authority expected to authorize this delegation.
221 pub root_pid: Principal,
222 /// Issuer permitted to sign application credentials.
223 pub issuer_pid: Principal,
224 /// Proof algorithm delegated to the issuer.
225 pub issuer_proof_alg: IssuerProofAlgorithm,
226 /// Canonical digest binding the issuer's proof key.
227 pub issuer_proof_binding_hash: [u8; 32],
228 /// Issuer key binding checked against the root's delegation leaf.
229 pub issuer_proof_binding: IssuerProofBinding,
230 /// Issue-time metadata in nanoseconds; excluded from the root-signed leaf.
231 pub issued_at_ns: u64,
232 /// Delegation validity start in nanoseconds.
233 pub not_before_ns: u64,
234 /// Exclusive delegation deadline in nanoseconds.
235 pub expires_at_ns: u64,
236 /// Maximum credential lifetime delegated to the issuer, in nanoseconds.
237 pub max_token_ttl_ns: u64,
238 /// Audience admitted by this delegation.
239 pub aud: DelegationAudience,
240 /// Maximum role/scope grants the issuer may assign under this delegation.
241 pub grants: Vec<DelegatedRoleGrant>,
242}
243
244//
245// DelegationProof
246//
247
248/// Unverified delegation certificate paired with its root authority proof.
249#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
250pub struct DelegationProof {
251 /// Certificate to compare with the root-signed issuer leaf.
252 pub cert: DelegationCert,
253 /// Root signature and inclusion evidence authorizing that leaf.
254 pub root_proof: RootProof,
255}