Skip to content

Commit 4dbcacd

Browse files
mastercactapusbradfitz
authored andcommitted
crypto/x509: load all trusted certs on darwin (nocgo)
The current implementation ignores certificates that exist in the login and System keychains. This change adds the missing System and login keychain files to the `/usr/bin/security` command in `execSecurityRoots`. If the current user cannot be obtained, the login keychain is ignored. Refs #16532 Change-Id: I8594a6b8940c58df8a8015b274fa45c39e18862c Reviewed-on: https://go-review.googlesource.com/36941 Run-TryBot: Emmanuel Odeke <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent a005a8d commit 4dbcacd

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/crypto/x509/root_darwin.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"io/ioutil"
1717
"os"
1818
"os/exec"
19+
"os/user"
1920
"path/filepath"
2021
"strings"
2122
"sync"
@@ -61,7 +62,26 @@ func execSecurityRoots() (*CertPool, error) {
6162
println(fmt.Sprintf("crypto/x509: %d certs have a trust policy", len(hasPolicy)))
6263
}
6364

64-
cmd := exec.Command("/usr/bin/security", "find-certificate", "-a", "-p", "/System/Library/Keychains/SystemRootCertificates.keychain")
65+
args := []string{"find-certificate", "-a", "-p",
66+
"/System/Library/Keychains/SystemRootCertificates.keychain",
67+
"/Library/Keychains/System.keychain",
68+
}
69+
70+
u, err := user.Current()
71+
if err != nil {
72+
if debugExecDarwinRoots {
73+
println(fmt.Sprintf("crypto/x509: get current user: %v", err))
74+
}
75+
} else {
76+
args = append(args,
77+
filepath.Join(u.HomeDir, "/Library/Keychains/login.keychain"),
78+
79+
// Fresh installs of Sierra use a slightly different path for the login keychain
80+
filepath.Join(u.HomeDir, "/Library/Keychains/login.keychain-db"),
81+
)
82+
}
83+
84+
cmd := exec.Command("/usr/bin/security", args...)
6585
data, err := cmd.Output()
6686
if err != nil {
6787
return nil, err

src/go/build/deps_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ var pkgDeps = map[string][]string{
377377
},
378378
"crypto/x509": {
379379
"L4", "CRYPTO-MATH", "OS", "CGO",
380-
"crypto/x509/pkix", "encoding/pem", "encoding/hex", "net", "syscall",
380+
"crypto/x509/pkix", "encoding/pem", "encoding/hex", "net", "os/user", "syscall",
381381
},
382382
"crypto/x509/pkix": {"L4", "CRYPTO-MATH"},
383383

0 commit comments

Comments
 (0)