Documentation
¶
Overview ¶
Package cert provides automatic TLS certificate management via ACME (Let's Encrypt / ZeroSSL). It supports IP certificates (RFC 8738) via TLS-ALPN-01 or HTTP-01 challenges, and domain certificates via DNS-01 challenge providers.
Index ¶
- func DetectPublicIP(ip string) (string, error)
- func IsCertValid(cert *tls.Certificate, renewBefore time.Duration) bool
- func ObtainDomainCert(cfg DomainCertConfig) (*certificate.Resource, error)
- func ObtainIPCert(cfg IPCertConfig) (*certificate.Resource, error)
- func RenewDomainCert(cfg DomainCertConfig, certRes *certificate.Resource) (*certificate.Resource, error)
- func RenewIPCert(cfg IPCertConfig, certRes *certificate.Resource) (*certificate.Resource, error)
- func SaveCert(dir, key string, certPEM, keyPEM []byte, meta CertMeta) error
- func SaveUser(cacheDir string, user *CertUser) error
- type CertManager
- type CertMeta
- type CertUser
- type DomainCertConfig
- type IPCertConfig
- type ZeroSSLEAB
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetectPublicIP ¶
DetectPublicIP returns the public IP address. If ip is non-empty, it validates and returns it as-is. If ip is empty, it auto-detects the first public (non-RFC 1918 / non-loopback / non-link-local) IPv4 address from available network interfaces.
func IsCertValid ¶
func IsCertValid(cert *tls.Certificate, renewBefore time.Duration) bool
IsCertValid checks whether the certificate is still valid for at least renewBefore duration. Returns false if the certificate expires within the renewBefore window or is already expired.
func ObtainDomainCert ¶
func ObtainDomainCert(cfg DomainCertConfig) (*certificate.Resource, error)
ObtainDomainCert obtains a new domain certificate via DNS-01 challenge.
func ObtainIPCert ¶
func ObtainIPCert(cfg IPCertConfig) (*certificate.Resource, error)
ObtainIPCert obtains a new IP certificate via ACME.
func RenewDomainCert ¶
func RenewDomainCert(cfg DomainCertConfig, certRes *certificate.Resource) (*certificate.Resource, error)
RenewDomainCert renews an existing domain certificate.
func RenewIPCert ¶
func RenewIPCert(cfg IPCertConfig, certRes *certificate.Resource) (*certificate.Resource, error)
RenewIPCert renews an existing IP certificate.
Types ¶
type CertManager ¶
type CertManager struct {
// contains filtered or unexported fields
}
CertManager manages certificate lifecycle: obtain, cache, hot-reload, auto-renew.
func NewCertManager ¶
func NewCertManager(cfg opt.TLSConfig) (*CertManager, error)
NewCertManager creates a new CertManager. It loads cached certs or obtains new ones.
func (*CertManager) Shutdown ¶
func (cm *CertManager) Shutdown(ctx context.Context) error
Shutdown gracefully stops the cert manager.
func (*CertManager) StartAutoRenew ¶
func (cm *CertManager) StartAutoRenew(ctx context.Context)
StartAutoRenew starts background auto-renewal.
func (*CertManager) TLSConfig ¶
func (cm *CertManager) TLSConfig() *tls.Config
TLSConfig returns a *tls.Config with GetCertificate callback for hot-reloading.
type CertUser ¶
type CertUser struct {
Email string
Registration *registration.Resource
// contains filtered or unexported fields
}
CertUser implements the registration.User interface for ACME.
func LoadOrCreateUser ¶
LoadOrCreateUser loads an existing ACME account or creates a new one.
func (*CertUser) GetPrivateKey ¶
func (u *CertUser) GetPrivateKey() crypto.PrivateKey
func (*CertUser) GetRegistration ¶
func (u *CertUser) GetRegistration() *registration.Resource
type DomainCertConfig ¶
type DomainCertConfig struct {
Domain string
CacheDir string
CA opt.CA
DNSProvider challenge.Provider
EABKid string // ZeroSSL EAB KID
EABHMACKey string // ZeroSSL EAB HMAC key
Logger *slog.Logger
User *CertUser
}
DomainCertConfig configures domain certificate acquisition.
type IPCertConfig ¶
type IPCertConfig struct {
IP string
CacheDir string
CA opt.CA
HTTP01Port int // non-zero = use HTTP-01 challenge
ALPN01Port int // non-zero = separate TLS-ALPN-01 listener port (for non-443 HTTPS)
EABKid string // ZeroSSL EAB KID
EABHMACKey string // ZeroSSL EAB HMAC key
Logger *slog.Logger
User *CertUser
}
IPCertConfig configures IP certificate acquisition.
type ZeroSSLEAB ¶
ZeroSSLEAB contains auto-fetched ZeroSSL EAB credentials.