portainer/api/http/tls.go

27 lines
620 B
Go
Raw Normal View History

2016-12-18 05:21:29 +00:00
package http
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
)
2016-12-18 05:21:29 +00:00
// createTLSConfiguration initializes a tls.Config using a CA certificate, a certificate and a key
func createTLSConfiguration(caCertPath, certPath, keyPath string) (*tls.Config, error) {
cert, err := tls.LoadX509KeyPair(certPath, keyPath)
if err != nil {
2016-12-18 05:21:29 +00:00
return nil, err
}
caCert, err := ioutil.ReadFile(caCertPath)
if err != nil {
2016-12-18 05:21:29 +00:00
return nil, err
}
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
2016-12-18 05:21:29 +00:00
config := &tls.Config{
Certificates: []tls.Certificate{cert},
RootCAs: caCertPool,
}
2016-12-18 05:21:29 +00:00
return config, nil
}