Skip to content

Fix: ocsp - validate response timestamps in wolfSSL_OCSP_check_validity - #11297

Open
jackctj117 wants to merge 4 commits into
wolfSSL:masterfrom
jackctj117:10718
Open

jackctj117 wants to merge 4 commits into
wolfSSL:masterfrom
jackctj117:10718

Conversation

@jackctj117

Copy link
Copy Markdown
Contributor

This pull request implements comprehensive validation for OCSP response timestamps in the wolfSSL_OCSP_check_validity function and adds a thorough suite of tests to ensure correct behavior, especially regarding clock skew, staleness, and absent fields. The changes also integrate the new test into the test suite.

OCSP response timestamp validation improvements:

  • src/ocsp.c: Rewrote wolfSSL_OCSP_check_validity to properly validate the thisUpdate and nextUpdate timestamps, enforcing clock skew (sec), maximum staleness (maxsec), and handling absent or malformed times as failures, except for absent nextUpdate which is now correctly accepted when represented as a zero-length structure.

Expanded OCSP validation testing:

  • tests/api/test_ocsp.c: Added a comprehensive test function test_ocsp_check_validity covering all relevant edge cases, including future, stale, missing, and malformed thisUpdate, expired or inconsistent nextUpdate, and correct handling of absent nextUpdate as a zero-length structure. Also tests integration with the OCSP status getter.
  • tests/api/test_ocsp.h: Declared the new test function for use in the test suite.
  • tests/api.c: Registered the new test case in the OCSP test group, ensuring it runs as part of the standard test suite.

Copilot AI lite review requested due to automatic review settings August 26, 2026 23:25
@wolfSSL-Bot

Copy link
Copy Markdown

Can one of the admins verify this patch?

@jackctj117 jackctj117 changed the title 10718 Fix: ocsp - validate response timestamps in wolfSSL_OCSP_check_validity Aug 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens OpenSSL-compat OCSP response validation by making wolfSSL_OCSP_check_validity actually enforce thisUpdate/nextUpdate timestamp rules (clock skew and staleness), and adds API tests to guard the behavior.

Changes:

  • Reworked wolfSSL_OCSP_check_validity in src/ocsp.c to validate thisUpdate presence/format and enforce skew/staleness, while treating a zero-length nextUpdate as “absent”.
  • Added a focused test suite for wolfSSL_OCSP_check_validity edge cases and integrated it into the API test runner.
  • Exposed the new test via tests/api/test_ocsp.h and registered it in tests/api.c.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/ocsp.c Implements timestamp validation logic for OCSP responses (thisUpdate/nextUpdate).
tests/api/test_ocsp.c Adds coverage for validity checks across future/stale/missing/malformed timestamp scenarios.
tests/api/test_ocsp.h Declares the new OCSP validity test entry point.
tests/api.c Registers the new OCSP validity test in the OCSP test group.
Suppressed comments (1)

src/ocsp.c:819

  • The nextUpdate expiration check is also strict (nextUpdate must be after now - sec). With the current wolfSSL_X509_cmp_time semantics (-1 for <=), this rejects a nextUpdate exactly at the edge of the allowed clock skew (nextUpdate == now - sec). Allow the boundary case by comparing against now - sec - 1.
        cmp = now - sec;
        if (wolfSSL_X509_cmp_time(nextupd, &cmp) != 1) {

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/ocsp.c Resolved
Comment thread src/ocsp.c Resolved
Comment thread src/ocsp.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #11297

Scan targets checked: wolfcrypt-rs-bugs, wolfssl-bugs, wolfssl-src

Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Comment thread src/ocsp.c Resolved
Comment thread src/ocsp.c Resolved
@philljj

philljj commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Retest this please.

tlslite.errors.TLSAbruptCloseError: TLSAbruptCloseError

@julek-wolfssl julek-wolfssl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The changes look correct but the comments are getting out of hand. Please bring them down to a necessary minimum and don't state the obvious.

Comment thread src/ocsp.c Resolved
julek-wolfssl
julek-wolfssl previously approved these changes Nov 6, 2026
@julek-wolfssl julek-wolfssl removed their assignment Nov 6, 2026

@philljj philljj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's rebase this to be safe

Only check nextUpdate once thisUpdate has passed, drop the redundant
thisUpdOk flag and cut the comments down to what is not obvious from
the code. Restore test_ocsp_forged_responder_cert_rejected, which the
previous commit dropped by mistake.

Since dacd8ee the compat getters return NULL for an absent nextUpdate,
so treat only NULL as absent and require any non-NULL nextUpdate to be
valid, as OpenSSL does.
DecodeSingleResponse set thisDateLen and nextDateLen inside the first
"if (ret == 0)" block and read them in the WOLFSSL_OCSP_PARSE_STATUS
blocks further down. MSVC cannot follow that flow and reports C4701
(potentially uninitialized) now that OPENSSL_EXTRA builds enable
WOLFSSL_OCSP_PARSE_STATUS, which made the Windows Jenkins job UNSTABLE.
Initialize both at declaration instead.
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.

6 participants