7
7
"crypto/x509"
8
8
"io/ioutil"
9
9
"os"
10
- "os/user"
11
10
"path/filepath"
12
11
13
12
"github.com/pkg/errors"
@@ -78,20 +77,14 @@ func ssl(o values) (*tls.Config, error) {
78
77
// in the user's home directory. The configured files must exist and have
79
78
// the correct permissions.
80
79
func sslClientCertificates (tlsConf * tls.Config , o values ) error {
81
- // usr.Current() might fail when cross-compiling. We have to ignore the
82
- // error and continue without home directory defaults, since we wouldn't
83
- // know from where to load them.
84
- usr , err := user .Current ()
85
- if err != nil {
86
- return err
87
- }
80
+ home := userHomeDir ()
88
81
89
82
// In libpq, the client certificate is only loaded if the setting is not blank.
90
83
//
91
84
// https://github.com/postgres/postgres/blob/REL9_6_2/src/interfaces/libpq/fe-secure-openssl.c#L1036-L1037
92
85
sslcert := o ["sslcert" ]
93
- if len (sslcert ) == 0 && usr != nil {
94
- sslcert = filepath .Join (usr . HomeDir , ".postgresql" , "postgresql.crt" )
86
+ if len (sslcert ) == 0 && home != "" {
87
+ sslcert = filepath .Join (home , ".postgresql" , "postgresql.crt" )
95
88
}
96
89
// https://github.com/postgres/postgres/blob/REL9_6_2/src/interfaces/libpq/fe-secure-openssl.c#L1045
97
90
if len (sslcert ) == 0 {
@@ -108,8 +101,8 @@ func sslClientCertificates(tlsConf *tls.Config, o values) error {
108
101
//
109
102
// https://github.com/postgres/postgres/blob/REL9_6_2/src/interfaces/libpq/fe-secure-openssl.c#L1123-L1222
110
103
sslkey := o ["sslkey" ]
111
- if len (sslkey ) == 0 && usr != nil {
112
- sslkey = filepath .Join (usr . HomeDir , ".postgresql" , "postgresql.key" )
104
+ if len (sslkey ) == 0 && home != "" {
105
+ sslkey = filepath .Join (home , ".postgresql" , "postgresql.key" )
113
106
}
114
107
115
108
if len (sslkey ) > 0 {
0 commit comments