Documentation
¶
Overview ¶
Package testca is a small certificate authority for the tests of the approver identity feature (docs/design/approver-identity.md, "Test plan"). It uses only the standard library, builds roots, intermediates and leaves with chosen keys, validity, names and extensions, and is deterministic where the tests need it to be: every time is an argument, nothing reads the clock.
It is test support. Nothing outside tests imports it.
Index ¶
- Variables
- func NewKey(tb testing.TB, k KeyKind) crypto.Signer
- func Person(n int) string
- func Revoked(cert *x509.Certificate, t time.Time, code int) x509.RevocationListEntry
- func WithInvalidity(e x509.RevocationListEntry, inv time.Time) x509.RevocationListEntry
- type CA
- func (c *CA) NewCRL(tb testing.TB, o CRLOpts) []byte
- func (c *CA) NewIntermediate(tb testing.TB, name string, o Opts) *CA
- func (c *CA) NewLeaf(tb testing.TB, o Opts) *Leaf
- func (c *CA) RawCRL(tb testing.TB, o RawCRLOpts) []byte
- func (c *CA) TryCRL(o CRLOpts) ([]byte, error)
- func (c *CA) TryLeaf(tb testing.TB, o Opts) (*Leaf, error)
- type CRLOpts
- type KeyKind
- type Leaf
- type Opts
- type RawCRLOpts
- type RawEntry
Constants ¶
This section is empty.
Variables ¶
var ( // EKU is the bank-assigned private extended key usage the approver certificates carry. EKU = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 99999, 1, 1} // PolicyOID is the certificate policy the bank's CA asserts after MFA step-up and a hardware key. PolicyOID = mustOID("1.3.6.1.4.1.99999.2.1") )
var T0 = time.Date(2026, 10, 1, 12, 0, 0, 0, time.UTC)
T0 is the instant the tests treat as "now". Certificates are issued around it.
Functions ¶
func Person ¶
Person returns the opaque person URI the default identity profile accepts for host "idp.bank.example" and the 32 hex digits made of n.
func Revoked ¶
func Revoked(cert *x509.Certificate, t time.Time, code int) x509.RevocationListEntry
Revoked is an entry for the serial of cert revoked at t with reason code code (0 omits it).
func WithInvalidity ¶
func WithInvalidity(e x509.RevocationListEntry, inv time.Time) x509.RevocationListEntry
WithInvalidity adds an invalidity date (entry extension 2.5.29.24) to e.
Types ¶
type CA ¶
type CA struct {
Cert *x509.Certificate
Key crypto.Signer
DER []byte
// contains filtered or unexported fields
}
CA is a certificate authority: a certificate and the key that signs for it.
func (*CA) NewIntermediate ¶
NewIntermediate returns a CA issued by c.
func (*CA) NewLeaf ¶
NewLeaf issues an approver certificate: one URI SAN (Person(1)), digital signature, the bank EKU and the bank policy, valid from an hour before T0 to an hour after it. Mutate changes any of it.
func (*CA) RawCRL ¶
func (c *CA) RawCRL(tb testing.TB, o RawCRLOpts) []byte
RawCRL builds and signs a CRL by marshalling the TBSCertList itself.
type CRLOpts ¶
type CRLOpts struct {
Number int64
ThisUpdate time.Time
NextUpdate time.Time
Entries []x509.RevocationListEntry
Extra []pkix.Extension // raw CRL extensions, such as the delta indicator or expiredCertsOnCRL
SigAlg x509.SignatureAlgorithm
}
CRLOpts shapes one CRL signed by a CA.
type Leaf ¶
type Leaf struct {
Cert *x509.Certificate
Key crypto.Signer
DER []byte
// contains filtered or unexported fields
}
Leaf is an issued end-entity certificate with its key.
func (*Leaf) Chain ¶
Chain returns the leaf-first DER chain a decision carries: the leaf, then every issuing CA up to but excluding the root (the root is the trust anchor the verifier holds).
func (*Leaf) ChainWithRoot ¶
ChainWithRoot is Chain plus the root, for tests that show a carried root is ignored.
type Opts ¶
type Opts struct {
Key KeyKind // the new certificate's key kind (default P-256)
KeyWith crypto.Signer // use this key instead of generating one
Mutate func(*x509.Certificate) // last word on the template, before signing
SigAlg x509.SignatureAlgorithm // the signature algorithm, when the default is not wanted
}
Opts shapes one certificate. The zero value gives the default for the certificate's role.
type RawCRLOpts ¶
type RawCRLOpts struct {
Number *big.Int // nil omits the cRLNumber extension
This, Next time.Time
OmitNext bool
OmitVersion bool // a version 1 CRL (no version field)
Serials []*big.Int // revoked at This, no extensions
Entries []RawEntry // revoked entries with their own times and extensions
Extensions []pkix.Extension
PadBytes int // adds a non-critical unknown extension of about this many bytes
// InnerAlg and OuterAlg override the signature algorithm identifiers in the TBSCertList and in
// the CertificateList (the signature itself is still the CA key's). OuterParams is the full DER of
// the outer identifier's parameters (for RSASSA-PSS).
InnerAlg, OuterAlg asn1.ObjectIdentifier
OuterParams []byte
// Indefinite re-encodes the outer SEQUENCE with an indefinite length (BER).
Indefinite bool
// NoAKI omits the authority key identifier extension.
NoAKI bool
}
RawCRLOpts shapes a hand-built CRL for inputs the standard library will not create: a missing CRL number, missing or backwards times, odd algorithm identifiers, padding. The CRL is signed with the CA's key (ECDSA P-256 or Ed25519 CAs only) so it verifies unless the options say otherwise; only its content is malformed.