testtls

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package testtls issues certificate material for tests that need real TLS sockets: one authority, the identities it signs, and the unusable variants a verification test has to reject. Everything is generated in the running process and written into a caller-owned directory, so no key is checked in and no test depends on an external tool.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Authority

type Authority struct {
	Identity
	// contains filtered or unexported fields
}

Authority signs identities and is the trust root its peers configure.

func NewAuthority

func NewAuthority(dir, name string) (*Authority, error)

NewAuthority creates a self-signed authority in dir. Its CertFile is the PEM file a peer names as its trust root.

func NewExpiredAuthority

func NewExpiredAuthority(dir, name string) (*Authority, error)

NewExpiredAuthority creates an authority whose own certificate has expired, for the checks that refuse a root no chain could be built on.

func (*Authority) ClientConfig

func (a *Authority) ClientConfig(identity *Identity, serverName string) *tls.Config

ClientConfig verifies the peer against this authority. A nil identity sends no client certificate, which is what an unenrolled peer looks like.

func (*Authority) Issue

func (a *Authority) Issue(name string, opts Options) (*Identity, error)

Issue signs one identity and writes it next to the authority.

func (*Authority) Pool

func (a *Authority) Pool() *x509.CertPool

Pool returns the authority as a verification root.

func (*Authority) ServerConfig

func (a *Authority) ServerConfig(identity *Identity, requireClient bool) *tls.Config

ServerConfig is a listener profile that verifies client certificates the authority issued when required, and requests none otherwise.

type Identity

type Identity struct {
	CertFile, KeyFile string
	CertPEM, KeyPEM   []byte
	Certificate       tls.Certificate
}

Identity is one issued certificate with its private key, held in memory and written as the PEM files a daemon configuration names.

type Options

type Options struct {
	// Hosts are the DNS names and IP addresses the certificate carries.
	Hosts []string
	// Client and Server select the extended key usages. Neither selected is
	// a server identity, which is what most fixtures need.
	Client, Server bool
	// NotBefore and NotAfter bound validity; zero spans an hour around now.
	NotBefore, NotAfter time.Time
}

Options selects what an issued identity is usable for. The zero value is a server identity valid for an hour around now and carrying no name.

Jump to

Keyboard shortcuts

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