From: "Max R. Carrara" <m.carrara@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [PATCH proxmox v3 1/5] rest-server: connection: use enum for TLS handshake check result
Date: Tue, 10 Nov 2026 12:07:23 +0100 [thread overview]
Message-ID: <20261110110728.144880-2-m.carrara@proxmox.com> (raw)
In-Reply-To: <20261110110728.144880-1-m.carrara@proxmox.com>
A plain bool doesn't tell callers what `true` and `false` stand for,
and it also can't represent further outcomes of the check, such as the
client closing the connection before the check could complete.
Therefore, return a dedicated enum instead.
Signed-off-by: Max R. Carrara <m.carrara@proxmox.com>
---
proxmox-rest-server/src/connection.rs | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/proxmox-rest-server/src/connection.rs b/proxmox-rest-server/src/connection.rs
index 153a44b0..3062c4f7 100644
--- a/proxmox-rest-server/src/connection.rs
+++ b/proxmox-rest-server/src/connection.rs
@@ -297,10 +297,21 @@ struct AcceptState {
struct AcceptFlags {
is_debug: bool,
}
+/// Outcome of checking whether a client initiates a TLS handshake on a new connection.
+enum TlsHandshakeCheck {
+ /// The client sent the beginning of a TLS handshake.
+ ///
+ /// See [contains_tls_handshake_fragment] for details on how this is
+ /// checked.
+ Initiated,
+ /// The client sent data that does not start a TLS handshake.
+ NotInitiated,
+}
+
impl AcceptBuilder {
async fn accept_connections(
self,
listener: TcpListener,
acceptor: Arc<Mutex<SslAcceptor>>,
@@ -464,14 +475,14 @@ impl AcceptBuilder {
let handshake_res =
Self::wait_for_client_tls_handshake(socket_ref, CLIENT_HANDSHAKE_TIMEOUT).await;
match handshake_res {
- Ok(true) => {
+ Ok(TlsHandshakeCheck::Initiated) => {
Self::do_accept_tls(state, flags, secure_sender).await;
}
- Ok(false) => {
+ Ok(TlsHandshakeCheck::NotInitiated) => {
let insecure_stream = Box::pin(state.socket);
if let Err(send_err) = insecure_sender.send(Ok(insecure_stream)).await {
log::error!(
"[{peer}] failed to accept connection - connection channel closed: {send_err}"
@@ -485,11 +496,11 @@ impl AcceptBuilder {
}
async fn wait_for_client_tls_handshake(
incoming_stream: &TcpStream,
timeout: Duration,
- ) -> Result<bool, Error> {
+ ) -> Result<TlsHandshakeCheck, Error> {
const HANDSHAKE_BYTES_LEN: usize = 5;
let future = async {
let mut previous_peek_len = 0;
incoming_stream
@@ -525,11 +536,17 @@ impl AcceptBuilder {
previous_peek_len = peek_len;
Err(io::ErrorKind::WouldBlock.into())
}
}
// Either we got Ok(HANDSHAKE_BYTES_LEN) or some error.
- res => res.map(|_| contains_tls_handshake_fragment(&buf)),
+ res => res.map(|_| {
+ if contains_tls_handshake_fragment(&buf) {
+ TlsHandshakeCheck::Initiated
+ } else {
+ TlsHandshakeCheck::NotInitiated
+ }
+ }),
}
})
.await
.context("couldn't peek into incoming TCP stream")
};
--
2.47.3
next prev parent reply other threads:[~2026-11-10 11:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 11:07 [PATCH proxmox v3 0/5] Fix #6738: Improve TLS Handshake Handling & Error Logging Max R. Carrara
2026-11-10 11:07 ` Max R. Carrara [this message]
2026-11-10 11:07 ` [PATCH proxmox v3 2/5] rest-server: connection: add tests for TLS handshake check Max R. Carrara
2026-11-10 11:07 ` [PATCH proxmox v3 3/5] rest-server: connection: log cause of TLS handshake check errors Max R. Carrara
2026-11-10 11:07 ` [PATCH proxmox v3 4/5] rest-server: connection: avoid dropping clients during TLS check Max R. Carrara
2026-11-10 11:07 ` [PATCH proxmox v3 5/5] fix #6738: rest-server: log early closed connections at debug level Max R. Carrara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261110110728.144880-2-m.carrara@proxmox.com \
--to=m.carrara@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox