mirror of
https://github.com/tailscale/tailscale.git
synced 2024-12-01 14:05:39 +00:00
3bab226299
Snapshotted from Go commit 619c7a48a38b28b521591b490fd14ccb7ea5e821 (https://go-review.googlesource.com/c/go/+/229762, "crypto/x509: add x509omitbundledroots build tag to not embed roots") With 975c01342a25899962969833d8b2873dc8856a4f (https://go-review.googlesource.com/c/go/+/220721) removed, because it depends on other stuff in Go std that doesn't yet exist in a Go release. Also, add a subset fork of Go's internal/testenv, for use by x509's tests.
93 lines
2.4 KiB
Go
93 lines
2.4 KiB
Go
// Copyright 2011 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// +build aix dragonfly freebsd js,wasm linux netbsd openbsd solaris
|
|
|
|
package x509
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
// Possible directories with certificate files; stop after successfully
|
|
// reading at least one file from a directory.
|
|
var certDirectories = []string{
|
|
"/etc/ssl/certs", // SLES10/SLES11, https://golang.org/issue/12139
|
|
"/system/etc/security/cacerts", // Android
|
|
"/usr/local/share/certs", // FreeBSD
|
|
"/etc/pki/tls/certs", // Fedora/RHEL
|
|
"/etc/openssl/certs", // NetBSD
|
|
"/var/ssl/certs", // AIX
|
|
}
|
|
|
|
const (
|
|
// certFileEnv is the environment variable which identifies where to locate
|
|
// the SSL certificate file. If set this overrides the system default.
|
|
certFileEnv = "SSL_CERT_FILE"
|
|
|
|
// certDirEnv is the environment variable which identifies which directory
|
|
// to check for SSL certificate files. If set this overrides the system default.
|
|
// It is a colon separated list of directories.
|
|
// See https://www.openssl.org/docs/man1.0.2/man1/c_rehash.html.
|
|
certDirEnv = "SSL_CERT_DIR"
|
|
)
|
|
|
|
func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate, err error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func loadSystemRoots() (*CertPool, error) {
|
|
roots := NewCertPool()
|
|
|
|
files := certFiles
|
|
if f := os.Getenv(certFileEnv); f != "" {
|
|
files = []string{f}
|
|
}
|
|
|
|
var firstErr error
|
|
for _, file := range files {
|
|
data, err := ioutil.ReadFile(file)
|
|
if err == nil {
|
|
roots.AppendCertsFromPEM(data)
|
|
break
|
|
}
|
|
if firstErr == nil && !os.IsNotExist(err) {
|
|
firstErr = err
|
|
}
|
|
}
|
|
|
|
dirs := certDirectories
|
|
if d := os.Getenv(certDirEnv); d != "" {
|
|
// OpenSSL and BoringSSL both use ":" as the SSL_CERT_DIR separator.
|
|
// See:
|
|
// * https://golang.org/issue/35325
|
|
// * https://www.openssl.org/docs/man1.0.2/man1/c_rehash.html
|
|
dirs = strings.Split(d, ":")
|
|
}
|
|
|
|
for _, directory := range dirs {
|
|
fis, err := ioutil.ReadDir(directory)
|
|
if err != nil {
|
|
if firstErr == nil && !os.IsNotExist(err) {
|
|
firstErr = err
|
|
}
|
|
continue
|
|
}
|
|
for _, fi := range fis {
|
|
data, err := ioutil.ReadFile(directory + "/" + fi.Name())
|
|
if err == nil {
|
|
roots.AppendCertsFromPEM(data)
|
|
}
|
|
}
|
|
}
|
|
|
|
if len(roots.certs) > 0 || firstErr == nil {
|
|
return roots, nil
|
|
}
|
|
|
|
return nil, firstErr
|
|
}
|