Commit Graph

242 Commits

Author SHA1 Message Date
Brian Smith 8f81719df5 Appease Clippy. 2024-02-18 13:14:42 -08:00
Brian Smith f1202b34b3 Restore SemVer compatibility for `verify_is_valid_tls_client_cert`. 2023-10-08 18:27:19 -07:00
Brian Smith bfde8f3b3f Move DoS tests from unit tests to integration tests.
This is an intermediate step towards moving them into a separate crate.

Leave the `tests` submodule for now, to make the comparison with the
old (identical) code easier. The next commit will remove it and
re-indent the code.
2023-10-08 10:31:11 -07:00
Brian Smith 87dd910480 Add `verify_is_valid_tls_server_cert_ext`.
Add a public API that allows the caller to distinguish the new DoS
errors.
2023-10-08 10:31:11 -07:00
Brian Smith 16a2638bd0 Upgrade to *ring* 0.17 and untrusted 0.9.
untrusted 0.9 is used by *ring*. untrusted stopped providing a `PartialEq`
for `Input` in 0.9; this was the driver for all the code changes.
2023-10-02 14:24:17 -07:00
Brian Smith 91992763fb NFC: Correct name of mozilla::pkix in comment. 2023-09-30 11:31:21 -07:00
Brian Smith d96f70b49d NFC: DRY in budget. 2023-09-30 11:31:21 -07:00
Brian Smith 2ad08d7bc2 NFC: Clarify `is_fatal()`. 2023-09-30 11:31:21 -07:00
Brian Smith 7793842de1 NFC: Encapsulate `Budget` internals.
Make it clear that nothing is reaching into the internals of `Budget`.
In particular, clarify that the tests are not messing around with the
defaults.
2023-09-30 11:31:21 -07:00
Tim Düsterhus 911e11c67f Reland Fix typo in Rustdoc for verify_signature().
[`git cherry-pick b481381e914de604df30b1be2fe72d938a5c0e57`.]
2023-09-29 21:50:11 -07:00
Daniel McCarney 519bcb6c23 verify_cert: check name constraints after sig. validation
Prior to this commit parsing and processing certificate name constraints
was done before validating a chain of signatures to a known trust
anchor. This increases the attack surface of these features, allowing an
adversary to force webpki to process name constraints on a crafted
certificate without needing to have that certificate issued by a trusted
entity.

This commit moves the parsing and processing of name constraints to
after building and verifying the chain of signatures to reduce the
potential for mischief.
2023-09-29 20:21:44 -07:00
Daniel McCarney 4d0cbba617 signed_data: fix code block missing close marker 2023-09-29 20:21:44 -07:00
Daniel McCarney f566cf1b3b verify_cert: apply path building budget
This is intended to be complementary to the signature validation limit
fix and addresses briansmith/webpki#276 in the same manner as NSS
libmozpkix.
2023-09-29 19:06:31 -07:00
Joseph Birr-Pixton 3ee04be687 Add comment indicating source of signature budget 2023-09-29 19:06:31 -07:00
Joseph Birr-Pixton 636037e9da Track signature limit using `Budget` type 2023-09-29 19:06:31 -07:00
Brian Smith 4a71d475e6 NFC: Address Clippy `explicit_auto_deref`. 2023-08-30 17:04:56 -07:00
Brian Smith 177c39eee5 NFC: Address Clippy `clone_on_copy`. 2023-08-30 17:04:56 -07:00
Brian Smith ae7a99f281 NFC: Address Clippy `useless_asref`. 2023-08-30 17:04:56 -07:00
Brian Smith 6d409c9039 NFC: Address Clippy `redundant_closure`. 2023-08-30 17:04:56 -07:00
Brian Smith d16bafbba4 NFC: Address Clippy `needless_borrow` complaints. 2023-08-30 17:04:56 -07:00
Brian Smith ad1fe9288e Documentation: Stop hard-coding briansmith.org paths.
Let people find the docs on docs.rs.
2023-08-30 17:04:56 -07:00
Daniel McCarney 30a108e080 verify_cert: enforce maximum number of signatures.
Cherry-picked from e473ee1ecb335d8efa3d4ceb2feb369f46b125f2 and modified
by Brian Smith. The main modifications were:

