Skip to content

Fix timestamp verification and -t/-ts option overflow - #532

Merged
mtrojnar merged 4 commits into
masterfrom
timestamp-verify-fixes
Nov 6, 2026
Merged

mtrojnar merged 4 commits into
masterfrom
timestamp-verify-fixes

Conversation

@mtrojnar

@mtrojnar mtrojnar commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Pull Request Type

  • Bug fix

Related Issue

Issue number: N/A. The message imprint fix is taken from #511, whose multiple-timestamp feature is not part of this PR.

Current Behavior

  • With more than one timestamp attribute, verify could take the verification time from a different attribute than the timestamp it verified. A timestamp replaced by a later one was also leaked.
  • An RFC 3161 token with an empty or shortened message imprint was accepted as bound to the signature, and a longer one was read past the computed digest.
  • More than 256 -t or -ts options wrote past fixed-size arrays and crashed.

New Behavior

  • A timestamp's time is used only together with that timestamp.
  • The message imprint must have exactly the digest length; an unknown imprint algorithm or a failed digest computation is rejected.
  • -t and -ts URLs beyond 256 are rejected with an error.

Scope of Changes

The three fixes, plus CTests that create RFC 3161 tokens with the test TSA key on a signature whose certificate is valid only during 2018. A valid 2018 token must verify; a 2030 token, empty and 1-byte imprints, and a second, unverifiable timestamp attribute must not. The generator needs only the cryptography module and no timestamping server.

Testing

  • Existing tests
  • New tests added
  • Manual testing

Linux, GCC 16.2.0, OpenSSL 3.6.5, ASan and UBSan: full serial ctest passes (397/397). With only the tests applied to master, the empty-imprint, 1-byte-imprint and two-attribute tests fail. Each commit builds without warnings. Verification results match master on 21 signatures with other multi-timestamp layouts. Windows, macOS and older OpenSSL are left to CI.

Additional Notes

Which timestamp is verified is unchanged: still the last attribute that decodes. Windows uses the first; aligning with it is a separate change.

License Declaration

  • I hereby agree to license my contribution under the project's license.

time_t_timestamp_get_attributes() keeps the last timestamp attribute
that decodes, but it updated the returned time before deciding whether
to keep the attribute. With more than one timestamp attribute, the time
used for verification could therefore come from a different attribute
than the timestamp that was verified.

Take the time only together with the timestamp it belongs to, and free
a timestamp replaced by a later one instead of leaking it. Also free
the countersignature when cms_get_timestamp() fails before taking
ownership of it.

Which timestamp is verified is unchanged.
verify_timestamp_token() compared the computed digest with the
token's messageImprint using the imprint's own length, so an empty or
shortened imprint was accepted, and a longer one read past the
computed value.

Require the imprint length to equal the digest size before comparing.
Also reject an unknown imprint algorithm explicitly and check the
digest computation, whose failure was previously ignored.

Authenticode timestamps are unaffected: CMS_verify() binds them
through the messageDigest attribute.
Each "-t" and "-ts" option was stored in a fixed array of
MAX_TS_SERVERS (256) entries without a bounds check, so a longer
command line wrote past the arrays in GLOBAL_OPTIONS and crashed.

Reject further URLs once the limit is reached.
The test TSA only produces correct tokens, so neither the message
imprint check nor signatures with more than one timestamp attribute
were covered. Generate RFC 3161 tokens with the test TSA key instead,
on a signature whose certificate is valid only during 2018: a valid
2018 token, which must verify, and tokens that must not: a valid 2030
token, empty and 1-byte message imprints, and the 2030 token followed
by a second, unverifiable timestamp attribute.

The helper builds the DER itself, so it needs only the cryptography
module, and it does not use the timestamping server.
@mtrojnar
mtrojnar merged commit 979ca02 into master Nov 6, 2026
10 checks passed
@mtrojnar
mtrojnar deleted the timestamp-verify-fixes branch November 6, 2026 18:06
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.

1 participant