Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions h3-quinn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,18 @@
recv: RecvStream,
}

impl<B> BidiStream<B>
where
B: Buf,
{
/// Check if this stream was opened during 0-RTT.
///
/// See [RFC 8470 Section 5.2](https://www.rfc-editor.org/rfc/rfc8470.html#section-5.2).
pub fn is_0rtt(&self) -> bool {
self.recv.is_0rtt()
Comment thread
Ruben2424 marked this conversation as resolved.
Outdated
}
}

impl<B> quic::BidiStream<B> for BidiStream<B>
where
B: Buf,
Expand Down Expand Up @@ -338,6 +350,15 @@
}
}

impl<B> h3::server::Is0rtt for BidiStream<B>
where
B: Buf,
{
fn is_0rtt(&self) -> bool {
BidiStream::is_0rtt(self)
}
}

/// Quinn-backed receive stream
///
/// Implements a [`quic::RecvStream`] backed by a [`quinn::RecvStream`].
Expand All @@ -360,8 +381,19 @@
stream: Some(stream),
// Should only allocate once the first time it's used
read_chunk_fut: ReusableBoxFuture::new(async { unreachable!() }),
}

Check warning on line 384 in h3-quinn/src/lib.rs

View workflow job for this annotation

GitHub Actions / Check Style

Diff in /home/runner/work/h3/h3/h3-quinn/src/lib.rs

Check warning on line 384 in h3-quinn/src/lib.rs

View workflow job for this annotation

GitHub Actions / Check Style

Diff in /home/runner/work/h3/h3/h3/src/tests/../../../h3-quinn/src/lib.rs
}

/// Check if this stream has been opened during 0-RTT.
///
/// In which case any non-idempotent request should be considered dangerous at the application
/// level. Because read data is subject to replay attacks.
pub fn is_0rtt(&self) -> bool {
self.stream
.as_ref()
.map(|s| s.is_0rtt())
.unwrap_or(false)
Comment thread
Ruben2424 marked this conversation as resolved.
Outdated
}
}

impl quic::RecvStream for RecvStream {
Expand Down
7 changes: 7 additions & 0 deletions h3/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ impl<S, B> FrameStream<S, B> {
pub fn into_inner(self) -> BufRecvStream<S, B> {
self.stream
}

pub(crate) fn is_0rtt(&self) -> bool
where
S: crate::server::Is0rtt,
Comment thread
Ruben2424 marked this conversation as resolved.
Outdated
{
self.stream.is_0rtt()
}
}

impl<S, B> FrameStream<S, B>
Expand Down
2 changes: 1 addition & 1 deletion h3/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ pub use builder::builder;
pub use builder::Builder;
pub use connection::Connection;
pub use request::RequestResolver;
pub use stream::RequestStream;
pub use stream::{Is0rtt, RequestStream};
28 changes: 28 additions & 0 deletions h3/src/server/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,36 @@

/// Returns the underlying stream id
pub fn id(&self) -> StreamId {
self.inner.stream.id()

Check warning on line 106 in h3/src/server/stream.rs

View workflow job for this annotation

GitHub Actions / Check Style

Diff in /home/runner/work/h3/h3/h3/src/server/stream.rs
}

/// Check if this stream was opened during 0-RTT.
///
/// See [RFC 8470 Section 5.2](https://www.rfc-editor.org/rfc/rfc8470.html#section-5.2).
///
/// # Example
///
/// ```no_run
/// # use h3::server::RequestStream;
/// # async fn example(mut stream: RequestStream<impl h3::quic::BidiStream<bytes::Bytes>, bytes::Bytes>) {
/// if stream.is_0rtt() {
/// // Reject non-idempotent methods (e.g., POST, PUT, DELETE)
/// // to prevent replay attacks
/// }
/// # }
/// ```
pub fn is_0rtt(&self) -> bool
where
S: Is0rtt,
{
self.inner.stream.is_0rtt()
}
}

/// Trait for QUIC streams that support 0-RTT detection.
pub trait Is0rtt {
/// Check if this stream was opened during 0-RTT.
Comment thread
Ruben2424 marked this conversation as resolved.
Outdated
fn is_0rtt(&self) -> bool;
}

impl<S, B> RequestStream<S, B>
Expand Down
7 changes: 7 additions & 0 deletions h3/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,13 @@ impl<S, B> BufRecvStream<S, B> {
_marker: PhantomData,
}
}

pub(crate) fn is_0rtt(&self) -> bool
where
S: crate::server::Is0rtt,
Comment thread
Ruben2424 marked this conversation as resolved.
Outdated
{
self.stream.is_0rtt()
}
}

impl<B, S: RecvStream> BufRecvStream<S, B> {
Expand Down
Loading