mirror of https://github.com/portainer/portainer
27 lines
622 B
Go
27 lines
622 B
Go
package crypto
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"crypto/x509"
|
|
"io/ioutil"
|
|
)
|
|
|
|
// 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 {
|
|
return nil, err
|
|
}
|
|
caCert, err := ioutil.ReadFile(caCertPath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
caCertPool := x509.NewCertPool()
|
|
caCertPool.AppendCertsFromPEM(caCert)
|
|
config := &tls.Config{
|
|
Certificates: []tls.Certificate{cert},
|
|
RootCAs: caCertPool,
|
|
}
|
|
return config, nil
|
|
}
|