Skip to content

Commit

Permalink
Simplify KU, EKU, and SKID fields of issued certs (#472)
Browse files Browse the repository at this point in the history
To reflect current WebPKI best practices:
- Do not include the KeyEncipherment KU in end-entity certs (it is not
used in TLS 1.2+)
- Do not include the TLS Client Auth EKU in any certs (root programs are
moving towards single-purpose hierarchies)
- Do not include the Subject Key ID in end-entity certs (it is not
useful for chain-building there)
  • Loading branch information
aarongable authored Aug 21, 2024
1 parent 9d3a771 commit ac77969
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions ca/ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func makeKey() (*rsa.PrivateKey, []byte, error) {
return key, ski, nil
}

func (ca *CAImpl) makeRootCert(
func (ca *CAImpl) makeCACert(
subjectKey crypto.Signer,
subject pkix.Name,
subjectKeyID []byte,
Expand All @@ -122,7 +122,7 @@ func (ca *CAImpl) makeRootCert(
NotAfter: time.Now().AddDate(30, 0, 0),

KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
SubjectKeyId: subjectKeyID,
BasicConstraintsValid: true,
IsCA: true,
Expand Down Expand Up @@ -175,7 +175,7 @@ func (ca *CAImpl) newRootIssuer(name string) (*issuer, error) {
subject := pkix.Name{
CommonName: rootCAPrefix + name,
}
rc, err := ca.makeRootCert(rk, subject, subjectKeyID, nil)
rc, err := ca.makeCACert(rk, subject, subjectKeyID, nil)
if err != nil {
return nil, err
}
Expand All @@ -192,7 +192,7 @@ func (ca *CAImpl) newIntermediateIssuer(root *issuer, intermediateKey crypto.Sig
return nil, errors.New("internal error: root must not be nil")
}
// Make an intermediate certificate with the root issuer
ic, err := ca.makeRootCert(intermediateKey, subject, subjectKeyID, root)
ic, err := ca.makeCACert(intermediateKey, subject, subjectKeyID, root)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -264,12 +264,8 @@ func (ca *CAImpl) newCertificate(domains []string, ips []net.IP, key crypto.Publ
}
issuer := defaultChain[0]

subjectKeyID, err := makeSubjectKeyID(key)
if err != nil {
return nil, fmt.Errorf("cannot create subject key ID: %s", err.Error())
}

certNotBefore := time.Now()
var err error
if notBefore != "" {
certNotBefore, err = time.Parse(time.RFC3339, notBefore)
if err != nil {
Expand Down Expand Up @@ -297,9 +293,8 @@ func (ca *CAImpl) newCertificate(domains []string, ips []net.IP, key crypto.Publ
NotBefore: certNotBefore,
NotAfter: certNotAfter,

KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
SubjectKeyId: subjectKeyID,
KeyUsage: x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
ExtraExtensions: extensions,
BasicConstraintsValid: true,
IsCA: false,
Expand Down

0 comments on commit ac77969

Please sign in to comment.