Commit 2f1ef6be authored by Kir Kolyshkin's avatar Kir Kolyshkin Committed by Brad Fitzpatrick

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 fa1a49aa there's a method to obtain
user's home directory -- use it here.

Change-Id: I852fbb24249bcfe08f3874fae6e7b9d01d869190
Reviewed-on: https://go-review.googlesource.com/c/139426Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent c6483b61
...@@ -16,7 +16,6 @@ import ( ...@@ -16,7 +16,6 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
"os/user"
"path/filepath" "path/filepath"
"strings" "strings"
"sync" "sync"
...@@ -67,17 +66,17 @@ func execSecurityRoots() (*CertPool, error) { ...@@ -67,17 +66,17 @@ func execSecurityRoots() (*CertPool, error) {
"/Library/Keychains/System.keychain", "/Library/Keychains/System.keychain",
} }
u, err := user.Current() home := os.UserHomeDir()
if err != nil { if home == "" {
if debugExecDarwinRoots { if debugExecDarwinRoots {
println(fmt.Sprintf("crypto/x509: get current user: %v", err)) println("crypto/x509: can't get user home directory")
} }
} else { } else {
args = append(args, 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 // 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"),
) )
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment