Skip to content

Fix regression in key usage purpose encoding#369

Merged
djc merged 2 commits into
mainfrom
key-usage-bits
Jul 20, 2025
Merged

Fix regression in key usage purpose encoding#369
djc merged 2 commits into
mainfrom
key-usage-bits

Conversation

@djc

@djc djc commented Jul 18, 2025

Copy link
Copy Markdown
Member

Key usage purpose encoding regressed in #287.

I don't (yet) really know what I'm doing here, just implementing @ctz's suggestion from the issue to keep this moving.

Anyone want to suggest some tests that would prevent this from regressing again? There are some tests in https://github.com/rustls/rcgen/pull/287/files#diff-1340717e703c8244b2ad18d09955bd825f1565daee83f900a26a5c956b57c125R380 but we should have something that catches this.

Fixes #368.

@djc djc requested review from cpu, ctz and est31 July 18, 2025 07:23

@ctz ctz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For a test, how about this?

diff --git a/rcgen/src/certificate.rs b/rcgen/src/certificate.rs
index 8f625b8..9438018 100644
--- a/rcgen/src/certificate.rs
+++ b/rcgen/src/certificate.rs
@@ -1146,6 +1150,10 @@ mod tests {

                for ext in cert.extensions() {
                        if key_usage_oid_str == ext.oid.to_id_string() {
+                               // should have the minimal number of octets, and no extra trailing zero bytes
+                               // ref. https://github.com/rustls/rcgen/issues/368
+                               assert_eq!(ext.value, vec![0x03, 0x02, 0x05, 0xe0]);
+
                                if let x509_parser::extensions::ParsedExtension::KeyUsage(usage) =
                                        ext.parsed_extension()

Comment thread rcgen/src/certificate.rs Outdated
@djc djc force-pushed the key-usage-bits branch from 38be30a to 41d9e5e Compare July 18, 2025 08:33
@djc

djc commented Jul 18, 2025

Copy link
Copy Markdown
Member Author

Thanks! I made you the commit author. 👍

@djc djc added this pull request to the merge queue Jul 20, 2025
Merged via the queue into main with commit 620e219 Jul 20, 2025
16 checks passed
@djc djc deleted the key-usage-bits branch July 20, 2025 18:41
@djc

djc commented Jul 21, 2025

Copy link
Copy Markdown
Member Author
  • Published rcgen v0.14.3 at registry crates-io
  • [new tag] v0.14.3 -> v0.14.3
  • Release notes

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.

Extra byte in Key Usage value

4 participants