Skip to content

Conversation

@tarcieri
Copy link
Member

Some DER serializer implementations fail to properly sort elements of a SET OF. This is technically non-canonical, but occurs frequently enough that most DER decoders tolerate it. Unfortunately because of that, we must also follow suit.

This commit builds an ArrayVec or Vec of the incoming decoded set elements, and then unconditionally sorts it retroactively, ensuring all SET OF types internally reflect the proper order, but out-of-order SET OF messages are tolerated when coming off-the-wire.

The sort implementation is merge sort, which should be efficient for already-in-order or mostly-in-order sets.

@tarcieri tarcieri mentioned this pull request Apr 27, 2022
5 tasks
@tarcieri
Copy link
Member Author

@carl-wallace it's now failing due to this test which checks for the old behavior:

https://github.com/RustCrypto/formats/blame/master/x509/tests/name.rs#L129-L133

I think it can be safely removed if we do wish to tolerate out-of-order sets.

@carl-wallace
Copy link
Contributor

Removed (or inverted). Thanks for making that change.

@tarcieri tarcieri force-pushed the der/remove-decode-time-setof-ordering-checks branch from 9b338c4 to 4a9dbce Compare April 27, 2022 18:20
@tarcieri
Copy link
Member Author

Ok, I inverted the check it was performing.

Perhaps I should vendor it into the der crate as it doesn't currently have a test for that.

Some DER serializer implementations fail to properly sort elements of a
`SET OF`. This is technically non-canonical, but occurs frequently
enough that most DER decoders tolerate it. Unfortunately because
of that, we must also follow suit.

This commit builds an `ArrayVec` or `Vec` of the incoming decoded set
elements, and then unconditionally sorts it retroactively, ensuring all
`SET OF` types internally reflect the proper order, but out-of-order
`SET OF` messages are tolerated when coming off-the-wire.

The sort implementation is merge sort, which should be efficient for
already-in-order or mostly-in-order sets.
@tarcieri tarcieri force-pushed the der/remove-decode-time-setof-ordering-checks branch from 4a9dbce to 1275597 Compare April 27, 2022 19:00
@tarcieri tarcieri merged commit fbf4334 into master Apr 27, 2022
@tarcieri tarcieri deleted the der/remove-decode-time-setof-ordering-checks branch April 27, 2022 19:13
@tarcieri tarcieri mentioned this pull request May 8, 2022
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.

3 participants