Skip to content
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

Use help Method beforeoron instead of #717

Merged
merged 15 commits into from
Mar 28, 2024
Merged

Conversation

mtgag
Copy link
Contributor

@mtgag mtgag commented May 17, 2023

Two lints use the before method to the calculate the validity of certificates, while the BeforeOrOn help method should be used. Two certificates that test the edge case are also added.

Copy link
Contributor

@robplee robplee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something isn't quite lining up for me, either the lint descriptions aren't accurate representations of the BRs and EV rules or else this change makes the lints too strict.

@@ -42,7 +42,7 @@ func (l *subCertValidTimeLongerThan39Months) CheckApplies(c *x509.Certificate) b
}

func (l *subCertValidTimeLongerThan39Months) Execute(c *x509.Certificate) *lint.LintResult {
if c.NotBefore.AddDate(0, 39, 0).Before(c.NotAfter) {
if util.BeforeOrOn(c.NotBefore.AddDate(0, 39, 0), c.NotAfter) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually correct to make this change? The Description of the lint says that the lint validity period must be "no greater than 39 months". A certificate that is valid for exactly 39 months doesn't have a validity period greater than 39 months so I think the original code is the correct version here.

@@ -47,7 +47,7 @@ func (l *evValidTooLong) CheckApplies(c *x509.Certificate) bool {
}

func (l *evValidTooLong) Execute(c *x509.Certificate) *lint.LintResult {
if c.NotBefore.AddDate(0, 27, 0).Before(c.NotAfter) {
if util.BeforeOrOn(c.NotBefore.AddDate(0, 27, 0), c.NotAfter) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here. The lint description says the validity period must be "27 months... or less", a 27 month validity would therefore be acceptable and yet this change makes that an error case.

@mtgag
Copy link
Contributor Author

mtgag commented May 19, 2023

The implementation in the pull request and jzlint was motivated by the following discussions/pull requests:

#467
#469

Certificate eeServerCertValidOver398.pem
(https://github.com/zmap/zlint/blob/master/v3/testdata/eeServerCertValidOver398.pem) from the testdata, as the name suggests, is valid over 398 days and the test lint_e_server_cert_valid_time_longer_than_398_days_test.go treats it as an error for the corresponding lint.

Accordingly, a certificate which has a notBefore "Jan 1 00:00:00 2023" and a notAfter "Feb 1 00:00:00 2023" has a validity of two months, which I believe is correct when the granularity of the duration is expressed in months.

@CBonnell
Copy link
Contributor

The definition of Validity Period in the BRs was not aligned with the RFC 5280 definition until SC31. Changing the validity period calculation to align with 5280 for certificates issued prior to the SC31 effective date will yield false positive findings/errors.

Given this, I agree with @robplee that the changes proposed in this PR do not align with the BRs as written.

@mtgag
Copy link
Contributor Author

mtgag commented May 19, 2023

Ok. Then, let us keep the certificates and change the assertion in the test to have an explicit test for this behaviour (or simply close this PR). I will commit this soon.

@zakird
Copy link
Member

zakird commented Feb 25, 2024

@CBonnell, are we in better shape after the latest change from @mtgag?

@CBonnell
Copy link
Contributor

I think it's fine, as there appears to be no actual logic change introduced as part of this PR. It appears to merely add test cases of existing lints.

@zakird zakird merged commit f9496fa into zmap:master Mar 28, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants