2019-03-11 16:56:48 +00:00
|
|
|
package certificate
|
2018-12-06 21:50:17 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2019-07-30 19:19:32 +00:00
|
|
|
"github.com/go-acme/lego/v3/acme"
|
|
|
|
"github.com/go-acme/lego/v3/log"
|
2018-12-06 21:50:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// overallRequestLimit is the overall number of request per second
|
|
|
|
// limited on the "new-reg", "new-authz" and "new-cert" endpoints.
|
|
|
|
// From the documentation the limitation is 20 requests per second,
|
|
|
|
// but using 20 as value doesn't work but 18 do
|
|
|
|
overallRequestLimit = 18
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Certifier) getAuthorizations(order acme.ExtendedOrder) ([]acme.Authorization, error) {
|
|
|
|
resc, errc := make(chan acme.Authorization), make(chan domainError)
|
|
|
|
|
|
|
|
delay := time.Second / overallRequestLimit
|
|
|
|
|
|
|
|
for _, authzURL := range order.Authorizations {
|
|
|
|
time.Sleep(delay)
|
|
|
|
|
|
|
|
go func(authzURL string) {
|
|
|
|
authz, err := c.core.Authorizations.Get(authzURL)
|
|
|
|
if err != nil {
|
|
|
|
errc <- domainError{Domain: authz.Identifier.Value, Error: err}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
resc <- authz
|
|
|
|
}(authzURL)
|
|
|
|
}
|
|
|
|
|
|
|
|
var responses []acme.Authorization
|
|
|
|
failures := make(obtainError)
|
|
|
|
for i := 0; i < len(order.Authorizations); i++ {
|
|
|
|
select {
|
|
|
|
case res := <-resc:
|
|
|
|
responses = append(responses, res)
|
|
|
|
case err := <-errc:
|
|
|
|
failures[err.Domain] = err.Error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, auth := range order.Authorizations {
|
|
|
|
log.Infof("[%s] AuthURL: %s", order.Identifiers[i].Value, auth)
|
|
|
|
}
|
|
|
|
|
|
|
|
close(resc)
|
|
|
|
close(errc)
|
|
|
|
|
|
|
|
// be careful to not return an empty failures map;
|
|
|
|
// even if empty, they become non-nil error values
|
|
|
|
if len(failures) > 0 {
|
|
|
|
return responses, failures
|
|
|
|
}
|
|
|
|
return responses, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Certifier) deactivateAuthorizations(order acme.ExtendedOrder) {
|
2019-10-24 22:28:26 +00:00
|
|
|
for _, authzURL := range order.Authorizations {
|
|
|
|
auth, err := c.core.Authorizations.Get(authzURL)
|
|
|
|
if err != nil {
|
|
|
|
log.Infof("Unable to get the authorization for: %s", authzURL)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if auth.Status == acme.StatusValid {
|
|
|
|
log.Infof("Skipping deactivating of valid auth: %s", authzURL)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Infof("Deactivating auth: %s", authzURL)
|
|
|
|
if c.core.Authorizations.Deactivate(authzURL) != nil {
|
|
|
|
log.Infof("Unable to deactivate the authorization: %s", authzURL)
|
2018-12-06 21:50:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|