certgen

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 14 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 certgen generates the certificate material a farm needs to run sqi over TLS: a farm certificate authority, server certificates for the API listener and the embedded broker, and client certificates for the optional worker mTLS path.

It sets the SANs and extended key usage that hand-rolled openssl invocations commonly get wrong, a mistake that otherwise surfaces only at worker-connect time rather than at load.

The same generator backs `sqi-server tls init`, `sqi-server tls issue` and the test suites, so tests exercise the shipped code path and need no checked-in certificate fixtures, which expire.

Index

Constants

This section is empty.

Variables

View Source
var ErrCAExists = errors.New("certgen: CA already exists")

ErrCAExists is returned by WriteCA when dir already holds a CA key. Regenerating a farm CA in place invalidates every certificate issued from it, so the caller must move the old one aside first.

Functions

func WriteCA

func WriteCA(dir string, ca *CA) error

WriteCA writes ca.crt (world-readable) and ca.key (owner-only, enforced by fsutil.WriteSecret on both platforms) into dir. It refuses to overwrite an existing ca.key.

func WriteLeaf

func WriteLeaf(dir, name string, leaf *Leaf) error

WriteLeaf writes <name>.crt (world-readable) and <name>.key (owner-only, enforced by fsutil.WriteSecret on both platforms) into dir.

Types

type CA

type CA struct {
	Cert    *x509.Certificate
	Key     *ecdsa.PrivateKey
	CertPEM []byte
	KeyPEM  []byte
}

CA is a generated certificate authority held in memory.

func LoadCA

func LoadCA(certPEM, keyPEM []byte) (*CA, error)

LoadCA reconstructs a CA from PEM material previously written by WriteCA, so certificates can be issued from a farm CA that already exists. `tls issue` uses it to add a worker to an established mTLS farm or rotate a server certificate without replacing the CA (`tls init` refuses to overwrite one).

func NewCA

func NewCA(commonName string, validFor time.Duration) (*CA, error)

NewCA generates a self-signed certificate authority valid for validFor.

func (*CA) NewClientCert

func (ca *CA) NewClientCert(commonName string, validFor time.Duration) (*Leaf, error)

NewClientCert signs a client certificate for the worker mTLS path. The common name is informational: sqi does not bind a certificate to a worker identity — the nkey does that. See docs/tls.md.

func (*CA) NewServerCert

func (ca *CA) NewServerCert(hosts []string, validFor time.Duration) (*Leaf, error)

NewServerCert signs a server certificate covering hosts. Entries that parse as an IP address become IP SANs; the rest become DNS SANs.

The validity window starts an hour in the past, so a certificate is usable immediately on a host whose clock runs slightly behind the issuer's.

func (*CA) NewServerCertNotBefore

func (ca *CA) NewServerCertNotBefore(hosts []string, notBefore time.Time, validFor time.Duration) (*Leaf, error)

NewServerCertNotBefore is CA.NewServerCert with an explicit start to the validity window, for a certificate minted ahead of a scheduled rollout.

type Leaf

type Leaf struct {
	CertPEM []byte
	KeyPEM  []byte
}

Leaf is a generated end-entity certificate held in memory.

Jump to

Keyboard shortcuts

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