-
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
refactor of SMIME aia contains #777
Merged
christopher-henderson
merged 28 commits into
zmap:master
from
mtgag:smime_aia_contains_refactor
Dec 12, 2023
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
6c23670
lint about the encoding of qcstatements for PSD2
4666bb7
Revert "lint about the encoding of qcstatements for PSD2"
01996c6
Merge https://github.com/zmap/zlint
28481cc
Merge https://github.com/zmap/zlint
749d896
Merge https://github.com/zmap/zlint
e56e2a0
util: gtld_map autopull updates for 2021-10-21T07:25:20 UTC
web-flow 8600050
Merge pull request #1 from mtgag/zlint-gtld-update
mtgag 30b096e
Merge https://github.com/zmap/zlint
mtgag 92e659c
always check and perform the operation in the execution
mtgag 351a379
Merge branch 'master' into master
christopher-henderson b52111b
Merge https://github.com/zmap/zlint
mtgag 526f9be
Merge https://github.com/zmap/zlint
mtgag 92902fc
Merge https://github.com/zmap/zlint
mtgag 1652cfa
synchronised with project
mtgag d4f2f9f
synchronised with project
mtgag 88c933e
Merge https://github.com/zmap/zlint
mtgag cee805f
Merge https://github.com/zmap/zlint
mtgag 87ee071
changed date, added check for existent extension
mtgag f1dea7f
updates in config after tests
mtgag 530737b
removed accidentally commited file
mtgag a1eee50
removed internal names part, kept only has http only
mtgag 2a6b887
changes addressing discussion in PR. Internal names are checked, IP a…
mtgag 313bed4
the check for HTTP scheme is not needed here. This is covered by the …
mtgag cb0e939
Merge branch 'zmap:master' into smime_aia_contains_refactor
mtgag 8a5d97c
fixed test
mtgag 447c0a0
Merge branch 'smime_aia_contains_refactor' of https://github.com/mtga…
mtgag 29eaf04
renamed file
mtgag a5711df
one lint for internal names in AIA covers all S/MIME generations, leg…
mtgag 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
91 changes: 91 additions & 0 deletions
91
v3/lints/cabf_smime_br/lint_aia_contains_internal_names.go
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,91 @@ | ||
package cabf_smime_br | ||
|
||
/* | ||
* ZLint Copyright 2023 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 ( | ||
"net" | ||
"net/url" | ||
"time" | ||
|
||
"github.com/zmap/zcrypto/x509" | ||
"github.com/zmap/zlint/v3/lint" | ||
"github.com/zmap/zlint/v3/util" | ||
) | ||
|
||
type smimeAIAContainsInternalNames struct{} | ||
|
||
/************************************************************************ | ||
BRs: 7.1.2.3c | ||
CA Certificate Authority Information Access | ||
The authorityInformationAccess extension MAY contain one or more accessMethod | ||
values for each of the following types: | ||
|
||
id-ad-ocsp specifies the URI of the Issuing CA's OCSP responder. | ||
id-ad-caIssuers specifies the URI of the Issuing CA's Certificate. | ||
|
||
*************************************************************************/ | ||
|
||
func init() { | ||
lint.RegisterCertificateLint(&lint.CertificateLint{ | ||
LintMetadata: lint.LintMetadata{ | ||
Name: "w_smime_aia_contains_internal_names", | ||
Description: "SMIME certificates authorityInformationAccess. Internal domain names should not be included.", | ||
Citation: "BRs: 7.1.2.3c", | ||
Source: lint.CABFSMIMEBaselineRequirements, | ||
EffectiveDate: util.CABF_SMIME_BRs_1_0_0_Date, | ||
}, | ||
Lint: NewSMIMEAIAInternalName, | ||
}) | ||
} | ||
|
||
func NewSMIMEAIAInternalName() lint.LintInterface { | ||
return &smimeAIAContainsInternalNames{} | ||
} | ||
|
||
func (l *smimeAIAContainsInternalNames) CheckApplies(c *x509.Certificate) bool { | ||
return util.IsExtInCert(c, util.AiaOID) && util.IsSubscriberCert(c) && util.IsSMIMEBRCertificate(c) | ||
} | ||
|
||
func (l *smimeAIAContainsInternalNames) Execute(c *x509.Certificate) *lint.LintResult { | ||
for _, u := range c.OCSPServer { | ||
purl, err := url.Parse(u) | ||
if err != nil { | ||
return &lint.LintResult{Status: lint.Error} | ||
} | ||
|
||
if net.ParseIP(purl.Host) != nil { | ||
continue | ||
} | ||
|
||
if !util.HasValidTLD(purl.Hostname(), time.Now()) { | ||
return &lint.LintResult{Status: lint.Warn} | ||
} | ||
} | ||
for _, u := range c.IssuingCertificateURL { | ||
purl, err := url.Parse(u) | ||
if err != nil { | ||
return &lint.LintResult{Status: lint.Error} | ||
} | ||
|
||
if net.ParseIP(purl.Host) != nil { | ||
continue | ||
} | ||
|
||
if !util.HasValidTLD(purl.Hostname(), time.Now()) { | ||
return &lint.LintResult{Status: lint.Warn} | ||
} | ||
} | ||
return &lint.LintResult{Status: lint.Pass} | ||
} |
50 changes: 50 additions & 0 deletions
50
v3/lints/cabf_smime_br/lint_aia_contains_internal_names_test.go
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,50 @@ | ||
package cabf_smime_br | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/zmap/zlint/v3/lint" | ||
"github.com/zmap/zlint/v3/test" | ||
) | ||
|
||
func TestSMIMEStrictAIAInternalName(t *testing.T) { | ||
testCases := []struct { | ||
Name string | ||
InputFilename string | ||
ExpectedResult lint.LintStatus | ||
}{ | ||
{ | ||
Name: "pass - aia with valid names", | ||
InputFilename: "smime/aiaWithValidNamesStrict.pem", | ||
ExpectedResult: lint.Pass, | ||
}, | ||
{ | ||
Name: "warn - aia with internal names in AIA OCSP ", | ||
InputFilename: "smime/aiaWithInternalNamesStrict.pem", | ||
ExpectedResult: lint.Warn, | ||
}, | ||
{ | ||
Name: "warn - aia with internal names in AIA CA issuers ", | ||
InputFilename: "smime/aiaWithInternalNamesCaIssuersStrict.pem", | ||
ExpectedResult: lint.Warn, | ||
}, | ||
{ | ||
Name: "warn - aia with valid names, one is ldap", | ||
InputFilename: "smime/aiaWithLDAPOCSPStrict.pem", | ||
ExpectedResult: lint.Pass, | ||
}, | ||
{ | ||
Name: "pass - aia with IP address in host part of the URL", | ||
InputFilename: "smime/aiaWithIPAddress.pem", | ||
ExpectedResult: lint.Pass, | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
result := test.TestLint("w_smime_aia_contains_internal_names", 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
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
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.
Good catch on the change from
w
toe
. It really should have been marked as an error class in the first place.