c++ boost socket proxy-server add SSL
I'm using http proxy-sever with boost libs. Like:
WebBrowser <-> Socket-ProxyServer <-> http Server. It's work fine. But I have a SSL-certificate and it's need to add then to my Proxy-server. My code is:
proxy-server.cpp:
server::server(const ios_deque& io_services, int port, std::string interface_address, int num)
: io_services_(io_services),
endpoint_(interface_address.empty()?
(ba::ip::tcp::endpoint(ba::ip::tcp::v4(), port)):
ba::ip::tcp::endpoint(ba::ip::address().from_string(interface_address), port) ),
acceptor_(*io_services.front(), endpoint_)
{
start_accept(num);
}
void server::start_accept(int num) {
io_services_.push_back(io_services_.front());
io_services_.pop_front();
connection::pointer new_connection = connection::create(*io_services_.front());
acceptor_.async_accept(new_connection->socket(),
boost::bind(&server::handle_accept, this, new_connection,
ba::placeholders::error, num));
}
void server::handle_accept(connection::pointer new_connection, const bs::error_code& error, int num) {
if (!error) {
new_connection->start(GlobalSett.CheckIp(inet_addr(new_connection->socket().remote_endpoint().address().to_string().c_str())), num);
start_accept(num);
}
}
proxy-server.hpp:
typedef std::deque<io_service_ptr> ios_deque;
class server {
public:
server(const ios_deque& io_services, int port, std::string interface_address, int);
private:
void start_accept(int);
void handle_accept(connection::pointer new_connection, const bs::error_code& error, int);
ios_deque io_services_;
const ba::ip::tcp::endpoint endpoint_;
ba::ip::tcp::acceptor acceptor_;
function FUNC;
};
and start server:
try {
int thread_num = atoi(GlobalSett.GetSetConfig("PROXY_THREAD[" + std::to_string(num) + "]")), port = atoi(GlobalSett.GetSetConfig("PROXY_LISTNER_PORT["+std::to_string(num)+"]"));
std::string interface_address = GlobalSett.GetSetConfig("PROXY_LISTNER_IP["+ std::to_string(num)+"]");
ios_deque io_services;
std::deque<ba::io_service::work> io_service_work;
boost::thread_group thr_grp;
for (int i = 0; i < thread_num; ++i) {
io_service_ptr ios(new ba::io_service);
io_services.push_back(ios);
io_service_work.push_back(ba::io_service::work(*ios));
thr_grp.create_thread(boost::bind(&ba::io_service::run, ios));
}
server server(io_services, port, interface_address, num);
thr_grp.join_all();
}
catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
It's need to add ssl to server socket. Any one can help with this? Thanks!
c++ sockets boost
add a comment |
I'm using http proxy-sever with boost libs. Like:
WebBrowser <-> Socket-ProxyServer <-> http Server. It's work fine. But I have a SSL-certificate and it's need to add then to my Proxy-server. My code is:
proxy-server.cpp:
server::server(const ios_deque& io_services, int port, std::string interface_address, int num)
: io_services_(io_services),
endpoint_(interface_address.empty()?
(ba::ip::tcp::endpoint(ba::ip::tcp::v4(), port)):
ba::ip::tcp::endpoint(ba::ip::address().from_string(interface_address), port) ),
acceptor_(*io_services.front(), endpoint_)
{
start_accept(num);
}
void server::start_accept(int num) {
io_services_.push_back(io_services_.front());
io_services_.pop_front();
connection::pointer new_connection = connection::create(*io_services_.front());
acceptor_.async_accept(new_connection->socket(),
boost::bind(&server::handle_accept, this, new_connection,
ba::placeholders::error, num));
}
void server::handle_accept(connection::pointer new_connection, const bs::error_code& error, int num) {
if (!error) {
new_connection->start(GlobalSett.CheckIp(inet_addr(new_connection->socket().remote_endpoint().address().to_string().c_str())), num);
start_accept(num);
}
}
proxy-server.hpp:
typedef std::deque<io_service_ptr> ios_deque;
class server {
public:
server(const ios_deque& io_services, int port, std::string interface_address, int);
private:
void start_accept(int);
void handle_accept(connection::pointer new_connection, const bs::error_code& error, int);
ios_deque io_services_;
const ba::ip::tcp::endpoint endpoint_;
ba::ip::tcp::acceptor acceptor_;
function FUNC;
};
and start server:
try {
int thread_num = atoi(GlobalSett.GetSetConfig("PROXY_THREAD[" + std::to_string(num) + "]")), port = atoi(GlobalSett.GetSetConfig("PROXY_LISTNER_PORT["+std::to_string(num)+"]"));
std::string interface_address = GlobalSett.GetSetConfig("PROXY_LISTNER_IP["+ std::to_string(num)+"]");
ios_deque io_services;
std::deque<ba::io_service::work> io_service_work;
boost::thread_group thr_grp;
for (int i = 0; i < thread_num; ++i) {
io_service_ptr ios(new ba::io_service);
io_services.push_back(ios);
io_service_work.push_back(ba::io_service::work(*ios));
thr_grp.create_thread(boost::bind(&ba::io_service::run, ios));
}
server server(io_services, port, interface_address, num);
thr_grp.join_all();
}
catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
It's need to add ssl to server socket. Any one can help with this? Thanks!
c++ sockets boost
add a comment |
I'm using http proxy-sever with boost libs. Like:
WebBrowser <-> Socket-ProxyServer <-> http Server. It's work fine. But I have a SSL-certificate and it's need to add then to my Proxy-server. My code is:
proxy-server.cpp:
server::server(const ios_deque& io_services, int port, std::string interface_address, int num)
: io_services_(io_services),
endpoint_(interface_address.empty()?
(ba::ip::tcp::endpoint(ba::ip::tcp::v4(), port)):
ba::ip::tcp::endpoint(ba::ip::address().from_string(interface_address), port) ),
acceptor_(*io_services.front(), endpoint_)
{
start_accept(num);
}
void server::start_accept(int num) {
io_services_.push_back(io_services_.front());
io_services_.pop_front();
connection::pointer new_connection = connection::create(*io_services_.front());
acceptor_.async_accept(new_connection->socket(),
boost::bind(&server::handle_accept, this, new_connection,
ba::placeholders::error, num));
}
void server::handle_accept(connection::pointer new_connection, const bs::error_code& error, int num) {
if (!error) {
new_connection->start(GlobalSett.CheckIp(inet_addr(new_connection->socket().remote_endpoint().address().to_string().c_str())), num);
start_accept(num);
}
}
proxy-server.hpp:
typedef std::deque<io_service_ptr> ios_deque;
class server {
public:
server(const ios_deque& io_services, int port, std::string interface_address, int);
private:
void start_accept(int);
void handle_accept(connection::pointer new_connection, const bs::error_code& error, int);
ios_deque io_services_;
const ba::ip::tcp::endpoint endpoint_;
ba::ip::tcp::acceptor acceptor_;
function FUNC;
};
and start server:
try {
int thread_num = atoi(GlobalSett.GetSetConfig("PROXY_THREAD[" + std::to_string(num) + "]")), port = atoi(GlobalSett.GetSetConfig("PROXY_LISTNER_PORT["+std::to_string(num)+"]"));
std::string interface_address = GlobalSett.GetSetConfig("PROXY_LISTNER_IP["+ std::to_string(num)+"]");
ios_deque io_services;
std::deque<ba::io_service::work> io_service_work;
boost::thread_group thr_grp;
for (int i = 0; i < thread_num; ++i) {
io_service_ptr ios(new ba::io_service);
io_services.push_back(ios);
io_service_work.push_back(ba::io_service::work(*ios));
thr_grp.create_thread(boost::bind(&ba::io_service::run, ios));
}
server server(io_services, port, interface_address, num);
thr_grp.join_all();
}
catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
It's need to add ssl to server socket. Any one can help with this? Thanks!
c++ sockets boost
I'm using http proxy-sever with boost libs. Like:
WebBrowser <-> Socket-ProxyServer <-> http Server. It's work fine. But I have a SSL-certificate and it's need to add then to my Proxy-server. My code is:
proxy-server.cpp:
server::server(const ios_deque& io_services, int port, std::string interface_address, int num)
: io_services_(io_services),
endpoint_(interface_address.empty()?
(ba::ip::tcp::endpoint(ba::ip::tcp::v4(), port)):
ba::ip::tcp::endpoint(ba::ip::address().from_string(interface_address), port) ),
acceptor_(*io_services.front(), endpoint_)
{
start_accept(num);
}
void server::start_accept(int num) {
io_services_.push_back(io_services_.front());
io_services_.pop_front();
connection::pointer new_connection = connection::create(*io_services_.front());
acceptor_.async_accept(new_connection->socket(),
boost::bind(&server::handle_accept, this, new_connection,
ba::placeholders::error, num));
}
void server::handle_accept(connection::pointer new_connection, const bs::error_code& error, int num) {
if (!error) {
new_connection->start(GlobalSett.CheckIp(inet_addr(new_connection->socket().remote_endpoint().address().to_string().c_str())), num);
start_accept(num);
}
}
proxy-server.hpp:
typedef std::deque<io_service_ptr> ios_deque;
class server {
public:
server(const ios_deque& io_services, int port, std::string interface_address, int);
private:
void start_accept(int);
void handle_accept(connection::pointer new_connection, const bs::error_code& error, int);
ios_deque io_services_;
const ba::ip::tcp::endpoint endpoint_;
ba::ip::tcp::acceptor acceptor_;
function FUNC;
};
and start server:
try {
int thread_num = atoi(GlobalSett.GetSetConfig("PROXY_THREAD[" + std::to_string(num) + "]")), port = atoi(GlobalSett.GetSetConfig("PROXY_LISTNER_PORT["+std::to_string(num)+"]"));
std::string interface_address = GlobalSett.GetSetConfig("PROXY_LISTNER_IP["+ std::to_string(num)+"]");
ios_deque io_services;
std::deque<ba::io_service::work> io_service_work;
boost::thread_group thr_grp;
for (int i = 0; i < thread_num; ++i) {
io_service_ptr ios(new ba::io_service);
io_services.push_back(ios);
io_service_work.push_back(ba::io_service::work(*ios));
thr_grp.create_thread(boost::bind(&ba::io_service::run, ios));
}
server server(io_services, port, interface_address, num);
thr_grp.join_all();
}
catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
It's need to add ssl to server socket. Any one can help with this? Thanks!
c++ sockets boost
c++ sockets boost
asked Nov 13 '18 at 19:46
user1786639user1786639
4410
4410
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You need to use boost::asio::ssl:stream. Have a look at boost asio SSL examples: https://www.boost.org/doc/libs/1_68_0/doc/html/boost_asio/example/cpp03/ssl/server.cpp
If you need SSL functionality not exposed in boost::asio::ssl::stream you can always use native_handle():
boost::asio::ssl::stream<asio:ip::tcp::socket> sock(io_context, ctx);
...
SSL_use_certificate(sock.native_handle(), x509_certificate);
...
thanks for answer! may be you can help with rewrite my code?...
– user1786639
Nov 15 '18 at 9:42
Please read the help pages, take the SO tour, read about how to ask good questions. We can help you with specific questions, but not write your code. It's also nice to upvote answers if you found them useful.
– sergiopm
Nov 15 '18 at 12:12
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288441%2fc-boost-socket-proxy-server-add-ssl%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to use boost::asio::ssl:stream. Have a look at boost asio SSL examples: https://www.boost.org/doc/libs/1_68_0/doc/html/boost_asio/example/cpp03/ssl/server.cpp
If you need SSL functionality not exposed in boost::asio::ssl::stream you can always use native_handle():
boost::asio::ssl::stream<asio:ip::tcp::socket> sock(io_context, ctx);
...
SSL_use_certificate(sock.native_handle(), x509_certificate);
...
thanks for answer! may be you can help with rewrite my code?...
– user1786639
Nov 15 '18 at 9:42
Please read the help pages, take the SO tour, read about how to ask good questions. We can help you with specific questions, but not write your code. It's also nice to upvote answers if you found them useful.
– sergiopm
Nov 15 '18 at 12:12
add a comment |
You need to use boost::asio::ssl:stream. Have a look at boost asio SSL examples: https://www.boost.org/doc/libs/1_68_0/doc/html/boost_asio/example/cpp03/ssl/server.cpp
If you need SSL functionality not exposed in boost::asio::ssl::stream you can always use native_handle():
boost::asio::ssl::stream<asio:ip::tcp::socket> sock(io_context, ctx);
...
SSL_use_certificate(sock.native_handle(), x509_certificate);
...
thanks for answer! may be you can help with rewrite my code?...
– user1786639
Nov 15 '18 at 9:42
Please read the help pages, take the SO tour, read about how to ask good questions. We can help you with specific questions, but not write your code. It's also nice to upvote answers if you found them useful.
– sergiopm
Nov 15 '18 at 12:12
add a comment |
You need to use boost::asio::ssl:stream. Have a look at boost asio SSL examples: https://www.boost.org/doc/libs/1_68_0/doc/html/boost_asio/example/cpp03/ssl/server.cpp
If you need SSL functionality not exposed in boost::asio::ssl::stream you can always use native_handle():
boost::asio::ssl::stream<asio:ip::tcp::socket> sock(io_context, ctx);
...
SSL_use_certificate(sock.native_handle(), x509_certificate);
...
You need to use boost::asio::ssl:stream. Have a look at boost asio SSL examples: https://www.boost.org/doc/libs/1_68_0/doc/html/boost_asio/example/cpp03/ssl/server.cpp
If you need SSL functionality not exposed in boost::asio::ssl::stream you can always use native_handle():
boost::asio::ssl::stream<asio:ip::tcp::socket> sock(io_context, ctx);
...
SSL_use_certificate(sock.native_handle(), x509_certificate);
...
answered Nov 14 '18 at 10:57
sergiopmsergiopm
1514
1514
thanks for answer! may be you can help with rewrite my code?...
– user1786639
Nov 15 '18 at 9:42
Please read the help pages, take the SO tour, read about how to ask good questions. We can help you with specific questions, but not write your code. It's also nice to upvote answers if you found them useful.
– sergiopm
Nov 15 '18 at 12:12
add a comment |
thanks for answer! may be you can help with rewrite my code?...
– user1786639
Nov 15 '18 at 9:42
Please read the help pages, take the SO tour, read about how to ask good questions. We can help you with specific questions, but not write your code. It's also nice to upvote answers if you found them useful.
– sergiopm
Nov 15 '18 at 12:12
thanks for answer! may be you can help with rewrite my code?...
– user1786639
Nov 15 '18 at 9:42
thanks for answer! may be you can help with rewrite my code?...
– user1786639
Nov 15 '18 at 9:42
Please read the help pages, take the SO tour, read about how to ask good questions. We can help you with specific questions, but not write your code. It's also nice to upvote answers if you found them useful.
– sergiopm
Nov 15 '18 at 12:12
Please read the help pages, take the SO tour, read about how to ask good questions. We can help you with specific questions, but not write your code. It's also nice to upvote answers if you found them useful.
– sergiopm
Nov 15 '18 at 12:12
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288441%2fc-boost-socket-proxy-server-add-ssl%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown