tls

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package tls provides automatic TLS certificate management using ACME protocol.

This package integrates with certmagic to provide automatic certificate issuance and renewal from Let's Encrypt, ZeroSSL, and other ACME CAs.

Features

- Automatic certificate issuance via ACME protocol - Automatic renewal before expiration - Support for HTTP-01 and DNS-01 challenge types - Multiple CA support with automatic failover - OCSP stapling for improved TLS performance

Example

mgr := tls.NewAutoManager(AutoManagerConfig{Email: "admin@example.com"})
mgr.AddDomains("example.com", "www.example.com")
tlsConfig := mgr.TLSConfig()
server := &http.Server{TLSConfig: tlsConfig}

Package tls provides DNS provider implementations for ACME DNS-01 challenges.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoManager

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

AutoManager manages automatic TLS certificates using ACME.

func DefaultAutoManager

func DefaultAutoManager(email string) *AutoManager

DefaultAutoManager returns a default auto manager with sensible defaults.

func NewAutoManager

func NewAutoManager(cfg AutoManagerConfig) *AutoManager

NewAutoManager creates a new automatic certificate manager.

func QuickSetup

func QuickSetup(email string, domains ...string) (*AutoManager, error)

QuickSetup quickly sets up automatic TLS for the given domains. This is a convenience function for simple use cases.

func (*AutoManager) AddDomains

func (m *AutoManager) AddDomains(domains ...string) error

AddDomains adds domains for certificate management.

func (*AutoManager) CacheStatus

func (m *AutoManager) CacheStatus() map[string]*CertStatus

CacheStatus returns the certificate cache status.

func (*AutoManager) Domains

func (m *AutoManager) Domains() []string

Domains returns all managed domains.

func (*AutoManager) GetCertificate

func (m *AutoManager) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, error)

GetCertificate returns the certificate for the given domain.

func (*AutoManager) RemoveDomains

func (m *AutoManager) RemoveDomains(domains ...string)

RemoveDomains removes domains from certificate management.

func (*AutoManager) RenewAll

func (m *AutoManager) RenewAll(ctx context.Context) error

RenewAll forces renewal of all managed certificates.

func (*AutoManager) Revoke

func (m *AutoManager) Revoke(ctx context.Context, domain string, reason int) error

Revoke revokes the certificate for the given domain.

func (*AutoManager) SetDNSProvider

func (m *AutoManager) SetDNSProvider(provider DNSProvider)

SetDNSProvider sets the DNS provider for DNS-01 challenges.

func (*AutoManager) SetHTTPPort

func (m *AutoManager) SetHTTPPort(port int)

SetHTTPPort sets the port for HTTP-01 challenges.

func (*AutoManager) SetStorage

func (m *AutoManager) SetStorage(storage certmagic.Storage)

SetStorage sets a custom storage backend.

func (*AutoManager) SetTLSPort

func (m *AutoManager) SetTLSPort(port int)

SetTLSPort sets the port for TLS-ALPN-01 challenges.

func (*AutoManager) TLSConfig

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

TLSConfig returns a tls.Config that uses managed certificates.

func (*AutoManager) UseProduction

func (m *AutoManager) UseProduction()

UseProduction switches to Let's Encrypt production CA.

func (*AutoManager) UseStaging

func (m *AutoManager) UseStaging()

UseStaging switches to Let's Encrypt staging CA.

func (*AutoManager) UseZeroSSL

func (m *AutoManager) UseZeroSSL()

UseZeroSSL switches to ZeroSSL CA.

type AutoManagerConfig

type AutoManagerConfig struct {
	// Email for ACME account registration
	Email string

	// CA directory URL (default: Let's Encrypt Production)
	CA string

	// Use DNS-01 challenge instead of HTTP-01
	UseDNS01 bool

	// DNS provider for DNS-01 challenge
	DNSProvider DNSProvider

	// Custom storage backend (default: filesystem)
	Storage certmagic.Storage

	// HTTP port for HTTP-01 challenge (default: 80)
	HTTPPort int

	// TLS port for TLS-ALPN-01 challenge (default: 443)
	TLSPort int

	// Agree to CA Terms of Service
	AgreeTerms bool

	// Enable staging mode (uses Let's Encrypt staging CA)
	Staging bool
}