1. Maintain API compatibility with webpki 0.22.0.
2. (In `build_chain_inner`), stop immediately on fatal error, without
   considering any more paths. The point of having such fatal errors
   is to fail ASAP and avoid unneeded work in the failure case.
3. The test uses rcgen which requires Rust 1.67.0 or later. (I don't
   think the non-test MSRV of webpki changes though.)

The original commit message is below:

Pathbuilding complexity can be quadratic, particularly when the set of
intermediates all have subjects matching a trust anchor. In these cases
we need to bound the number of expensive signature validation operations
that are performed to avoid a DoS on CPU usage.

This commit implements a simple maximum signature check limit inspired
by the approach taken in the Golang x509 package. No more than 100
signatures will be evaluated while pathbuilding. This limit works in
practice for Go when processing real world certificate chains and so
should be appropriate for our use case as well.
2023-08-30 14:08:00 -07:00
Daniel McCarney 522cecd950 Cherry pick f0259b9588bab116c7dfbc62524b98794c90aaef: verify: break out build_chain recursion.
[`git cherry-pick f0259b9588bab116c7dfbc62524b98794c90aaef`, merged by Brian Smith.]

Crate-internal consumers of `build_chain` always pass `0` as the sub CA
count, only the `verify_cert.rs` internal recursion changes this
parameter.

This commit separates the external interface from the internal
recursion to remove one extra parameter from an already complicated
interface.
2023-08-30 14:08:00 -07:00
Brian Smith 0cd0b31beb Revert main branch crate contents to the 0.22.0 release contents.
Reset the crate contents (sources, tests, etc.)
to what they were at that commit, while retaining the newer CI
configuration.

The changes since the 0.22.0 release were primarily intended to
accomplish two goals:

* Fix and improve the GitHub Actions configuration.
* Prepare a 0.21.5 release that was backward compatible with 0.21.4
  but which also contained the improvements that were in 0.22.0.

0.21.5 was never released and will not be released. Therefore all
of the noise to facilitate the 0.21.5 release can just be deleted,
as long as we leave the CI changes that are necessary for GitHub
Actions to work correctly now.

The exact commands I used were:

```
git checkout \
    6c334a2cf5 \
    -- \
    Cargo.toml \
    LICENSE \
    README.md \
    src \
    tests \
    third-party
git rm src/trust_anchor_util.rs
```

Commit 6c334a2cf5 was the commit from
which 0.22.0 was released. It is confusing because the commit
immediately prior, 0b7cbf2d32, has
commit message "0.22.0". It appears that I merged the "0.22.0"
commit, expecting to `cargo publish` from that commit, but then
`cargo publish` failed. Then I added
6c334a2cf5 to fix `cargo publish`
and did the `cargo publish` from that commit. That's why I added
the `package` CI step at that time, to prevent this confusing
situation from happening again.

`trust_anchor_utils.rs` was not in 0.22.0; the `git checkout` didn't
delete it, so I had to do it separately.

I left the tests added subsequent to 0.22.0 in `tests/` (e.g.
`name_tests.rs`) since those tests pass with the 0.22.0 sources too.

Unfortunately, this requires disabling a bunch of Clippy lints, to
avoid modifying the contents from 0.22.0.

