// mustGetSystemCertPool returns empty cert pool in case of error (windows) func mustGetSystemCertPool() *x509.CertPool { pool, err := x509.SystemCertPool() if err != nil { return x509.NewCertPool() } return pool }
func init() { var err error RootCAs, err = x509.SystemCertPool() if err != nil { RootCAs = roots.MozillaRootCAs } }
// SystemCertPool returns a copy of the system cert pool, // returns an error if failed to load or empty pool on windows. func SystemCertPool() (*x509.CertPool, error) { certpool, err := x509.SystemCertPool() if err != nil && runtime.GOOS == "windows" { logrus.Warnf("Unable to use system certificate pool: %v", err) return x509.NewCertPool(), nil } return certpool, err }
func printSystemCerts() { certPool, err := x509.SystemCertPool() if err != nil { fmt.Printf("Get system cert pool failed: %v", err) return } subjects := certPool.Subjects() for _, subject := range subjects { fmt.Println(subject) } }
func caBundle(caBundlePath string) (*x509.CertPool, error) { if caBundlePath == "" { return x509.SystemCertPool() } caBundleBytes, err := ioutil.ReadFile(caBundlePath) if err != nil { return nil, err } bundle := x509.NewCertPool() bundle.AppendCertsFromPEM(caBundleBytes) return bundle, nil }
// newClient returns a new coverage server client. func newClient(server, cert, token string) client.Client { pool, err := x509.SystemCertPool() if err != nil { pool = x509.NewCertPool() } conf := &tls.Config{RootCAs: pool} pem, _ := ioutil.ReadFile(cert) if len(pem) != 0 { pool.AppendCertsFromPEM(pem) } if len(token) == 0 { return client.NewClientTLS(server, conf) } return client.NewClientTokenTLS(server, token, conf) }
func LoadSystemRoots() (*x509.CertPool, error) { return x509.SystemCertPool() }