Check all the C/N and SANs of provided certificates before generating ACME certificates in ACME provider

This commit is contained in:
NicoMen 2018-03-06 10:12:04 +01:00 committed by Traefiker Bot
parent 8380de1bd9
commit d3edccb839
9 changed files with 97 additions and 86 deletions

View file

@ -89,7 +89,7 @@ func (f FileOrContent) Read() ([]byte, error) {
// CreateTLSConfig creates a TLS config from Certificate structures
func (c *Certificates) CreateTLSConfig(entryPointName string) (*tls.Config, error) {
config := &tls.Config{}
domainsCertificates := make(map[string]*DomainsCertificates)
domainsCertificates := make(map[string]map[string]*tls.Certificate)
if c.isEmpty() {
config.Certificates = []tls.Certificate{}
cert, err := generate.DefaultCertificate()
@ -105,7 +105,7 @@ func (c *Certificates) CreateTLSConfig(entryPointName string) (*tls.Config, erro
continue
}
for _, certDom := range domainsCertificates {
for _, cert := range certDom.Get().(map[string]*tls.Certificate) {
for _, cert := range map[string]*tls.Certificate(certDom) {
config.Certificates = append(config.Certificates, *cert)
}
}
@ -130,7 +130,7 @@ func (c *Certificates) isEmpty() bool {
}
// AppendCertificates appends a Certificate to a certificates map sorted by entrypoints
func (c *Certificate) AppendCertificates(certs map[string]*DomainsCertificates, ep string) error {
func (c *Certificate) AppendCertificates(certs map[string]map[string]*tls.Certificate, ep string) error {
certContent, err := c.CertFile.Read()
if err != nil {
@ -161,10 +161,9 @@ func (c *Certificate) AppendCertificates(certs map[string]*DomainsCertificates,
certExists := false
if certs[ep] == nil {
certs[ep] = new(DomainsCertificates)
*certs[ep] = make(map[string]*tls.Certificate)
certs[ep] = make(map[string]*tls.Certificate)
} else {
for domains := range *certs[ep] {
for domains := range certs[ep] {
if domains == certKey {
certExists = true
break
@ -175,7 +174,7 @@ func (c *Certificate) AppendCertificates(certs map[string]*DomainsCertificates,
log.Warnf("Into EntryPoint %s, try to add certificate for domains which already have this certificate (%s). The new certificate will not be append to the EntryPoint.", ep, certKey)
} else {
log.Debugf("Add certificate for domains %s", certKey)
err = certs[ep].add(certKey, &tlsCert)
certs[ep][certKey] = &tlsCert
}
return err