Skip to content

Commit 47689b3

Browse files
committed
Merge branch 'hyotak-yun-master' into development
2 parents 9e9bcbe + 525db49 commit 47689b3

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

Release/include/cpprest/ws_client.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ class websocket_client_config
8484
/// <summary>
8585
/// Creates a websocket client configuration with default settings.
8686
/// </summary>
87-
websocket_client_config() : m_sni_enabled(true) {}
87+
websocket_client_config() :
88+
m_sni_enabled(true),
89+
m_validate_certificates(true)
90+
{
91+
}
8892

8993
/// <summary>
9094
/// Get the web proxy object
@@ -187,13 +191,33 @@ class websocket_client_config
187191
/// <remarks>If you want all the subprotocols in a comma separated string
188192
/// they can be directly looked up in the headers using 'Sec-WebSocket-Protocol'.</remarks>
189193
_ASYNCRTIMP std::vector<::utility::string_t> subprotocols() const;
194+
195+
/// <summary>
196+
/// Gets the server certificate validation property.
197+
/// </summary>
198+
/// <returns>True if certificates are to be verified, false otherwise.</returns>
199+
bool validate_certificates() const
200+
{
201+
return m_validate_certificates;
202+
}
203+
204+
/// <summary>
205+
/// Sets the server certificate validation property.
206+
/// </summary>
207+
/// <param name="validate_certs">False to turn ignore all server certificate validation errors, true otherwise.</param>
208+
/// <remarks>Note ignoring certificate errors can be dangerous and should be done with caution.</remarks>
209+
void set_validate_certificates(bool validate_certs)
210+
{
211+
m_validate_certificates = validate_certs;
212+
}
190213

191214
private:
192215
web::web_proxy m_proxy;
193216
web::credentials m_credentials;
194217
web::http::http_headers m_headers;
195218
bool m_sni_enabled;
196219
utf8string m_sni_hostname;
220+
bool m_validate_certificates;
197221
};
198222

199223
/// <summary>

Release/src/websockets/client/ws_client_wspp.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,14 @@ class wspp_callback_client : public websocket_client_callback_impl, public std::
180180
auto sslContext = websocketpp::lib::shared_ptr<boost::asio::ssl::context>(new boost::asio::ssl::context(boost::asio::ssl::context::sslv23));
181181
sslContext->set_default_verify_paths();
182182
sslContext->set_options(boost::asio::ssl::context::default_workarounds);
183-
sslContext->set_verify_mode(boost::asio::ssl::context::verify_peer);
183+
if (m_config.validate_certificates())
184+
{
185+
sslContext->set_verify_mode(boost::asio::ssl::context::verify_peer);
186+
}
187+
else
188+
{
189+
sslContext->set_verify_mode(boost::asio::ssl::context::verify_none);
190+
}
184191

185192
#if defined(__APPLE__) || (defined(ANDROID) || defined(__ANDROID__)) || defined(_WIN32)
186193
m_openssl_failed = false;

0 commit comments

Comments
 (0)