Skip to content

Commit b4e39e7

Browse files
authored
fix ca certificate verification to ignore trailing whitespaces (#40)
1 parent cdb7a73 commit b4e39e7

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

app/ca.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func parsePEM(bundle []byte) (certBlocks [][]byte, pemBlocks []byte, err error)
4242
}
4343
// If p is greater than 0, then this means that there was a portion of the certificate that
4444
// is/was malformed.
45-
if len(p) > 0 {
45+
if len(p) > 0 && strings.TrimSpace(string(p)) != "" {
4646
return nil, nil, fmt.Errorf("failed to parse one or more certificates, remainingBytesLen=%d", len(p))
4747
}
4848
return certBlocks, pemBlocks, nil

app/ca_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ func TestCABundleParser(t *testing.T) {
156156
out, err = parseCertificates(encodedBundle)
157157
assert.Error(t, err)
158158

159+
// ignore trailing whitespaces
160+
encodedBundle = base64.StdEncoding.EncodeToString([]byte(cert1 + "\n" + cert2 + "\n "))
161+
out, err = parseCertificates(encodedBundle)
162+
assert.NoError(t, err)
159163
}
160164

161165
func TestCAAddAndRemove(t *testing.T) {

0 commit comments

Comments
 (0)