Commit Graph

240 Commits

Author SHA1 Message Date
Benjamin Jurk 20ac87f64f examples: unbuffered-server: skip argv[0] 2024-01-08 12:09:04 +00:00
Benjamin Jurk 567d89227d examples: simpleserver: skip argv[0] & update doc comment 2024-01-08 12:09:04 +00:00
Daniel McCarney ba97712be2 examples: use CLI args vs env vars in simpleserver 2024-01-04 13:41:11 +00:00
Daniel McCarney f0934452ca examples: use CLI args vs env vars in unbuff-server 2024-01-04 13:41:11 +00:00
Daniel McCarney 59351ff6a4 examples: move consts to bottom in unbuff-server 2024-01-04 13:41:11 +00:00
Daniel McCarney 90fce7e9b4 examples: move consts to bottom in unbuff-client 2024-01-04 13:41:11 +00:00
Daniel McCarney 85b36ec8b0 examples: move consts to bottom in unbuff-async-client 2024-01-04 13:41:11 +00:00
Daniel McCarney 8c6fb1c9c3 examples: top-level doc comment for unbuffered-async-client 2024-01-04 13:41:11 +00:00
Daniel McCarney 83fa7a3d4f examples: top-level doc comment for unbuffered-server 2024-01-04 13:41:11 +00:00
Daniel McCarney 0d7c256c32 docs: add README for examples
* Inventory of the existing examples, with brief descriptions
* Guidance to look at the "simple" examples first.
2024-01-03 15:05:38 +00:00
Daniel McCarney c9963b0ecc examples: add a simple server example
This commit adds an example *server* that is roughly contemporary with
the existing "simpleclient".

It is the absolute bare minimum needed to run a server using Rustls
(e.g. it only accepts a single connection before terminating).

You can run the server with:
```
CERTFILE=test-ca/rsa/end.fullchain PRIV_KEY_FILE=test-ca/rsa/end.key  cargo run --package rustls-examples --bin simpleserver
```

