func GetTLSConfig()

in gateway/gateway.go [48:70]


func GetTLSConfig(trust *entity.Trust) (*tls.Config, error) {
	config := &tls.Config{}
	if trust.ClientCertificateFilePath != nil && trust.ClientKeyFilePath != nil {
		cert, err := tls.LoadX509KeyPair(*trust.ClientCertificateFilePath, *trust.ClientKeyFilePath)
		if err != nil {
			return nil, fmt.Errorf(
				"error creating x509 keypair from client cert file %s and client key file %s",
				*trust.ClientCertificateFilePath, *trust.ClientKeyFilePath)
		}
		config.Certificates = []tls.Certificate{cert}
	}
	caCertPool := x509.NewCertPool()
	if trust.CAFilePath != nil {
		caCert, err := ioutil.ReadFile(*trust.CAFilePath)
		if err != nil {
			return nil, fmt.Errorf("error opening certificate file %s, error: %s", *trust.CAFilePath, err)
		}
		caCertPool.AppendCertsFromPEM(caCert)
		config.RootCAs = caCertPool
	}

	return config, nil
}