From: Kir Kolyshkin Date: Thu, 4 Oct 2018 01:41:18 +0000 (-0700) Subject: crypto/x509: fix getting user home dir on darwin X-Git-Tag: go1.12beta1~901 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2f1ef6be000fdf4ab74cb306e448c9e0e49bf148;p=gostls13.git crypto/x509: fix getting user home dir on darwin As pointed out in https://github.com/golang/go/issues/26463, HOME (or equivalent) environment variable (rather than the value obtained by parsing /etc/passwd or the like) should be used to obtain user's home directory. Since commit fa1a49aa556d8 there's a method to obtain user's home directory -- use it here. Change-Id: I852fbb24249bcfe08f3874fae6e7b9d01d869190 Reviewed-on: https://go-review.googlesource.com/c/139426 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/crypto/x509/root_darwin.go b/src/crypto/x509/root_darwin.go index 9d7b3a6ffb..ae69a2fadd 100644 --- a/src/crypto/x509/root_darwin.go +++ b/src/crypto/x509/root_darwin.go @@ -16,7 +16,6 @@ import ( "io/ioutil" "os" "os/exec" - "os/user" "path/filepath" "strings" "sync" @@ -67,17 +66,17 @@ func execSecurityRoots() (*CertPool, error) { "/Library/Keychains/System.keychain", } - u, err := user.Current() - if err != nil { + home := os.UserHomeDir() + if home == "" { if debugExecDarwinRoots { - println(fmt.Sprintf("crypto/x509: get current user: %v", err)) + println("crypto/x509: can't get user home directory") } } else { args = append(args, - filepath.Join(u.HomeDir, "/Library/Keychains/login.keychain"), + filepath.Join(home, "/Library/Keychains/login.keychain"), // Fresh installs of Sierra use a slightly different path for the login keychain - filepath.Join(u.HomeDir, "/Library/Keychains/login.keychain-db"), + filepath.Join(home, "/Library/Keychains/login.keychain-db"), ) }