-
Notifications
You must be signed in to change notification settings - Fork 19
/
tls.go
33 lines (26 loc) · 926 Bytes
/
tls.go
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
33
package database
import (
"crypto/tls"
"github.com/moov-io/base/log"
)
func LoadTLSClientCertsFromConfig(logger log.Logger, config *MySQLConfig) ([]tls.Certificate, error) {
var clientCerts []tls.Certificate
for _, clientCert := range config.TLSClientCerts {
cert, err := LoadTLSClientCertFromFile(logger, clientCert.CertFilePath, clientCert.KeyFilePath)
if err != nil {
return []tls.Certificate{}, err
}
clientCerts = append(clientCerts, cert)
}
return clientCerts, nil
}
func LoadTLSClientCertFromFile(logger log.Logger, certFile, keyFile string) (tls.Certificate, error) {
if certFile == "" || keyFile == "" {
return tls.Certificate{}, logger.LogErrorf("cert path or key path not provided").Err()
}
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
if err != nil {
return tls.Certificate{}, logger.LogErrorf("error loading client cert/key from file: %v", err).Err()
}
return cert, nil
}