Skip to content

Commit 91633b5

Browse files
committed
BACKPORT: Merge system certificate pool with custom certificates
Upstream reference: moby#27918 Upstream reference: moby#12756 Signed-off-by: Antonio Murdaca <runcom@redhat.com>
1 parent e772208 commit 91633b5

6 files changed

Lines changed: 48 additions & 138 deletions

File tree

pkg/tlsconfig/config.go

Lines changed: 0 additions & 133 deletions
This file was deleted.

registry/registry.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package registry
33

44
import (
55
"crypto/tls"
6-
"crypto/x509"
76
"errors"
87
"fmt"
98
"io/ioutil"
@@ -64,8 +63,11 @@ func ReadCertsDirectory(tlsConfig *tls.Config, directory string) error {
6463
for _, f := range fs {
6564
if strings.HasSuffix(f.Name(), ".crt") {
6665
if tlsConfig.RootCAs == nil {
67-
// TODO(dmcgowan): Copy system pool
68-
tlsConfig.RootCAs = x509.NewCertPool()
66+
systemPool, err := tlsconfig.SystemCertPool()
67+
if err != nil {
68+
return fmt.Errorf("unable to get system cert pool: %v", err)
69+
}
70+
tlsConfig.RootCAs = systemPool
6971
}
7072
logrus.Debugf("crt: %s", filepath.Join(directory, f.Name()))
7173
data, err := ioutil.ReadFile(filepath.Join(directory, f.Name()))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// +build go1.7
2+
3+
package tlsconfig
4+
5+
import (
6+
"crypto/x509"
7+
"runtime"
8+
9+
"github.com/Sirupsen/logrus"
10+
)
11+
12+
// SystemCertPool returns a copy of the system cert pool,
13+
// returns an error if failed to load or empty pool on windows.
14+
func SystemCertPool() (*x509.CertPool, error) {
15+
certpool, err := x509.SystemCertPool()
16+
if err != nil && runtime.GOOS == "windows" {
17+
logrus.Warnf("Unable to use system certificate pool: %v", err)
18+
return x509.NewCertPool(), nil
19+
}
20+
return certpool, err
21+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// +build !go1.7
2+
3+
package tlsconfig
4+
5+
import (
6+
"crypto/x509"
7+
8+
"github.com/Sirupsen/logrus"
9+
)
10+
11+
// SystemCertPool returns an new empty cert pool,
12+
// accessing system cert pool is supported in go 1.7
13+
func SystemCertPool() (*x509.CertPool, error) {
14+
logrus.Warn("Unable to use system certificate pool: requires building with go 1.7 or later")
15+
return x509.NewCertPool(), nil
16+
}

vendor/src/github.com/docker/go-connections/tlsconfig/config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,13 @@ var ClientDefault = tls.Config{
6565
func certPool(caFile string) (*x509.CertPool, error) {
6666
// If we should verify the server, we need to load a trusted ca
6767
certPool := x509.NewCertPool()
68+
certPool, err := SystemCertPool()
69+
if err != nil {
70+
return nil, fmt.Errorf("failed to read system certificates: %v", err)
71+
}
6872
pem, err := ioutil.ReadFile(caFile)
6973
if err != nil {
70-
return nil, fmt.Errorf("Could not read CA certificate %q: %v", caFile, err)
74+
return nil, fmt.Errorf("could not read CA certificate %q: %v", caFile, err)
7175
}
7276
if !certPool.AppendCertsFromPEM(pem) {
7377
return nil, fmt.Errorf("failed to append certificates from PEM file: %q", caFile)

vendor/src/github.com/docker/libnetwork/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/BurntSushi/toml"
77
log "github.com/Sirupsen/logrus"
88
"github.com/docker/docker/pkg/discovery"
9-
"github.com/docker/docker/pkg/tlsconfig"
9+
"github.com/docker/go-connections/tlsconfig"
1010
"github.com/docker/libkv/store"
1111
"github.com/docker/libnetwork/cluster"
1212
"github.com/docker/libnetwork/datastore"

0 commit comments

Comments
 (0)