@@ -543,11 +543,16 @@ func (c *Certificate) checkNameConstraints(count *int,
543
543
return nil
544
544
}
545
545
546
+ const (
547
+ checkingAgainstIssuerCert = iota
548
+ checkingAgainstLeafCert
549
+ )
550
+
546
551
// ekuPermittedBy returns true iff the given extended key usage is permitted by
547
552
// the given EKU from a certificate. Normally, this would be a simple
548
553
// comparison plus a special case for the “any” EKU. But, in order to support
549
554
// existing certificates, some exceptions are made.
550
- func ekuPermittedBy (eku , certEKU ExtKeyUsage ) bool {
555
+ func ekuPermittedBy (eku , certEKU ExtKeyUsage , context int ) bool {
551
556
if certEKU == ExtKeyUsageAny || eku == certEKU {
552
557
return true
553
558
}
@@ -564,18 +569,23 @@ func ekuPermittedBy(eku, certEKU ExtKeyUsage) bool {
564
569
eku = mapServerAuthEKUs (eku )
565
570
certEKU = mapServerAuthEKUs (certEKU )
566
571
567
- if eku == certEKU ||
568
- // ServerAuth in a CA permits ClientAuth in the leaf.
569
- (eku == ExtKeyUsageClientAuth && certEKU == ExtKeyUsageServerAuth ) ||
572
+ if eku == certEKU {
573
+ return true
574
+ }
575
+
576
+ // If checking a requested EKU against the list in a leaf certificate there
577
+ // are fewer exceptions.
578
+ if context == checkingAgainstLeafCert {
579
+ return false
580
+ }
581
+
582
+ // ServerAuth in a CA permits ClientAuth in the leaf.
583
+ return (eku == ExtKeyUsageClientAuth && certEKU == ExtKeyUsageServerAuth ) ||
570
584
// Any CA may issue an OCSP responder certificate.
571
585
eku == ExtKeyUsageOCSPSigning ||
572
586
// Code-signing CAs can use Microsoft's commercial and
573
587
// kernel-mode EKUs.
574
- ((eku == ExtKeyUsageMicrosoftCommercialCodeSigning || eku == ExtKeyUsageMicrosoftKernelCodeSigning ) && certEKU == ExtKeyUsageCodeSigning ) {
575
- return true
576
- }
577
-
578
- return false
588
+ (eku == ExtKeyUsageMicrosoftCommercialCodeSigning || eku == ExtKeyUsageMicrosoftKernelCodeSigning ) && certEKU == ExtKeyUsageCodeSigning
579
589
}
580
590
581
591
// isValid performs validity checks on c given that it is a candidate to append
@@ -716,7 +726,7 @@ func (c *Certificate) isValid(certType int, currentChain []*Certificate, opts *V
716
726
717
727
for _ , caEKU := range c .ExtKeyUsage {
718
728
comparisonCount ++
719
- if ekuPermittedBy (eku , caEKU ) {
729
+ if ekuPermittedBy (eku , caEKU , checkingAgainstIssuerCert ) {
720
730
continue NextEKU
721
731
}
722
732
}
@@ -850,7 +860,7 @@ func (c *Certificate) Verify(opts VerifyOptions) (chains [][]*Certificate, err e
850
860
NextUsage:
851
861
for _ , eku := range requestedKeyUsages {
852
862
for _ , leafEKU := range c .ExtKeyUsage {
853
- if ekuPermittedBy (eku , leafEKU ) {
863
+ if ekuPermittedBy (eku , leafEKU , checkingAgainstLeafCert ) {
854
864
continue NextUsage
855
865
}
856
866
}
0 commit comments