trust

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 41 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	TRCValidity    = 365 * 24 * time.Hour
	VotingValidity = 365 * 24 * time.Hour
	RootValidity   = 365 * 24 * time.Hour
	CAValidity     = 11 * 24 * time.Hour
	ASValidity     = 3 * 24 * time.Hour

	// ChainRetention is how long an expired chain outlives its expiry before the
	// trust database's sweep deletes it: skew tolerance, the signingBackdate's
	// minute enlarged to cover the fetch it guards — a peer whose clock trails by
	// less than the window still fetches from the node the chain under which, on
	// that peer's clock, the node's signatures still verify.
	ChainRetention = time.Hour
)

Recommended validity periods of the trust material (PKI draft, Section 2.5). Chains rotate on the enrollment clock, and the cores' voting and root certificates roll inside the sensitive updates their holders cast; the base TRC alone never rolls — outliving it means redeploying.

View Source
const (
	// ASKeyFile holds the AS key that certifies control-plane messages.
	ASKeyFile = "cp-as.key"
	// SensitiveKeyFile holds the sensitive voting key of the founding core.
	SensitiveKeyFile = "sensitive-voting.key"
	// RegularKeyFile holds the regular voting key of the founding core, and
	// of an authoritative core beside it — a node is one tier or the other
	// for its lifetime, never both.
	RegularKeyFile = "regular-voting.key"
	// RegularVotingCertFile holds the self-signed regular voting certificate
	// of an authoritative core, created once its provisional identity
	// completes so retries, restarts, and operators all see the same bytes.
	RegularVotingCertFile = "regular-voting.crt"
	// RootKeyFile holds the CP root key of the founding core. It signs CP
	// CA certificates and is part of the TRC's anchor set.
	RootKeyFile = "cp-root.key"
	// CAKeyFile holds the CP CA key of the founding core. It signs AS
	// certificates; the matching certificate is never placed in the TRC.
	CAKeyFile = "cp-ca.key"
	// StagedFile holds a roll's fresh material from before anything can pin
	// it until a pinned TRC names it: PEM blocks, each one's File header
	// naming the live file the block replaces.
	StagedFile = "staged.pem"
)

Names of the key files inside the state directory's keys folder. All keys are ECDSA P-256, the curve all SCION signature algorithms build on.

View Source
const (
	// IAFile is the node's ISD-AS, one line, e.g. "20-fd00:0:123".
	IAFile = "ia"
	// ForwardingKeyFile holds the hex-encoded forwarding key MACing the
	// node's own hop fields.
	ForwardingKeyFile = "fwd.key"
)

IAFile holds the node's ISD-AS in the state directory's root; ForwardingKeyFile holds the forwarding key beside the AS keys. Both are generated on first start and persisted for the node's lifetime.

View Source
const (
	// EnrollmentRetryInterval is the pause between enrollment attempts.
	EnrollmentRetryInterval = 5 * time.Second
	// ChainInspectInterval is the pause between validity inspections of a
	// valid chain.
	ChainInspectInterval = time.Minute
	// EnrollmentTimeout bounds one enrollment attempt: a wedged connection
	// must not stall the loop renewing through it.
	EnrollmentTimeout = 10 * time.Second
	// ChainSweepInterval is the period of the trust database's expired-chain
	// sweep.
	ChainSweepInterval = time.Hour
)

Chain lifecycle intervals: while unenrolled the loop keeps a fast retry cadence; with a valid chain it settles to a calm inspection interval.

View Source
const ChainRenewalThreshold = 24 * time.Hour

ChainRenewalThreshold is the remaining validity below which the enrollment loop re-enrolls: roughly one day, against the three-day ASValidity. A node crossing it still holds a valid chain while the renewal round trip runs.

View Source
const RollTimeout = 10 * time.Second

RollTimeout bounds one roll attempt: a wedged submission must not stall the watch rolling behind it.

View Source
const RotationThreshold = 30 * 24 * time.Hour

RotationThreshold is the remaining validity below which a core's rotation watch rolls the trust material it holds: thirty days, the counterpart of the chain renewal threshold's one day against the three-day chain validity. Long enough to tolerate a month of failed casts, short enough that the successor's validity stays comfortable.

Variables

View Source
var ErrNoVotingApp = errors.New("the core hosts no voting application")

ErrNoVotingApp reports a core that hosts no voting application: nothing answers the submission, so the joining core cannot obtain voting power through the founder. A terminal condition — the node stops itself on it, for the network keeps serving everything else without the application.

Functions

func AssembleOnboarding

func AssembleOnboarding(
	pred cppki.SignedTRC,
	joiner addr.IA,
	votingCert *x509.Certificate,
) (cppki.TRC, error)

AssembleOnboarding builds the successor TRC that onboards an admitted joiner as an authoritative core: the serial incremented on the same base, the joiner's AS appended to the core and authoritative AS lists, its regular voting certificate appended to the certificate set, and the quorum, noTrustReset, and grace period untouched — a sensitive update, as cppki's classification reads it. The votes field carries the predecessor's index of the founder's sensitive voting certificate (PKI draft, Section 3.5.5), and the validity is the window every certificate the successor carries still covers — the joiner's fresh certificate never rules that window; the founder's carried ones do.

