libid-profiles 0.25.0

The libID ceremony profiles: what each platform's notarized sessions request and reveal, mirroring CeremonyProfile.sol byte for byte.
Documentation
// Generated by scripts/regen-ceremony-profiles.py. Do not edit.
// The source of truth is solidity/contracts/ceremony/profiles.json.

//! The ceremony profiles. scripts/regen-ceremony-profiles.py generates
//! the Solidity, Rust and TypeScript constants from profiles.json, and
//! the hand-written Platform Verifiers read them.
//!
//! These literals are the one copy the verifiers, the browser that
//! notarizes the sessions and the notary must reproduce byte for byte.
//! A mismatch fails silently: a Consumer and a verifier keyed by
//! different strings never meet, and a request line composed one byte
//! differently is refused with no reason given.
//!
//! Changing a value changes what a deployed verifier accepts. On a live
//! deployment that is a new ceremonyVersion; a fresh deployment keeps its
//! versions.

/// Which shape a platform's immutable identifier takes in its response.
///
/// A bare integer is revealed with its terminator, which proves the digits
/// are the whole number (REQ-PLAT-51).
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum IdShape {
    /// `"id":"2244994945"`.
    JsonString,
    /// `"id":583231,`
    JsonInteger,
}

/// One notarized session: which server, and which request.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Session {
    /// The lowercase TLS server name the notary authenticates, with no
    /// trailing dot, and the request's `Host` header. The verifier compares
    /// its keccak256, `authorityId`, to the profile's pin (REQ-COMMON-21A).
    pub authority: &'static str,
    pub method: &'static str,
    pub path: &'static str,
    /// The request-line prefix the verifier compares byte for byte. The
    /// trailing space stops `GET /user` from prefixing `GET /users/me`.
    pub request_line: &'static str,
}

/// The token session: the OAuth exchange.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct TokenSession {
    pub session: Session,
    /// The header lines a Platform Verifier requires exactly once: `host`
    /// and `content-type`, lowercased as on the wire. Other headers pass
    /// unless `FORBIDDEN_REQUEST_HEADERS` names them. `content-length` is
    /// absent: the HTTP client writes it and the verifier reads it.
    pub required_headers: &'static [&'static str],
    /// The body's form fields in serialization order. Verifiers require
    /// exactly these names in this order, each once with a nonempty value,
    /// and nothing after the last. GitHub's list is REQ-PLAT-61's and X's
    /// is REQ-PLAT-63's.
    pub token_fields: &'static [&'static str],
}

/// The identity session: the authenticated read that names the account.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct IdentitySession {
    pub session: Session,
    /// The header lines a Platform Verifier requires exactly once: `host`.
    pub required_headers: &'static [&'static str],
    pub id_field: &'static str,
    pub id_shape: IdShape,
    pub handle_field: &'static str,
}

/// One platform's ceremony profile at one Platform Ceremony Version.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Profile {
    /// The platform name. `platformId` is its keccak256.
    pub platform: &'static str,
    /// The Platform Ceremony Version. Platform and version together name a
    /// profile (REQ-PLAT-01).
    pub ceremony_version: u16,
    /// `None` where the profile notarizes nothing.
    pub token: Option<TokenSession>,
    pub identity: Option<IdentitySession>,
}

impl Profile {
    /// How many attestations a submission for this profile carries, one per
    /// session (REQ-COMMON-41).
    pub const fn attestation_count(&self) -> u8 {
        self.token.is_some() as u8 + self.identity.is_some() as u8
    }
}

/// Google's evidence is a token signed with Google's published keys, so
/// the profile notarizes nothing: no session, no attestation and no
/// Notary Fee.
pub const GOOGLE: Profile = Profile {
    platform: "google",
    ceremony_version: 1,
    token: None,
    identity: None,
};

/// A public client with S256 PKCE and two browser-owned sessions, both
/// served by the same host.
pub const X: Profile = Profile {
    platform: "x",
    ceremony_version: 1,
    token: Some(TokenSession {
        session: Session {
            authority: "api.x.com",
            method: "POST",
            path: "/2/oauth2/token",
            request_line: "POST /2/oauth2/token ",
        },
        required_headers: &[
            "host: api.x.com",
            "content-type: application/x-www-form-urlencoded",
        ],
        token_fields: &[
            "grant_type",
            "client_id",
            "code",
            "redirect_uri",
            "code_verifier",
        ],
    }),
    identity: Some(IdentitySession {
        session: Session {
            authority: "api.x.com",
            method: "GET",
            path: "/2/users/me",
            request_line: "GET /2/users/me ",
        },
        required_headers: &["host: api.x.com"],
        id_field: "id",
        id_shape: IdShape::JsonString,
        handle_field: "username",
    }),
};

