Skip to content
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
18 changes: 7 additions & 11 deletions tlsconfig/certpool.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package tlsconfig

import (
"crypto/x509"
"runtime"
)
import "crypto/x509"

// SystemCertPool returns a copy of the system cert pool,
// returns an error if failed to load or empty pool on windows.
// SystemCertPool returns a copy of the system cert pool.
//
// Deprecated: use [x509.SystemCertPool] instead.
//
//go:fix inline
func SystemCertPool() (*x509.CertPool, error) {
certpool, err := x509.SystemCertPool()
if err != nil && runtime.GOOS == "windows" {
return x509.NewCertPool(), nil
}
return certpool, err
return x509.SystemCertPool()
}
2 changes: 1 addition & 1 deletion tlsconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func certPool(caFile string, exclusivePool bool) (*x509.CertPool, error) {
if exclusivePool {
pool = x509.NewCertPool()
} else {
pool, err = SystemCertPool()
pool, err = x509.SystemCertPool()
if err != nil {
return nil, fmt.Errorf("failed to read system certificates: %v", err)
}
Expand Down
8 changes: 4 additions & 4 deletions tlsconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ func TestConfigServerTLSClientCASet(t *testing.T) {
if tlsConfig.ClientAuth != tls.VerifyClientCertIfGiven {
t.Fatal("ClientAuth was not set to what was in the options")
}
basePool, err := SystemCertPool()
basePool, err := x509.SystemCertPool()
if err != nil {
basePool = x509.NewCertPool()
t.Fatal("Failed to get SystemCertPool", err)
}
// because we are not enabling `ExclusiveRootPools`, any root pool will also contain the system roots
if tlsConfig.ClientCAs == nil || len(tlsConfig.ClientCAs.Subjects()) != len(basePool.Subjects())+2 { //nolint:staticcheck // Ignore SA1019: tlsConfig.ClientCAs.Subjects has been deprecated since Go 1.18: if s was returned by SystemCertPool, Subjects will not include the system roots.
Expand Down Expand Up @@ -441,9 +441,9 @@ func TestConfigClientTLSRootCAFileWithOneCert(t *testing.T) {
if err != nil || tlsConfig == nil {
t.Fatal("Unable to configure client TLS", err)
}
basePool, err := SystemCertPool()
basePool, err := x509.SystemCertPool()
if err != nil {
basePool = x509.NewCertPool()
t.Fatal("Failed to get SystemCertPool", err)
}
// because we are not enabling `ExclusiveRootPools`, any root pool will also contain the system roots
if tlsConfig.RootCAs == nil || len(tlsConfig.RootCAs.Subjects()) != len(basePool.Subjects())+2 { //nolint:staticcheck // Ignore SA1019: tlsConfig.ClientCAs.Subjects has been deprecated since Go 1.18: if s was returned by SystemCertPool, Subjects will not include the system roots.
Expand Down
Loading