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

🐛 implement ordered components of ASN.1 sets #1025

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dhensby
Copy link
Contributor

@dhensby dhensby commented Mar 28, 2023

Fixes #1013

This implements sorting of ASN.1 types.

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 checks if the current ASN.1 object is a SET - if so it will order the encoded values. It also allows the option of sort to be set to force sorting, this is required when items need to be encoded as SET but have context specific tag class.

The ordering is done by comparing each byte in turn until we find either a difference or can determine they are the same.

Because of the change in how internals are now constructing the ASN.1 values, the PKCS#7 test output has had to change.

For completeness I have tested openssl is still able to validate the produced PKCS#7 signatures:

$ openssl smime -verify -attime 1332945777 -in ./signedDataWithAttrs1949GeneralizedTime-new.pem -signer certificate.pem -out signedtext.txt -inform PEM -CAfile certificate.pem
Verification successful
$ openssl smime -verify -attime 1332945777 -in ./signedDataWithAttrs1950UTCTime-new.pem -signer certificate.pem -out signedtext.txt -inform PEM -CAfile certificate.pem 
Verification successful
$ openssl smime -verify -attime 1332945777 -in ./signedDataWithAttrs2049UTCTime-new.pem -signer certificate.pem -out signedtext.txt -inform PEM -CAfile certificate.pem 
Verification successful
$openssl smime -verify -attime 1332945777 -in ./signedDataWithAttrs2050GeneralizedTime-new.pem -signer certificate.pem -out signedtext.txt -inform PEM -CAfile certificate.pem 
Verification successful
$ openssl smime -verify -attime 1332945777 -in ./detachedSignature-new.pem -signer certificate.pem -out signedtext.txt -inform PEM -CAfile certificate.pem -content content.txt
Verification successful

@dhensby
Copy link
Contributor Author

dhensby commented Apr 13, 2023

@davidlehn - any chance you could take a look at this, please?

@dhensby
Copy link
Contributor Author

dhensby commented Aug 29, 2023

@davidlehn - sorry for another ping on this, but it would be really great to get this in

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.

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