Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the missing ssl::context callback in websocket_client_config #1049

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Release/include/cpprest/ws_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
#include <memory>
#include <mutex>

#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.
Expand Down Expand Up @@ -168,13 +179,36 @@ class websocket_client_config
/// caution.</remarks>
void set_validate_certificates(bool validate_certs) { m_validate_certificates = validate_certs; }

#if !defined(_WIN32) || !defined(__cplusplus_winrt)
/// <summary>
/// Sets a callback to enable custom setting of the ssl context, at construction time.
/// </summary>
/// <param name="callback">A user callback allowing for customization of the ssl context at construction
/// time.</param>
void set_ssl_context_callback(const std::function<void(boost::asio::ssl::context&)>& callback)
{
m_ssl_context_callback = callback;
}

/// <summary>
/// Gets the user's callback to allow for customization of the ssl context.
/// </summary>
const std::function<void(boost::asio::ssl::context&)>& get_ssl_context_callback() const
{
return m_ssl_context_callback;
}
#endif

private:
web::web_proxy m_proxy;
web::credentials m_credentials;
web::http::http_headers m_headers;
bool m_sni_enabled;
utf8string m_sni_hostname;
bool m_validate_certificates;
#if !defined(_WIN32) || !defined(__cplusplus_winrt)
std::function<void(boost::asio::ssl::context&)> m_ssl_context_callback;
#endif
};

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions Release/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions Release/src/websockets/client/ws_client_wspp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down