func AssembleRotation

func AssembleRotation(
	pred cppki.SignedTRC,
	voter *x509.Certificate,
	fresh []*x509.Certificate,
) (cppki.TRC, error)

AssembleRotation builds the successor TRC that rolls the staged certificates: each staged certificate replaces the predecessor's same-named counterpart of its class, everything else carried unchanged — the quorum, both AS lists, and noTrustReset as they were, for a roll changes keys, never membership. The votes field carries the voter's index in the predecessor: a sensitive voting certificate makes a sensitive update (PKI draft, Section 3.5.5), and the regular one the roll replaces makes a regular update (Section 3.5.4). The validity is the window every certificate the successor carries still covers, and the grace period is the AS certificate validity: the window a chain issued under replaced material keeps verifying, the draft's Section 3.2.4 update grace.

func BuildRenewalRequest

func BuildRenewalRequest(
	csr *x509.CertificateRequest,
	key crypto.Signer,
) ([]byte, error)

BuildRenewalRequest builds the CMS-signed chain renewal request for the CSR. The wrapper is signed by the CSR's subject key itself — proof of possession (PKI draft, Section 4.3) — because a fresh node has no certificate chain yet. CMS identifies signers by certificate, so the wrapper carries a self-signed certificate minted on the spot for the subject key; it is never trusted or used beyond binding the signature to the CSR.

func CertsOf

func CertsOf(trc cppki.TRC, ia addr.IA) []*x509.Certificate

CertsOf returns the certificates in the TRC naming the ISD-AS: the material the holder of the ISD-AS rolls — the founder's three, an authoritative core's one.

func CoSign

func CoSign(
	signed cppki.SignedTRC,
	key crypto.Signer,
	cert *x509.Certificate,
) (cppki.SignedTRC, error)

CoSign adds the signer info the given key makes over the signed TRC, beside the signatures the artifact carries already. The founder's control plane completes a submitted successor with it — the sensitive certificate of its newest pinned TRC signing beside the submitter's proof of possession.

func CoreNamed

func CoreNamed(trc cppki.TRC, ia addr.IA) bool

CoreNamed reports whether the TRC's core list names the ISD-AS.

func CreateCSR

func CreateCSR(ia addr.IA, key crypto.Signer) (*x509.CertificateRequest, error)

CreateCSR creates a self-signed certificate signing request for the node's key; the self-signature is the proof of possession of the subject key.

func GenerateIA

func GenerateIA() (addr.IA, error)

GenerateIA draws an ISD-AS from the private ranges: ISD from the private ISD range and AS from the private AS range (control plane draft, Section 1.5.1). The draw is provisional until persisted — a joiner's ISD completes with the network's.

func Genesis

func Genesis(
	ctx context.Context, db trustdb.DB, ia addr.IA, keys CoreKeys, cores ...addr.IA,
) (cppki.SignedTRC, error)

Genesis creates the ISD's base TRC for the founding core and persists it in the trust DB, listing the given fellow cores of the same ISD beside it — without voting certificates, the founder alone forming the quorum. Genesis is idempotent: if the base TRC is already in the DB, it is returned unchanged and never silently replaced.

The base TRC follows the PKI draft's genesis rules: the ID is ISDx-B1-S1, gracePeriod is zero, votes is empty, and votingQuorum is 1 — valid only because the single core holds one sensitive and one regular voting certificate. The TRC is CMS-signed by both voting keys, as cppki's base-TRC verification requires a signature for every voting certificate.

func JoinCore

func JoinCore(
	ctx context.Context,
	db trustdb.DB,
	remote Remote,
	caster TRCCaster,
	ia addr.IA,
	key crypto.Signer,
	cert *x509.Certificate,
) error

JoinCore obtains voting power for the authoritative core by sensitive TRC update: it resolves the founder's newest TRC — the drafts' numbers-less ask, verified against the pinned chain and pinned — assembles the successor onboarding itself, signs the proof of possession, and submits the partially signed artifact to the founder's voting application, whose control plane casts the sensitive vote and pins the completion. A core the newest TRC already names casts nothing: the resolved TRC pins, and the dance ends.

func KeyMatchesCert

func KeyMatchesCert(key crypto.Signer, cert *x509.Certificate) bool

KeyMatchesCert reports whether the certificate covers the key's public half.

func LastExpiring

func LastExpiring[T interface{ Validity() cppki.Validity }](
	signers []T, validity cppki.Validity,
) (T, error)

LastExpiring returns the Signer with the latest expiration time that covers the given validity. If no signer is found an error is returned.

func LoadIA

func LoadIA(stateDir string) (addr.IA, error)

LoadIA returns the persisted ISD-AS, the zero one when none is persisted yet — a first start.

func LoadOrCreateASKey

func LoadOrCreateASKey(stateDir string) (crypto.Signer, error)

LoadOrCreateASKey returns the node's AS key, generating and persisting a new one on first start. Keys live in the keys subdirectory of the state directory, created if needed.

