mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-22 11:46:13 +00:00
Drop the SNI of a failed handshake on the Mbed TLS server
The Mbed TLS server keeps the SNI from the ClientHello in a thread-local until the handshake succeeds, and its SNI callback only runs for a ClientHello that carries one. A handshake that failed left its SNI behind, so the next connection served by the same thread without SNI reported the earlier client's name in req.sni(). Start each handshake with the thread-local cleared.
This commit is contained in:
1 parent
71b5f0a1c8
commit
7a9cee0e05
2 files changed
+44
-2
No files matched your search
@@ -21467,6 +21467,9 @@ inline TlsError connect(session_t session) {
|
||||
}
|
||||
|
||||
inline TlsError accept(session_t session) {
|
||||
// A failed handshake leaves its SNI behind, so start without it
|
||||
impl::mbedpending_sni().clear();
|
||||
|
||||
// Same as connect for Mbed TLS - handshake works for both client and server
|
||||
auto result = connect(session);
|
||||
|
||||
@@ -21474,7 +21477,6 @@ inline TlsError accept(session_t session) {
|
||||
if (result.code == ErrorCode::Success && session) {
|
||||
auto msession = static_cast<impl::MbedTlsSession *>(session);
|
||||
msession->sni_hostname = std::move(impl::mbedpending_sni());
|
||||
impl::mbedpending_sni().clear();
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -21519,6 +21521,9 @@ inline bool connect_nonblocking(session_t session, socket_t sock,
|
||||
inline bool accept_nonblocking(session_t session, socket_t sock,
|
||||
time_t timeout_sec, time_t timeout_usec,
|
||||
TlsError *err) {
|
||||
// A failed handshake leaves its SNI behind, so start without it
|
||||
impl::mbedpending_sni().clear();
|
||||
|
||||
// Same implementation as connect for Mbed TLS
|
||||
bool result =
|
||||
connect_nonblocking(session, sock, timeout_sec, timeout_usec, err);
|
||||
@@ -21527,7 +21532,6 @@ inline bool accept_nonblocking(session_t session, socket_t sock,
|
||||
if (result && session) {
|
||||
auto msession = static_cast<impl::MbedTlsSession *>(session);
|
||||
msession->sni_hostname = std::move(impl::mbedpending_sni());
|
||||
impl::mbedpending_sni().clear();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in new issue
Block a user