NewClientTLSConfig: generate TLS config for client side if insecureSkipVerify is set to true, serverName will not be validated
(caPem, certPem, keyPem []byte, insecureSkipVerify bool, serverName string)
| 8 | // NewClientTLSConfig: generate TLS config for client side |
| 9 | // if insecureSkipVerify is set to true, serverName will not be validated |
| 10 | func NewClientTLSConfig(caPem, certPem, keyPem []byte, insecureSkipVerify bool, serverName string) *tls.Config { |
| 11 | pool := x509.NewCertPool() |
| 12 | if !pool.AppendCertsFromPEM(caPem) { |
| 13 | panic("failed to add ca PEM") |
| 14 | } |
| 15 | |
| 16 | cert, err := tls.X509KeyPair(certPem, keyPem) |
| 17 | if err != nil { |
| 18 | panic(err) |
| 19 | } |
| 20 | |
| 21 | config := &tls.Config{ |
| 22 | Certificates: []tls.Certificate{cert}, |
| 23 | RootCAs: pool, |
| 24 | InsecureSkipVerify: insecureSkipVerify, |
| 25 | ServerName: serverName, |
| 26 | } |
| 27 | return config |
| 28 | } |
nothing calls this directly
no outgoing calls
no test coverage detected