Commit Graph

165 Commits

Author SHA1 Message Date
stormshield-gt 184568ea59 Fix example std::net imports 2024-10-17 18:56:55 +00:00
Lars Eggert 15a4dcef42 chore: Replace IP strings with address types
Avoids a bunch of parsing and checking.
2024-10-09 08:05:22 +00:00
Dirkjan Ochtman 9a656d2d0b Enable use of aws-lc-rs instead of ring 2024-09-24 07:33:03 +00:00
Dirkjan Ochtman 7b97a3fbd8 Apply clippy suggestions from Rust 1.79 2024-06-13 10:59:05 -07:00
Benjamin Saunders 772c269c8d Fix panic in example due to unset default crypto provider 2024-05-24 20:43:35 +02:00
Benjamin Saunders b42e21e74d Make SendStream::finish synchronous
`await`ing on this was error-prone and not very useful, since it gave
little insight into application state, and was redundant to `stopped`.
2024-05-03 11:52:44 -07:00
gabrik ce13559778 proto: validate ServerConfig crypto provider
Signed-off-by: gabrik <gabriele.baldoni@gmail.com>
2024-04-22 09:45:53 +02:00
Dirkjan Ochtman e6d48970af proto: validate ClientConfig crypto provider
Co-authored-by: gabrik <gabriele.baldoni@gmail.com>
2024-04-22 09:45:53 +02:00
Dirkjan Ochtman 3be1ab5ab2 Upgrade to rcgen 0.13 2024-04-22 09:45:53 +02:00
Dirkjan Ochtman a85a4c12ee Update rustls to 0.23 and ring to 0.17 2024-04-22 09:45:53 +02:00
Dirkjan Ochtman 76875408a9 quinn: inline single-use helper function 2024-04-22 09:45:53 +02:00
Dirkjan Ochtman 07e428169b proto: deduplicate rustls ClientConfig setup 2024-04-22 09:45:53 +02:00
Dirkjan Ochtman e28b29f76e quinn: add bounds in dyn Error types 2024-04-22 09:45:53 +02:00
Phoenix Kahlo ff487f01c8 Demonstrate connection limiting in example
This commit adds a new --connection-limit option to the server example
to illustrate how a user could implement a limit to the number of
connections open at a time with the new "incoming" API and
Endpoint::open_connections method rather than with the now-removed
concurrent_connections ServerConfig parameter.
2024-04-03 10:02:29 +02:00
Phoenix Kahlo 75c0e0192a Demonstrate IP blocking in example
This commit adds a new --block option to the server example to
illustate in a simplified way the general structure one would use to
implement IP address blocking with the new accept/reject/retry API.

For example:

    cargo run --example server ./ --listen 127.0.0.1:4433 --stateless-retry --block 127.0.0.1:8065
    cargo run --example client https://127.0.0.1:4433/Cargo.toml --host localhost --bind 127.0.0.1:8065

One thing to note is that that example places the reject condition
before the retry condition. This expends slightly less effort rejecting
connections, but does create a blocked IP address oracle for an attacker
who can do address spoofing.
2024-04-03 10:02:29 +02:00
Phoenix Kahlo 54d5d60b42 Allow accept/refuse/retry before handshake begins
This commit removes use_retry from the server config and provides a
public API for the user to manually accept/refuse/retry incoming
connections before a handshake begins, and inspect properties such as
an incoming connection's remote address and whether that address is
validated when doing so.

In quinn-proto, Incoming is made public, as well as Endpoint's accept/
refuse/retry methods which operate on it. The
DatagramEvent::NewConnection event is modified to return an incoming
but not yet accepted connection.

In quinn, awaiting Endpoint::accept now yields a new
quinn::Incoming type, rather than quinn::Connecting. The new
quinn::Incoming type has all the methods its quinn_proto equivalent has,
as well as an accept method to (fallibly) transition it into a
Connecting, and also refuse, retry, and ignore methods.

