-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add lint to cover TLS BR v2 EKU checks #833
Merged
christopher-henderson
merged 11 commits into
zmap:master
from
vanbroup:e_sub_cert_eku_check
Apr 28, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5f32586
Add EV policy and Pre Certiicate Signing Certificate EKU
vanbroup 816b156
Apply serverAuth to certificates with CA/B TLS policy OID
vanbroup a1f6f24
lint subscriber EKU according to TLS BR v2
vanbroup 237965d
Make lint ineffective since TLS BR v2
vanbroup e83c664
Correct expected result
vanbroup 15db930
Correct numbers as result of CA/B policy inclusion in additon to serv…
vanbroup 4e27fe5
Check if subscriber certificate with EKU extension
vanbroup 8d4f254
Pass certificate in subscriber certificate check
vanbroup 7d05f9f
Remove unnecessary len check
vanbroup 8bcd48c
Format
vanbroup 20a483c
Merge branch 'master' into e_sub_cert_eku_check
christopher-henderson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package cabf_br | ||
|
||
/* | ||
* ZLint Copyright 2024 Regents of the University of Michigan | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/zmap/zcrypto/x509" | ||
"github.com/zmap/zlint/v3/lint" | ||
"github.com/zmap/zlint/v3/util" | ||
) | ||
|
||
type subExtKeyUsageCheck struct{} | ||
|
||
func init() { | ||
lint.RegisterCertificateLint(&lint.CertificateLint{ | ||
LintMetadata: lint.LintMetadata{ | ||
Name: "e_sub_cert_eku_check", | ||
Description: "Subscriber certificates MUST have id-kp-serverAuth and MAY have id-kp-clientAuth present in extKeyUsage", | ||
Citation: "BRs: 7.1.2.7.10 Subscriber Certificate Extended Key Usage", | ||
Source: lint.CABFBaselineRequirements, | ||
EffectiveDate: util.CABFBRs_2_0_0_Date, | ||
}, | ||
Lint: NewSubExtKeyUsageCheck, | ||
}) | ||
} | ||
|
||
func NewSubExtKeyUsageCheck() lint.LintInterface { | ||
return &subExtKeyUsageCheck{} | ||
} | ||
|
||
func (l *subExtKeyUsageCheck) CheckApplies(c *x509.Certificate) bool { | ||
return util.IsSubscriberCert(c) && util.IsExtInCert(c, util.EkuSynOid) | ||
} | ||
|
||
func (l *subExtKeyUsageCheck) Execute(c *x509.Certificate) *lint.LintResult { | ||
var hasClientAuthEKU, hasServerAuthEKU bool | ||
|
||
for _, eku := range c.ExtKeyUsage { | ||
switch eku { | ||
case x509.ExtKeyUsageServerAuth: | ||
hasServerAuthEKU = true | ||
|
||
case x509.ExtKeyUsageClientAuth: | ||
hasClientAuthEKU = true | ||
|
||
case x509.ExtKeyUsageAny, x509.ExtKeyUsageCodeSigning, x509.ExtKeyUsageTimeStamping, | ||
x509.ExtKeyUsageOcspSigning, x509.ExtKeyUsageEmailProtection: | ||
|
||
return &lint.LintResult{Status: lint.Error, Details: fmt.Sprintf("%s MUST NOT be present", util.GetEKUString(eku))} | ||
} | ||
} | ||
|
||
if !hasServerAuthEKU { | ||
return &lint.LintResult{Status: lint.Error, Details: "id-kp-serverAuth MUST be present"} | ||
} | ||
|
||
for _, eku := range c.UnknownExtKeyUsage { | ||
if eku.Equal(util.PreCertificateSigningCertificateEKU) { | ||
return &lint.LintResult{Status: lint.Error, Details: "Precertificate Signing Certificate extKeyUsage MUST NOT be present"} | ||
} | ||
} | ||
|
||
if (len(c.ExtKeyUsage) > 2 && !hasClientAuthEKU) || len(c.UnknownExtKeyUsage) > 0 { | ||
return &lint.LintResult{Status: lint.Warn, Details: "any other value than id-kp-serverAuth and id-kp-clientAuth is NOT RECOMMENDED"} | ||
} | ||
|
||
return &lint.LintResult{Status: lint.Pass} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package cabf_br | ||
|
||
/* | ||
* ZLint Copyright 2024 Regents of the University of Michigan | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/zmap/zlint/v3/lint" | ||
"github.com/zmap/zlint/v3/test" | ||
) | ||
|
||
func TestSubExtKeyUsageCheck(t *testing.T) { | ||
testCases := []struct { | ||
Name string | ||
InputFilename string | ||
ExpectedResult lint.LintStatus | ||
}{ | ||
{ | ||
Name: "pass - serverAuth EKU", | ||
InputFilename: "subExtKeyUsageServerAuth.pem", | ||
ExpectedResult: lint.Pass, | ||
}, | ||
{ | ||
Name: "pass - serverAuth and clientAuth EKU", | ||
InputFilename: "subExtKeyUSageServerAndClientAuth.pem", | ||
ExpectedResult: lint.Pass, | ||
}, | ||
{ | ||
Name: "error - only clientAuth EKU with CA/B TLS BR policy OID", | ||
InputFilename: "subExtKeyUsageClientAuth.pem", | ||
ExpectedResult: lint.Error, | ||
}, | ||
{ | ||
Name: "ne - only clientAuth EKU, with CA/B TLS BR policy OID, NotBefore before effective date", | ||
InputFilename: "subExtKeyUsageClientAuthPreBRv2.pem", | ||
ExpectedResult: lint.NE, | ||
}, | ||
{ | ||
Name: "error - serverAuth and timeStamping EKU", | ||
InputFilename: "subExtKeyUsageServerAuthAndTimeStamping.pem", | ||
ExpectedResult: lint.Error, | ||
}, | ||
{ | ||
Name: "error - serverAuth and unknown PreCertSigCert EKU", | ||
InputFilename: "subExtKeyUsageServerAuthAndPreCertSigCert.pem", | ||
ExpectedResult: lint.Error, | ||
}, | ||
{ | ||
Name: "warn - serverAuth and MicrosoftDocumentSigning EKU", | ||
InputFilename: "subExtKeyUsageServerAuthAndUnknown.pem", | ||
ExpectedResult: lint.Warn, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
result := test.TestLint("e_sub_cert_eku_check", tc.InputFilename) | ||
if result.Status != tc.ExpectedResult { | ||
t.Errorf("expected result %v was %v - details: %v", tc.ExpectedResult, result.Status, result.Details) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Certificate: | ||
Data: | ||
Version: 3 (0x2) | ||
Serial Number: 3 (0x3) | ||
Signature Algorithm: ecdsa-with-SHA256 | ||
Issuer: | ||
Validity | ||
Not Before: Sep 15 12:00:00 2023 GMT | ||
Not After : Sep 15 12:00:00 2024 GMT | ||
Subject: | ||
Subject Public Key Info: | ||
Public Key Algorithm: id-ecPublicKey | ||
Public-Key: (256 bit) | ||
pub: | ||
04:f1:d5:c1:b1:f9:0f:63:d7:c2:ba:83:a3:c6:b7: | ||
fb:cf:07:bb:c7:33:03:61:4d:13:0f:45:46:8d:47: | ||
7f:41:ce:8f:9f:1f:85:37:ee:ff:30:00:37:3c:53: | ||
8b:60:aa:38:48:a8:5c:ca:c7:0c:78:12:f4:2e:ca: | ||
62:d8:f7:6c:b5 | ||
ASN1 OID: prime256v1 | ||
NIST CURVE: P-256 | ||
X509v3 extensions: | ||
X509v3 Extended Key Usage: | ||
TLS Web Server Authentication, TLS Web Client Authentication | ||
Signature Algorithm: ecdsa-with-SHA256 | ||
Signature Value: | ||
30:45:02:20:79:05:6d:37:0a:db:85:a5:6f:54:68:1d:37:50: | ||
33:ce:4a:97:d6:59:77:d3:98:1b:df:89:43:f9:02:d8:e2:91: | ||
02:21:00:83:cd:55:a0:54:f1:88:be:71:23:96:7b:4c:38:6a: | ||
d6:14:2c:dc:e0:75:e8:51:c3:bd:bc:09:74:63:5e:3d:7b | ||
-----BEGIN CERTIFICATE----- | ||
MIIBDzCBtqADAgECAgEDMAoGCCqGSM49BAMCMAAwHhcNMjMwOTE1MTIwMDAwWhcN | ||
MjQwOTE1MTIwMDAwWjAAMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE8dXBsfkP | ||
Y9fCuoOjxrf7zwe7xzMDYU0TD0VGjUd/Qc6Pnx+FN+7/MAA3PFOLYKo4SKhcyscM | ||
eBL0Lspi2PdstaMhMB8wHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMAoG | ||
CCqGSM49BAMCA0gAMEUCIHkFbTcK24Wlb1RoHTdQM85Kl9ZZd9OYG9+JQ/kC2OKR | ||
AiEAg81VoFTxiL5xI5Z7TDhq1hQs3OB16FHDvbwJdGNePXs= | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Certificate: | ||
Data: | ||
Version: 3 (0x2) | ||
Serial Number: 3 (0x3) | ||
Signature Algorithm: ecdsa-with-SHA256 | ||
Issuer: | ||
Validity | ||
Not Before: Sep 15 12:00:00 2023 GMT | ||
Not After : Sep 15 12:00:00 2024 GMT | ||
Subject: | ||
Subject Public Key Info: | ||
Public Key Algorithm: id-ecPublicKey | ||
Public-Key: (256 bit) | ||
pub: | ||
04:04:3b:ca:38:58:01:84:3c:49:f1:45:a8:b6:02: | ||
18:00:dc:f3:3d:78:2b:d0:ff:3d:16:62:07:4d:2e: | ||
63:e0:92:0b:45:fc:f8:90:90:ce:bf:b6:db:ba:60: | ||
e5:d2:fb:b0:f7:d1:39:18:7a:40:a9:7d:e3:22:ac: | ||
ef:e9:f6:70:4c | ||
ASN1 OID: prime256v1 | ||
NIST CURVE: P-256 | ||
X509v3 extensions: | ||
X509v3 Extended Key Usage: | ||
TLS Web Client Authentication | ||
X509v3 Certificate Policies: | ||
Policy: 2.23.140.1.2.1 | ||
Signature Algorithm: ecdsa-with-SHA256 | ||
Signature Value: | ||
30:44:02:20:25:79:7b:74:45:0d:29:f9:24:f0:81:4d:03:e4: | ||
e0:b6:01:19:31:ee:dc:81:e6:bb:2a:88:91:ae:cd:d5:8e:5a: | ||
02:20:03:2f:9a:da:62:e6:d4:8f:96:99:f4:ea:22:0d:23:e0: | ||
a4:9b:eb:42:08:9f:47:ff:50:ba:e7:f1:e7:9f:15:39 | ||
-----BEGIN CERTIFICATE----- | ||
MIIBGTCBwaADAgECAgEDMAoGCCqGSM49BAMCMAAwHhcNMjMwOTE1MTIwMDAwWhcN | ||
MjQwOTE1MTIwMDAwWjAAMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEBDvKOFgB | ||
hDxJ8UWotgIYANzzPXgr0P89FmIHTS5j4JILRfz4kJDOv7bbumDl0vuw99E5GHpA | ||
qX3jIqzv6fZwTKMsMCowEwYDVR0lBAwwCgYIKwYBBQUHAwIwEwYDVR0gBAwwCjAI | ||
BgZngQwBAgEwCgYIKoZIzj0EAwIDRwAwRAIgJXl7dEUNKfkk8IFNA+TgtgEZMe7c | ||
gea7KoiRrs3VjloCIAMvmtpi5tSPlpn06iINI+Ckm+tCCJ9H/1C65/HnnxU5 | ||
-----END CERTIFICATE----- |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could set a variable in the
default
case in therange c.ExtKeyUsage
loop and check that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may advocate for keeping a list of of OIDs found during the execution of the lint and cross referencing them at them end against the list of known OIDs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ExtKeyUsage and UnknownExtKeyUsage are not of the same type:
The lint currently checks for MUST, MUST NOT, MAY, and NOT RECOMMENDED, and returns the corresponding lint status and error.
We can create a map with each EKU and the requirement (i.e., MUST) and lookup the value while ranging over the two EKU lists, but I guess this would be less efficient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reckon that this would be an efficiency modifier in the range of nanoseconds (possibly into ms) for each run of the lint. In general, legibility trumps such optimizations since correctness of the lint is paramount.