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

lib: use ext helper in more places, test custom exts. #154

Merged
merged 4 commits into from
Sep 11, 2023

Conversation

cpu
Copy link
Member

@cpu cpu commented Sep 10, 2023

This branch updates a couple places that were writing x509 extensions by hand to use the existing write_x509_extension helper instead.

Since custom extensions are a bit trickier a unit test for custom extensions in CSRs and certificates is added before refactoring the existing code to use the helper. This helps ensure the change is a no-op from the perspective of users.

With the updated test, it was possible to demonstrate a bug similar to #122. The CSR serialization logic requiring SANs to be present in order to emit the custom extensions into the CSR PKCS9 extension request attribute. This branch fixes the issue.

Previously there was no test coverage for custom extensions in
certificates or CSRs. This commit adds a simple example of encoding
a custom extension, and then demonstrating that it can be parsed with
`x509-parser`, both in a serialized certificate and in a CSR.

There's no support in webpki, openssl-rs or botan-rs for handling custom
extensions so no test coverage for those libraries is possible at this
time.
@cpu cpu self-assigned this Sep 10, 2023
@codecov
Copy link

codecov bot commented Sep 10, 2023

Codecov Report

Merging #154 (646e8fc) into main (163b8d4) will increase coverage by 1.62%.
Report is 1 commits behind head on main.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #154      +/-   ##
==========================================
+ Coverage   70.28%   71.90%   +1.62%     
==========================================
  Files           7        7              
  Lines        1898     1876      -22     
==========================================
+ Hits         1334     1349      +15     
+ Misses        564      527      -37     
Files Changed Coverage Δ
src/lib.rs 75.53% <100.00%> (+2.53%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Previously when writing CSR DER from `CertificateParams` that specified
custom extensions, but did not specify any SANs, the serialization code
would skip over writing the PKCS9 extension request attribute.

This commit updates the serialization logic to ensure the attribute is
written when either SANs are provided, or custom extensions are present.

Prior to this update, the modified `test_x509_custom_ext` test fails,
reproducing the problem reported in the issue tracker:

```
'test_x509_custom_ext::custom_ext' panicked at 'missing requested extensions'
```

With the update, it passes again.
Copy link
Member

@est31 est31 left a comment

Choose a reason for hiding this comment

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

I only gave this a cursory glance due to limited time but the general idea of the PR is good, thanks. Maybe it would be good to get another review?

@cpu
Copy link
Member Author

cpu commented Sep 10, 2023

Maybe it would be good to get another review?

Sounds good. @djc when you have some time I'd appreciate a review pass.

FWIW I'm also working on a subsequent refactoring of extension handling to fix #122 - I'll open that as a follow-up shortly.

@cpu cpu mentioned this pull request Sep 10, 2023
10 tasks
@cpu
Copy link
Member Author

cpu commented Sep 10, 2023

FWIW I'm also working on a subsequent refactoring of extension handling to fix #122 - I'll open that as a follow-up shortly.

General idea is in cpu#1 I haven't done a self-review pass yet and I'd like to add more tests.

src/lib.rs Show resolved Hide resolved
@djc
Copy link
Member

djc commented Sep 11, 2023

Nice!

@cpu cpu merged commit 6cdcd7b into rustls:main Sep 11, 2023
11 checks passed
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