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?
ssl::stream
is implemented on top of atcp::socket
, and you can access the socket directly through thenext_layer
orlowest_layer
member functions. In fact, to use thessl::stream
, you first connect the underlining socket and then invokessl::stream::handshake
. Note that you can do whatever you want between these two steps, like reading and writing from thattcp::socket
directly. See this example for details.