ca

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: GPL-3.0 Imports: 15 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 ca manages the certificate authority used to terminate TLS for intercepted hosts.

The material is generated once and then reused, so the trust anchor a client was told to trust keeps working across restarts. Three files are kept:

ca.crt   the root certificate — the trust anchor clients install
tls.crt  the server certificate for the intercepted hosts
tls.key  its private key, mode 0600

The root's private key is deliberately not among them. It is generated in memory, used once to sign ca.crt and tls.crt, and discarded before the proxy serves anything. Nothing on disk can therefore mint a certificate for a host that is not already in tls.crt: a leaked tls.key impersonates exactly the intercepted hosts, where a leaked CA key would have impersonated anything.

The cost of not keeping the root key is that new material — a new trust anchor — is needed whenever the certificates expire or the set of intercepted hosts grows, and clients have to trust the new ca.crt at that point.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CertPathIn

func CertPathIn(dir string) string

CertPathIn reports where the root certificate lives for a given directory, without creating anything.

func ReadCert

func ReadCert(dir string) ([]byte, error)

ReadCert returns the root certificate previously written to dir.

Types

type Bundle

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

Bundle is the certificate material for one run.

func Open

func Open(dir string, hosts []string) (*Bundle, error)

Open returns the certificate material for hosts, reusing what is stored in dir when it is still valid and covers every host, and creating it otherwise.

func (*Bundle) CertPEM

func (b *Bundle) CertPEM() []byte

CertPEM returns the PEM-encoded root certificate.

func (*Bundle) CertPath

func (b *Bundle) CertPath() string

CertPath reports the PEM file holding the root certificate. This is the file clients must trust (for Claude Code: NODE_EXTRA_CA_CERTS).

func (*Bundle) GetCertificate

func (b *Bundle) GetCertificate(fallbackHost string) func(*tls.ClientHelloInfo) (*tls.Certificate, error)

GetCertificate is a tls.Config.GetCertificate callback. It falls back to fallbackHost when the client omits SNI or asks for a name this bundle does not cover.

func (*Bundle) Hosts

func (b *Bundle) Hosts() []string

Hosts lists the names this bundle serves.

func (*Bundle) IssuedNow

func (b *Bundle) IssuedNow() bool

IssuedNow reports whether Open had to create new material.

func (*Bundle) IssuedReason

func (b *Bundle) IssuedReason() string

IssuedReason explains why new material was created.

func (*Bundle) Leaf

func (b *Bundle) Leaf(host string) (*tls.Certificate, error)

Leaf returns the certificate for host. host may carry a port, which is stripped. Only the hosts the certificate was issued for are available: the root key is gone, so nothing else can be signed.

func (*Bundle) NotAfter

func (b *Bundle) NotAfter() time.Time

NotAfter reports when the material stops being usable, which is the earlier of the two certificates' expiries.

func (*Bundle) Root

func (b *Bundle) Root() *x509.Certificate

Root exposes the parsed root certificate.

Jump to

Keyboard shortcuts

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