Skip to content

Commit

Permalink
fix(Certificate): Cap expiry date at issuer's (#230)
Browse files Browse the repository at this point in the history
Not only is this semantically correct, but it helps with certificate rotation as subjects can simply check their own expiry dates without looking at the rest of the chain.

This is the JVM counterpart to relaycorp/relaynet-core-js#430
  • Loading branch information
gnarea authored Mar 17, 2022
1 parent a1d6a09 commit 9e104e0
Show file tree
Hide file tree
Showing 2 changed files with 271 additions and 216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ class Certificate constructor(internal val certificateHolder: X509CertificateHol
pathLenConstraint: Int = 0,
validityStartDate: ZonedDateTime = ZonedDateTime.now()
): Certificate {
if (validityStartDate >= validityEndDate) {
val expiryDate = if (issuerCertificate != null) minOf(
issuerCertificate.expiryDate,
validityEndDate
) else validityEndDate

if (validityStartDate >= expiryDate) {
throw CertificateException("The end date must be later than the start date")
}
if (issuerCertificate != null && !issuerCertificate.isCA) {
Expand All @@ -77,7 +82,7 @@ class Certificate constructor(internal val certificateHolder: X509CertificateHol
issuerDistinguishedName,
generateRandomBigInteger(),
Date.from(validityStartDate.toInstant()),
Date.from(validityEndDate.toInstant()),
Date.from(expiryDate.toInstant()),
subjectDistinguishedName,
subjectPublicKeyInfo
)
Expand Down
Loading

0 comments on commit 9e104e0

Please sign in to comment.