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

verify_cert: bound name constraint comparisons. #160

Closed
wants to merge 2 commits into from

Conversation

cpu
Copy link
Member

@cpu cpu commented Aug 31, 2023

Enforcing name constraints during path building is quadratic with the number of names, and the number of name constraints. To avoid the possibility of excessive CPU consumption enforcing name constraints TLS libraries typically enforce a maximum number of comparisons while evaluating a constrained certificate against subsequent certificate names. Note that unlike #152 the possible runtime of crafted certificate chains within the limits imposed by Rustls/webpki prior to this commit is O(seconds) and not O(hours+), making this a less grave concern generally.

In this commit we adopt the same limit as the default limit used by Go's x509 package, bounding comparisons for a single constrained certificate to 250,000 comparisons.

This is done per-constrained certificate and not for the overall path-building operation, but the number of constrained certificates that can be included in a path is constrained elsewhere (e.g. by Rustls imposing a 64KB limit to the entire chain). Other users of this library should consider similar countermeasures.

cpu added 2 commits August 31, 2023 11:34
Enforcing name constraints during path building is quadratic with the
number of names, and the number of name constraints. To avoid the
possibility of excessive CPU consumption enforcing name constraints
TLS libraries typically enforce a maximum number of comparisons while
evaluating a constrained certificate against subsequent certificate
names.

In this commit we adopt the same limit as the default limit used by Go's
`x509` package[0], bounding comparisons for a single constrained
certificate to 250,000 comparisons.

This is done per-constrained certificate and not overall path-building
operation, but the number of constrained certificates that can be
included in a path is constrained elsewhere (e.g. by Rustls imposing
a 64KB limit to the entire chain). Other users of this library should
consider similar countermeasures.

[0]: https://github.com/golang/go/blob/9aaf5234bf652fc788782fc04a06044879b5957a/src/crypto/x509/verify.go#L588-L591
@cpu cpu self-assigned this Aug 31, 2023
@codecov
Copy link

codecov bot commented Aug 31, 2023

Codecov Report

Merging #160 (03f7ca9) into main (02b8423) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #160   +/-   ##
=======================================
  Coverage   96.54%   96.55%           
=======================================
  Files          15       15           
  Lines        4376     4388   +12     
=======================================
+ Hits         4225     4237   +12     
  Misses        151      151           
Files Changed Coverage Δ
src/error.rs 55.10% <100.00%> (ø)
src/subject_name/verify.rs 96.35% <100.00%> (+0.15%) ⬆️
src/verify_cert.rs 97.31% <100.00%> (+<0.01%) ⬆️

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

@cpu
Copy link
Member Author

cpu commented Aug 31, 2023

This is done per-constrained certificate and not for the overall path-building operation, but the number of constrained certificates that can be included in a path is constrained elsewhere (e.g. by Rustls imposing a 64KB limit to the entire chain). Other users of this library should consider similar countermeasures.

Imposing this limit within webpki seems reasonable, but perhaps better as a follow-up separate from this item of work.

@cpu cpu marked this pull request as draft August 31, 2023 16:20
@cpu
Copy link
Member Author

cpu commented Sep 5, 2023

Reworking this locally. Will reopen with a better implementation shortly.

@cpu cpu closed this Sep 5, 2023
@cpu
Copy link
Member Author

cpu commented Sep 5, 2023

Reworked as #165

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.

1 participant