diff --git a/Release/include/cpprest/ws_client.h b/Release/include/cpprest/ws_client.h index a956731e16..9c202d7f73 100644 --- a/Release/include/cpprest/ws_client.h +++ b/Release/include/cpprest/ws_client.h @@ -28,6 +28,17 @@ #include #include +#if !defined(_WIN32) || !defined(__cplusplus_winrt) +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wconversion" +#endif +#include "boost/asio/ssl.hpp" +#if defined(__clang__) +#pragma clang diagnostic pop +#endif +#endif + namespace web { // For backwards compatibility for when in the experimental namespace. @@ -168,6 +179,26 @@ class websocket_client_config /// caution. void set_validate_certificates(bool validate_certs) { m_validate_certificates = validate_certs; } +#if !defined(_WIN32) || !defined(__cplusplus_winrt) + /// + /// Sets a callback to enable custom setting of the ssl context, at construction time. + /// + /// A user callback allowing for customization of the ssl context at construction + /// time. + void set_ssl_context_callback(const std::function& callback) + { + m_ssl_context_callback = callback; + } + + /// + /// Gets the user's callback to allow for customization of the ssl context. + /// + const std::function& get_ssl_context_callback() const + { + return m_ssl_context_callback; + } +#endif + private: web::web_proxy m_proxy; web::credentials m_credentials; @@ -175,6 +206,9 @@ class websocket_client_config bool m_sni_enabled; utf8string m_sni_hostname; bool m_validate_certificates; +#if !defined(_WIN32) || !defined(__cplusplus_winrt) + std::function m_ssl_context_callback; +#endif }; /// diff --git a/Release/src/CMakeLists.txt b/Release/src/CMakeLists.txt index 81751b13f8..89d2bc55c3 100644 --- a/Release/src/CMakeLists.txt +++ b/Release/src/CMakeLists.txt @@ -67,6 +67,9 @@ elseif(CPPREST_WEBSOCKETS_IMPL STREQUAL "wspp") ) cpprest_find_websocketpp() target_link_libraries(cpprest PRIVATE cpprestsdk_websocketpp_internal) + cpprest_find_boost() + cpprest_find_openssl() + target_link_libraries(cpprest PUBLIC cpprestsdk_boost_internal cpprestsdk_openssl_internal) else() message(FATAL_ERROR "Invalid implementation") endif() diff --git a/Release/src/websockets/client/ws_client_wspp.cpp b/Release/src/websockets/client/ws_client_wspp.cpp index 3b6e9c8ddf..810df4d403 100644 --- a/Release/src/websockets/client/ws_client_wspp.cpp +++ b/Release/src/websockets/client/ws_client_wspp.cpp @@ -189,6 +189,10 @@ class wspp_callback_client : public websocket_client_callback_impl, new boost::asio::ssl::context(boost::asio::ssl::context::sslv23)); sslContext->set_default_verify_paths(); sslContext->set_options(boost::asio::ssl::context::default_workarounds); + if (m_config.get_ssl_context_callback()) + { + m_config.get_ssl_context_callback()(*sslContext); + } if (m_config.validate_certificates()) { sslContext->set_verify_mode(boost::asio::ssl::context::verify_peer);