fix bug when trying to enable ssl and not suceeding. now we handle it gracefully instead of failing and randomly crashing

This commit is contained in:
ps 2011-09-29 19:48:21 +00:00
parent 25b8d879d9
commit dd51b74c90
2 changed files with 13 additions and 5 deletions

View File

@ -216,17 +216,19 @@ void Proxy::run(string &peer_address)
#ifdef HAVE_SSL
try
{
LINF("STARTTLS issued by remote, TLS enabled");
outside.writeLine("220 You can speak now, line is secure!!");
outside.enableSSL(true);
LINF("STARTTLS issued by remote, TLS enabled");
outside.writeLine("220 You can speak now, line is secure!!");
}
catch(Exception &e)
{
LINF("STARTTLS issued by remote, but enableSSL failed!");
LERR(e);
outside.writeLine("454 Tried to enable SSL but failed");
}
#else
outside.writeLine("454 TLS temporarily not available");
LINF("STARTTLS issued by remote, TLS was not enabled because this build lacks SSL support");
LINF("STARTTLS issued by remote, TLS was not enabled because this build lacks SSL support");
#endif //HAVE_SSL
strtemp="";
}

View File

@ -159,6 +159,8 @@ Socket::~Socket()
*/
void Socket::enableSSL(bool server)
{
int retval;
if(server)
ssl=SSL_new(ssl_ctx_server);
else
@ -172,9 +174,13 @@ void Socket::enableSSL(bool server)
throw Exception(_("Error creating ssl structure"),__FILE__,__LINE__);
if(server)
SSL_accept(ssl);
retval=SSL_accept(ssl);
else
SSL_connect(ssl);
retval=SSL_connect(ssl);
//SSL_accept and SSL_connect have the same semantics so we handle them together
if(1!=retval)
throw Exception(_("Error enabling SSL on the socket"),__FILE__,__LINE__);
}
#endif //HAVE_SSL