Reputation: 358
I'm trying to configure TLS with cpprestsdk (casablanca). All documentation I've read says that this is only supported on Windows, however when I look at any code related to configuring SSL, I see #if !defined _WIN32
surrounding it. I can not configure any certificates because the functions are hidden from me. Does anyone know what is going on here?
Upvotes: 3
Views: 4230
Reputation: 111
For Windows, you only need to change protocol from 'http' to 'https' in url provided that you have attached the SSL server certificate to the port your server is using on the machine the server is running. See here for a very good description and detailed steps involved in this procedure.
For Linux, there is web::http::experimental::listener::http_listener_config
. You can set SSL options like providing certificate, private key, chain along with other options using conf
object and then provide it to http_listener
object.
web::http::experimental::listener::http_listener_config conf;
conf.set_ssl_context_callback([](boost::asio::ssl::context &ctx)
{
ctx.set_options(boost::asio::ssl::context::default_workarounds);
// Password callback needs to be set before setting cert and key.
ctx.set_password_callback([](std::size_t max_length, boost::asio::ssl::context::password_purpose purpose)
{
return "password";
});
ctx.use_certificate_file("cert.pem", boost::asio::ssl::context::pem);
ctx.use_private_key_file("key.pem", boost::asio::ssl::context::pem);
ctx.use_certificate_chain_file("chain.pem");
});
auto listener = std::unique_ptr<http_listener>(new http_listener(url, conf));
Upvotes: 7