func LoadOrCreateForwardingKey

func LoadOrCreateForwardingKey(stateDir string) ([]byte, error)

LoadOrCreateForwardingKey returns the node's forwarding key, generating and persisting a new one on first start. The key MACs only the node's own hop fields, so it needs no coordination.

func LoadOrCreateVotingCert

func LoadOrCreateVotingCert(
	stateDir string,
	ia addr.IA,
	key crypto.Signer,
) (*x509.Certificate, error)

LoadOrCreateVotingCert returns the authoritative core's self-signed regular voting certificate, minting and persisting it beside the key when none is persisted yet. The certificate names the completed ISD-AS, so it is created only after the provisional identity completes; a persisted certificate that does not match the key or name the ISD-AS is refused, not silently replaced.

func LoadOrCreateVotingKey

func LoadOrCreateVotingKey(stateDir string) (crypto.Signer, error)

LoadOrCreateVotingKey returns the authoritative core's regular voting key, generating and persisting it on first start. It occupies the file the founder's regular voting key occupies — the tiers never share a state directory — and nothing else is created: no sensitive, root, or CA key.

func NewestChain

func NewestChain(
	ctx context.Context,
	db trustdb.DB,
	ia addr.IA,
	now time.Time,
) ([]*x509.Certificate, error)

NewestChain returns the chain for ia with the latest expiration among the chains valid at now, or nil when none is valid.

func NewestTRCID

func NewestTRCID(isd addr.ISD) cppki.TRCID

NewestTRCID returns the numbers-less TRC ID asking an ISD's newest TRC — the active-discovery form the drafts' request carries (PKI draft, Section 4.1.2).

func ParseRenewalResponse

func ParseRenewalResponse(der []byte) ([]*x509.Certificate, error)

ParseRenewalResponse extracts the certificate chain from the CMS-signed renewal response, checking that the response is signed by the CP CA certificate it carries.

func PersistIA

func PersistIA(stateDir string, ia addr.IA) error

PersistIA rewrites the persisted ISD-AS — the completion of a joiner's identity, whose first ISD was a provisional draw replaced by the network's once a neighbor answered.

func PromoteStaged

func PromoteStaged(stateDir string, ia addr.IA, trc cppki.TRC) (bool, error)

PromoteStaged makes a roll's staged material live once the TRC names it: when the staged keys cover every certificate the TRC names for the ISD-AS, it writes each staged block to the live file its header names, removes the staged file, and reports true. It reports false, leaving any staged file in place, when none is staged or the TRC does not name it: the roll has not pinned, or the founder pinned a TRC the node has not learned yet. A promotion that stops partway is redone whole: each write gives a file the content it would hold anyway, and the staged file goes last.

func RenewChain

func RenewChain(
	ctx context.Context,
	db trustdb.DB,
	remote Remote,
	ia addr.IA,
	key crypto.Signer,
) ([]*x509.Certificate, error)

RenewChain requests a fresh chain for the node's key from the core and stores it, whatever chains the DB holds: the enrollment loop calls it when the node holds no valid chain, when the chain nears its expiry, and when the chain no longer anchors in the newest pinned TRC.

func RollVotingKey

func RollVotingKey(
	ctx context.Context,
	db trustdb.DB,
	remote Remote,
	caster TRCCaster,
	ia addr.IA,
	stateDir string,
) error

RollVotingKey rolls the authoritative core's regular voting certificate through the submission channel its join used: it resolves the founder's newest TRC — the drafts' numbers-less ask, verified against the pinned chain and pinned — and promotes the staged pair if the newest names it, for then an earlier attempt landed though its answer was lost, and the roll is complete without a submission. Otherwise it stages a fresh key with its self-signed certificate, or reuses the pair an earlier attempt staged, and assembles the successor replacing the certificate the newest names for the core. While the live key covers that certificate, the successor is a regular update the live key votes on beside the fresh key's proof of possession, and the founder pins it as submitted. Once it no longer does, the live key has no vote to cast: the successor is a sensitive update the fresh key alone signs, completed by the founder's vote on its admission policy's allow. What the founder answers verifies against the resolved predecessor before it pins here, and must name the staged pair, which the pin then promotes.

func RunEnrollment

func RunEnrollment(ctx context.Context, cfg EnrollmentConfig) error

RunEnrollment runs a node's chain lifecycle: each pass reads the newest chain's remaining validity and reports the newest pinned TRC's. It renews the Renewal's way when no valid chain exists, when the chain's validity drops below the renewal threshold, or when the chain does not verify against the newest pinned TRC alone — anchored in a root the TRC replaced — and with a valid chain does the work the role still owes. It also runs the trust database's expired-chain sweep on its own interval. The founding core's synchronous startup self-enrollment is its first pass. It returns nil once the context ends, and the owed work's terminal failure — a joining core's ErrNoVotingApp — with the sweep stopped.

func RunRotation

func RunRotation(ctx context.Context, cfg RotationConfig)

