Skip to content

Commit

Permalink
Fix for fetching alt root certs
Browse files Browse the repository at this point in the history
  • Loading branch information
eggsampler committed Mar 20, 2020
1 parent 04972c7 commit d967753
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
12 changes: 8 additions & 4 deletions certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ func (c Client) FetchAllCertificates(account Account, certificateURL string) (ma

alternates := fetchLinks(resp, "alternate")

for _, v := range alternates {
altCertChain, err := c.decodeCertificateChain(body, resp, account)
for _, altURL := range alternates {
altResp, altBody, err := c.postRaw(0, altURL, account.URL, account.PrivateKey, "", []int{http.StatusOK})
if err != nil {
return certs, fmt.Errorf("acme: error fetching alt cert chain at %q - %v", v, err)
return certs, fmt.Errorf("acme: error fetching alt cert chain at %q - %v", altURL, err)
}
certs[v] = altCertChain
altCertChain, err := c.decodeCertificateChain(altBody, altResp, account)
if err != nil {
return certs, fmt.Errorf("acme: error decoding alt cert chain at %q - %v", altURL, err)
}
certs[altURL] = altCertChain
}

return certs, nil
Expand Down
30 changes: 15 additions & 15 deletions certificate_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package acme

import (
"os"
"strconv"
"testing"
)

Expand All @@ -26,10 +24,6 @@ func TestClient_FetchCertificates(t *testing.T) {
}

func TestClient_FetchAllCertificates(t *testing.T) {
if testClientMeta.Software == clientBoulder {
t.Skip("boulder doesnt support alt cert chains: https://github.com/letsencrypt/boulder/issues/4567")
return
}
account, order, _ := makeOrderFinalised(t, nil)
if order.Certificate == "" {
t.Fatalf("no certificate: %+v", order)
Expand All @@ -38,16 +32,22 @@ func TestClient_FetchAllCertificates(t *testing.T) {
if err != nil {
t.Fatalf("expeceted no error, got: %v", err)
}
roots, ok := os.LookupEnv("PEBBLE_ALTERNATE_ROOTS")
if !ok {
return
}
numRoots, err := strconv.Atoi(roots)
if err != nil {
panic(err)

if len(certs) == 1 {
t.Skip("no alternative root certificates")
}
if numRoots > 0 && len(certs) <= numRoots {
t.Fatalf("expected > %d cert chains, got: %d", numRoots, len(certs))

for url1, certs1 := range certs {
for url2, certs2 := range certs {
if url2 == url1 {
continue
}
root1 := certs1[len(certs1)-1].Issuer.String()
root2 := certs2[len(certs2)-1].Issuer.String()
if root1 == root2 {
t.Fatalf("same root on cetificates: %s", root1)
}
}
}
}

Expand Down

0 comments on commit d967753

Please sign in to comment.