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 ¶
const ( LetsEncryptProduction = acme.LetsEncryptURL LetsEncryptStaging = "https://acme-staging-v02.api.letsencrypt.org/directory" )
ACME directory URLs of Let's Encrypt.
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
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 ¶
SelfSignedCertFile returns the path of the self-signed certificate kept in dir.
func ValidACMEDomain ¶ added in v0.2.0
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
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.
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 ¶
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 ¶
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).