caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
58.12k stars 4.03k forks source link

Error "input contained more than a single PEM block" due to extra whitespace #6530

Closed mdepot closed 2 months ago

mdepot commented 2 months ago

Caddy is throwing the error "input contained more than a single PEM block" even though I confirmed the cert I was referencing was a single block. It turns out this is happening simply because my cert file had an extra newline at the end of the file.

The error comes from function pemDecodeSingleCert in file caddy/modules/caddypki/crypto.go

Perhaps consider changing from if len(remaining) > 0 to if len(strings.TrimSpace(remaining)) > 0

mholt commented 2 months ago

Interesting -- I guess that makes sense. Have you confirmed that fixes it for you? If so I can push a patch right away (or merge a PR if you want the credit).

mdepot commented 2 months ago

I did not test any code changes, however I can say that removing the extra (second) newline at the end of my cert file did eliminate the error.

mholt commented 2 months ago

By adding a newline to a certificate I am not able to reproduce the error, so I can't fix the bug.

If you can post enough information here to reproduce the behavior, I can reopen this and patch it up. Until then this isn't actionable so I'll close the issue.