boost::asio convert socket to secure

梦想与她 提交于 2019-12-10 17:47:55

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/11699766/boostasio-convert-socket-to-secure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!