AutoManagerConfig holds configuration for AutoManager.

type CertStatus

type CertStatus struct {
	Domain    string `json:"domain"`
	Valid     bool   `json:"valid"`
	NotBefore string `json:"not_before,omitempty"`
	NotAfter  string `json:"not_after,omitempty"`
	Issuer    string `json:"issuer,omitempty"`
	Message   string `json:"message,omitempty"`
}

CertStatus represents the status of a certificate.

type DNSProvider

type DNSProvider interface {
	libdns.RecordAppender
	libdns.RecordDeleter
}

DNSProvider is the interface for DNS-01 challenge providers.

func DNSProviderFromEnv

func DNSProviderFromEnv() (DNSProvider, error)

DNSProviderFromEnv creates a DNS provider from environment variables. Supports: CLOUDFLARE_API_TOKEN, ALIDNS_ACCESS_KEY_ID, AWS_ACCESS_KEY_ID, etc. Note: This returns placeholder providers. For production, import the specific libdns provider package and configure it directly.

func NewAlidnsProvider

func NewAlidnsProvider(accessKeyID, accessKeySecret string) DNSProvider

NewAlidnsProvider creates an AliDNS provider. For production, use github.com/libdns/alidns instead.

func NewCloudflareProvider

func NewCloudflareProvider(apiToken string) DNSProvider

NewCloudflareProvider creates a Cloudflare DNS provider. For production, use github.com/libdns/cloudflare instead.

func NewDNSProvider

func NewDNSProvider(cfg DNSProviderConfig) (DNSProvider, error)

NewDNSProvider creates a DNS provider based on configuration. Returns nil if no valid provider is configured. Note: For production use, import the specific libdns provider package:

  • Cloudflare: github.com/libdns/cloudflare
  • AliDNS: github.com/libdns/alidns
  • Route53: github.com/libdns/route53
  • DigitalOcean: github.com/libdns/digitalocean
  • GoDaddy: github.com/libdns/godaddy

func NewRoute53Provider

func NewRoute53Provider(accessKeyID, secretAccessKey, region string) DNSProvider

NewRoute53Provider creates a Route53 provider. For production, use github.com/libdns/route53 instead.

type DNSProviderConfig

type DNSProviderConfig struct {
	// Provider type: "cloudflare", "alidns", "route53", "digitalocean", "godaddy"
	Provider string

	// Cloudflare
	CloudflareAPIToken string
	CloudflareEmail    string
	CloudflareAPIKey   string

	// AliDNS (Alibaba Cloud DNS)
	AliAccessKeyID     string
	AliAccessKeySecret string

	// AWS Route53
	AWSAccessKeyID     string
	AWSSecretAccessKey string
	AWSRegion          string

	// DigitalOcean
	DigitalOceanToken string

	// GoDaddy
	GoDaddyKey    string
	GoDaddySecret string

	// General
	PropagationTimeout time.Duration
	PollingInterval    time.Duration
}

DNSProviderConfig holds configuration for DNS providers.

type MockDNSProvider

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

MockDNSProvider is a mock DNS provider for testing.

func NewMockDNSProvider

func NewMockDNSProvider() *MockDNSProvider

NewMockDNSProvider creates a new mock DNS provider for testing.

func (*MockDNSProvider) AppendRecords

func (p *MockDNSProvider) AppendRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

AppendRecords adds records to a zone.

func (*MockDNSProvider) DeleteRecords

func (p *MockDNSProvider) DeleteRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

DeleteRecords removes records from a zone.

func (*MockDNSProvider) GetRecords

func (p *MockDNSProvider) GetRecords(ctx context.Context, zone string) ([]libdns.Record, error)

GetRecords returns all records for a zone.

Jump to

Keyboard shortcuts

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