Skip to content

Commit

Permalink
Merge pull request #695 from pbabilas/master
Browse files Browse the repository at this point in the history
Allow signer to work with wildcard dns certs
  • Loading branch information
jcmoraisjr authored Nov 4, 2020
2 parents ef31287 + d4401b8 commit c07fbf3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
14 changes: 5 additions & 9 deletions pkg/acme/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (s *signer) verify(secretName string, domains []string) (verifyErr error) {
duedate := time.Now().Add(s.expiring)
tls := s.cache.GetTLSSecretContent(secretName)
strdomains := strings.Join(domains, ",")
if tls == nil || tls.Crt.NotAfter.Before(duedate) || !match(domains, tls.Crt.DNSNames) {
if tls == nil || tls.Crt.NotAfter.Before(duedate) || !match(domains, tls.Crt) {
var collector func(domains string, success bool)
var reason string
if tls == nil {
Expand Down Expand Up @@ -165,17 +165,13 @@ func (s *signer) verify(secretName string, domains []string) (verifyErr error) {

// match return true if all hosts in hostnames (desired configuration)
// are already in dnsnames (current certificate).
func match(domains, dnsnames []string) bool {
func match(domains []string, crt *x509.Certificate) bool {
found := false
for _, domain := range domains {
found := false
for _, dns := range dnsnames {
if domain == dns {
found = true
}
}
found = crt.VerifyHostname(domain) == nil
if !found {
return false
}
}
return true
}
}
27 changes: 24 additions & 3 deletions pkg/acme/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,28 @@ import (
)

const dumbcrt = `MIIC+DCCAeCgAwIBAgIBAzANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdEdW1iIENBMB4XDTE5MTIwMTE2MzMxNFoXDTIwMTIwMTE2MzMxNFowEzERMA8GA1UEAwwIZDEubG9jYWwwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDZuSjOKNrlOFQ/6JCZDbh5OykiSyv/GVzEsazMeLCcvmQecI9CtqCTMLENaDpSUC4/j2b5i61CoRHoucr9EoMo4KJslWRebfBz5y8H6zbRSI9J3MskVB5oDq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Oi2uCL1Oo7j7k1G7Xd1pLWmj14Rkldadfz/TmC2OHHvLHZwExMuivP/4cZqACfKoFtWzasdaYc24b0vAsquDRe+Kz63UFO/nHApUar2QdnuUwWpEttMqAKmzdP4gCTk/0GfsvADjvsaV9dKnFdcb2NfaTuDNP/JppkEhYSnryptbVRag+wip83VD9axT5yH4KtVV35IgABUFjo28WxUI7HaWkzxA5UBt0uE9c1UqVlI0Zk7KFMMvrZZryJRZqho1Ul5W0TIRr04ww98H3629Lomw9AH/2i5J1tI34JK5amcrmvJf4MnhMjeGu0B0eqUJPY2NX0zKLSKq4KfHZepq2iz/HZsYsCLgsmtlRWQ4/RBtnms/jIFavKH6nNg=`

func TestNotifyVerify(t *testing.T) {
testCases := []struct {
input string
expiresIn time.Duration
cert string
logging string
}{
// 0
{
input: "s1,d1.local",
expiresIn: 10 * 24 * time.Hour,
cert: dumbcrt,
logging: `
INFO-V(2) acme: skipping sign, certificate is updated: secret=s1 domain(s)=d1.local`,
},
// 1
{
input: "s1,d2.local",
expiresIn: -10 * 24 * time.Hour,
cert: dumbcrt,
logging: `
INFO acme: authorizing: id=1 secret=s1 domain(s)=d2.local endpoint=https://acme-v2.local reason='certificate expires in 2020-12-01 16:33:14 +0000 UTC'
INFO acme: new certificate issued: id=1 secret=s1 domain(s)=d2.local`,
Expand All @@ -53,6 +57,7 @@ INFO acme: new certificate issued: id=1 secret=s1 domain(s)=d2.local`,
{
input: "s1,d3.local",
expiresIn: 10 * 24 * time.Hour,
cert: dumbcrt,
logging: `
INFO acme: authorizing: id=1 secret=s1 domain(s)=d3.local endpoint=https://acme-v2.local reason='added one or more domains to an existing certificate'
INFO acme: new certificate issued: id=1 secret=s1 domain(s)=d3.local`,
Expand All @@ -61,17 +66,33 @@ INFO acme: new certificate issued: id=1 secret=s1 domain(s)=d3.local`,
{
input: "s2,d1.local",
expiresIn: 10 * 24 * time.Hour,
cert: dumbcrt,
logging: `
INFO acme: authorizing: id=1 secret=s2 domain(s)=d1.local endpoint=https://acme-v2.local reason='certificate does not exist'
INFO acme: new certificate issued: id=1 secret=s2 domain(s)=d1.local`,
},
{
input: "s1,s3.dev.local",
expiresIn: 10 * 24 * time.Hour,
cert: dumbwildcardcrt,
logging: `
INFO-V(2) acme: skipping sign, certificate is updated: secret=s1 domain(s)=s3.dev.local`,
},
{
input: "s1,other.s3.dev.local",
expiresIn: 10 * 24 * time.Hour,
cert: dumbwildcardcrt,
logging: `
INFO acme: authorizing: id=1 secret=s1 domain(s)=other.s3.dev.local endpoint=https://acme-v2.local reason='added one or more domains to an existing certificate'
INFO acme: new certificate issued: id=1 secret=s1 domain(s)=other.s3.dev.local`,
},
}
c := setup(t)
defer c.teardown()
crt, _ := base64.StdEncoding.DecodeString(dumbcrt)
x509, _ := x509.ParseCertificate(crt)
c.cache.tlsSecret["s1"] = &TLSSecret{Crt: x509}
for _, test := range testCases {
crt, _ := base64.StdEncoding.DecodeString(test.cert)
x509, _ := x509.ParseCertificate(crt)
c.cache.tlsSecret["s1"] = &TLSSecret{Crt: x509}
signer := c.newSigner()
signer.account.Endpoint = "https://acme-v2.local"
signer.expiring = x509.NotAfter.Sub(time.Now().Add(test.expiresIn))
Expand Down

0 comments on commit c07fbf3

Please sign in to comment.