mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-19 11:19:36 +00:00
Tidy the Mbed TLS verify callback after the per-session change
Remove the now-unused forward declaration and the null checks that can no longer fire, since create_session() always sets the session and its context before installing the callback, and shorten the comments. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGAYpQgXt95LdDQcJYgjB8
This commit is contained in:
1 file changed
+8
-16
@@ -20423,25 +20423,18 @@ inline void mbedtls_clear_cn_mismatch(uint32_t *flags) {
|
|||||||
*flags &= ~static_cast<uint32_t>(hostname_mismatch_code());
|
*flags &= ~static_cast<uint32_t>(hostname_mismatch_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int mbedtls_verify_callback(void *data, mbedtls_x509_crt *crt,
|
|
||||||
int cert_depth, uint32_t *flags);
|
|
||||||
|
|
||||||
// MbedTLS verify callback wrapper
|
// MbedTLS verify callback wrapper
|
||||||
inline int mbedtls_verify_callback(void *data, mbedtls_x509_crt *crt,
|
inline int mbedtls_verify_callback(void *data, mbedtls_x509_crt *crt,
|
||||||
int cert_depth, uint32_t *flags) {
|
int cert_depth, uint32_t *flags) {
|
||||||
// data points to the MbedTlsSession
|
// data points to the MbedTlsSession
|
||||||
auto *session = static_cast<MbedTlsSession *>(data);
|
auto *session = static_cast<MbedTlsSession *>(data);
|
||||||
|
|
||||||
// set_sni() disabled hostname verification for this session: drop the
|
// set_sni() disabled hostname verification for this session: ignore the
|
||||||
// CN/SAN mismatch flag so it doesn't fail the chain check below, mirroring
|
// CN/SAN mismatch flag, as the OpenSSL/wolfSSL backends do. The final
|
||||||
// the OpenSSL/wolfSSL backends where identity checking is independent of
|
// pass/fail decision still comes from the remaining flags (or, below, from
|
||||||
// SNI. The final pass/fail decision still comes from the remaining flags
|
// the user's own verify callback).
|
||||||
// (or, below, from the user's own verify callback).
|
if (session->suppress_hostname_mismatch) { mbedtls_clear_cn_mismatch(flags); }
|
||||||
if (session && session->suppress_hostname_mismatch) {
|
|
||||||
mbedtls_clear_cn_mismatch(flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!session || !session->ctx) { return 0; }
|
|
||||||
const auto &callback = session->ctx->verify_callback;
|
const auto &callback = session->ctx->verify_callback;
|
||||||
if (!callback) { return 0; } // Continue with default verification
|
if (!callback) { return 0; } // Continue with default verification
|
||||||
|
|
||||||
@@ -20858,9 +20851,9 @@ inline session_t create_session(ctx_t ctx, socket_t sock) {
|
|||||||
mbedtls_ssl_set_bio(&session->ssl, &session->sock, impl::mbedtls_net_send_cb,
|
mbedtls_ssl_set_bio(&session->ssl, &session->sock, impl::mbedtls_net_send_cb,
|
||||||
impl::mbedtls_net_recv_cb, nullptr);
|
impl::mbedtls_net_recv_cb, nullptr);
|
||||||
|
|
||||||
// Set the per-session verify callback. It looks up the context's user
|
// Always install the verify callback: it reads the context's user callback
|
||||||
// callback, if any, when the handshake runs, so it does not matter whether
|
// when the handshake runs, so the order of set_verify_callback() and this
|
||||||
// set_verify_callback() is called before or after this session is created.
|
// call does not matter.
|
||||||
session->ctx = mctx;
|
session->ctx = mctx;
|
||||||
mbedtls_ssl_set_verify(&session->ssl, impl::mbedtls_verify_callback, session);
|
mbedtls_ssl_set_verify(&session->ssl, impl::mbedtls_verify_callback, session);
|
||||||
|
|
||||||
@@ -20888,7 +20881,6 @@ inline bool set_sni(session_t session, const char *hostname,
|
|||||||
|
|
||||||
msession->hostname = hostname;
|
msession->hostname = hostname;
|
||||||
|
|
||||||
// mbedtls_verify_callback() masks the mismatch flag for this session
|
|
||||||
if (!verify_hostname) { msession->suppress_hostname_mismatch = true; }
|
if (!verify_hostname) { msession->suppress_hostname_mismatch = true; }
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in new issue
Block a user