Skip to content

Commit 02ed95d

Browse files
committed
doc: recommend in-window X509Certificate validity check
Per review, tell callers to test that the current time is inside the validity window, which rejects an invalid bound, instead of testing whether it is outside the window, which an invalid bound passes. Signed-off-by: Sarthak Ahuja <39986642+SarthakAhuja@users.noreply.github.com>
1 parent 0baec30 commit 02ed95d

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

‎doc/api/crypto.md‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3534,8 +3534,12 @@ The date/time from which this certificate is valid, encapsulated in a `Date` obj
35343534

35353535
If the certificate's `notBefore` time cannot be parsed, this is an invalid
35363536
`Date` (its `getTime()` method returns `NaN`). Every relational comparison
3537-
with an invalid `Date` evaluates to `false`, so callers should reject an
3538-
invalid `Date` before comparing it with other dates.
3537+
with an invalid `Date` evaluates to `false`. To check whether a certificate
3538+
is currently valid, test that the current time is inside the validity window
3539+
(`now >= x509.validFromDate && now <= x509.validToDate`), which rejects an
3540+
invalid bound. Do not test whether it is outside the window
3541+
(`now < x509.validFromDate || now > x509.validToDate`): with an invalid
3542+
bound, that test is `false` and the certificate appears valid.
35393543

35403544
### `x509.validTo`
35413545

@@ -3564,8 +3568,12 @@ The date/time until which this certificate is valid, encapsulated in a `Date` ob
35643568

35653569
If the certificate's `notAfter` time cannot be parsed, this is an invalid
35663570
`Date` (its `getTime()` method returns `NaN`). Every relational comparison
3567-
with an invalid `Date` evaluates to `false`, so callers should reject an
3568-
invalid `Date` before comparing it with other dates.
3571+
with an invalid `Date` evaluates to `false`. To check whether a certificate
3572+
is currently valid, test that the current time is inside the validity window
3573+
(`now >= x509.validFromDate && now <= x509.validToDate`), which rejects an
3574+
invalid bound. Do not test whether it is outside the window
3575+
(`now < x509.validFromDate || now > x509.validToDate`): with an invalid
3576+
bound, that test is `false` and the certificate appears valid.
35693577

35703578
### `x509.signature`
35713579

0 commit comments

Comments
 (0)