Furthermore, quinn::Incoming implements IntoFuture with the output type
Result<Connection, ConnectionError>>, which is the same as the Future
output type of Connecting. This lets server code which was
straightforwardly awaiting the result of quinn::Endpoint::accept work
with little to no modification.

The test accept_after_close was removed because the functionality it
was testing for no longer exists.
2024-04-03 10:02:29 +02:00
Phoenix Kahlo 597b10b2d5 Fix parsing of IPV6 URLs in client example
Currently, when trying to run the client example with an IPV6 address
URL, such as by running:

    cargo run --example client https://[::1]:4433/Cargo.toml --host localhost

A "failed to lookup address information: Name or service not known"
error is raised. This is because `url.host_str()` is `"[::1]"`, which
is wrapped in brackets. These brackets, specified by by RFC 2732, are
part of the URL syntax, not the IP address syntax.

Although this code succeeds, because the standard library treats this
like a URL:

    use std::net::ToSocketAddrs;
    "[::1]:4433".to_socket_addrs()

This code does not:

    use std::net::Ipv6Addr;
    "[::1]".parse::<Ipv6Addr>()

As the stdlib expects to just receive "::1". Consequentially, this
does not succeed, counterintuitively:

    use std::net::ToSocketAddrs;
    ("[::1]", 4433).to_socket_addrs()

This code fixes the client example's URL parsing behavior by
stripping out such brackets in the same way as [is done in
tokio-tungstenite][1].

[1]: https://github.com/snapview/tokio-tungstenite/blob/052d085aff4708b924b92becaa83923b15045841/src/lib.rs#L404
2024-01-20 18:15:03 -08:00
Benjamin Saunders 044eab53ff Update clap 2023-05-11 14:10:19 +02:00
Benjamin Saunders 092a7686a4 Enable PMTUD by default when appropriate 2023-05-06 08:05:17 +02:00
Adolfo Ochagavía 2d48482180 Use PLPMTUD in bench, perf and examples
Sponsored by Stormshield
2023-04-04 17:40:20 -07:00
Benjamin Saunders 90a99193a9 Borrow self in read_to_end, rather than consuming
Allows `RecvStream::stop` to be called with custom error codes if
`ReadToEndError::TooLong` is encountered.
2023-03-05 08:52:31 +01:00
Dirkjan Ochtman f7354ef6ac Inline format arguments 2023-02-27 07:34:35 +01:00
Dirkjan Ochtman 2c6aa43610 Apply clippy suggestions from Rust 1.66 2022-12-19 10:13:01 -08:00
StygianLightning 0d366990f1 Removed an obsolete lint control annotation.
The lint issue that made the workaround necessary has been resolved.
2022-12-10 11:07:03 -08:00
StygianLightning b170993bd1 Fixed a typo. 2022-12-10 11:07:03 -08:00
Benjamin Saunders 641114a69d Fix clippy lints 2022-11-14 01:17:22 -08:00
Benjamin Saunders 7d51d2e57e Remove Incoming stream in favor of Endpoint::accept 2022-10-23 08:18:42 +02:00
Benjamin Saunders 6e4bcbb2fc Drop NewConnection in favor of simpler API 2022-09-27 11:08:26 +02:00
Benjamin Saunders fe93a68108 Replace structopt with its successor, clap 3 2022-07-03 21:02:33 +02:00
François Garillot f731019c83 Clean up a few Option/Result patterns that fit an std combinator 2022-01-29 13:00:48 -08:00
Benjamin Saunders f91f74610c Update example README output samples 2022-01-01 21:36:29 +01:00
Benjamin Saunders 19b58cc948 Drop futures-util dev-dependency
This wasn't serving any purpose we couldn't more readably accomplish
with async/await.
2021-12-29 07:34:22 +01:00
Benjamin Saunders 7ed94be3e4 Provide inherent next methods on streams
Allows for convenient use in async blocks by downstream code without a
futures_util dependency.
2021-12-21 07:03:27 +01:00
Benjamin Saunders 5822ff3781 Fix ALPN misconfiguration in example
Introduced by a copy-paste error in
9daaa15da2
2021-12-10 10:16:53 +01:00
Benjamin Saunders 1159ae3c65 Non-exhaustive ClientConfig 2021-11-10 11:25:19 +01:00
BiagioFesta 25d9a40bf9 followup: rename "stateless retry" -> "retry"
Fix compile error in quinn-proto after field rename
2021-11-06 13:11:56 +01:00
Benjamin Saunders b923c4c8b0 Pass SocketAddr by value
We always consume this by value in the end, and it's a little more
ergonomic.
2021-10-29 20:12:45 +02:00
Benjamin Saunders 5d1b6a101b Remove EndpointBuilder
Now that rustls configuration is more straightforward, this is not
adding significant value.
2021-10-29 20:12:45 +02:00
Benjamin Saunders 34ca6cff61 Privatize crypto config helpers
We're now sufficiently compatible with rustls defaults that these
aren't worth the API surface area.
2021-10-29 08:02:13 +02:00
Benjamin Saunders 495d2927cb Remove certificate newtypes 2021-10-29 08:02:13 +02:00
Benjamin Saunders 4927355049 Remove config builders
These aren't significantly more convenient than working with rustls
directly at this point.
2021-10-27 17:49:48 -07:00
Benjamin Saunders a384ee2edb Erase crypto::Session::HandshakeData 2021-10-27 17:49:48 -07:00
Dirkjan Ochtman 9daaa15da2 Upgrade to rustls 0.20 2021-10-26 11:05:30 -07:00
Dirkjan Ochtman fed3c5cb39 Require explicit construction of ServerConfigs 2021-09-29 10:12:44 -07:00
Dirkjan Ochtman a7efd92044 Require explicit construction of ClientConfigs 2021-09-29 10:12:44 -07:00
Chris Connelly e63dd77376 Make TransportConfig setters infallible
For most setters this was just a case of changing the signature to take
a `VarInt`.

