From 0ca9bc9dadfec778fb8b343d5777f518876bb190 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Tue, 6 Mar 2018 18:07:34 +0100 Subject: [PATCH] added error in case openssl is missing --- examples/libev.cpp | 5 +++-- src/linux_tcp/openssl.h | 12 +++++++++--- src/linux_tcp/sslhandshake.h | 2 +- src/linux_tcp/tcpresolver.h | 9 +++++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/examples/libev.cpp b/examples/libev.cpp index 43cad39..4d909f6 100644 --- a/examples/libev.cpp +++ b/examples/libev.cpp @@ -4,7 +4,7 @@ * Test program to check AMQP functionality based on LibEV * * @author Emiel Bruijntjes - * @copyright 2015 - 2017 Copernica BV + * @copyright 2015 - 2018 Copernica BV */ /** @@ -13,6 +13,7 @@ #include #include #include +#include /** * Custom handler @@ -65,7 +66,7 @@ int main() MyHandler handler(loop); // init the SSL library - SSL_library_init(); +// SSL_library_init(); // make a connection AMQP::Address address("amqps://guest:guest@localhost/"); diff --git a/src/linux_tcp/openssl.h b/src/linux_tcp/openssl.h index f30359c..9a21dc9 100644 --- a/src/linux_tcp/openssl.h +++ b/src/linux_tcp/openssl.h @@ -22,10 +22,16 @@ /** * Begin of namespace */ -namespace Copernica { namespace OpenSSL { - +namespace AMQP { namespace OpenSSL { + /** - * List of all methods that we need + * Function to check if openssl is loaded + * @return bool + */ +bool valid(); + +/** + * List of all wrapper methods that are in use inside AMQP-CPP */ SSL_CTX *SSL_CTX_new(const SSL_METHOD *method); SSL *SSL_new(SSL_CTX *ctx); diff --git a/src/linux_tcp/sslhandshake.h b/src/linux_tcp/sslhandshake.h index b5e3870..fb8af3b 100644 --- a/src/linux_tcp/sslhandshake.h +++ b/src/linux_tcp/sslhandshake.h @@ -158,7 +158,7 @@ public: if (fd != _socket) return this; // start the ssl handshake - int result = SSL_do_handshake(_ssl); + int result = OpenSSL::SSL_do_handshake(_ssl); // if the connection succeeds, we can move to the ssl-connected state if (result == 1) return nextstate(new SslConnected(_connection, _socket, _ssl, std::move(_out), _handler)); diff --git a/src/linux_tcp/tcpresolver.h b/src/linux_tcp/tcpresolver.h index 7b194d2..be45c4f 100644 --- a/src/linux_tcp/tcpresolver.h +++ b/src/linux_tcp/tcpresolver.h @@ -20,7 +20,8 @@ #include "tcpstate.h" #include "tcpclosed.h" #include "tcpconnected.h" -//#include "sslhandshake.h" +#include "openssl.h" +#include "sslhandshake.h" #include /** @@ -91,6 +92,9 @@ private: // prevent exceptions try { + // check if we support openssl in the first place + if (!OpenSSL::valid()) throw std::runtime_error("Secure connection cannot be established: the application has no access to openssl"); + // get address info AddressInfo addresses(_hostname.data(), _port); @@ -190,7 +194,8 @@ public: if (_socket >= 0) { // if we need a secure connection, we move to the tls handshake - //if (_secure) return new SslHandshake(_connection, _socket, _hostname, std::move(_buffer), _handler); + // @todo catch exception + if (_secure) return new SslHandshake(_connection, _socket, _hostname, std::move(_buffer), _handler); // otherwise we have a valid regular tcp connection return new TcpConnected(_connection, _socket, std::move(_buffer), _handler);