-
Notifications
You must be signed in to change notification settings - Fork 321
/
Copy pathclient_cert.go
39 lines (35 loc) · 1 KB
/
client_cert.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
34
35
36
37
38
39
package main
import (
"crypto/tls"
)
// readClientCert - helper function to read client certificate
// from pem formatted certPath and keyPath files
func readClientCert(certPath, keyPath string) ([]tls.Certificate, error) {
// load keypair
cert, err := tls.LoadX509KeyPair(certPath, keyPath)
return []tls.Certificate{cert}, err
}
// generateTLSConfig - helper function to generate a TLS configuration based on
// config
func generateTLSConfig(c config) (*tls.Config, error) {
var (
certs []tls.Certificate
err error
)
// This assumes that the caller has validated that either both or none of
// the c.certPath and c.keyPath are set.
if c.certPath != "" && c.keyPath != "" {
certs, err = readClientCert(c.certPath, c.keyPath)
if err != nil {
return nil, err
}
}
// Disable gas warning, because InsecureSkipVerify may be set to true
// for the purpose of testing
/* #nosec */
tlsConfig := &tls.Config{
InsecureSkipVerify: c.insecure,
Certificates: certs,
}
return tlsConfig, nil
}