Skip to content

Commit fc8584f

Browse files
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 golang#16532 Change-Id: I8594a6b8940c58df8a8015b274fa45c39e18862c
1 parent a610957 commit fc8584f

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
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

0 commit comments

Comments
 (0)