Documentation ¶
Index ¶
- Variables
- func CheckConfig(c *Config) error
- func ListenAndServeTLS(addr string, handler http.Handler, mail string, cleanup func(), ...) error
- func ListenAndServeTLSCustom(addr string, handler http.Handler, cfg *Config, tlsconf *tls.Config, ...) error
- func ListenAndServeTLSLocal(addr string, handler http.Handler, cleanup func(), domains ...string) error
- func Redirect(w http.ResponseWriter, req *http.Request)
- type CR
- type CertReloader
- type CertStatus
- type Config
- type SSLUser
Constants ¶
This section is empty.
Variables ¶
var Default = &Config{ RenewBefore: 30 * 24, CheckInterval: 2 * 24 * time.Hour, SSLEmail: "", DirectoryURL: "https://acme-v02.api.letsencrypt.org/directory", HTTPAddress: ":80", TLSAddress: ":443", CacheDirPerm: 0700, Domains: []string{}, CacheDir: "letsencrypt", DNSProvider: "", Local: false, UpdateHosts: true, }
Default contains a default configuration
Functions ¶
func CheckConfig ¶
CheckConfig checks if config can be used to obtain a cert
func ListenAndServeTLS ¶
func ListenAndServeTLS(addr string, handler http.Handler, mail string, cleanup func(), domains ...string) error
ListenAndServeTLS is a util to use simplecert in production
func ListenAndServeTLSCustom ¶
func ListenAndServeTLSCustom(addr string, handler http.Handler, cfg *Config, tlsconf *tls.Config, cleanup func(), domains ...string) error
ListenAndServeTLSCustom allows to specify the simplecert and TLS configuration and does not redirect the traffic arriving at port 80
Types ¶
type CR ¶
type CR struct { Domain string `json:"domain"` CertURL string `json:"certUrl"` CertStableURL string `json:"certStableUrl"` PrivateKey []byte `json:"privateKey"` Certificate []byte `json:"certificate"` IssuerCertificate []byte `json:"issuerCertificate"` CSR []byte `json:"csr"` }
CR represents an ACME Certificate Resource It can be persisted on the FileSystem with all fields which cannot be done with acme.CertificateResource
type CertReloader ¶
CertReloader manages a hot reload of a new cert
func Init ¶
func Init(cfg *Config, cleanup func()) (*CertReloader, error)
Init obtains a new LetsEncrypt cert for the specified domains if there is none in cacheDir or loads an existing one. Certs will be auto renewed in the configured interval. 1. Check if we have a cached certificate, if yes kickoff renewal routine and return 2. No Cached Certificate found - make sure the supplied cacheDir exists 3. Create a new SSLUser and ACME Client 4. Obtain a new certificate 5. Save To Disk 6. Kickoff Renewal Routine
func NewCertReloader ¶
func NewCertReloader(certPath, keyPath string, logFile *os.File, cleanup func()) (*CertReloader, error)
NewCertReloader returns a new CertReloader instance the optional cleanup func will be called when a syscall.SIGINT, syscall.SIGABRT is received
func (*CertReloader) GetCertificateFunc ¶
func (reloader *CertReloader) GetCertificateFunc() func(*tls.ClientHelloInfo) (*tls.Certificate, error)
GetCertificateFunc is needed for hot reload
type CertStatus ¶ added in v1.6.9
func Status ¶ added in v1.6.9
func Status() *CertStatus
Status can be used to check the validity status of the certificate as well as the configured renewal interval in case of errors, they will simply be logged, but should not disrupt the service the actual error message will never be passed to the caller and only appear in the simplecert logs therefore always check if you received a result != nil when calling Status()
type Config ¶
type Config struct { // renew the certificate X hours before it expires // LetsEncrypt Certs are valid for 90 Days RenewBefore int // Interval for checking if cert is closer to expiration than RenewBefore CheckInterval time.Duration // SSLEmail for contact SSLEmail string // ACME Directory URL. Can be set to https://acme-staging-v02.api.letsencrypt.org/directory for testing DirectoryURL string // Endpoints for webroot challenge // CAUTION: challenge must be received on port 80 and 443 // if you choose different ports here you must redirect the traffic HTTPAddress string TLSAddress string // UNIX Permission for the CacheDir and all files inside CacheDirPerm os.FileMode // Domains for which to obtain the certificate Domains []string // Path of the CacheDir CacheDir string // DNSProvider name for DNS challenges (optional) // see: https://godoc.org/github.com/go-acme/lego/providers/dns DNSProvider string // Local runmode Local bool // UpdateHosts adds the domains to /etc/hosts if running in local mode UpdateHosts bool // Handler funcs for graceful service shutdown and restoring WillRenewCertificate func() DidRenewCertificate func() FailedToRenewCertificate func(error) }
Config allows configuration of simplecert
type SSLUser ¶
type SSLUser struct { Email string Registration *registration.Resource Key *rsa.PrivateKey }
SSLUser implements the ACME User interface
func (SSLUser) GetPrivateKey ¶
func (u SSLUser) GetPrivateKey() crypto.PrivateKey
GetPrivateKey returns the users private key
func (SSLUser) GetRegistration ¶
func (u SSLUser) GetRegistration() *registration.Resource
GetRegistration returns the users registration resource