/// The credential GitHub calls `client_secret` is sent and revealed, so
/// an attestation publishes it. The two sessions are served by different
/// hosts, so each session pins its own authority.
pub const GITHUB: Profile = Profile {
    platform: "github",
    ceremony_version: 1,
    token: Some(TokenSession {
        session: Session {
            authority: "github.com",
            method: "POST",
            path: "/login/oauth/access_token",
            request_line: "POST /login/oauth/access_token ",
        },
        required_headers: &[
            "host: github.com",
            "content-type: application/x-www-form-urlencoded",
        ],
        token_fields: &[
            "client_id",
            "code",
            "redirect_uri",
            "code_verifier",
            "client_secret",
        ],
    }),
    identity: Some(IdentitySession {
        session: Session {
            authority: "api.github.com",
            method: "GET",
            path: "/user",
            request_line: "GET /user ",
        },
        required_headers: &["host: api.github.com"],
        id_field: "id",
        id_shape: IdShape::JsonInteger,
        handle_field: "login",
    }),
};

/// Like Google, the evidence is a token signed with the platform's published
/// keys, so the profile notarizes nothing. The audience is the bot id the
/// payload names, and any bot is admitted (REQ-COMMON-17C).
pub const TELEGRAM: Profile = Profile {
    platform: "telegram",
    ceremony_version: 1,
    token: None,
    identity: None,
};

/// The launch profiles. `CeremonyProfile.attestationCount` reverts on any
/// other platform.
pub const LAUNCH: &[&Profile] = &[&GOOGLE, &X, &GITHUB, &TELEGRAM];

/// The launch profile for a platform name, or `None` if it has none.
pub fn launch(platform: &str) -> Option<&'static Profile> {
    LAUNCH.iter().copied().find(|p| p.platform == platform)
}

/// Header names no notarized request may carry, compared lowercased, with
/// whitespace removed and `_` read as `-`. Each changes what the platform
/// does in a way no revealed byte shows: `authorization` the client it
/// authenticates, `content-encoding` and `transfer-encoding` the bytes it
/// parses, `cookie` the session, the three override names the method. The
/// identity request is excepted from `authorization` alone: its one such
/// header, under any scheme, is what REQ-COMMON-39 counts. The verifier
/// also requires each session's requiredHeaders once with their value,
/// reads the token request's `content-length`, and ignores every other
/// header: such a header changes only the response, which the verifier
/// then cannot read.
pub const FORBIDDEN_REQUEST_HEADERS: &[&str] = &[
    "authorization",
    "content-encoding",
    "cookie",
    "transfer-encoding",
    "x-http-method",
    "x-http-method-override",
    "x-method-override",
];

// The seconds each profile fixes. A Platform Verifier reads them as
// constants, so a different value is a new ceremonyVersion (REQ-PARAM-01)
// and a client that knows its version knows the validity every chain
// enforces. `IdentityRegistry` replaces a binding only on a strictly newer
// `observedAt`, so the future allowance bounds how long a proof dated ahead
// holds a name.

// The signed `exp` bounds validity, so the profile fixes no lifetime and
// no attestation skew. The OIDC circuit exposes no `iat`, so the
// observation is the token's `exp`, about an hour after Google issued
// it.
/// `google/v1`: how far ahead of Block Time the evidence time may run.
/// The verifier subtracts it, so every version of a platform reports
/// time on one scale.
pub const FUTURE_OBSERVATION_ALLOWANCE_SECONDS_GOOGLE: u64 = 7200;

// The token attestation's creation time is the evidence time. A notary
// states the wall-clock time it observes, so five minutes covers clock
// skew between the notary and the chain.
/// `x/v1`: maximum age of the token attestation.
pub const PROOF_LIFETIME_SECONDS_X: u64 = 3600;
/// `x/v1`: how far ahead of Block Time the token attestation may be
/// dated.
pub const MAX_FUTURE_ATTESTATION_SKEW_SECONDS_X: u64 = 300;
/// `x/v1`: how far ahead of Block Time the evidence time may run. The
/// verifier subtracts it, so every version of a platform reports time
/// on one scale.
pub const FUTURE_OBSERVATION_ALLOWANCE_SECONDS_X: u64 = 300;

// Same as X: notary wall-clock, five minutes for skew.
/// `github/v1`: maximum age of the token attestation.
pub const PROOF_LIFETIME_SECONDS_GITHUB: u64 = 3600;
/// `github/v1`: how far ahead of Block Time the token attestation may
/// be dated.
pub const MAX_FUTURE_ATTESTATION_SKEW_SECONDS_GITHUB: u64 = 300;
/// `github/v1`: how far ahead of Block Time the evidence time may run.
/// The verifier subtracts it, so every version of a platform reports
/// time on one scale.
pub const FUTURE_OBSERVATION_ALLOWANCE_SECONDS_GITHUB: u64 = 300;

// The circuit exposes the signed `iat`. A token is accepted while
// Block Time is in [iat - 5 min, iat + 1 h): five minutes for clock
// skew. The observation is `iat` less five minutes, so an `iat` inside
// the skew cannot outrank a later binding.
/// `telegram/v1`: maximum age of the signed `iat`.
pub const PROOF_LIFETIME_SECONDS_TELEGRAM: u64 = 3600;
/// `telegram/v1`: how far ahead of Block Time the signed `iat` may be
/// dated.
pub const MAX_FUTURE_ATTESTATION_SKEW_SECONDS_TELEGRAM: u64 = 300;
/// `telegram/v1`: how far ahead of Block Time the evidence time may
/// run. The verifier subtracts it, so every version of a platform
/// reports time on one scale.
pub const FUTURE_OBSERVATION_ALLOWANCE_SECONDS_TELEGRAM: u64 = 300;