Skip to content

Commit

Permalink
Clearer detection of encrypted PEM
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepeterson committed May 13, 2022
1 parent 4122483 commit 1796922
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
"encoding/pem"
"errors"
Expand Down Expand Up @@ -273,8 +274,8 @@ func readPEMCertAndKey(input []byte) (cert []byte, key []byte, err error) {
if block.Type == "CERTIFICATE" {
cert = pem.EncodeToMemory(block)
} else if block.Type == "PRIVATE KEY" || strings.HasSuffix(block.Type, " PRIVATE KEY") {
if len(block.Headers) > 0 {
err = errors.New("private key PEM headers present: possibly encrypted")
if x509.IsEncryptedPEMBlock(block) {
err = errors.New("private key PEM appears to be encrypted")
break
}
key = pem.EncodeToMemory(block)
Expand Down

0 comments on commit 1796922

Please sign in to comment.