certposture

package
v0.81.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Window is the default challenge window. A nonce stays valid through the window
	// after the one it was issued in, so a peer re-proves possession of its key between
	// once and twice per window. One window early is accepted too, for clock skew.
	Window = 12 * time.Hour

	// EnvWindow overrides Window, for end-to-end tests that cannot wait half a day to
	// watch a renewal. Every management instance has to be given the same value: the
	// window is part of the nonce, so instances that disagree reject each other's.
	EnvWindow = "NB_CERT_CHALLENGE_WINDOW"

	// NonceSize is the length of every nonce a Challenger issues.
	NonceSize = nonceLen
)
View Source
const (
	SigAlgECDSASHA256  = "ecdsa-sha256"
	SigAlgECDSASHA384  = "ecdsa-sha384"
	SigAlgRSAPSSSHA256 = "rsa-pss-sha256"
	SigAlgEd25519      = "ed25519"
)

Variables

View Source
var (
	ErrNonceMalformed = errors.New("certificate challenge nonce is malformed")
	ErrNonceExpired   = errors.New("certificate challenge nonce is expired")
	ErrNonceMismatch  = errors.New("certificate challenge nonce was not issued to this peer")
)
View Source
var (
	ErrUnsupportedKey   = errors.New("unsupported certificate key")
	ErrEmptyChain       = errors.New("certificate chain is empty")
	ErrSignatureInvalid = errors.New("certificate proof signature is invalid")
	ErrSigAlgMismatch   = errors.New("signature algorithm does not match the certificate key")
)
View Source
var ErrNoCertificateInPEM = errors.New("no certificate found in PEM data")

Functions

func AnyChainMatchesCAs

func AnyChainMatchesCAs(chainPEMs, caPEMs []string, now time.Time) bool

AnyChainMatchesCAs reports whether at least one of the peer's verified chains is anchored in one of the configured CAs.

func ChainMatchesCAs

func ChainMatchesCAs(chainPEM string, caPEMs []string, now time.Time) bool

ChainMatchesCAs is VerifyChain over the PEM forms stored in peer meta and check config.

func EffectiveWindow

func EffectiveWindow() time.Duration

EffectiveWindow returns the challenge window in force, which is Window unless EnvWindow overrides it. Everything timed against the window derives from this, so a test that shortens it shortens the renewal that goes with it.

func EncodeChainPEM

func EncodeChainPEM(chain []*x509.Certificate) string

func NonceAcceptedAlongside

func NonceAcceptedAlongside(nonce, current []byte) bool

NonceAcceptedAlongside reports whether a proof answering nonce is still accepted while management issues current to the same peer, by the same window rule verification uses.

func ParseCAs

func ParseCAs(pems []string) (*x509.CertPool, error)

ParseCAs builds a root pool from PEM encoded CA certificates.

func ParseChainPEM

func ParseChainPEM(chainPEM string) ([]*x509.Certificate, error)

func Sign

func Sign(signer crypto.Signer, nonce, peerKey []byte) (string, []byte, error)

Sign produces the proof signature for a nonce using the leaf's private key. The key never leaves the signer, which may be backed by a file, a TPM or an OS keystore.

func VerifiedChain

func VerifiedChain(leaf *x509.Certificate, intermediates []*x509.Certificate, roots *x509.CertPool, now time.Time) ([]*x509.Certificate, error)

VerifiedChain finds a path from leaf to one of roots through any of intermediates, trying every candidate issuer rather than the first that matches, and returns it without the root, leaf first. It applies the same rules as VerifyChain.

func VerifyChain

func VerifyChain(chain []*x509.Certificate, roots *x509.CertPool, now time.Time) error

VerifyChain reports whether the leaf (chain[0]) chains to one of roots using the remaining certificates as intermediates.

Types

type Challenger

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

Challenger issues and verifies stateless per-peer nonces. A nonce is bound to the peer and to a time window, so any instance sharing the secret can verify it.

func NewChallenger

func NewChallenger(secret []byte) *Challenger

func (*Challenger) Nonce

func (c *Challenger) Nonce(peerKey []byte, now time.Time) []byte

func (*Challenger) Verify

func (c *Challenger) Verify(proof Proof, peerKey []byte, now time.Time) ([]*x509.Certificate, error)

Verify checks that the proof's nonce was issued by this challenger to peerKey and is still fresh, and that the signature validates against the leaf's public key. It returns the parsed chain on success. Chain trust is deliberately not evaluated here.

type Proof

type Proof struct {
	Nonce     []byte
	Chain     [][]byte
	SigAlg    string
	Signature []byte
}

Proof is a client's demonstration that it holds the private key of the leaf certificate in Chain, made by signing the challenge nonce bound to its peer key.

Directories

Path Synopsis
Package certtest builds throwaway CAs and leaf certificates for certificate posture tests.
Package certtest builds throwaway CAs and leaf certificates for certificate posture tests.

Jump to

Keyboard shortcuts

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