Skip to content

Commit 9dc30e1

Browse files
authored
TLS improvements (gophercloud#134)
This commit contains two improvements to the existing TLS module: 1. Now the library ignores the fact the CA certificate can be broken (if it can't parse it for some reason, it just leaves an empty string without a notice). From now we raise an error in this case. 2. It tries to prevent some obvious formatting errors in the certificate like leading and trailing spaces, additional new lines etc.
1 parent f41c176 commit 9dc30e1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

internal/util.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package internal
22

33
import (
4+
"bytes"
45
"crypto/tls"
56
"crypto/x509"
67
"fmt"
@@ -50,7 +51,9 @@ func PrepareTLSConfig(caCertFile, clientCertFile, clientKeyFile string, insecure
5051
}
5152

5253
caCertPool := x509.NewCertPool()
53-
caCertPool.AppendCertsFromPEM(caCert)
54+
if ok := caCertPool.AppendCertsFromPEM(bytes.TrimSpace(caCert)); !ok {
55+
return nil, fmt.Errorf("Error parsing CA Cert from %s", caCertFile)
56+
}
5457
config.RootCAs = caCertPool
5558
}
5659

0 commit comments

Comments
 (0)