ca

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 18 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 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

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

File names inside the instance directory.

View Source
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 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

func Load(dir, instance string) (*CA, error)

Load opens the CA in dir, creating it if absent. instance names it.

func (*CA) Certificate

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

Certificate returns the root certificate.

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) PEM

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

PEM returns the root certificate in PEM form.

func (*CA) Path

func (c *CA) Path() string

Path returns the path of ca.pem.

func (*CA) Pool

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

Pool returns a cert pool containing only the root.

func (*CA) Rotate

func (c *CA) Rotate(instance string) error

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.

Jump to

Keyboard shortcuts

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