(I know it is confusing. It took me a while to figure it out myself
today.)
2023-08-30 08:31:51 -07:00
Tim Düsterhus b481381e91 Fix typo in Rustdoc for verify_signature() 2021-12-13 22:06:46 -08:00
Brian Smith 97507d40ab Appease the newest stable Clippy. 2021-12-13 21:44:26 -08:00
Brian Smith 17d9189981 Temporarily undo some renaming that can't be alised, to get back webpki 0.21.4 compat.
Make it easier to maintain support for Rustls 0.19.1 by restoring the webpki main branch to a
state compatible with webpki 0.21.4.
2021-05-07 15:12:11 -07:00
Brian Smith de7fb02d2e Restore `Time::try_from`. 2021-05-07 15:12:11 -07:00
Brian Smith 5d5c71095c Add more backward-compatibility aliases. 2021-05-07 15:12:11 -07:00
Brian Smith 2baa7f8ebc Remove `EndEntityCert::verify_is_valid_for_at_least_one_dns_name`.
This doesn't really do the thing we hoped it would do, and it's dead weight.
2021-04-22 13:19:33 -07:00
Brian Smith 81bd1e3fbf Add missing docs and check for missing docs during build. 2021-04-20 18:32:56 -07:00
Brian Smith 279933295a Move clippy configuration out of `lib.rs` and into clippy.sh.
Reduce sensitivity to the set of clippy lints over time.
2021-04-20 18:18:12 -07:00
Brian Smith 2208a22acd Use `impl Trait` instead of an unnecessarily-named parameter. 2021-04-10 22:05:07 -07:00
Brian Smith cd59614740 Rename internal names to conform to Rust conventions. 2021-04-09 15:58:41 -07:00
Brian Smith 5b67fb92da Rename error variants according to Rust conventions. 2021-04-09 15:58:41 -07:00
Brian Smith 2cb889b7c5 Rename `TrustAnchor::from_cert_der` to `TrustAnchor::try_from_cert_der`. 2021-04-09 15:58:41 -07:00
Brian Smith bc6893f6ef Use Rust naming conventions for abbreviations. 2021-04-09 15:58:41 -07:00
Brian Smith 5fd730eb18 Disable some clippy pedantic lints. 2021-02-18 15:58:12 -08:00
Brian Smith 092393e2ef Time: Use `Self` more. 2021-02-18 13:56:23 -08:00
Brian Smith 4942c65d97 Tweak `AllowWildcards` to pass `clippy::needless-pass-by-value`. 2021-02-18 13:50:37 -08:00
Brian Smith 628b8d6d6f Remove `der::Value::tlv`.
This was added as a prerequisite for a feature that hasn't landed yet, but it
is currently unused. Further, it is using deprecated features of `untrusted`.
Remove it. We'll add it back if/when we need it, probably with a different
implementation.
2021-02-18 13:30:21 -08:00
Brian Smith 1d5f4bd649 Avoid using `as` to convert `u8` to `usize`.
Enable the clippy lint for this.
2021-02-18 12:30:28 -08:00
Brian Smith 0789a90d94 Avoid using `as` for conversions from `Tag` to `u8`.
*ring* added a safer way to do this conversion a while back.
2021-02-18 12:30:28 -08:00
Brian Smith ead26ed429 Style: use `impl Trait` instead of explicitly-named type parameters. 2021-02-18 10:54:16 -08:00
Stiopa Koltsov ba54ede055 Error::UnsupportedCertWithoutExtensions
Better error than `BadDER` when certificate is generated incorrectly.

I agree to license my contributions to each file under the terms given at the top of each file I changed.
2021-02-17 14:39:43 -08:00
Stiopa Koltsov 1364e7a902 Error::UnsupportedCertVersion instead of BadDER on certificate v1
I agree to license my contributions to each file under the terms given at the top of each file I changed.
2021-02-17 14:37:35 -08:00
Brian Smith 07306a64a3 Remove `nested_mut`.
`nested_mut` does what `nested` does. It was written when the author was
confused about how the closure traits work.
2021-02-17 00:53:17 -08:00
Stiopa Koltsov db1f0d1d64 Fix clippy warnings
I agree to license my contributions to each file under the terms given at the top of each file I changed.
2021-02-17 00:24:12 -08:00
Brian Smith 082a74427e Remove `trust_anchor_util::generate_code_for_trust_anchors`.
This was intended to be used by things like webpki-roots, but
webpki-roots is not using it and the implementation was not good, and
not tested.
2021-02-04 13:37:55 -08:00
Brian Smith e8d040cefa Rename `TrustAnchor::from_x509_der` to `from_cert_der`. 2021-02-04 13:09:28 -08:00