forked from codesenberg/bombardier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_cert.go
37 lines (33 loc) · 911 Bytes
/
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
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) {
if certPath != "" && keyPath != "" {
// load keypair
cert, err := tls.LoadX509KeyPair(certPath, keyPath)
if err != nil {
return nil, err
}
return []tls.Certificate{cert}, nil
}
return nil, nil
}
// generateTLSConfig - helper function to generate a TLS configuration based on
// config
func generateTLSConfig(c config) (*tls.Config, error) {
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
}