Skip to main content

libid_profiles/
profiles.rs

1// Generated by scripts/regen-ceremony-profiles.py. Do not edit.
2// The source of truth is solidity/contracts/ceremony/profiles.json.
3
4//! The ceremony profiles. scripts/regen-ceremony-profiles.py generates
5//! the Solidity, Rust and TypeScript constants from profiles.json, and
6//! the hand-written Platform Verifiers read them.
7//!
8//! These literals are the one copy the verifiers, the browser that
9//! notarizes the sessions and the notary must reproduce byte for byte.
10//! A mismatch fails silently: a Consumer and a verifier keyed by
11//! different strings never meet, and a request line composed one byte
12//! differently is refused with no reason given.
13//!
14//! Changing a value changes what a deployed verifier accepts. On a live
15//! deployment that is a new ceremonyVersion; a fresh deployment keeps its
16//! versions.
17
18/// Which shape a platform's immutable identifier takes in its response.
19///
20/// A bare integer is revealed with its terminator, which proves the digits
21/// are the whole number (REQ-PLAT-51).
22#[derive(Clone, Copy, Debug, PartialEq, Eq)]
23pub enum IdShape {
24    /// `"id":"2244994945"`.
25    JsonString,
26    /// `"id":583231,`
27    JsonInteger,
28}
29
30/// One notarized session: which server, and which request.
31#[derive(Clone, Copy, Debug, PartialEq, Eq)]
32pub struct Session {
33    /// The lowercase TLS server name the notary authenticates, with no
34    /// trailing dot, and the request's `Host` header. The verifier compares
35    /// its keccak256, `authorityId`, to the profile's pin (REQ-COMMON-21A).
36    pub authority: &'static str,
37    pub method: &'static str,
38    pub path: &'static str,
39    /// The request-line prefix the verifier compares byte for byte. The
40    /// trailing space stops `GET /user` from prefixing `GET /users/me`.
41    pub request_line: &'static str,
42}
43
44/// The token session: the OAuth exchange.
45#[derive(Clone, Copy, Debug, PartialEq, Eq)]
46pub struct TokenSession {
47    pub session: Session,
48    /// The header lines a Platform Verifier requires exactly once: `host`
49    /// and `content-type`, lowercased as on the wire. Other headers pass
50    /// unless `FORBIDDEN_REQUEST_HEADERS` names them. `content-length` is
51    /// absent: the HTTP client writes it and the verifier reads it.
52    pub required_headers: &'static [&'static str],
53    /// The body's form fields in serialization order. Verifiers require
54    /// exactly these names in this order, each once with a nonempty value,
55    /// and nothing after the last. GitHub's list is REQ-PLAT-61's and X's
56    /// is REQ-PLAT-63's.
57    pub token_fields: &'static [&'static str],
58}
59
60/// The identity session: the authenticated read that names the account.
61#[derive(Clone, Copy, Debug, PartialEq, Eq)]
62pub struct IdentitySession {
63    pub session: Session,
64    /// The header lines a Platform Verifier requires exactly once: `host`.
65    pub required_headers: &'static [&'static str],
66    pub id_field: &'static str,
67    pub id_shape: IdShape,
68    pub handle_field: &'static str,
69}
70
71/// One platform's ceremony profile at one Platform Ceremony Version.
72#[derive(Clone, Copy, Debug, PartialEq, Eq)]
73pub struct Profile {
74    /// The platform name. `platformId` is its keccak256.
75    pub platform: &'static str,
76    /// The Platform Ceremony Version. Platform and version together name a
77    /// profile (REQ-PLAT-01).
78    pub ceremony_version: u16,
79    /// `None` where the profile notarizes nothing.
80    pub token: Option<TokenSession>,
81    pub identity: Option<IdentitySession>,
82}
83
84impl Profile {
85    /// How many attestations a submission for this profile carries, one per
86    /// session (REQ-COMMON-41).
87    pub const fn attestation_count(&self) -> u8 {
88        self.token.is_some() as u8 + self.identity.is_some() as u8
89    }
90}
91
92/// Google's evidence is a token signed with Google's published keys, so
93/// the profile notarizes nothing: no session, no attestation and no
94/// Notary Fee.
95pub const GOOGLE: Profile = Profile {
96    platform: "google",
97    ceremony_version: 1,
98    token: None,
99    identity: None,
100};
101
102/// A public client with S256 PKCE and two browser-owned sessions, both
103/// served by the same host.
104pub const X: Profile = Profile {
105    platform: "x",
106    ceremony_version: 1,
107    token: Some(TokenSession {
108        session: Session {
109            authority: "api.x.com",
110            method: "POST",
111            path: "/2/oauth2/token",
112            request_line: "POST /2/oauth2/token ",
113        },
114        required_headers: &[
115            "host: api.x.com",
116            "content-type: application/x-www-form-urlencoded",
117        ],
118        token_fields: &[
119            "grant_type",
120            "client_id",
121            "code",
122            "redirect_uri",
123            "code_verifier",
124        ],
125    }),
126    identity: Some(IdentitySession {
127        session: Session {
128            authority: "api.x.com",
129            method: "GET",
130            path: "/2/users/me",
131            request_line: "GET /2/users/me ",
132        },
133        required_headers: &["host: api.x.com"],
134        id_field: "id",
135        id_shape: IdShape::JsonString,
136        handle_field: "username",
137    }),
138};
139
140/// The credential GitHub calls `client_secret` is sent and revealed, so
141/// an attestation publishes it. The two sessions are served by different
142/// hosts, so each session pins its own authority.
143pub const GITHUB: Profile = Profile {
144    platform: "github",
145    ceremony_version: 1,
146    token: Some(TokenSession {
147        session: Session {
148            authority: "github.com",
149            method: "POST",
150            path: "/login/oauth/access_token",
151            request_line: "POST /login/oauth/access_token ",
152        },
153        required_headers: &[
154            "host: github.com",
155            "content-type: application/x-www-form-urlencoded",
156        ],
157        token_fields: &[
158            "client_id",
159            "code",
160            "redirect_uri",
161            "code_verifier",
162            "client_secret",
163        ],
164    }),
165    identity: Some(IdentitySession {
166        session: Session {
167            authority: "api.github.com",
168            method: "GET",
169            path: "/user",
170            request_line: "GET /user ",
171        },
172        required_headers: &["host: api.github.com"],
173        id_field: "id",
174        id_shape: IdShape::JsonInteger,
175        handle_field: "login",
176    }),
177};
178
179/// Like Google, the evidence is a token signed with the platform's published
180/// keys, so the profile notarizes nothing. The audience is the bot id the
181/// payload names, and any bot is admitted (REQ-COMMON-17C).
182pub const TELEGRAM: Profile = Profile {
183    platform: "telegram",
184    ceremony_version: 1,
185    token: None,
186    identity: None,
187};
188
189/// The launch profiles. `CeremonyProfile.attestationCount` reverts on any
190/// other platform.
191pub const LAUNCH: &[&Profile] = &[&GOOGLE, &X, &GITHUB, &TELEGRAM];
192
193/// The launch profile for a platform name, or `None` if it has none.
194pub fn launch(platform: &str) -> Option<&'static Profile> {
195    LAUNCH.iter().copied().find(|p| p.platform == platform)
196}
197
198/// Header names no notarized request may carry, compared lowercased, with
199/// whitespace removed and `_` read as `-`. Each changes what the platform
200/// does in a way no revealed byte shows: `authorization` the client it
201/// authenticates, `content-encoding` and `transfer-encoding` the bytes it
202/// parses, `cookie` the session, the three override names the method. The
203/// identity request is excepted from `authorization` alone: its one such
204/// header, under any scheme, is what REQ-COMMON-39 counts. The verifier
205/// also requires each session's requiredHeaders once with their value,
206/// reads the token request's `content-length`, and ignores every other
207/// header: such a header changes only the response, which the verifier
208/// then cannot read.
209pub const FORBIDDEN_REQUEST_HEADERS: &[&str] = &[
210    "authorization",
211    "content-encoding",
212    "cookie",
213    "transfer-encoding",
214    "x-http-method",
215    "x-http-method-override",
216    "x-method-override",
217];
218
219// The seconds each profile fixes. A Platform Verifier reads them as
220// constants, so a different value is a new ceremonyVersion (REQ-PARAM-01)
221// and a client that knows its version knows the validity every chain
222// enforces. `IdentityRegistry` replaces a binding only on a strictly newer
223// `observedAt`, so the future allowance bounds how long a proof dated ahead
224// holds a name.
225
226// The signed `exp` bounds validity, so the profile fixes no lifetime and
227// no attestation skew. The OIDC circuit exposes no `iat`, so the
228// observation is the token's `exp`, about an hour after Google issued
229// it.
230/// `google/v1`: how far ahead of Block Time the evidence time may run.
231/// The verifier subtracts it, so every version of a platform reports
232/// time on one scale.
233pub const FUTURE_OBSERVATION_ALLOWANCE_SECONDS_GOOGLE: u64 = 7200;
234
235// The token attestation's creation time is the evidence time. A notary
236// states the wall-clock time it observes, so five minutes covers clock
237// skew between the notary and the chain.
238/// `x/v1`: maximum age of the token attestation.
239pub const PROOF_LIFETIME_SECONDS_X: u64 = 3600;
240/// `x/v1`: how far ahead of Block Time the token attestation may be
241/// dated.
242pub const MAX_FUTURE_ATTESTATION_SKEW_SECONDS_X: u64 = 300;
243/// `x/v1`: how far ahead of Block Time the evidence time may run. The
244/// verifier subtracts it, so every version of a platform reports time
245/// on one scale.
246pub const FUTURE_OBSERVATION_ALLOWANCE_SECONDS_X: u64 = 300;
247
248// Same as X: notary wall-clock, five minutes for skew.
249/// `github/v1`: maximum age of the token attestation.
250pub const PROOF_LIFETIME_SECONDS_GITHUB: u64 = 3600;
251/// `github/v1`: how far ahead of Block Time the token attestation may
252/// be dated.
253pub const MAX_FUTURE_ATTESTATION_SKEW_SECONDS_GITHUB: u64 = 300;
254/// `github/v1`: how far ahead of Block Time the evidence time may run.
255/// The verifier subtracts it, so every version of a platform reports
256/// time on one scale.
257pub const FUTURE_OBSERVATION_ALLOWANCE_SECONDS_GITHUB: u64 = 300;
258
259// The circuit exposes the signed `iat`. A token is accepted while
260// Block Time is in [iat - 5 min, iat + 1 h): five minutes for clock
261// skew. The observation is `iat` less five minutes, so an `iat` inside
262// the skew cannot outrank a later binding.
263/// `telegram/v1`: maximum age of the signed `iat`.
264pub const PROOF_LIFETIME_SECONDS_TELEGRAM: u64 = 3600;
265/// `telegram/v1`: how far ahead of Block Time the signed `iat` may be
266/// dated.
267pub const MAX_FUTURE_ATTESTATION_SKEW_SECONDS_TELEGRAM: u64 = 300;
268/// `telegram/v1`: how far ahead of Block Time the evidence time may
269/// run. The verifier subtracts it, so every version of a platform
270/// reports time on one scale.
271pub const FUTURE_OBSERVATION_ALLOWANCE_SECONDS_TELEGRAM: u64 = 300;