RunRotation runs the rotation watch of a core: a calm inspection interval while nothing is due, the retry cadence while a cast is failing. Each pass reads the newest pinned TRC, promotes a staged file it names, reads the certificates in it the node itself holds, finds their earliest expiry, and rolls inside the threshold — or on the mismatch a live key and the newest TRC's certificates disagree on.

func SelfIssue

func SelfIssue(
	ctx context.Context,
	db trustdb.DB,
	issuer *Issuer,
	ia addr.IA,
	key crypto.Signer,
) error

SelfIssue issues ia's chain for key through the issuer that serves the enrollment requests and stores it in db: the founding core's renewal, and the chain its boot holds before the endpoint serves.

func SignCMS

func SignCMS(msg []byte, chain []*x509.Certificate, key crypto.Signer) ([]byte, error)

SignCMS wraps msg in a CMS SignedData signed by key, embedding chain[0] as the signer certificate.

func SignRotation

func SignRotation(
	trc cppki.TRC,
	keys []crypto.Signer,
	certs []*x509.Certificate,
) (cppki.SignedTRC, error)

SignRotation signs the assembled successor with each key under its certificate: the staged keys' proof of possession cppki requires of every certificate that supersedes a same-named one, extended to the root, and on a regular update the vote of the key the roll replaces.

func SignUpdate

func SignUpdate(
	trc cppki.TRC,
	key crypto.Signer,
	cert *x509.Certificate,
) (cppki.SignedTRC, error)

SignUpdate signs the assembled successor with the joining core's regular voting key — the proof of possession the draft requires of every new voter (PKI draft, Section 3.5.6). The artifact carries exactly the one signature; the founder's sensitive vote is what completes it.

func SignerCert

func SignerCert(trc cppki.TRC, ct cppki.CertType) (*x509.Certificate, error)

SignerCert returns the voting certificate of the given type in the TRC's certificate set.

Types

type ASType

type ASType int

ASType is the tiered role of an AS, coupling the spec's core, voting, and authoritative properties. The type decides which key material a node generates on first start.

const (
	// ASTypeNormal is a non-core AS. It holds no voting or CA key material
	// and obtains its certificate chain by enrollment.
	ASTypeNormal ASType = iota
	// ASTypeAuthoritative is a core AS that joined its ISD over the network:
	// it holds a regular voting certificate beside the AS key, enrolls and
	// renews its chain like any node, and issues no trust material of its
	// own — the founding core stays the ISD's sensitive voter and CA.
	ASTypeAuthoritative
	// ASTypeCore is the founding core of an ISD. It self-issues the base
	// TRC and signs certificate chains for the ISD.
	ASTypeCore
)

func ParseASType

func ParseASType(s string) (ASType, error)

ParseASType parses the configuration representation of the AS type.

func (ASType) String

func (t ASType) String() string

type CA

type CA struct {
	// contains filtered or unexported fields
}

CA is one snapshot of an issuer's CA material: the CA certificate, the key signing with it, and the TRC anchoring them, read as one set. A renewal issues its chain and signs its response from one snapshot, for the client requires the response signed by the chain's CA certificate.

func (*CA) IssueChain

func (c *CA) IssueChain(csr *x509.CertificateRequest) ([]*x509.Certificate, error)

IssueChain creates a certificate chain for the subject of the CSR. The CSR must be self-signed (proof of possession of the subject key, PKI draft, Section 4.3) and its subject ISD-AS must be in the same ISD as the issuer.

func (*CA) SignResponse

func (c *CA) SignResponse(msg []byte) ([]byte, error)

SignResponse wraps msg in a CMS SignedData signed with the snapshot's CA certificate, as the chain renewal response requires.

type CMSSigned

type CMSSigned struct {
	// Payload is the encapsulated content.
	Payload []byte
	// SignerCerts are the certificates matching the signer infos, in order.
	SignerCerts []*x509.Certificate
	// Certificates are all certificates embedded in the SignedData.
	Certificates []*x509.Certificate
}

CMSSigned is a parsed CMS SignedData whose signer infos are verified against the certificates embedded in the message.

func ParseCMS

func ParseCMS(der []byte) (*CMSSigned, error)

ParseCMS parses der and verifies the signature of every signer info against the embedded certificates. Verification here proves the message was signed by the holder of the certificate's private key; whether that certificate is trusted is up to the caller.

func (*CMSSigned) SignedBy

func (s *CMSSigned) SignedBy(pub crypto.PublicKey) bool

SignedBy reports whether one of the signers holds the given public key.

type CoreKeys

type CoreKeys struct {
	// Sensitive signs TRC updates with the sensitive voting certificate.
	Sensitive crypto.Signer
	// Regular signs TRC updates with the regular voting certificate.
	Regular crypto.Signer
	// Root signs CP CA certificates.
	Root crypto.Signer
	// CA signs AS certificate chains.
	CA crypto.Signer
}

CoreKeys is the key material of the founding core.

func LoadOrCreateCoreKeys

func LoadOrCreateCoreKeys(stateDir string) (CoreKeys, error)

LoadOrCreateCoreKeys returns the founding core's key material, generating and persisting any missing keys on first start.

