Commit Graph

1966 Commits

Author SHA1 Message Date
Brian Smith 477d3b79cd Remove redundant client auth signature algorithm tests.
Bogo tests all the signature algorithms for client auth already, both
in client and server. Bogo tests TLS 1.3 and TLS 1.2 individually, which
is an important improvement over the redundant tests.

Regarding Ed25519 specifically, BoringSSL doesn't enable it by default,
but it does still test it, e.g.:

```
    "Server-Verify-Ed25519-TLS12": {
      "actual": "PASS",
      "expected": "PASS",
      "is_unexpected": false
    },
    "Server-Verify-Ed25519-TLS13": {
       "actual": "PASS",
       "expected": "PASS",
       "is_unexpected": false
    },
```
2022-01-27 21:36:15 +01:00
Brian Smith 116e31157c Add tests for `Debug` implementations of assertions. 2022-01-27 20:05:32 +00:00
Brian Smith d71648e3b6 AllowAnyAuthenticatedClient: Remove redundant function.
The implementation of `client_auth_mandatory()` is redundant with the
default implementation. By removing this redundant implementation, we
add test coverage of the default implementation, which is currently
uncovered.
2022-01-27 20:04:39 +00:00
Brian Smith 3916e445de Add integration test for `AllowAnyAnonymousOrAuthenticatedClient`. 2022-01-27 20:02:28 +00:00
Brian Smith 7382da50e7 Remove redundant OpenSSL-based ALPN tests and "skipped()" test helper.
ALPN is now tested in `alpn()` in rustls/tests/api.rs and by the Bogo tests
that have names staring with "ALPN".

Of the BoGo tests, only these are disabled in bogo.json:

```
    "ALPN*SelectEmpty-*": "",
```

By removing these tests, we can remove `skipped()`.
2022-01-27 19:59:26 +00:00
Brian Smith 50f2c6c266 Remove redundant rustls-mio/tests/{client,server}_suites.rs tests.
These are now redundant with the Bogo tests.
2022-01-26 22:41:04 +01:00
Brian Smith b849ef1c90 Remove redundant rustls-mio/tests/curves.rs.
These tests are redundant with the Bogo "CurveTest-" tests. Of those,
only the ones that are testing unsupported curves are disabled:

```
    "CurveTest-Client-P-521-TLS12": "",
    "CurveTest-Server-P-521-TLS12": "",
    "CurveTest-Client-Compressed-P-521-TLS12": "",
    "CurveTest-Server-Compressed-P-521-TLS12": "",
    "CurveTest-Client-P-521-TLS13": "",
    "CurveTest-Server-P-521-TLS13": "",
    "CurveTest-Client-Compressed-P-521-TLS13": "",
    "CurveTest-Server-Compressed-P-521-TLS13": "",
```
2022-01-26 22:10:54 +01:00
Brian Smith cecf224dc1 Server: Don't depend on `ALL_CIPHER_SUITES` when not using `Acceptor`.
Reduce the chances that code for unwanted cipher suites will be linked
in, when not using the `Acceptor` API. This fixes a code size regression
from 0.20.0.

Doing the same for the case where `Acceptor` is used is tracked as
https://github.com/rustls/rustls/issues/973.
2022-01-26 19:35:39 +00:00
Brian Smith 6faedc11a6 TLS 1.3: Fix build warning with default feature set.
After the most recent changes, `inappropriate_message` is only used
in server/tls13.rs if QUIC is enabled.
2022-01-25 19:07:18 +00:00
Brian Smith daa0d73116 TLS 1.3: Improve error reporting for handshake message received during early data.
Fixes #958.
2022-01-25 18:11:08 +01:00
Brian Smith 0fe3052208 Tests: Move dangerous_configuration` cert verifier tests into separate suites.
Make it easier to find the {Client,Server}CertVerifier tests. Split
them into separate files so that we can use `diff` to compare how we're
testing each.

This removes all of the `dangerous_configuration` tests from tests/api.rs.

Each of the mock Client/Server verifiers were eached move into the single test
suite that uses it.

Use these commands with a whitespace-smart diff tool to see that the tests
were not modified except for whitespace and formatting:
```
git difftool HEAD^1:rustls/tests/api.rs rustls/tests/server_cert_verifier.rs
git difftool HEAD^1:rustls/tests/api.rs rustls/tests/client_cert_verifier.rs
git difftool HEAD^1:rustls/tests/common/mod.rs rustls/tests/client_cert_verifier.rs
git difftool HEAD^1:rustls/tests/common/mod.rs rustls/tests/server_cert_verifier.rs
```
2022-01-25 10:28:44 +01:00
Brian Smith edeff1e552 TLS client: Make the logic for sending Certificate/CertificateVerify clearer.
Factor out the common logic between TLS 1.2 and TLS 1.3.
2022-01-25 09:20:52 +01:00
Brian Smith 8d76aa67a9 Style: Replace `ref payload` with more idiomatic uses.
There are other places `ref` is used but I didn't change those.
2022-01-23 23:31:06 +01:00
Brian Smith a39b34cfc7 Remove `check_message`. 2022-01-23 23:31:06 +01:00
Brian Smith d82858c3ed Avoid redundant `check_message` calls.
A common pattern in the code is:
```
     check_message(...);
     match m.payload {
     }
