Sitelet https://github.com/RustCrypto/formats/pull/2465
Skip to content

cms: tag TimeStampedData / ERS types implicitly, as RFC 5544 and RFC 4998 define - #2465

Open
yuxi-liu-wired wants to merge 1 commit into
RustCrypto:masterfrom
yuxi-liu-wired:fix/cms-timestamped-data-implicit-tags
Open

yuxi-liu-wired wants to merge 1 commit into
RustCrypto:masterfrom
yuxi-liu-wired:fix/cms-timestamped-data-implicit-tags

Conversation

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor

cms::timestamped_data implements RFC 5544 (TimeStampedData) and the RFC 4998 Evidence Record Syntax types it embeds. Both RFCs' ASN.1 modules are DEFINITIONS IMPLICIT TAGS (RFC 5544 Appendix A; RFC 4998 Appendices A and C), but the context-tagged fields here use the derive's default, EXPLICIT:

  • Evidence ::= CHOICE { tstEvidence [0] …, ersEvidence [1] EvidenceRecord, otherEvidence [2] … }
  • EvidenceRecord: cryptoInfos [0], encryptionInfo [1]
  • ArchiveTimeStamp: digestAlgorithm [0], attributes [1], reducedHashtree [2]

So RFC-encoded data doesn't decode. For an EvidenceRecord encoded by pyasn1 from the RFC 4998 module:

EvidenceRecord::from_der(..)  // Err: unexpected ASN.1 DER tag: expected SEQUENCE, got OBJECT IDENTIFIER

because encryptionInfo [1] is a1 06 06 02 2a03 0500 (the SEQUENCE tag replaced), while the derive expects a1 08 30 06 …. Encoding has the mirror problem, and an ArchiveTimeStamp carrying a digestAlgorithm or reducedHashtree (both present in practice) is affected the same way.

The fix marks the eight fields tag_mode = "IMPLICIT". The CHOICE alternatives are also marked constructed = "true", as revocation.rs already does for RevocationInfoChoice.

Tests: tests/timestamped_data.rs decodes the pyasn1-encoded EvidenceRecord (with encryptionInfo [1], digestAlgorithm [0] and reducedHashtree [2]) and re-encodes it byte for byte, standalone and as Evidence::ErsEvidence. Both fail on master. The cms.yml matrix passed locally: powerset tests on stable and 1.85, thumbv7em powerset build, fmt, clippy.

This PR was produced by AI agents (Claude) and reviewed by me before submission.

…4998 define

Both ASN.1 modules are DEFINITIONS IMPLICIT TAGS, but the context-tagged
fields of Evidence, EvidenceRecord and ArchiveTimeStamp used the derive's
default, EXPLICIT. So cms could not decode an RFC-encoded evidence
record: e.g. EvidenceRecord.encryptionInfo [1] fails with "expected
SEQUENCE, got OBJECT IDENTIFIER", and encoding produced bytes other
implementations don't read.

Mark the eight fields tag_mode = "IMPLICIT" (constructed for the CHOICE
alternatives, as in revocation.rs). New tests decode and re-encode an
EvidenceRecord produced by pyasn1 from the RFC 4998 module, standalone
and as Evidence::ErsEvidence.

This branch has not been deployed

No deployments
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