func RotateCoreKeys

func RotateCoreKeys(
	ctx context.Context,
	db trustdb.DB,
	stateDir string,
	ia addr.IA,
	pred cppki.SignedTRC,
) (CoreKeys, cppki.SignedTRC, error)

RotateCoreKeys rolls the founder's whole trust material — the sensitive and regular voting certificates and the root certificate, the CA key beside them — inside the cast it signs itself: the fresh keys staged on disk, or the ones an earlier attempt staged, certified afresh; the successor assembled on the given predecessor, each fresh certificate signing it, the live sensitive key casting the vote. The completed artifact verifies against the predecessor before it pins. The roll ends at the pin and answers with the staged keys and the successor, so the caller moves the decision's signer and the issuer onto them before it promotes the staged file.

type DBProvider

type DBProvider interface {
	LocalTRC(id cppki.TRCID) (cppki.SignedTRC, error)
	LocalChains(ctx context.Context, q trustdb.ChainQuery) ([][]*x509.Certificate, error)
}

DBProvider is implemented by providers that hold a local trust database.

type Engine

type Engine struct {
	// IA is the node's ISD-AS.
	IA addr.IA
	// Key is the AS private key certifying the node's messages.
	Key crypto.Signer
	// Provider resolves the node's chains and TRCs; DB-first, network-backed
	// on the nodes that enroll.
	Provider Provider
	// contains filtered or unexported fields
}

Engine composes the signer, verifier, and provider into the node's trust interface: it signs control-plane messages with a signer backed by the node's own chains, and verifies signatures against TRC-anchored chains resolved through the provider.

func NewEngine

func NewEngine(ia addr.IA, key crypto.Signer, provider Provider) *Engine

NewEngine returns an engine for the node's IA, AS key, and provider.

func (*Engine) AnchorPool

func (e *Engine) AnchorPool() ([]*cppki.TRC, error)

AnchorPool returns the active TRCs that anchor chain verification, as activePool reads them: the newest pinned TRC and, inside its grace period, its predecessor. Local state only, like BaseTRC: a TLS handshake must not spawn trust fetches. An empty pool means the node has not pinned the TRC yet.

func (*Engine) BaseTRC

func (e *Engine) BaseTRC() (cppki.SignedTRC, error)

BaseTRC returns the ISD's base TRC as pinned in the provider, without fetching it over the network. The zero TRC means the node has not pinned the TRC yet.

func (*Engine) Chain

func (e *Engine) Chain(ctx context.Context) ([]*x509.Certificate, error)

Chain returns the node's newest chain valid now, for the SCION-native TLS channel's certificates. It reads local state only: a TLS handshake must not spawn trust fetches, and an un-enrolled node simply has none.

func (*Engine) CoreASes

func (e *Engine) CoreASes(isd addr.ISD) ([]addr.IA, error)

CoreASes returns the core ASes of the given ISD named by the newest pinned TRC, with the ISD substituted. An empty result means the TRC is not pinned.

func (*Engine) IssuerASes

func (e *Engine) IssuerASes(isd addr.ISD) ([]addr.IA, error)

IssuerASes returns the ASes of the given ISD a root certificate in the newest pinned TRC names as its subject — exactly the nodes that can serve a chain renewal, the signal enrollment's core route selects by. An empty result means the TRC is not pinned.

func (*Engine) Sign

func (e *Engine) Sign(
	ctx context.Context,
	msg []byte,
	associatedData ...[]byte,
) (*cryptopb.SignedMessage, error)

Sign signs the message with the associated data using the current signer (control plane draft, Section 2.2.2.6).

func (*Engine) Signer

func (e *Engine) Signer(ctx context.Context) (Signer, error)

Signer returns a signer backed by the node's newest chain valid now: the algorithm is selected for the AS key, the TRC ID cites the newest TRC held locally, and validity and subject come from the chain.

func (*Engine) Verify

func (e *Engine) Verify(
	ctx context.Context,
	signedMsg *cryptopb.SignedMessage,
	associatedData ...[]byte,
) (*signed.Message, error)

Verify verifies the signed message against chains resolved through the engine's provider, with the engine's certificate cache.

func (*Engine) VerifyBound

func (e *Engine) VerifyBound(
	ctx context.Context,
	ia addr.IA,
	signedMsg *cryptopb.SignedMessage,
	associatedData ...[]byte,
) (*signed.Message, error)

VerifyBound verifies the signed message with the signer bound to ia: a signature whose verification key names another ISD-AS fails with the mismatch named. The signed bytes of a beacon's AS entry claim the entry's own ISD-AS; this form reads the claim back to the signer and refuses the difference.

type EnrollmentConfig

type EnrollmentConfig struct {
	// IA is the node's ISD-AS.
	IA addr.IA
	// DB holds the node's chains and the pinned TRC.
	DB trustdb.DB
	// Key is the node's AS key.
	Key crypto.Signer
	// Renewal is the role's part of the lifecycle: FounderRenewal,
	// NormalRenewal, or AuthoritativeRenewal.
	Renewal Renewal
	// RetryInterval and InspectInterval override the defaults; zero keeps
	// them.
	RetryInterval   time.Duration
	InspectInterval time.Duration
}

