Merge branch 'v1.6' into 'v1.7'
This commit is contained in:
commit
6ef0e6791b
3 changed files with 61 additions and 52 deletions
|
@ -1,7 +1,6 @@
|
||||||
package acme
|
package acme
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
@ -21,43 +20,12 @@ type challengeHTTP struct {
|
||||||
|
|
||||||
// Present presents a challenge to obtain new ACME certificate
|
// Present presents a challenge to obtain new ACME certificate
|
||||||
func (c *challengeHTTP) Present(domain, token, keyAuth string) error {
|
func (c *challengeHTTP) Present(domain, token, keyAuth string) error {
|
||||||
httpChallenges, err := c.Store.GetHTTPChallenges()
|
return c.Store.SetHTTPChallengeToken(token, domain, []byte(keyAuth))
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("unable to get HTTPChallenges : %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if httpChallenges == nil {
|
|
||||||
httpChallenges = map[string]map[string][]byte{}
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := httpChallenges[token]; !ok {
|
|
||||||
httpChallenges[token] = map[string][]byte{}
|
|
||||||
}
|
|
||||||
|
|
||||||
httpChallenges[token][domain] = []byte(keyAuth)
|
|
||||||
|
|
||||||
return c.Store.SaveHTTPChallenges(httpChallenges)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CleanUp cleans the challenges when certificate is obtained
|
// CleanUp cleans the challenges when certificate is obtained
|
||||||
func (c *challengeHTTP) CleanUp(domain, token, keyAuth string) error {
|
func (c *challengeHTTP) CleanUp(domain, token, keyAuth string) error {
|
||||||
httpChallenges, err := c.Store.GetHTTPChallenges()
|
return c.Store.RemoveHTTPChallengeToken(token, domain)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("unable to get HTTPChallenges : %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugf("Challenge CleanUp for domain %s", domain)
|
|
||||||
|
|
||||||
if _, ok := httpChallenges[token]; ok {
|
|
||||||
if _, domainOk := httpChallenges[token][domain]; domainOk {
|
|
||||||
delete(httpChallenges[token], domain)
|
|
||||||
}
|
|
||||||
if len(httpChallenges[token]) == 0 {
|
|
||||||
delete(httpChallenges, token)
|
|
||||||
}
|
|
||||||
return c.Store.SaveHTTPChallenges(httpChallenges)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Timeout calculates the maximum of time allowed to resolved an ACME challenge
|
// Timeout calculates the maximum of time allowed to resolved an ACME challenge
|
||||||
|
@ -70,16 +38,9 @@ func getTokenValue(token, domain string, store Store) []byte {
|
||||||
var result []byte
|
var result []byte
|
||||||
|
|
||||||
operation := func() error {
|
operation := func() error {
|
||||||
httpChallenges, err := store.GetHTTPChallenges()
|
var err error
|
||||||
if err != nil {
|
result, err = store.GetHTTPChallengeToken(token, domain)
|
||||||
return fmt.Errorf("HTTPChallenges not available : %s", err)
|
return err
|
||||||
}
|
|
||||||
|
|
||||||
var ok bool
|
|
||||||
if result, ok = httpChallenges[token][domain]; !ok {
|
|
||||||
return fmt.Errorf("cannot find challenge for token %v", token)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
notify := func(err error, time time.Duration) {
|
notify := func(err error, time time.Duration) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package acme
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -154,14 +155,60 @@ func (s *LocalStore) SaveCertificates(certificates []*Certificate) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHTTPChallenges returns ACME HTTP Challenges list
|
// GetHTTPChallengeToken Get the http challenge token from the store
|
||||||
func (s *LocalStore) GetHTTPChallenges() (map[string]map[string][]byte, error) {
|
func (s *LocalStore) GetHTTPChallengeToken(token, domain string) ([]byte, error) {
|
||||||
return s.storedData.HTTPChallenges, nil
|
s.lock.RLock()
|
||||||
|
defer s.lock.RUnlock()
|
||||||
|
|
||||||
|
if s.storedData.HTTPChallenges == nil {
|
||||||
|
s.storedData.HTTPChallenges = map[string]map[string][]byte{}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := s.storedData.HTTPChallenges[token]; !ok {
|
||||||
|
return nil, fmt.Errorf("cannot find challenge for token %v", token)
|
||||||
|
}
|
||||||
|
|
||||||
|
result, ok := s.storedData.HTTPChallenges[token][domain]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("cannot find challenge for token %v", token)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveHTTPChallenges stores ACME HTTP Challenges list
|
// SetHTTPChallengeToken Set the http challenge token in the store
|
||||||
func (s *LocalStore) SaveHTTPChallenges(httpChallenges map[string]map[string][]byte) error {
|
func (s *LocalStore) SetHTTPChallengeToken(token, domain string, keyAuth []byte) error {
|
||||||
s.storedData.HTTPChallenges = httpChallenges
|
s.lock.Lock()
|
||||||
|
defer s.lock.Unlock()
|
||||||
|
|
||||||
|
if s.storedData.HTTPChallenges == nil {
|
||||||
|
s.storedData.HTTPChallenges = map[string]map[string][]byte{}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := s.storedData.HTTPChallenges[token]; !ok {
|
||||||
|
s.storedData.HTTPChallenges[token] = map[string][]byte{}
|
||||||
|
}
|
||||||
|
|
||||||
|
s.storedData.HTTPChallenges[token][domain] = []byte(keyAuth)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveHTTPChallengeToken Remove the http challenge token in the store
|
||||||
|
func (s *LocalStore) RemoveHTTPChallengeToken(token, domain string) error {
|
||||||
|
s.lock.Lock()
|
||||||
|
defer s.lock.Unlock()
|
||||||
|
|
||||||
|
if s.storedData.HTTPChallenges == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := s.storedData.HTTPChallenges[token]; ok {
|
||||||
|
if _, domainOk := s.storedData.HTTPChallenges[token][domain]; domainOk {
|
||||||
|
delete(s.storedData.HTTPChallenges[token], domain)
|
||||||
|
}
|
||||||
|
if len(s.storedData.HTTPChallenges[token]) == 0 {
|
||||||
|
delete(s.storedData.HTTPChallenges, token)
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,9 @@ type Store interface {
|
||||||
GetCertificates() ([]*Certificate, error)
|
GetCertificates() ([]*Certificate, error)
|
||||||
SaveCertificates([]*Certificate) error
|
SaveCertificates([]*Certificate) error
|
||||||
|
|
||||||
GetHTTPChallenges() (map[string]map[string][]byte, error)
|
GetHTTPChallengeToken(token, domain string) ([]byte, error)
|
||||||
SaveHTTPChallenges(map[string]map[string][]byte) error
|
SetHTTPChallengeToken(token, domain string, keyAuth []byte) error
|
||||||
|
RemoveHTTPChallengeToken(token, domain string) error
|
||||||
|
|
||||||
AddTLSChallenge(domain string, cert *Certificate) error
|
AddTLSChallenge(domain string, cert *Certificate) error
|
||||||
GetTLSChallenge(domain string) (*Certificate, error)
|
GetTLSChallenge(domain string) (*Certificate, error)
|
||||||
|
|
Loading…
Add table
Reference in a new issue