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

ASN.1 Set Of invalid DER encoding for PKCS#7 authenticatedAttributes #1013

Open
dhensby opened this issue Jan 26, 2023 · 2 comments · May be fixed by #1025
Open

ASN.1 Set Of invalid DER encoding for PKCS#7 authenticatedAttributes #1013

dhensby opened this issue Jan 26, 2023 · 2 comments · May be fixed by #1025

Comments

@dhensby
Copy link
Contributor

dhensby commented Jan 26, 2023

According to the X.690 specification (ISO/IEC 8825-1:2021 (E)) the ASN.1 standard for Set Of components must be encoded in order when using DER:

11 Restrictions on BER employed by both CER and DER
...
11.6 Set of components
The encodings of the component values of a set-of value shall appear in ascending order, the encodings being compared as octet strings with the shorter components being padded at their trailing end with 0-octets.
NOTE – The padding octets are for comparison purposes only and do not appear in the encodings.

This has been determined to cause bouncy castle to reject the PKCS#7 signatures that this library produces.

I'll take a look into ordering the Set Of components, presumably this is best done in the toDer method on the asn1 package? Otherwise the sorting could be done when the ASN.1 is constructed.

@T-Ricks
Copy link

T-Ricks commented Feb 2, 2023

I noticed that same thing too: not ordering the attribute list to sign causes the library to produce invalid signatures.
The bug is easily reproducible by including the signingTime attribute along with the messageDigest and contentType attributes: the signingTime is put by the library at the end of the attribute list , while it should appear before the messageDigest (because in this case the ordering criteria ends up being the length of the DER Encoding of the attribute).

@dhensby dhensby linked a pull request Mar 28, 2023 that will close this issue
@dhensby
Copy link
Contributor Author

dhensby commented Mar 28, 2023

@T-Ricks just FYI - I have now opened a PR that fixes the issue

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 a pull request may close this issue.

2 participants