Documentation
¶
Overview ¶
Package certs is a tiny demo PKI for the separated client/server holt examples. It generates a CA plus two leaf certificates — one named "hub", one named "peer" — each valid for BOTH server and client authentication, and writes them as PEM files that two separate processes can load.
A single leaf that works in either TLS role keeps the examples simple: the transport-tls hub uses the "hub" cert as its server cert while the peer uses "peer" as its client cert; the encrypted example (roles inverted, peer is the TLS server) uses the same two files the other way round. Both sides trust the shared CA.
This is example scaffolding, not a real PKI: keys live in a temp dir, unencrypted. Never reuse it for anything real.
Index ¶
Constants ¶
const ( Hub = "hub" Peer = "peer" )
Names of the two identities issued by EnsureDir.
Variables ¶
This section is empty.
Functions ¶
func DefaultDir ¶
func DefaultDir() string
DefaultDir is the shared location both example binaries default to, so the server can generate the certs and the client can read them without any flags.
func EnsureDir ¶
EnsureDir generates the CA + hub + peer certificates into dir if they are not already present. Idempotent: an existing ca.pem short- circuits. Start the server (which calls this) before the client.
func Issue ¶
func Issue(dir, name string) (tls.Certificate, error)
Issue mints a fresh leaf certificate for name, signed by the demo CA, and returns it in memory (nothing written to disk). It lets a client present a certificate carrying its OWN identity — the CN the hub then reads as the authenticated peer id. Requires EnsureDir to have created ca.pem / ca-key.pem.
Types ¶
type Bundle ¶
Bundle is a client's credential set as PEM: the CA to trust plus the client's own certificate and key. Encode it to a copy-pasteable token; DecodeBundle reverses it.
func DecodeBundle ¶
DecodeBundle parses a token produced by Bundle.Encode.
type PKI ¶
type PKI struct {
// contains filtered or unexported fields
}
PKI is an in-memory certificate authority for one demo run.
func (*PKI) ClientBundle ¶
ClientBundle issues a leaf for name and packages it with the CA into a Bundle the client can load without touching disk.
func (*PKI) Pool ¶
Pool returns a cert pool trusting this CA — used to verify the other side's certificate.
func (*PKI) ServerCert ¶
func (p *PKI) ServerCert(name string) (tls.Certificate, error)
ServerCert issues a leaf certificate for name, for the hub to present on its TLS listener.