ca

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package ca is the agent host's gateway CA (gateway.md, "The CA"): a name-constrained ECDSA P-256 certificate authority whose leaves the gateway presents for the hosts it intercepts.

The CA lives in a directory of its own (0700): CertFile (0644) and KeyFile (0600, PKCS #8). Its name constraints permit only the intercepted hosts' DNS names, exclude every IP address, and permit URI and email names only under "invalid", so a leaked key can't mint a certificate a client would accept for any other site. Leaves are minted on first use and kept in a bounded in-memory cache; they never touch the disk.

The PoC has no rotation: LoadOrGenerate makes a CA when there is none, and an expired or out-of-date one is replaced by removing its directory.

Index

Constants

View Source
const (
	CertFile = "ca.pem"
	KeyFile  = "ca.key"
)

The CA directory's files.

Variables

View Source
var ErrInvalid = errors.New("ca: invalid gateway CA")

ErrInvalid is wrapped by every refusal of Load: a file of the wrong kind, mode or owner, a certificate that isn't a CA or isn't valid now, or a key that doesn't match it.

Functions

This section is empty.

Types

type CA

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

CA signs the gateway's leaves. It is safe for concurrent use.

func Generate

func Generate(ctx context.Context, dir string, clk clock.Clock) (*CA, error)

Generate makes a new CA in dir (created 0700 when missing) and returns it. It refuses to replace an existing CertFile or KeyFile. clk times the CA's and its leaves' validity.

func Load

func Load(ctx context.Context, dir string, clk clock.Clock) (*CA, error)

Load reads the CA in dir. Both files are read through one handle on the directory. It refuses (ErrInvalid) a KeyFile that isn't a regular file of this user's with mode 0600, a certificate that isn't a CA or isn't valid on clk, and a key that doesn't match it. A missing directory or file is an fs.ErrNotExist error.

func LoadOrGenerate

func LoadOrGenerate(ctx context.Context, dir string, clk clock.Clock) (*CA, error)

LoadOrGenerate loads the CA in dir, or generates one when the directory or the certificate doesn't exist.

func (*CA) CertPEM

func (c *CA) CertPEM() []byte

CertPEM is the CA certificate in PEM: the public half a workspace's bundle carries.

func (*CA) Certificate

func (c *CA) Certificate() *x509.Certificate

Certificate is the parsed CA certificate.

func (*CA) Leaf

func (c *CA) Leaf(host string) (*tls.Certificate, error)

Leaf is the leaf certificate for host, one of policy.InterceptedHosts (normalised): minted on first use, valid from an hour before for 7 days (capped at the CA's NotAfter), and minted again when less than an hour is left. Its chain holds the CA.

func (*CA) Pool

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

Pool is a certificate pool holding only the CA.

Jump to

Keyboard shortcuts

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