EnrollmentConfig configures the lifetime chain lifecycle of a node: every node keeps a valid chain — the founding core included — by re-enrolling before expiry, with warnings as expiry approaches and errors once it passes. The Renewal carries what the node's role adds to the loop.

type Issuer

type Issuer struct {
	// IA is the core's ISD-AS.
	IA addr.IA
	// RootKey signs CP CA certificates; its certificate is in the TRC.
	RootKey crypto.Signer
	// CAKey signs AS certificates; its certificate is never in the TRC.
	CAKey crypto.Signer
	// TRC is the base TRC anchoring the issued chains.
	TRC cppki.SignedTRC
	// contains filtered or unexported fields
}

Issuer issues AS certificate chains with the founding core's CP CA key. The chains are two-certificate chains [AS certificate, CP CA certificate] verified against the root pool extracted from the TRC (PKI draft, Section 4.2.2; enforced by cppki.ValidateChain).

func NewIssuer

func NewIssuer(ia addr.IA, keys CoreKeys, trc cppki.SignedTRC) (*Issuer, error)

NewIssuer returns an issuer anchored in the given TRC. The allowlist is handled by the caller, so issuance here is only about correct certificates.

func (*Issuer) CA

func (i *Issuer) CA() (*CA, error)

CA snapshots the issuer's current CA material under the mutex — the rotation's rekey swaps all three as a set.

func (*Issuer) IssueChain

func (i *Issuer) IssueChain(csr *x509.CertificateRequest) ([]*x509.Certificate, error)

IssueChain creates a certificate chain for the subject of the CSR from the issuer's current CA material.

func (*Issuer) Rekey

func (i *Issuer) Rekey(keys CoreKeys, trc cppki.SignedTRC) error

Rekey rekeys the issuer under the successor a rotation pinned: the staged root and CA keys taking the place of the ones it held, the CA certificate minted afresh under the successor's root certificate, the chains issuing under it from the pin on. The successor is already verified and pinned; the live key files catch up when the staged keys are promoted.

type NetworkProvider

type NetworkProvider struct {
	// DB is the local trust database.
	DB trustdb.DB
	// Remote resolves missing trust material over the network. Nil means the
	// provider is local-only.
	Remote Remote
}

NetworkProvider is a DB-first trust.Provider: lookups go to the local database and fall back to a Remote on a miss, caching the result. The founding core runs without a Remote — its DB holds every chain it issued — and a nil Remote resolves to "not found", never a panic.

func (*NetworkProvider) GetChains

func (p *NetworkProvider) GetChains(
	ctx context.Context,
	q trustdb.ChainQuery,
	opts ...Option,
) ([][]*x509.Certificate, error)

GetChains returns the chains matching the query that verify against the anchor pool — the newest pinned TRC's roots, the predecessor's beside them while the newest is within its grace period: the database's when any of them verifies, else the Remote's, which are cached. A stored chain whose root no pooled TRC carries is passed over.

func (*NetworkProvider) GetSignedTRC

func (p *NetworkProvider) GetSignedTRC(
	ctx context.Context,
	id cppki.TRCID,
	opts ...Option,
) (cppki.SignedTRC, error)

GetSignedTRC returns the TRC with the given ID, fetching and validating it from the Remote if it is not in the DB. A base TRC is verified with its own voting certificates; an update is verified against its pinned predecessor — fetched first when it is missing, so a node holding only the base can chain its way to any successor. The numbers-less ID asks the ISD's newest TRC.

func (*NetworkProvider) LocalChains

func (p *NetworkProvider) LocalChains(
	ctx context.Context, q trustdb.ChainQuery) ([][]*x509.Certificate, error)

LocalChains looks up chains in the local database only.

func (*NetworkProvider) LocalTRC

func (p *NetworkProvider) LocalTRC(id cppki.TRCID) (cppki.SignedTRC, error)

LocalTRC looks up the TRC in the local database only.

func (*NetworkProvider) NotifyTRC

func (p *NetworkProvider) NotifyTRC(ctx context.Context, id cppki.TRCID, opts ...Option) error

NotifyTRC ensures the TRC with the given ID is known locally.

type Option

type Option func(o *options)

Option is a function that sets an option.

func AllowInactive

func AllowInactive() Option

AllowInactive allows chains that are verifiable with TRCs that are no longer active.

func Client

func Client(client net.Addr) Option

Client sets the client that spawned the query. This lets the provider decide whether recursive resolution is allowed.

func Server

func Server(server net.Addr) Option

Server sets the server that should be queried in case of a crypto material resolution.

type Provider

