Skip to content

Commit

Permalink
PKI: improve error message when parsing PEM bundles (openbao#760)
Browse files Browse the repository at this point in the history
* PKI: improve error message when parsing PEM bundles

Add block counter and add the block number to the error message

Signed-off-by: Klaus Kiefer <[email protected]>

* Update builtin/logical/pki/path_manage_issuers.go

Signed-off-by: Alexander Scheel <[email protected]>

---------

Signed-off-by: Klaus Kiefer <[email protected]>
Signed-off-by: Alexander Scheel <[email protected]>
Co-authored-by: Alexander Scheel <[email protected]>
  • Loading branch information
klaus-sap and cipherboy authored Nov 25, 2024
1 parent 72a1c59 commit 67674a4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion builtin/logical/pki/path_manage_issuers.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,13 @@ func (b *backend) pathImportIssuers(ctx context.Context, req *logical.Request, d
// them to validate no duplicate issuers exist (and place greater
// restrictions during parsing) but allows this code to accept OpenSSL
// parsed chains (with full textual output between PEM entries).
blockCounter := 0
for len(bytes.TrimSpace(pemBytes)) > 0 {
blockCounter++
pemBlock, pemBytes = pem.Decode(pemBytes)
if pemBlock == nil {
return logical.ErrorResponse("provided PEM block contained no data"), nil
msg := fmt.Sprintf("error when parsing block %d: invalid PEM data", blockCounter)
return logical.ErrorResponse(msg), nil
}

pemBlockString := string(pem.EncodeToMemory(pemBlock))
Expand Down

0 comments on commit 67674a4

Please sign in to comment.