2 Commits
Author SHA1 Message Date
Vladislav Khorev d3ce055a25 UpdateProxySettings 2022-10-28 06:05:09 +03:00
vladislav.khorev 330d838ffc Version without SSL 2018-08-24 00:15:23 +03:00
3 changed files with 44 additions and 115 deletions

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@ CC=g++
CFLAGS=-Wall -O3 -fpermissive -std=c++11 -DOPENSSL_NO_SSL2 -DOPENSSL_USE_DEPRECATED CFLAGS=-Wall -O3 -fpermissive -std=c++11 -DOPENSSL_NO_SSL2 -DOPENSSL_USE_DEPRECATED
LDFLAGS= -lpthread -lrt -lssl -lcrypto \ LDFLAGS= -lpthread -lrt -lssl -lcrypto \
-L/home/ubuntu/work/openssl-out/lib -L/home/ubuntu/work/openssl-out/lib
BOOST_PATH=/home/ubuntu/work/boost_1_67_0 BOOST_PATH=/home/ubuntu/work/boost_1_63_0
#====================================================== #======================================================
#====================== BOOST ========================= #====================== BOOST =========================
#====================================================== #======================================================
+36 -107
View File
@@ -9,10 +9,12 @@
#include <boost/thread.hpp> #include <boost/thread.hpp>
#if 0
#define SSL_R_SHORT_READ 219 #define SSL_R_SHORT_READ 219
#include "ssl/ssl_locl.h" #include "ssl/ssl_locl.h"
#include <boost/asio/ssl.hpp> #include <boost/asio/ssl.hpp>
#endif
#if defined(close) #if defined(close)
#undef close #undef close
@@ -78,17 +80,13 @@ std::string ConnectRequestRecord::getRequestData()
typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> ssl_socket;
class ProxySession : class ProxySession :
public std::enable_shared_from_this<ProxySession> public std::enable_shared_from_this<ProxySession>
{ {
public: public:
ProxySession(std::shared_ptr<ssl_socket> socket, boost::asio::io_service& inIoService) ProxySession(boost::asio::ip::tcp::socket inSocket, boost::asio::io_service& inIoService)
: ioService(inIoService) : ioService(inIoService)
, mSocket(socket) , mSocket(std::move(inSocket))
, outsideConnectSocket(ioService) , outsideConnectSocket(ioService)
{ {
std::cout << "ProxySession Create" << std::endl; std::cout << "ProxySession Create" << std::endl;
@@ -102,61 +100,18 @@ public:
void start() void start()
{ {
std::cout << "ProxySession::start" << std::endl; std::cout << "ProxySession::start" << std::endl;
asyncHandshake(); //asyncHandshake();
//readClientVersion(); readClientVersion();
} }
private: private:
ssl_socket& socket() boost::asio::ip::tcp::socket& socket()
{ {
return *mSocket; return mSocket;
} }
ssl_socket::lowest_layer_type& lowerSocket()
{
return mSocket->lowest_layer();
}
void asyncHandshake()
{
std::cout << "ProxySession::asyncHandshake" << std::endl;
auto self(shared_from_this());
socket().async_handshake(boost::asio::ssl::stream_base::server,
[this, self](boost::system::error_code ec) {
std::cout << "ProxySession::asyncHandshake inner" << std::endl;
if (!ec)
{
readClientVersion();
}
else
{
std::string msg = ec.message();
std::cout << msg << std::endl;
lowerSocket().close();
}
});
}
/*
void handleHandshake(const boost::system::error_code& error)
{
if (!error)
{
readClientVersion();
}
else
{
lowerSocket().close();
}
}*/
std::array<unsigned char, 3> clientVersion; std::array<unsigned char, 3> clientVersion;
@@ -184,14 +139,14 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
lowerSocket().close(); socket().close();
} }
} }
else else
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
lowerSocket().close(); socket().close();
} }
}); });
} }
@@ -219,7 +174,7 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
lowerSocket().close(); socket().close();
} }
}); });
} }
@@ -247,7 +202,7 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
lowerSocket().close(); socket().close();
} }
}); });
@@ -288,14 +243,14 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
lowerSocket().close(); socket().close();
} }
} }
else else
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
lowerSocket().close(); socket().close();
} }
}); });
@@ -322,7 +277,7 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
lowerSocket().close(); socket().close();
} }
}); });
} }
@@ -362,14 +317,14 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
lowerSocket().close(); socket().close();
} }
} }
else else
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
lowerSocket().close(); socket().close();
} }
}); });
@@ -411,7 +366,7 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
lowerSocket().close(); socket().close();
} }
}); });
@@ -455,7 +410,7 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
lowerSocket().close(); socket().close();
} }
}); });
@@ -477,7 +432,7 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
lowerSocket().close(); socket().close();
outsideConnectSocket.close(); outsideConnectSocket.close();
} }
}); });
@@ -498,7 +453,7 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
lowerSocket().close(); socket().close();
outsideConnectSocket.close(); outsideConnectSocket.close();
} }
}); });
@@ -536,7 +491,7 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
lowerSocket().close(); socket().close();
outsideConnectSocket.close(); outsideConnectSocket.close();
} }
}); });
@@ -577,7 +532,7 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
lowerSocket().close(); socket().close();
outsideConnectSocket.close(); outsideConnectSocket.close();
} }
}); });
@@ -621,7 +576,7 @@ private:
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
outsideConnectSocket.close(); outsideConnectSocket.close();
lowerSocket().close(); socket().close();
} }
}); });
} }
@@ -639,7 +594,7 @@ private:
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
outsideConnectSocket.close(); outsideConnectSocket.close();
lowerSocket().close(); socket().close();
} }
}); });
} }
@@ -674,7 +629,7 @@ private:
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
outsideConnectSocket.close(); outsideConnectSocket.close();
lowerSocket().close(); socket().close();
} }
}); });
} }
@@ -692,14 +647,14 @@ private:
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
outsideConnectSocket.close(); outsideConnectSocket.close();
lowerSocket().close(); socket().close();
} }
}); });
} }
boost::asio::io_service& ioService; boost::asio::io_service& ioService;
std::shared_ptr<ssl_socket> mSocket; boost::asio::ip::tcp::socket mSocket;
boost::asio::ip::tcp::socket outsideConnectSocket; boost::asio::ip::tcp::socket outsideConnectSocket;
@@ -714,12 +669,10 @@ class ProxyServer
{ {
public: public:
ProxyServer(boost::asio::io_service& inIoService, ProxyServer(boost::asio::io_service& inIoService,
const boost::asio::ip::tcp::endpoint& endpoint, const boost::asio::ip::tcp::endpoint& endpoint)
boost::asio::ssl::context& inSslContext)
: ioService(inIoService) : ioService(inIoService)
, acceptor(inIoService, endpoint) , acceptor(inIoService, endpoint)
, socket(std::make_shared<ssl_socket>(inIoService, inSslContext)) , socket(inIoService)
, sslContext(inSslContext)
{ {
doAccept(); doAccept();
} }
@@ -727,17 +680,17 @@ public:
private: private:
void doAccept() void doAccept()
{ {
acceptor.async_accept(socket->lowest_layer(), acceptor.async_accept(socket,
[this](boost::system::error_code ec) [this](boost::system::error_code ec)
{ {
if (!ec) if (!ec)
{ {
std::make_shared<ProxySession>(socket, ioService)->start(); std::make_shared<ProxySession>(std::move(socket), ioService)->start();
} }
counter++; counter++;
socket = std::make_shared<ssl_socket>(ioService, sslContext); socket = boost::asio::ip::tcp::socket(ioService);
doAccept(); doAccept();
}); });
@@ -746,11 +699,7 @@ private:
boost::asio::io_service& ioService; boost::asio::io_service& ioService;
boost::asio::ip::tcp::acceptor acceptor; boost::asio::ip::tcp::acceptor acceptor;
std::shared_ptr<ssl_socket> socket; boost::asio::ip::tcp::socket socket;
boost::asio::ssl::context& sslContext;
//std::map<size_t, ProxySession> proxySessionMap;
size_t counter = 0; size_t counter = 0;
}; };
@@ -766,29 +715,9 @@ int main()
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), 8043); boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), 8043);
boost::asio::ssl::context sslContext(boost::asio::ssl::context::tls_server);
SSL_CTX_set_cipher_list(sslContext.native_handle(), "EECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS");
sslContext.set_options(boost::asio::ssl::context::default_workarounds
| boost::asio::ssl::context::verify_none
| boost::asio::ssl::context::no_sslv2
| boost::asio::ssl::context::no_sslv3
| boost::asio::ssl::context::no_tlsv1
| boost::asio::ssl::context::single_dh_use
);
std::function<std::string(std::size_t, boost::asio::ssl::context_base::password_purpose)> f = [](std::size_t, boost::asio::ssl::context_base::password_purpose) -> std::string { return ""; };
sslContext.set_password_callback(f);
sslContext.use_certificate_chain_file("server.crt");
sslContext.use_private_key_file("server.key", boost::asio::ssl::context::pem);
sslContext.use_tmp_dh_file("dh2048.pem");
ProxyServer proxyServer(ioService, endpoint, sslContext); ProxyServer proxyServer(ioService, endpoint);
boost::thread_group threadpool; boost::thread_group threadpool;
+7 -7
View File
@@ -21,32 +21,32 @@
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{066072DA-FC40-49C7-A432-FA85F715B0F6}</ProjectGuid> <ProjectGuid>{066072DA-FC40-49C7-A432-FA85F715B0F6}</ProjectGuid>
<RootNamespace>proxyServerTest</RootNamespace> <RootNamespace>proxyServerTest</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
@@ -88,12 +88,12 @@
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>../boost_1_67_0;../../openssl-master;../../openssl-master/include;../../openssl-master/output/include</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>../boost_1_80_0</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>../boost_1_67_0/stage/x64/lib/</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>C:\Work\Projects\boost_1_80_0\stage\x64\lib</AdditionalLibraryDirectories>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">