type Provider interface {
	// NotifyTRC notifies a provider of the existence of a TRC. When a signature
	// metadata is received that contains base and serial number, this method
	// should be invoked.
	NotifyTRC(context.Context, cppki.TRCID, ...Option) error
	// GetChains returns certificate chains that match the chain query. If no
	// chain is locally available, the provider can resolve them over the
	// network. By default, the provider only returns certificate chains that
	// are verifiable with the currently active TRCs. To configure the behavior,
	// options can be provided.
	GetChains(context.Context, trustdb.ChainQuery, ...Option) ([][]*x509.Certificate, error)
	// GetSignedTRC returns the TRC with the given ID. If the TRC is not
	// available, the provider can resolve it over the network.
	GetSignedTRC(context.Context, cppki.TRCID, ...Option) (cppki.SignedTRC, error)
}

Provider provides crypto material. A crypto provider can spawn network requests if necessary and permitted.

type Remote

type Remote interface {
	// TRC fetches the signed TRC with the given ID.
	TRC(ctx context.Context, id cppki.TRCID) (cppki.SignedTRC, error)
	// Chains fetches the chains matching the query.
	Chains(ctx context.Context, q trustdb.ChainQuery) ([][]*x509.Certificate, error)
	// RenewChain requests a certificate chain for the CSR, proving possession
	// of the subject key with the given signer. It returns the chain carried
	// by the verified renewal response.
	RenewChain(ctx context.Context, csr *x509.CertificateRequest,
		key crypto.Signer) ([]*x509.Certificate, error)
}

Remote resolves trust material over the network, typically from the core's control endpoint.

type Renewal

type Renewal interface {
	// contains filtered or unexported methods
}

Renewal is a role's part of the chain lifecycle RunEnrollment runs: how the node obtains a fresh chain, and the work the role owes once its chain is valid. FounderRenewal, NormalRenewal, and AuthoritativeRenewal build the three.

func AuthoritativeRenewal

func AuthoritativeRenewal(
	remote Remote,
	caster TRCCaster,
	votingKey crypto.Signer,
	votingCert *x509.Certificate,
) Renewal

AuthoritativeRenewal is the joining core's renewal: its chain renewed against the core's endpoint through the remote and, once the chain is valid, the sensitive update that onboards it, owed until the newest pinned TRC names the core — a successor carrying the voting certificate, signed with the voting key as its proof of possession, and submitted through the caster to the founder's voting application.

func FounderRenewal

func FounderRenewal(issuer *Issuer) Renewal

FounderRenewal is the founding core's renewal: its chain self-issued through the issuer that serves the enrollment requests, and nothing more owed.

func NormalRenewal

func NormalRenewal(remote Remote) Renewal

NormalRenewal is the normal node's renewal: its chain renewed against the core's endpoint through the remote, and nothing more owed.

type Roll

type Roll interface {
	// contains filtered or unexported methods
}

Roll is a holder's part of the rotation watch RunRotation runs: whether the live material agrees with the certificates the newest TRC names for the node, and how the holder rolls it. FounderRoll and AuthoritativeRoll build the two.

func AuthoritativeRoll

func AuthoritativeRoll(remote Remote, caster TRCCaster) Roll

AuthoritativeRoll is the authoritative core's roll: its regular voting key checked, and the roll submitted through the caster to the founder's voting application, the channel its join used, the founder's newest TRC resolved through the remote.

func FounderRoll

func FounderRoll(decider *TRCDecider, issuer *Issuer) Roll

FounderRoll is the founding core's roll: its sensitive, regular, and root keys checked, and the roll of all three cast alone inside the decision's CastLocal, serialized with the submissions; once it pins, the decision votes with the fresh sensitive key and the issuer issues under the fresh root.

type RotationConfig

type RotationConfig struct {
	// IA is the core's ISD-AS.
	IA addr.IA
	// DB holds the pinned TRCs.
	DB trustdb.DB
	// State is the state directory whose keys folder holds the voting
	// material: the live files the node signs with, and a roll's staged file
	// until a pinned TRC names it. Each pass promotes a staged file the
	// newest pinned TRC names and rereads the live files, so an operator's
	// replacement of the material, such as the eviction of a compromised
	// key, is seen at the next pass.
	State string
	// Roll is the holder's part of the watch: FounderRoll or
	// AuthoritativeRoll.
	Roll Roll

	// Threshold overrides RotationThreshold; zero keeps it.
	Threshold time.Duration
	// RetryInterval and InspectInterval override the defaults; zero keeps
	// them.
	RetryInterval   time.Duration
	InspectInterval time.Duration
	// Timeout bounds one roll attempt; zero uses the default.
	Timeout time.Duration
}

RotationConfig configures the rotation watch of a core: the loop beside the enrollment loop that rolls the trust material the node itself holds — the founder's sensitive and regular voting certificates and its root certificate, an authoritative core's regular one — before the earliest expiry among them crosses the threshold, or the moment the live keys and the newest TRC's certificates disagree, whatever the calendar says. The Roll carries what the holder adds to the watch.

type Signer

type Signer struct {
	PrivateKey    crypto.Signer
	Algorithm     signed.SignatureAlgorithm
	IA            addr.IA
	Subject       pkix.Name
	Chain         []*x509.Certificate
	SubjectKeyID  []byte
	Expiration    time.Time
	TRCID         cppki.TRCID
	ChainValidity cppki.Validity
	InGrace       bool
}

