testpki

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package testpki creates ephemeral certificate authorities and identities for tests and the device simulator.

Design

Shared fixtures provide device signing identities, TLS server certificates and APNs-topic certificates with consistent chain structure. Keys are generated at test time and validity is short. These helpers do not apply production issuance policy and their roots must not be trusted outside tests. Production signing uses pki/ca with configured keys, policy and storage.

References

Index

Constants

This section is empty.

Variables

View Source
var ErrNilKey = errors.New("testpki: nil key")

ErrNilKey is returned when no key is supplied.

Functions

This section is empty.

Types

type CA

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

CA is a test certificate authority.

func NewCA

func NewCA(name string) (*CA, error)

NewCA creates a self-signed RSA CA valid for one day.

func (*CA) Issue

func (ca *CA) Issue(commonName string, notBefore time.Time) (*Identity, error)

Issue signs a device identity (ECDSA P-256) with the given common name, valid from notBefore for one day.

func (*CA) IssueApp added in v0.3.0

func (ca *CA) IssueApp(topic string, notBefore time.Time) (*Identity, error)

IssueApp signs a provider identity whose Apple topic extension authorizes ordinary app notifications. It does not authorize MDM pushes.

func (*CA) IssuePush

func (ca *CA) IssuePush(topic string, notBefore time.Time) (*Identity, error)

IssuePush signs an APNs push certificate (RSA 2048, like the ones Apple issues) whose subject UID carries topic, valid from notBefore for one day.

func (*CA) IssuePushWithKey

func (ca *CA) IssuePushWithKey(
	topic string,
	notBefore time.Time,
	key crypto.Signer,
) (*Identity, error)

IssuePushWithKey signs an APNs push certificate for an existing key with the subject UID set to topic.

func (*CA) IssueWithKey

func (ca *CA) IssueWithKey(
	commonName string,
	notBefore time.Time,
	key crypto.Signer,
) (*Identity, error)

IssueWithKey signs a device identity for an existing key.

func (*CA) Pool

func (ca *CA) Pool() *x509.CertPool

Pool returns a pool containing only this CA.

type Identity

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

Identity is a certificate with its private key.

func (*Identity) PEM

func (i *Identity) PEM() (certPEM, keyPEM []byte, err error)

PEM encodes the certificate as a CERTIFICATE block and the key as a PKCS#8 PRIVATE KEY block.

Jump to

Keyboard shortcuts

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