Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 00:15 UTC
caddypki: Return error if no PEM data found
Best guess for https://caddy.community/t/on-fly-certificate-generation-based-on-sni/14639/4
Matthew Holt committed
Jan 7, 2022 at 10:55 UTC
c634bbe9cc7ef6ce6f9f776010ce96384fd43340
1 file changed
+3
modules/caddypki/crypto.go
+3
@@ -81,6 +81,9 @@ func pemEncodePrivateKey(key crypto.PrivateKey) ([]byte, error) {
81
// TODO: this is the same thing as in certmagic. Should we reuse that code somehow? It's unexported.
82
func pemDecodePrivateKey(keyPEMBytes []byte) (crypto.PrivateKey, error) {
83
keyBlockDER, _ := pem.Decode(keyPEMBytes)
84
+ if keyBlockDER == nil {
85
+ return nil, fmt.Errorf("no PEM data found")
86
+ }
87
88
if keyBlockDER.Type != "PRIVATE KEY" && !strings.HasSuffix(keyBlockDER.Type, " PRIVATE KEY") {
89
return nil, fmt.Errorf("unknown PEM header %q", keyBlockDER.Type)