Skip to content

Parse OCSP GeneralizedTime in UTC and reject invalid dates - #470

Closed
SougataXdev wants to merge 1 commit into
apple:mainfrom
SougataXdev:fix/ocsp-x509-date-utc
Closed

SougataXdev wants to merge 1 commit into
apple:mainfrom
SougataXdev:fix/ocsp-x509-date-utc

Conversation

@SougataXdev

Copy link
Copy Markdown

Fixes #447.

parseX509Date only matched 14 digits with no suffix, so GeneralizedTime values ending in Z fell through to new Date unchanged and parsed as Invalid Date. NaN timestamps made both sides of the freshness check in checkOCSPStatus false, so stale or future-dated good responses were accepted. Values without Z were also parsed in the local timezone instead of UTC.

This change parses the supported format explicitly with Date.UTC, verifies the calendar components round-trip (Date.UTC normalizes overflow), and throws FAILURE on malformed input so it can never pass the gate as NaN. nextUpdate is optional per RFC 6960, so when absent only the thisUpdate half of the check applies.

Tests:

  • new OCSP date parsing suite in tests/unit-tests/jws_verification.test.ts (UTC with/without Z, malformed and out-of-range rejection)
  • full suite: 22 suites, 358 tests passed

parseX509Date ignored the trailing Z in GeneralizedTime values, so dates parsed as NaN and the freshness check in checkOCSPStatus never rejected stale responses. It also used the local timezone for values without Z. Parse explicitly with Date.UTC, validate the components round-trip, and throw on malformed input. nextUpdate is optional per RFC 6960, so skip only the expiry half of the check when absent.
@alexanderjordanbaker

Copy link
Copy Markdown
Collaborator

Resolved via #473

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.

SignedDataVerifier accepts stale OCSP status information because GeneralizedTime dates parse as NaN

2 participants