Berserker | 5 Sep 16:11
Favicon

Asio and SSL problem

I tried to post this problem in the asio mailing list but I hadn't any feedback, so I'm reporting it here with
the hope that someone can help me.

I have a "stack overflow" problem with the following code (using boost 1.36):

void test_handshake(const std::string &host, const std::string &cert)
{
   boost::asio::io_service service;

   boost::asio::ssl::context sslContext(service, boost::asio::ssl::context::sslv23);
   sslContext.set_verify_mode(boost::asio::ssl::context::verify_peer);
   sslContext.load_verify_file(cert);

   boost::asio::ip::tcp::resolver resolver(service);

boost::asio::ip::tcp::resolver::iterator endpoint_iterator =
resolver.resolve(boost::asio::ip::tcp::resolver::query(host, "443"));
   boost::asio::ip::tcp::resolver::iterator end;

   boost::asio::ssl::stream<boost::asio::ip::tcp::socket> sslSocket(service, sslContext);    

   boost::system::error_code error = boost::asio::error::host_not_found;
   while(error && endpoint_iterator != end)
   {
      sslSocket.next_layer().close();
      sslSocket.next_layer().connect(*endpoint_iterator++, error);
   }

   if(error)
      throw boost::system::system_error(error);    
(Continue reading)

Carlo Medas | 5 Sep 17:01

Re: Asio and SSL problem

Hi,
we've been using asio with SSL, but with async mode; it's working perfectly
both in successful and failure cases.

I see one major difference in your code:
 * when you close and connect again, we use 'lowest_layer()' where you use
'next_layer()'
 * stupid one (you never know...): are you catching exceptions on the
caller? :)

Best regards,

Carlo Medas

On Fri, Sep 5, 2008 at 4:14 PM, Berserker <berserker_r <at> hotmail.com> wrote:

> I tried to post this problem in the asio mailing list but I hadn't any
> feedback, so I'm reporting it here with the hope that someone can help me.
>
> I have a "stack overflow" problem with the following code (using boost
> 1.36):
>
> void test_handshake(const std::string &host, const std::string &cert)
> {
>   boost::asio::io_service service;
>
>   boost::asio::ssl::context sslContext(service,
> boost::asio::ssl::context::sslv23);
>   sslContext.set_verify_mode(boost::asio::ssl::context::verify_peer);
>   sslContext.load_verify_file(cert);
(Continue reading)

Berserker | 5 Sep 17:45
Favicon

Re: Asio and SSL problem

Thanks for the reply Carlo :)

>  * when you close and connect again, we use 'lowest_layer()' where you use
> 'next_layer()'

stream::lowest_layer() is only a wrapper around "next_layer_.lowest_layer()" where, in case of a
"basic_socket" as template argument, is:

lowest_layer_type& basic_socket::lowest_layer()
{
  return *this;
}

So there is no difference with:

next_layer_type& stream::next_layer()
{
  return next_layer_;
}

>  * stupid one (you never know...): are you catching exceptions on the
> caller? :)

Sure but I don't think that a stack overflow is a "catchable exception" don't you think :) ?

_________________________________________________________________
Cerchi un locale per la serata? Chiedilo a Live Maps!
http://maps.live.it/
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
(Continue reading)

Carlo Medas | 5 Sep 19:24

Re: Asio and SSL problem

Dear Berserker,
I was afraid that by uncatching the exceptions in the caller, moreover if in
a multithreaded application, you're going to have for sure an abort, if not
some other side effect in the worst case... (I told you that it was the
stupid one, if you're not a newbie!).

Btw, with boost 1.35.0 and 1.36.0, same stuff but with async methods works
more than perfectly, both if you use client auth or not.

Ciao,

Carlo Medas

On Fri, Sep 5, 2008 at 5:47 PM, Berserker <berserker_r <at> hotmail.com> wrote:

> Thanks for the reply Carlo :)
>
> >  * when you close and connect again, we use 'lowest_layer()' where you
> use
> > 'next_layer()'
>
> stream::lowest_layer() is only a wrapper around
> "next_layer_.lowest_layer()" where, in case of a "basic_socket" as template
> argument, is:
>
> lowest_layer_type& basic_socket::lowest_layer()
> {
>  return *this;
> }
>
(Continue reading)


Gmane