tlsutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: AGPL-3.0 Imports: 25 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 tlsutil provides the TLS certificate for nerdui's HTTPS server (ADR-0005): either a generated self-signed certificate kept in <data-dir>/tls, or a user-provided certificate/key pair that is reloaded when the files change.

Index

Constants

View Source
const (
	LetsEncryptProduction = acme.LetsEncryptURL
	LetsEncryptStaging    = "https://acme-staging-v02.api.letsencrypt.org/directory"
)

ACME directory URLs of Let's Encrypt.

View Source
const (
	// SelfSignedValidity is the lifetime of generated certificates (Apple platforms reject
	// longer-lived TLS server certificates).
	SelfSignedValidity = 825 * 24 * time.Hour
	// RenewBefore is how long before expiry a self-signed certificate is regenerated.
	RenewBefore = 30 * 24 * time.Hour
)

Variables

This section is empty.

Functions

func ACMEDirectory added in v0.2.0

func ACMEDirectory(ca string) (string, error)

ACMEDirectory resolves --tls-acme-ca: "production", "staging" or an https URL.

func Fingerprint

func Fingerprint(cert *x509.Certificate) string

Fingerprint returns the colon-separated upper-case SHA-256 fingerprint of a certificate.

func LocalHosts

func LocalHosts() []string

LocalHosts returns SANs for a self-signed certificate: "localhost", the hostname and all non-link-local unicast addresses of the machine.

func SelfSignedCertFile

func SelfSignedCertFile(dir string) string

SelfSignedCertFile returns the path of the self-signed certificate kept in dir.

func ValidACMEDomain added in v0.2.0

func ValidACMEDomain(d string) error

ValidACMEDomain reports whether d is a public DNS name a certificate can be issued for (no IP addresses, no wildcards: those need DNS-01).

Types

type ACME added in v0.2.0

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

ACME serves certificates from an ACME CA for its domains and the fallback certificate for any other name (localhost, IP addresses, the health check) and while issuance fails.

func NewACME added in v0.2.0

func NewACME(fallback *Manager, o ACMEOptions) *ACME

NewACME returns the ACME certificate source.

func (*ACME) HTTPHandler added in v0.2.0

func (a *ACME) HTTPHandler(httpsPort string) http.Handler

HTTPHandler answers HTTP-01 challenges and redirects other requests to HTTPS on httpsPort.

func (*ACME) Status added in v0.2.0

func (a *ACME) Status() ACMEStatus

Status reports the ACME certificate.

func (*ACME) TLSConfig added in v0.2.0

func (a *ACME) TLSConfig() *tls.Config

TLSConfig serves ACME certificates and answers TLS-ALPN-01 challenges.

func (*ACME) Warm added in v0.2.0

func (a *ACME) Warm(ctx context.Context, interval time.Duration)

Warm obtains the certificates at start, so the first visitor does not wait and the UI knows the result, retrying every interval until ctx ends or all domains succeeded.

type ACMEOptions added in v0.2.0

type ACMEOptions struct {
	Domains      []string
	Email        string
	DirectoryURL string
	// CacheDir keeps the account key and certificates (<data-dir>/tls/acme).
	CacheDir string
	Logf     func(format string, args ...any)
	// Client overrides the ACME client (tests).
	Client *acme.Client
}

ACMEOptions configure ACME certificates.

type ACMEStatus added in v0.2.0

type ACMEStatus struct {
	Domains []string `json:"domains"`
	// Ready: a certificate was obtained and is served.
	Ready    bool       `json:"ready"`
	NotAfter *time.Time `json:"notAfter,omitempty"`
	// Error of the newest failed attempt while no certificate is ready; the self-signed
	// certificate is served meanwhile.
	Error   string     `json:"error,omitempty"`
	ErrorAt *time.Time `json:"errorAt,omitempty"`
}

ACMEStatus describes the ACME certificate for the UI. Keep in sync with api/openapi.yaml.

type Info

type Info struct {
	SelfSigned  bool
	CertFile    string
	NotAfter    time.Time
	DNSNames    []string
	IPAddresses []net.IP
	// SHA256 is the colon-separated SHA-256 fingerprint as shown by browsers.
	SHA256 string
}

Info describes the certificate currently served.

type Manager

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

Manager serves a certificate via tls.Config.GetCertificate and renews/reloads it.

func FromFiles

func FromFiles(certFile, keyFile string, opts ...Option) (*Manager, error)

FromFiles returns a manager for a user-provided certificate and key (PEM). The files are re-read when their modification time changes, e.g. after certbot renews them.

func SelfSigned

func SelfSigned(dir string, hosts []string, opts ...Option) (*Manager, error)

SelfSigned returns a manager for a self-signed certificate stored in dir (created 0700). The certificate is generated on first use and regenerated when it is invalid or expires within RenewBefore. hosts become the SANs (DNS names or IP addresses).

func (*Manager) Info

func (m *Manager) Info() Info

Info returns details about the current certificate.

func (*Manager) TLSConfig

func (m *Manager) TLSConfig() *tls.Config

TLSConfig returns a server configuration that always serves the current certificate.

type Option

type Option func(*Manager)

Option configures a Manager.

func WithClock

func WithClock(now func() time.Time) Option

WithClock overrides the time source (tests).

func WithLogf

func WithLogf(logf func(format string, args ...any)) Option

WithLogf sets a logger for renewals and reloads.

Jump to

Keyboard shortcuts

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