Commit 30c94908 authored by Matthew Holt's avatar Matthew Holt

letsencrypt: Stubbed out OCSP staple updates

OCSP status is checked at a regular interval, and if the OCSP status changes for any of the certificates, the change callback is executed (restarts the server, updating the OCSP staple).
parent 6762df41
...@@ -13,7 +13,7 @@ import ( ...@@ -13,7 +13,7 @@ import (
) )
func init() { func init() {
letsencrypt.OnRenew = func() error { return Restart(nil) } letsencrypt.OnChange = func() error { return Restart(nil) }
} }
// isLocalhost returns true if the string looks explicitly like a localhost address. // isLocalhost returns true if the string looks explicitly like a localhost address.
......
...@@ -18,12 +18,6 @@ import ( ...@@ -18,12 +18,6 @@ import (
"github.com/xenolf/lego/acme" "github.com/xenolf/lego/acme"
) )
// OnRenew is the function that will be used to restart
// the application or the part of the application that uses
// the certificates maintained by this package. When at least
// one certificate is renewed, this function will be called.
var OnRenew func() error
// Activate sets up TLS for each server config in configs // Activate sets up TLS for each server config in configs
// as needed. It only skips the config if the cert and key // as needed. It only skips the config if the cert and key
// are already provided or if plaintext http is explicitly // are already provided or if plaintext http is explicitly
...@@ -40,7 +34,9 @@ var OnRenew func() error ...@@ -40,7 +34,9 @@ var OnRenew func() error
// Also note that calling this function activates asset // Also note that calling this function activates asset
// management automatically, which <TODO>. // management automatically, which <TODO>.
func Activate(configs []server.Config) ([]server.Config, error) { func Activate(configs []server.Config) ([]server.Config, error) {
// First identify and configure any elligible hosts for which // TODO: Is multiple activation (before a deactivation) an error?
// First identify and configure any eligible hosts for which
// we already have certs and keys in storage from last time. // we already have certs and keys in storage from last time.
configLen := len(configs) // avoid infinite loop since this loop appends plaintext to the slice configLen := len(configs) // avoid infinite loop since this loop appends plaintext to the slice
for i := 0; i < configLen; i++ { for i := 0; i < configLen; i++ {
...@@ -269,6 +265,7 @@ func autoConfigure(cfg *server.Config, allConfigs []server.Config) []server.Conf ...@@ -269,6 +265,7 @@ func autoConfigure(cfg *server.Config, allConfigs []server.Config) []server.Conf
// TODO: Handle these errors better // TODO: Handle these errors better
if err == nil { if err == nil {
ocsp, status, err := acme.GetOCSPForCert(bundleBytes) ocsp, status, err := acme.GetOCSPForCert(bundleBytes)
ocspStatus[&bundleBytes] = status
if err == nil && status == acme.OCSPGood { if err == nil && status == acme.OCSPGood {
cfg.TLS.OCSPStaple = ocsp cfg.TLS.OCSPStaple = ocsp
} }
...@@ -402,3 +399,8 @@ var rsaKeySizeToUse = RSA_2048 ...@@ -402,3 +399,8 @@ var rsaKeySizeToUse = RSA_2048
// stopChan is used to signal the maintenance goroutine // stopChan is used to signal the maintenance goroutine
// to terminate. // to terminate.
var stopChan chan struct{} var stopChan chan struct{}
// ocspStatus maps certificate bundle to OCSP status at start.
// It is used during regular OCSP checks to see if the OCSP
// status has changed.
var ocspStatus = make(map[*[]byte]int)
...@@ -10,6 +10,13 @@ import ( ...@@ -10,6 +10,13 @@ import (
"github.com/xenolf/lego/acme" "github.com/xenolf/lego/acme"
) )
// OnChange is a callback function that will be used to restart
// the application or the part of the application that uses
// the certificates maintained by this package. When at least
// one certificate is renewed or an OCSP status changes, this
// function will be called.
var OnChange func() error
// maintainAssets is a permanently-blocking function // maintainAssets is a permanently-blocking function
// that loops indefinitely and, on a regular schedule, checks // that loops indefinitely and, on a regular schedule, checks
// certificates for expiration and initiates a renewal of certs // certificates for expiration and initiates a renewal of certs
...@@ -30,15 +37,25 @@ func maintainAssets(configs []server.Config, stopChan chan struct{}) { ...@@ -30,15 +37,25 @@ func maintainAssets(configs []server.Config, stopChan chan struct{}) {
for _, err := range errs { for _, err := range errs {
log.Printf("[ERROR] cert renewal: %v\n", err) log.Printf("[ERROR] cert renewal: %v\n", err)
} }
if n > 0 && OnRenew != nil { if n > 0 && OnChange != nil {
err := OnRenew() err := OnChange()
if err != nil { if err != nil {
log.Printf("[ERROR] onrenew callback: %v\n", err) log.Printf("[ERROR] onchange after cert renewal: %v\n", err)
} }
} }
} }
case <-ocspTicker.C: case <-ocspTicker.C:
// TODO: Update OCSP for bundle, oldStatus := range ocspStatus {
_, newStatus, err := acme.GetOCSPForCert(*bundle)
if err == nil && newStatus != oldStatus && OnChange != nil {
log.Printf("[INFO] ocsp status changed from %v to %v\n", oldStatus, newStatus)
err := OnChange()
if err != nil {
log.Printf("[ERROR] onchange after ocsp update: %v\n", err)
}
break
}
}
case <-stopChan: case <-stopChan:
renewalTicker.Stop() renewalTicker.Stop()
ocspTicker.Stop() ocspTicker.Stop()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment