Repository navigation
Fix timestamp verification and -t/-ts option overflow - #532
Merged
Merged
Conversation
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.
This was referenced Nov 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Type
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
verifycould take the verification time from a different attribute than the timestamp it verified. A timestamp replaced by a later one was also leaked.-tor-tsoptions wrote past fixed-size arrays and crashed.New Behavior
-tand-tsURLs 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
cryptographymodule and no timestamping server.Testing
Linux, GCC 16.2.0, OpenSSL 3.6.5, ASan and UBSan: full serial
ctestpasses (397/397). With only the tests applied tomaster, the empty-imprint, 1-byte-imprint and two-attribute tests fail. Each commit builds without warnings. Verification results matchmasteron 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