CrowCpp / Crow

A Fast and Easy to use microframework for the web.
https://crowcpp.org
Other
3.33k stars 366 forks source link

Cannot setup asio ssl ctx #958

Open rbahegne opened 3 days ago

rbahegne commented 3 days ago

Hello, i'm trying to setup a custom context as described is the example :

crow::ssl_context_t ctx(boost::asio::ssl::context::sslv23);
ctx.set_verify_mode(boost::asio::ssl::verify_peer | boost::asio::ssl::verify_fail_if_no_peer_cert);
crow::SimpleApp app;
app.port(443).ssl(ctx).multithreaded().run();

But it won't compile :

error: cannot bind rvalue reference of type ‘boost::asio::ssl::context&&’ to lvalue of type ‘crow::ssl_context_t’ {aka ‘boost::asio::ssl::context’}
     app.port(443).ssl(ctx).multithreaded().run();
                       ^~~
In file included from /home/raph/qbridgeCrow/qbridge/src/headerOnlyLibs/crow/crow.h:25,
                 from /home/raph/qbridgeCrow/qbridge/src/governor/qPuGov.cpp:14:
/home/raph/qbridgeCrow/qbridge/src/headerOnlyLibs/crow/crow/app.h:620:17: note:   initializing argument 1 of ‘crow::Crow<Middlewares>::self_t& crow::Crow<Middlewares>::ssl(boost::asio::ssl::context&&) [with Middlewares = {}; crow::Crow<Middlewares>::self_t = crow::Crow<>]’
         self_t& ssl(asio::ssl::context&& ctx)

Any hint ?

gittiver commented 2 days ago

My first question - crow is normally build with standalone asio, you are using boost::asio classes for the ssl_context, that will not work to mix asio and boost::asio.

It is possible to build crow with boost using CMake Option CROW_USE_BOOST or alternatively rename all the boost::asio... types to asio::.. types in your sources.

rbahegne commented 14 hours ago

You are right i mixed up things a little bit.

So i have add_definitions(-DCROW_USE_BOOST) on my cmake. So using boost look like this :

    crow::SimpleApp app;
    boost::asio::ssl::context ctx(boost::asio::ssl::context::sslv23);
    app.port(443).ssl(ctx).multithreaded().run();

I still get

error: cannot bind rvalue reference of type ‘boost::asio::ssl::context&&’ to lvalue of type ‘boost::asio::ssl::context’
     app.port(443).ssl(ctx).multithreaded().run();

It expects a double &&, not sure why and how to initiate this kind of thing. Also in this example it looks simple.

In fact i don't really needs a custom ctx, i just want mutual authentification. With the .ssl i can directly provide a cert and key but no CA. Is ssl_file or ssl_chainfile is the way to go ? I'm not so sure of the difference between CA and chainfile.

mrozigor commented 7 hours ago

Just move your context ;)

app.port(443).ssl(std::move(ctx)).multithreaded().run();