about summary refs log tree commit diff
path: root/pkgs/development/compilers/go/cacert-1.7.patch
blob: 57f09c975d9ca1bf95fbcf1dd2c96177d0615368 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
diff --git a/src/crypto/x509/root_cgo_darwin.go b/src/crypto/x509/root_cgo_darwin.go
index a4b33c7..9700b75 100644
--- a/src/crypto/x509/root_cgo_darwin.go
+++ b/src/crypto/x509/root_cgo_darwin.go
@@ -151,11 +151,20 @@ int FetchPEMRoots(CFDataRef *pemRoots) {
 import "C"
 import (
 	"errors"
+	"io/ioutil"
+	"os"
 	"unsafe"
 )
 
 func loadSystemRoots() (*CertPool, error) {
 	roots := NewCertPool()
+	if file := os.Getenv("SSL_CERT_FILE"); file != "" {
+		data, err := ioutil.ReadFile(file)
+		if err == nil {
+			roots.AppendCertsFromPEM(data)
+			return roots, nil
+		}
+	}
 
 	var data C.CFDataRef = nil
 	err := C.FetchPEMRoots(&data)
diff --git a/src/crypto/x509/root_darwin.go b/src/crypto/x509/root_darwin.go
index 59b303d..d4a34ac 100644
--- a/src/crypto/x509/root_darwin.go
+++ b/src/crypto/x509/root_darwin.go
@@ -28,16 +28,25 @@ func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate
 // The linker will not include these unused functions in binaries built with cgo enabled.
 
 func execSecurityRoots() (*CertPool, error) {
+	var (
+		mu    sync.Mutex
+		roots = NewCertPool()
+	)
+
+	if file := os.Getenv("SSL_CERT_FILE"); file != "" {
+		data, err := ioutil.ReadFile(file)
+		if err == nil {
+			roots.AppendCertsFromPEM(data)
+			return roots, nil
+		}
+	}
+
 	cmd := exec.Command("/usr/bin/security", "find-certificate", "-a", "-p", "/System/Library/Keychains/SystemRootCertificates.keychain")
 	data, err := cmd.Output()
 	if err != nil {
 		return nil, err
 	}
 
-	var (
-		mu    sync.Mutex
-		roots = NewCertPool()
-	)
 	add := func(cert *Certificate) {
 		mu.Lock()
 		defer mu.Unlock()
diff --git a/src/crypto/x509/root_unix.go b/src/crypto/x509/root_unix.go
index 7bcb3d6..3986e1a 100644
--- a/src/crypto/x509/root_unix.go
+++ b/src/crypto/x509/root_unix.go
@@ -24,6 +24,14 @@ func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate
 
 func loadSystemRoots() (*CertPool, error) {
 	roots := NewCertPool()
+	if file := os.Getenv("SSL_CERT_FILE"); file != "" {
+		data, err := ioutil.ReadFile(file)
+		if err == nil {
+			roots.AppendCertsFromPEM(data)
+			return roots, nil
+		}
+	}
+
 	var firstErr error
 	for _, file := range certFiles {
 		data, err := ioutil.ReadFile(file)