microsoft / cpprestsdk

The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Other
7.96k stars 1.65k forks source link

Client certificates with websocket client #520

Open jbmercha opened 7 years ago

jbmercha commented 7 years ago

I am using the SingalR C++ client (https://github.com/aspnet/SignalR-Client-Cpp) which uses cpprestsdk and would like to use Client Certificates with the TLS connection for both http and websocket connections. For http, I am able to use http_client_config::set_nativehandle_options as described in #199 but I see no equivalent in websocket_client_config.

Could a client certificate path be added to the websocket_client_config, to be used for the ssl::context's use_certificate_file and use_private_key_file? Or exposing the ssl context in a callback (if it is okay to put boost in the interface)?

sivakumar101 commented 4 years ago

@jbmercha I am also trying to fix a similar problem. Have you managed to find a way out of this issue?

jbmercha commented 4 years ago

I am using websocket_client_config::set_ssl_context_callback to configure the boost::asio::ssl::context

sivakumar101 commented 4 years ago

Thanks for your reply. But isn't the websocket part abstracted from the signalr library user? What I mean is when you call the hub_connection.start, everything happens internally in the signalr library including the WSS connection request. So could you please tell me where you had set up the websocket_client_config with the ssl context callback?

jbmercha commented 4 years ago

Before calling hub_connection.start, I call hub_connection.set_client_config. That config has get/set_websocket_client_config which is where I configure the ssl context callback.

garethsb commented 4 years ago

Although it doesn't add client certs to the config, there's an example of using the same SSL context callback for both HTTPS and Secure WebSocket clients here: https://github.com/sony/nmos-cpp/blob/master/Development/nmos/client_utils.cpp#L27-L79