From 5a94e3a473ba9132536d4159a1d4e03b2ff72910 Mon Sep 17 00:00:00 2001 From: Jackarain Date: Tue, 30 Jul 2024 22:38:40 +0800 Subject: [PATCH] Remove unused alpn callback --- proxy/include/proxy/proxy_server.hpp | 73 ++-------------------------- 1 file changed, 4 insertions(+), 69 deletions(-) diff --git a/proxy/include/proxy/proxy_server.hpp b/proxy/include/proxy/proxy_server.hpp index e664acb85f..dc916fcf7b 100644 --- a/proxy/include/proxy/proxy_server.hpp +++ b/proxy/include/proxy/proxy_server.hpp @@ -1122,6 +1122,10 @@ R"x*x*x( } else if (detect[0] == 0x16) // http/socks proxy with ssl crypto protocol. { + XLOG_DBG << "connection id: " + << m_connection_id + << ", ssl protocol"; + auto& srv_ssl_context = server->ssl_context(); // instantiate socks stream with ssl context. @@ -1132,15 +1136,6 @@ R"x*x*x( ssl_stream& ssl_socket = boost::variant2::get(ssl_socks_stream); - // set this to SSL* ex data. - auto ex_index = SSL_get_ex_new_index(0, nullptr, nullptr, nullptr, nullptr); - SSL_set_ex_data(ssl_socket.native_handle(), ex_index, (void*)this); - - XLOG_DBG << "connection id: " - << m_connection_id - << ", ssl protocol, ex index: " - << ex_index; - // do async ssl handshake. co_await ssl_socket.async_handshake( net::ssl::stream_base::server, @@ -4542,62 +4537,6 @@ R"x*x*x( return result; } - static int alpn_select_callback(SSL* ssl, const unsigned char** out, unsigned char* outlen, - const unsigned char* in, unsigned int inlen, void* arg) - { - proxy_server* self = (proxy_server*)arg; - return self->alpn_callback(ssl, out, outlen, in, inlen); - } - - int alpn_callback(SSL* ssl, const unsigned char** out, unsigned char* outlen, - const unsigned char* in, unsigned int inlen) - { - static int ex_index = 1; - proxy_session* self = (proxy_session*)SSL_get_ex_data(ssl, ex_index); - if (!self) - { - for (int i = 1; i <= (ex_index << 1); i++) - { - self = (proxy_session*)SSL_get_ex_data(ssl, ex_index + i); - if (self) - break; - self = (proxy_session*)SSL_get_ex_data(ssl, ex_index - i); - if (self) - break; - } - } - - ex_index++; - - auto connection_id = self->connection_id(); - - const unsigned char* client_proto = in; - unsigned int client_proto_len = 0; - - std::string protocols; - - while (inlen > 0) - { - client_proto_len = *client_proto; - client_proto++; // Skip the length byte - - if (!protocols.empty()) - protocols += ", "; - protocols += std::string((const char*)client_proto, client_proto_len); - - inlen -= client_proto_len + 1; - client_proto += client_proto_len; - } - - XLOG_DBG << "connection id: " << connection_id << ", Client ALPN: " << protocols; - - const unsigned char* alpn = (const unsigned char*)"\x08http/1.1"; - *out = alpn + 1; // Skip the length byte - *outlen = alpn[0]; - - return 0; - } - inline void find_cert(const fs::path& directory) { if (!fs::exists(directory) || !fs::is_directory(directory)) @@ -4729,10 +4668,6 @@ R"x*x*x( ); } - // 设置 ssl context 的 ALPN 协议. - SSL_CTX_set_alpn_select_cb(ssl_ctx.native_handle(), - proxy_server::alpn_select_callback, (void*)this); - // 保存到 m_certificates 中. m_certificates.emplace_back(std::move(file)); }