Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose certificates pool creation #2210

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion challenge/http01/domain_matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (m *hostMatcher) matches(r *http.Request, domain string) bool {
return strings.HasPrefix(r.Host, domain)
}

// hostMatcher checks whether the specified (*net/http.Request).Header value starts with a domain name.
// arbitraryMatcher checks whether the specified (*net/http.Request).Header value starts with a domain name.
type arbitraryMatcher string

func (m arbitraryMatcher) name() string {
Expand Down
34 changes: 25 additions & 9 deletions lego/client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,41 @@ func initCertPool() *x509.CertPool {
return nil
}

certPool := getCertPool()
useSystemCertPool, _ := strconv.ParseBool(os.Getenv(caSystemCertPool))

caCerts := strings.Split(customCACertsPath, string(os.PathListSeparator))

certPool, err := CreateCertPool(caCerts, useSystemCertPool)
if err != nil {
panic(fmt.Sprintf("create certificates pool: %v", err))
}

return certPool
}

for _, customPath := range strings.Split(customCACertsPath, string(os.PathListSeparator)) {
// CreateCertPool creates a *x509.CertPool populated with the PEM certificates.
func CreateCertPool(caCerts []string, useSystemCertPool bool) (*x509.CertPool, error) {
if len(caCerts) == 0 {
return nil, nil
}

certPool := newCertPool(useSystemCertPool)

for _, customPath := range caCerts {
customCAs, err := os.ReadFile(customPath)
if err != nil {
panic(fmt.Sprintf("error reading %s=%q: %v",
caCertificatesEnvVar, customPath, err))
return nil, fmt.Errorf("error reading %q: %w", customPath, err)
}

if ok := certPool.AppendCertsFromPEM(customCAs); !ok {
panic(fmt.Sprintf("error creating x509 cert pool from %s=%q: %v",
caCertificatesEnvVar, customPath, err))
return nil, fmt.Errorf("error creating x509 cert pool from %q: %w", customPath, err)
}
}

return certPool
return certPool, nil
}

func getCertPool() *x509.CertPool {
useSystemCertPool, _ := strconv.ParseBool(os.Getenv(caSystemCertPool))
func newCertPool(useSystemCertPool bool) *x509.CertPool {
if !useSystemCertPool {
return x509.NewCertPool()
}
Expand All @@ -128,5 +143,6 @@ func getCertPool() *x509.CertPool {
if err == nil {
return pool
}

return x509.NewCertPool()
}
2 changes: 1 addition & 1 deletion providers/dns/acmedns/acmedns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c mockUpdateClient) UpdateTXTRecord(acct goacmedns.Account, value string)
return nil
}

// errorRegisterClient is a mock implementing the acmeDNSClient interface that always
// errorUpdateClient is a mock implementing the acmeDNSClient interface that always
// returns errors from errorUpdateClient.
type errorUpdateClient struct {
mockClient
Expand Down