No description
  • Go 97.7%
  • Makefile 2.3%
Find a file
Mohan Manikanta 0e7b58ffb5
Merge pull request #39 from hashicorp/compliance/add-headers
[IND-4226] [COMPLIANCE] Add Copyright and License Headers
2025-11-04 12:57:03 +05:30
.github [COMPLIANCE] Update Copyright and License Headers 2025-11-03 15:29:03 +00:00
test-fixtures Add a few more basic unit tests 2016-05-03 09:04:01 -05:00
.go-version IND-2101 suggested changes made 2025-03-10 16:49:20 +05:30
.golangci.yml [COMPLIANCE] Add Copyright and License Headers 2025-11-04 07:24:57 +00:00
.travis.yml [COMPLIANCE] Add Copyright and License Headers 2025-11-04 07:24:57 +00:00
CHANGELOG.md CHANGELOG.md file is added 2025-06-06 16:56:58 +05:30
doc.go [COMPLIANCE] Add Copyright and License Headers 2025-11-04 07:24:57 +00:00
go.mod IND-2101 suggested changes made 2025-03-10 16:49:20 +05:30
go.sum Update to new version of homedir 2019-06-10 17:58:08 -04:00
LICENSE [COMPLIANCE] Update Copyright and License Headers 2025-11-03 15:29:03 +00:00
Makefile workflow updation 2025-02-18 15:52:49 +05:30
README.md Fix outdated readme 2019-12-16 11:16:03 +01:00
rootcerts.go [COMPLIANCE] Add Copyright and License Headers 2025-11-04 07:24:57 +00:00
rootcerts_base.go [COMPLIANCE] Add Copyright and License Headers 2025-11-04 07:24:57 +00:00
rootcerts_darwin.go [COMPLIANCE] Add Copyright and License Headers 2025-11-04 07:24:57 +00:00
rootcerts_darwin_test.go [COMPLIANCE] Add Copyright and License Headers 2025-11-04 07:24:57 +00:00
rootcerts_test.go [COMPLIANCE] Add Copyright and License Headers 2025-11-04 07:24:57 +00:00

rootcerts

Functions for loading root certificates for TLS connections.


Go's standard library crypto/tls provides a common mechanism for configuring TLS connections in tls.Config. The RootCAs field on this struct is a pool of certificates for the client to use as a trust store when verifying server certificates.

This library contains utility functions for loading certificates destined for that field, as well as one other important thing:

When the RootCAs field is nil, the standard library attempts to load the host's root CA set. This behavior is OS-specific, and the Darwin implementation contains a bug that prevents trusted certificates from the System and Login keychains from being loaded. This library contains Darwin-specific behavior that works around that bug.

Example Usage

Here's a snippet demonstrating how this library is meant to be used:

func httpClient() (*http.Client, error)
	tlsConfig := &tls.Config{}
	err := rootcerts.ConfigureTLS(tlsConfig, &rootcerts.Config{
		CAFile:        os.Getenv("MYAPP_CAFILE"),
		CAPath:        os.Getenv("MYAPP_CAPATH"),
		CACertificate: []byte(os.Getenv("MYAPP_CERTIFICATE")),
	})
	if err != nil {
		return nil, err
	}
	c := cleanhttp.DefaultClient()
	t := cleanhttp.DefaultTransport()
	t.TLSClientConfig = tlsConfig
	c.Transport = t
	return c, nil
}