pkitest

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 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

Overview

Package pkitest builds small test PKIs at test time: a root, intermediates and leaf variants with exactly the properties a fixture needs. Keys are ECDSA P-256 (fast) unless a fixture asks for RSA. Test support only.

Index

Constants

This section is empty.

Variables

View Source
var Epoch = time.Date(2026, 6, 1, 0, 0, 0, 0, time.UTC)

Epoch is a fixed reference time fixtures are built around, so tests pass their own "now" instead of reading the clock.

Functions

func DER

func DER(certs ...*x509.Certificate) [][]byte

DER returns the raw encodings, in the given order.

func SCT

func SCT(s SCTSpec) []byte

SCT returns one serialized SCT body (RFC 6962 §3.2) with a dummy signature.

func SCTList

func SCTList(scts []SCTSpec) []byte

SCTList returns a TLS-encoded SignedCertificateTimestampList.

func SmallScalarKey added in v0.4.1

func SmallScalarKey(t testing.TB, curve elliptic.Curve, d int64) *ecdsa.PrivateKey

SmallScalarKey returns the ECDSA key whose private scalar is d on curve: the class of key behind the eMudhra compromise (P-384, d < 256), where the public key is d·G and anyone can recover d by counting.

Types

type CA

type CA struct {
	Cert *x509.Certificate
	Key  crypto.Signer
}

CA is a certificate authority that can issue.

func NewRoot

func NewRoot(t testing.TB, name string, o CAOpts) *CA

NewRoot makes a self-signed root.

func (*CA) CRL added in v0.4.1

func (ca *CA) CRL(t testing.TB, revoked []x509.RevocationListEntry, thisUpdate, nextUpdate time.Time) *x509.RevocationList

CRL issues a CRL under ca listing revoked, valid from thisUpdate to nextUpdate.

func (*CA) CrossSign added in v0.4.1

func (ca *CA) CrossSign(t testing.TB, sub *CA, o CAOpts) *x509.Certificate

CrossSign issues a second certificate for sub's name and key under ca: the same CA reachable through another issuer.

func (*CA) Intermediate

func (ca *CA) Intermediate(t testing.TB, name string, o CAOpts) *CA

Intermediate issues a subordinate CA.

func (*CA) IntermediateWithKey added in v0.4.1

func (ca *CA) IntermediateWithKey(t testing.TB, name string, o CAOpts, k *ecdsa.PrivateKey) *CA

IntermediateWithKey issues a subordinate CA for a key the test chose, for example a deliberately weak one from SmallScalarKey.

func (*CA) Leaf

func (ca *CA) Leaf(t testing.TB, o LeafOpts) *x509.Certificate

Leaf issues an end-entity certificate.

func (*CA) LeafKey

func (ca *CA) LeafKey(t testing.TB, o LeafOpts) (*x509.Certificate, crypto.Signer)

LeafKey is Leaf that also returns the private key (nil for RSAExponent).

func (*CA) TLS

func (ca *CA) TLS(t testing.TB, o LeafOpts, chain ...*x509.Certificate) tls.Certificate

TLS returns a leaf (with its key) and the given chain as a tls.Certificate a test server can present.

type CAOpts

type CAOpts struct {
	NotBefore, NotAfter time.Time // default Epoch-1y .. Epoch+10y
	PermittedDNS        []string
	EKU                 []x509.ExtKeyUsage
	CRL                 []string // CRL distribution points the CA certificate names
}

CAOpts shape a CA certificate.

type LeafOpts

type LeafOpts struct {
	CN                  string
	DNS                 []string
	IPs                 []net.IP
	NotBefore, NotAfter time.Time
	EKU                 []x509.ExtKeyUsage // default serverAuth
	NoEKU               bool
	MustStaple          bool
	OCSP, CRL, AIA      []string
	SCTs                []SCTSpec
	RSAExponent         int      // >0: an RSA-2048 key with this public exponent
	Policies            []string // dotted OIDs
}

LeafOpts shape a leaf certificate. The zero value is a valid serverAuth leaf for "leaf.test", issued a month before Epoch and valid 90 days.

type SCTSpec

type SCTSpec struct {
	LogID     [32]byte
	Timestamp time.Time
}

SCTSpec is one SCT to embed in a leaf.

Jump to

Keyboard shortcuts

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