Documentation
¶
Overview ¶
Package ca is the emulator's local certificate authority (Section 7.4). On first start a root CA is created in the instance directory (ca.pem, ca-key.pem, mode 0600); it signs Google-managed certificates for load balancers (FR-LB-004), host-mode serving certificates (FR-CORE-043) and anything else that must chain to a root the user trusts once.
Index ¶
- Constants
- func CRLURL(addr string) string
- func EncodeCert(cert *tls.Certificate) (chainPEM, keyPEM []byte, err error)
- type CA
- func (c *CA) CRL() ([]byte, error)
- func (c *CA) Certificate() *x509.Certificate
- func (c *CA) Current(leaf *x509.Certificate) bool
- func (c *CA) CurrentPEM(chainPEM []byte) bool
- func (c *CA) Issue(l Leaf) (*tls.Certificate, error)
- func (c *CA) PEM() []byte
- func (c *CA) Path() string
- func (c *CA) Pool() *x509.CertPool
- func (c *CA) Rotate(instance string) error
- func (c *CA) ServerCert(names ...string) (*tls.Certificate, error)
- func (c *CA) SetCRLURL(u string)
- type Leaf
Constants ¶
const ( CertFile = "ca.pem" KeyFile = "ca-key.pem" )
File names inside the instance directory.
const CRLPath = "/ca.crl"
CRLPath is where the API gateway serves the CRL.
const CRLValidity = 7 * 24 * time.Hour
CRLValidity is how long a CRL is valid (NextUpdate - ThisUpdate).
const DefaultLeafValidity = 90 * 24 * time.Hour
DefaultLeafValidity is the lifetime of issued leaf certificates (Google-managed certificates are valid for 90 days).
Variables ¶
This section is empty.
Functions ¶
func CRLURL ¶ added in v0.13.0
CRLURL returns the CRL distribution point of an Instance whose API gateway listens on addr, a dialable host:port (emu.Dialable).
func EncodeCert ¶
func EncodeCert(cert *tls.Certificate) (chainPEM, keyPEM []byte, err error)
EncodeCert returns the PEM chain and PEM private key of a tls.Certificate.
Types ¶
type CA ¶
type CA struct {
// contains filtered or unexported fields
}
CA is a root certificate authority backed by files in a directory.
func Load ¶
Load opens the Instance CA in dir. instance names it. The CA is created only when neither ca.pem nor ca-key.pem exists (a missing dir counts as a first start); a CA with only one of its files, or with files that don't match, is an error, and no error case changes anything in dir.
func (*CA) CRL ¶ added in v0.13.0
CRL returns a DER CRL revoking nothing, signed now by the current Instance CA. Its number is taken from the clock and only increases.
func (*CA) Certificate ¶
func (c *CA) Certificate() *x509.Certificate
Certificate returns the root certificate.
func (*CA) Current ¶ added in v0.13.0
func (c *CA) Current(leaf *x509.Certificate) bool
Current reports whether leaf was signed by the current Instance CA and names the current CRL URL as its only distribution point, so a stored leaf that isn't is issued again.
func (*CA) CurrentPEM ¶ added in v0.13.0
CurrentPEM is Current for the leaf at the head of a PEM chain; a chain that doesn't parse is not current.
func (*CA) Issue ¶
func (c *CA) Issue(l Leaf) (*tls.Certificate, error)
Issue signs a new leaf certificate with a fresh P-256 key.
func (*CA) Rotate ¶
Rotate replaces the root CA with a new one (`gcpemu ca rotate`). Leaf certificates issued by the old root stop verifying once clients trust only the new one.
func (*CA) ServerCert ¶
func (c *CA) ServerCert(names ...string) (*tls.Certificate, error)
ServerCert returns a cached serving certificate for the given names, issuing (or re-issuing near expiry) as needed.
type Leaf ¶
type Leaf struct {
// DNSNames and IPs become SANs; the first DNS name (or IP) is the CN.
DNSNames []string
IPs []net.IP
// Validity defaults to DefaultLeafValidity.
Validity time.Duration
// Client adds the clientAuth extended key usage (serverAuth is always set
// unless ClientOnly).
Client bool
ClientOnly bool
// Organization for the subject (optional).
Organization string
}
Leaf describes a certificate to issue.