1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build aix dragonfly freebsd linux nacl netbsd openbsd solaris
14 // Possible directories with certificate files; stop after successfully
15 // reading at least one file from a directory.
16 var certDirectories
= []string{
17 "/etc/ssl/certs", // SLES10/SLES11, https://golang.org/issue/12139
18 "/system/etc/security/cacerts", // Android
19 "/usr/local/share/certs", // FreeBSD
20 "/etc/pki/tls/certs", // Fedora/RHEL
21 "/etc/openssl/certs", // NetBSD
22 "/var/ssl/certs", // AIX
26 // certFileEnv is the environment variable which identifies where to locate
27 // the SSL certificate file. If set this overrides the system default.
28 certFileEnv
= "SSL_CERT_FILE"
30 // certDirEnv is the environment variable which identifies which directory
31 // to check for SSL certificate files. If set this overrides the system default.
32 certDirEnv
= "SSL_CERT_DIR"
35 func (c
*Certificate
) systemVerify(opts
*VerifyOptions
) (chains
[][]*Certificate
, err error
) {
39 func loadSystemRoots() (*CertPool
, error
) {
40 roots
:= NewCertPool()
43 if f
:= os
.Getenv(certFileEnv
); f
!= "" {
48 for _
, file
:= range files
{
49 data
, err
:= ioutil
.ReadFile(file
)
51 roots
.AppendCertsFromPEM(data
)
54 if firstErr
== nil && !os
.IsNotExist(err
) {
59 dirs
:= certDirectories
60 if d
:= os
.Getenv(certDirEnv
); d
!= "" {
64 for _
, directory
:= range dirs
{
65 fis
, err
:= ioutil
.ReadDir(directory
)
67 if firstErr
== nil && !os
.IsNotExist(err
) {
73 for _
, fi
:= range fis
{
74 data
, err
:= ioutil
.ReadFile(directory
+ "/" + fi
.Name())
75 if err
== nil && roots
.AppendCertsFromPEM(data
) {
84 if len(roots
.certs
) > 0 {