And connect to it with a client:
```
cargo run --package rustls-examples --bin tlsclient-mio -- --port 4443 --cafile test-ca/rsa/ca.cert localhost --http
```
2024-01-03 15:05:38 +00:00
Niklas Fiekas 309a5d5051
Implement FromIterator for RootCertStore (#1708)
Co-authored-by: Daniel McCarney <daniel@binaryparadox.net>
2023-12-25 10:58:26 +01:00
Joseph Birr-Pixton 74fb489a2c Ensure buffer discard tracking works even on error
This sticks the error from `process_tls_records()` inside
`UnbufferedStatus`.  That means the `discard` field is still
available, but continues to require handling the error to learn
the `state` field's underlying value.

TODO: the example code is made to unwrap errors in this PR.
They need reorganising so the discard processing happens before
error handling.
2023-12-19 09:30:04 +00:00
Jorge Aparicio a416464099 add async example 2023-12-19 09:30:04 +00:00
Jorge Aparicio 07297f7f4f early data support 2023-12-19 09:30:04 +00:00
Jorge Aparicio 3535879a11 add UnbufferedServerConnection API + example 2023-12-19 09:30:04 +00:00
Jorge Aparicio 57c963951f add UnbufferedClientConnection API + example 2023-12-19 09:30:04 +00:00
Daniel McCarney 902c8e0264 examples: add intro doc string for mio server 2023-12-18 14:36:08 +00:00
Daniel McCarney 1e45a8ec1f examples: add intro doc string for mio client 2023-12-18 14:36:08 +00:00
Daniel McCarney 5bb2a2536b examples: add intro doc string for 0rtt client 2023-12-18 14:36:08 +00:00
dependabot[bot] 6c951b5d23 build(deps): bump the crates-io group with 1 update
Bumps the crates-io group with 1 update: [rcgen](https://github.com/rustls/rcgen).

- [Commits](https://github.com/rustls/rcgen/compare/v0.11.3...v0.12.0)

---
updated-dependencies:
- dependency-name: rcgen
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: crates-io
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-18 12:42:12 +00:00
Jacob Hoffman-Andrews 0963cca28d update examples to use pki_types re-export
We now re-export the rustls-pki-types crate. I think that means
our preferred way for crates to consume pki-types is through the
re-exports.
2023-12-08 09:31:35 +00:00
girlbuzz e051f5c172
minor fix: fix comment that incorrectly says "google.com" instead of "rust-lang.org" (#1667)
fix inaccurate comment
2023-12-05 09:25:02 -05:00
Joseph Birr-Pixton 381dcf99ee Update dependencies 2023-12-01 19:10:46 +00:00
Daniel McCarney a7191785f6 remove unwrap for protocol versions w/ default provider
When building a client config or a server config using the default
provider we know that the ciphersuites will be compatible with any
choice of protocol version. By having the default `builder` method
configure itself with safe default versions, and offering
a `builder_with_protocol_versions` for customization we can transition
directly to `WantsVerifier` for these default provider builders,
removing a `Result` that will never be an error and making the API more
ergonomic in the common case.
2023-11-30 15:53:39 +00:00
Daniel McCarney b92fd839e3 crypto: rework CryptoProvider as struct
This commit replaces the existing `CryptoProvider` trait with
a `CryptoProvider` struct. This has several advantages:

* it consolidates all of the cryptography related settings into one API
  surface, the `CryptoProvider` struct members. Previously the provider
  had methods to suggest default ciphersuites, key exchanges etc, but
  the builder API methods could override them in confusing ways.
* it allows removing the `WantsCipherSuites` and `WantsKxGroups` builder
  states - the "safe defaults" are automatically supplied by the choice
  of a crypto provider. Customization is achieved by overriding the
  provider's struct fields. Having fewer builder states makes the API
  easier to understand and document.
* it makes customization easier: the end user can rely on "struct update
  syntax"[0] to only specify fields values for the required
  customization, and defer the rest to an existing `CryptoProvider`.

Achieving this requires a couple of additional changes:

* The cipher suite and key exchange groups are now expressed as `Vec`
  elements. This avoids imposing a `&'static` lifetime that would
  preclude runtime customization (e.g. the tls*-mio examples that
  build the list of ciphersuites at runtime based on command line
  flags).
* As a result of the `Vec` members we can no longer offer the concrete
  `CryptoProvider`s as `static` members of their respective modules.
  Instead we add `pub fn default_provider() -> CryptoProvider` methods
  to the `ring` and `aws-lc-rs` module that construct the `CryptoProvider`
  with the safe defaults, ready for further customization.

[0]: https://doc.rust-lang.org/book/ch05-01-defining-structs.html#creating-instances-from-other-instances-with-struct-update-syntax
2023-11-30 15:53:39 +00:00
Daniel McCarney d963be3c45 webpki: remove 'default' WebPkiServerVerifier helpers
These helpers assumed the *ring* crypto provider. Consumers can now use
the exported `verify_tls12_signature` and `verify_tls13_signature`
helpers with the crypto provider of their choice to implement these fns.
Similarly since `WebPkiSupportedAlgorithms` now exposes the
`supported_schemes` fn there's no need for the
`default_supported_verify_schemes` helper.
2023-11-30 15:12:14 +00:00
Dirkjan Ochtman 26ec868b8c Migrate to pki-types ServerName 2023-11-23 21:57:10 +00:00
Dirkjan Ochtman ab5e2a917b Upgrade to latest rustls-pemfile 2023-11-23 21:57:10 +00:00
Joseph Birr-Pixton 538cb78f83 Abolish quic crate feature
This reveals that bogo_shim fails to build for `--no-default-features --features tls12`.
Feature gate the entire program on `ring | aws-lc-rs`.
2023-11-17 19:27:21 +00:00
Daniel McCarney cc0666e795 verify: add Debug bound to ServerCertVerifier
This commit adds a `Debug` bound to the `ServerCertVerifier` trait in
addition to `Send` and `Sync`. Types implementing this trait are updated
to either derive `Debug` or implement it by hand as appropriate.
2023-11-09 18:26:12 +00:00
Joseph Birr-Pixton 0e296980fd Move `rustls::cipher_suite` members into provider module
Naming cipher suites individually seems like a "detail" feature, and
therefore having to name the provider too is not a large imposition.

Naturally this is a breaking change.
2023-11-09 16:18:11 +00:00
Daniel McCarney dbc5562c6b examples: CRLUpdater -> CrlUpdater
This commit updates the server acceptor example's `CRLUpdater` struct to
be named `CrlUpdater` to match Rust naming conventions.
2023-10-18 08:25:00 +00:00
Dirkjan Ochtman 47c0450ce9 Remove unused dev-dependencies in examples crate 2023-10-10 13:19:18 +00:00
Dirkjan Ochtman 9f9f5f1c34 Drop rust-version metadata for internal crates 2023-10-04 14:17:18 +00:00
dependabot[bot] babfe038ee build(deps): bump rcgen from 0.11.2 to 0.11.3
Bumps [rcgen](https://github.com/est31/rcgen) from 0.11.2 to 0.11.3.
- [Changelog](https://github.com/rustls/rcgen/blob/main/CHANGELOG.md)
- [Commits](https://github.com/est31/rcgen/commits)

---
updated-dependencies:
- dependency-name: rcgen
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-02 13:19:12 +00:00
dependabot[bot] d980e2bd38 build(deps): bump regex from 1.9.5 to 1.9.6
Bumps [regex](https://github.com/rust-lang/regex) from 1.9.5 to 1.9.6.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.9.5...1.9.6)

---
updated-dependencies:
- dependency-name: regex
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-02 13:18:32 +00:00
Daniel McCarney f141da4a2e Cargo: remove rcgen git patch
The `rcgen` crate has cut a 0.11.2 release that includes the CRL
functionality we were using a Cargo patch to depend on previously. This
commit removes the patch, fixes one breakage in the server acceptor
example, and updates the `Cargo.toml` and `Cargo.lock` files.
2023-09-27 14:36:11 +00:00
Daniel McCarney 5fd434f7bd proj: remove dangerous_configuration feature
In an effort to reduce our feature list, this commit replaces the
`dangerous_configuration` feature flag with separate `danger` modules.

Cargo features are additive, which means transitive dependencies could
enable them for you without explicit opt-in. Using obviously named
modules will maintain the property that it's easy to grep for imports,
but avoids feature flag bloat and the additive downsides.

After discussion we've chosen to not include the webpki verifier and
helper functions as part of the dangerous API surface. Functionality for
setting a custom verifier, or implementing one to make assertions about
verification status, remain marked as dangerous via their module name.
2023-09-19 17:53:52 +00:00
Daniel McCarney e7a15fb935 lib: remove crypto:💍:kx_group re-export 2023-09-19 13:39:44 +00:00
Daniel McCarney 34bb3e3806 lib: remove crypto:💍:DEFAULT_CIPHER_SUITES re-export 2023-09-19 13:39:44 +00:00
Daniel McCarney 46b3442d57 lib: remove crypto:💍:ALL_CIPHER_SUITES re-export 2023-09-19 13:39:44 +00:00
Daniel McCarney 76db9fb00f lib: remove crypto:💍:Ticketer re-export 2023-09-19 13:39:44 +00:00
Joseph Birr-Pixton 048ff10740 Use dynamic dispatch for `CryptoProvider`
Instead of the type `rustls::crypto:💍:Ring`, the value
`rustls::crypto:💍:RING` implements this, and is more
entertaining to write.

`ServerConfig::builder()` references this by default, and
is equivalent to `ServerConfig::builder_with_provider(crypto:💍:RING)`.
2023-09-19 11:09:38 +00:00
Joseph Birr-Pixton 0e1908890d Use dynamic dispatch for key exchanges
This turns `SupportedKxGroup` into a trait, which can tell you
which `NamedGroup` it is, and `start()` an `ActiveKeyExchange`.

An `ActiveKeyExchange` represents the need for the peer's public key
which can be passed to `ActiveKeyExchange::complete`.

Unfortunately we can't be generic at compile-time over the various uses
of the resulting shared secret, so define a further type
which encapsulates the resulting shared secret.

Predefined key exchange algorithms (eg `rustls::kx_group::X25519`)
are now `&'static dyn rustls::SupportedKxGroup`.

The remainder of this commit is noise as much code ceased needing
to be generic of CryptoProvider (for its `KeyExchange` associated type).
2023-09-19 11:09:38 +00:00
Dirkjan Ochtman 1b33f8d46c Switch to using pki_types::UnixTime 2023-09-13 13:14:41 +00:00
Dirkjan Ochtman 53e9e77424 Implement Extend for RootCertStore instead of using a custom method 2023-09-11 13:38:42 +00:00
Joseph Birr-Pixton c21eca793b Take latest webpki, pki-types, pemfile, webpki-roots 2023-09-07 15:46:48 +00:00
Dirkjan Ochtman c9a3974462 Switch to using pki-types crate 2023-09-05 13:20:21 +00:00
Dirkjan Ochtman 4d825932a8 examples: clean up imports and module-level comments 2023-09-05 13:20:21 +00:00