Commit Graph

58 Commits

Author SHA1 Message Date
Brian Smith 8f81719df5 Appease Clippy. 2024-02-18 13:14:42 -08: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 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
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 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 d16bafbba4 NFC: Address Clippy `needless_borrow` complaints. 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
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 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 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 ead26ed429 Style: use `impl Trait` instead of explicitly-named type parameters. 2021-02-18 10:54:16 -08:00
Brian Smith 0486ea10f6 `cargo fmt`. 2020-12-29 13:09:55 -08:00
Brian Smith 13c904afac Clippy: Temporarily suppress `clippy::identity_op` in OID constants. 2020-12-07 17:57:08 -08:00
Brian Smith fd438cbe5e Clippy: Take Clippy's advice regarding `clippy::match-ref-pats`. 2020-12-07 17:57:08 -08:00
Brian Smith d2c995a842 Retain the entire `SubjectPublicKeyInfo` structure when parsing.
Retain the tag and value of the `subjectPublicKeyInfo` field so that
the entire `SEQUENCE` can be accessed in future code.
2020-03-22 14:33:12 -05:00
Brian Smith 0d2699a389 Remove use of `untrusted` from the public API. 2019-07-15 21:25:11 -10:00
Brian Smith f1264202da Update for latest `untrusted` prerelease. 2019-04-05 10:30:30 -10:00
Brian Smith 8c73c9c9f1 `cargo +nightly fmt.` 2019-03-28 15:26:38 -10:00
Brian Smith 0d8a27161a Switch to Rust 2018 Edition. 2019-03-28 15:26:38 -10:00
Brian Smith 1e96f33624 Eliminate unnecessary (named) lifetime annotations. 2019-03-28 15:19:47 -10:00
Brian Smith 003f503124 Update dependencies to in-development versions. 2019-03-28 15:19:47 -10:00
Brian Smith faa7f2b88b Revert "`cargo +nightly fmt`."
This reverts commit 7379d6062b. We'll merge
some outstanding PRs before doing the reformat.
2019-01-29 17:06:47 -10:00
Brian Smith 7379d6062b `cargo +nightly fmt`. 2019-01-29 17:03:53 -10:00
Brian Smith 76da76ef5b Remove obsolete id-Netscape-stepUp EKU matching workaround.
This workaround isn't needed for compatibility any more. See
https://bugs.chromium.org/p/chromium/issues/detail?id=733403#c3.

See also https://bugzilla.mozilla.org/show_bug.cgi?id=982932. That
was done two years ago so they can probably remove the workaround
completely now as well.
2018-04-25 16:50:13 -10:00
Lalit Maganti 22a645db61 Add support for verifying client certificates. 2017-09-02 09:44:54 -10:00
Brian Smith 5a739cd967 Replace `try!(...)` with `...?`. 2017-08-25 09:00:43 -10:00
Brian Smith edbbb81329 Drop dependency on the time crate; use `std::time::SystemTime`. 2017-08-18 10:40:25 -10:00
Alex Gaynor 748c8e24b3 Fix typo in comment: s/remember_extensions/remember_extension/. 2017-08-18 09:30:58 -10:00
Brian Smith 272de41132 Use `use` more consistently.
Follow the way it is done in *ring* (mostly).
2016-08-12 23:08:27 -10:00
Brian Smith 011adae3af Rename {expect,read}_tag_and_get_input -> {expect,read}_tag_and_get_value.
Be consistent with the *ring* names.
2016-08-12 21:52:59 -10:00
Brian Smith f7cfa50cd3 Create a new public API. 2016-08-12 16:11:52 -10:00
Brian Smith 6f3d48ef4f Add **Important** notes about the two-step validation process. 2016-08-11 16:39:59 -10:00
Brian Smith 859f3905e3 Add documentation for `verify_tls_cert`. 2016-08-11 16:39:58 -10:00
Brian Smith 30c8ed1a8c Remove the unneeded concept of fatal errors.
`InvalidTrustAnchor` wasn't even used. `ImpossibleState` was replaced
with a panic.
2016-08-11 15:40:06 -10:00
Brian Smith de83e4810a Enable unused_results lint. 2016-08-11 15:33:20 -10:00
Brian Smith 868a07b88d Use `Option::map` instead of a manual match. 2016-07-09 08:51:44 -10:00
Brian Smith e680cc18ab Update to new untrusted::Input API. 2016-06-30 17:59:21 -10:00
Brian Smith 3497ab6ea6 Use `ring::der::small_nonnegative_integer`.
`webpki::der::integer` was moved to *ring* and renamed.
2016-06-17 18:07:37 -10:00
Brian Smith 2f3c98c178 Updates for untrusted.rs API changes. 2016-06-05 13:26:46 -10:00
Brian Smith 0a2d7891d4 use new |ring::signature| API for verifying signatures. 2015-12-10 18:25:16 -10:00
Brian Smith 46d1725a95 Use |ring::input| and |ring::der|.
|webpki::input| was copied to |ring::input|. The core of |webpki::der|
was copied to |ring::der|. This change removes the duplicate code from
libwebpki and adapts the rest of libwebpki accordingly.
2015-12-10 17:48:32 -10:00