Skip to main content

Module compiled

Module compiled 

Source
Expand description

Compiled-policy distribution + signing (S4 / #570).

The PolicyService (PDP authority) compiles policy into a CompiledPolicy (the TE matrix plus the lattice generation it is valid for), serializes it canonically, hashes it, and signs (generation, policy_hash) with the hybrid COSE composite (EdDSA + ML-DSA-65; design §13a, §14). Nodes (PEPs) load the signed artifact and the PolicyLoader rejects any policy whose signature does not verify and (per design §14 / S5 containment backstop) whose hash does not match an approval.

This module is the transport/verification boundary; the per-op hot path (te + avc) never touches it. Signature verification happens once at load, never per op (design §7, §13a “never verify-per-op”).

§What S5 owns vs what this owns

  • S5: the UCAN→TE compiler that produces the TeMatrix and the approval signature over (canonical_UCAN_CID, bundle_hash).
  • S4 (here): wrapping the matrix as a versioned, hashed, signed distributable; and the loader that rejects anything unsigned/mismatched before it can feed an evaluator.

The actual COSE composite sign/verify lives in hyprstream_rpc::crypto::cose_sign; this module abstracts it behind PolicySigner / PolicyVerifier so the hot-path crate has no crypto dependency and so tests can use a trivial signer. The production wiring (using MlDsaSigningKeyStore + Ed25519) is in cose.

Modules§

cose
Production signer/verifier adapters over hyprstream_rpc::crypto::cose_sign.

Structs§

CompiledPolicy
A compiled, distributable policy artifact: the TE matrix, the S1 lattice it was compiled against (embedded verbatim), and the generation that binds them. generation ties the matrix to a specific lattice generation (S1) AND is the AVC’s cache-invalidation key — bumping it invalidates every cached decision.
PolicyApproval
An approval record (design §14 containment backstop): the human-approved binding of a policy generation to its expected hash. The loader accepts ONLY a policy whose recomputed hash matches an approval for its generation. Even an undetected compiler bug then can’t smuggle authority past review. S5 produces these (signed (UCAN_CID, bundle_hash)); here we model the hash-match the loader enforces.
PolicyLoader
PEP side: verify signature + match against an approval, then yield the CompiledPolicy ready to feed a crate::mac::te::LatticeTeEvaluator. Fail-closed: any failure returns an error and NO policy is loaded (the PEP keeps denying).
SignedPolicy
A signed, distributable policy: the canonical policy bytes + a detached composite signature over (generation || policy_hash). This is the wire artifact PolicyService publishes and PEPs fetch.

Enums§

PolicyDistError
Errors in compiled-policy distribution. All are load-time; the hot path never sees them.

Traits§

PolicySigner
Abstraction over the authority’s signing key (production = hybrid EdDSA+ML-DSA-65 COSE composite). Implemented in cose over the existing crypto stack.
PolicyVerifier
Abstraction over signature verification at the loader (production = composite verify with require_pq = true, fail-closed).

Functions§

sign_policy
PolicyService side: compile → hash → sign → distributable artifact.
signing_input
The exact bytes that get signed: domain-separated (generation, policy_hash). Binding the generation prevents a rollback/replay of an older signed matrix under a new generation.