Skip to content

Commit

Permalink
Don't bundle the CA certificate when selfsigned
Browse files Browse the repository at this point in the history
  • Loading branch information
munnerz committed Aug 10, 2018
1 parent 6308c7b commit 478e0d8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/util/pki/csr.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,14 @@ func SignCertificate(template *x509.Certificate, issuerCert *x509.Certificate, p
return nil, nil, fmt.Errorf("error encoding certificate PEM: %s", err.Error())
}

// bundle the CA
err = pem.Encode(pemBytes, &pem.Block{Type: "CERTIFICATE", Bytes: issuerCert.Raw})
if err != nil {
return nil, nil, fmt.Errorf("error encoding issuer cetificate PEM: %s", err.Error())
// don't bundle the CA for selfsigned certificates
// TODO: better comparison method here? for now we can just compare pointers.
if issuerCert != template {
// bundle the CA
err = pem.Encode(pemBytes, &pem.Block{Type: "CERTIFICATE", Bytes: issuerCert.Raw})
if err != nil {
return nil, nil, fmt.Errorf("error encoding issuer cetificate PEM: %s", err.Error())
}
}

return pemBytes.Bytes(), cert, err
Expand Down

0 comments on commit 478e0d8

Please sign in to comment.