`max_idle_timeout` was a bit more involved in order to maintain a usable
conversion from `Duration`. The internal representation was changed from
`Duration` from `VarInt`, and an `IdleTimeout` newtype was introduced
for the setter signature. `IdleTimeout` contains a `VarInt`-encoded
millisecond value, and has a fallible conversion from `Duration`. The
use of a newtype is preferable to a direct `Duration` -> `VarInt`
encoding since there could be other `VarInt`-encoded values in future
that use a different resolution than milliseconds.

These changes allow callers to avoid the type-level possibility of error
if they have a `VarInt` (or a value that can be converted infallibly
into one). Fallible conversion from `VarInt` is still convenient with
`TryInto`, and callers can handle the conversion errors without the
indirection of `ConfigError`.

Closes #1176.

BREAKING CHANGE: The `max_concurrent_bidi_streams`,
`max_concurrent_uni_streams`, `stream_receive_window`, and
`receive_window` methods on `TransportConfig` now take `VarInt`
arguments and return `&mut Self`. `TransportConfig::max_idle_timeout`
now takes an `IdleTimeout` argument and returns `&mut Self`.
2021-09-19 18:30:43 -07:00
Marcel Märtens b224d1d0fa switch to futures_utils in tests and benches, also use futures_utils isntead of futures_core 2021-08-11 10:27:32 +02:00
Dirkjan Ochtman d78b3187a9 Apply clippy suggestions from Rust 1.54 2021-07-30 13:29:32 -07:00
Benjamin Saunders 14813d33c2 Remove unintentional, obfuscatory use of Result::into_iter 2021-03-21 22:27:17 +01:00
Benjamin Saunders 612c9ac2b8 Remove unnecessary dropping in client/server examples 2021-01-26 06:46:32 +01:00