Skip to content

Commit

Permalink
caddypki: Return error if no PEM data found
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed Jan 7, 2022
1 parent 4b9849c commit c634bbe
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions modules/caddypki/crypto.go
Expand Up @@ -81,6 +81,9 @@ func pemEncodePrivateKey(key crypto.PrivateKey) ([]byte, error) {
// TODO: this is the same thing as in certmagic. Should we reuse that code somehow? It's unexported.
func pemDecodePrivateKey(keyPEMBytes []byte) (crypto.PrivateKey, error) {
keyBlockDER, _ := pem.Decode(keyPEMBytes)
if keyBlockDER == nil {
return nil, fmt.Errorf("no PEM data found")
}

if keyBlockDER.Type != "PRIVATE KEY" && !strings.HasSuffix(keyBlockDER.Type, " PRIVATE KEY") {
return nil, fmt.Errorf("unknown PEM header %q", keyBlockDER.Type)
Expand Down

1 comment on commit c634bbe

@simaotwx
Copy link
Contributor

@simaotwx simaotwx commented on c634bbe Jan 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed here:

caddyserver/certmagic@0335715

I experienced this issue which is why I fixed the crash in certmagic

Please sign in to comment.