Signer is used to sign control plane messages with the AS private key.

func (Signer) Equal

func (s Signer) Equal(o Signer) bool

func (Signer) Sign

func (s Signer) Sign(
	ctx context.Context,
	msg []byte,
	associatedData ...[]byte,
) (*cryptopb.SignedMessage, error)

Sign signs the message with the associated data and returns a SignedMessage protobuf payload. The associated data is not included in the header or body of the signed message.

func (Signer) SignCMS

func (s Signer) SignCMS(ctx context.Context, msg []byte) ([]byte, error)

SignCMS signs the message and returns a CMS/PKCS7 encoded payload.

func (Signer) Validity

func (s Signer) Validity() cppki.Validity

type TRCCaster

type TRCCaster interface {
	// SubmitTRC hands the signed successor — the submitter's proofs of
	// possession, and its vote when it rolls by regular update — to the
	// core's decision. It returns the TRC the decision pinned: the successor
	// as submitted when it verified without the founder's vote, the
	// successor carrying the founder's sensitive vote otherwise, or the
	// newest TRC when that already carries the landing. The implementation
	// reports ErrNoVotingApp when nothing answers.
	SubmitTRC(ctx context.Context, trc cppki.SignedTRC) (cppki.SignedTRC, error)
}

TRCCaster submits a TRC update to the core's voting application: the channel a core presents its successor on, an onboarding or a roll, for the control plane behind the application to decide on.

type TRCDecider

type TRCDecider struct {
	// DB serves and pins the founder's TRCs and chains.
	DB trustdb.DB
	// IA is the founding core's ISD-AS, the ISD the updates belong to.
	IA addr.IA
	// Sensitive casts the founder's vote with the sensitive voting key of
	// the newest pinned TRC's certificate set. The decision exists on the
	// founding core alone, built with its sensitive key.
	Sensitive crypto.Signer
	// Authorizer is the policy asked before the founder's sensitive vote on
	// a submission. Nil denies every such vote: the run arguments left the
	// policy unset.
	Authorizer enrollauth.AdmissionAuthorizer
	// contains filtered or unexported fields
}

TRCDecider is the control plane's decision on a submitted TRC update, with no network of its own: the voting application hands each submission over, and the decision is made here. A submission that verifies against the newest pinned TRC as submitted pins as it is, and a sensitive update short of the founder's vote gets the vote only on the admission policy's allow, the completed artifact verified against the newest pinned TRC before it pins. The founder's own casts run through CastLocal instead.

func (*TRCDecider) CastLocal

func (c *TRCDecider) CastLocal(
	ctx context.Context,
	cast func(newest cppki.SignedTRC) error,
) error

CastLocal runs the founder's own cast under the decision's mutex: the founder's roll reads the newest pinned TRC and completes its successor on the same lock the submissions decide under, so the serials stay monotone whichever path a successor takes — a submission the cast overlaps is refused on the older view and retried onto the new newest. The cast may reassign the decision's sensitive signer, the roll's pin landing on it; only the mutex's holders touch the field.

func (*TRCDecider) DecideTRC

func (c *TRCDecider) DecideTRC(
	ctx context.Context,
	presenter addr.IA,
	source netip.AddrPort,
	trc cppki.SignedTRC,
) (cppki.SignedTRC, error)

DecideTRC decides whether the founder accepts the successor a core submitted. A submission whose landing the newest pinned TRC already carries is answered with that TRC — the idempotent re-presentation, read from what the submission holds, never from the presenter's name. Otherwise the update must classify against the newest pinned TRC and the presenter must be the channel's verified peer holding an enrolled chain. Past those gates a submission that verifies as submitted pins as it is, the founder signing nothing; a sensitive update that does not verify yet gets the founder's vote on the admission policy's allow; anything else is refused. What refuses pins nothing.

type Verifier

type Verifier struct {
	// BoundIA when non-zero makes sure that only a signature originated from that IA
	// can be valid.
	BoundIA addr.IA
	// BoundServer binds a remote server to ask for missing crypto material.
	BoundServer net.Addr
	// Engine provides verified certificate chains.
	Engine Provider

	// MaxCacheExpiration bounds how long fetched chains are cached; zero
	// means a minute, and a chain's own validity can shorten the window.
	MaxCacheExpiration time.Duration
	// contains filtered or unexported fields
}

Verifier is used to verify control plane messages using the AS cert stored in the database.

func (Verifier) Verify

func (v Verifier) Verify(ctx context.Context, signedMsg *cryptopb.SignedMessage,
	associatedData ...[]byte) (*signed.Message, error)

Verify verifies the signature of the msg with a chain of the signer valid now.

Directories

Path Synopsis
Package trusttest founds an ISD for other packages' tests: a founding core's keys in a temporary directory, its genesis TRC pinned in the caller's trust database, its issuer, and the enrollment of ISD-ASes under it.
Package trusttest founds an ISD for other packages' tests: a founding core's keys in a temporary directory, its genesis TRC pinned in the caller's trust database, its issuer, and the enrollment of ISD-ASes under it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL