Skip to content

Commit 2d495ac

Browse files
codesenbergWGH-
andcommitted
TLS: make --insecure option actually work without custom certificates
As #116 points out, the flag is not really working at the moment, if you don't provide custom client certificates. This commit is doing mostly the same as #116, but I also cleared up some stuff, while we're at it. Hope Github correctly shows the co-authorship. Co-authored-by: WGH <wgh@torlan.ru>
1 parent 39c14df commit 2d495ac

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

client_cert.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,27 @@ import (
77
// readClientCert - helper function to read client certificate
88
// from pem formatted certPath and keyPath files
99
func readClientCert(certPath, keyPath string) ([]tls.Certificate, error) {
10-
if certPath != "" && keyPath != "" {
11-
// load keypair
12-
cert, err := tls.LoadX509KeyPair(certPath, keyPath)
13-
if err != nil {
14-
return nil, err
15-
}
16-
17-
return []tls.Certificate{cert}, nil
18-
}
19-
return nil, nil
10+
// load keypair
11+
cert, err := tls.LoadX509KeyPair(certPath, keyPath)
12+
return []tls.Certificate{cert}, err
2013
}
2114

2215
// generateTLSConfig - helper function to generate a TLS configuration based on
2316
// config
2417
func generateTLSConfig(c config) (*tls.Config, error) {
25-
// Return nil, if no custom cert/key pair was provided.
18+
var (
19+
certs []tls.Certificate
20+
err error
21+
)
2622
// This assumes that the caller has validated that either both or none of
2723
// the c.certPath and c.keyPath are set.
28-
if c.certPath == "" && c.keyPath == "" {
29-
return nil, nil
30-
}
31-
certs, err := readClientCert(c.certPath, c.keyPath)
32-
if err != nil {
33-
return nil, err
24+
if c.certPath != "" && c.keyPath != "" {
25+
certs, err = readClientCert(c.certPath, c.keyPath)
26+
if err != nil {
27+
return nil, err
28+
}
3429
}
30+
3531
// Disable gas warning, because InsecureSkipVerify may be set to true
3632
// for the purpose of testing
3733
/* #nosec */

0 commit comments

Comments
 (0)