Skip to content

Commit

Permalink
Fix panic when parsing x509
Browse files Browse the repository at this point in the history
Signed-off-by: David VIEJO <dviejo@kungfusoftware.es>
  • Loading branch information
dviejokfs committed Nov 4, 2024
1 parent 6f184ae commit 2601809
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion controllers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"crypto/x509"
"encoding/pem"
"errors"
log "github.com/sirupsen/logrus"
"net"
"strconv"
"strings"
"time"

log "github.com/sirupsen/logrus"

corev1 "k8s.io/api/core/v1"
v12 "k8s.io/api/core/v1"
apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
Expand Down Expand Up @@ -70,7 +71,13 @@ func ParseECDSAPrivateKey(contents []byte) (*ecdsa.PrivateKey, error) {
return ecdsaKey, nil
}
func ParseX509Certificate(contents []byte) (*x509.Certificate, error) {
if len(contents) == 0 {
return nil, errors.New("certificate pem is empty")
}
block, _ := pem.Decode(contents)
if block == nil {
return nil, errors.New("failed to decode PEM block")
}
crt, err := x509.ParseCertificate(block.Bytes)
if err != nil {
return nil, err
Expand Down

0 comments on commit 2601809

Please sign in to comment.