cpprestsdk icon indicating copy to clipboard operation
cpprestsdk copied to clipboard

https request handling with listener

Open aprole opened this issue 5 years ago • 6 comments

Is the listener supposed to be able to handle https requests? When I try a basic test using curl to connect to the http listener sample I get this:

curl --request POST https://localhost:9080/A/B/C curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to localhost:9080

I'm initializing the http_listener with the URI "https://127.0.0.1:9080" When I use http it works fine. I'm testing on Linux

aprole avatar Jul 02 '19 18:07 aprole

Same problem here! @aprole did you find a solution?

emilio-simoes avatar Sep 13 '19 16:09 emilio-simoes

No, I actually switched to using Restbed instead. Works much better and is stable. I would recommend it.

aprole avatar Sep 13 '19 16:09 aprole

No, I actually switched to using Restbed instead. Works much better and is stable. I would recommend it.

Thanks @aprole ;) Restbed does seems much easier to use.

But just in case anyone else has this issue you need to provide the SSL certificated when creating the listener:

http_listener_config config;
config.set_ssl_context_callback([](boost::asio::ssl::context& context) {
    context.use_certificate_chain_file("server.pem");
    context.use_private_key_file("server_key.pem", boost::asio::ssl::context::pem);
});
_listener = http_listener(endpointBuilder.to_uri(), config);

Cheers

emilio-simoes avatar Sep 13 '19 17:09 emilio-simoes

No, I actually switched to using Restbed instead. Works much better and is stable. I would recommend it.

Thanks @aprole ;) Restbed does seems much easier to use.

But just in case anyone else has this issue you need to provide the SSL certificated when creating the listener:

http_listener_config config;
config.set_ssl_context_callback([](boost::asio::ssl::context& context) {
    context.use_certificate_chain_file("server.pem");
    context.use_private_key_file("server_key.pem", boost::asio::ssl::context::pem);
});
_listener = http_listener(endpointBuilder.to_uri(), config);

Cheers

seems it does NOT work on window?

yzxandfcm avatar Apr 02 '20 12:04 yzxandfcm

No, I actually switched to using Restbed instead. Works much better and is stable. I would recommend it.

Thanks @aprole ;) Restbed does seems much easier to use. But just in case anyone else has this issue you need to provide the SSL certificated when creating the listener:

http_listener_config config;
config.set_ssl_context_callback([](boost::asio::ssl::context& context) {
    context.use_certificate_chain_file("server.pem");
    context.use_private_key_file("server_key.pem", boost::asio::ssl::context::pem);
});
_listener = http_listener(endpointBuilder.to_uri(), config);

Cheers

seems it does NOT work on window?

Have you addressed the problem?

sinall avatar Oct 02 '21 09:10 sinall

Anyone else face issue when you need to provide the SSL certificated while creating the listener and validating client certificate on server side. Here my code...[call back function never got hit]

http_listener_config config; config.set_ssl_context_callback([](boost::asio::ssl::context &ctx) { try { std::clog << "set_ssl_context_callback" << std::endl; ctx.set_options( boost::asio::ssl::context::default_workarounds | boost::asio::ssl::context::no_sslv2 | boost::asio::ssl::context::no_tlsv1 | boost::asio::ssl::context::no_tlsv1_1 | boost::asio::ssl::context::single_dh_use); ctx.set_password_callback([](std::size_t max_length, boost::asio::ssl::context::password_purpose purpose) { return "password"; }); ctx.use_certificate_chain_file("F://certificate.crt"); ctx.use_private_key_file("F://certificate.key", boost::asio::ssl::context::pem); } catch (std::exception const& e) { std::clog << "ERROR: " << e.what() << "\n"; }

});

Akvenki avatar Feb 02 '23 10:02 Akvenki