Skip to content

Commit b9b5bc1

Browse files
committed
Allow blocks in pem files in any order
GODRIVER-287 Closes #39 Change-Id: Id3cb2d6d2143844b5a27d3b45f967220caaff48c
1 parent d3ebe37 commit b9b5bc1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

core/connection/tlsconfig.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ func (c *TLSConfig) AddClientCertFromFile(clientFile string) (string, error) {
9191
certDecodedBlock = currentBlock.Bytes
9292
start += len(certBlock)
9393
} else if strings.HasSuffix(currentBlock.Type, "PRIVATE KEY") {
94-
if len(certBlock) == 0 {
95-
return "", fmt.Errorf("failed to find CERTIFICATE but did find private key; PEM inputs may be switched")
96-
}
9794
if c.clientCertPass != nil && x509.IsEncryptedPEMBlock(currentBlock) {
9895
var encoded bytes.Buffer
9996
buf, err := x509.DecryptPEMBlock(currentBlock, []byte(c.clientCertPass()))
@@ -110,6 +107,12 @@ func (c *TLSConfig) AddClientCertFromFile(clientFile string) (string, error) {
110107
}
111108
}
112109
}
110+
if len(certBlock) == 0 {
111+
return "", fmt.Errorf("failed to find CERTIFICATE")
112+
}
113+
if len(keyBlock) == 0 {
114+
return "", fmt.Errorf("failed to find PRIVATE KEY")
115+
}
113116

114117
cert, err := tls.X509KeyPair(certBlock, keyBlock)
115118
if err != nil {

0 commit comments

Comments
 (0)