Debian Codegraph @

ct/x509/root_unix.go

raw symbols SCIP
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.
4
5 //go:build dragonfly || freebsd || linux || nacl || netbsd || openbsd || solaris
6 // +build dragonfly freebsd linux nacl netbsd openbsd solaris
7
8 package x509scip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/ct/x509`/
9
10 import (
11 "io/ioutilscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/"
12 "osscip-go gomod github.com/golang/go/src go1.16 os/"
13 )
14
15 // Possible directories with certificate files; stop after successfully
16 // reading at least one file from a directory.
17 var certDirectoriesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/ct/x509`/certDirectories. = []string{
18 "/etc/ssl/certs", // SLES10/SLES11, https://golang.org/issue/12139
19 "/system/etc/security/cacerts", // Android
20 "/usr/local/share/certs", // FreeBSD
21 "/etc/pki/tls/certs", // Fedora/RHEL
22 "/etc/openssl/certs", // NetBSD
23 }
24
25 const (
26 // certFileEnv is the environment variable which identifies where to locate
27 // the SSL certificate file. If set this overrides the system default.
28 certFileEnvscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/ct/x509`/certFileEnv. = "SSL_CERT_FILE"
29
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 certDirEnvscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/ct/x509`/certDirEnv. = "SSL_CERT_DIR"
33 )
34
35 func (c *Certificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/ct/x509`/Certificate#) systemVerifyscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/ct/x509`/Certificate#systemVerify().(opts *VerifyOptionsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/ct/x509`/VerifyOptions#) (chains [][]*Certificatescip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/ct/x509`/Certificate#, err error) {
36 return nil, nil
37 }
38
39 func loadSystemRootsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/ct/x509`/loadSystemRoots().() (*CertPoolscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/ct/x509`/CertPool#, error) {
40 roots := NewCertPoolscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/ct/x509`/NewCertPool().()
41
42 files := certFilesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/ct/x509`/certFiles.
43 if f := osscip-go gomod github.com/golang/go/src go1.16 os/.Getenvscip-go gomod github.com/golang/go/src go1.16 os/Getenv().(certFileEnvscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/ct/x509`/certFileEnv.); f != "" {
44 files = []string{f}
45 }
46
47 var firstErr error
48 for _, file := range files {
49 data, err := ioutilscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/.ReadFilescip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/ReadFile().(file)
50 if err == nil {
51 roots.AppendCertsFromPEMscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/ct/x509`/CertPool#AppendCertsFromPEM().(data)
52 break
53 }
54 if firstErr == nil && !osscip-go gomod github.com/golang/go/src go1.16 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.16 os/IsNotExist().(err) {
55 firstErr = err
56 }
57 }
58
59 dirs := certDirectoriesscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/ct/x509`/certDirectories.
60 if d := osscip-go gomod github.com/golang/go/src go1.16 os/.Getenvscip-go gomod github.com/golang/go/src go1.16 os/Getenv().(certDirEnvscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/ct/x509`/certDirEnv.); d != "" {
61 dirs = []string{d}
62 }
63
64 for _, directory := range dirs {
65 fis, err := ioutilscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/.ReadDirscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/ReadDir().(directory)
66 if err != nil {
67 if firstErr == nil && !osscip-go gomod github.com/golang/go/src go1.16 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.16 os/IsNotExist().(err) {
68 firstErr = err
69 }
70 continue
71 }
72 rootsAdded := false
73 for _, fi := range fis {
74 data, err := ioutilscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/.ReadFilescip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/ReadFile().(directory + "/" + fi.Namescip-go gomod github.com/golang/go/src go1.16 `io/fs`/FileInfo#Name().())
75 if err == nil && roots.AppendCertsFromPEMscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/ct/x509`/CertPool#AppendCertsFromPEM().(data) {
76 rootsAdded = true
77 }
78 }
79 if rootsAdded {
80 return roots, nil
81 }
82 }
83
84 if len(roots.certsscip-go gomod github.com/zmap/zcrypto . `github.com/zmap/zcrypto/ct/x509`/CertPool#certs.) > 0 {
85 return roots, nil
86 }
87
88 return nil, firstErr
89 }