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

Expose built path in public API #174

Merged
merged 13 commits into from Oct 5, 2023
Merged

Expose built path in public API #174

merged 13 commits into from Oct 5, 2023

Conversation

djc
Copy link
Member

@djc djc commented Sep 10, 2023

Builds on top of #173. This shows that it is possible to expose the built path without doing substantial extra work (130 extra lines, but with fairly okay abstractions IMO).

Instead of storing the intermediate certificates in stack frames, this pre-allocates an array of fixed size MAX_CA_SUB_COUNT (on the stack) and stores the parsed certificates in there. The PathNode from #173 is then redefined to iterate over the PartialPath type containing this array, and path building functions are changed to yield the TrustAnchor.

@djc djc requested review from cpu and ctz September 10, 2023 09:44
@codecov
Copy link

codecov bot commented Sep 10, 2023

Codecov Report

Merging #174 (5dfe82e) into main (a3a4b94) will increase coverage by 0.08%.
The diff coverage is 98.85%.

@@            Coverage Diff             @@
##             main     #174      +/-   ##
==========================================
+ Coverage   96.44%   96.53%   +0.08%     
==========================================
  Files          20       20              
  Lines        4478     4617     +139     
==========================================
+ Hits         4319     4457     +138     
- Misses        159      160       +1     
Files Coverage Δ
src/cert.rs 97.60% <100.00%> (+0.02%) ⬆️
src/crl/mod.rs 97.42% <100.00%> (-0.08%) ⬇️
src/crl/types.rs 99.53% <100.00%> (+<0.01%) ⬆️
src/end_entity.rs 100.00% <100.00%> (ø)
src/lib.rs 100.00% <ø> (ø)
src/verify_cert.rs 97.31% <98.61%> (+0.58%) ⬆️

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

src/verify_cert.rs Show resolved Hide resolved
@ctz
Copy link
Member

ctz commented Sep 10, 2023

It's common for there to be several possible valid paths (eg if a CA is both cross-signed and also directly trusted, like Let's Encrypt in past years). So this API would be OK for consumers that want to (eg) display or log one of the valid paths, but not for those who want to apply further constraints to it (HPKP, DANE, etc.) if those constraints allow one possible chain but not others. Further constraints really have to be applied during path building so the search could continue to consider other paths.

@djc
Copy link
Member Author

djc commented Sep 10, 2023

It's common for there to be several possible valid paths (eg if a CA is both cross-signed and also directly trusted, like Let's Encrypt in past years). So this API would be OK for consumers that want to (eg) display or log one of the valid paths, but not for those who want to apply further constraints to it (HPKP, DANE, etc.) if those constraints allow one possible chain but not others. Further constraints really have to be applied during path building so the search could continue to consider other paths.

Fair point! This PR (and the previous) were mostly focused on first creating a representation of the Path in away that can be presented in a public API. I've now added an extension point that allows callers to fail a particular complete path. Do you think that would be a good fit for the HPKP/DANE/etc use case? At least what I've seen from DANE it seems like it would allow callers to take care of that use case (though we may have to extend the public API of our Cert type some more).

(Would appreciate any suggestions on how to test verify_path().)

Copy link
Member

@cpu cpu left a comment

Choose a reason for hiding this comment

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

Very cool!

In terms of testing, I think my comment about exposing more public API surface will be helpful. After that, perhaps generate some certificate paths where one contains an additional EKU that you verify for in the callback, rejecting the candidates that do not have the required EKU throughout?

src/verify_cert.rs Outdated Show resolved Hide resolved
src/verify_cert.rs Outdated Show resolved Hide resolved
src/crl/mod.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/verify_cert.rs Outdated Show resolved Hide resolved
src/verify_cert.rs Outdated Show resolved Hide resolved
src/verify_cert.rs Outdated Show resolved Hide resolved
src/verify_cert.rs Outdated Show resolved Hide resolved
src/verify_cert.rs Outdated Show resolved Hide resolved
src/verify_cert.rs Outdated Show resolved Hide resolved
src/verify_cert.rs Outdated Show resolved Hide resolved
tests/integration.rs Outdated Show resolved Hide resolved
@djc djc force-pushed the path-node branch 2 times, most recently from bc5a487 to 8c68276 Compare September 11, 2023 20:47
Base automatically changed from path-node to main September 11, 2023 20:57
@cpu
Copy link
Member

cpu commented Sep 14, 2023

Should this be a blocker for #159 ? I'm not sure what timeline we're thinking for #159, if we want to cut the tag Soon this might be better for a follow-up. WDYT?

@djc
Copy link
Member Author

djc commented Sep 14, 2023

I think so? I think there's no point in cutting a 0.102 release until rustls is ready for 0.22, so I suspect there's some time.

@cpu cpu mentioned this pull request Sep 14, 2023
13 tasks
@cpu
Copy link
Member

cpu commented Sep 14, 2023

👍 Added to the list.

src/verify_cert.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
@djc djc force-pushed the path-array branch 5 times, most recently from ff13776 to 6307b14 Compare September 21, 2023 13:59
Copy link
Member

@cpu cpu left a comment

Choose a reason for hiding this comment

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

This is great 👍

src/end_entity.rs Outdated Show resolved Hide resolved
src/verify_cert.rs Outdated Show resolved Hide resolved
src/verify_cert.rs Show resolved Hide resolved
src/verify_cert.rs Show resolved Hide resolved
src/verify_cert.rs Show resolved Hide resolved
src/verify_cert.rs Show resolved Hide resolved
@djc djc force-pushed the path-array branch 2 times, most recently from de9386c to c7d165a Compare September 21, 2023 15:09
src/verify_cert.rs Outdated Show resolved Hide resolved
I find this useful while developing (especially for more explorative
development). We deny warnings in CI, so warnings still shouldn't
make it to the main branch.
@djc djc force-pushed the path-array branch 2 times, most recently from 4bfbcd2 to 58b4de2 Compare October 5, 2023 12:56
@djc
Copy link
Member Author

djc commented Oct 5, 2023

@ctz did you want to take another look at this?

Copy link
Member

@ctz ctz left a comment

Choose a reason for hiding this comment

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

lgtm!

/// Path from end-entity certificate to trust anchor that's been verified.
///
/// See [`EndEntityCert::verify_for_usage()`] for more details on what verification entails.
pub struct VerifiedPath<'p> {
Copy link
Member

Choose a reason for hiding this comment

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

do we want any derives on this? (i guess not, based on EndEntityCert and Cert not having any?)

Copy link
Member Author

Choose a reason for hiding this comment

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

We should maybe reconsider that, but given that EndEntityCert and Cert don't have any it seems mostly orthogonal to this PR.

@djc djc added this pull request to the merge queue Oct 5, 2023
Merged via the queue into main with commit cbbf352 Oct 5, 2023
56 checks passed
@djc djc deleted the path-array branch October 5, 2023 14:35
@djc
Copy link
Member Author

djc commented Oct 5, 2023

Published alpha.5.

@cpu
Copy link
Member

cpu commented Oct 5, 2023

@djc Did the test from #191 get dropped in a rebase?

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.

None yet

3 participants