cert

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: LGPL-3.0 Imports: 29 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectPublicIP

func DetectPublicIP(ip string) (string, error)

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.

func SaveCert

func SaveCert(dir, key string, certPEM, keyPEM []byte, meta CertMeta) error

SaveCert saves certificate PEM, key PEM, and metadata to disk.

func SaveUser

func SaveUser(cacheDir string, user *CertUser) error

SaveUser persists the ACME user account.

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 CertMeta

type CertMeta struct {
	Domain  string `json:"domain"`
	CertURL string `json:"cert_url"`
}

CertMeta holds metadata for a cached certificate.

func LoadCert

func LoadCert(dir, key string) (*tls.Certificate, CertMeta, error)

LoadCert loads a certificate from disk. Returns the tls.Certificate, metadata, and any error.

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

func LoadOrCreateUser(cacheDir, email string) (*CertUser, error)

LoadOrCreateUser loads an existing ACME account or creates a new one.

func (*CertUser) GetEmail

func (u *CertUser) GetEmail() string

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

type ZeroSSLEAB struct {
	KID     string `json:"eab_kid"`
	HMACKey string `json:"eab_hmac_key"`
}

ZeroSSLEAB contains auto-fetched ZeroSSL EAB credentials.

Jump to

Keyboard shortcuts

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