2 Commits
Author SHA1 Message Date
vladislav.khorev bcb714ee04 Update TLS options 2018-08-25 14:20:53 +03:00
Ubuntu ca5d2cb32f update boost for linux 2018-08-25 11:19:32 +00:00
3 changed files with 115 additions and 44 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_63_0 BOOST_PATH=/home/ubuntu/work/boost_1_67_0
#====================================================== #======================================================
#====================== BOOST ========================= #====================== BOOST =========================
#====================================================== #======================================================
+107 -36
View File
@@ -9,12 +9,10 @@
#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
@@ -80,13 +78,17 @@ 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(boost::asio::ip::tcp::socket inSocket, boost::asio::io_service& inIoService) ProxySession(std::shared_ptr<ssl_socket> socket, boost::asio::io_service& inIoService)
: ioService(inIoService) : ioService(inIoService)
, mSocket(std::move(inSocket)) , mSocket(socket)
, outsideConnectSocket(ioService) , outsideConnectSocket(ioService)
{ {
std::cout << "ProxySession Create" << std::endl; std::cout << "ProxySession Create" << std::endl;
@@ -100,18 +102,61 @@ public:
void start() void start()
{ {
std::cout << "ProxySession::start" << std::endl; std::cout << "ProxySession::start" << std::endl;
//asyncHandshake(); asyncHandshake();
readClientVersion(); //readClientVersion();
} }
private: private:
boost::asio::ip::tcp::socket& socket() ssl_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;
@@ -139,14 +184,14 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
socket().close(); lowerSocket().close();
} }
} }
else else
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
socket().close(); lowerSocket().close();
} }
}); });
} }
@@ -174,7 +219,7 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
socket().close(); lowerSocket().close();
} }
}); });
} }
@@ -202,7 +247,7 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
socket().close(); lowerSocket().close();
} }
}); });
@@ -243,14 +288,14 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
socket().close(); lowerSocket().close();
} }
} }
else else
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
socket().close(); lowerSocket().close();
} }
}); });
@@ -277,7 +322,7 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
socket().close(); lowerSocket().close();
} }
}); });
} }
@@ -317,14 +362,14 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
socket().close(); lowerSocket().close();
} }
} }
else else
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
socket().close(); lowerSocket().close();
} }
}); });
@@ -366,7 +411,7 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
socket().close(); lowerSocket().close();
} }
}); });
@@ -410,7 +455,7 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
socket().close(); lowerSocket().close();
} }
}); });
@@ -432,7 +477,7 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
socket().close(); lowerSocket().close();
outsideConnectSocket.close(); outsideConnectSocket.close();
} }
}); });
@@ -453,7 +498,7 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
socket().close(); lowerSocket().close();
outsideConnectSocket.close(); outsideConnectSocket.close();
} }
}); });
@@ -491,7 +536,7 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
socket().close(); lowerSocket().close();
outsideConnectSocket.close(); outsideConnectSocket.close();
} }
}); });
@@ -532,7 +577,7 @@ private:
{ {
std::string msg = ec.message(); std::string msg = ec.message();
std::cout << msg << std::endl; std::cout << msg << std::endl;
socket().close(); lowerSocket().close();
outsideConnectSocket.close(); outsideConnectSocket.close();
} }
}); });
@@ -576,7 +621,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();
socket().close(); lowerSocket().close();
} }
}); });
} }
@@ -594,7 +639,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();
socket().close(); lowerSocket().close();
} }
}); });
} }
@@ -629,7 +674,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();
socket().close(); lowerSocket().close();
} }
}); });
} }
@@ -647,14 +692,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();
socket().close(); lowerSocket().close();
} }
}); });
} }
boost::asio::io_service& ioService; boost::asio::io_service& ioService;
boost::asio::ip::tcp::socket mSocket; std::shared_ptr<ssl_socket> mSocket;
boost::asio::ip::tcp::socket outsideConnectSocket; boost::asio::ip::tcp::socket outsideConnectSocket;
@@ -669,10 +714,12 @@ 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(inIoService) , socket(std::make_shared<ssl_socket>(inIoService, inSslContext))
, sslContext(inSslContext)
{ {
doAccept(); doAccept();
} }
@@ -680,17 +727,17 @@ public:
private: private:
void doAccept() void doAccept()
{ {
acceptor.async_accept(socket, acceptor.async_accept(socket->lowest_layer(),
[this](boost::system::error_code ec) [this](boost::system::error_code ec)
{ {
if (!ec) if (!ec)
{ {
std::make_shared<ProxySession>(std::move(socket), ioService)->start(); std::make_shared<ProxySession>(socket, ioService)->start();
} }
counter++; counter++;
socket = boost::asio::ip::tcp::socket(ioService); socket = std::make_shared<ssl_socket>(ioService, sslContext);
doAccept(); doAccept();
}); });
@@ -699,7 +746,11 @@ private:
boost::asio::io_service& ioService; boost::asio::io_service& ioService;
boost::asio::ip::tcp::acceptor acceptor; boost::asio::ip::tcp::acceptor acceptor;
boost::asio::ip::tcp::socket socket; std::shared_ptr<ssl_socket> socket;
boost::asio::ssl::context& sslContext;
//std::map<size_t, ProxySession> proxySessionMap;
size_t counter = 0; size_t counter = 0;
}; };
@@ -715,9 +766,29 @@ 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); ProxyServer proxyServer(ioService, endpoint, sslContext);
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</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0.17134.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>v143</PlatformToolset> <PlatformToolset>v141</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>v143</PlatformToolset> <PlatformToolset>v141</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>v143</PlatformToolset> <PlatformToolset>v141</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>v143</PlatformToolset> <PlatformToolset>v141</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_80_0</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>../boost_1_67_0;../../openssl-master;../../openssl-master/include;../../openssl-master/output/include</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>C:\Work\Projects\boost_1_80_0\stage\x64\lib</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>../boost_1_67_0/stage/x64/lib/</AdditionalLibraryDirectories>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">