Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 16 additions & 4 deletions boring/src/ssl/async_callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,16 @@ impl SslContextBuilder {
Poll::Pending => return Err(SelectCertError::RETRY),
};

let finish = fut_result.or(Err(SelectCertError::ERROR))?;

finish(client_hello).or(Err(SelectCertError::ERROR))
let finish = fut_result.map_err(|e| match e {
AsyncSelectCertError::Error => SelectCertError::ERROR,
AsyncSelectCertError::DisableEch => SelectCertError::DISABLE_ECH,
})?;

match finish(client_hello) {
Ok(_) => Ok(()),
Err(AsyncSelectCertError::Error) => Err(SelectCertError::ERROR),
Err(AsyncSelectCertError::DisableEch) => Err(SelectCertError::DISABLE_ECH),
}
});
}

Expand Down Expand Up @@ -230,7 +237,12 @@ where

/// A fatal error to be returned from async select certificate callbacks.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs to be updated to reflect the fact that it's not really a fatal error anymore.

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct AsyncSelectCertError;
pub enum AsyncSelectCertError {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really an "error" anymore, and since we are changing the type anyway we might as well rename it as well. Maybe "AsyncSelectCertResult" or "AsyncSelectCertAction" or something along those lines.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also maybe make this enum non_exhaustive so future changes won't break API, but not 100% sure that makes sense.

/// A fatal error occurred and the handshake should be terminated.
Error,
/// Discard ECH ClientHelloInner and re-handshake with ClientHelloOuter.
DisableEch,
}

/// Describes async private key hooks. This is used to off-load signing
/// operations to a custom, potentially asynchronous, backend. Metadata about the
Expand Down
3 changes: 3 additions & 0 deletions boring/src/ssl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,9 @@ impl SelectCertError {

/// The operation could not be completed and should be retried later.
pub const RETRY: Self = Self(ffi::ssl_select_cert_result_t::ssl_select_cert_retry);

/// Discard ECH ClientHelloInner and re-handshake with ClientHelloOuter.
pub const DISABLE_ECH: Self = Self(ffi::ssl_select_cert_result_t::ssl_select_cert_disable_ech);
}

/// Extension types, to be used with `ClientHello::get_extension`.
Expand Down
11 changes: 7 additions & 4 deletions tokio-boring/tests/async_select_certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ async fn test_async_select_certificate_callback_yield() {

#[tokio::test]
async fn test_async_select_certificate_callback_return_error() {
with_async_select_certificate_callback_error(|_| Err(AsyncSelectCertError)).await;
with_async_select_certificate_callback_error(|_| Err(AsyncSelectCertError::Error)).await;
}

#[tokio::test]
async fn test_async_select_certificate_callback_future_error() {
with_async_select_certificate_callback_error(|_| {
Ok(Box::pin(async move { Err(AsyncSelectCertError) }))
Ok(Box::pin(async move { Err(AsyncSelectCertError::Error) }))
})
.await;
}
Expand All @@ -52,7 +52,7 @@ async fn test_async_select_certificate_callback_future_yield_error() {
Ok(Box::pin(async move {
yield_now().await;

Err(AsyncSelectCertError)
Err(AsyncSelectCertError::Error)
}))
})
.await;
Expand All @@ -64,7 +64,10 @@ async fn test_async_select_certificate_callback_finish_error() {
Ok(Box::pin(async move {
yield_now().await;

Ok(Box::new(|_: ClientHello<'_>| Err(AsyncSelectCertError)) as BoxSelectCertFinish)
Ok(
Box::new(|_: ClientHello<'_>| Err(AsyncSelectCertError::Error))
as BoxSelectCertFinish,
)
}))
})
.await;
Expand Down
Loading