tlsconftest

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package tlsconftest issues throwaway certificates for tests that need TLS or mutual TLS, in the spirit of net/http/httptest.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pair

type Pair struct {
	Cert *x509.Certificate
	Key  *ecdsa.PrivateKey
}

Pair is a certificate and its private key.

func NewCA

func NewCA(t testing.TB, name string) Pair

NewCA is a self-signed certificate authority named name.

func SelfSigned

func SelfSigned(t testing.TB, tmpl *x509.Certificate) Pair

SelfSigned issues tmpl signed by its own fresh key. It fills in the serial number and a validity window around now.

func (Pair) CertPEM

func (p Pair) CertPEM() []byte

CertPEM is the certificate in PEM.

func (Pair) Client

func (p Pair) Client(t testing.TB, cn string) Pair

Client is a client certificate from p named cn.

func (Pair) Issue

func (p Pair) Issue(t testing.TB, tmpl *x509.Certificate) Pair

Issue signs tmpl with p, which must be a CA.

func (Pair) IssueCert

func (p Pair) IssueCert(t testing.TB, tmpl *x509.Certificate, pub crypto.PublicKey) *x509.Certificate

IssueCert signs tmpl with p, which must be a CA, over pub of any type.

func (Pair) IssueKey

func (p Pair) IssueKey(t testing.TB, tmpl *x509.Certificate, key *ecdsa.PrivateKey) Pair

IssueKey signs tmpl with p, which must be a CA, over key.

func (Pair) Pool

func (p Pair) Pool() *x509.CertPool

Pool is a pool holding only p.

func (Pair) Renew

func (p Pair) Renew(t testing.TB, leaf Pair) Pair

Renew is a new certificate from p over leaf's key, with leaf's subject, names and usage, the way cert-manager renews without rotating the key.

func (Pair) Server

func (p Pair) Server(t testing.TB) Pair

Server is a server certificate from p for localhost and 127.0.0.1.

func (Pair) TLS

func (p Pair) TLS() tls.Certificate

TLS is p as a certificate to present in a handshake.

func (Pair) Thumbprint

func (p Pair) Thumbprint(t testing.TB) string

Thumbprint is the RFC 7638 thumbprint of p's key, the cnf jkt of a grant bound to p. It is computed here because tlsconf's internal tests import this package, so importing tlsconf would be a cycle.

func (Pair) UnnamedClient

func (p Pair) UnnamedClient(t testing.TB) Pair

UnnamedClient is a client certificate from p over a fresh P-224 key. Go issues and parses the curve, and the key has no RFC 7638 thumbprint, so the certificate names no caller.

func (Pair) Write

func (p Pair) Write(t testing.TB, dir, name string) (certFile, keyFile string)

Write stores the certificate and key as PEM files name.crt and name.key in dir, and returns their paths.

Jump to

Keyboard shortcuts

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