Documentation
¶
Overview ¶
Package ca is an in-memory certificate authority for tests and examples.
It is the error-returning core beneath authtest.CA. The split exists because authtest reports failures through testing.TB, which a program that is not a test cannot supply: the examples mint their own credentials at startup, and an example binary should not link the testing package to do it.
Nothing here belongs to purser's exported surface. Consumers get the test-shaped wrapper in authtest; the examples reach this directly because they live inside the module.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodePEM ¶
func EncodePEM(cert tls.Certificate) (certPEM, keyPEM []byte, err error)
EncodePEM renders a minted certificate as the two PEM documents a file-backed credential source reads: the chain, leaf first, and the PKCS#8 private key.
Leaf first is not a stylistic choice. Both crypto/tls and x509svid.Parse read element zero as the leaf and treat the remainder as intermediates, so a chain written root-first authenticates as the root — or, far more often, fails to parse at all.
Types ¶
type CA ¶
type CA struct {
// contains filtered or unexported fields
}
CA is an in-memory certificate authority. Use it to mint client and server certificates for handshake tests, and to build the trust pool a verifier is configured with.
A caller that needs an untrusted-issuer negative creates a second CA and offers its leaf to a verifier configured with the first CA's pool.
func New ¶
New returns a fresh self-signed authority named name. The name appears in the issuer DN, so give the trusted and untrusted authorities in a test distinguishable names: it is the difference between a legible failure and "x509: certificate signed by unknown authority".
func (*CA) Cert ¶
func (ca *CA) Cert() *x509.Certificate
Cert returns the authority's own certificate.
func (*CA) CertPEM ¶
CertPEM returns the authority's certificate in PEM form — the trust anchor file a file-backed verifier is pointed at.
func (*CA) Issue ¶
func (ca *CA) Issue(opts LeafOptions) (tls.Certificate, error)
Issue mints and signs a leaf certificate. The returned tls.Certificate carries the leaf's parsed form in its Leaf field and the issuing CA in its chain, so it can be presented directly by either side of a handshake.
func (*CA) IssueClient ¶
func (ca *CA) IssueClient(cn string) (tls.Certificate, error)
IssueClient mints a client certificate whose subject CN is cn. A shorthand for the common case; reach for Issue when the caller cares about SANs or validity.
func (*CA) IssueServer ¶
func (ca *CA) IssueServer(host string) (tls.Certificate, error)
IssueServer mints a server certificate valid for host, which may be a DNS name or an IP literal.
type LeafOptions ¶
type LeafOptions struct {
// CommonName sets the subject CN.
CommonName string
// Organization and OrganizationalUnit set the corresponding
// subject RDNs, for authenticators that match on OU membership or
// render the full DN as the identity.
Organization []string
OrganizationalUnit []string
// EmailSANs, DNSSANs, and IPSANs populate the matching subject
// alternative names.
EmailSANs []string
DNSSANs []string
IPSANs []net.IP
// URISANs populates URI subject alternative names. SPIFFE IDs go
// here: a SPIFFE X.509-SVID is an ordinary certificate whose sole
// URI SAN is a spiffe:// identity, so this mints one without
// depending on go-spiffe.
URISANs []string
// NotBefore and NotAfter override the validity window. Zero means
// an hour ago and an hour from now respectively; set NotAfter to a
// past instant for the expired-certificate case.
NotBefore time.Time
NotAfter time.Time
// ExtKeyUsage overrides the extended key usage. Nil means client
// authentication.
ExtKeyUsage []x509.ExtKeyUsage
}
LeafOptions describes a certificate to mint. The zero value yields a client certificate valid from an hour ago until an hour from now, with no subject and no SANs — useful in itself, as the certificate that carries none of the fields an authenticator might read.