From 23fed281ea945ff8bda570de1c17073cc2f3ca4c Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Tue, 15 Sep 2020 10:53:57 -0700 Subject: [PATCH 01/32] Cmake changes --- CMakeLists.txt | 19 +++++++++++++++---- cmake/FindBoostAsioGnuTLS.cmake | 14 ++++++++++++++ include/CMakeLists.txt | 14 +++++++++++++- 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 cmake/FindBoostAsioGnuTLS.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 72f2c1a3d..b347c4fe2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ OPTION(MQTT_ALWAYS_SEND_REASON_CODE "Always send a reason code, even if the stan OPTION(MQTT_USE_STATIC_BOOST "Statically link with boost libraries" OFF) OPTION(MQTT_USE_STATIC_OPENSSL "Statically link with openssl libraries" OFF) OPTION(MQTT_USE_TLS "Enable building TLS code" OFF) +OPTION(MQTT_USE_GNU_TLS "Enable the use of GnuTLS instead of OpenSSL" OFF) OPTION(MQTT_USE_WS "Enable building WebSockets code" OFF) OPTION(MQTT_USE_STR_CHECK "Enable UTF8 String check" ON) OPTION(MQTT_USE_LOG "Enable building logging code" OFF) @@ -33,6 +34,12 @@ ELSE () MESSAGE (STATUS "TLS disabled") ENDIF () +IF (MQTT_USE_GNU_TLS) + MESSAGE (STATUS "GNU TLS enabled") +ELSE () + MESSAGE (STATUS "GNU TLS disabled") +ENDIF () + IF (MQTT_USE_WS) MESSAGE (STATUS "WebSocket enabled") ELSE () @@ -130,10 +137,14 @@ ELSE () ENDIF () IF (MQTT_USE_TLS) - FIND_PACKAGE (OpenSSL REQUIRED) - IF (MQTT_USE_STATIC_OPENSSL) - FIND_PACKAGE (ZLIB REQUIRED) - ENDIF () + IF (NOT MQTT_USE_GNU_TLS) + FIND_PACKAGE (OpenSSL REQUIRED) + IF (MQTT_USE_STATIC_OPENSSL) + FIND_PACKAGE (ZLIB REQUIRED) + ENDIF () + ELSE () + find_package(GnuTLS REQUIRED) + find_package(BoostAsioGnuTLS REQUIRED) ENDIF () ADD_SUBDIRECTORY (include) diff --git a/cmake/FindBoostAsioGnuTLS.cmake b/cmake/FindBoostAsioGnuTLS.cmake new file mode 100644 index 000000000..db7eaa9a1 --- /dev/null +++ b/cmake/FindBoostAsioGnuTLS.cmake @@ -0,0 +1,14 @@ +find_path(BoostAsioGnuTLS_INCLUDE_DIR NAMES boost-asio-gnutls/boost/asio/gnutls.hpp) + +mark_as_advanced(BoostAsioGnuTLS_INCLUDE_DIR) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(BoostAsioGnuTLS + REQUIRED_VARS + BoostAsioGnuTLS_INCLUDE_DIR + ) + +if(BoostAsioGnuTLS_FOUND) + set(BoostAsioGnuTLS_INCLUDE_DIRS /usr/local/include/boost-asio-gnutls/ ${BoostAsioGnuTLS_INCLUDE_DIR}) +endif() \ No newline at end of file diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 73f704b6a..66ca9250c 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -16,7 +16,10 @@ IF(MQTT_USE_STATIC_OPENSSL) TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$:${CMAKE_DL_LIBS} ZLIB::ZLIB>) ENDIF() -TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$:OpenSSL::SSL>) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$,$>:OpenSSL::SSL>) + +# TODO: Should this be PRIVATE? +TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$:${GNUTLS_LIBRARIES}) TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} INTERFACE @@ -25,6 +28,15 @@ TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} $ ) +IF(MQTT_USE_GNU_TLS) + TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} + INTERFACE + ${BoostAsioGnuTLS_INCLUDE_DIRS} + PRIVATE + ${GNUTLS_INCLUDE_DIRS} + ) +ENDIF() + TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_TLS>) TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_WS>) TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_STR_CHECK>) From 49561d2c6dd419174dcfec82826f37b753c474b6 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Tue, 15 Sep 2020 10:57:25 -0700 Subject: [PATCH 02/32] ifdef changes in files --- include/mqtt/client.hpp | 7 ++++++- include/mqtt/server.hpp | 7 ++++++- include/mqtt/tcp_endpoint.hpp | 7 ++++++- test/test_ctx_init.hpp | 8 +++++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/include/mqtt/client.hpp b/include/mqtt/client.hpp index d783cb453..e0fcd7f54 100644 --- a/include/mqtt/client.hpp +++ b/include/mqtt/client.hpp @@ -21,7 +21,12 @@ #include #if defined(MQTT_USE_TLS) -#include +#if !defined(MQTT_USE_GNU_TLS) + #include +#else + #include + #include +#endif // !defined(MQTT_USE_TLS) #endif // defined(MQTT_USE_TLS) #include diff --git a/include/mqtt/server.hpp b/include/mqtt/server.hpp index 62cdb37c3..fd1cabaad 100644 --- a/include/mqtt/server.hpp +++ b/include/mqtt/server.hpp @@ -15,7 +15,12 @@ #include #if defined(MQTT_USE_TLS) -#include +#if !defined(MQTT_USE_GNU_TLS) + #include +#else + #include + #include +#endif // !defined(MQTT_USE_TLS) #endif // defined(MQTT_USE_TLS) #include diff --git a/include/mqtt/tcp_endpoint.hpp b/include/mqtt/tcp_endpoint.hpp index 686d831df..ede2ae429 100644 --- a/include/mqtt/tcp_endpoint.hpp +++ b/include/mqtt/tcp_endpoint.hpp @@ -11,7 +11,12 @@ #include #if defined(MQTT_USE_TLS) -#include +#if !defined(MQTT_USE_GNU_TLS) + #include +#else + #include + #include +#endif // !defined(MQTT_USE_TLS) #endif // defined(MQTT_USE_TLS) #include diff --git a/test/test_ctx_init.hpp b/test/test_ctx_init.hpp index be4a3c6c4..a8aac13b1 100644 --- a/test/test_ctx_init.hpp +++ b/test/test_ctx_init.hpp @@ -10,7 +10,13 @@ #if defined(MQTT_USE_TLS) #include -#include + +#if !defined(MQTT_USE_GNU_TLS) + #include +#else + #include + #include +#endif // !defined(MQTT_USE_TLS) #include "test_settings.hpp" From ad9271bbb0a272eec51a032d0dc38ea78b56d02c Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Tue, 15 Sep 2020 11:05:29 -0700 Subject: [PATCH 03/32] Replaced all --- example/tls_both.cpp | 20 +++++-- example/tls_server.cpp | 20 +++++-- example/tls_ws_both.cpp | 20 +++++-- example/tls_ws_server.cpp | 20 +++++-- include/mqtt/client.hpp | 112 ++++++++++++++++++++------------------ include/mqtt/endpoint.hpp | 10 +++- include/mqtt/server.hpp | 44 +++++++++------ test/test_ctx_init.hpp | 20 +++++-- 8 files changed, 169 insertions(+), 97 deletions(-) diff --git a/example/tls_both.cpp b/example/tls_both.cpp index 3e6d6183e..cc87d57be 100644 --- a/example/tls_both.cpp +++ b/example/tls_both.cpp @@ -16,6 +16,16 @@ #include "locked_cout.hpp" +namespace as = boost::asio; + +#if defined(MQTT_USE_TLS) +#if !defined(MQTT_USE_GNU_TLS) + namespace ssl = as::ssl; +#else + namespace ssl = as::gnutls; +#endif // !defined(MQTT_USE_TLS) +#endif // defined(MQTT_USE_TLS) + template void client_proc( Client& c, @@ -340,12 +350,12 @@ int main(int argc, char** argv) { std::uint16_t port = boost::lexical_cast(argv[1]); // server - boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12); + ssl::context ctx(ssl::context::tlsv12); ctx.set_options( - boost::asio::ssl::context::default_workarounds | - boost::asio::ssl::context::single_dh_use); - ctx.use_certificate_file(base + "server.crt.pem", boost::asio::ssl::context::pem); - ctx.use_private_key_file(base + "server.key.pem", boost::asio::ssl::context::pem); + ssl::context::default_workarounds | + ssl::context::single_dh_use); + ctx.use_certificate_file(base + "server.crt.pem", ssl::context::pem); + ctx.use_private_key_file(base + "server.key.pem", ssl::context::pem); boost::asio::io_context iocs; auto s = MQTT_NS::server_tls<>( diff --git a/example/tls_server.cpp b/example/tls_server.cpp index 839a7cc53..d204cbb3a 100644 --- a/example/tls_server.cpp +++ b/example/tls_server.cpp @@ -20,6 +20,16 @@ namespace mi = boost::multi_index; using con_t = MQTT_NS::server_tls<>::endpoint_t; using con_sp_t = std::shared_ptr; +namespace as = boost::asio; + +#if defined(MQTT_USE_TLS) +#if !defined(MQTT_USE_GNU_TLS) + namespace ssl = as::ssl; +#else + namespace ssl = as::gnutls; +#endif // !defined(MQTT_USE_TLS) +#endif // defined(MQTT_USE_TLS) + struct sub_con { sub_con(MQTT_NS::buffer topic, con_sp_t con, MQTT_NS::qos qos_value) :topic(std::move(topic)), con(std::move(con)), qos_value(qos_value) {} @@ -68,12 +78,12 @@ int main(int argc, char** argv) { std::string cert = argv[2]; std::string key = argv[3]; - boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12); + ssl::context ctx(ssl::context::tlsv12); ctx.set_options( - boost::asio::ssl::context::default_workarounds | - boost::asio::ssl::context::single_dh_use); - ctx.use_certificate_file(cert, boost::asio::ssl::context::pem); - ctx.use_private_key_file(key, boost::asio::ssl::context::pem); + ssl::context::default_workarounds | + ssl::context::single_dh_use); + ctx.use_certificate_file(cert, ssl::context::pem); + ctx.use_private_key_file(key, ssl::context::pem); auto s = MQTT_NS::server_tls<>( boost::asio::ip::tcp::endpoint( diff --git a/example/tls_ws_both.cpp b/example/tls_ws_both.cpp index 23e532dc9..63b776730 100644 --- a/example/tls_ws_both.cpp +++ b/example/tls_ws_both.cpp @@ -16,6 +16,16 @@ #include "locked_cout.hpp" +namespace as = boost::asio; + +#if defined(MQTT_USE_TLS) +#if !defined(MQTT_USE_GNU_TLS) + namespace ssl = as::ssl; +#else + namespace ssl = as::gnutls; +#endif // !defined(MQTT_USE_TLS) +#endif // defined(MQTT_USE_TLS) + template void client_proc( Client& c, @@ -339,12 +349,12 @@ int main(int argc, char** argv) { std::uint16_t port = boost::lexical_cast(argv[1]); // server - boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12); + ssl::context ctx(ssl::context::tlsv12); ctx.set_options( - boost::asio::ssl::context::default_workarounds | - boost::asio::ssl::context::single_dh_use); - ctx.use_certificate_file(base + "server.crt.pem", boost::asio::ssl::context::pem); - ctx.use_private_key_file(base + "server.key.pem", boost::asio::ssl::context::pem); + ssl::context::default_workarounds | + ssl::context::single_dh_use); + ctx.use_certificate_file(base + "server.crt.pem", ssl::context::pem); + ctx.use_private_key_file(base + "server.key.pem", ssl::context::pem); boost::asio::io_context iocs; auto s = MQTT_NS::server_tls_ws<>( diff --git a/example/tls_ws_server.cpp b/example/tls_ws_server.cpp index 272ba4e5f..7b84b1425 100644 --- a/example/tls_ws_server.cpp +++ b/example/tls_ws_server.cpp @@ -20,6 +20,16 @@ namespace mi = boost::multi_index; using con_t = MQTT_NS::server_tls_ws<>::endpoint_t; using con_sp_t = std::shared_ptr; +namespace as = boost::asio; + +#if defined(MQTT_USE_TLS) +#if !defined(MQTT_USE_GNU_TLS) + namespace ssl = as::ssl; +#else + namespace ssl = as::gnutls; +#endif // !defined(MQTT_USE_TLS) +#endif // defined(MQTT_USE_TLS) + struct sub_con { sub_con(MQTT_NS::buffer topic, con_sp_t con, MQTT_NS::qos qos_value) :topic(std::move(topic)), con(std::move(con)), qos_value(qos_value) {} @@ -68,12 +78,12 @@ int main(int argc, char** argv) { std::string cert = argv[2]; std::string key = argv[3]; - boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12); + ssl::context ctx(ssl::context::tlsv12); ctx.set_options( - boost::asio::ssl::context::default_workarounds | - boost::asio::ssl::context::single_dh_use); - ctx.use_certificate_file(cert, boost::asio::ssl::context::pem); - ctx.use_private_key_file(key, boost::asio::ssl::context::pem); + ssl::context::default_workarounds | + ssl::context::single_dh_use); + ctx.use_certificate_file(cert, ssl::context::pem); + ctx.use_private_key_file(key, ssl::context::pem); auto s = MQTT_NS::server_tls_ws<>( boost::asio::ip::tcp::endpoint( diff --git a/include/mqtt/client.hpp b/include/mqtt/client.hpp index e0fcd7f54..b5458f314 100644 --- a/include/mqtt/client.hpp +++ b/include/mqtt/client.hpp @@ -47,6 +47,14 @@ namespace MQTT_NS { namespace as = boost::asio; namespace mi = boost::multi_index; +#if defined(MQTT_USE_TLS) +#if !defined(MQTT_USE_GNU_TLS) + namespace ssl = as::ssl; +#else + namespace ssl = as::gnutls; +#endif // !defined(MQTT_USE_TLS) +#endif // defined(MQTT_USE_TLS) + template class client : public endpoint { using this_type = client; @@ -117,7 +125,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -127,7 +135,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -140,7 +148,7 @@ class client : public endpoint { * @return client object. * strand is controlled by ws_endpoint, not endpoint, so client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -151,7 +159,7 @@ class client : public endpoint { * @param path path string * @return client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -209,7 +217,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -219,7 +227,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -232,7 +240,7 @@ class client : public endpoint { * @return client object. * strand is controlled by ws_endpoint, not endpoint, so client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -243,7 +251,7 @@ class client : public endpoint { * @param path path string * @return client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -340,7 +348,7 @@ class client : public endpoint { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context& get_ssl_context() { + ssl::context& get_ssl_context() { static_assert(has_tls>::value, "Client is required to support TLS."); return ctx_; } @@ -349,7 +357,7 @@ class client : public endpoint { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context const& get_ssl_context() const { + ssl::context const& get_ssl_context() const { static_assert(has_tls>::value, "Client is required to support TLS."); return ctx_; } @@ -1022,7 +1030,7 @@ class client : public endpoint { tim_session_expiry_(ioc_) { #if defined(MQTT_USE_TLS) - ctx_.set_verify_mode(as::ssl::verify_peer); + ctx_.set_verify_mode(ssl::verify_peer); #endif // defined(MQTT_USE_TLS) } @@ -1043,14 +1051,14 @@ class client : public endpoint { #if defined(MQTT_USE_TLS) template - void setup_socket(std::shared_ptr, Strand>>& socket) { + void setup_socket(std::shared_ptr, Strand>>& socket) { socket = std::make_shared(ioc_, ctx_); base::socket_optional().emplace(socket); } #if defined(MQTT_USE_WS) template - void setup_socket(std::shared_ptr, Strand>>& socket) { + void setup_socket(std::shared_ptr, Strand>>& socket) { socket = std::make_shared(ioc_, ctx_); base::socket_optional().emplace(socket); } @@ -1137,20 +1145,20 @@ class client : public endpoint { template void handshake_socket( - tcp_endpoint, Strand>& socket, + tcp_endpoint, Strand>& socket, v5::properties props, any session_life_keeper) { - socket.handshake(as::ssl::stream_base::client); + socket.handshake(ssl::stream_base::client); start_session(force_move(props), force_move(session_life_keeper)); } template void handshake_socket( - tcp_endpoint, Strand>& socket, + tcp_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, boost::system::error_code& ec) { - socket.handshake(as::ssl::stream_base::client, ec); + socket.handshake(ssl::stream_base::client, ec); if (ec) return; start_session(force_move(props), force_move(session_life_keeper)); } @@ -1159,21 +1167,21 @@ class client : public endpoint { template void handshake_socket( - ws_endpoint, Strand>& socket, + ws_endpoint, Strand>& socket, v5::properties props, any session_life_keeper) { - socket.next_layer().handshake(as::ssl::stream_base::client); + socket.next_layer().handshake(ssl::stream_base::client); socket.handshake(host_, path_); start_session(force_move(props), force_move(session_life_keeper)); } template void handshake_socket( - ws_endpoint, Strand>& socket, + ws_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, boost::system::error_code& ec) { - socket.next_layer().handshake(as::ssl::stream_base::client, ec); + socket.next_layer().handshake(ssl::stream_base::client, ec); if (ec) return; socket.handshake(host_, path_, ec); if (ec) return; @@ -1224,12 +1232,12 @@ class client : public endpoint { template void async_handshake_socket( - tcp_endpoint, Strand>& socket, + tcp_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, async_handler_t func) { socket.async_handshake( - as::ssl::stream_base::client, + ssl::stream_base::client, [ this, self = this->shared_from_this(), @@ -1249,12 +1257,12 @@ class client : public endpoint { #if defined(MQTT_USE_WS) template void async_handshake_socket( - ws_endpoint, Strand>& socket, + ws_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, async_handler_t func) { socket.next_layer().async_handshake( - as::ssl::stream_base::client, + ssl::stream_base::client, [ this, self = this->shared_from_this(), @@ -1499,12 +1507,12 @@ class client : public endpoint { }; template - struct has_tls, U>>> : std::true_type { + struct has_tls, U>>> : std::true_type { }; #if defined(MQTT_USE_WS) template - struct has_tls, U>>> : std::true_type { + struct has_tls, U>>> : std::true_type { }; #endif // defined(MQTT_USE_WS) @@ -1524,7 +1532,7 @@ class client : public endpoint { optional password_; bool async_pingreq_ = false; #if defined(MQTT_USE_TLS) - as::ssl::context ctx_{as::ssl::context::tlsv12}; + ssl::context ctx_{ssl::context::tlsv12}; #endif // defined(MQTT_USE_TLS) #if defined(MQTT_USE_WS) std::string path_; @@ -1637,9 +1645,9 @@ make_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t po #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>>; + using client_t = client, as::io_context::strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1652,7 +1660,7 @@ make_tls_client(as::io_context& ioc, std::string host, std::string port, protoco ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client( ioc, @@ -1662,9 +1670,9 @@ make_tls_client(as::io_context& ioc, std::string host, std::uint16_t port, proto ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>>; + using client_t = client, null_strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1677,7 +1685,7 @@ make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string por ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand( ioc, @@ -1689,9 +1697,9 @@ make_tls_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t p #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>>; + using client_t = client, as::io_context::strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1702,7 +1710,7 @@ make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std: ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_ws( ioc, @@ -1713,9 +1721,9 @@ make_tls_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, st ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>>; + using client_t = client, null_strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1726,7 +1734,7 @@ make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_ws( ioc, @@ -1848,9 +1856,9 @@ make_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>, 4>; + using client_t = client, as::io_context::strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1863,7 +1871,7 @@ make_tls_client_32(as::io_context& ioc, std::string host, std::string port, prot ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_32( ioc, @@ -1873,9 +1881,9 @@ make_tls_client_32(as::io_context& ioc, std::string host, std::uint16_t port, pr ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>, 4>; + using client_t = client, null_strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1888,7 +1896,7 @@ make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_32( ioc, @@ -1900,9 +1908,9 @@ make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_ #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>, 4>; + using client_t = client, as::io_context::strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1913,7 +1921,7 @@ make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, s ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_ws_32( ioc, @@ -1924,9 +1932,9 @@ make_tls_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>, 4>; + using client_t = client, null_strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1937,7 +1945,7 @@ make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::stri ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/endpoint.hpp b/include/mqtt/endpoint.hpp index 108185416..556e4c0f3 100644 --- a/include/mqtt/endpoint.hpp +++ b/include/mqtt/endpoint.hpp @@ -153,6 +153,14 @@ constexpr bool should_generate_packet_id(Params const& ... params) { namespace as = boost::asio; namespace mi = boost::multi_index; +#if defined(MQTT_USE_TLS) +#if !defined(MQTT_USE_GNU_TLS) + namespace ssl = as::ssl; +#else + namespace ssl = as::gnutls; +#endif // !defined(MQTT_USE_TLS) +#endif // defined(MQTT_USE_TLS) + template class LockGuard = std::lock_guard, std::size_t PacketIdBytes = 2> class endpoint : public std::enable_shared_from_this> { using this_type = endpoint; @@ -4541,7 +4549,7 @@ class endpoint : public std::enable_shared_from_this class LockGuard, std::size_t PacketIdBytes> class server_endpoint : public endpoint { public: @@ -217,7 +225,7 @@ template < > class server_tls { public: - using socket_t = tcp_endpoint, Strand>; + using socket_t = tcp_endpoint, Strand>; using endpoint_t = callable_overlay>; /** @@ -235,7 +243,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - as::ssl::context&& ctx, + ssl::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con, AcceptorConfig&& config) @@ -251,7 +259,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - as::ssl::context&& ctx, + ssl::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con) : server_tls(std::forward(ep), force_move(ctx), ioc_accept, ioc_con, [](as::ip::tcp::acceptor&) {}) {} @@ -259,7 +267,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - as::ssl::context&& ctx, + ssl::context&& ctx, as::io_context& ioc, AcceptorConfig&& config) : server_tls(std::forward(ep), force_move(ctx), ioc, ioc, std::forward(config)) {} @@ -267,7 +275,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - as::ssl::context&& ctx, + ssl::context&& ctx, as::io_context& ioc) : server_tls(std::forward(ep), force_move(ctx), ioc, ioc, [](as::ip::tcp::acceptor&) {}) {} @@ -354,7 +362,7 @@ class server_tls { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context& get_ssl_context() { + ssl::context& get_ssl_context() { return ctx_; } @@ -362,7 +370,7 @@ class server_tls { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context const& get_ssl_context() const { + ssl::context const& get_ssl_context() const { return ctx_; } @@ -398,7 +406,7 @@ class server_tls { ); auto ps = socket.get(); ps->async_handshake( - as::ssl::stream_base::server, + ssl::stream_base::server, [this, socket = force_move(socket), tim, underlying_finished] (error_code ec) mutable { *underlying_finished = true; @@ -424,7 +432,7 @@ class server_tls { bool close_request_{false}; accept_handler h_accept_; error_handler h_error_; - as::ssl::context ctx_; + ssl::context ctx_; protocol_version version_ = protocol_version::undetermined; std::chrono::steady_clock::duration underlying_connect_timeout_ = std::chrono::seconds(10); }; @@ -706,7 +714,7 @@ template < > class server_tls_ws { public: - using socket_t = ws_endpoint, Strand>; + using socket_t = ws_endpoint, Strand>; using endpoint_t = callable_overlay>; /** @@ -724,7 +732,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - as::ssl::context&& ctx, + ssl::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con, AcceptorConfig&& config) @@ -740,7 +748,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - as::ssl::context&& ctx, + ssl::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con) : server_tls_ws(std::forward(ep), force_move(ctx), ioc_accept, ioc_con, [](as::ip::tcp::acceptor&) {}) {} @@ -748,7 +756,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - as::ssl::context&& ctx, + ssl::context&& ctx, as::io_context& ioc, AcceptorConfig&& config) : server_tls_ws(std::forward(ep), force_move(ctx), ioc, ioc, std::forward(config)) {} @@ -756,7 +764,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - as::ssl::context&& ctx, + ssl::context&& ctx, as::io_context& ioc) : server_tls_ws(std::forward(ep), force_move(ctx), ioc, ioc, [](as::ip::tcp::acceptor&) {}) {} @@ -843,7 +851,7 @@ class server_tls_ws { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context& get_ssl_context() { + ssl::context& get_ssl_context() { return ctx_; } @@ -851,7 +859,7 @@ class server_tls_ws { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context const& get_ssl_context() const { + ssl::context const& get_ssl_context() const { return ctx_; } @@ -888,7 +896,7 @@ class server_tls_ws { auto ps = socket.get(); ps->next_layer().async_handshake( - as::ssl::stream_base::server, + ssl::stream_base::server, [this, socket = force_move(socket), tim, underlying_finished] (error_code ec) mutable { if (ec) { @@ -992,7 +1000,7 @@ class server_tls_ws { bool close_request_{false}; accept_handler h_accept_; error_handler h_error_; - as::ssl::context ctx_; + ssl::context ctx_; protocol_version version_ = protocol_version::undetermined; std::chrono::steady_clock::duration underlying_connect_timeout_ = std::chrono::seconds(10); }; diff --git a/test/test_ctx_init.hpp b/test/test_ctx_init.hpp index a8aac13b1..7e4d76156 100644 --- a/test/test_ctx_init.hpp +++ b/test/test_ctx_init.hpp @@ -20,18 +20,26 @@ #include "test_settings.hpp" +#if defined(MQTT_USE_TLS) +#if !defined(MQTT_USE_GNU_TLS) + namespace ssl = as::ssl; +#else + namespace ssl = as::gnutls; +#endif // !defined(MQTT_USE_TLS) +#endif // defined(MQTT_USE_TLS) + struct ctx_init { - ctx_init() : ctx(boost::asio::ssl::context::tlsv12) { + ctx_init() : ctx(ssl::context::tlsv12) { ctx.set_options( - boost::asio::ssl::context::default_workarounds | - boost::asio::ssl::context::single_dh_use); + ssl::context::default_workarounds | + ssl::context::single_dh_use); std::string path = boost::unit_test::framework::master_test_suite().argv[0]; std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - ctx.use_certificate_file(base + "server.crt.pem", boost::asio::ssl::context::pem); - ctx.use_private_key_file(base + "server.key.pem", boost::asio::ssl::context::pem); + ctx.use_certificate_file(base + "server.crt.pem", ssl::context::pem); + ctx.use_private_key_file(base + "server.key.pem", ssl::context::pem); } - boost::asio::ssl::context ctx; + ssl::context ctx; }; #endif // defined(MQTT_USE_TLS) From 7444c042b4ca0bd050cc1dc092eb5def0b728cdb Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Tue, 15 Sep 2020 14:13:17 -0700 Subject: [PATCH 04/32] Cmake fixes --- CMakeLists.txt | 3 +++ include/CMakeLists.txt | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b347c4fe2..484d44033 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,8 @@ IF (POLICY CMP0074) CMAKE_POLICY(SET CMP0074 NEW) ENDIF () +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake ${CMAKE_MODULE_PATH}) + IF (MQTT_USE_TLS) MESSAGE (STATUS "TLS enabled") ELSE () @@ -145,6 +147,7 @@ IF (MQTT_USE_TLS) ELSE () find_package(GnuTLS REQUIRED) find_package(BoostAsioGnuTLS REQUIRED) + ENDIF () ENDIF () ADD_SUBDIRECTORY (include) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 66ca9250c..1f73fafb1 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -16,10 +16,10 @@ IF(MQTT_USE_STATIC_OPENSSL) TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$:${CMAKE_DL_LIBS} ZLIB::ZLIB>) ENDIF() -TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$,$>:OpenSSL::SSL>) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$,$>>:OpenSSL::SSL>) # TODO: Should this be PRIVATE? -TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$:${GNUTLS_LIBRARIES}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$:${GNUTLS_LIBRARIES}>) TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} INTERFACE @@ -32,7 +32,6 @@ IF(MQTT_USE_GNU_TLS) TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} INTERFACE ${BoostAsioGnuTLS_INCLUDE_DIRS} - PRIVATE ${GNUTLS_INCLUDE_DIRS} ) ENDIF() From 9d94ec51468c7e32da6ec702e5d37bfc893dd077 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Wed, 16 Sep 2020 12:26:24 -0700 Subject: [PATCH 05/32] Final working changes --- include/CMakeLists.txt | 1 + include/mqtt/async_client.hpp | 64 +++++++++++++++++------------------ include/mqtt/endpoint.hpp | 3 ++ include/mqtt/sync_client.hpp | 64 +++++++++++++++++------------------ test/underlying_timeout.cpp | 20 +++++------ 5 files changed, 78 insertions(+), 74 deletions(-) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 1f73fafb1..1683d3da5 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -37,6 +37,7 @@ IF(MQTT_USE_GNU_TLS) ENDIF() TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_TLS>) +TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_GNU_TLS>) TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_WS>) TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_STR_CHECK>) TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_LOG>) diff --git a/include/mqtt/async_client.hpp b/include/mqtt/async_client.hpp index 210e63a56..0a32819b6 100644 --- a/include/mqtt/async_client.hpp +++ b/include/mqtt/async_client.hpp @@ -82,7 +82,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_async_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -92,7 +92,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -105,7 +105,7 @@ class async_client : public client { * @return async_client object. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -116,7 +116,7 @@ class async_client : public client { * @param path path string * @return async_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -174,7 +174,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -184,7 +184,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -197,7 +197,7 @@ class async_client : public client { * @return async_client object. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -208,7 +208,7 @@ class async_client : public client { * @param path path string * @return async_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -374,9 +374,9 @@ make_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint1 #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>>; + using async_client_t = async_client, as::io_context::strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -389,7 +389,7 @@ make_tls_async_client(as::io_context& ioc, std::string host, std::string port, p ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client( ioc, @@ -399,9 +399,9 @@ make_tls_async_client(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>>; + using async_client_t = async_client, null_strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -414,7 +414,7 @@ make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::stri ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand( ioc, @@ -426,9 +426,9 @@ make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::uint #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>>; + using async_client_t = async_client, as::io_context::strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -439,7 +439,7 @@ make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_ws( ioc, @@ -450,9 +450,9 @@ make_tls_async_client_ws(as::io_context& ioc, std::string host, std::uint16_t po ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>>; + using async_client_t = async_client, null_strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -463,7 +463,7 @@ make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::s ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_ws( ioc, @@ -585,9 +585,9 @@ make_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::ui #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>, 4>; + using async_client_t = async_client, as::io_context::strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -600,7 +600,7 @@ make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_32( ioc, @@ -610,9 +610,9 @@ make_tls_async_client_32(as::io_context& ioc, std::string host, std::uint16_t po ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>, 4>; + using async_client_t = async_client, null_strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -625,7 +625,7 @@ make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::s ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_32( ioc, @@ -637,9 +637,9 @@ make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::u #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>, 4>; + using async_client_t = async_client, as::io_context::strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -650,7 +650,7 @@ make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string p ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_ws_32( ioc, @@ -661,9 +661,9 @@ make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>, 4>; + using async_client_t = async_client, null_strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -674,7 +674,7 @@ make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/endpoint.hpp b/include/mqtt/endpoint.hpp index 556e4c0f3..1a1857450 100644 --- a/include/mqtt/endpoint.hpp +++ b/include/mqtt/endpoint.hpp @@ -4546,6 +4546,9 @@ class endpoint : public std::enable_shared_from_this { * @param port port number * @return sync_client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -92,7 +92,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -105,7 +105,7 @@ class sync_client : public client { * @return sync_client object. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -116,7 +116,7 @@ class sync_client : public client { * @param path path string * @return sync_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -174,7 +174,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -184,7 +184,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -197,7 +197,7 @@ class sync_client : public client { * @return sync_client object. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -208,7 +208,7 @@ class sync_client : public client { * @param path path string * @return sync_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -372,9 +372,9 @@ make_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16 #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>>; + using sync_client_t = sync_client, as::io_context::strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -387,7 +387,7 @@ make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, pr ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client( ioc, @@ -397,9 +397,9 @@ make_tls_sync_client(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>>; + using sync_client_t = sync_client, null_strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -412,7 +412,7 @@ make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::strin ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand( ioc, @@ -424,9 +424,9 @@ make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::uint1 #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>>; + using sync_client_t = sync_client, as::io_context::strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -437,7 +437,7 @@ make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_ws( ioc, @@ -448,9 +448,9 @@ make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::uint16_t por ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>>; + using sync_client_t = sync_client, null_strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -461,7 +461,7 @@ make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::st ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_ws( ioc, @@ -583,9 +583,9 @@ make_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uin #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>, 4>; + using sync_client_t = sync_client, as::io_context::strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -598,7 +598,7 @@ make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_32( ioc, @@ -608,9 +608,9 @@ make_tls_sync_client_32(as::io_context& ioc, std::string host, std::uint16_t por ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>, 4>; + using sync_client_t = sync_client, null_strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -623,7 +623,7 @@ make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::st ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_32( ioc, @@ -635,9 +635,9 @@ make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::ui #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>, 4>; + using sync_client_t = sync_client, as::io_context::strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -648,7 +648,7 @@ make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string po ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_ws_32( ioc, @@ -659,9 +659,9 @@ make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>, 4>; + using sync_client_t = sync_client, null_strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -672,7 +672,7 @@ make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std: ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_ws_32( ioc, diff --git a/test/underlying_timeout.cpp b/test/underlying_timeout.cpp index a953c7061..01dc635ad 100644 --- a/test/underlying_timeout.cpp +++ b/test/underlying_timeout.cpp @@ -112,10 +112,10 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_ashs ) { std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - as::ssl::context ctx {as::ssl::context::tlsv12}; + ssl::context ctx {ssl::context::tlsv12}; ctx.load_verify_file(base + "cacert.pem"); - ctx.set_verify_mode(as::ssl::verify_peer); - boost::beast::websocket::stream> socket(ioc, ctx); + ctx.set_verify_mode(ssl::verify_peer); + boost::beast::websocket::stream> socket(ioc, ctx); char buf; @@ -178,10 +178,10 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_upg ) { std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - as::ssl::context ctx {as::ssl::context::tlsv12}; + ssl::context ctx {ssl::context::tlsv12}; ctx.load_verify_file(base + "cacert.pem"); - ctx.set_verify_mode(as::ssl::verify_peer); - boost::beast::websocket::stream> socket(ioc, ctx); + ctx.set_verify_mode(ssl::verify_peer); + boost::beast::websocket::stream> socket(ioc, ctx); char buf; @@ -200,7 +200,7 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_upg ) { BOOST_TEST(!ec); socket.next_layer().async_handshake( - as::ssl::stream_base::client, + ssl::stream_base::client, [&] (MQTT_NS::error_code ec) { if (ec) { @@ -261,10 +261,10 @@ BOOST_AUTO_TEST_CASE( connect_tls_ashs ) { std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - as::ssl::context ctx {as::ssl::context::tlsv12}; + ssl::context ctx {ssl::context::tlsv12}; ctx.load_verify_file(base + "cacert.pem"); - ctx.set_verify_mode(as::ssl::verify_peer); - as::ssl::stream socket(ioc, ctx); + ctx.set_verify_mode(ssl::verify_peer); + ssl::stream socket(ioc, ctx); char buf; From 6ef17e860f85a88d65eb7173b49afa329bf61045 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Wed, 16 Sep 2020 15:37:56 -0700 Subject: [PATCH 06/32] Using nested namespaces and redefining as::ssl --- .gitignore | 1 + example/tls_both.cpp | 30 ++++---- example/tls_server.cpp | 30 ++++---- example/tls_ws_both.cpp | 28 ++++---- example/tls_ws_server.cpp | 30 ++++---- include/mqtt/async_client.hpp | 64 ++++++++--------- include/mqtt/client.hpp | 126 ++++++++++++++++++---------------- include/mqtt/endpoint.hpp | 22 +++--- include/mqtt/server.hpp | 56 ++++++++------- include/mqtt/sync_client.hpp | 64 ++++++++--------- include/mqtt/tcp_endpoint.hpp | 2 +- test/test_ctx_init.hpp | 28 ++++---- test/underlying_timeout.cpp | 20 +++--- 13 files changed, 267 insertions(+), 234 deletions(-) diff --git a/.gitignore b/.gitignore index cf25ac6db..5e75662d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ CMakeLists.txt.user* +build/ \ No newline at end of file diff --git a/example/tls_both.cpp b/example/tls_both.cpp index cc87d57be..6a0120242 100644 --- a/example/tls_both.cpp +++ b/example/tls_both.cpp @@ -16,15 +16,19 @@ #include "locked_cout.hpp" -namespace as = boost::asio; +// #if defined(MQTT_USE_TLS) +// #if defined(MQTT_USE_GNU_TLS) +// namespace boost +// { +// namespace asio +// { +// namespace ssl = boost::asio::gnutls; +// } +// } +// #endif // defined(MQTT_USE_GNU_TLS) +// #endif // defined(MQTT_USE_TLS) -#if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - namespace ssl = as::ssl; -#else - namespace ssl = as::gnutls; -#endif // !defined(MQTT_USE_TLS) -#endif // defined(MQTT_USE_TLS) +namespace as = boost::asio; template void client_proc( @@ -350,12 +354,12 @@ int main(int argc, char** argv) { std::uint16_t port = boost::lexical_cast(argv[1]); // server - ssl::context ctx(ssl::context::tlsv12); + as::ssl::context ctx(as::ssl::context::tlsv12); ctx.set_options( - ssl::context::default_workarounds | - ssl::context::single_dh_use); - ctx.use_certificate_file(base + "server.crt.pem", ssl::context::pem); - ctx.use_private_key_file(base + "server.key.pem", ssl::context::pem); + as::ssl::context::default_workarounds | + as::ssl::context::single_dh_use); + ctx.use_certificate_file(base + "server.crt.pem", as::ssl::context::pem); + ctx.use_private_key_file(base + "server.key.pem", as::ssl::context::pem); boost::asio::io_context iocs; auto s = MQTT_NS::server_tls<>( diff --git a/example/tls_server.cpp b/example/tls_server.cpp index d204cbb3a..b5ce64c2f 100644 --- a/example/tls_server.cpp +++ b/example/tls_server.cpp @@ -20,15 +20,19 @@ namespace mi = boost::multi_index; using con_t = MQTT_NS::server_tls<>::endpoint_t; using con_sp_t = std::shared_ptr; -namespace as = boost::asio; +// #if defined(MQTT_USE_TLS) +// #if defined(MQTT_USE_GNU_TLS) +// namespace boost +// { +// namespace asio +// { +// namespace ssl = boost::asio::gnutls; +// } +// } +// #endif // defined(MQTT_USE_GNU_TLS) +// #endif // defined(MQTT_USE_TLS) -#if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - namespace ssl = as::ssl; -#else - namespace ssl = as::gnutls; -#endif // !defined(MQTT_USE_TLS) -#endif // defined(MQTT_USE_TLS) +namespace as = boost::asio; struct sub_con { sub_con(MQTT_NS::buffer topic, con_sp_t con, MQTT_NS::qos qos_value) @@ -78,12 +82,12 @@ int main(int argc, char** argv) { std::string cert = argv[2]; std::string key = argv[3]; - ssl::context ctx(ssl::context::tlsv12); + as::ssl::context ctx(as::ssl::context::tlsv12); ctx.set_options( - ssl::context::default_workarounds | - ssl::context::single_dh_use); - ctx.use_certificate_file(cert, ssl::context::pem); - ctx.use_private_key_file(key, ssl::context::pem); + as::ssl::context::default_workarounds | + as::ssl::context::single_dh_use); + ctx.use_certificate_file(cert, as::ssl::context::pem); + ctx.use_private_key_file(key, as::ssl::context::pem); auto s = MQTT_NS::server_tls<>( boost::asio::ip::tcp::endpoint( diff --git a/example/tls_ws_both.cpp b/example/tls_ws_both.cpp index 63b776730..206ca4baf 100644 --- a/example/tls_ws_both.cpp +++ b/example/tls_ws_both.cpp @@ -16,16 +16,20 @@ #include "locked_cout.hpp" -namespace as = boost::asio; - #if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - namespace ssl = as::ssl; -#else - namespace ssl = as::gnutls; -#endif // !defined(MQTT_USE_TLS) +#if defined(MQTT_USE_GNU_TLS) + namespace boost + { + namespace asio + { + namespace ssl = boost::asio::gnutls; + } + } +#endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) +namespace as = boost::asio; + template void client_proc( Client& c, @@ -349,12 +353,12 @@ int main(int argc, char** argv) { std::uint16_t port = boost::lexical_cast(argv[1]); // server - ssl::context ctx(ssl::context::tlsv12); + as::ssl::context ctx(as::ssl::context::tlsv12); ctx.set_options( - ssl::context::default_workarounds | - ssl::context::single_dh_use); - ctx.use_certificate_file(base + "server.crt.pem", ssl::context::pem); - ctx.use_private_key_file(base + "server.key.pem", ssl::context::pem); + as::ssl::context::default_workarounds | + as::ssl::context::single_dh_use); + ctx.use_certificate_file(base + "server.crt.pem", as::ssl::context::pem); + ctx.use_private_key_file(base + "server.key.pem", as::ssl::context::pem); boost::asio::io_context iocs; auto s = MQTT_NS::server_tls_ws<>( diff --git a/example/tls_ws_server.cpp b/example/tls_ws_server.cpp index 7b84b1425..020c92f12 100644 --- a/example/tls_ws_server.cpp +++ b/example/tls_ws_server.cpp @@ -20,15 +20,19 @@ namespace mi = boost::multi_index; using con_t = MQTT_NS::server_tls_ws<>::endpoint_t; using con_sp_t = std::shared_ptr; -namespace as = boost::asio; +// #if defined(MQTT_USE_TLS) +// #if defined(MQTT_USE_GNU_TLS) +// namespace boost +// { +// namespace asio +// { +// namespace ssl = boost::asio::gnutls; +// } +// } +// #endif // defined(MQTT_USE_GNU_TLS) +// #endif // defined(MQTT_USE_TLS) -#if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - namespace ssl = as::ssl; -#else - namespace ssl = as::gnutls; -#endif // !defined(MQTT_USE_TLS) -#endif // defined(MQTT_USE_TLS) +namespace as = boost::asio; struct sub_con { sub_con(MQTT_NS::buffer topic, con_sp_t con, MQTT_NS::qos qos_value) @@ -78,12 +82,12 @@ int main(int argc, char** argv) { std::string cert = argv[2]; std::string key = argv[3]; - ssl::context ctx(ssl::context::tlsv12); + as::ssl::context ctx(as::ssl::context::tlsv12); ctx.set_options( - ssl::context::default_workarounds | - ssl::context::single_dh_use); - ctx.use_certificate_file(cert, ssl::context::pem); - ctx.use_private_key_file(key, ssl::context::pem); + as::ssl::context::default_workarounds | + as::ssl::context::single_dh_use); + ctx.use_certificate_file(cert, as::ssl::context::pem); + ctx.use_private_key_file(key, as::ssl::context::pem); auto s = MQTT_NS::server_tls_ws<>( boost::asio::ip::tcp::endpoint( diff --git a/include/mqtt/async_client.hpp b/include/mqtt/async_client.hpp index 0a32819b6..210e63a56 100644 --- a/include/mqtt/async_client.hpp +++ b/include/mqtt/async_client.hpp @@ -82,7 +82,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_async_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -92,7 +92,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -105,7 +105,7 @@ class async_client : public client { * @return async_client object. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -116,7 +116,7 @@ class async_client : public client { * @param path path string * @return async_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -174,7 +174,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -184,7 +184,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -197,7 +197,7 @@ class async_client : public client { * @return async_client object. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -208,7 +208,7 @@ class async_client : public client { * @param path path string * @return async_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -374,9 +374,9 @@ make_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint1 #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>>; + using async_client_t = async_client, as::io_context::strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -389,7 +389,7 @@ make_tls_async_client(as::io_context& ioc, std::string host, std::string port, p ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client( ioc, @@ -399,9 +399,9 @@ make_tls_async_client(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>>; + using async_client_t = async_client, null_strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -414,7 +414,7 @@ make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::stri ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand( ioc, @@ -426,9 +426,9 @@ make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::uint #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>>; + using async_client_t = async_client, as::io_context::strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -439,7 +439,7 @@ make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_ws( ioc, @@ -450,9 +450,9 @@ make_tls_async_client_ws(as::io_context& ioc, std::string host, std::uint16_t po ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>>; + using async_client_t = async_client, null_strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -463,7 +463,7 @@ make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::s ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_ws( ioc, @@ -585,9 +585,9 @@ make_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::ui #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>, 4>; + using async_client_t = async_client, as::io_context::strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -600,7 +600,7 @@ make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_32( ioc, @@ -610,9 +610,9 @@ make_tls_async_client_32(as::io_context& ioc, std::string host, std::uint16_t po ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>, 4>; + using async_client_t = async_client, null_strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -625,7 +625,7 @@ make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::s ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_32( ioc, @@ -637,9 +637,9 @@ make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::u #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>, 4>; + using async_client_t = async_client, as::io_context::strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -650,7 +650,7 @@ make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string p ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_ws_32( ioc, @@ -661,9 +661,9 @@ make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>, 4>; + using async_client_t = async_client, null_strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -674,7 +674,7 @@ make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/client.hpp b/include/mqtt/client.hpp index b5458f314..8f792d47d 100644 --- a/include/mqtt/client.hpp +++ b/include/mqtt/client.hpp @@ -26,7 +26,7 @@ #else #include #include -#endif // !defined(MQTT_USE_TLS) +#endif // !defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) #include @@ -44,17 +44,21 @@ namespace MQTT_NS { -namespace as = boost::asio; -namespace mi = boost::multi_index; - #if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - namespace ssl = as::ssl; -#else - namespace ssl = as::gnutls; -#endif // !defined(MQTT_USE_TLS) +#if defined(MQTT_USE_GNU_TLS) + namespace boost + { + namespace asio + { + namespace ssl = boost::asio::gnutls; + } + } +#endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) +namespace as = boost::asio; +namespace mi = boost::multi_index; + template class client : public endpoint { using this_type = client; @@ -125,7 +129,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -135,7 +139,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -148,7 +152,7 @@ class client : public endpoint { * @return client object. * strand is controlled by ws_endpoint, not endpoint, so client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -159,7 +163,7 @@ class client : public endpoint { * @param path path string * @return client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -217,7 +221,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -227,7 +231,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -240,7 +244,7 @@ class client : public endpoint { * @return client object. * strand is controlled by ws_endpoint, not endpoint, so client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -251,7 +255,7 @@ class client : public endpoint { * @param path path string * @return client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -348,7 +352,7 @@ class client : public endpoint { * @brief Get boost asio ssl context. * @return ssl context */ - ssl::context& get_ssl_context() { + as::ssl::context& get_ssl_context() { static_assert(has_tls>::value, "Client is required to support TLS."); return ctx_; } @@ -357,7 +361,7 @@ class client : public endpoint { * @brief Get boost asio ssl context. * @return ssl context */ - ssl::context const& get_ssl_context() const { + as::ssl::context const& get_ssl_context() const { static_assert(has_tls>::value, "Client is required to support TLS."); return ctx_; } @@ -1030,7 +1034,7 @@ class client : public endpoint { tim_session_expiry_(ioc_) { #if defined(MQTT_USE_TLS) - ctx_.set_verify_mode(ssl::verify_peer); + ctx_.set_verify_mode(as::ssl::verify_peer); #endif // defined(MQTT_USE_TLS) } @@ -1051,14 +1055,14 @@ class client : public endpoint { #if defined(MQTT_USE_TLS) template - void setup_socket(std::shared_ptr, Strand>>& socket) { + void setup_socket(std::shared_ptr, Strand>>& socket) { socket = std::make_shared(ioc_, ctx_); base::socket_optional().emplace(socket); } #if defined(MQTT_USE_WS) template - void setup_socket(std::shared_ptr, Strand>>& socket) { + void setup_socket(std::shared_ptr, Strand>>& socket) { socket = std::make_shared(ioc_, ctx_); base::socket_optional().emplace(socket); } @@ -1145,20 +1149,20 @@ class client : public endpoint { template void handshake_socket( - tcp_endpoint, Strand>& socket, + tcp_endpoint, Strand>& socket, v5::properties props, any session_life_keeper) { - socket.handshake(ssl::stream_base::client); + socket.handshake(as::ssl::stream_base::client); start_session(force_move(props), force_move(session_life_keeper)); } template void handshake_socket( - tcp_endpoint, Strand>& socket, + tcp_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, boost::system::error_code& ec) { - socket.handshake(ssl::stream_base::client, ec); + socket.handshake(as::ssl::stream_base::client, ec); if (ec) return; start_session(force_move(props), force_move(session_life_keeper)); } @@ -1167,21 +1171,21 @@ class client : public endpoint { template void handshake_socket( - ws_endpoint, Strand>& socket, + ws_endpoint, Strand>& socket, v5::properties props, any session_life_keeper) { - socket.next_layer().handshake(ssl::stream_base::client); + socket.next_layer().handshake(as::ssl::stream_base::client); socket.handshake(host_, path_); start_session(force_move(props), force_move(session_life_keeper)); } template void handshake_socket( - ws_endpoint, Strand>& socket, + ws_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, boost::system::error_code& ec) { - socket.next_layer().handshake(ssl::stream_base::client, ec); + socket.next_layer().handshake(as::ssl::stream_base::client, ec); if (ec) return; socket.handshake(host_, path_, ec); if (ec) return; @@ -1232,12 +1236,12 @@ class client : public endpoint { template void async_handshake_socket( - tcp_endpoint, Strand>& socket, + tcp_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, async_handler_t func) { socket.async_handshake( - ssl::stream_base::client, + as::ssl::stream_base::client, [ this, self = this->shared_from_this(), @@ -1257,12 +1261,12 @@ class client : public endpoint { #if defined(MQTT_USE_WS) template void async_handshake_socket( - ws_endpoint, Strand>& socket, + ws_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, async_handler_t func) { socket.next_layer().async_handshake( - ssl::stream_base::client, + as::ssl::stream_base::client, [ this, self = this->shared_from_this(), @@ -1507,12 +1511,12 @@ class client : public endpoint { }; template - struct has_tls, U>>> : std::true_type { + struct has_tls, U>>> : std::true_type { }; #if defined(MQTT_USE_WS) template - struct has_tls, U>>> : std::true_type { + struct has_tls, U>>> : std::true_type { }; #endif // defined(MQTT_USE_WS) @@ -1532,7 +1536,7 @@ class client : public endpoint { optional password_; bool async_pingreq_ = false; #if defined(MQTT_USE_TLS) - ssl::context ctx_{ssl::context::tlsv12}; + as::ssl::context ctx_{as::ssl::context::tlsv12}; #endif // defined(MQTT_USE_TLS) #if defined(MQTT_USE_WS) std::string path_; @@ -1645,9 +1649,9 @@ make_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t po #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>>; + using client_t = client, as::io_context::strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1660,7 +1664,7 @@ make_tls_client(as::io_context& ioc, std::string host, std::string port, protoco ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client( ioc, @@ -1670,9 +1674,9 @@ make_tls_client(as::io_context& ioc, std::string host, std::uint16_t port, proto ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>>; + using client_t = client, null_strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1685,7 +1689,7 @@ make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string por ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand( ioc, @@ -1697,9 +1701,9 @@ make_tls_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t p #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>>; + using client_t = client, as::io_context::strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1710,7 +1714,7 @@ make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std: ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_ws( ioc, @@ -1721,9 +1725,9 @@ make_tls_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, st ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>>; + using client_t = client, null_strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1734,7 +1738,7 @@ make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_ws( ioc, @@ -1856,9 +1860,9 @@ make_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>, 4>; + using client_t = client, as::io_context::strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1871,7 +1875,7 @@ make_tls_client_32(as::io_context& ioc, std::string host, std::string port, prot ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_32( ioc, @@ -1881,9 +1885,9 @@ make_tls_client_32(as::io_context& ioc, std::string host, std::uint16_t port, pr ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>, 4>; + using client_t = client, null_strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1896,7 +1900,7 @@ make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_32( ioc, @@ -1908,9 +1912,9 @@ make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_ #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>, 4>; + using client_t = client, as::io_context::strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1921,7 +1925,7 @@ make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, s ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_ws_32( ioc, @@ -1932,9 +1936,9 @@ make_tls_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>, 4>; + using client_t = client, null_strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1945,7 +1949,7 @@ make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::stri ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/endpoint.hpp b/include/mqtt/endpoint.hpp index 1a1857450..9d3152243 100644 --- a/include/mqtt/endpoint.hpp +++ b/include/mqtt/endpoint.hpp @@ -150,17 +150,21 @@ constexpr bool should_generate_packet_id(Params const& ... params) { } // namespace detail +// #if defined(MQTT_USE_TLS) +// #if defined(MQTT_USE_GNU_TLS) +// namespace boost +// { +// namespace asio +// { +// namespace ssl = boost::asio::gnutls; +// } +// } +// #endif // defined(MQTT_USE_GNU_TLS) +// #endif // defined(MQTT_USE_TLS) + namespace as = boost::asio; namespace mi = boost::multi_index; -#if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - namespace ssl = as::ssl; -#else - namespace ssl = as::gnutls; -#endif // !defined(MQTT_USE_TLS) -#endif // defined(MQTT_USE_TLS) - template class LockGuard = std::lock_guard, std::size_t PacketIdBytes = 2> class endpoint : public std::enable_shared_from_this> { using this_type = endpoint; @@ -4552,7 +4556,7 @@ class endpoint : public std::enable_shared_from_this #include -#endif // !defined(MQTT_USE_TLS) +#endif // !defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) #include @@ -36,16 +36,20 @@ namespace MQTT_NS { -namespace as = boost::asio; - #if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - namespace ssl = as::ssl; -#else - namespace ssl = as::gnutls; -#endif // !defined(MQTT_USE_TLS) +#if defined(MQTT_USE_GNU_TLS) + namespace boost + { + namespace asio + { + namespace ssl = boost::asio::gnutls; + } + } +#endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) +namespace as = boost::asio; + template class LockGuard, std::size_t PacketIdBytes> class server_endpoint : public endpoint { public: @@ -225,7 +229,7 @@ template < > class server_tls { public: - using socket_t = tcp_endpoint, Strand>; + using socket_t = tcp_endpoint, Strand>; using endpoint_t = callable_overlay>; /** @@ -243,7 +247,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - ssl::context&& ctx, + as::ssl::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con, AcceptorConfig&& config) @@ -259,7 +263,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - ssl::context&& ctx, + as::ssl::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con) : server_tls(std::forward(ep), force_move(ctx), ioc_accept, ioc_con, [](as::ip::tcp::acceptor&) {}) {} @@ -267,7 +271,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - ssl::context&& ctx, + as::ssl::context&& ctx, as::io_context& ioc, AcceptorConfig&& config) : server_tls(std::forward(ep), force_move(ctx), ioc, ioc, std::forward(config)) {} @@ -275,7 +279,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - ssl::context&& ctx, + as::ssl::context&& ctx, as::io_context& ioc) : server_tls(std::forward(ep), force_move(ctx), ioc, ioc, [](as::ip::tcp::acceptor&) {}) {} @@ -362,7 +366,7 @@ class server_tls { * @brief Get boost asio ssl context. * @return ssl context */ - ssl::context& get_ssl_context() { + as::ssl::context& get_ssl_context() { return ctx_; } @@ -370,7 +374,7 @@ class server_tls { * @brief Get boost asio ssl context. * @return ssl context */ - ssl::context const& get_ssl_context() const { + as::ssl::context const& get_ssl_context() const { return ctx_; } @@ -406,7 +410,7 @@ class server_tls { ); auto ps = socket.get(); ps->async_handshake( - ssl::stream_base::server, + as::ssl::stream_base::server, [this, socket = force_move(socket), tim, underlying_finished] (error_code ec) mutable { *underlying_finished = true; @@ -432,7 +436,7 @@ class server_tls { bool close_request_{false}; accept_handler h_accept_; error_handler h_error_; - ssl::context ctx_; + as::ssl::context ctx_; protocol_version version_ = protocol_version::undetermined; std::chrono::steady_clock::duration underlying_connect_timeout_ = std::chrono::seconds(10); }; @@ -714,7 +718,7 @@ template < > class server_tls_ws { public: - using socket_t = ws_endpoint, Strand>; + using socket_t = ws_endpoint, Strand>; using endpoint_t = callable_overlay>; /** @@ -732,7 +736,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - ssl::context&& ctx, + as::ssl::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con, AcceptorConfig&& config) @@ -748,7 +752,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - ssl::context&& ctx, + as::ssl::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con) : server_tls_ws(std::forward(ep), force_move(ctx), ioc_accept, ioc_con, [](as::ip::tcp::acceptor&) {}) {} @@ -756,7 +760,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - ssl::context&& ctx, + as::ssl::context&& ctx, as::io_context& ioc, AcceptorConfig&& config) : server_tls_ws(std::forward(ep), force_move(ctx), ioc, ioc, std::forward(config)) {} @@ -764,7 +768,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - ssl::context&& ctx, + as::ssl::context&& ctx, as::io_context& ioc) : server_tls_ws(std::forward(ep), force_move(ctx), ioc, ioc, [](as::ip::tcp::acceptor&) {}) {} @@ -851,7 +855,7 @@ class server_tls_ws { * @brief Get boost asio ssl context. * @return ssl context */ - ssl::context& get_ssl_context() { + as::ssl::context& get_ssl_context() { return ctx_; } @@ -859,7 +863,7 @@ class server_tls_ws { * @brief Get boost asio ssl context. * @return ssl context */ - ssl::context const& get_ssl_context() const { + as::ssl::context const& get_ssl_context() const { return ctx_; } @@ -896,7 +900,7 @@ class server_tls_ws { auto ps = socket.get(); ps->next_layer().async_handshake( - ssl::stream_base::server, + as::ssl::stream_base::server, [this, socket = force_move(socket), tim, underlying_finished] (error_code ec) mutable { if (ec) { @@ -1000,7 +1004,7 @@ class server_tls_ws { bool close_request_{false}; accept_handler h_accept_; error_handler h_error_; - ssl::context ctx_; + as::ssl::context ctx_; protocol_version version_ = protocol_version::undetermined; std::chrono::steady_clock::duration underlying_connect_timeout_ = std::chrono::seconds(10); }; diff --git a/include/mqtt/sync_client.hpp b/include/mqtt/sync_client.hpp index 559cc99ac..79d71485e 100644 --- a/include/mqtt/sync_client.hpp +++ b/include/mqtt/sync_client.hpp @@ -82,7 +82,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -92,7 +92,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -105,7 +105,7 @@ class sync_client : public client { * @return sync_client object. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -116,7 +116,7 @@ class sync_client : public client { * @param path path string * @return sync_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -174,7 +174,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -184,7 +184,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -197,7 +197,7 @@ class sync_client : public client { * @return sync_client object. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -208,7 +208,7 @@ class sync_client : public client { * @param path path string * @return sync_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -372,9 +372,9 @@ make_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16 #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>>; + using sync_client_t = sync_client, as::io_context::strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -387,7 +387,7 @@ make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, pr ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client( ioc, @@ -397,9 +397,9 @@ make_tls_sync_client(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>>; + using sync_client_t = sync_client, null_strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -412,7 +412,7 @@ make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::strin ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand( ioc, @@ -424,9 +424,9 @@ make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::uint1 #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>>; + using sync_client_t = sync_client, as::io_context::strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -437,7 +437,7 @@ make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_ws( ioc, @@ -448,9 +448,9 @@ make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::uint16_t por ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>>; + using sync_client_t = sync_client, null_strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -461,7 +461,7 @@ make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::st ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_ws( ioc, @@ -583,9 +583,9 @@ make_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uin #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>, 4>; + using sync_client_t = sync_client, as::io_context::strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -598,7 +598,7 @@ make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_32( ioc, @@ -608,9 +608,9 @@ make_tls_sync_client_32(as::io_context& ioc, std::string host, std::uint16_t por ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>, 4>; + using sync_client_t = sync_client, null_strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -623,7 +623,7 @@ make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::st ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_32( ioc, @@ -635,9 +635,9 @@ make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::ui #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>, 4>; + using sync_client_t = sync_client, as::io_context::strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -648,7 +648,7 @@ make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string po ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_ws_32( ioc, @@ -659,9 +659,9 @@ make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>, 4>; + using sync_client_t = sync_client, null_strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -672,7 +672,7 @@ make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std: ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/tcp_endpoint.hpp b/include/mqtt/tcp_endpoint.hpp index ede2ae429..2db1e6d64 100644 --- a/include/mqtt/tcp_endpoint.hpp +++ b/include/mqtt/tcp_endpoint.hpp @@ -16,7 +16,7 @@ #else #include #include -#endif // !defined(MQTT_USE_TLS) +#endif // !defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) #include diff --git a/test/test_ctx_init.hpp b/test/test_ctx_init.hpp index 7e4d76156..76199fc4d 100644 --- a/test/test_ctx_init.hpp +++ b/test/test_ctx_init.hpp @@ -16,30 +16,34 @@ #else #include #include -#endif // !defined(MQTT_USE_TLS) +#endif // !defined(MQTT_USE_GNU_TLS) #include "test_settings.hpp" #if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - namespace ssl = as::ssl; -#else - namespace ssl = as::gnutls; -#endif // !defined(MQTT_USE_TLS) +#if defined(MQTT_USE_GNU_TLS) + namespace boost + { + namespace asio + { + namespace ssl = boost::asio::gnutls; + } + } +#endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) struct ctx_init { - ctx_init() : ctx(ssl::context::tlsv12) { + ctx_init() : ctx(as::ssl::context::tlsv12) { ctx.set_options( - ssl::context::default_workarounds | - ssl::context::single_dh_use); + as::ssl::context::default_workarounds | + as::ssl::context::single_dh_use); std::string path = boost::unit_test::framework::master_test_suite().argv[0]; std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - ctx.use_certificate_file(base + "server.crt.pem", ssl::context::pem); - ctx.use_private_key_file(base + "server.key.pem", ssl::context::pem); + ctx.use_certificate_file(base + "server.crt.pem", as::ssl::context::pem); + ctx.use_private_key_file(base + "server.key.pem", as::ssl::context::pem); } - ssl::context ctx; + as::ssl::context ctx; }; #endif // defined(MQTT_USE_TLS) diff --git a/test/underlying_timeout.cpp b/test/underlying_timeout.cpp index 01dc635ad..a953c7061 100644 --- a/test/underlying_timeout.cpp +++ b/test/underlying_timeout.cpp @@ -112,10 +112,10 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_ashs ) { std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - ssl::context ctx {ssl::context::tlsv12}; + as::ssl::context ctx {as::ssl::context::tlsv12}; ctx.load_verify_file(base + "cacert.pem"); - ctx.set_verify_mode(ssl::verify_peer); - boost::beast::websocket::stream> socket(ioc, ctx); + ctx.set_verify_mode(as::ssl::verify_peer); + boost::beast::websocket::stream> socket(ioc, ctx); char buf; @@ -178,10 +178,10 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_upg ) { std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - ssl::context ctx {ssl::context::tlsv12}; + as::ssl::context ctx {as::ssl::context::tlsv12}; ctx.load_verify_file(base + "cacert.pem"); - ctx.set_verify_mode(ssl::verify_peer); - boost::beast::websocket::stream> socket(ioc, ctx); + ctx.set_verify_mode(as::ssl::verify_peer); + boost::beast::websocket::stream> socket(ioc, ctx); char buf; @@ -200,7 +200,7 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_upg ) { BOOST_TEST(!ec); socket.next_layer().async_handshake( - ssl::stream_base::client, + as::ssl::stream_base::client, [&] (MQTT_NS::error_code ec) { if (ec) { @@ -261,10 +261,10 @@ BOOST_AUTO_TEST_CASE( connect_tls_ashs ) { std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - ssl::context ctx {ssl::context::tlsv12}; + as::ssl::context ctx {as::ssl::context::tlsv12}; ctx.load_verify_file(base + "cacert.pem"); - ctx.set_verify_mode(ssl::verify_peer); - ssl::stream socket(ioc, ctx); + ctx.set_verify_mode(as::ssl::verify_peer); + as::ssl::stream socket(ioc, ctx); char buf; From cc9d4d84db50da6ac7ec7916e1adba14f41a0f68 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Wed, 16 Sep 2020 15:46:29 -0700 Subject: [PATCH 07/32] Add ssl_implementation.hpp --- example/tls_ws_both.cpp | 22 ++++++++--------- include/mqtt/client.hpp | 29 +++++++++------------- include/mqtt/server.hpp | 38 ++++++++++++++++------------- include/mqtt/ssl_implementation.hpp | 31 +++++++++++++++++++++++ include/mqtt/tcp_endpoint.hpp | 16 +++++++----- include/mqtt_client_cpp.hpp | 1 + test/test_ctx_init.hpp | 38 ++++++++++++++++------------- 7 files changed, 107 insertions(+), 68 deletions(-) create mode 100644 include/mqtt/ssl_implementation.hpp diff --git a/example/tls_ws_both.cpp b/example/tls_ws_both.cpp index 206ca4baf..7b372e548 100644 --- a/example/tls_ws_both.cpp +++ b/example/tls_ws_both.cpp @@ -16,17 +16,17 @@ #include "locked_cout.hpp" -#if defined(MQTT_USE_TLS) -#if defined(MQTT_USE_GNU_TLS) - namespace boost - { - namespace asio - { - namespace ssl = boost::asio::gnutls; - } - } -#endif // defined(MQTT_USE_GNU_TLS) -#endif // defined(MQTT_USE_TLS) +// #if defined(MQTT_USE_TLS) +// #if defined(MQTT_USE_GNU_TLS) +// namespace boost +// { +// namespace asio +// { +// namespace ssl = boost::asio::gnutls; +// } +// } +// #endif // defined(MQTT_USE_GNU_TLS) +// #endif // defined(MQTT_USE_TLS) namespace as = boost::asio; diff --git a/include/mqtt/client.hpp b/include/mqtt/client.hpp index 8f792d47d..bfa1d72d5 100644 --- a/include/mqtt/client.hpp +++ b/include/mqtt/client.hpp @@ -21,12 +21,7 @@ #include #if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - #include -#else - #include - #include -#endif // !defined(MQTT_USE_GNU_TLS) +#include #endif // defined(MQTT_USE_TLS) #include @@ -44,17 +39,17 @@ namespace MQTT_NS { -#if defined(MQTT_USE_TLS) -#if defined(MQTT_USE_GNU_TLS) - namespace boost - { - namespace asio - { - namespace ssl = boost::asio::gnutls; - } - } -#endif // defined(MQTT_USE_GNU_TLS) -#endif // defined(MQTT_USE_TLS) +// #if defined(MQTT_USE_TLS) +// #if defined(MQTT_USE_GNU_TLS) +// namespace boost +// { +// namespace asio +// { +// namespace ssl = boost::asio::gnutls; +// } +// } +// #endif // defined(MQTT_USE_GNU_TLS) +// #endif // defined(MQTT_USE_TLS) namespace as = boost::asio; namespace mi = boost::multi_index; diff --git a/include/mqtt/server.hpp b/include/mqtt/server.hpp index 37d5bb702..8876c0ff4 100644 --- a/include/mqtt/server.hpp +++ b/include/mqtt/server.hpp @@ -14,13 +14,17 @@ #include +// #if defined(MQTT_USE_TLS) +// #if !defined(MQTT_USE_GNU_TLS) +// #include +// #else +// #include +// #include +// #endif // !defined(MQTT_USE_GNU_TLS) +// #endif // defined(MQTT_USE_TLS) + #if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - #include -#else - #include - #include -#endif // !defined(MQTT_USE_GNU_TLS) +#include #endif // defined(MQTT_USE_TLS) #include @@ -36,17 +40,17 @@ namespace MQTT_NS { -#if defined(MQTT_USE_TLS) -#if defined(MQTT_USE_GNU_TLS) - namespace boost - { - namespace asio - { - namespace ssl = boost::asio::gnutls; - } - } -#endif // defined(MQTT_USE_GNU_TLS) -#endif // defined(MQTT_USE_TLS) +// #if defined(MQTT_USE_TLS) +// #if defined(MQTT_USE_GNU_TLS) +// namespace boost +// { +// namespace asio +// { +// namespace ssl = boost::asio::gnutls; +// } +// } +// #endif // defined(MQTT_USE_GNU_TLS) +// #endif // defined(MQTT_USE_TLS) namespace as = boost::asio; diff --git a/include/mqtt/ssl_implementation.hpp b/include/mqtt/ssl_implementation.hpp new file mode 100644 index 000000000..0be1d9a5f --- /dev/null +++ b/include/mqtt/ssl_implementation.hpp @@ -0,0 +1,31 @@ +// Copyright Takatoshi Kondo 2018 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#if !defined(MQTT_SSL_IMPLEMENTATION_HPP) +#define MQTT_SSL_IMPLEMENTATION_HPP + +#if defined(MQTT_USE_TLS) +#if !defined(MQTT_USE_GNU_TLS) + #include +#else + #include + #include +#endif // !defined(MQTT_USE_GNU_TLS) +#endif // defined(MQTT_USE_TLS) + +namespace MQTT_NS { + +#if defined(MQTT_USE_TLS) +#if !defined(MQTT_USE_GNU_TLS) + namespace ssl = boost::asio::ssl; +#else + namespace ssl = boost::asio::gnutls; +#endif // !defined(MQTT_USE_GNU_TLS) +#endif // defined(MQTT_USE_TLS) + +} // namespace MQTT_NS + +#endif // MQTT_SSL_IMPLEMENTATION_HPP diff --git a/include/mqtt/tcp_endpoint.hpp b/include/mqtt/tcp_endpoint.hpp index 2db1e6d64..6e7957d08 100644 --- a/include/mqtt/tcp_endpoint.hpp +++ b/include/mqtt/tcp_endpoint.hpp @@ -10,13 +10,17 @@ #include #include +// #if defined(MQTT_USE_TLS) +// #if !defined(MQTT_USE_GNU_TLS) +// #include +// #else +// #include +// #include +// #endif // !defined(MQTT_USE_GNU_TLS) +// #endif // defined(MQTT_USE_TLS) + #if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - #include -#else - #include - #include -#endif // !defined(MQTT_USE_GNU_TLS) +#include #endif // defined(MQTT_USE_TLS) #include diff --git a/include/mqtt_client_cpp.hpp b/include/mqtt_client_cpp.hpp index 3bd280215..17a8eabd7 100644 --- a/include/mqtt_client_cpp.hpp +++ b/include/mqtt_client_cpp.hpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/test/test_ctx_init.hpp b/test/test_ctx_init.hpp index 76199fc4d..def0c4205 100644 --- a/test/test_ctx_init.hpp +++ b/test/test_ctx_init.hpp @@ -11,27 +11,31 @@ #include -#if !defined(MQTT_USE_GNU_TLS) - #include -#else - #include - #include -#endif // !defined(MQTT_USE_GNU_TLS) - -#include "test_settings.hpp" +// #if !defined(MQTT_USE_GNU_TLS) +// #include +// #else +// #include +// #include +// #endif // !defined(MQTT_USE_GNU_TLS) #if defined(MQTT_USE_TLS) -#if defined(MQTT_USE_GNU_TLS) - namespace boost - { - namespace asio - { - namespace ssl = boost::asio::gnutls; - } - } -#endif // defined(MQTT_USE_GNU_TLS) +#include #endif // defined(MQTT_USE_TLS) +#include "test_settings.hpp" + +// #if defined(MQTT_USE_TLS) +// #if defined(MQTT_USE_GNU_TLS) +// namespace boost +// { +// namespace asio +// { +// namespace ssl = boost::asio::gnutls; +// } +// } +// #endif // defined(MQTT_USE_GNU_TLS) +// #endif // defined(MQTT_USE_TLS) + struct ctx_init { ctx_init() : ctx(as::ssl::context::tlsv12) { ctx.set_options( From 1367a85427510e233480c1e51372328ef4abd9df Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Thu, 17 Sep 2020 17:48:44 -0700 Subject: [PATCH 08/32] Working changes --- README.md | 3 +- example/tls_both.cpp | 29 +++---- example/tls_client.cpp | 7 ++ example/tls_server.cpp | 22 ++--- example/tls_ws_both.cpp | 29 +++---- example/tls_ws_client.cpp | 7 ++ example/tls_ws_server.cpp | 22 ++--- include/mqtt/async_client.hpp | 64 +++++++-------- include/mqtt/client.hpp | 119 ++++++++++++---------------- include/mqtt/endpoint.hpp | 21 ++--- include/mqtt/server.hpp | 61 +++++--------- include/mqtt/ssl_implementation.hpp | 15 ++-- include/mqtt/sync_client.hpp | 64 +++++++-------- include/mqtt/tcp_endpoint.hpp | 12 --- include/mqtt_server_cpp.hpp | 1 + test/combi_test.hpp | 8 ++ test/test_ctx_init.hpp | 36 ++------- test/underlying_timeout.cpp | 47 ++++++++--- 18 files changed, 251 insertions(+), 316 deletions(-) diff --git a/README.md b/README.md index 4bd2b42f1..2555e166a 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,8 @@ g++ -std=c++14 -Ipath_to_mqtt_cpp/include your_program.cpp -pthread additional_o |what you want|required option| |---|---| -|TLS support|`-DMQTT_USE_TLS -pthread -lssl -lcrypto`| +|TLS support with OpenSSL|`-DMQTT_USE_TLS -pthread -lssl -lcrypto`| +|TLS support with GnuTLS|`-DMQTT_USE_TLS -DMQTT_USE_GNU_TLS -pthread -lssl -lcrypto`| |Logging support|`-DMQTT_USE_LOG -DBOOST_LOG_DYN_LINK -lboost_log -lboost_filesystem -lboost_thread`| |WebSocket support|`-DMQTT_USE_WS`| diff --git a/example/tls_both.cpp b/example/tls_both.cpp index 6a0120242..92c1a5941 100644 --- a/example/tls_both.cpp +++ b/example/tls_both.cpp @@ -16,18 +16,6 @@ #include "locked_cout.hpp" -// #if defined(MQTT_USE_TLS) -// #if defined(MQTT_USE_GNU_TLS) -// namespace boost -// { -// namespace asio -// { -// namespace ssl = boost::asio::gnutls; -// } -// } -// #endif // defined(MQTT_USE_GNU_TLS) -// #endif // defined(MQTT_USE_TLS) - namespace as = boost::asio; template @@ -354,12 +342,12 @@ int main(int argc, char** argv) { std::uint16_t port = boost::lexical_cast(argv[1]); // server - as::ssl::context ctx(as::ssl::context::tlsv12); + ssl::context ctx(ssl::context::tlsv12); ctx.set_options( - as::ssl::context::default_workarounds | - as::ssl::context::single_dh_use); - ctx.use_certificate_file(base + "server.crt.pem", as::ssl::context::pem); - ctx.use_private_key_file(base + "server.key.pem", as::ssl::context::pem); + ssl::context::default_workarounds | + ssl::context::single_dh_use); + ctx.use_certificate_file(base + "server.crt.pem", ssl::context::pem); + ctx.use_private_key_file(base + "server.key.pem", ssl::context::pem); boost::asio::io_context iocs; auto s = MQTT_NS::server_tls<>( @@ -385,7 +373,14 @@ int main(int argc, char** argv) { std::uint16_t pid_sub2; auto c = MQTT_NS::make_tls_sync_client(ioc, "localhost", port); + +#if defined(MQTT_USE_TLS) +#if !defined(MQTT_USE_GNU_TLS) c->get_ssl_context().load_verify_file(base + "cacert.pem"); +#else + c->get_ssl_context().use_verify_file(base + "cacert.pem", ssl::context::pem); +#endif // !defined(MQTT_USE_GNU_TLS) +#endif // defined(MQTT_USE_TLS) int count = 0; auto disconnect = [&] { diff --git a/example/tls_client.cpp b/example/tls_client.cpp index 1e066277f..eff5d6ec2 100644 --- a/example/tls_client.cpp +++ b/example/tls_client.cpp @@ -39,7 +39,14 @@ int main(int argc, char** argv) { // Setup client c->set_client_id("cid1"); c->set_clean_session(true); + +#if defined(MQTT_USE_TLS) +#if !defined(MQTT_USE_GNU_TLS) c->get_ssl_context().load_verify_file(cacert); +#else + c->get_ssl_context().use_verify_file(cacert, ssl::context::pem); +#endif // !defined(MQTT_USE_GNU_TLS) +#endif // defined(MQTT_USE_TLS) #if OPENSSL_VERSION_NUMBER >= 0x10101000L diff --git a/example/tls_server.cpp b/example/tls_server.cpp index b5ce64c2f..868e586c9 100644 --- a/example/tls_server.cpp +++ b/example/tls_server.cpp @@ -20,18 +20,6 @@ namespace mi = boost::multi_index; using con_t = MQTT_NS::server_tls<>::endpoint_t; using con_sp_t = std::shared_ptr; -// #if defined(MQTT_USE_TLS) -// #if defined(MQTT_USE_GNU_TLS) -// namespace boost -// { -// namespace asio -// { -// namespace ssl = boost::asio::gnutls; -// } -// } -// #endif // defined(MQTT_USE_GNU_TLS) -// #endif // defined(MQTT_USE_TLS) - namespace as = boost::asio; struct sub_con { @@ -82,12 +70,12 @@ int main(int argc, char** argv) { std::string cert = argv[2]; std::string key = argv[3]; - as::ssl::context ctx(as::ssl::context::tlsv12); + ssl::context ctx(ssl::context::tlsv12); ctx.set_options( - as::ssl::context::default_workarounds | - as::ssl::context::single_dh_use); - ctx.use_certificate_file(cert, as::ssl::context::pem); - ctx.use_private_key_file(key, as::ssl::context::pem); + ssl::context::default_workarounds | + ssl::context::single_dh_use); + ctx.use_certificate_file(cert, ssl::context::pem); + ctx.use_private_key_file(key, ssl::context::pem); auto s = MQTT_NS::server_tls<>( boost::asio::ip::tcp::endpoint( diff --git a/example/tls_ws_both.cpp b/example/tls_ws_both.cpp index 7b372e548..0825f366f 100644 --- a/example/tls_ws_both.cpp +++ b/example/tls_ws_both.cpp @@ -16,18 +16,6 @@ #include "locked_cout.hpp" -// #if defined(MQTT_USE_TLS) -// #if defined(MQTT_USE_GNU_TLS) -// namespace boost -// { -// namespace asio -// { -// namespace ssl = boost::asio::gnutls; -// } -// } -// #endif // defined(MQTT_USE_GNU_TLS) -// #endif // defined(MQTT_USE_TLS) - namespace as = boost::asio; template @@ -353,12 +341,12 @@ int main(int argc, char** argv) { std::uint16_t port = boost::lexical_cast(argv[1]); // server - as::ssl::context ctx(as::ssl::context::tlsv12); + ssl::context ctx(ssl::context::tlsv12); ctx.set_options( - as::ssl::context::default_workarounds | - as::ssl::context::single_dh_use); - ctx.use_certificate_file(base + "server.crt.pem", as::ssl::context::pem); - ctx.use_private_key_file(base + "server.key.pem", as::ssl::context::pem); + ssl::context::default_workarounds | + ssl::context::single_dh_use); + ctx.use_certificate_file(base + "server.crt.pem", ssl::context::pem); + ctx.use_private_key_file(base + "server.key.pem", ssl::context::pem); boost::asio::io_context iocs; auto s = MQTT_NS::server_tls_ws<>( @@ -384,7 +372,14 @@ int main(int argc, char** argv) { std::uint16_t pid_sub2; auto c = MQTT_NS::make_tls_sync_client_ws(ioc, "localhost", port); + +#if defined(MQTT_USE_TLS) +#if !defined(MQTT_USE_GNU_TLS) c->get_ssl_context().load_verify_file(base + "cacert.pem"); +#else + c->get_ssl_context().use_verify_file(base + "cacert.pem", ssl::context::pem); +#endif // !defined(MQTT_USE_GNU_TLS) +#endif // defined(MQTT_USE_TLS) int count = 0; auto disconnect = [&] { diff --git a/example/tls_ws_client.cpp b/example/tls_ws_client.cpp index 98d3ea614..1bf11bc21 100644 --- a/example/tls_ws_client.cpp +++ b/example/tls_ws_client.cpp @@ -40,7 +40,14 @@ int main(int argc, char** argv) { // Setup client c->set_client_id("cid1"); c->set_clean_session(true); + +#if defined(MQTT_USE_TLS) +#if !defined(MQTT_USE_GNU_TLS) c->get_ssl_context().load_verify_file(cacert); +#else + c->get_ssl_context().use_verify_file(cacert, ssl::context::pem); +#endif // !defined(MQTT_USE_GNU_TLS) +#endif // defined(MQTT_USE_TLS) // Setup handlers c->set_connack_handler( diff --git a/example/tls_ws_server.cpp b/example/tls_ws_server.cpp index 020c92f12..7a50828b3 100644 --- a/example/tls_ws_server.cpp +++ b/example/tls_ws_server.cpp @@ -20,18 +20,6 @@ namespace mi = boost::multi_index; using con_t = MQTT_NS::server_tls_ws<>::endpoint_t; using con_sp_t = std::shared_ptr; -// #if defined(MQTT_USE_TLS) -// #if defined(MQTT_USE_GNU_TLS) -// namespace boost -// { -// namespace asio -// { -// namespace ssl = boost::asio::gnutls; -// } -// } -// #endif // defined(MQTT_USE_GNU_TLS) -// #endif // defined(MQTT_USE_TLS) - namespace as = boost::asio; struct sub_con { @@ -82,12 +70,12 @@ int main(int argc, char** argv) { std::string cert = argv[2]; std::string key = argv[3]; - as::ssl::context ctx(as::ssl::context::tlsv12); + ssl::context ctx(ssl::context::tlsv12); ctx.set_options( - as::ssl::context::default_workarounds | - as::ssl::context::single_dh_use); - ctx.use_certificate_file(cert, as::ssl::context::pem); - ctx.use_private_key_file(key, as::ssl::context::pem); + ssl::context::default_workarounds | + ssl::context::single_dh_use); + ctx.use_certificate_file(cert, ssl::context::pem); + ctx.use_private_key_file(key, ssl::context::pem); auto s = MQTT_NS::server_tls_ws<>( boost::asio::ip::tcp::endpoint( diff --git a/include/mqtt/async_client.hpp b/include/mqtt/async_client.hpp index 210e63a56..0a32819b6 100644 --- a/include/mqtt/async_client.hpp +++ b/include/mqtt/async_client.hpp @@ -82,7 +82,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_async_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -92,7 +92,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -105,7 +105,7 @@ class async_client : public client { * @return async_client object. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -116,7 +116,7 @@ class async_client : public client { * @param path path string * @return async_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -174,7 +174,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -184,7 +184,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -197,7 +197,7 @@ class async_client : public client { * @return async_client object. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -208,7 +208,7 @@ class async_client : public client { * @param path path string * @return async_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -374,9 +374,9 @@ make_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint1 #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>>; + using async_client_t = async_client, as::io_context::strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -389,7 +389,7 @@ make_tls_async_client(as::io_context& ioc, std::string host, std::string port, p ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client( ioc, @@ -399,9 +399,9 @@ make_tls_async_client(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>>; + using async_client_t = async_client, null_strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -414,7 +414,7 @@ make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::stri ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand( ioc, @@ -426,9 +426,9 @@ make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::uint #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>>; + using async_client_t = async_client, as::io_context::strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -439,7 +439,7 @@ make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_ws( ioc, @@ -450,9 +450,9 @@ make_tls_async_client_ws(as::io_context& ioc, std::string host, std::uint16_t po ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>>; + using async_client_t = async_client, null_strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -463,7 +463,7 @@ make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::s ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_ws( ioc, @@ -585,9 +585,9 @@ make_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::ui #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>, 4>; + using async_client_t = async_client, as::io_context::strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -600,7 +600,7 @@ make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_32( ioc, @@ -610,9 +610,9 @@ make_tls_async_client_32(as::io_context& ioc, std::string host, std::uint16_t po ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>, 4>; + using async_client_t = async_client, null_strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -625,7 +625,7 @@ make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::s ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_32( ioc, @@ -637,9 +637,9 @@ make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::u #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>, 4>; + using async_client_t = async_client, as::io_context::strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -650,7 +650,7 @@ make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string p ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_ws_32( ioc, @@ -661,9 +661,9 @@ make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>, 4>; + using async_client_t = async_client, null_strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -674,7 +674,7 @@ make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/client.hpp b/include/mqtt/client.hpp index bfa1d72d5..408dfbc51 100644 --- a/include/mqtt/client.hpp +++ b/include/mqtt/client.hpp @@ -20,10 +20,7 @@ #include #include -#if defined(MQTT_USE_TLS) #include -#endif // defined(MQTT_USE_TLS) - #include #if defined(MQTT_USE_WS) @@ -39,18 +36,6 @@ namespace MQTT_NS { -// #if defined(MQTT_USE_TLS) -// #if defined(MQTT_USE_GNU_TLS) -// namespace boost -// { -// namespace asio -// { -// namespace ssl = boost::asio::gnutls; -// } -// } -// #endif // defined(MQTT_USE_GNU_TLS) -// #endif // defined(MQTT_USE_TLS) - namespace as = boost::asio; namespace mi = boost::multi_index; @@ -124,7 +109,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -134,7 +119,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -147,7 +132,7 @@ class client : public endpoint { * @return client object. * strand is controlled by ws_endpoint, not endpoint, so client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -158,7 +143,7 @@ class client : public endpoint { * @param path path string * @return client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -216,7 +201,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -226,7 +211,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -239,7 +224,7 @@ class client : public endpoint { * @return client object. * strand is controlled by ws_endpoint, not endpoint, so client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -250,7 +235,7 @@ class client : public endpoint { * @param path path string * @return client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -347,7 +332,7 @@ class client : public endpoint { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context& get_ssl_context() { + ssl::context& get_ssl_context() { static_assert(has_tls>::value, "Client is required to support TLS."); return ctx_; } @@ -356,7 +341,7 @@ class client : public endpoint { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context const& get_ssl_context() const { + ssl::context const& get_ssl_context() const { static_assert(has_tls>::value, "Client is required to support TLS."); return ctx_; } @@ -1029,7 +1014,7 @@ class client : public endpoint { tim_session_expiry_(ioc_) { #if defined(MQTT_USE_TLS) - ctx_.set_verify_mode(as::ssl::verify_peer); + ctx_.set_verify_mode(ssl::verify_peer); #endif // defined(MQTT_USE_TLS) } @@ -1050,14 +1035,14 @@ class client : public endpoint { #if defined(MQTT_USE_TLS) template - void setup_socket(std::shared_ptr, Strand>>& socket) { + void setup_socket(std::shared_ptr, Strand>>& socket) { socket = std::make_shared(ioc_, ctx_); base::socket_optional().emplace(socket); } #if defined(MQTT_USE_WS) template - void setup_socket(std::shared_ptr, Strand>>& socket) { + void setup_socket(std::shared_ptr, Strand>>& socket) { socket = std::make_shared(ioc_, ctx_); base::socket_optional().emplace(socket); } @@ -1144,20 +1129,20 @@ class client : public endpoint { template void handshake_socket( - tcp_endpoint, Strand>& socket, + tcp_endpoint, Strand>& socket, v5::properties props, any session_life_keeper) { - socket.handshake(as::ssl::stream_base::client); + socket.handshake(ssl::stream_base::client); start_session(force_move(props), force_move(session_life_keeper)); } template void handshake_socket( - tcp_endpoint, Strand>& socket, + tcp_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, boost::system::error_code& ec) { - socket.handshake(as::ssl::stream_base::client, ec); + socket.handshake(ssl::stream_base::client, ec); if (ec) return; start_session(force_move(props), force_move(session_life_keeper)); } @@ -1166,21 +1151,21 @@ class client : public endpoint { template void handshake_socket( - ws_endpoint, Strand>& socket, + ws_endpoint, Strand>& socket, v5::properties props, any session_life_keeper) { - socket.next_layer().handshake(as::ssl::stream_base::client); + socket.next_layer().handshake(ssl::stream_base::client); socket.handshake(host_, path_); start_session(force_move(props), force_move(session_life_keeper)); } template void handshake_socket( - ws_endpoint, Strand>& socket, + ws_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, boost::system::error_code& ec) { - socket.next_layer().handshake(as::ssl::stream_base::client, ec); + socket.next_layer().handshake(ssl::stream_base::client, ec); if (ec) return; socket.handshake(host_, path_, ec); if (ec) return; @@ -1231,12 +1216,12 @@ class client : public endpoint { template void async_handshake_socket( - tcp_endpoint, Strand>& socket, + tcp_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, async_handler_t func) { socket.async_handshake( - as::ssl::stream_base::client, + ssl::stream_base::client, [ this, self = this->shared_from_this(), @@ -1256,12 +1241,12 @@ class client : public endpoint { #if defined(MQTT_USE_WS) template void async_handshake_socket( - ws_endpoint, Strand>& socket, + ws_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, async_handler_t func) { socket.next_layer().async_handshake( - as::ssl::stream_base::client, + ssl::stream_base::client, [ this, self = this->shared_from_this(), @@ -1506,12 +1491,12 @@ class client : public endpoint { }; template - struct has_tls, U>>> : std::true_type { + struct has_tls, U>>> : std::true_type { }; #if defined(MQTT_USE_WS) template - struct has_tls, U>>> : std::true_type { + struct has_tls, U>>> : std::true_type { }; #endif // defined(MQTT_USE_WS) @@ -1531,7 +1516,7 @@ class client : public endpoint { optional password_; bool async_pingreq_ = false; #if defined(MQTT_USE_TLS) - as::ssl::context ctx_{as::ssl::context::tlsv12}; + ssl::context ctx_{ssl::context::tlsv12}; #endif // defined(MQTT_USE_TLS) #if defined(MQTT_USE_WS) std::string path_; @@ -1644,9 +1629,9 @@ make_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t po #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>>; + using client_t = client, as::io_context::strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1659,7 +1644,7 @@ make_tls_client(as::io_context& ioc, std::string host, std::string port, protoco ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client( ioc, @@ -1669,9 +1654,9 @@ make_tls_client(as::io_context& ioc, std::string host, std::uint16_t port, proto ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>>; + using client_t = client, null_strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1684,7 +1669,7 @@ make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string por ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand( ioc, @@ -1696,9 +1681,9 @@ make_tls_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t p #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>>; + using client_t = client, as::io_context::strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1709,7 +1694,7 @@ make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std: ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_ws( ioc, @@ -1720,9 +1705,9 @@ make_tls_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, st ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>>; + using client_t = client, null_strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1733,7 +1718,7 @@ make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_ws( ioc, @@ -1855,9 +1840,9 @@ make_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>, 4>; + using client_t = client, as::io_context::strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1870,7 +1855,7 @@ make_tls_client_32(as::io_context& ioc, std::string host, std::string port, prot ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_32( ioc, @@ -1880,9 +1865,9 @@ make_tls_client_32(as::io_context& ioc, std::string host, std::uint16_t port, pr ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>, 4>; + using client_t = client, null_strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1895,7 +1880,7 @@ make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_32( ioc, @@ -1907,9 +1892,9 @@ make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_ #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>, 4>; + using client_t = client, as::io_context::strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1920,7 +1905,7 @@ make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, s ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_ws_32( ioc, @@ -1931,9 +1916,9 @@ make_tls_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>, 4>; + using client_t = client, null_strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1944,7 +1929,7 @@ make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::stri ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/endpoint.hpp b/include/mqtt/endpoint.hpp index 9d3152243..dd80cf817 100644 --- a/include/mqtt/endpoint.hpp +++ b/include/mqtt/endpoint.hpp @@ -150,18 +150,6 @@ constexpr bool should_generate_packet_id(Params const& ... params) { } // namespace detail -// #if defined(MQTT_USE_TLS) -// #if defined(MQTT_USE_GNU_TLS) -// namespace boost -// { -// namespace asio -// { -// namespace ssl = boost::asio::gnutls; -// } -// } -// #endif // defined(MQTT_USE_GNU_TLS) -// #endif // defined(MQTT_USE_TLS) - namespace as = boost::asio; namespace mi = boost::multi_index; @@ -4536,6 +4524,9 @@ class endpoint : public std::enable_shared_from_this void shutdown_from_client(T& socket) { boost::system::error_code ec; + // socket.shutdown(); socket.lowest_layer().close(ec); } diff --git a/include/mqtt/server.hpp b/include/mqtt/server.hpp index 8876c0ff4..85841fe26 100644 --- a/include/mqtt/server.hpp +++ b/include/mqtt/server.hpp @@ -13,20 +13,7 @@ #include #include - -// #if defined(MQTT_USE_TLS) -// #if !defined(MQTT_USE_GNU_TLS) -// #include -// #else -// #include -// #include -// #endif // !defined(MQTT_USE_GNU_TLS) -// #endif // defined(MQTT_USE_TLS) - -#if defined(MQTT_USE_TLS) #include -#endif // defined(MQTT_USE_TLS) - #include #if defined(MQTT_USE_WS) @@ -40,18 +27,6 @@ namespace MQTT_NS { -// #if defined(MQTT_USE_TLS) -// #if defined(MQTT_USE_GNU_TLS) -// namespace boost -// { -// namespace asio -// { -// namespace ssl = boost::asio::gnutls; -// } -// } -// #endif // defined(MQTT_USE_GNU_TLS) -// #endif // defined(MQTT_USE_TLS) - namespace as = boost::asio; template class LockGuard, std::size_t PacketIdBytes> @@ -233,7 +208,7 @@ template < > class server_tls { public: - using socket_t = tcp_endpoint, Strand>; + using socket_t = tcp_endpoint, Strand>; using endpoint_t = callable_overlay>; /** @@ -251,7 +226,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - as::ssl::context&& ctx, + ssl::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con, AcceptorConfig&& config) @@ -267,7 +242,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - as::ssl::context&& ctx, + ssl::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con) : server_tls(std::forward(ep), force_move(ctx), ioc_accept, ioc_con, [](as::ip::tcp::acceptor&) {}) {} @@ -275,7 +250,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - as::ssl::context&& ctx, + ssl::context&& ctx, as::io_context& ioc, AcceptorConfig&& config) : server_tls(std::forward(ep), force_move(ctx), ioc, ioc, std::forward(config)) {} @@ -283,7 +258,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - as::ssl::context&& ctx, + ssl::context&& ctx, as::io_context& ioc) : server_tls(std::forward(ep), force_move(ctx), ioc, ioc, [](as::ip::tcp::acceptor&) {}) {} @@ -370,7 +345,7 @@ class server_tls { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context& get_ssl_context() { + ssl::context& get_ssl_context() { return ctx_; } @@ -378,7 +353,7 @@ class server_tls { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context const& get_ssl_context() const { + ssl::context const& get_ssl_context() const { return ctx_; } @@ -414,7 +389,7 @@ class server_tls { ); auto ps = socket.get(); ps->async_handshake( - as::ssl::stream_base::server, + ssl::stream_base::server, [this, socket = force_move(socket), tim, underlying_finished] (error_code ec) mutable { *underlying_finished = true; @@ -440,7 +415,7 @@ class server_tls { bool close_request_{false}; accept_handler h_accept_; error_handler h_error_; - as::ssl::context ctx_; + ssl::context ctx_; protocol_version version_ = protocol_version::undetermined; std::chrono::steady_clock::duration underlying_connect_timeout_ = std::chrono::seconds(10); }; @@ -722,7 +697,7 @@ template < > class server_tls_ws { public: - using socket_t = ws_endpoint, Strand>; + using socket_t = ws_endpoint, Strand>; using endpoint_t = callable_overlay>; /** @@ -740,7 +715,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - as::ssl::context&& ctx, + ssl::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con, AcceptorConfig&& config) @@ -756,7 +731,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - as::ssl::context&& ctx, + ssl::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con) : server_tls_ws(std::forward(ep), force_move(ctx), ioc_accept, ioc_con, [](as::ip::tcp::acceptor&) {}) {} @@ -764,7 +739,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - as::ssl::context&& ctx, + ssl::context&& ctx, as::io_context& ioc, AcceptorConfig&& config) : server_tls_ws(std::forward(ep), force_move(ctx), ioc, ioc, std::forward(config)) {} @@ -772,7 +747,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - as::ssl::context&& ctx, + ssl::context&& ctx, as::io_context& ioc) : server_tls_ws(std::forward(ep), force_move(ctx), ioc, ioc, [](as::ip::tcp::acceptor&) {}) {} @@ -859,7 +834,7 @@ class server_tls_ws { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context& get_ssl_context() { + ssl::context& get_ssl_context() { return ctx_; } @@ -867,7 +842,7 @@ class server_tls_ws { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context const& get_ssl_context() const { + ssl::context const& get_ssl_context() const { return ctx_; } @@ -904,7 +879,7 @@ class server_tls_ws { auto ps = socket.get(); ps->next_layer().async_handshake( - as::ssl::stream_base::server, + ssl::stream_base::server, [this, socket = force_move(socket), tim, underlying_finished] (error_code ec) mutable { if (ec) { @@ -1008,7 +983,7 @@ class server_tls_ws { bool close_request_{false}; accept_handler h_accept_; error_handler h_error_; - as::ssl::context ctx_; + ssl::context ctx_; protocol_version version_ = protocol_version::undetermined; std::chrono::steady_clock::duration underlying_connect_timeout_ = std::chrono::seconds(10); }; diff --git a/include/mqtt/ssl_implementation.hpp b/include/mqtt/ssl_implementation.hpp index 0be1d9a5f..e136f83e6 100644 --- a/include/mqtt/ssl_implementation.hpp +++ b/include/mqtt/ssl_implementation.hpp @@ -9,23 +9,24 @@ #if defined(MQTT_USE_TLS) #if !defined(MQTT_USE_GNU_TLS) - #include +#include #else - #include - #include +#include +#include +# define ERR_GET_REASON(l) (int)( (l) & 0xFFFL) #endif // !defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) -namespace MQTT_NS { +// namespace MQTT_NS { #if defined(MQTT_USE_TLS) #if !defined(MQTT_USE_GNU_TLS) - namespace ssl = boost::asio::ssl; +namespace ssl = boost::asio::ssl; #else - namespace ssl = boost::asio::gnutls; +namespace ssl = boost::asio::gnutls; #endif // !defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) -} // namespace MQTT_NS +// } // namespace MQTT_NS #endif // MQTT_SSL_IMPLEMENTATION_HPP diff --git a/include/mqtt/sync_client.hpp b/include/mqtt/sync_client.hpp index 79d71485e..559cc99ac 100644 --- a/include/mqtt/sync_client.hpp +++ b/include/mqtt/sync_client.hpp @@ -82,7 +82,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -92,7 +92,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -105,7 +105,7 @@ class sync_client : public client { * @return sync_client object. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -116,7 +116,7 @@ class sync_client : public client { * @param path path string * @return sync_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -174,7 +174,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -184,7 +184,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -197,7 +197,7 @@ class sync_client : public client { * @return sync_client object. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -208,7 +208,7 @@ class sync_client : public client { * @param path path string * @return sync_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -372,9 +372,9 @@ make_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16 #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>>; + using sync_client_t = sync_client, as::io_context::strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -387,7 +387,7 @@ make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, pr ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client( ioc, @@ -397,9 +397,9 @@ make_tls_sync_client(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>>; + using sync_client_t = sync_client, null_strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -412,7 +412,7 @@ make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::strin ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand( ioc, @@ -424,9 +424,9 @@ make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::uint1 #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>>; + using sync_client_t = sync_client, as::io_context::strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -437,7 +437,7 @@ make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_ws( ioc, @@ -448,9 +448,9 @@ make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::uint16_t por ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>>; + using sync_client_t = sync_client, null_strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -461,7 +461,7 @@ make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::st ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_ws( ioc, @@ -583,9 +583,9 @@ make_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uin #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>, 4>; + using sync_client_t = sync_client, as::io_context::strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -598,7 +598,7 @@ make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_32( ioc, @@ -608,9 +608,9 @@ make_tls_sync_client_32(as::io_context& ioc, std::string host, std::uint16_t por ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>, 4>; + using sync_client_t = sync_client, null_strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -623,7 +623,7 @@ make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::st ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_32( ioc, @@ -635,9 +635,9 @@ make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::ui #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>, 4>; + using sync_client_t = sync_client, as::io_context::strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -648,7 +648,7 @@ make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string po ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_ws_32( ioc, @@ -659,9 +659,9 @@ make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>, 4>; + using sync_client_t = sync_client, null_strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -672,7 +672,7 @@ make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std: ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/tcp_endpoint.hpp b/include/mqtt/tcp_endpoint.hpp index 6e7957d08..38123364b 100644 --- a/include/mqtt/tcp_endpoint.hpp +++ b/include/mqtt/tcp_endpoint.hpp @@ -10,19 +10,7 @@ #include #include -// #if defined(MQTT_USE_TLS) -// #if !defined(MQTT_USE_GNU_TLS) -// #include -// #else -// #include -// #include -// #endif // !defined(MQTT_USE_GNU_TLS) -// #endif // defined(MQTT_USE_TLS) - -#if defined(MQTT_USE_TLS) #include -#endif // defined(MQTT_USE_TLS) - #include namespace MQTT_NS { diff --git a/include/mqtt_server_cpp.hpp b/include/mqtt_server_cpp.hpp index 4c6ee6418..dd24c5b70 100644 --- a/include/mqtt_server_cpp.hpp +++ b/include/mqtt_server_cpp.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/test/combi_test.hpp b/test/combi_test.hpp index f4c63b154..e8c3ad972 100644 --- a/test/combi_test.hpp +++ b/test/combi_test.hpp @@ -108,7 +108,15 @@ inline void do_tls_test( std::string path = boost::unit_test::framework::master_test_suite().argv[0]; std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); + +#if defined(MQTT_USE_TLS) +#if !defined(MQTT_USE_GNU_TLS) c->get_ssl_context().load_verify_file(base + "cacert.pem"); +#else + c->get_ssl_context().use_verify_file(base + "cacert.pem", ssl::context::pem); +#endif // !defined(MQTT_USE_GNU_TLS) +#endif // defined(MQTT_USE_TLS) + test( ioc, c, diff --git a/test/test_ctx_init.hpp b/test/test_ctx_init.hpp index def0c4205..b51ba758d 100644 --- a/test/test_ctx_init.hpp +++ b/test/test_ctx_init.hpp @@ -11,43 +11,23 @@ #include -// #if !defined(MQTT_USE_GNU_TLS) -// #include -// #else -// #include -// #include -// #endif // !defined(MQTT_USE_GNU_TLS) - -#if defined(MQTT_USE_TLS) -#include -#endif // defined(MQTT_USE_TLS) - #include "test_settings.hpp" +#include -// #if defined(MQTT_USE_TLS) -// #if defined(MQTT_USE_GNU_TLS) -// namespace boost -// { -// namespace asio -// { -// namespace ssl = boost::asio::gnutls; -// } -// } -// #endif // defined(MQTT_USE_GNU_TLS) -// #endif // defined(MQTT_USE_TLS) +// namespace ssl = boost::asio::gnutls; struct ctx_init { - ctx_init() : ctx(as::ssl::context::tlsv12) { + ctx_init() : ctx(ssl::context::tlsv12) { ctx.set_options( - as::ssl::context::default_workarounds | - as::ssl::context::single_dh_use); + ssl::context::default_workarounds | + ssl::context::single_dh_use); std::string path = boost::unit_test::framework::master_test_suite().argv[0]; std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - ctx.use_certificate_file(base + "server.crt.pem", as::ssl::context::pem); - ctx.use_private_key_file(base + "server.key.pem", as::ssl::context::pem); + ctx.use_certificate_file(base + "server.crt.pem", ssl::context::pem); + ctx.use_private_key_file(base + "server.key.pem", ssl::context::pem); } - as::ssl::context ctx; + ssl::context ctx; }; #endif // defined(MQTT_USE_TLS) diff --git a/test/underlying_timeout.cpp b/test/underlying_timeout.cpp index a953c7061..1fede625a 100644 --- a/test/underlying_timeout.cpp +++ b/test/underlying_timeout.cpp @@ -112,10 +112,17 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_ashs ) { std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - as::ssl::context ctx {as::ssl::context::tlsv12}; + ssl::context ctx {ssl::context::tlsv12}; +#if defined(MQTT_USE_TLS) +#if !defined(MQTT_USE_GNU_TLS) ctx.load_verify_file(base + "cacert.pem"); - ctx.set_verify_mode(as::ssl::verify_peer); - boost::beast::websocket::stream> socket(ioc, ctx); +#else + ctx.use_verify_file(base + "cacert.pem", ssl::context::pem); +#endif // !defined(MQTT_USE_GNU_TLS) +#endif // defined(MQTT_USE_TLS) + + ctx.set_verify_mode(ssl::verify_peer); + boost::beast::websocket::stream> socket(ioc, ctx); char buf; @@ -178,10 +185,17 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_upg ) { std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - as::ssl::context ctx {as::ssl::context::tlsv12}; + ssl::context ctx {ssl::context::tlsv12}; + // ctx.load_verify_file(base + "cacert.pem"); +#if defined(MQTT_USE_TLS) +#if !defined(MQTT_USE_GNU_TLS) ctx.load_verify_file(base + "cacert.pem"); - ctx.set_verify_mode(as::ssl::verify_peer); - boost::beast::websocket::stream> socket(ioc, ctx); +#else + ctx.use_verify_file(base + "cacert.pem", ssl::context::pem); +#endif // !defined(MQTT_USE_GNU_TLS) +#endif // defined(MQTT_USE_TLS) + ctx.set_verify_mode(ssl::verify_peer); + boost::beast::websocket::stream> socket(ioc, ctx); char buf; @@ -200,7 +214,7 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_upg ) { BOOST_TEST(!ec); socket.next_layer().async_handshake( - as::ssl::stream_base::client, + ssl::stream_base::client, [&] (MQTT_NS::error_code ec) { if (ec) { @@ -261,10 +275,23 @@ BOOST_AUTO_TEST_CASE( connect_tls_ashs ) { std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - as::ssl::context ctx {as::ssl::context::tlsv12}; + ssl::context ctx {ssl::context::tlsv12}; + + std::cout << "Setting verify file" << std::endl; + + std::cout << base << std::endl; + // ctx.load_verify_file(base + "cacert.pem"); +#if defined(MQTT_USE_TLS) +#if !defined(MQTT_USE_GNU_TLS) ctx.load_verify_file(base + "cacert.pem"); - ctx.set_verify_mode(as::ssl::verify_peer); - as::ssl::stream socket(ioc, ctx); +#else + ctx.use_verify_file(base + "cacert.pem", ssl::context::pem); +#endif // !defined(MQTT_USE_GNU_TLS) +#endif // defined(MQTT_USE_TLS) + ctx.set_verify_mode(ssl::verify_peer); + ssl::stream socket(ioc, ctx); + + std::cout << "Set verify file" << std::endl; char buf; From 8b9ee52682f8aef9a51d066cd4880e80c700b17a Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Thu, 17 Sep 2020 17:50:12 -0700 Subject: [PATCH 09/32] Remove not condition from ssl_implementation --- include/mqtt/ssl_implementation.hpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/include/mqtt/ssl_implementation.hpp b/include/mqtt/ssl_implementation.hpp index e136f83e6..d7a514dda 100644 --- a/include/mqtt/ssl_implementation.hpp +++ b/include/mqtt/ssl_implementation.hpp @@ -8,25 +8,21 @@ #define MQTT_SSL_IMPLEMENTATION_HPP #if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) -#include -#else +#if defined(MQTT_USE_GNU_TLS) #include #include # define ERR_GET_REASON(l) (int)( (l) & 0xFFFL) -#endif // !defined(MQTT_USE_GNU_TLS) +#else +#include +#endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) -// namespace MQTT_NS { - #if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) -namespace ssl = boost::asio::ssl; -#else +#if defined(MQTT_USE_GNU_TLS) namespace ssl = boost::asio::gnutls; -#endif // !defined(MQTT_USE_GNU_TLS) +#else +namespace ssl = boost::asio::ssl; +#endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) -// } // namespace MQTT_NS - #endif // MQTT_SSL_IMPLEMENTATION_HPP From d3778b36777244e58fe33db52e6e8a18de861cab Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Thu, 17 Sep 2020 17:54:04 -0700 Subject: [PATCH 10/32] remove all not conditions --- example/tls_both.cpp | 8 ++++---- example/tls_client.cpp | 14 +++++++++++--- example/tls_ws_both.cpp | 8 ++++---- example/tls_ws_client.cpp | 8 ++++---- test/combi_test.hpp | 8 ++++---- test/underlying_timeout.cpp | 31 +++++++++++++++++-------------- 6 files changed, 44 insertions(+), 33 deletions(-) diff --git a/example/tls_both.cpp b/example/tls_both.cpp index 92c1a5941..1bb07c2e3 100644 --- a/example/tls_both.cpp +++ b/example/tls_both.cpp @@ -375,11 +375,11 @@ int main(int argc, char** argv) { auto c = MQTT_NS::make_tls_sync_client(ioc, "localhost", port); #if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - c->get_ssl_context().load_verify_file(base + "cacert.pem"); -#else +#if defined(MQTT_USE_GNU_TLS) c->get_ssl_context().use_verify_file(base + "cacert.pem", ssl::context::pem); -#endif // !defined(MQTT_USE_GNU_TLS) +#else + c->get_ssl_context().load_verify_file(base + "cacert.pem"); +#endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) int count = 0; diff --git a/example/tls_client.cpp b/example/tls_client.cpp index eff5d6ec2..3890d9152 100644 --- a/example/tls_client.cpp +++ b/example/tls_client.cpp @@ -41,11 +41,19 @@ int main(int argc, char** argv) { c->set_clean_session(true); #if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - c->get_ssl_context().load_verify_file(cacert); +#if defined(MQTT_USE_GNU_TLS) + c->get_ssl_context().use_verify_file(cacert, ssl::context::pem); #else + c->get_ssl_context().load_verify_file(cacert); +#endif // defined(MQTT_USE_GNU_TLS) +#endif // defined(MQTT_USE_TLS) + +#if defined(MQTT_USE_TLS) +#if defined(MQTT_USE_GNU_TLS) c->get_ssl_context().use_verify_file(cacert, ssl::context::pem); -#endif // !defined(MQTT_USE_GNU_TLS) +#else + c->get_ssl_context().load_verify_file(cacert); +#endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) #if OPENSSL_VERSION_NUMBER >= 0x10101000L diff --git a/example/tls_ws_both.cpp b/example/tls_ws_both.cpp index 0825f366f..d23db0617 100644 --- a/example/tls_ws_both.cpp +++ b/example/tls_ws_both.cpp @@ -374,11 +374,11 @@ int main(int argc, char** argv) { auto c = MQTT_NS::make_tls_sync_client_ws(ioc, "localhost", port); #if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - c->get_ssl_context().load_verify_file(base + "cacert.pem"); -#else +#if defined(MQTT_USE_GNU_TLS) c->get_ssl_context().use_verify_file(base + "cacert.pem", ssl::context::pem); -#endif // !defined(MQTT_USE_GNU_TLS) +#else + c->get_ssl_context().load_verify_file(base + "cacert.pem"); +#endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) int count = 0; diff --git a/example/tls_ws_client.cpp b/example/tls_ws_client.cpp index 1bf11bc21..534f05a0c 100644 --- a/example/tls_ws_client.cpp +++ b/example/tls_ws_client.cpp @@ -42,11 +42,11 @@ int main(int argc, char** argv) { c->set_clean_session(true); #if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - c->get_ssl_context().load_verify_file(cacert); -#else +#if defined(MQTT_USE_GNU_TLS) c->get_ssl_context().use_verify_file(cacert, ssl::context::pem); -#endif // !defined(MQTT_USE_GNU_TLS) +#else + c->get_ssl_context().load_verify_file(cacert); +#endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) // Setup handlers diff --git a/test/combi_test.hpp b/test/combi_test.hpp index e8c3ad972..7cee353f9 100644 --- a/test/combi_test.hpp +++ b/test/combi_test.hpp @@ -110,11 +110,11 @@ inline void do_tls_test( std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); #if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - c->get_ssl_context().load_verify_file(base + "cacert.pem"); -#else +#if defined(MQTT_USE_GNU_TLS) c->get_ssl_context().use_verify_file(base + "cacert.pem", ssl::context::pem); -#endif // !defined(MQTT_USE_GNU_TLS) +#else + c->get_ssl_context().load_verify_file(base + "cacert.pem"); +#endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) test( diff --git a/test/underlying_timeout.cpp b/test/underlying_timeout.cpp index 1fede625a..26f9fb7e9 100644 --- a/test/underlying_timeout.cpp +++ b/test/underlying_timeout.cpp @@ -113,12 +113,13 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_ashs ) { std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); ssl::context ctx {ssl::context::tlsv12}; + #if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - ctx.load_verify_file(base + "cacert.pem"); -#else +#if defined(MQTT_USE_GNU_TLS) ctx.use_verify_file(base + "cacert.pem", ssl::context::pem); -#endif // !defined(MQTT_USE_GNU_TLS) +#else + ctx.load_verify_file(base + "cacert.pem"); +#endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) ctx.set_verify_mode(ssl::verify_peer); @@ -186,14 +187,15 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_upg ) { std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); ssl::context ctx {ssl::context::tlsv12}; - // ctx.load_verify_file(base + "cacert.pem"); + #if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - ctx.load_verify_file(base + "cacert.pem"); -#else +#if defined(MQTT_USE_GNU_TLS) ctx.use_verify_file(base + "cacert.pem", ssl::context::pem); -#endif // !defined(MQTT_USE_GNU_TLS) +#else + ctx.load_verify_file(base + "cacert.pem"); +#endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) + ctx.set_verify_mode(ssl::verify_peer); boost::beast::websocket::stream> socket(ioc, ctx); @@ -280,14 +282,15 @@ BOOST_AUTO_TEST_CASE( connect_tls_ashs ) { std::cout << "Setting verify file" << std::endl; std::cout << base << std::endl; - // ctx.load_verify_file(base + "cacert.pem"); + #if defined(MQTT_USE_TLS) -#if !defined(MQTT_USE_GNU_TLS) - ctx.load_verify_file(base + "cacert.pem"); -#else +#if defined(MQTT_USE_GNU_TLS) ctx.use_verify_file(base + "cacert.pem", ssl::context::pem); -#endif // !defined(MQTT_USE_GNU_TLS) +#else + ctx.load_verify_file(base + "cacert.pem"); +#endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) + ctx.set_verify_mode(ssl::verify_peer); ssl::stream socket(ioc, ctx); From 6eb8d09d8c0ac9da56e282e4d990aa832e6f64ab Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Thu, 17 Sep 2020 17:55:14 -0700 Subject: [PATCH 11/32] Rename to TLS from SSL --- example/tls_both.cpp | 12 ++-- example/tls_client.cpp | 4 +- example/tls_server.cpp | 10 +-- example/tls_ws_both.cpp | 12 ++-- example/tls_ws_client.cpp | 2 +- example/tls_ws_server.cpp | 10 +-- include/CMakeLists.txt | 2 +- include/mqtt/async_client.hpp | 64 ++++++++--------- include/mqtt/client.hpp | 104 ++++++++++++++-------------- include/mqtt/endpoint.hpp | 2 +- include/mqtt/server.hpp | 36 +++++----- include/mqtt/ssl_implementation.hpp | 4 +- include/mqtt/sync_client.hpp | 64 ++++++++--------- test/combi_test.hpp | 2 +- test/test_ctx_init.hpp | 12 ++-- test/underlying_timeout.cpp | 26 +++---- 16 files changed, 183 insertions(+), 183 deletions(-) diff --git a/example/tls_both.cpp b/example/tls_both.cpp index 1bb07c2e3..384ce4689 100644 --- a/example/tls_both.cpp +++ b/example/tls_both.cpp @@ -342,12 +342,12 @@ int main(int argc, char** argv) { std::uint16_t port = boost::lexical_cast(argv[1]); // server - ssl::context ctx(ssl::context::tlsv12); + tls::context ctx(tls::context::tlsv12); ctx.set_options( - ssl::context::default_workarounds | - ssl::context::single_dh_use); - ctx.use_certificate_file(base + "server.crt.pem", ssl::context::pem); - ctx.use_private_key_file(base + "server.key.pem", ssl::context::pem); + tls::context::default_workarounds | + tls::context::single_dh_use); + ctx.use_certificate_file(base + "server.crt.pem", tls::context::pem); + ctx.use_private_key_file(base + "server.key.pem", tls::context::pem); boost::asio::io_context iocs; auto s = MQTT_NS::server_tls<>( @@ -376,7 +376,7 @@ int main(int argc, char** argv) { #if defined(MQTT_USE_TLS) #if defined(MQTT_USE_GNU_TLS) - c->get_ssl_context().use_verify_file(base + "cacert.pem", ssl::context::pem); + c->get_ssl_context().use_verify_file(base + "cacert.pem", tls::context::pem); #else c->get_ssl_context().load_verify_file(base + "cacert.pem"); #endif // defined(MQTT_USE_GNU_TLS) diff --git a/example/tls_client.cpp b/example/tls_client.cpp index 3890d9152..5243d2afa 100644 --- a/example/tls_client.cpp +++ b/example/tls_client.cpp @@ -42,7 +42,7 @@ int main(int argc, char** argv) { #if defined(MQTT_USE_TLS) #if defined(MQTT_USE_GNU_TLS) - c->get_ssl_context().use_verify_file(cacert, ssl::context::pem); + c->get_ssl_context().use_verify_file(cacert, tls::context::pem); #else c->get_ssl_context().load_verify_file(cacert); #endif // defined(MQTT_USE_GNU_TLS) @@ -50,7 +50,7 @@ int main(int argc, char** argv) { #if defined(MQTT_USE_TLS) #if defined(MQTT_USE_GNU_TLS) - c->get_ssl_context().use_verify_file(cacert, ssl::context::pem); + c->get_ssl_context().use_verify_file(cacert, tls::context::pem); #else c->get_ssl_context().load_verify_file(cacert); #endif // defined(MQTT_USE_GNU_TLS) diff --git a/example/tls_server.cpp b/example/tls_server.cpp index 868e586c9..0b4bc8730 100644 --- a/example/tls_server.cpp +++ b/example/tls_server.cpp @@ -70,12 +70,12 @@ int main(int argc, char** argv) { std::string cert = argv[2]; std::string key = argv[3]; - ssl::context ctx(ssl::context::tlsv12); + tls::context ctx(tls::context::tlsv12); ctx.set_options( - ssl::context::default_workarounds | - ssl::context::single_dh_use); - ctx.use_certificate_file(cert, ssl::context::pem); - ctx.use_private_key_file(key, ssl::context::pem); + tls::context::default_workarounds | + tls::context::single_dh_use); + ctx.use_certificate_file(cert, tls::context::pem); + ctx.use_private_key_file(key, tls::context::pem); auto s = MQTT_NS::server_tls<>( boost::asio::ip::tcp::endpoint( diff --git a/example/tls_ws_both.cpp b/example/tls_ws_both.cpp index d23db0617..51668d6e2 100644 --- a/example/tls_ws_both.cpp +++ b/example/tls_ws_both.cpp @@ -341,12 +341,12 @@ int main(int argc, char** argv) { std::uint16_t port = boost::lexical_cast(argv[1]); // server - ssl::context ctx(ssl::context::tlsv12); + tls::context ctx(tls::context::tlsv12); ctx.set_options( - ssl::context::default_workarounds | - ssl::context::single_dh_use); - ctx.use_certificate_file(base + "server.crt.pem", ssl::context::pem); - ctx.use_private_key_file(base + "server.key.pem", ssl::context::pem); + tls::context::default_workarounds | + tls::context::single_dh_use); + ctx.use_certificate_file(base + "server.crt.pem", tls::context::pem); + ctx.use_private_key_file(base + "server.key.pem", tls::context::pem); boost::asio::io_context iocs; auto s = MQTT_NS::server_tls_ws<>( @@ -375,7 +375,7 @@ int main(int argc, char** argv) { #if defined(MQTT_USE_TLS) #if defined(MQTT_USE_GNU_TLS) - c->get_ssl_context().use_verify_file(base + "cacert.pem", ssl::context::pem); + c->get_ssl_context().use_verify_file(base + "cacert.pem", tls::context::pem); #else c->get_ssl_context().load_verify_file(base + "cacert.pem"); #endif // defined(MQTT_USE_GNU_TLS) diff --git a/example/tls_ws_client.cpp b/example/tls_ws_client.cpp index 534f05a0c..ad9000383 100644 --- a/example/tls_ws_client.cpp +++ b/example/tls_ws_client.cpp @@ -43,7 +43,7 @@ int main(int argc, char** argv) { #if defined(MQTT_USE_TLS) #if defined(MQTT_USE_GNU_TLS) - c->get_ssl_context().use_verify_file(cacert, ssl::context::pem); + c->get_ssl_context().use_verify_file(cacert, tls::context::pem); #else c->get_ssl_context().load_verify_file(cacert); #endif // defined(MQTT_USE_GNU_TLS) diff --git a/example/tls_ws_server.cpp b/example/tls_ws_server.cpp index 7a50828b3..ad2ee5512 100644 --- a/example/tls_ws_server.cpp +++ b/example/tls_ws_server.cpp @@ -70,12 +70,12 @@ int main(int argc, char** argv) { std::string cert = argv[2]; std::string key = argv[3]; - ssl::context ctx(ssl::context::tlsv12); + tls::context ctx(tls::context::tlsv12); ctx.set_options( - ssl::context::default_workarounds | - ssl::context::single_dh_use); - ctx.use_certificate_file(cert, ssl::context::pem); - ctx.use_private_key_file(key, ssl::context::pem); + tls::context::default_workarounds | + tls::context::single_dh_use); + ctx.use_certificate_file(cert, tls::context::pem); + ctx.use_private_key_file(key, tls::context::pem); auto s = MQTT_NS::server_tls_ws<>( boost::asio::ip::tcp::endpoint( diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 1683d3da5..8a19ad81a 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -16,7 +16,7 @@ IF(MQTT_USE_STATIC_OPENSSL) TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$:${CMAKE_DL_LIBS} ZLIB::ZLIB>) ENDIF() -TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$,$>>:OpenSSL::SSL>) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$,$>>:Opentls::SSL>) # TODO: Should this be PRIVATE? TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$:${GNUTLS_LIBRARIES}>) diff --git a/include/mqtt/async_client.hpp b/include/mqtt/async_client.hpp index 0a32819b6..d9f46af81 100644 --- a/include/mqtt/async_client.hpp +++ b/include/mqtt/async_client.hpp @@ -82,7 +82,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_async_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -92,7 +92,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -105,7 +105,7 @@ class async_client : public client { * @return async_client object. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -116,7 +116,7 @@ class async_client : public client { * @param path path string * @return async_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -174,7 +174,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -184,7 +184,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -197,7 +197,7 @@ class async_client : public client { * @return async_client object. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -208,7 +208,7 @@ class async_client : public client { * @param path path string * @return async_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -374,9 +374,9 @@ make_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint1 #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>>; + using async_client_t = async_client, as::io_context::strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -389,7 +389,7 @@ make_tls_async_client(as::io_context& ioc, std::string host, std::string port, p ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client( ioc, @@ -399,9 +399,9 @@ make_tls_async_client(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>>; + using async_client_t = async_client, null_strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -414,7 +414,7 @@ make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::stri ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand( ioc, @@ -426,9 +426,9 @@ make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::uint #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>>; + using async_client_t = async_client, as::io_context::strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -439,7 +439,7 @@ make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_ws( ioc, @@ -450,9 +450,9 @@ make_tls_async_client_ws(as::io_context& ioc, std::string host, std::uint16_t po ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>>; + using async_client_t = async_client, null_strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -463,7 +463,7 @@ make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::s ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_ws( ioc, @@ -585,9 +585,9 @@ make_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::ui #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>, 4>; + using async_client_t = async_client, as::io_context::strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -600,7 +600,7 @@ make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_32( ioc, @@ -610,9 +610,9 @@ make_tls_async_client_32(as::io_context& ioc, std::string host, std::uint16_t po ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>, 4>; + using async_client_t = async_client, null_strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -625,7 +625,7 @@ make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::s ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_32( ioc, @@ -637,9 +637,9 @@ make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::u #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>, 4>; + using async_client_t = async_client, as::io_context::strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -650,7 +650,7 @@ make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string p ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_ws_32( ioc, @@ -661,9 +661,9 @@ make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>, 4>; + using async_client_t = async_client, null_strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -674,7 +674,7 @@ make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/client.hpp b/include/mqtt/client.hpp index 408dfbc51..371e3a36d 100644 --- a/include/mqtt/client.hpp +++ b/include/mqtt/client.hpp @@ -109,7 +109,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -119,7 +119,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -132,7 +132,7 @@ class client : public endpoint { * @return client object. * strand is controlled by ws_endpoint, not endpoint, so client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -143,7 +143,7 @@ class client : public endpoint { * @param path path string * @return client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -201,7 +201,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -211,7 +211,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -224,7 +224,7 @@ class client : public endpoint { * @return client object. * strand is controlled by ws_endpoint, not endpoint, so client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -235,7 +235,7 @@ class client : public endpoint { * @param path path string * @return client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -332,7 +332,7 @@ class client : public endpoint { * @brief Get boost asio ssl context. * @return ssl context */ - ssl::context& get_ssl_context() { + tls::context& get_ssl_context() { static_assert(has_tls>::value, "Client is required to support TLS."); return ctx_; } @@ -341,7 +341,7 @@ class client : public endpoint { * @brief Get boost asio ssl context. * @return ssl context */ - ssl::context const& get_ssl_context() const { + tls::context const& get_ssl_context() const { static_assert(has_tls>::value, "Client is required to support TLS."); return ctx_; } @@ -1014,7 +1014,7 @@ class client : public endpoint { tim_session_expiry_(ioc_) { #if defined(MQTT_USE_TLS) - ctx_.set_verify_mode(ssl::verify_peer); + ctx_.set_verify_mode(tls::verify_peer); #endif // defined(MQTT_USE_TLS) } @@ -1035,14 +1035,14 @@ class client : public endpoint { #if defined(MQTT_USE_TLS) template - void setup_socket(std::shared_ptr, Strand>>& socket) { + void setup_socket(std::shared_ptr, Strand>>& socket) { socket = std::make_shared(ioc_, ctx_); base::socket_optional().emplace(socket); } #if defined(MQTT_USE_WS) template - void setup_socket(std::shared_ptr, Strand>>& socket) { + void setup_socket(std::shared_ptr, Strand>>& socket) { socket = std::make_shared(ioc_, ctx_); base::socket_optional().emplace(socket); } @@ -1129,20 +1129,20 @@ class client : public endpoint { template void handshake_socket( - tcp_endpoint, Strand>& socket, + tcp_endpoint, Strand>& socket, v5::properties props, any session_life_keeper) { - socket.handshake(ssl::stream_base::client); + socket.handshake(tls::stream_base::client); start_session(force_move(props), force_move(session_life_keeper)); } template void handshake_socket( - tcp_endpoint, Strand>& socket, + tcp_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, boost::system::error_code& ec) { - socket.handshake(ssl::stream_base::client, ec); + socket.handshake(tls::stream_base::client, ec); if (ec) return; start_session(force_move(props), force_move(session_life_keeper)); } @@ -1151,21 +1151,21 @@ class client : public endpoint { template void handshake_socket( - ws_endpoint, Strand>& socket, + ws_endpoint, Strand>& socket, v5::properties props, any session_life_keeper) { - socket.next_layer().handshake(ssl::stream_base::client); + socket.next_layer().handshake(tls::stream_base::client); socket.handshake(host_, path_); start_session(force_move(props), force_move(session_life_keeper)); } template void handshake_socket( - ws_endpoint, Strand>& socket, + ws_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, boost::system::error_code& ec) { - socket.next_layer().handshake(ssl::stream_base::client, ec); + socket.next_layer().handshake(tls::stream_base::client, ec); if (ec) return; socket.handshake(host_, path_, ec); if (ec) return; @@ -1216,12 +1216,12 @@ class client : public endpoint { template void async_handshake_socket( - tcp_endpoint, Strand>& socket, + tcp_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, async_handler_t func) { socket.async_handshake( - ssl::stream_base::client, + tls::stream_base::client, [ this, self = this->shared_from_this(), @@ -1241,12 +1241,12 @@ class client : public endpoint { #if defined(MQTT_USE_WS) template void async_handshake_socket( - ws_endpoint, Strand>& socket, + ws_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, async_handler_t func) { socket.next_layer().async_handshake( - ssl::stream_base::client, + tls::stream_base::client, [ this, self = this->shared_from_this(), @@ -1491,12 +1491,12 @@ class client : public endpoint { }; template - struct has_tls, U>>> : std::true_type { + struct has_tls, U>>> : std::true_type { }; #if defined(MQTT_USE_WS) template - struct has_tls, U>>> : std::true_type { + struct has_tls, U>>> : std::true_type { }; #endif // defined(MQTT_USE_WS) @@ -1516,7 +1516,7 @@ class client : public endpoint { optional password_; bool async_pingreq_ = false; #if defined(MQTT_USE_TLS) - ssl::context ctx_{ssl::context::tlsv12}; + tls::context ctx_{tls::context::tlsv12}; #endif // defined(MQTT_USE_TLS) #if defined(MQTT_USE_WS) std::string path_; @@ -1629,9 +1629,9 @@ make_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t po #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>>; + using client_t = client, as::io_context::strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1644,7 +1644,7 @@ make_tls_client(as::io_context& ioc, std::string host, std::string port, protoco ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client( ioc, @@ -1654,9 +1654,9 @@ make_tls_client(as::io_context& ioc, std::string host, std::uint16_t port, proto ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>>; + using client_t = client, null_strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1669,7 +1669,7 @@ make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string por ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand( ioc, @@ -1681,9 +1681,9 @@ make_tls_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t p #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>>; + using client_t = client, as::io_context::strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1694,7 +1694,7 @@ make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std: ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_ws( ioc, @@ -1705,9 +1705,9 @@ make_tls_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, st ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>>; + using client_t = client, null_strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1718,7 +1718,7 @@ make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_ws( ioc, @@ -1840,9 +1840,9 @@ make_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>, 4>; + using client_t = client, as::io_context::strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1855,7 +1855,7 @@ make_tls_client_32(as::io_context& ioc, std::string host, std::string port, prot ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_32( ioc, @@ -1865,9 +1865,9 @@ make_tls_client_32(as::io_context& ioc, std::string host, std::uint16_t port, pr ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>, 4>; + using client_t = client, null_strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1880,7 +1880,7 @@ make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_32( ioc, @@ -1892,9 +1892,9 @@ make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_ #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>, 4>; + using client_t = client, as::io_context::strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1905,7 +1905,7 @@ make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, s ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_ws_32( ioc, @@ -1916,9 +1916,9 @@ make_tls_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>, 4>; + using client_t = client, null_strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1929,7 +1929,7 @@ make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::stri ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/endpoint.hpp b/include/mqtt/endpoint.hpp index dd80cf817..50f104a2d 100644 --- a/include/mqtt/endpoint.hpp +++ b/include/mqtt/endpoint.hpp @@ -4544,7 +4544,7 @@ class endpoint : public std::enable_shared_from_this class server_tls { public: - using socket_t = tcp_endpoint, Strand>; + using socket_t = tcp_endpoint, Strand>; using endpoint_t = callable_overlay>; /** @@ -226,7 +226,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con, AcceptorConfig&& config) @@ -242,7 +242,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con) : server_tls(std::forward(ep), force_move(ctx), ioc_accept, ioc_con, [](as::ip::tcp::acceptor&) {}) {} @@ -250,7 +250,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc, AcceptorConfig&& config) : server_tls(std::forward(ep), force_move(ctx), ioc, ioc, std::forward(config)) {} @@ -258,7 +258,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc) : server_tls(std::forward(ep), force_move(ctx), ioc, ioc, [](as::ip::tcp::acceptor&) {}) {} @@ -345,7 +345,7 @@ class server_tls { * @brief Get boost asio ssl context. * @return ssl context */ - ssl::context& get_ssl_context() { + tls::context& get_ssl_context() { return ctx_; } @@ -353,7 +353,7 @@ class server_tls { * @brief Get boost asio ssl context. * @return ssl context */ - ssl::context const& get_ssl_context() const { + tls::context const& get_ssl_context() const { return ctx_; } @@ -389,7 +389,7 @@ class server_tls { ); auto ps = socket.get(); ps->async_handshake( - ssl::stream_base::server, + tls::stream_base::server, [this, socket = force_move(socket), tim, underlying_finished] (error_code ec) mutable { *underlying_finished = true; @@ -415,7 +415,7 @@ class server_tls { bool close_request_{false}; accept_handler h_accept_; error_handler h_error_; - ssl::context ctx_; + tls::context ctx_; protocol_version version_ = protocol_version::undetermined; std::chrono::steady_clock::duration underlying_connect_timeout_ = std::chrono::seconds(10); }; @@ -697,7 +697,7 @@ template < > class server_tls_ws { public: - using socket_t = ws_endpoint, Strand>; + using socket_t = ws_endpoint, Strand>; using endpoint_t = callable_overlay>; /** @@ -715,7 +715,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con, AcceptorConfig&& config) @@ -731,7 +731,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con) : server_tls_ws(std::forward(ep), force_move(ctx), ioc_accept, ioc_con, [](as::ip::tcp::acceptor&) {}) {} @@ -739,7 +739,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc, AcceptorConfig&& config) : server_tls_ws(std::forward(ep), force_move(ctx), ioc, ioc, std::forward(config)) {} @@ -747,7 +747,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc) : server_tls_ws(std::forward(ep), force_move(ctx), ioc, ioc, [](as::ip::tcp::acceptor&) {}) {} @@ -834,7 +834,7 @@ class server_tls_ws { * @brief Get boost asio ssl context. * @return ssl context */ - ssl::context& get_ssl_context() { + tls::context& get_ssl_context() { return ctx_; } @@ -842,7 +842,7 @@ class server_tls_ws { * @brief Get boost asio ssl context. * @return ssl context */ - ssl::context const& get_ssl_context() const { + tls::context const& get_ssl_context() const { return ctx_; } @@ -879,7 +879,7 @@ class server_tls_ws { auto ps = socket.get(); ps->next_layer().async_handshake( - ssl::stream_base::server, + tls::stream_base::server, [this, socket = force_move(socket), tim, underlying_finished] (error_code ec) mutable { if (ec) { @@ -983,7 +983,7 @@ class server_tls_ws { bool close_request_{false}; accept_handler h_accept_; error_handler h_error_; - ssl::context ctx_; + tls::context ctx_; protocol_version version_ = protocol_version::undetermined; std::chrono::steady_clock::duration underlying_connect_timeout_ = std::chrono::seconds(10); }; diff --git a/include/mqtt/ssl_implementation.hpp b/include/mqtt/ssl_implementation.hpp index d7a514dda..056e4f76d 100644 --- a/include/mqtt/ssl_implementation.hpp +++ b/include/mqtt/ssl_implementation.hpp @@ -19,9 +19,9 @@ #if defined(MQTT_USE_TLS) #if defined(MQTT_USE_GNU_TLS) -namespace ssl = boost::asio::gnutls; +namespace tls = boost::asio::gnutls; #else -namespace ssl = boost::asio::ssl; +namespace tls = boost::asio::ssl; #endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) diff --git a/include/mqtt/sync_client.hpp b/include/mqtt/sync_client.hpp index 559cc99ac..2cc2c4305 100644 --- a/include/mqtt/sync_client.hpp +++ b/include/mqtt/sync_client.hpp @@ -82,7 +82,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -92,7 +92,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -105,7 +105,7 @@ class sync_client : public client { * @return sync_client object. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -116,7 +116,7 @@ class sync_client : public client { * @param path path string * @return sync_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -174,7 +174,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -184,7 +184,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -197,7 +197,7 @@ class sync_client : public client { * @return sync_client object. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -208,7 +208,7 @@ class sync_client : public client { * @param path path string * @return sync_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -372,9 +372,9 @@ make_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16 #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>>; + using sync_client_t = sync_client, as::io_context::strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -387,7 +387,7 @@ make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, pr ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client( ioc, @@ -397,9 +397,9 @@ make_tls_sync_client(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>>; + using sync_client_t = sync_client, null_strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -412,7 +412,7 @@ make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::strin ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand( ioc, @@ -424,9 +424,9 @@ make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::uint1 #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>>; + using sync_client_t = sync_client, as::io_context::strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -437,7 +437,7 @@ make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_ws( ioc, @@ -448,9 +448,9 @@ make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::uint16_t por ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>>; + using sync_client_t = sync_client, null_strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -461,7 +461,7 @@ make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::st ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_ws( ioc, @@ -583,9 +583,9 @@ make_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uin #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>, 4>; + using sync_client_t = sync_client, as::io_context::strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -598,7 +598,7 @@ make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_32( ioc, @@ -608,9 +608,9 @@ make_tls_sync_client_32(as::io_context& ioc, std::string host, std::uint16_t por ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>, 4>; + using sync_client_t = sync_client, null_strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -623,7 +623,7 @@ make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::st ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_32( ioc, @@ -635,9 +635,9 @@ make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::ui #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>, 4>; + using sync_client_t = sync_client, as::io_context::strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -648,7 +648,7 @@ make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string po ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_ws_32( ioc, @@ -659,9 +659,9 @@ make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>, 4>; + using sync_client_t = sync_client, null_strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -672,7 +672,7 @@ make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std: ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_ws_32( ioc, diff --git a/test/combi_test.hpp b/test/combi_test.hpp index 7cee353f9..c9467245e 100644 --- a/test/combi_test.hpp +++ b/test/combi_test.hpp @@ -111,7 +111,7 @@ inline void do_tls_test( #if defined(MQTT_USE_TLS) #if defined(MQTT_USE_GNU_TLS) - c->get_ssl_context().use_verify_file(base + "cacert.pem", ssl::context::pem); + c->get_ssl_context().use_verify_file(base + "cacert.pem", tls::context::pem); #else c->get_ssl_context().load_verify_file(base + "cacert.pem"); #endif // defined(MQTT_USE_GNU_TLS) diff --git a/test/test_ctx_init.hpp b/test/test_ctx_init.hpp index b51ba758d..1831d6480 100644 --- a/test/test_ctx_init.hpp +++ b/test/test_ctx_init.hpp @@ -17,17 +17,17 @@ // namespace ssl = boost::asio::gnutls; struct ctx_init { - ctx_init() : ctx(ssl::context::tlsv12) { + ctx_init() : ctx(tls::context::tlsv12) { ctx.set_options( - ssl::context::default_workarounds | - ssl::context::single_dh_use); + tls::context::default_workarounds | + tls::context::single_dh_use); std::string path = boost::unit_test::framework::master_test_suite().argv[0]; std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - ctx.use_certificate_file(base + "server.crt.pem", ssl::context::pem); - ctx.use_private_key_file(base + "server.key.pem", ssl::context::pem); + ctx.use_certificate_file(base + "server.crt.pem", tls::context::pem); + ctx.use_private_key_file(base + "server.key.pem", tls::context::pem); } - ssl::context ctx; + tls::context ctx; }; #endif // defined(MQTT_USE_TLS) diff --git a/test/underlying_timeout.cpp b/test/underlying_timeout.cpp index 26f9fb7e9..8454bfb23 100644 --- a/test/underlying_timeout.cpp +++ b/test/underlying_timeout.cpp @@ -112,18 +112,18 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_ashs ) { std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - ssl::context ctx {ssl::context::tlsv12}; + tls::context ctx {tls::context::tlsv12}; #if defined(MQTT_USE_TLS) #if defined(MQTT_USE_GNU_TLS) - ctx.use_verify_file(base + "cacert.pem", ssl::context::pem); + ctx.use_verify_file(base + "cacert.pem", tls::context::pem); #else ctx.load_verify_file(base + "cacert.pem"); #endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) - ctx.set_verify_mode(ssl::verify_peer); - boost::beast::websocket::stream> socket(ioc, ctx); + ctx.set_verify_mode(tls::verify_peer); + boost::beast::websocket::stream> socket(ioc, ctx); char buf; @@ -186,18 +186,18 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_upg ) { std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - ssl::context ctx {ssl::context::tlsv12}; + tls::context ctx {tls::context::tlsv12}; #if defined(MQTT_USE_TLS) #if defined(MQTT_USE_GNU_TLS) - ctx.use_verify_file(base + "cacert.pem", ssl::context::pem); + ctx.use_verify_file(base + "cacert.pem", tls::context::pem); #else ctx.load_verify_file(base + "cacert.pem"); #endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) - ctx.set_verify_mode(ssl::verify_peer); - boost::beast::websocket::stream> socket(ioc, ctx); + ctx.set_verify_mode(tls::verify_peer); + boost::beast::websocket::stream> socket(ioc, ctx); char buf; @@ -216,7 +216,7 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_upg ) { BOOST_TEST(!ec); socket.next_layer().async_handshake( - ssl::stream_base::client, + tls::stream_base::client, [&] (MQTT_NS::error_code ec) { if (ec) { @@ -277,7 +277,7 @@ BOOST_AUTO_TEST_CASE( connect_tls_ashs ) { std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - ssl::context ctx {ssl::context::tlsv12}; + tls::context ctx {tls::context::tlsv12}; std::cout << "Setting verify file" << std::endl; @@ -285,14 +285,14 @@ BOOST_AUTO_TEST_CASE( connect_tls_ashs ) { #if defined(MQTT_USE_TLS) #if defined(MQTT_USE_GNU_TLS) - ctx.use_verify_file(base + "cacert.pem", ssl::context::pem); + ctx.use_verify_file(base + "cacert.pem", tls::context::pem); #else ctx.load_verify_file(base + "cacert.pem"); #endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) - ctx.set_verify_mode(ssl::verify_peer); - ssl::stream socket(ioc, ctx); + ctx.set_verify_mode(tls::verify_peer); + tls::stream socket(ioc, ctx); std::cout << "Set verify file" << std::endl; From 52ef72d3d4c24a962b12f4629cb9d23378188aa2 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Thu, 17 Sep 2020 17:57:02 -0700 Subject: [PATCH 12/32] Rename file to tls_implementation.hpp --- include/mqtt/client.hpp | 2 +- include/mqtt/server.hpp | 2 +- include/mqtt/tcp_endpoint.hpp | 2 +- .../mqtt/{ssl_implementation.hpp => tls_implementation.hpp} | 6 +++--- include/mqtt_client_cpp.hpp | 2 +- include/mqtt_server_cpp.hpp | 2 +- test/test_ctx_init.hpp | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) rename include/mqtt/{ssl_implementation.hpp => tls_implementation.hpp} (85%) diff --git a/include/mqtt/client.hpp b/include/mqtt/client.hpp index 371e3a36d..6b87ab72e 100644 --- a/include/mqtt/client.hpp +++ b/include/mqtt/client.hpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include #if defined(MQTT_USE_WS) diff --git a/include/mqtt/server.hpp b/include/mqtt/server.hpp index 9da21fd51..2f62a7ea4 100644 --- a/include/mqtt/server.hpp +++ b/include/mqtt/server.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #if defined(MQTT_USE_WS) diff --git a/include/mqtt/tcp_endpoint.hpp b/include/mqtt/tcp_endpoint.hpp index 38123364b..4c813a750 100644 --- a/include/mqtt/tcp_endpoint.hpp +++ b/include/mqtt/tcp_endpoint.hpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include namespace MQTT_NS { diff --git a/include/mqtt/ssl_implementation.hpp b/include/mqtt/tls_implementation.hpp similarity index 85% rename from include/mqtt/ssl_implementation.hpp rename to include/mqtt/tls_implementation.hpp index 056e4f76d..d642c38ad 100644 --- a/include/mqtt/ssl_implementation.hpp +++ b/include/mqtt/tls_implementation.hpp @@ -4,8 +4,8 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#if !defined(MQTT_SSL_IMPLEMENTATION_HPP) -#define MQTT_SSL_IMPLEMENTATION_HPP +#if !defined(MQTT_TLS_IMPLEMENTATION_HPP) +#define MQTT_TLS_IMPLEMENTATION_HPP #if defined(MQTT_USE_TLS) #if defined(MQTT_USE_GNU_TLS) @@ -25,4 +25,4 @@ namespace tls = boost::asio::ssl; #endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) -#endif // MQTT_SSL_IMPLEMENTATION_HPP +#endif // MQTT_tls_implementation_HPP diff --git a/include/mqtt_client_cpp.hpp b/include/mqtt_client_cpp.hpp index 17a8eabd7..32143e0af 100644 --- a/include/mqtt_client_cpp.hpp +++ b/include/mqtt_client_cpp.hpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/mqtt_server_cpp.hpp b/include/mqtt_server_cpp.hpp index dd24c5b70..197c02e93 100644 --- a/include/mqtt_server_cpp.hpp +++ b/include/mqtt_server_cpp.hpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/test/test_ctx_init.hpp b/test/test_ctx_init.hpp index 1831d6480..059c4b2f1 100644 --- a/test/test_ctx_init.hpp +++ b/test/test_ctx_init.hpp @@ -12,7 +12,7 @@ #include #include "test_settings.hpp" -#include +#include // namespace ssl = boost::asio::gnutls; From 10e6871ff050d5dda56a318256022d5741558324 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 10:25:00 -0700 Subject: [PATCH 13/32] Update yaml files + cmake module --- .github/workflows/gha.yml | 9 ++++++ azure-pipelines.yml | 50 ++++++++++++++++++++++++++++- cmake/FindBoostAsioGnuTLS.cmake | 4 +-- include/mqtt/tls_implementation.hpp | 1 - 4 files changed, 60 insertions(+), 4 deletions(-) diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml index 0c3ebff0c..e3851cbe7 100644 --- a/.github/workflows/gha.yml +++ b/.github/workflows/gha.yml @@ -20,6 +20,10 @@ jobs: - '-DMQTT_TEST_1=ON -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON' - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF' - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=ON -DMQTT_TEST_7=ON -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF' + - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=ON -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=OFF -DMQTT_USE_GNU_TLS=ON' + - '-DMQTT_TEST_1=ON -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_USE_GNU_TLS=ON' + - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_USE_GNU_TLS=ON' + - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=ON -DMQTT_TEST_7=ON -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_USE_GNU_TLS=ON' steps: - name: Checkout uses: actions/checkout@v2 @@ -66,6 +70,11 @@ jobs: [ ${{ matrix.pattern }} == 5 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=ON -DMQTT_TEST_4=ON -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" [ ${{ matrix.pattern }} == 6 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" [ ${{ matrix.pattern }} == 7 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" + [ ${{ matrix.pattern }} == 1 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" + [ ${{ matrix.pattern }} == 2 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=ON -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" + [ ${{ matrix.pattern }} == 3 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" + [ ${{ matrix.pattern }} == 6 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" + [ ${{ matrix.pattern }} == 7 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" cmake -S ${{ github.workspace }} -B ${{ runner.temp }} ${FLAGS} -DBOOSTROOT=/usr - name: Check Header Dependencies diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 8769abc0a..978462ccf 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -28,6 +28,18 @@ strategy: MQTT_TEST_5: OFF MQTT_TEST_6: OFF MQTT_BUILD_EXAMPLES: ON + ExamplesGnuTls: + MQTT_USE_TLS: ON + MQTT_USE_GNU_TLS: ON + MQTT_USE_WS: OFF + MQTT_USE_STR_CHECK: ON + MQTT_TEST_1: OFF + MQTT_TEST_2: OFF + MQTT_TEST_3: OFF + MQTT_TEST_4: OFF + MQTT_TEST_5: OFF + MQTT_TEST_6: OFF + MQTT_BUILD_EXAMPLES: ON ExamplesWs: MQTT_USE_TLS: OFF MQTT_USE_WS: ON @@ -116,6 +128,42 @@ strategy: MQTT_TEST_5: OFF MQTT_TEST_6: ON MQTT_BUILD_EXAMPLES: OFF + TestGroup8: + MQTT_USE_TLS: ON + MQTT_USE_GNU_TLS: ON + MQTT_USE_WS: OFF + MQTT_USE_STR_CHECK: OFF + MQTT_TEST_1: ON + MQTT_TEST_2: OFF + MQTT_TEST_3: OFF + MQTT_TEST_4: OFF + MQTT_TEST_5: OFF + MQTT_TEST_6: OFF + MQTT_BUILD_EXAMPLES: OFF + TestGroup9: + MQTT_USE_TLS: ON + MQTT_USE_GNU_TLS: ON + MQTT_USE_WS: OFF + MQTT_USE_STR_CHECK: ON + MQTT_TEST_1: OFF + MQTT_TEST_2: OFF + MQTT_TEST_3: ON + MQTT_TEST_4: OFF + MQTT_TEST_5: OFF + MQTT_TEST_6: OFF + MQTT_BUILD_EXAMPLES: OFF + TestGroup10: + MQTT_USE_TLS: ON + MQTT_USE_GNU_TLS: ON + MQTT_USE_WS: OFF + MQTT_USE_STR_CHECK: ON + MQTT_TEST_1: OFF + MQTT_TEST_2: OFF + MQTT_TEST_3: OFF + MQTT_TEST_4: OFF + MQTT_TEST_5: OFF + MQTT_TEST_6: ON + MQTT_BUILD_EXAMPLES: OFF steps: - script: | @@ -127,7 +175,7 @@ steps: mkdir build cd build set CL=/D_WIN32_WINNT#0x0601 - cmake -A x64 -DMQTT_USE_TLS=%MQTT_USE_TLS% -DMQTT_USE_WS=%MQTT_USE_WS% -DMQTT_USE_STR_CHECK=%MQTT_USE_STR_CHECK% -DMQTT_TEST_1=%MQTT_TEST_1% -DMQTT_TEST_2=%MQTT_TEST_2% -DMQTT_TEST_3=%MQTT_TEST_3% -DMQTT_TEST_4=%MQTT_TEST_4% -DMQTT_TEST_5=%MQTT_TEST_5% -DMQTT_TEST_6=%MQTT_TEST_6% -DMQTT_BUILD_EXAMPLES=%MQTT_BUILD_EXAMPLES% .. + cmake -A x64 -DMQTT_USE_TLS=%MQTT_USE_TLS% -DMQTT_USE_GNU_TLS=%MQTT_USE_GNU_TLS% -DMQTT_USE_WS=%MQTT_USE_WS% -DMQTT_USE_STR_CHECK=%MQTT_USE_STR_CHECK% -DMQTT_TEST_1=%MQTT_TEST_1% -DMQTT_TEST_2=%MQTT_TEST_2% -DMQTT_TEST_3=%MQTT_TEST_3% -DMQTT_TEST_4=%MQTT_TEST_4% -DMQTT_TEST_5=%MQTT_TEST_5% -DMQTT_TEST_6=%MQTT_TEST_6% -DMQTT_BUILD_EXAMPLES=%MQTT_BUILD_EXAMPLES% .. cmake --build . --config Release -- -verbosity:minimal cd test set PATH=%BOOST_ROOT%\lib;%PATH% diff --git a/cmake/FindBoostAsioGnuTLS.cmake b/cmake/FindBoostAsioGnuTLS.cmake index db7eaa9a1..a2fd9cffd 100644 --- a/cmake/FindBoostAsioGnuTLS.cmake +++ b/cmake/FindBoostAsioGnuTLS.cmake @@ -1,4 +1,4 @@ -find_path(BoostAsioGnuTLS_INCLUDE_DIR NAMES boost-asio-gnutls/boost/asio/gnutls.hpp) +find_path(BoostAsioGnuTLS_INCLUDE_DIR NAMES boost/asio/gnutls.hpp) mark_as_advanced(BoostAsioGnuTLS_INCLUDE_DIR) @@ -10,5 +10,5 @@ find_package_handle_standard_args(BoostAsioGnuTLS ) if(BoostAsioGnuTLS_FOUND) - set(BoostAsioGnuTLS_INCLUDE_DIRS /usr/local/include/boost-asio-gnutls/ ${BoostAsioGnuTLS_INCLUDE_DIR}) + set(BoostAsioGnuTLS_INCLUDE_DIRS ${BoostAsioGnuTLS_INCLUDE_DIR}) endif() \ No newline at end of file diff --git a/include/mqtt/tls_implementation.hpp b/include/mqtt/tls_implementation.hpp index d642c38ad..cde1fb769 100644 --- a/include/mqtt/tls_implementation.hpp +++ b/include/mqtt/tls_implementation.hpp @@ -10,7 +10,6 @@ #if defined(MQTT_USE_TLS) #if defined(MQTT_USE_GNU_TLS) #include -#include # define ERR_GET_REASON(l) (int)( (l) & 0xFFFL) #else #include From 0aa328868223256f3b536e68c71be97d565a6c62 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 10:26:01 -0700 Subject: [PATCH 14/32] Update gitignore --- .gitignore | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5e75662d2..e9d3e9d63 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,7 @@ CMakeLists.txt.user* -build/ \ No newline at end of file + +# Build artifacts +build/ + +# VS code settings +.vscode/ \ No newline at end of file From abf1536e335ad832050f7695e4eafdc5a9235752 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 10:37:56 -0700 Subject: [PATCH 15/32] cosmetic fixes --- CMakeLists.txt | 8 ++++---- cmake/FindBoostAsioGnuTLS.cmake | 2 +- example/tls_both.cpp | 2 -- example/tls_client.cpp | 8 -------- example/tls_server.cpp | 2 -- example/tls_ws_both.cpp | 2 -- example/tls_ws_server.cpp | 2 -- include/CMakeLists.txt | 6 ++---- include/mqtt/endpoint.hpp | 4 ---- include/mqtt/tls_implementation.hpp | 1 + test/test_ctx_init.hpp | 2 -- test/underlying_timeout.cpp | 4 ---- 12 files changed, 8 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 484d44033..f08d4e492 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,14 +139,14 @@ ELSE () ENDIF () IF (MQTT_USE_TLS) - IF (NOT MQTT_USE_GNU_TLS) + IF (MQTT_USE_GNU_TLS) + FIND_PACKAGE (GnuTLS REQUIRED) + # FIND_PACKAGE (BoostAsioGnuTLS REQUIRED) + ELSE () FIND_PACKAGE (OpenSSL REQUIRED) IF (MQTT_USE_STATIC_OPENSSL) FIND_PACKAGE (ZLIB REQUIRED) ENDIF () - ELSE () - find_package(GnuTLS REQUIRED) - find_package(BoostAsioGnuTLS REQUIRED) ENDIF () ENDIF () diff --git a/cmake/FindBoostAsioGnuTLS.cmake b/cmake/FindBoostAsioGnuTLS.cmake index a2fd9cffd..6fa06b54a 100644 --- a/cmake/FindBoostAsioGnuTLS.cmake +++ b/cmake/FindBoostAsioGnuTLS.cmake @@ -11,4 +11,4 @@ find_package_handle_standard_args(BoostAsioGnuTLS if(BoostAsioGnuTLS_FOUND) set(BoostAsioGnuTLS_INCLUDE_DIRS ${BoostAsioGnuTLS_INCLUDE_DIR}) -endif() \ No newline at end of file +endif() diff --git a/example/tls_both.cpp b/example/tls_both.cpp index 384ce4689..2ab673667 100644 --- a/example/tls_both.cpp +++ b/example/tls_both.cpp @@ -16,8 +16,6 @@ #include "locked_cout.hpp" -namespace as = boost::asio; - template void client_proc( Client& c, diff --git a/example/tls_client.cpp b/example/tls_client.cpp index 5243d2afa..602406936 100644 --- a/example/tls_client.cpp +++ b/example/tls_client.cpp @@ -48,14 +48,6 @@ int main(int argc, char** argv) { #endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) -#if defined(MQTT_USE_TLS) -#if defined(MQTT_USE_GNU_TLS) - c->get_ssl_context().use_verify_file(cacert, tls::context::pem); -#else - c->get_ssl_context().load_verify_file(cacert); -#endif // defined(MQTT_USE_GNU_TLS) -#endif // defined(MQTT_USE_TLS) - #if OPENSSL_VERSION_NUMBER >= 0x10101000L SSL_CTX_set_keylog_callback( diff --git a/example/tls_server.cpp b/example/tls_server.cpp index 0b4bc8730..b02284661 100644 --- a/example/tls_server.cpp +++ b/example/tls_server.cpp @@ -20,8 +20,6 @@ namespace mi = boost::multi_index; using con_t = MQTT_NS::server_tls<>::endpoint_t; using con_sp_t = std::shared_ptr; -namespace as = boost::asio; - struct sub_con { sub_con(MQTT_NS::buffer topic, con_sp_t con, MQTT_NS::qos qos_value) :topic(std::move(topic)), con(std::move(con)), qos_value(qos_value) {} diff --git a/example/tls_ws_both.cpp b/example/tls_ws_both.cpp index 51668d6e2..168ca797f 100644 --- a/example/tls_ws_both.cpp +++ b/example/tls_ws_both.cpp @@ -16,8 +16,6 @@ #include "locked_cout.hpp" -namespace as = boost::asio; - template void client_proc( Client& c, diff --git a/example/tls_ws_server.cpp b/example/tls_ws_server.cpp index ad2ee5512..347bf7d27 100644 --- a/example/tls_ws_server.cpp +++ b/example/tls_ws_server.cpp @@ -20,8 +20,6 @@ namespace mi = boost::multi_index; using con_t = MQTT_NS::server_tls_ws<>::endpoint_t; using con_sp_t = std::shared_ptr; -namespace as = boost::asio; - struct sub_con { sub_con(MQTT_NS::buffer topic, con_sp_t con, MQTT_NS::qos qos_value) :topic(std::move(topic)), con(std::move(con)), qos_value(qos_value) {} diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 8a19ad81a..75b5109de 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -16,9 +16,7 @@ IF(MQTT_USE_STATIC_OPENSSL) TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$:${CMAKE_DL_LIBS} ZLIB::ZLIB>) ENDIF() -TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$,$>>:Opentls::SSL>) - -# TODO: Should this be PRIVATE? +TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$,$>>:OpenSSL::SSL>) TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$:${GNUTLS_LIBRARIES}>) TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} @@ -31,7 +29,7 @@ TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} IF(MQTT_USE_GNU_TLS) TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} INTERFACE - ${BoostAsioGnuTLS_INCLUDE_DIRS} + # ${BoostAsioGnuTLS_INCLUDE_DIRS} ${GNUTLS_INCLUDE_DIRS} ) ENDIF() diff --git a/include/mqtt/endpoint.hpp b/include/mqtt/endpoint.hpp index 50f104a2d..0b8c2db3a 100644 --- a/include/mqtt/endpoint.hpp +++ b/include/mqtt/endpoint.hpp @@ -4524,9 +4524,6 @@ class endpoint : public std::enable_shared_from_this void shutdown_from_client(T& socket) { boost::system::error_code ec; - // socket.shutdown(); socket.lowest_layer().close(ec); } diff --git a/include/mqtt/tls_implementation.hpp b/include/mqtt/tls_implementation.hpp index cde1fb769..7aac37cc7 100644 --- a/include/mqtt/tls_implementation.hpp +++ b/include/mqtt/tls_implementation.hpp @@ -10,6 +10,7 @@ #if defined(MQTT_USE_TLS) #if defined(MQTT_USE_GNU_TLS) #include +// The following is used in 'endpoint.hpp' and is not defined by default for Gnu TLS. # define ERR_GET_REASON(l) (int)( (l) & 0xFFFL) #else #include diff --git a/test/test_ctx_init.hpp b/test/test_ctx_init.hpp index 059c4b2f1..547a8b846 100644 --- a/test/test_ctx_init.hpp +++ b/test/test_ctx_init.hpp @@ -14,8 +14,6 @@ #include "test_settings.hpp" #include -// namespace ssl = boost::asio::gnutls; - struct ctx_init { ctx_init() : ctx(tls::context::tlsv12) { ctx.set_options( diff --git a/test/underlying_timeout.cpp b/test/underlying_timeout.cpp index 8454bfb23..da934387f 100644 --- a/test/underlying_timeout.cpp +++ b/test/underlying_timeout.cpp @@ -279,10 +279,6 @@ BOOST_AUTO_TEST_CASE( connect_tls_ashs ) { tls::context ctx {tls::context::tlsv12}; - std::cout << "Setting verify file" << std::endl; - - std::cout << base << std::endl; - #if defined(MQTT_USE_TLS) #if defined(MQTT_USE_GNU_TLS) ctx.use_verify_file(base + "cacert.pem", tls::context::pem); From 5746ffd9bbf41c7be1367ec094125c7bb0081ba7 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 10:50:02 -0700 Subject: [PATCH 16/32] Remove find boost asio gnu tls cmake module --- CMakeLists.txt | 1 - cmake/FindBoostAsioGnuTLS.cmake | 14 -------------- include/CMakeLists.txt | 1 - 3 files changed, 16 deletions(-) delete mode 100644 cmake/FindBoostAsioGnuTLS.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f08d4e492..bd4d990fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,7 +141,6 @@ ENDIF () IF (MQTT_USE_TLS) IF (MQTT_USE_GNU_TLS) FIND_PACKAGE (GnuTLS REQUIRED) - # FIND_PACKAGE (BoostAsioGnuTLS REQUIRED) ELSE () FIND_PACKAGE (OpenSSL REQUIRED) IF (MQTT_USE_STATIC_OPENSSL) diff --git a/cmake/FindBoostAsioGnuTLS.cmake b/cmake/FindBoostAsioGnuTLS.cmake deleted file mode 100644 index 6fa06b54a..000000000 --- a/cmake/FindBoostAsioGnuTLS.cmake +++ /dev/null @@ -1,14 +0,0 @@ -find_path(BoostAsioGnuTLS_INCLUDE_DIR NAMES boost/asio/gnutls.hpp) - -mark_as_advanced(BoostAsioGnuTLS_INCLUDE_DIR) - -include(FindPackageHandleStandardArgs) - -find_package_handle_standard_args(BoostAsioGnuTLS - REQUIRED_VARS - BoostAsioGnuTLS_INCLUDE_DIR - ) - -if(BoostAsioGnuTLS_FOUND) - set(BoostAsioGnuTLS_INCLUDE_DIRS ${BoostAsioGnuTLS_INCLUDE_DIR}) -endif() diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 75b5109de..bf2f29303 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -29,7 +29,6 @@ TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} IF(MQTT_USE_GNU_TLS) TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} INTERFACE - # ${BoostAsioGnuTLS_INCLUDE_DIRS} ${GNUTLS_INCLUDE_DIRS} ) ENDIF() From a9da0f2bbd003d12c8326278180ee321a82a058e Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 10:56:04 -0700 Subject: [PATCH 17/32] Use conditional expression in include/Cmakelists.txt --- include/CMakeLists.txt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index bf2f29303..f297dee7e 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -24,15 +24,9 @@ TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} $ $ $ + $<$:${GNUTLS_INCLUDE_DIRS}> ) -IF(MQTT_USE_GNU_TLS) - TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} - INTERFACE - ${GNUTLS_INCLUDE_DIRS} - ) -ENDIF() - TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_TLS>) TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_GNU_TLS>) TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_WS>) From ac1ecbbe3cb4ba3161a9dfcc7641a280bd042457 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 11:13:30 -0700 Subject: [PATCH 18/32] Install GnuTLS packages --- .github/workflows/gha.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml index e3851cbe7..9bfad6390 100644 --- a/.github/workflows/gha.yml +++ b/.github/workflows/gha.yml @@ -29,7 +29,7 @@ jobs: uses: actions/checkout@v2 - name: Install Dependencies run: | - brew install boost openssl + brew install boost openssl gnutls - name: Configure env: OPENSSL_ROOT_DIR: /usr/local/opt/openssl @@ -60,6 +60,7 @@ jobs: sudo add-apt-repository ppa:mhier/libboost-latest sudo apt-get update sudo apt-get install boost1.67 + sudo apt-get install libgnutls28-dev - name: Configure run: | [ ${{ matrix.pattern }} == 0 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" From 195e1f9dfbba5b1967a3beb9f81a5a91f4a45701 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 11:18:05 -0700 Subject: [PATCH 19/32] Update matrix pattern numbers: --- .github/workflows/gha.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml index 9bfad6390..cb0d951a0 100644 --- a/.github/workflows/gha.yml +++ b/.github/workflows/gha.yml @@ -63,19 +63,19 @@ jobs: sudo apt-get install libgnutls28-dev - name: Configure run: | - [ ${{ matrix.pattern }} == 0 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 1 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 2 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=ON -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 3 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 4 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=ON" - [ ${{ matrix.pattern }} == 5 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=ON -DMQTT_TEST_4=ON -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 6 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 7 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 1 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" - [ ${{ matrix.pattern }} == 2 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=ON -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" - [ ${{ matrix.pattern }} == 3 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" - [ ${{ matrix.pattern }} == 6 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" - [ ${{ matrix.pattern }} == 7 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" + [ ${{ matrix.pattern }} == 0 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" + [ ${{ matrix.pattern }} == 1 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" + [ ${{ matrix.pattern }} == 2 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=ON -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" + [ ${{ matrix.pattern }} == 3 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" + [ ${{ matrix.pattern }} == 4 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=ON" + [ ${{ matrix.pattern }} == 5 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=ON -DMQTT_TEST_4=ON -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" + [ ${{ matrix.pattern }} == 6 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" + [ ${{ matrix.pattern }} == 7 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" + [ ${{ matrix.pattern }} == 8 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" + [ ${{ matrix.pattern }} == 9 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=ON -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" + [ ${{ matrix.pattern }} == 10 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" + [ ${{ matrix.pattern }} == 11 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" + [ ${{ matrix.pattern }} == 12 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" cmake -S ${{ github.workspace }} -B ${{ runner.temp }} ${FLAGS} -DBOOSTROOT=/usr - name: Check Header Dependencies From 50688b710ada61cb6e472a690e13d82f81ee042a Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 11:30:33 -0700 Subject: [PATCH 20/32] Update matrix strategy pattern list --- .github/workflows/gha.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml index cb0d951a0..d4f0ddf1b 100644 --- a/.github/workflows/gha.yml +++ b/.github/workflows/gha.yml @@ -51,7 +51,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - pattern: [0, 1, 2, 3, 4, 5, 6, 7] + pattern: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] steps: - name: Checkout uses: actions/checkout@v2 From d5a3ef2dbeff88308e3081c534731acfde4b6753 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 12:01:00 -0700 Subject: [PATCH 21/32] Install boost-asio-gnutls --- .github/workflows/gha.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml index d4f0ddf1b..ee6f9daa3 100644 --- a/.github/workflows/gha.yml +++ b/.github/workflows/gha.yml @@ -30,6 +30,12 @@ jobs: - name: Install Dependencies run: | brew install boost openssl gnutls + + git clone https://github.com/paullouisageneau/boost-asio-gnutls.git + cd boost-asio-gnutls + git checkout 22ec973 + cp -r include/boost/asio/* /usr/local/include/boost/asio + cd .. - name: Configure env: OPENSSL_ROOT_DIR: /usr/local/opt/openssl @@ -61,6 +67,12 @@ jobs: sudo apt-get update sudo apt-get install boost1.67 sudo apt-get install libgnutls28-dev + + git clone https://github.com/paullouisageneau/boost-asio-gnutls.git + cd boost-asio-gnutls + git checkout 22ec973 + cp -r include/boost/asio/* /usr/local/include/boost/asio + cd .. - name: Configure run: | [ ${{ matrix.pattern }} == 0 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" From dc982568ddf7c64012131462dcacaa72e9ad817a Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 12:15:43 -0700 Subject: [PATCH 22/32] Rename use_verify_file to load_verify_file --- example/tls_both.cpp | 7 ------- example/tls_client.cpp | 7 ------- example/tls_ws_both.cpp | 7 ------- example/tls_ws_client.cpp | 7 ------- test/CMakeLists.txt | 12 ++++++------ test/combi_test.hpp | 7 ------- test/underlying_timeout.cpp | 24 ------------------------ 7 files changed, 6 insertions(+), 65 deletions(-) diff --git a/example/tls_both.cpp b/example/tls_both.cpp index 2ab673667..f4185f65a 100644 --- a/example/tls_both.cpp +++ b/example/tls_both.cpp @@ -371,14 +371,7 @@ int main(int argc, char** argv) { std::uint16_t pid_sub2; auto c = MQTT_NS::make_tls_sync_client(ioc, "localhost", port); - -#if defined(MQTT_USE_TLS) -#if defined(MQTT_USE_GNU_TLS) - c->get_ssl_context().use_verify_file(base + "cacert.pem", tls::context::pem); -#else c->get_ssl_context().load_verify_file(base + "cacert.pem"); -#endif // defined(MQTT_USE_GNU_TLS) -#endif // defined(MQTT_USE_TLS) int count = 0; auto disconnect = [&] { diff --git a/example/tls_client.cpp b/example/tls_client.cpp index 602406936..1e066277f 100644 --- a/example/tls_client.cpp +++ b/example/tls_client.cpp @@ -39,14 +39,7 @@ int main(int argc, char** argv) { // Setup client c->set_client_id("cid1"); c->set_clean_session(true); - -#if defined(MQTT_USE_TLS) -#if defined(MQTT_USE_GNU_TLS) - c->get_ssl_context().use_verify_file(cacert, tls::context::pem); -#else c->get_ssl_context().load_verify_file(cacert); -#endif // defined(MQTT_USE_GNU_TLS) -#endif // defined(MQTT_USE_TLS) #if OPENSSL_VERSION_NUMBER >= 0x10101000L diff --git a/example/tls_ws_both.cpp b/example/tls_ws_both.cpp index 168ca797f..1d72d36b1 100644 --- a/example/tls_ws_both.cpp +++ b/example/tls_ws_both.cpp @@ -370,14 +370,7 @@ int main(int argc, char** argv) { std::uint16_t pid_sub2; auto c = MQTT_NS::make_tls_sync_client_ws(ioc, "localhost", port); - -#if defined(MQTT_USE_TLS) -#if defined(MQTT_USE_GNU_TLS) - c->get_ssl_context().use_verify_file(base + "cacert.pem", tls::context::pem); -#else c->get_ssl_context().load_verify_file(base + "cacert.pem"); -#endif // defined(MQTT_USE_GNU_TLS) -#endif // defined(MQTT_USE_TLS) int count = 0; auto disconnect = [&] { diff --git a/example/tls_ws_client.cpp b/example/tls_ws_client.cpp index ad9000383..98d3ea614 100644 --- a/example/tls_ws_client.cpp +++ b/example/tls_ws_client.cpp @@ -40,14 +40,7 @@ int main(int argc, char** argv) { // Setup client c->set_client_id("cid1"); c->set_clean_session(true); - -#if defined(MQTT_USE_TLS) -#if defined(MQTT_USE_GNU_TLS) - c->get_ssl_context().use_verify_file(cacert, tls::context::pem); -#else c->get_ssl_context().load_verify_file(cacert); -#endif // defined(MQTT_USE_GNU_TLS) -#endif // defined(MQTT_USE_TLS) // Setup handlers c->set_connack_handler( diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f161b7ada..bad197b6e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,12 +11,12 @@ IF (POLICY CMP0074) ENDIF () OPTION(MQTT_TEST_1 "Build test part1" ON) -OPTION(MQTT_TEST_2 "Build test part2" ON) -OPTION(MQTT_TEST_3 "Build test part3" ON) -OPTION(MQTT_TEST_4 "Build test part4" ON) -OPTION(MQTT_TEST_5 "Build test part5" ON) -OPTION(MQTT_TEST_6 "Build test part6" ON) -OPTION(MQTT_TEST_7 "Build test part7" ON) +OPTION(MQTT_TEST_2 "Build test part2" OFF) +OPTION(MQTT_TEST_3 "Build test part3" OFF) +OPTION(MQTT_TEST_4 "Build test part4" OFF) +OPTION(MQTT_TEST_5 "Build test part5" OFF) +OPTION(MQTT_TEST_6 "Build test part6" OFF) +OPTION(MQTT_TEST_7 "Build test part7" OFF) IF (MQTT_TEST_1) LIST (APPEND check_PROGRAMS diff --git a/test/combi_test.hpp b/test/combi_test.hpp index c9467245e..7ad5b3473 100644 --- a/test/combi_test.hpp +++ b/test/combi_test.hpp @@ -108,14 +108,7 @@ inline void do_tls_test( std::string path = boost::unit_test::framework::master_test_suite().argv[0]; std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - -#if defined(MQTT_USE_TLS) -#if defined(MQTT_USE_GNU_TLS) - c->get_ssl_context().use_verify_file(base + "cacert.pem", tls::context::pem); -#else c->get_ssl_context().load_verify_file(base + "cacert.pem"); -#endif // defined(MQTT_USE_GNU_TLS) -#endif // defined(MQTT_USE_TLS) test( ioc, diff --git a/test/underlying_timeout.cpp b/test/underlying_timeout.cpp index da934387f..e04d4be3d 100644 --- a/test/underlying_timeout.cpp +++ b/test/underlying_timeout.cpp @@ -113,15 +113,7 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_ashs ) { std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); tls::context ctx {tls::context::tlsv12}; - -#if defined(MQTT_USE_TLS) -#if defined(MQTT_USE_GNU_TLS) - ctx.use_verify_file(base + "cacert.pem", tls::context::pem); -#else ctx.load_verify_file(base + "cacert.pem"); -#endif // defined(MQTT_USE_GNU_TLS) -#endif // defined(MQTT_USE_TLS) - ctx.set_verify_mode(tls::verify_peer); boost::beast::websocket::stream> socket(ioc, ctx); @@ -187,15 +179,7 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_upg ) { std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); tls::context ctx {tls::context::tlsv12}; - -#if defined(MQTT_USE_TLS) -#if defined(MQTT_USE_GNU_TLS) - ctx.use_verify_file(base + "cacert.pem", tls::context::pem); -#else ctx.load_verify_file(base + "cacert.pem"); -#endif // defined(MQTT_USE_GNU_TLS) -#endif // defined(MQTT_USE_TLS) - ctx.set_verify_mode(tls::verify_peer); boost::beast::websocket::stream> socket(ioc, ctx); @@ -278,15 +262,7 @@ BOOST_AUTO_TEST_CASE( connect_tls_ashs ) { std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); tls::context ctx {tls::context::tlsv12}; - -#if defined(MQTT_USE_TLS) -#if defined(MQTT_USE_GNU_TLS) - ctx.use_verify_file(base + "cacert.pem", tls::context::pem); -#else ctx.load_verify_file(base + "cacert.pem"); -#endif // defined(MQTT_USE_GNU_TLS) -#endif // defined(MQTT_USE_TLS) - ctx.set_verify_mode(tls::verify_peer); tls::stream socket(ioc, ctx); From c0ea73c514501e10cbd4301fedaea01275d04421 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 13:50:26 -0700 Subject: [PATCH 23/32] Create a function to check for short reads --- .github/workflows/gha.yml | 8 ++++---- include/mqtt/endpoint.hpp | 8 +------- include/mqtt/tls_implementation.hpp | 19 +++++++++++++++++++ test/underlying_timeout.cpp | 2 -- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml index ee6f9daa3..540a01bae 100644 --- a/.github/workflows/gha.yml +++ b/.github/workflows/gha.yml @@ -33,8 +33,8 @@ jobs: git clone https://github.com/paullouisageneau/boost-asio-gnutls.git cd boost-asio-gnutls - git checkout 22ec973 - cp -r include/boost/asio/* /usr/local/include/boost/asio + git checkout 259ec02 + cp -r include/boost/asio/* /usr/include/boost/asio cd .. - name: Configure env: @@ -70,8 +70,8 @@ jobs: git clone https://github.com/paullouisageneau/boost-asio-gnutls.git cd boost-asio-gnutls - git checkout 22ec973 - cp -r include/boost/asio/* /usr/local/include/boost/asio + git checkout 259ec02 + cp -r include/boost/asio/* /usr/include/boost/asio cd .. - name: Configure run: | diff --git a/include/mqtt/endpoint.hpp b/include/mqtt/endpoint.hpp index 0b8c2db3a..12e21a1be 100644 --- a/include/mqtt/endpoint.hpp +++ b/include/mqtt/endpoint.hpp @@ -4537,13 +4537,7 @@ class endpoint : public std::enable_shared_from_this socket(ioc, ctx); - std::cout << "Set verify file" << std::endl; - char buf; as::async_connect( From 11bc857a67db35f59c1d027788713532e7e22872 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 13:52:52 -0700 Subject: [PATCH 24/32] Use sudo for copying files --- .github/workflows/gha.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml index 540a01bae..2357aa5f2 100644 --- a/.github/workflows/gha.yml +++ b/.github/workflows/gha.yml @@ -34,7 +34,7 @@ jobs: git clone https://github.com/paullouisageneau/boost-asio-gnutls.git cd boost-asio-gnutls git checkout 259ec02 - cp -r include/boost/asio/* /usr/include/boost/asio + sudo cp -r include/boost/asio/* /usr/include/boost/asio cd .. - name: Configure env: @@ -71,7 +71,7 @@ jobs: git clone https://github.com/paullouisageneau/boost-asio-gnutls.git cd boost-asio-gnutls git checkout 259ec02 - cp -r include/boost/asio/* /usr/include/boost/asio + sudo cp -r include/boost/asio/* /usr/include/boost/asio cd .. - name: Configure run: | From 9867f96618d50a1b4c5e49b1553178c73afe0791 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 14:06:20 -0700 Subject: [PATCH 25/32] Reenable all tests --- test/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bad197b6e..f161b7ada 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,12 +11,12 @@ IF (POLICY CMP0074) ENDIF () OPTION(MQTT_TEST_1 "Build test part1" ON) -OPTION(MQTT_TEST_2 "Build test part2" OFF) -OPTION(MQTT_TEST_3 "Build test part3" OFF) -OPTION(MQTT_TEST_4 "Build test part4" OFF) -OPTION(MQTT_TEST_5 "Build test part5" OFF) -OPTION(MQTT_TEST_6 "Build test part6" OFF) -OPTION(MQTT_TEST_7 "Build test part7" OFF) +OPTION(MQTT_TEST_2 "Build test part2" ON) +OPTION(MQTT_TEST_3 "Build test part3" ON) +OPTION(MQTT_TEST_4 "Build test part4" ON) +OPTION(MQTT_TEST_5 "Build test part5" ON) +OPTION(MQTT_TEST_6 "Build test part6" ON) +OPTION(MQTT_TEST_7 "Build test part7" ON) IF (MQTT_TEST_1) LIST (APPEND check_PROGRAMS From 3a4a8e064bb494af98371edbdb1ef2b40fc0e9a5 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 14:11:40 -0700 Subject: [PATCH 26/32] Fix MacOs copy command --- .github/workflows/gha.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml index 2357aa5f2..a9335871d 100644 --- a/.github/workflows/gha.yml +++ b/.github/workflows/gha.yml @@ -33,8 +33,7 @@ jobs: git clone https://github.com/paullouisageneau/boost-asio-gnutls.git cd boost-asio-gnutls - git checkout 259ec02 - sudo cp -r include/boost/asio/* /usr/include/boost/asio + sudo cp -R include/boost/asio/* /usr/include/boost/asio cd .. - name: Configure env: @@ -70,7 +69,6 @@ jobs: git clone https://github.com/paullouisageneau/boost-asio-gnutls.git cd boost-asio-gnutls - git checkout 259ec02 sudo cp -r include/boost/asio/* /usr/include/boost/asio cd .. - name: Configure From a6b4579b0cb70990ded8ffc8cbd3c53507765c3e Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 14:20:12 -0700 Subject: [PATCH 27/32] Add default return statement to is_tls_short_read --- include/mqtt/tls_implementation.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/mqtt/tls_implementation.hpp b/include/mqtt/tls_implementation.hpp index dbecd7138..c93dd5fb0 100644 --- a/include/mqtt/tls_implementation.hpp +++ b/include/mqtt/tls_implementation.hpp @@ -40,6 +40,7 @@ inline constexpr bool is_tls_short_read(int error_val) #endif // defined(SSL_R_SHORT_READ) #endif // defined(MQTT_USE_GNU_TLS) #endif // defined(MQTT_USE_TLS) + return false; } } // namespace MQTT_NS From a018a30557d53e1033b6af7b9a5d345d15ab2605 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 14:23:12 -0700 Subject: [PATCH 28/32] Debug macos --- .github/workflows/gha.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml index a9335871d..866060113 100644 --- a/.github/workflows/gha.yml +++ b/.github/workflows/gha.yml @@ -31,9 +31,11 @@ jobs: run: | brew install boost openssl gnutls + locate boost + git clone https://github.com/paullouisageneau/boost-asio-gnutls.git cd boost-asio-gnutls - sudo cp -R include/boost/asio/* /usr/include/boost/asio + sudo cp -R include/boost/asio/ /usr/local/include/boost/asio cd .. - name: Configure env: From c7d4bb61dc2bc22e7bd0ecf0d7211d24ebd2eb56 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 14:37:30 -0700 Subject: [PATCH 29/32] Debug macos --- .github/workflows/gha.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml index 866060113..13eceb901 100644 --- a/.github/workflows/gha.yml +++ b/.github/workflows/gha.yml @@ -31,7 +31,7 @@ jobs: run: | brew install boost openssl gnutls - locate boost + ls /usr/include git clone https://github.com/paullouisageneau/boost-asio-gnutls.git cd boost-asio-gnutls From bf54b28b80cc3ef69a9ba99014e54ae86de4c218 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 14:42:37 -0700 Subject: [PATCH 30/32] Add new patterns to pipeline steps --- .github/workflows/gha.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml index 13eceb901..e5371efc9 100644 --- a/.github/workflows/gha.yml +++ b/.github/workflows/gha.yml @@ -94,7 +94,7 @@ jobs: run: | cmake --build ${{ runner.temp }} --parallel $(nproc) --clean-first --target check_deps - name: Compile with Sanitizer - if: (matrix.pattern == 1) || (matrix.pattern == 2) || (matrix.pattern == 3) + if: (matrix.pattern == 1) || (matrix.pattern == 2) || (matrix.pattern == 3) || (matrix.pattern == 8) || (matrix.pattern == 9) || (matrix.pattern == 10) env: CFLAGS: -Werror -g -Wall -Wextra -Wno-ignored-qualifiers -Wconversion -fno-omit-frame-pointer -DBOOST_ASIO_NO_DEPRECATED -fsanitize=address CXXFLAGS: -Werror -g -Wall -Wextra -Wno-ignored-qualifiers -Wconversion -fno-omit-frame-pointer -DBOOST_ASIO_NO_DEPRECATED -fsanitize=address @@ -103,7 +103,7 @@ jobs: CXXFLAGS="${CXXFLAGS} -pedantic -DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING" cmake --build ${{ runner.temp }} --clean-first - name: Compile without Sanitizer - if: (matrix.pattern == 0) || (matrix.pattern == 4) || (matrix.pattern == 5) || (matrix.pattern == 6) || (matrix.pattern == 7) + if: (matrix.pattern == 0) || (matrix.pattern == 4) || (matrix.pattern == 5) || (matrix.pattern == 6) || (matrix.pattern == 7) || (matrix.pattern == 11) || (matrix.pattern == 12) env: CFLAGS: -Werror -g -Wall -Wextra -Wno-ignored-qualifiers -Wconversion -fno-omit-frame-pointer -DBOOST_ASIO_NO_DEPRECATED CXXFLAGS: -Werror -g -Wall -Wextra -Wno-ignored-qualifiers -Wconversion -fno-omit-frame-pointer -DBOOST_ASIO_NO_DEPRECATED @@ -116,7 +116,7 @@ jobs: run: | ctest -VV - name: Code Coverage - if: (matrix.pattern == 4) || (matrix.pattern == 5) || (matrix.pattern == 6) || (matrix.pattern == 7) + if: (matrix.pattern == 4) || (matrix.pattern == 5) || (matrix.pattern == 6) || (matrix.pattern == 7) || (matrix.pattern == 11) || (matrix.pattern == 12) run: | sudo apt-get install lcov # Create lcov report From 98c658f3db126de6e1caea414ed73d8a4071a29c Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 18 Sep 2020 16:25:33 -0700 Subject: [PATCH 31/32] Mac os debug --- .github/workflows/gha.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml index e5371efc9..adad9b3b3 100644 --- a/.github/workflows/gha.yml +++ b/.github/workflows/gha.yml @@ -31,7 +31,7 @@ jobs: run: | brew install boost openssl gnutls - ls /usr/include + ls /usr/local/Cellar/boost/1.73.0 git clone https://github.com/paullouisageneau/boost-asio-gnutls.git cd boost-asio-gnutls From 36fc136be2711a800f2c75d85166eacc2ff33e07 Mon Sep 17 00:00:00 2001 From: Shantanu Singh Date: Fri, 2 Oct 2020 10:28:06 -0700 Subject: [PATCH 32/32] Redefine MQTT_USE_TLS to take type of TLS library as value: --- .github/workflows/gha.yml | 61 +++++++++++++---------------- CMakeLists.txt | 21 +++++----- azure-pipelines.yml | 16 +++----- include/CMakeLists.txt | 9 ++--- include/mqtt/tls_implementation.hpp | 43 ++++++++++---------- test/CMakeLists.txt | 6 ++- 6 files changed, 77 insertions(+), 79 deletions(-) diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml index adad9b3b3..f423588dc 100644 --- a/.github/workflows/gha.yml +++ b/.github/workflows/gha.yml @@ -15,15 +15,13 @@ jobs: strategy: matrix: pattern: - - '-DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=ON -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_USE_TLS=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=OFF' - - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=ON -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=OFF' - - '-DMQTT_TEST_1=ON -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON' - - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF' - - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=ON -DMQTT_TEST_7=ON -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF' - - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=ON -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=OFF -DMQTT_USE_GNU_TLS=ON' - - '-DMQTT_TEST_1=ON -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_USE_GNU_TLS=ON' - - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_USE_GNU_TLS=ON' - - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=ON -DMQTT_TEST_7=ON -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_USE_GNU_TLS=ON' + - '-DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=ON -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=OFF -DMQTT_USE_TLS=OFF' + - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=ON -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=OFF -DMQTT_USE_TLS=ON' + - '-DMQTT_TEST_1=ON -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_USE_TLS=ON' + - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_USE_TLS=ON' + - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=ON -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_USE_TLS=MQTT_TLS_OPENSSL' + - '-DMQTT_TEST_1=ON -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=OFF -DMQTT_USE_TLS=MQTT_TLS_GNUTLS -DMQTT_BOOST_ASIO_GNUTLS_INCLUDE=/usr/local/include/boost-asio-gnutls/' + - '-DMQTT_TEST_1=ON -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=OFF -DMQTT_USE_TLS=MQTT_TLS_GNUTLS -DMQTT_BOOST_ASIO_GNUTLS_INCLUDE=/usr/local/include/boost-asio-gnutls/' steps: - name: Checkout uses: actions/checkout@v2 @@ -31,12 +29,10 @@ jobs: run: | brew install boost openssl gnutls - ls /usr/local/Cellar/boost/1.73.0 - + mkdir -p /usr/local/include/boost-asio-gnutls git clone https://github.com/paullouisageneau/boost-asio-gnutls.git - cd boost-asio-gnutls - sudo cp -R include/boost/asio/ /usr/local/include/boost/asio - cd .. + sudo cp -R boost-asio-gnutls/include/. /usr/local/include/boost-asio-gnutls/ + rm -rf boost-asio-gnutls - name: Configure env: OPENSSL_ROOT_DIR: /usr/local/opt/openssl @@ -58,7 +54,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - pattern: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] + pattern: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] steps: - name: Checkout uses: actions/checkout@v2 @@ -70,31 +66,28 @@ jobs: sudo apt-get install libgnutls28-dev git clone https://github.com/paullouisageneau/boost-asio-gnutls.git - cd boost-asio-gnutls - sudo cp -r include/boost/asio/* /usr/include/boost/asio - cd .. + sudo cp -R boost-asio-gnutls/include/. /usr/local/include/boost-asio-gnutls/ + rm -rf boost-asio-gnutls - name: Configure run: | - [ ${{ matrix.pattern }} == 0 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 1 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 2 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=ON -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 3 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 4 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=ON" - [ ${{ matrix.pattern }} == 5 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=ON -DMQTT_TEST_4=ON -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 6 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 7 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 8 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" - [ ${{ matrix.pattern }} == 9 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=ON -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" - [ ${{ matrix.pattern }} == 10 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" - [ ${{ matrix.pattern }} == 11 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" - [ ${{ matrix.pattern }} == 12 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_GNU_TLS=ON" + [ ${{ matrix.pattern }} == 0 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=OFF" + [ ${{ matrix.pattern }} == 1 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=ON" + [ ${{ matrix.pattern }} == 2 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=ON -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=ON" + [ ${{ matrix.pattern }} == 3 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=ON" + [ ${{ matrix.pattern }} == 4 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=ON -DMQTT_USE_TLS=OFF" + [ ${{ matrix.pattern }} == 5 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=ON -DMQTT_TEST_4=ON -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=OFF" + [ ${{ matrix.pattern }} == 6 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=ON" + [ ${{ matrix.pattern }} == 7 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=ON" + [ ${{ matrix.pattern }} == 8 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=MQTT_TLS_GNUTLS -DMQTT_BOOST_ASIO_GNUTLS_INCLUDE=/usr/local/include/boost-asio-gnutls/" + [ ${{ matrix.pattern }} == 9 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=ON -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=MQTT_TLS_GNUTLS -DMQTT_BOOST_ASIO_GNUTLS_INCLUDE=/usr/local/include/boost-asio-gnutls/" + [ ${{ matrix.pattern }} == 10 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=ON -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=MQTT_TLS_GNUTLS -DMQTT_BOOST_ASIO_GNUTLS_INCLUDE=/usr/local/include/boost-asio-gnutls/" cmake -S ${{ github.workspace }} -B ${{ runner.temp }} ${FLAGS} -DBOOSTROOT=/usr - name: Check Header Dependencies run: | cmake --build ${{ runner.temp }} --parallel $(nproc) --clean-first --target check_deps - name: Compile with Sanitizer - if: (matrix.pattern == 1) || (matrix.pattern == 2) || (matrix.pattern == 3) || (matrix.pattern == 8) || (matrix.pattern == 9) || (matrix.pattern == 10) + if: (matrix.pattern == 1) || (matrix.pattern == 2) || (matrix.pattern == 3) || (matrix.pattern == 8) env: CFLAGS: -Werror -g -Wall -Wextra -Wno-ignored-qualifiers -Wconversion -fno-omit-frame-pointer -DBOOST_ASIO_NO_DEPRECATED -fsanitize=address CXXFLAGS: -Werror -g -Wall -Wextra -Wno-ignored-qualifiers -Wconversion -fno-omit-frame-pointer -DBOOST_ASIO_NO_DEPRECATED -fsanitize=address @@ -103,7 +96,7 @@ jobs: CXXFLAGS="${CXXFLAGS} -pedantic -DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING" cmake --build ${{ runner.temp }} --clean-first - name: Compile without Sanitizer - if: (matrix.pattern == 0) || (matrix.pattern == 4) || (matrix.pattern == 5) || (matrix.pattern == 6) || (matrix.pattern == 7) || (matrix.pattern == 11) || (matrix.pattern == 12) + if: (matrix.pattern == 0) || (matrix.pattern == 4) || (matrix.pattern == 5) || (matrix.pattern == 6) || (matrix.pattern == 7) || (matrix.pattern == 9) || (matrix.pattern == 10) env: CFLAGS: -Werror -g -Wall -Wextra -Wno-ignored-qualifiers -Wconversion -fno-omit-frame-pointer -DBOOST_ASIO_NO_DEPRECATED CXXFLAGS: -Werror -g -Wall -Wextra -Wno-ignored-qualifiers -Wconversion -fno-omit-frame-pointer -DBOOST_ASIO_NO_DEPRECATED @@ -116,7 +109,7 @@ jobs: run: | ctest -VV - name: Code Coverage - if: (matrix.pattern == 4) || (matrix.pattern == 5) || (matrix.pattern == 6) || (matrix.pattern == 7) || (matrix.pattern == 11) || (matrix.pattern == 12) + if: (matrix.pattern == 4) || (matrix.pattern == 5) || (matrix.pattern == 6) || (matrix.pattern == 7) || (matrix.pattern == 9) || (matrix.pattern == 10) run: | sudo apt-get install lcov # Create lcov report diff --git a/CMakeLists.txt b/CMakeLists.txt index bd4d990fb..8fca91425 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,6 @@ OPTION(MQTT_ALWAYS_SEND_REASON_CODE "Always send a reason code, even if the stan OPTION(MQTT_USE_STATIC_BOOST "Statically link with boost libraries" OFF) OPTION(MQTT_USE_STATIC_OPENSSL "Statically link with openssl libraries" OFF) OPTION(MQTT_USE_TLS "Enable building TLS code" OFF) -OPTION(MQTT_USE_GNU_TLS "Enable the use of GnuTLS instead of OpenSSL" OFF) OPTION(MQTT_USE_WS "Enable building WebSockets code" OFF) OPTION(MQTT_USE_STR_CHECK "Enable UTF8 String check" ON) OPTION(MQTT_USE_LOG "Enable building logging code" OFF) @@ -28,20 +27,24 @@ IF (POLICY CMP0074) CMAKE_POLICY(SET CMP0074 NEW) ENDIF () -set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake ${CMAKE_MODULE_PATH}) +SET (MQTT_TLS_OPENSSL "MQTT_TLS_OPENSSL") +SET (MQTT_TLS_GNUTLS "MQTT_TLS_GNUTLS") IF (MQTT_USE_TLS) MESSAGE (STATUS "TLS enabled") + IF (MQTT_USE_TLS STREQUAL ${MQTT_TLS_GNUTLS}) + MESSAGE (STATUS "Using GNUTLS") + IF (MQTT_BOOST_ASIO_GNUTLS_INCLUDE STREQUAL "") + MESSAGE (FATAL_ERROR "The MQTT_BOOST_ASIO_GNUTLS_INCLUDE variable needs to be set to the path of the boost-asio-gnutls headers") + ENDIF () + ELSE () + MESSAGE (STATUS "Using OpenSSL") + SET (MQTT_USE_TLS ${MQTT_TLS_OPENSSL}) + ENDIF() ELSE () MESSAGE (STATUS "TLS disabled") ENDIF () -IF (MQTT_USE_GNU_TLS) - MESSAGE (STATUS "GNU TLS enabled") -ELSE () - MESSAGE (STATUS "GNU TLS disabled") -ENDIF () - IF (MQTT_USE_WS) MESSAGE (STATUS "WebSocket enabled") ELSE () @@ -139,7 +142,7 @@ ELSE () ENDIF () IF (MQTT_USE_TLS) - IF (MQTT_USE_GNU_TLS) + IF (MQTT_USE_TLS STREQUAL ${MQTT_TLS_GNUTLS}) FIND_PACKAGE (GnuTLS REQUIRED) ELSE () FIND_PACKAGE (OpenSSL REQUIRED) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 978462ccf..5d778bae0 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -29,8 +29,7 @@ strategy: MQTT_TEST_6: OFF MQTT_BUILD_EXAMPLES: ON ExamplesGnuTls: - MQTT_USE_TLS: ON - MQTT_USE_GNU_TLS: ON + MQTT_USE_TLS: MQTT_TLS_GNUTLS MQTT_USE_WS: OFF MQTT_USE_STR_CHECK: ON MQTT_TEST_1: OFF @@ -107,7 +106,7 @@ strategy: MQTT_TEST_6: OFF MQTT_BUILD_EXAMPLES: OFF TestGroup6: - MQTT_USE_TLS: ON + MQTT_USE_TLS: MQTT_TLS_OPENSSL MQTT_USE_WS: OFF MQTT_USE_STR_CHECK: ON MQTT_TEST_1: OFF @@ -129,8 +128,7 @@ strategy: MQTT_TEST_6: ON MQTT_BUILD_EXAMPLES: OFF TestGroup8: - MQTT_USE_TLS: ON - MQTT_USE_GNU_TLS: ON + MQTT_USE_TLS: MQTT_TLS_GNUTLS MQTT_USE_WS: OFF MQTT_USE_STR_CHECK: OFF MQTT_TEST_1: ON @@ -141,8 +139,7 @@ strategy: MQTT_TEST_6: OFF MQTT_BUILD_EXAMPLES: OFF TestGroup9: - MQTT_USE_TLS: ON - MQTT_USE_GNU_TLS: ON + MQTT_USE_TLS: MQTT_TLS_GNUTLS MQTT_USE_WS: OFF MQTT_USE_STR_CHECK: ON MQTT_TEST_1: OFF @@ -153,8 +150,7 @@ strategy: MQTT_TEST_6: OFF MQTT_BUILD_EXAMPLES: OFF TestGroup10: - MQTT_USE_TLS: ON - MQTT_USE_GNU_TLS: ON + MQTT_USE_TLS: MQTT_TLS_GNUTLS MQTT_USE_WS: OFF MQTT_USE_STR_CHECK: ON MQTT_TEST_1: OFF @@ -175,7 +171,7 @@ steps: mkdir build cd build set CL=/D_WIN32_WINNT#0x0601 - cmake -A x64 -DMQTT_USE_TLS=%MQTT_USE_TLS% -DMQTT_USE_GNU_TLS=%MQTT_USE_GNU_TLS% -DMQTT_USE_WS=%MQTT_USE_WS% -DMQTT_USE_STR_CHECK=%MQTT_USE_STR_CHECK% -DMQTT_TEST_1=%MQTT_TEST_1% -DMQTT_TEST_2=%MQTT_TEST_2% -DMQTT_TEST_3=%MQTT_TEST_3% -DMQTT_TEST_4=%MQTT_TEST_4% -DMQTT_TEST_5=%MQTT_TEST_5% -DMQTT_TEST_6=%MQTT_TEST_6% -DMQTT_BUILD_EXAMPLES=%MQTT_BUILD_EXAMPLES% .. + cmake -A x64 -DMQTT_USE_TLS=%MQTT_USE_TLS% -DMQTT_USE_WS=%MQTT_USE_WS% -DMQTT_USE_STR_CHECK=%MQTT_USE_STR_CHECK% -DMQTT_TEST_1=%MQTT_TEST_1% -DMQTT_TEST_2=%MQTT_TEST_2% -DMQTT_TEST_3=%MQTT_TEST_3% -DMQTT_TEST_4=%MQTT_TEST_4% -DMQTT_TEST_5=%MQTT_TEST_5% -DMQTT_TEST_6=%MQTT_TEST_6% -DMQTT_BUILD_EXAMPLES=%MQTT_BUILD_EXAMPLES% .. cmake --build . --config Release -- -verbosity:minimal cd test set PATH=%BOOST_ROOT%\lib;%PATH% diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index f297dee7e..4cddb9a14 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -16,19 +16,18 @@ IF(MQTT_USE_STATIC_OPENSSL) TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$:${CMAKE_DL_LIBS} ZLIB::ZLIB>) ENDIF() -TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$,$>>:OpenSSL::SSL>) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$:${GNUTLS_LIBRARIES}>) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$:OpenSSL::SSL>) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$:${GNUTLS_LIBRARIES}>) TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} INTERFACE $ $ $ - $<$:${GNUTLS_INCLUDE_DIRS}> + $<$:${GNUTLS_INCLUDE_DIRS} ${MQTT_BOOST_ASIO_GNUTLS_INCLUDE}> ) -TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_TLS>) -TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_GNU_TLS>) +TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_TLS=${MQTT_USE_TLS}>) TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_WS>) TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_STR_CHECK>) TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_LOG>) diff --git a/include/mqtt/tls_implementation.hpp b/include/mqtt/tls_implementation.hpp index c93dd5fb0..8a1671dc2 100644 --- a/include/mqtt/tls_implementation.hpp +++ b/include/mqtt/tls_implementation.hpp @@ -7,42 +7,45 @@ #if !defined(MQTT_TLS_IMPLEMENTATION_HPP) #define MQTT_TLS_IMPLEMENTATION_HPP +#define MQTT_TLS_OPENSSL 1 +#define MQTT_TLS_GNUTLS 2 + #if defined(MQTT_USE_TLS) -#if defined(MQTT_USE_GNU_TLS) -#include -// The following is used in 'endpoint.hpp' and is not defined by default for Gnu TLS. -# define ERR_GET_REASON(l) (int)( (l) & 0xFFFL) -#else -#include -#endif // defined(MQTT_USE_GNU_TLS) +#if MQTT_USE_TLS == 0 +#define MQTT_USE_TLS MQTT_TLS_OPENSSL +#endif // MQTT_USE_TLS == 0 #endif // defined(MQTT_USE_TLS) -#if defined(MQTT_USE_TLS) -#if defined(MQTT_USE_GNU_TLS) -namespace tls = boost::asio::gnutls; -#else +#if MQTT_USE_TLS == MQTT_TLS_OPENSSL +#include +#elif MQTT_USE_TLS == MQTT_TLS_GNUTLS +#include +#endif // MQTT_USE_TLS == MQTT_TLS_OPENSSL + +#if MQTT_USE_TLS == MQTT_TLS_OPENSSL namespace tls = boost::asio::ssl; -#endif // defined(MQTT_USE_GNU_TLS) -#endif // defined(MQTT_USE_TLS) +#elif MQTT_USE_TLS == MQTT_TLS_GNUTLS +namespace tls = boost::asio::gnutls; +#endif // MQTT_USE_TLS == MQTT_TLS_OPENSSL namespace MQTT_NS { inline constexpr bool is_tls_short_read(int error_val) { -#if defined(MQTT_USE_TLS) -#if defined(MQTT_USE_GNU_TLS) - return error_val == tls::error::stream_truncated; -#else + +#if MQTT_USE_TLS == MQTT_TLS_OPENSSL #if defined(SSL_R_SHORT_READ) return ERR_GET_REASON(error_val) == SSL_R_SHORT_READ; #else // defined(SSL_R_SHORT_READ) return ERR_GET_REASON(error_val) == tls::error::stream_truncated; #endif // defined(SSL_R_SHORT_READ) -#endif // defined(MQTT_USE_GNU_TLS) -#endif // defined(MQTT_USE_TLS) +#elif MQTT_USE_TLS == MQTT_TLS_GNUTLS + return error_val == tls::error::stream_truncated; +#endif // MQTT_USE_TLS == MQTT_TLS_OPENSSL + return false; } } // namespace MQTT_NS -#endif // MQTT_tls_implementation_HPP +#endif // MQTT_TLS_IMPLEMENTATION_HPP diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f161b7ada..507fbcc82 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -89,6 +89,10 @@ ENDIF () FOREACH (source_file ${check_PROGRAMS}) GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE) + + # target_compile_options(${source_file_we} PUBLIC -Werror -g -Wall -Wextra -Wno-ignored-qualifiers -Wconversion) + set(BOOST_ASIO_NO_DEPRECATED) + ADD_EXECUTABLE (${source_file_we} ${source_file}) TARGET_COMPILE_DEFINITIONS (${source_file_we} PUBLIC $,,BOOST_TEST_DYN_LINK>) TARGET_LINK_LIBRARIES ( @@ -103,7 +107,7 @@ FOREACH (source_file ${check_PROGRAMS}) IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") IF (MQTT_CODECOV) SET_PROPERTY (TARGET ${source_file_we} - APPEND_STRING PROPERTY COMPILE_FLAGS " -O0 -g --coverage -fno-inline") + APPEND_STRING PROPERTY COMPILE_FLAGS " -O0 -g --coverage -fno-inline -fno-omit-frame-pointer -Werror -g -Wall -Wextra -Wno-ignored-qualifiers -Wconversion -DBOOST_ASIO_NO_DEPRECATED") SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY LINK_FLAGS " --coverage") ENDIF ()