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

Pin notAfter dates for certificates to max out at signing CA notAfter date #378

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,24 @@ private X509Certificate getSignedByIssuer(

final BigInteger certificateSerialNumber = serialNumberGenerator.generate();

Date nvb = Date.from(now);
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest more descriptive names like notBefore and notAfter.

Data nva = Date.from(now.plus(Duration.ofDays(params.getDuration())));
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't compile - should be "Date". Please run "gradlew test" after fixing.

if (issuerCertificate != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add unit test coverage for this new logic? I'm assuming we didn't already have good assertions for it, even though the tests hit this code.

// don't allow a child certificate to be valid before the signing certificate
if (nvb.isBefore(issuerCertificate.getNotBefore())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There isn't an isBefore method on Date, but you can use before.

nvb = issuerCertificate.getNotBefore();
}
// don't allow a child certificate to be valid after the signing certificate
if (nva.isAfter(issuerCertificate.getNotAfter())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

isAfter should be `after'.

nva = issuerCertificate.getNotAfter();
}
}

final JcaX509v3CertificateBuilder certificateBuilder = new JcaX509v3CertificateBuilder(
issuerDn,
certificateSerialNumber,
Date.from(now),
Date.from(now.plus(Duration.ofDays(params.getDuration()))),
nvb,
nva,
params.getX500Principal(),
keyPair.getPublic()
);
Expand Down