Hi
I'm trying to hack cpp-netlib to implement a https server. I have used the ssl server example from boost 1.46.1 which is working okay, but when I (think) I do the same thing in cpp-net lib I got this segmentation fault:
#0 0x00007ffff7bbda57 in SSL_accept () from /usr/lib64/libssl.so.1.0.0
#1 0x00000000004c1702 in boost::network::http::sync_connection<boost::network::http::tags::http_server, handler>::socket (this=0x4d58ca)
at /home/awn/git/buildroot5/git/gmbinit/test/cpp-netlib-0.9.2/boost/network/protocol/http/server/sync_connection.hpp:50
#2 0x00000000004d4e67 in boost::detail::function::function_invoker1<int (*)(SSL*), int, SSL*>::invoke (function_ptr=..., a0=0x731820) at /usr/include/boost-1_46/boost/function/function_template.hpp:95
#3 0x00000000004d0fd6 in boost::function1<int, SSL*>::operator() (this=0x73b490, a0=0x731820) at /usr/include/boost-1_46/boost/function/function_template.hpp:1013
#4 0x00000000004cde2f in boost::asio::ssl::detail::openssl_operation<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> > >::start (this=0x73b490)
at /usr/include/boost-1_46/boost/asio/ssl/detail/openssl_operation.hpp:149
#5 0x00000000004df1b3 in boost::_mfi::mf0<int, boost::asio::ssl::detail::openssl_operation<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> > > >::operator() (
this=0x7fffffffc500, p=0x73b490) at /usr/include/boost-1_46/boost/bind/mem_fn_template.hpp:49
#6 0x00000000004dd693 in boost::_bi::list1<boost::_bi::value<boost::asio::ssl::detail::openssl_operation<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> > >*> >::operator()<int, boost::_mfi::mf0<int, boost::asio::ssl::detail::openssl_operation<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> > > >, boost::_bi::list0> (this=0x7fffffffc510, f=...,
a=...) at /usr/include/boost-1_46/boost/bind/bind.hpp:243
#7 0x00000000004db687 in boost::_bi::bind_t<int, boost::_mfi::mf0<int, boost::asio::ssl::detail::openssl_operation<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> > > >, boost::_bi::list1<boost::_bi::value<boost::asio::ssl::detail::openssl_operation<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> > >*> > >::operator() (this=0x7fffffffc500)
at /usr/include/boost-1_46/boost/bind/bind_template.hpp:20
#8 0x00000000004d980e in boost::asio::asio_handler_invoke<boost::_bi::bind_t<int, boost::_mfi::mf0<int, boost::asio::ssl::detail::openssl_operation<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> > > >, boost::_bi::list1<boost::_bi::value<boost::asio::ssl::detail::openssl_operation<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> > >*> > > > (
function=...) at /usr/include/boost-1_46/boost/asio/handler_invoke_hook.hpp:64
#9 0x00000000004d7b22 in boost_asio_handler_invoke_helpers::invoke<boost::_bi::bind_t<int, boost::_mfi::mf0<int, boost::asio::ssl::detail::openssl_operation<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> > > >, boost::_bi::list1<boost::_bi::value<boost::asio::ssl::detail::openssl_operation<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> > >*> > >, boost::_bi::bind_t<int, boost::_mfi::mf0<int, boost::asio::ssl::detail::openssl_operation<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> > > >, boost::_bi::list1<boost::_bi::value<boost::asio::ssl::detail::openssl_operation<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> > >*> > > > (function=..., context=...)
at /usr/include/boost-1_46/boost/asio/detail/handler_invoke_helpers.hpp:39
#10 0x00000000004d5990 in boost::asio::detail::completion_handler<boost::_bi::bind_t<int, boost::_mfi::mf0<int, boost::asio::ssl::detail::openssl_operation<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> > > >, boost::_bi::list1<boost::_bi::value<boost::asio::ssl::detail::openssl_operation<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> > >*> > > >::do_complete (owner=0x734c60, base=0x72fb80) at /usr/include/boost-1_46/boost/asio/detail/completion_handler.hpp:63
#11 0x00000000004ae40b in boost::asio::detail::task_io_service_operation::complete (this=0x72fb80, owner=...) at /usr/include/boost-1_46/boost/asio/detail/task_io_service_operation.hpp:35
#12 0x00000000004b3fb2 in boost::asio::detail::strand_service::do_complete (owner=0x734c60, base=0x7308e0) at /usr/include/boost-1_46/boost/asio/detail/impl/strand_service.ipp:98
#13 0x00000000004ae40b in boost::asio::detail::task_io_service_operation::complete (this=0x7308e0, owner=...) at /usr/include/boost-1_46/boost/asio/detail/task_io_service_operation.hpp:35
#14 0x00000000004b0449 in boost::asio::detail::task_io_service::do_one (this=0x734c60, lock=..., this_idle_thread=0x7fffffffc790) at /usr/include/boost-1_46/boost/asio/detail/impl/task_io_service.ipp:278
#15 0x00000000004aff97 in boost::asio::detail::task_io_service::run (this=0x734c60, ec=...) at /usr/include/boost-1_46/boost/asio/detail/impl/task_io_service.ipp:130
#16 0x00000000004b0841 in boost::asio::io_service::run (this=0x7fffffffc980) at /usr/include/boost-1_46/boost/asio/impl/io_service.ipp:57
#17 0x00000000004ac04b in main (arg=1, argv=0x7fffffffcb18) at /home/awn/git/buildroot5/git/gmbinit/test/serverTest.cxx:51
As the problem is in SSL_accept () i expect there is something wrong with my SSL context which I create like this:
boost::asio::ssl::context context_(io_service, boost::asio::ssl::context::sslv23);
context_.set_verify_mode(boost::asio::ssl::context::verify_none);
context_.use_certificate_chain_file("/etc/ssl/gamblify/gamblify.cert");
context_.use_private_key_file("/etc/ssl/gamblify/gamblify.pem", boost::asio::ssl::context::pem);
The context is created in my main function, and then passed around as a reference.
The type of my socket is:
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> socket_;
I create it like this:
socket_(service_, context)
Accept is using the lowest layer which I return like this
boost::asio::ssl::stream<boost::asio::ip::tcp::socket>::lowest_layer_type& socket()
{
return socket_.lowest_layer();
}
I call async_accept like this:
new_connection.reset(new sync_connection<Tag,Handler>(service_, handler_, context_));
acceptor_.async_accept(new_connection->socket(),
boost::bind(&sync_server_base<Tag,Handler>::handle_accept,
this, boost::asio::placeholders::error));
The handler looks like this:
void handle_accept(boost::system::error_code const & ec) {
if (!ec) {
new_connection->start();
new_connection.reset(new sync_connection<Tag,Handler>(service_, handler_, context_));
acceptor_.async_accept(new_connection->socket(),
boost::bind(&sync_server_base<Tag,Handler>::handle_accept,
this, boost::asio::placeholders::error));
}
}
Eventually the accept handler and it is running start which looks like this:
void start()
{
std::cerr << "Running start" << std::endl;
socket_.async_handshake(boost::asio::ssl::stream_base::server,
boost::bind(&sync_connection<Tag,Handler>::handle_handshake, this,
boost::asio::placeholders::error));
}
Then at some point before I reach the handle_handshake I get an segmentation fault...
Can any body see any problems with this, or just give some hints on how to debug this kind of bugs...
--
Allan W. Nielsen