Skip to content

Conversation

@algogrit
Copy link

@algogrit algogrit commented Oct 30, 2025

Added a test case to illustrate and fix the issue.

=== Demonstrating Attribute Order Bug ===
Total signed attributes: 3

Actual order of attributes:
 Position 0: content-type (OID: 1.2.840.113549.1.9.3)
 Position 1: signing-time (OID: 1.2.840.113549.1.9.5)
 Position 2: message-digest (OID: 1.2.840.113549.1.9.4)

=== RFC 5652 Requirements ===
According to RFC 5652 Section 5.3:
- Signed attributes MUST be DER encoded
- DER encoding requires SET OF to be sorted by tag (OID)
- OID comparison is lexicographic on encoded bytes

Expected order by OID:
 1. content-type     (1.2.840.113549.1.9.3)
 2. message-digest   (1.2.840.113549.1.9.4)
 3. signing-time     (1.2.840.113549.1.9.5)

=== Bug Detected ===
❌ message-digest is at position 2
❌ signing-time is at position 1
❌ This violates DER encoding rules!

The attributes should be sorted by OID, but currently:
 signing-time (OID .9.5) comes BEFORE message-digest (OID .9.4)

BUG CONFIRMED: Attributes are not in DER order!
message-digest should be at position 1 but is at position 2
signing-time should be at position 2 but is at position 1

Copy link
Owner

@indygreg indygreg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deletion of the sort_by line seems fundamentally wrong.

Did you use an AI/LLM tool to generate this PR? The PR summary and added test feel like LLM output to me.

})
.collect::<Result<Vec<(_, _)>, std::io::Error>>()?;

attributes.sort_by(|(a, _), (b, _)| a.cmp(b));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the sort removed? The sort was added by #614 to fix the prior sorting behavior being buggy.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous PR didn't come with tests and didn't prove the fix it claimed to have provided.

}

#[test]
fn signed_attributes_order() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is very verbose. I think it can be minimized.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is something concrete here, I would be happy to remove. This test was initially generated using LLM, then adjusted to reflect the intention of clearly explaining the issue.

@algogrit
Copy link
Author

It's not vibe coded if that's what you are getting at. The test has been generated via LLM, but figuring out the cause for the attributes to become unordered has been an human effort.

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.

2 participants