Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost::asio convert socket to secure

I'm writing a server for the game Minecraft in C++.

The client sends an initial handshake packet to the server through a normal socket. The server then sends an RSA key back to the game and all socket communication from that point onwards becomes AES encrypted with the RSA key sent to the client.

I had an idea that I could avoid implementing AES/RSA and linking to other libraries in my server by simply transforming my regular boost::asio socket into a boost::asio ssl socket directly after the server sends the RSA key to the client.

How can I transform the socket if it's already been created?

like image 448
kvanbere Avatar asked Oct 26 '25 06:10

kvanbere


1 Answers

ssl::stream is implemented on top of a tcp::socket, and you can access the socket directly through the next_layer or lowest_layer member functions. In fact, to use the ssl::stream, you first connect the underlining socket and then invoke ssl::stream::handshake. Note that you can do whatever you want between these two steps, like reading and writing from that tcp::socket directly. See this example for details.

like image 167
Yakov Galka Avatar answered Oct 27 '25 21:10

Yakov Galka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!