Browse Source

SecureSocket:

* SSLdata_ is no longer destroyed and created in closeSocket().
* Adjusted handling of SSL context and method in initSSL() to prevent memory leaks.
* The above changes prevent a bug where SSL certificates were lost after closeSocket() was called.
release/0.19 v0.15
JustinAJ 10 years ago
parent
commit
de74e2fb57
  1. 21
      Jupiter/SecureSocket.cpp
  2. BIN
      Release/Jupiter.lib

21
Jupiter/SecureSocket.cpp

@ -91,8 +91,13 @@ void Jupiter::SecureSocket::closeSocket()
if (Jupiter::SecureSocket::SSLdata_ != nullptr) if (Jupiter::SecureSocket::SSLdata_ != nullptr)
{ {
Jupiter::Socket::closeSocket(); Jupiter::Socket::closeSocket();
delete Jupiter::SecureSocket::SSLdata_; if (Jupiter::SecureSocket::SSLdata_->handle != nullptr)
Jupiter::SecureSocket::SSLdata_ = new Jupiter::SecureSocket::SSLData(); {
if (SSL_shutdown(Jupiter::SecureSocket::SSLdata_->handle) == 0)
SSL_shutdown(Jupiter::SecureSocket::SSLdata_->handle);
SSL_free(Jupiter::SecureSocket::SSLdata_->handle);
Jupiter::SecureSocket::SSLdata_->handle = nullptr;
}
} }
} }
@ -194,8 +199,16 @@ bool Jupiter::SecureSocket::initSSL()
{ {
SSL_load_error_strings(); SSL_load_error_strings();
SSL_library_init(); SSL_library_init();
if (Jupiter::SecureSocket::SSLdata_->context == nullptr)
{
if (Jupiter::SecureSocket::SSLdata_->method == nullptr)
{
Jupiter::SecureSocket::SSLdata_->method = translateEncryptionMethod(Jupiter::SecureSocket::SSLdata_->eMethod); Jupiter::SecureSocket::SSLdata_->method = translateEncryptionMethod(Jupiter::SecureSocket::SSLdata_->eMethod);
if (Jupiter::SecureSocket::SSLdata_->method == nullptr) return false; if (Jupiter::SecureSocket::SSLdata_->method == nullptr)
return false;
}
Jupiter::SecureSocket::SSLdata_->context = SSL_CTX_new(Jupiter::SecureSocket::SSLdata_->method); Jupiter::SecureSocket::SSLdata_->context = SSL_CTX_new(Jupiter::SecureSocket::SSLdata_->method);
if (Jupiter::SecureSocket::SSLdata_->context == nullptr) if (Jupiter::SecureSocket::SSLdata_->context == nullptr)
{ {
@ -204,6 +217,8 @@ bool Jupiter::SecureSocket::initSSL()
} }
if (Jupiter::SecureSocket::SSLdata_->cert.isNotEmpty()) if (Jupiter::SecureSocket::SSLdata_->cert.isNotEmpty())
loadCertificate(Jupiter::SecureSocket::SSLdata_->context, Jupiter::SecureSocket::SSLdata_->cert.c_str(), Jupiter::SecureSocket::SSLdata_->key.c_str()); loadCertificate(Jupiter::SecureSocket::SSLdata_->context, Jupiter::SecureSocket::SSLdata_->cert.c_str(), Jupiter::SecureSocket::SSLdata_->key.c_str());
}
Jupiter::SecureSocket::SSLdata_->handle = SSL_new(Jupiter::SecureSocket::SSLdata_->context); Jupiter::SecureSocket::SSLdata_->handle = SSL_new(Jupiter::SecureSocket::SSLdata_->context);
if (Jupiter::SecureSocket::SSLdata_->handle == nullptr) if (Jupiter::SecureSocket::SSLdata_->handle == nullptr)
{ {

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save