3413 Commits

Author SHA1 Message Date
Phoenix Kahlo d34b375da6 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-03-27 10:37:02 +01:00
Phoenix Kahlo 736f87bcdc Allow accept/reject/retry before handshake begins
This commit removes use_retry from the server config and provides a
public API for the user to manually accept/reject/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/
reject/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 reject, 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-03-27 10:37:01 +01:00
Phoenix Kahlo 0af674127f Refactor proto endpoint to use Incoming
This commit refactors the logic for a quinn_proto::Endpoint accepting
an incoming connection so that it constructs an explicit Incoming struct
containing all the necessary state to accept/reject/retry the
connection-creating packet. However, the external API stays the same.

The bulk of this code change is just moving around existing code.
Additionally, adds some gitignore lines I was using for coverage
testing.
2024-03-27 10:36:57 +01:00
Dirkjan Ochtman a74370865c proto: extract Endpoint::retry() method 2024-03-27 10:18:34 +01:00
Dirkjan Ochtman d67682c082 quinn: improve TransmitState abstraction 2024-03-27 10:10:19 +01:00
Phoenix Kahlo 7c470a8060 Factor out TransmitState sub-struct from State
This commit factors out the two fields of a quinn::Endpoint's State
necessary to process a proto::Transmit into a new sub-struct,
TransmitState. This is to alleviate borrowing issues, because
proto::Transmit will soon be called from more call sites than
previously.

The bulk of this code change is just moving around existing code.
2024-03-27 10:01:10 +01:00
Phoenix K 3e82064c09 Factor out check_connection_limit
This commit factors out the connection limit check from
quinn_proto::Endpoint::early_validate_first_packet to a new method. This
commit also adds a new ConnectionLimitExceeded variant to
ConnectionError, although it is not yet instantiated. These changes are
made because this exception case will soon be possible to encounter at
more points than previously.
2024-03-27 09:55:48 +01:00
Dirkjan Ochtman 56f03f1b37 Tweak comment alignment for transport parameter validation 2024-03-26 19:08:09 -07:00
Benjamin Saunders a509b4a429 Add missing transport parameter validation checks 2024-03-26 11:08:52 -07:00
Benjamin Saunders 6a1467d231 Document and tighten CID length validation 2024-03-26 10:59:06 -07:00
Benjamin Saunders 835a65fac2 Perform early first-packet validation before decryption 2024-03-26 10:59:06 -07:00
Benjamin Saunders 36950c6bb1 Factor initial packet plain header fields out into a struct 2024-03-26 10:59:06 -07:00
Benjamin Saunders 95ac70d6b6 Factor out payload-independent connection refusal tests 2024-03-26 10:59:06 -07:00
Benjamin Saunders 990203b477 Bound memory use in RETIRE_CONNECTION_ID frame queue 2024-03-26 10:50:17 -07:00
Jamil a2a214b968 Enable all macos UDP features on ios 2024-03-23 11:40:29 -07:00
jean-airoldie a5b6fac103 Expose RecvStream::poll_read 2024-03-19 09:10:41 +01:00
jean-airoldie a100fc76da Improve poll_finish documentation 2024-03-17 08:31:00 +01:00
jean-airoldie 5dd70afc42 Expose SendStream::poll_write and poll_finish methods 2024-03-17 08:31:00 +01:00
Gabi ffac4a339c Enable packet info and related flags for quinn-udp on Android 2024-03-11 19:55:24 +00:00
Benjamin Saunders 62205e80d7 Encapsulate more congestion control logic inside PathData 2024-03-11 12:19:34 -07:00
Benjamin Saunders 214f694ce0 Maintain in-flight counters separately per path 2024-03-11 12:19:34 -07:00
Benjamin Saunders a19966ba07 Move Connection::remove_in_flight onto InFlight 2024-03-11 12:19:34 -07:00
Felician Nemeth 2e72f27bfd Fix constant of frame_type IMMEDIATE_ACK
Both the draft and the IANA registry say the current value for
frame_type IMMEDIATE_ACK is 0x1F.

