{"modulePath":"github.com/CrisisTextLine/modular/modules/letsencrypt","version":"v0.4.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package letsencrypt\n\nPackage letsencrypt provides a module for automatic SSL certificate generation via Let's Encrypt for the modular framework.\n\nPackage letsencrypt provides a module for automatic SSL certificate generation via Let's Encrypt for the modular framework.\n\nThis module integrates Let's Encrypt ACME protocol support into the modular framework, enabling automatic SSL/TLS certificate provisioning, renewal, and management. It supports multiple challenge types and DNS providers for flexible certificate acquisition.\n\n### Features {#hdr-Features}\n\nThe letsencrypt module provides the following capabilities:\n\n  - Automatic SSL certificate acquisition from Let's Encrypt\n  - Support for HTTP-01 and DNS-01 challenge types\n  - Multiple DNS provider integrations (Cloudflare, Route53, DigitalOcean, etc.)\n  - Automatic certificate renewal before expiration\n  - Certificate storage and management\n  - Staging and production environment support\n  - Service interface for integration with HTTP servers\n\n### Challenge Types {#hdr-Challenge_Types}\n\nThe module supports two ACME challenge types:\n\n  - HTTP-01: Domain validation via HTTP endpoints\n  - DNS-01: Domain validation via DNS TXT records\n\n### Supported DNS Providers {#hdr-Supported_DNS_Providers}\n\nWhen using DNS-01 challenges, the following providers are supported:\n\n  - Cloudflare\n  - AWS Route53\n  - DigitalOcean\n  - Google Cloud DNS\n  - Azure DNS\n  - Namecheap\n\n### Configuration {#hdr-Configuration}\n\nThe module can be configured through the LetsEncryptConfig structure:\n\n\tconfig := \u0026LetsEncryptConfig{\n\t    Email:           \"admin@example.com\",\n\t    Domains:         []string{\"example.com\", \"www.example.com\"},\n\t    ChallengeType:   \"http-01\",        // or \"dns-01\"\n\t    DNSProvider:     \"cloudflare\",     // for DNS challenges\n\t    CADirectory:     CAProduction,     // or CAStaging for testing\n\t    CertificatePath: \"/etc/ssl/certs\", // certificate storage path\n\t    KeyPath:         \"/etc/ssl/private\", // private key storage path\n\t    DNSProviderConfig: \u0026CloudflareConfig{\n\t        APIToken: \"your-cloudflare-token\",\n\t    },\n\t}\n\n### Service Registration {#hdr-Service_Registration}\n\nThe module registers itself as a certificate service:\n\n\t// Get the certificate service\n\tcertService := app.GetService(\"letsencrypt.certificates\").(letsencrypt.CertificateService)\n\n\t// Get a certificate for a domain\n\tcert, err := certService.GetCertificate(\"example.com\")\n\n\t// Configure TLS with automatic certificates\n\ttlsConfig := \u0026tls.Config{\n\t    GetCertificate: certService.GetCertificate,\n\t}\n\n### Usage Examples {#hdr-Usage_Examples}\n\nBasic HTTP server with automatic HTTPS:\n\n\t// Configure Let's Encrypt module\n\tconfig := \u0026LetsEncryptConfig{\n\t    Email:   \"admin@example.com\",\n\t    Domains: []string{\"example.com\"},\n\t    ChallengeType: \"http-01\",\n\t    CADirectory: CAProduction,\n\t}\n\n\t// Get certificate service\n\tcertService := app.GetService(\"letsencrypt.certificates\").(CertificateService)\n\n\t// Create TLS config with automatic certificates\n\ttlsConfig := \u0026tls.Config{\n\t    GetCertificate: certService.GetCertificate,\n\t}\n\n\t// Start HTTPS server\n\tserver := \u0026http.Server{\n\t    Addr:      \":443\",\n\t    TLSConfig: tlsConfig,\n\t    Handler:   httpHandler,\n\t}\n\tserver.ListenAndServeTLS(\"\", \"\")\n\nDNS challenge with Cloudflare:\n\n\tconfig := \u0026LetsEncryptConfig{\n\t    Email:       \"admin@example.com\",\n\t    Domains:     []string{\"example.com\", \"*.example.com\"},\n\t    ChallengeType: \"dns-01\",\n\t    DNSProvider: \"cloudflare\",\n\t    DNSProviderConfig: \u0026CloudflareConfig{\n\t        APIToken: os.Getenv(\"CLOUDFLARE_API_TOKEN\"),\n\t    },\n\t}\n\n### Certificate Management {#hdr-Certificate_Management}\n\nThe module automatically handles:\n\n  - Certificate acquisition on first request\n  - Certificate renewal (default: 30 days before expiration)\n  - Certificate storage and loading\n  - OCSP stapling support\n  - Certificate chain validation\n\n### Security Considerations {#hdr-Security_Considerations}\n\n\\- Use staging environment for testing to avoid rate limits - Store API credentials securely (environment variables, secrets) - Ensure proper file permissions for certificate storage - Monitor certificate expiration and renewal logs - Use strong private keys (RSA 2048+ or ECDSA P-256+)\n\nPackage letsencrypt provides a module for automatic SSL certificate generation via Let's Encrypt for the modular framework.\n\n## Constants\n\n```go\nconst (\n\t// Configuration events\n\tEventTypeConfigLoaded    = \"com.modular.letsencrypt.config.loaded\"\n\tEventTypeConfigValidated = \"com.modular.letsencrypt.config.validated\"\n\n\t// Certificate lifecycle events\n\tEventTypeCertificateRequested = \"com.modular.letsencrypt.certificate.requested\"\n\tEventTypeCertificateIssued    = \"com.modular.letsencrypt.certificate.issued\"\n\tEventTypeCertificateRenewed   = \"com.modular.letsencrypt.certificate.renewed\"\n\tEventTypeCertificateRevoked   = \"com.modular.letsencrypt.certificate.revoked\"\n\tEventTypeCertificateExpiring  = \"com.modular.letsencrypt.certificate.expiring\"\n\tEventTypeCertificateExpired   = \"com.modular.letsencrypt.certificate.expired\"\n\n\t// ACME protocol events\n\tEventTypeAcmeChallenge     = \"com.modular.letsencrypt.acme.challenge\"\n\tEventTypeAcmeAuthorization = \"com.modular.letsencrypt.acme.authorization\"\n\tEventTypeAcmeOrder         = \"com.modular.letsencrypt.acme.order\"\n\n\t// Service events\n\tEventTypeServiceStarted = \"com.modular.letsencrypt.service.started\"\n\tEventTypeServiceStopped = \"com.modular.letsencrypt.service.stopped\"\n\n\t// Storage events\n\tEventTypeStorageRead  = \"com.modular.letsencrypt.storage.read\"\n\tEventTypeStorageWrite = \"com.modular.letsencrypt.storage.write\"\n\tEventTypeStorageError = \"com.modular.letsencrypt.storage.error\"\n\n\t// Module lifecycle events\n\tEventTypeModuleStarted = \"com.modular.letsencrypt.module.started\"\n\tEventTypeModuleStopped = \"com.modular.letsencrypt.module.stopped\"\n\n\t// Error events\n\tEventTypeError   = \"com.modular.letsencrypt.error\"\n\tEventTypeWarning = \"com.modular.letsencrypt.warning\"\n)\n```\nEvent type constants for letsencrypt module events. Following CloudEvents specification reverse domain notation.\n\n```go\nconst (\n\t// CAStaging is the URL for Let's Encrypt's staging environment.\n\t// Use this for testing to avoid hitting production rate limits.\n\t// Certificates from staging are not trusted by browsers.\n\tCAStaging = \"https://acme-staging-v02.api.letsencrypt.org/directory\"\n\n\t// CAProduction is the URL for Let's Encrypt's production environment.\n\t// Use this for production deployments. Has strict rate limits.\n\t// Certificates from production are trusted by all major browsers.\n\tCAProduction = \"https://acme-v02.api.letsencrypt.org/directory\"\n)\n```\nConstants for Let's Encrypt URLs\n\n```go\nconst ModuleName = \"letsencrypt\"\n```\nModuleName is the unique identifier for the letsencrypt module.\n\n## Variables\n\n```go\nvar (\n\t// Configuration errors\n\tErrEmailRequired              = errors.New(\"email address is required for Let's Encrypt registration\")\n\tErrDomainsRequired            = errors.New(\"at least one domain is required\")\n\tErrConflictingProviders       = errors.New(\"cannot specify both HTTP and DNS challenge providers\")\n\tErrServerNameEmpty            = errors.New(\"server name is empty\")\n\tErrNoCertificateFound         = errors.New(\"no certificate found for domain\")\n\tErrCloudflareConfigMissing    = errors.New(\"cloudflare provider configuration is missing\")\n\tErrRoute53ConfigMissing       = errors.New(\"route53 provider configuration is missing\")\n\tErrDigitalOceanConfigMissing  = errors.New(\"digitalocean provider configuration is missing\")\n\tErrDigitalOceanTokenRequired  = errors.New(\"digitalocean auth token is required\")\n\tErrDNSConfigMissing           = errors.New(\"DNS provider configuration is missing or invalid\")\n\tErrUnsupportedDNSProvider     = errors.New(\"unsupported DNS provider\")\n\tErrGoogleCloudProjectRequired = errors.New(\"google Cloud DNS project ID is required\")\n\tErrAzureDNSConfigIncomplete   = errors.New(\"azure DNS provider requires client_id, client_secret, subscription_id, tenant_id, and resource_group\")\n\tErrNamecheapConfigIncomplete  = errors.New(\"namecheap DNS provider requires api_user, api_key, and username\")\n\tErrHTTPChallengeNotConfigured = errors.New(\"HTTP challenge handler not configured\")\n\n\t// Service dependency errors\n\tErrLoggerServiceUnavailable = errors.New(\"required logger service not found or invalid type\")\n\n\t// Certificate errors\n\tErrCertificateFileNotFound = errors.New(\"certificate file not found\")\n\tErrKeyFileNotFound         = errors.New(\"key file not found\")\n\tErrPEMDecodeFailure        = errors.New(\"failed to decode PEM block containing certificate\")\n\n\t// Event observation errors\n\tErrNoSubjectForEventEmission = errors.New(\"no subject available for event emission\")\n)\n```\nStatic error definitions for the letsencrypt module\n\n## Types\n\n```go\ntype CertificateService interface {\n\t// GetCertificate returns a certificate for the given ClientHello\n\tGetCertificate(*tls.ClientHelloInfo) (*tls.Certificate, error)\n\n\t// GetCertificateForDomain returns a certificate for the specified domain\n\tGetCertificateForDomain(domain string) (*tls.Certificate, error)\n\n\t// Domains returns a list of domains this service can provide certificates for\n\tDomains() []string\n}\n```\nCertificateService defines the interface for a service that can provide TLS certificates\n\n```go\ntype ChallengeHandler interface {\n\t// PresentChallenge is called when a challenge token needs to be made available\n\tPresentChallenge(domain, token, keyAuth string) error\n\n\t// CleanupChallenge is called when a challenge token needs to be removed\n\tCleanupChallenge(domain, token, keyAuth string) error\n}\n```\nChallengeHandler defines the interface for handlers that can handle ACME challenges\n\n```go\ntype CloudflareConfig struct {\n\tEmail    string `yaml:\"email\" json:\"email\" env:\"EMAIL\"`\n\tAPIKey   string `yaml:\"api_key\" json:\"api_key\" env:\"API_KEY\"`\n\tAPIToken string `yaml:\"api_token\" json:\"api_token\" env:\"API_TOKEN\"`\n}\n```\nCloudflareConfig holds the configuration for Cloudflare DNS API\n\n```go\ntype DNSProviderConfig struct {\n\t// Provider is the name of the DNS provider (e.g., \"cloudflare\", \"route53\", etc.)\n\tProvider string `yaml:\"provider\" json:\"provider\" env:\"PROVIDER\"`\n\n\t// Parameters is a map of provider-specific configuration parameters\n\tParameters map[string]string `yaml:\"parameters\" json:\"parameters\" env:\"PARAMETERS\"`\n\n\t// Provider-specific configurations\n\tCloudflare   *CloudflareConfig   `yaml:\"cloudflare,omitempty\" json:\"cloudflare,omitempty\"`\n\tRoute53      *Route53Config      `yaml:\"route53,omitempty\" json:\"route53,omitempty\"`\n\tDigitalOcean *DigitalOceanConfig `yaml:\"digitalocean,omitempty\" json:\"digitalocean,omitempty\"`\n}\n```\nDNSProviderConfig defines the configuration for DNS challenge providers\n\n```go\ntype DigitalOceanConfig struct {\n\tAuthToken string `yaml:\"auth_token\" json:\"auth_token\" env:\"AUTH_TOKEN\"`\n}\n```\nDigitalOceanConfig holds the configuration for DigitalOcean DNS API\n\n```go\ntype HTTPProviderConfig struct {\n\t// Use the built-in HTTP server for challenges\n\tUseBuiltIn bool `yaml:\"use_built_in\" json:\"use_built_in\" env:\"USE_BUILT_IN\"`\n\n\t// Port to use for the HTTP challenge server (default: 80)\n\tPort int `yaml:\"port\" json:\"port\" env:\"PORT\"`\n}\n```\nHTTPProviderConfig defines the configuration for HTTP challenge providers\n\n```go\ntype LetsEncryptConfig struct {\n\t// Email is the email address to use for registration with Let's Encrypt\n\tEmail string `yaml:\"email\" json:\"email\" env:\"EMAIL\"`\n\n\t// Domains is a list of domain names to obtain certificates for\n\tDomains []string `yaml:\"domains\" json:\"domains\" env:\"DOMAINS\"`\n\n\t// UseStaging determines whether to use Let's Encrypt's staging environment\n\t// Set to true for testing to avoid rate limits\n\tUseStaging bool `yaml:\"use_staging\" json:\"use_staging\" env:\"USE_STAGING\"`\n\n\t// UseProduction is the opposite of UseStaging, for clarity in configuration\n\tUseProduction bool `yaml:\"use_production\" json:\"use_production\" env:\"USE_PRODUCTION\"`\n\n\t// StoragePath is the directory where certificates and account information will be stored\n\tStoragePath string `yaml:\"storage_path\" json:\"storage_path\" env:\"STORAGE_PATH\"`\n\n\t// RenewBefore sets how long before expiry certificates should be renewed (in days)\n\tRenewBefore int `yaml:\"renew_before\" json:\"renew_before\" env:\"RENEW_BEFORE\"`\n\n\t// RenewBeforeDays is an alias for RenewBefore for backward compatibility\n\tRenewBeforeDays int `yaml:\"renew_before_days\" json:\"renew_before_days\" env:\"RENEW_BEFORE_DAYS\"`\n\n\t// AutoRenew enables automatic certificate renewal\n\tAutoRenew bool `yaml:\"auto_renew\" json:\"auto_renew\" env:\"AUTO_RENEW\"`\n\n\t// UseDNS indicates whether to use DNS challenges instead of HTTP\n\tUseDNS bool `yaml:\"use_dns\" json:\"use_dns\" env:\"USE_DNS\"`\n\n\t// DNSProvider configuration for DNS challenges\n\tDNSProvider *DNSProviderConfig `yaml:\"dns_provider,omitempty\" json:\"dns_provider,omitempty\"`\n\n\t// DNSConfig is a map of DNS provider specific configuration parameters\n\tDNSConfig map[string]string `yaml:\"dns_config,omitempty\" json:\"dns_config,omitempty\" env:\"DNS_CONFIG\"`\n\n\t// HTTPProvider configuration for HTTP challenges\n\tHTTPProvider *HTTPProviderConfig `yaml:\"http_provider,omitempty\" json:\"http_provider,omitempty\"`\n\n\t// HTTPChallengeHandler is an HTTP handler for HTTP-01 challenges\n\tHTTPChallengeHandler http.Handler `yaml:\"-\" json:\"-\"`\n\n\t// CustomCACertificate is a custom CA certificate to be trusted\n\tCustomCACertificate []byte `yaml:\"-\" json:\"-\"`\n}\n```\nLetsEncryptConfig defines the configuration for the Let's Encrypt module.\n\n```go\nfunc (c *LetsEncryptConfig) Validate() error\n```\nValidate checks if the configuration is valid and sets default values where appropriate.\n\n```go\ntype LetsEncryptModule struct {\n\t// contains filtered or unexported fields\n}\n```\nLetsEncryptModule provides automatic SSL certificate management using Let's Encrypt. It handles certificate acquisition, renewal, and storage with support for multiple challenge types and DNS providers.\n\nThe module implements the following interfaces:\n\n  - modular.Module: Basic module lifecycle\n  - modular.Configurable: Configuration management\n  - modular.ServiceAware: Service dependency management\n  - modular.Constructable: Constructor-based dependency injection\n  - modular.Startable: Startup logic\n  - modular.Stoppable: Shutdown logic\n  - CertificateService: Certificate management interface\n\nCertificate operations are thread-safe and support concurrent requests.\n\n```go\nfunc New(config *LetsEncryptConfig) (*LetsEncryptModule, error)\n```\nNew creates a new Let's Encrypt module\n\n```go\nfunc (m *LetsEncryptModule) Config() interface{}\n```\nConfig returns the module's configuration\n\n```go\nfunc (m *LetsEncryptModule) Constructor() modular.ModuleConstructor\n```\nConstructor returns a function to construct this module with dependency injection\n\n```go\nfunc (m *LetsEncryptModule) Dependencies() []string\n```\nDependencies returns the names of modules this module depends on\n\n```go\nfunc (m *LetsEncryptModule) Domains() []string\n```\nDomains returns the list of domains this service can provide certificates for\n\n```go\nfunc (m *LetsEncryptModule) EmitEvent(ctx context.Context, event cloudevents.Event) error\n```\nEmitEvent implements the ObservableModule interface. This allows the letsencrypt module to emit events that other modules or observers can receive.\n\n```go\nfunc (m *LetsEncryptModule) GetCertificate(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error)\n```\nGetCertificate implements the CertificateService.GetCertificate method to be used with tls.Config.GetCertificate\n\n```go\nfunc (m *LetsEncryptModule) GetCertificateForDomain(domain string) (*tls.Certificate, error)\n```\nGetCertificateForDomain returns a certificate for the specified domain\n\n```go\nfunc (m *LetsEncryptModule) GetRegisteredEventTypes() []string\n```\nGetRegisteredEventTypes implements the ObservableModule interface. Returns all event types that this letsencrypt module can emit.\n\n```go\nfunc (m *LetsEncryptModule) Init(app modular.Application) error\n```\nInit initializes the module with the application context\n\n```go\nfunc (m *LetsEncryptModule) Name() string\n```\nName returns the name of the module\n\n```go\nfunc (m *LetsEncryptModule) ProvidesServices() []modular.ServiceProvider\n```\nProvidesServices declares services provided by this module\n\n```go\nfunc (m *LetsEncryptModule) RegisterConfig(app modular.Application) error\n```\nRegisterConfig registers configuration requirements with the application\n\n```go\nfunc (m *LetsEncryptModule) RegisterObservers(subject modular.Subject) error\n```\nRegisterObservers implements the ObservableModule interface. This allows the letsencrypt module to register as an observer for events it's interested in.\n\n```go\nfunc (m *LetsEncryptModule) RequiresServices() []modular.ServiceDependency\n```\nRequiresServices declares services required by this module\n\n```go\nfunc (m *LetsEncryptModule) RevokeCertificate(domain string) error\n```\nRevokeCertificate revokes a certificate for the specified domain\n\n```go\nfunc (m *LetsEncryptModule) Start(ctx context.Context) error\n```\nStart initializes the module and starts any background processes\n\n```go\nfunc (m *LetsEncryptModule) Stop(ctx context.Context) error\n```\nStop stops any background processes\n\n```go\ntype Route53Config struct {\n\tAccessKeyID     string `yaml:\"access_key_id\" json:\"access_key_id\" env:\"ACCESS_KEY_ID\"`\n\tSecretAccessKey string `yaml:\"secret_access_key\" json:\"secret_access_key\" env:\"SECRET_ACCESS_KEY\"`\n\tRegion          string `yaml:\"region\" json:\"region\" env:\"REGION\"`\n\tHostedZoneID    string `yaml:\"hosted_zone_id\" json:\"hosted_zone_id\" env:\"HOSTED_ZONE_ID\"`\n}\n```\nRoute53Config holds the configuration for AWS Route53 DNS API\n\n```go\ntype User struct {\n\tEmail        string\n\tRegistration *registration.Resource\n\tKey          crypto.PrivateKey // Changed from certcrypto.PrivateKey to crypto.PrivateKey\n}\n```\nUser implements the ACME User interface for Let's Encrypt\n\n```go\nfunc (u *User) GetEmail() string\n```\nGetEmail returns the email address for the user\n\n```go\nfunc (u *User) GetPrivateKey() crypto.PrivateKey\n```\nGetPrivateKey returns the private key for the user\n\n```go\nfunc (u *User) GetRegistration() *registration.Resource\n```\nGetRegistration returns the registration resource\n\n","path":"github.com/CrisisTextLine/modular/modules/letsencrypt","name":"letsencrypt","synopsis":"Package letsencrypt provides a module for automatic SSL certificate generation via Let's Encrypt for the modular framework.","isRedistributable":true}
