예제 #1
0
// 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
}
예제 #2
0
func init() {
	var err error
	RootCAs, err = x509.SystemCertPool()
	if err != nil {
		RootCAs = roots.MozillaRootCAs
	}
}
예제 #3
0
// 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
}
예제 #4
0
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)
	}
}
예제 #5
0
파일: tls.go 프로젝트: square/ghostunnel
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
}
예제 #6
0
// 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)
}
예제 #7
0
func LoadSystemRoots() (*x509.CertPool, error) {
	return x509.SystemCertPool()
}