ca

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package ca is pano's local certificate authority: it generates a root CA on first run, mints per-host leaf certificates on demand for TLS interception, and (on macOS) installs/uninstalls trust in the login keychain.

Index

Constants

View Source
const (
	DefaultRootTTL = 2 * 365 * 24 * time.Hour // default root validity
	MaxRootTTL     = 825 * 24 * time.Hour     // hard cap (Apple's classic ceiling)
	DefaultLeafTTL = 30 * 24 * time.Hour
	MaxLeafTTL     = 397 * 24 * time.Hour // Apple rejects longer TLS server certs
	// RenewWarning is how long before root expiry status output starts nagging.
	RenewWarning = 30 * 24 * time.Hour
	// SubjectPrefix starts every root CN pano has ever generated; the rest is
	// "<hostname>, <date>)" so rotated roots never collide in a trust store.
	SubjectPrefix = "pano Root CA ("
)

Lifetimes. A leaked root key is only useful until the root expires, so the root is short-lived for a CA (two years, like a private dev CA, not the ten most MITM tools ship) and is regenerated automatically once it lapses.

Variables

View Source
var ErrUnsupported = errors.New("ca: automatic trust install is not supported on this OS")

ErrUnsupported is returned when the OS trust store is not automated.

Functions

This section is empty.

Types

type Authority

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

Authority mints leaf certificates signed by a local root.

func Load

func Load(opts Options) (*Authority, error)

Load opens the authority at the given paths, generating a root CA and leaf key if they do not exist. An expired root is replaced by a fresh one (see RotatedFrom). Key files must be mode 0600.

func (*Authority) CertFor

func (a *Authority) CertFor(host string) (*tls.Certificate, error)

CertFor returns a certificate valid for host (DNS name or IP).

func (*Authority) CertPEM

func (a *Authority) CertPEM() []byte

CertPEM returns the root certificate in PEM form.

func (*Authority) ExpiryWarning

func (a *Authority) ExpiryWarning() string

ExpiryWarning returns a human sentence when the root is within RenewWarning of expiring (or has been rotated), else "". Front ends print it verbatim.

func (*Authority) GetCertificate

func (a *Authority) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, error)

GetCertificate implements tls.Config.GetCertificate.

func (*Authority) NotAfter

func (a *Authority) NotAfter() time.Time

NotAfter returns when the root expires.

func (*Authority) Root

func (a *Authority) Root() *x509.Certificate

Root returns the parsed root certificate.

func (*Authority) RotatedFrom

func (a *Authority) RotatedFrom() string

RotatedFrom returns the subject of the expired root this Load replaced, or "" when the root on disk was reused. A rotated root must be trusted again.

func (*Authority) Subject

func (a *Authority) Subject() string

Subject returns the root CN, used to find it in trust stores.

func (*Authority) TLSConfig

func (a *Authority) TLSConfig() *tls.Config

TLSConfig returns a server config that mints certificates on demand and offers HTTP/2 and HTTP/1.1 via ALPN.

func (*Authority) TLSConfigForClient

func (a *Authority) TLSConfigForClient() *tls.Config

TLSConfigForClient returns a client config that trusts this authority, used when pano sends requests through its own proxy (replays).

type Options

type Options struct {
	CertFile, KeyFile, LeafKeyFile, CacheDir string
	RootTTL                                  time.Duration // default DefaultRootTTL, capped at MaxRootTTL
	LeafTTL                                  time.Duration // default DefaultLeafTTL, capped at MaxLeafTTL
	MemCache                                 int           // default 4096
	Organization                             string        // default "pano"
}

Options tune the authority.

type TargetConn

type TargetConn interface {
	net.Conn
	ConnectTarget() string
}

TargetConn is implemented by connections that know the CONNECT target, so a certificate can be chosen even when the ClientHello carries no SNI.

type TrustStatus

type TrustStatus struct {
	Supported bool   `json:"supported"`
	Installed bool   `json:"installed"`
	Detail    string `json:"detail,omitempty"`
}

TrustStatus describes whether the root is trusted by the OS.

type TrustStore

type TrustStore interface {
	Install(ctx context.Context, certPath, subject string, system bool) error
	Uninstall(ctx context.Context, certPath, subject string) error
	Status(ctx context.Context, certPath, subject string) TrustStatus
	// ManualInstructions returns human steps for platforms without automation.
	ManualInstructions(certPath string) string
}

TrustStore installs the root into the operating system trust store.

func NewTrustStore

func NewTrustStore() TrustStore

NewTrustStore returns a store that only prints instructions.

Jump to

Keyboard shortcuts

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