Skip to content

Commit

Permalink
Checks if the TLS secret contains a valid keypair structure, with 'CE…
Browse files Browse the repository at this point in the history
…RTIFICATE' before the Private Key
  • Loading branch information
Ricardo Pchevuzinske Katz committed Mar 1, 2017
1 parent fb8e2d7 commit 02fbf00
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions core/pkg/net/ssl/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func AddOrUpdateCertAndKey(name string, cert, key, ca []byte) (*ingress.SSLCert,
return nil, fmt.Errorf("No valid PEM formatted block found")
}

// If the file does not start with 'BEGIN CERTIFICATE' it's invalid and must not be used.
if pemBlock.Type != "CERTIFICATE" {
return nil, fmt.Errorf("Certificate %v contains invalid data, and must be created with 'kubectl create secret tls'", name)
}

pemCert, err := x509.ParseCertificate(pemBlock.Bytes)
if err != nil {
return nil, err
Expand Down Expand Up @@ -138,6 +143,10 @@ func AddCertAuth(name string, ca []byte) (*ingress.SSLCert, error) {
if pemCABlock == nil {
return nil, fmt.Errorf("No valid PEM formatted block found")
}
// If the first certificate does not start with 'BEGIN CERTIFICATE' it's invalid and must not be used.
if pemCABlock.Type != "CERTIFICATE" {
return nil, fmt.Errorf("CA File %v contains invalid data, and must be created only with PEM formated certificates", name)
}

_, err := x509.ParseCertificate(pemCABlock.Bytes)
if err != nil {
Expand Down

0 comments on commit 02fbf00

Please sign in to comment.