summary refs log tree commit diff
path: root/pkgs/development/compilers/go/ssl-cert-file-1.15.patch
blob: cca48eb5705cc9c3dbdb7d512f4a0956e7288c4b (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
diff --git a/src/crypto/x509/root_darwin_amd64.go b/src/crypto/x509/root_darwin_amd64.go
index 8ad5a9607d..1d6091cf83 100644
--- a/src/crypto/x509/root_darwin_amd64.go
+++ b/src/crypto/x509/root_darwin_amd64.go
@@ -8,6 +8,7 @@ import (
 	"bytes"
 	"crypto/x509/internal/macOS"
 	"fmt"
+	"io/ioutil"
 	"os"
 	"strings"
 )
@@ -23,6 +24,14 @@ func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate
 var loadSystemRootsWithCgo func() (*CertPool, error)
 
 func loadSystemRoots() (*CertPool, error) {
+	if file := os.Getenv("NIX_SSL_CERT_FILE"); file != "" {
+		data, err := ioutil.ReadFile(file)
+		if err == nil {
+			roots := NewCertPool()
+			roots.AppendCertsFromPEM(data)
+			return roots, nil
+		}
+	}
 	var trustedRoots []*Certificate
 	untrustedRoots := make(map[string]bool)
 
diff --git a/src/crypto/x509/root_darwin_arm64.go b/src/crypto/x509/root_darwin_arm64.go
index 2fb079ba66..6a072f3e78 100644
--- a/src/crypto/x509/root_darwin_arm64.go
+++ b/src/crypto/x509/root_darwin_arm64.go
@@ -6,6 +6,11 @@
 
 package x509
 
+import (
+	"io/ioutil"
+	"os"
+)
+
 func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate, err error) {
 	return nil, nil
 }
@@ -14,6 +19,14 @@ func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate
 var loadSystemRootsWithCgo func() (*CertPool, error)
 
 func loadSystemRoots() (*CertPool, error) {
+	if file := os.Getenv("NIX_SSL_CERT_FILE"); file != "" {
+		data, err := ioutil.ReadFile(file)
+		if err == nil {
+			roots := NewCertPool()
+			roots.AppendCertsFromPEM(data)
+			return roots, nil
+		}
+	}
 	p := NewCertPool()
 	p.AppendCertsFromPEM([]byte(systemRootsPEM))
 	return p, nil
diff --git a/src/crypto/x509/root_unix.go b/src/crypto/x509/root_unix.go
index b48e618a65..195c1ff25a 100644
--- a/src/crypto/x509/root_unix.go
+++ b/src/crypto/x509/root_unix.go
@@ -42,6 +42,13 @@ func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate
 
 func loadSystemRoots() (*CertPool, error) {
 	roots := NewCertPool()
+	if file := os.Getenv("NIX_SSL_CERT_FILE"); file != "" {
+		data, err := ioutil.ReadFile(file)
+		if err == nil {
+			roots.AppendCertsFromPEM(data)
+			return roots, nil
+		}
+	}
 
 	files := certFiles
 	if f := os.Getenv(certFileEnv); f != "" {