-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtls.go
More file actions
32 lines (27 loc) · 765 Bytes
/
tls.go
File metadata and controls
32 lines (27 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package cmhttp
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"net/http"
)
// ConfigureTLS reads the certificate bundle at rootCertsFilePath and
// configures the given transport to verify server certificate against these
// certificates.
func ConfigureTLS(t *http.Transport, rootCertsFilePath string) error {
certPool := x509.NewCertPool()
buf, err := ioutil.ReadFile(rootCertsFilePath)
if err != nil {
return err
}
certPool.AppendCertsFromPEM(buf)
t.TLSClientConfig = &tls.Config{RootCAs: certPool}
return nil
}
// MustConfigureTLS is the same as ConfigureTLS, but panics if there is an
// error.
func MustConfigureTLS(t *http.Transport, rootCertsFilePath string) {
if err := ConfigureTLS(t, rootCertsFilePath); err != nil {
panic(err)
}
}