Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DER-encoded CMS SignedData object using CMSSignedDataStreamGenerator #1482

Closed
SkyCrawl opened this issue Aug 30, 2023 · 2 comments
Closed

DER-encoded CMS SignedData object using CMSSignedDataStreamGenerator #1482

SkyCrawl opened this issue Aug 30, 2023 · 2 comments

Comments

@SkyCrawl
Copy link

Hello,

in ETSI TS 102 778-3 v1.2.1, and later also ETSI EN 319 142-1 v1.1.1, there is the following requirement:

A DER-encoded SignedData object as specified in CMS (RFC 3852 [4]) shall be included as the PDF signature in the entry with the key Contents of the Signature Dictionary as described in ISO 32000-1 [1], clause 12.8.1.

A DER-encoded SignedData object can be generated with BouncyCastle, but only using the CMSSignedDataGenerator class, not CMSSignedDataStreamGenerator. I was wondering why and whether it would be possible to bring support for DER-encoded SignedData objects to CMSSignedDataStreamGenerator as well.

@peterdettman
Copy link
Collaborator

DER encoding includes definite lengths at the start of encodings, which means that it needs to know the exact length of the output before it starts producing any. The purpose of the CMS stream generators is to produce output directly (i.e. without keeping in memory a full copy of the data), which is fundamentally incompatible with DER in the general case.

@dghgit dghgit closed this as completed Sep 10, 2023
@bsanchezb
Copy link

Hello @peterdettman,

I would like to ask if it is feasible to extend CMSSignedDataStreamGenerator functionality to create DER-encoded CMS, provided that the size of the encapsulated content info is provided in advance?

This limitation on creating only BER-encoded signatures with CMSSignedDataStreamGenerator creates problems on augmentation of CAdES signatures containing archiveTimestampV2, which message-imprint computation is dependent on the data encoding within the signature (see #1983 for more information).

Currently, if we try to extend a DER-encoded signature with a CMSSignedDataStreamGenerator, the produced signature is generated using a BER-encoding, which breaks the available archiveTimestampV2.

Provided that the size of the original ContentInfo and other properties is known in advance, would it be possible to generate all the required DER tags on the fly using CMSSignedDataStreamGenerator or an alternative implementation, so the provided signature result is DER encoded or encoded in the same way as the original signature provided to the augmentation service?

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

No branches or pull requests

4 participants