```

The check_message call does its own pattern matching very much like what
is immediately done after. Avoid doing that redundant pattern matching.
2022-01-23 23:31:06 +01:00
Brian Smith fadb6f658f TLS 1.3: Avoid pattern matching on incoming certificate (request) twice. 2022-01-23 23:31:06 +01:00
Brian Smith f0e36082b6 Allow `inappropriate_handshake_message` to handle more cases.
Allow `inappropriate_handshake_message` to handle cases where
non-handshake messages are also accepted. This simplifies more callers.

I intentionally didn't try to simplify `check_message` because my next
set of commits would remove it.
2022-01-23 23:31:06 +01:00
Brian Smith e1ce891f20 Simplify `require_handshake_msg[_move]`.
Use `inappropriate_handshake_message` to reduce the amonut of code that
will be inlined into the "caller" of the macros.
2022-01-23 23:31:06 +01:00
Brian Smith e3fba94139 Simplify `inappropriate[_handshake]_message`. 2022-01-23 23:31:06 +01:00
Brian Smith 85809b1e43 Make `cargo {check,build,test} --all-features` work on Rust Stable.
Make the `read_buf` feature do nothing on non-Nightly Rust.

This makes it easier for people not depending on that feature to
build/test Rustls, as demonstrated by the CI/CD changes here.

Use `rustversion` instead of `rustc_version`; `rustc_version` has more
dependencies.
2022-01-23 23:30:52 +01:00
Dirkjan Ochtman 7d091bfba2 Remove unused variant HandshakeType::EarlyData 2022-01-23 16:03:10 +00:00
Brian Smith 8c203e1500 Restore thread-safety to the integration test suite w.r.t. `env::set_var`.
Serialize all tests that use `std::env::set_var` & isolate them. See the
comments in key_log_file_env.rs for details.

Also add notes about the fact that these tests aren't really testing the
functionality.

Use a whitespace-smart diff tool to compare the new file to what was in
api.rs:
```
git difftool HEAD^1:rustls/tests/api.rs rustls/tests/key_log_file_env.rs
```
2022-01-22 11:27:08 +00:00
Brian Smith 97c3669452 Remove `RsaSigningKey` from the public API documentation.
The API isn't part of the public API. It is `pub` only because some tests use it.
2022-01-22 10:56:15 +01:00
Brian Smith 5835681bbf CommonState::process_main_protocol: Remove misleading comments.
The comments are out of date. In particular, `check_message` isn't
used, but also the other comments are misleading. Just remove them.
2022-01-22 10:54:58 +01:00
Brian Smith 3e466251eb Clarify when `may_receive_application_data` is set.
`start_incoming_traffic()` doesn't need to exist as a `pub(crate)`
function, or at all, because it is only used by the function right
below it. Inline it into that function to make it clearer when
`may_receive_application_data` is set.
2022-01-21 23:29:06 +01:00
Dirkjan Ochtman be5b3972a0 tls12: inline downgrade marker handling
Avoids duplicating the client/server state in the ConnectionRandoms,
which was unused if TLS 1.2 was disabled.
2022-01-21 21:06:44 +01:00
Dirkjan Ochtman 9a4307f7a7 Explicitly pass side to make_cipher_pair() 2022-01-21 21:06:44 +01:00
Dirkjan Ochtman 3405c4fc77 Implement enum for client/server distinctions 2022-01-21 21:06:44 +01:00
Brian Smith ead429fb6a Correct comment typos: `RSASigningKey` -> `RsaSigningKey`.
The type was renamed but the references in documentation weren't updated.
2022-01-18 18:02:06 +01:00
Brian Smith 97945db5d8 TLS 1.3 client: Stop holding onto entire `ClientConfig` after handshake.
TLS 1.2 client and server `ExpectTraffic`, and TLS 1.3 server `ExpectTraffic` already
don't store `ClientConfig` any longer. The TLS 1.3 client `ExpectTraffic` seems to be
the last instance.
2022-01-17 07:17:39 +01:00
Joseph Birr-Pixton ce3bd130a5 Improve type of record_layer trial_decryption_len 2022-01-15 12:12:16 +00:00
Joseph Birr-Pixton fc5488378e Refuse early_data if resumption data is not fresh
At the same time, support the -resumption-delay flag in bogo_shim.
This is achieved by editing the session data as it is persisted.
This also enables bogo tests that we respect TLS1.2 ticket lifetimes.
2022-01-15 12:12:16 +00:00
Joseph Birr-Pixton 082362de63 Make ServerSessionValue record its time of creation 2022-01-15 12:12:16 +00:00
Joseph Birr-Pixton 7f7bf75ff3 List 0-RTT data as a supported feature. 2022-01-15 12:12:16 +00:00
Joseph Birr-Pixton a80da9967b Test 0-RTT
This has some api tests, but mainly enables bogo tests.

In passing, ensure TLS1.3 NewSessionTicket checks for duplicated
extensions.
2022-01-15 12:12:16 +00:00
Joseph Birr-Pixton 725870a480 Enable server support for 0-RTT data
This previously existed, but only for QUIC.

There are some unfortunate shortcomings with the protocol design here:

Because the client must send 0-RTT data whether or not the server
accepts it or even the client hello, there must be several
disjoint methods for identifying and skipping these messages.  One
of these is in the record_layer.rs, and works by trial decryption.
Another happens if the server rejects the client's hello altogether,
and skips encrypted messages between the two client hellos.

The amount of data to skip is limited but -- because the design
appears to be defective -- the quantity is expressed (in
`max_early_data_size` provided with a ticket) in units of plaintext
bytes, but skipping data requires it in units of padded, tagged
ciphertext bytes.  The server cannot compute one from the other,
so we're interpretting `max_early_data_size` as both at the same time.
2022-01-15 12:12:16 +00:00
Joseph Birr-Pixton b0c29c2468 Allow two ChangeCipherSpecs in TLS1.3 middlebox mode
The server receives two of these if the client attempts
early_data but is rebuffed by the server with a HelloRetryRequest.
2022-01-15 12:12:16 +00:00
Joseph Birr-Pixton 7c30826398 Support 0.5RTT server->client traffic
This means the server can send application data in its first
flight.  We only do this, though, if no client auth is in play
(as otherwise we'd be sending data to an unauthenticated peer,
and that would be exceedingly bad.)

This is useful for server-speaks-first protocols, as well as
replying to a 0-RTT request in a client-speaks-first one.

In terms of code changes, this splits start_traffic() into
start_incoming_traffic() and start_outgoing_traffic().
2022-01-15 12:12:16 +00:00
Joseph Birr-Pixton 7aaffe6977 Clean up client extension construction
- move unconditional extensions into vec construction
- make supported_versions unconditional: it was conditional because
  one with zero elements is illegal, but in fact it is a library
  invariant that at last one version is configured.
2022-01-15 11:08:48 +00:00
Brian Smith 9159a82c33 Use the new feature resolver (`resolver = "2"`).
Use the new feature resolver stablized in Rust 1.51.0 to improve how
features are handled.
2022-01-14 00:28:46 +01:00
Klim Tsoutsman c5383e5cc9 Derive debug for marker types
Signed-off-by: Klim Tsoutsman <klimusha@gmail.com>
2022-01-14 00:17:09 +01:00
Brian Smith d0c1ddbc84 Rename `{keylog,keylogfile}` to `{key_log,key_log_file}`.
Be consistent with other modules.

```sh
git diff HEAD^1:rustls/src/keylog.rs rustls/src/key_log.rs
git diff HEAD^1:rustls/src/keylogfile.rs rustls/src/key_log_file.rs
```
2022-01-14 00:16:07 +01:00
Brian Smith d99178da8b Split `KeyLogFile` into its own module.
Make it clear that `KeyLog` doesn't depend on `std::{env,fs,io,path,sync}`.

Use `git diff main:rustls/src/keylog.rs rustls/src/keylogfile.rs` to
verify that none of the `KeyLogFile` code has changed at all.
2022-01-14 00:16:07 +01:00
Brian Smith 467a07911d Revert "Defer opening key log file until writing to it"
This reverts commit 5e3de58514 because it
isn't a hackward compatible change. The `KeyLogFile::new()` constructor
promises that the file is opened within `new()`.

Fixes https://github.com/rustls/rustls/issues/919.
2022-01-13 23:22:04 +01:00
Brian Smith 1824673eee Address Clippy warnings about `unwrap_or_else(Vec::new)`. 2022-01-13 23:20:34 +01:00
Brian Smith 6b8f724e7a Use `Self(())` instead of `Self { 0: () }`.
GitHub is warnings about this in the code review UI.
2022-01-13 20:28:21 +00:00
Dirkjan Ochtman 8e3a720d3b Fix new unreachable_pub warnings 2022-01-13 21:22:58 +01:00
Alex Rawson c516d599a5 Fix deny-by-default clippy lints in examples and api.rs 2022-01-07 07:42:51 +01:00
Joseph Birr-Pixton 4ae7cff55a Update (and thereby fix) verifybench tests
Ran admin/capture-certdata and then recorded timestamp in verifybench.rs
2021-12-30 13:38:49 +00:00
Dirkjan Ochtman 5e5a3c3fdd Avoid temporary allocations for encoding TLS vectors
When encoding a TLS vector we previously encoded the items into
a temporary `Vec`, then wrote the length of that `Vec` into the
output stream, then copied the temporary `Vec` into the output.
Instead, we can write the correct amount of zero bytes into the
output stream before writing the items, then overwrite the zero
bytes with the correct length. This avoids the allocation for
the temporary `Vec` and copying the item data from the temporary
`Vec` into the output stream.
2021-12-28 22:52:21 +01:00