Help us shape the future of Go! Take the 2026 Go Developer Survey

devtls

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package devtls provides a shared, in-memory self-signed TLS certificate generator for gopherstack's opt-in/mandatory dev HTTPS listeners.

It is lifted out of cli.go's original generateSelfSignedCert (used by the main port's opt-in TLS mode) so that services/azurearm -- which must serve its ARM/AAD-discovery listener over HTTPS unconditionally, see AZURE.md section 10.8 -- can share the exact same cert-generation logic instead of duplicating it. cli.go now calls GenerateSelfSignedCert instead of defining its own copy.

Index

Constants

View Source
const DefaultValidity = 365 * 24 * time.Hour

DefaultValidity is the validity window of a generated certificate.

Variables

View Source
var ErrInvalidCAPEM = errors.New("devtls: invalid CA PEM")

ErrInvalidCAPEM is returned when a persisted CA cannot be decoded.

Functions

func GenerateSelfSignedCert

func GenerateSelfSignedCert(hosts ...string) (tls.Certificate, error)

GenerateSelfSignedCert creates an in-memory self-signed certificate valid for localhost/127.0.0.1/::1, plus any extra DNS names or IP addresses passed in hosts (each entry is tried as an IP first, falling back to a DNS name). Suitable for an opt-in or mandatory dev HTTPS listener -- never for production use.

func GenerateSelfSignedCertPEM

func GenerateSelfSignedCertPEM(hosts ...string) ([]byte, []byte, error)

GenerateSelfSignedCertPEM is the PEM-returning variant of GenerateSelfSignedCert, used by callers (e.g. the terraform test harness) that need to write the certificate to disk for a child process (such as `tofu`/`terraform`) to trust via SSL_CERT_FILE.

Types

type CA

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

CA is an in-memory certificate authority that signs short-lived leaf certificates.

func LoadOrCreateCA

func LoadOrCreateCA(dir string) (*CA, error)

LoadOrCreateCA returns the CA persisted in dir, creating and saving one when absent, so clients can trust it once across restarts.

func NewCA

func NewCA() (*CA, error)

NewCA creates a self-signed CA certificate valid for DefaultValidity.

func (*CA) CertPEM

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

CertPEM returns the CA certificate in PEM form, for clients to trust.

func (*CA) Issue

func (c *CA) Issue(hosts ...string) (*tls.Certificate, error)

Issue signs a server leaf certificate covering the given DNS names and IPs (each entry is tried as an IP first).

func (*CA) Pool

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

Pool returns a cert pool containing only this CA.

Jump to

Keyboard shortcuts

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