https://www.iana.org/assignments/quic/quic.xhtml
https://datatracker.ietf.org/doc/html/draft-ietf-quic-ack-frequency#section-10.2

Co-Authored-By: Tamas Levai <levait@tmit.bme.hu>
2024-03-06 11:51:22 -08:00
Benjamin Saunders 9611c5ef69 Limit memory used to track sent ACKs when purely receiving 2024-02-29 11:09:51 -08:00
Benjamin Saunders e82ae58bb0 Update space in-flight counter in Space::take
Unifying this with removing a packet's tracking state is less
error-prone, and moves some responsibility out of the Connection
monolith.
2024-02-29 11:09:51 -08:00
Benjamin Saunders b50a7e426e Abstract out helper for removing sent packet state 2024-02-29 11:09:51 -08:00
Benjamin Saunders 06bd20d446 Occasionally ACK packets even when unprompted by peer 2024-02-29 11:09:51 -08:00
Benjamin Saunders b08d1089df Remove redundant assert 2024-02-29 11:09:51 -08:00
Benjamin Saunders cd69fa5260 Don't double-count buffer consumption in close length checks
PacketBuilder::max_size previously subtracted out the start index and
header size of the packet, and therefore described the admissible size
of the packet's frames. However, most of our logic operates in terms
of absolute buffer positions instead. This was confusing, and led to
erroneous double-counting of space use in close packets.
2024-02-25 00:04:26 -08:00
Benjamin Saunders 1ed8e976eb Test closing incoming connections before a response is sent 2024-02-24 23:59:31 -08:00
Benjamin Saunders 88e6958a7d Allow detailed transport-layer errors in insecure spaces
Required for reliable delivery of e.g. handshake errors.
2024-02-24 23:59:31 -08:00
Benjamin Saunders 0b1116be21 Improve reliability of Close delivery during handshakes 2024-02-24 23:59:31 -08:00
Max Inden a947962131 fix(quinn-udp): use TOS for IPv4-mapped IPv6 dst addrs 2024-02-22 12:28:44 -08:00
Benjamin Saunders 614fef62f7 Document cancel-safety of stream I/O operations 2024-02-21 09:56:49 +01:00
dependabot[bot] dcc8048974 build(deps): bump codecov/codecov-action from 3 to 4
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3 to 4.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/v3...v4)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-05 15:02:55 +01:00
Benjamin Saunders 1c7c46049c Send path validation responses to the correct remote 2024-01-25 11:01:07 +01:00
Benjamin Saunders d95c65e6f0 Factor out helper structure for path validation responses 2024-01-25 11:01:07 +01:00
Benjamin Saunders bfd1b24769 Move PathResponse into mod paths 2024-01-25 11:01:07 +01:00
Benjamin Saunders ebc1b9d684 Reduce coercion 2024-01-25 11:01:07 +01:00
Benjamin Saunders eeb12911ac Factor out udp_tx stats update 2024-01-25 11:01:07 +01:00
Benjamin Saunders 268cfb9981 Don't shadow builder storage in poll_transmit 2024-01-25 11:01:07 +01:00
Al Liu 2e4074afb1 Copy the AsyncStdRuntime module to create SmolRuntime 2024-01-24 23:34:34 +01:00
Al Liu b2e0667cb5 Wrap AsyncStdRuntime in an inline module, in place 2024-01-24 23:34:34 +01:00
Al Liu 3fded56a6d Introduce UdpSocket::new() and use it in the AsyncStdRuntime impl 2024-01-24 23:34:34 +01: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 2a1b614c01 Document two more commonly-observed mistakes in RecvStream use 2024-01-19 09:27:48 +01:00
Benjamin Saunders b5dd5a978b Replace rustls-native-certs with rustls-platform-verifier 2024-01-18 07:52:09 +01:00
Benjamin Saunders 66cb4a964a udp: Expand crate documentation 2024-01-17 13:27:15 -08:00
Damien Deville 20dff915e1 udp: use io::Result<> where possible 2024-01-08 11:14:52 -08:00
Damien Deville 6e3d10857e udp: make basic test work even if Ipv6 support is disabled 2024-01-04 11:26:22 -08:00