QSslSocket and QTcpSocket ... how to know if the connection is incorrect

  • I have a TCP client and server, and either can be in SSL mode or not, depending on use case. It took me a while to get the two to talk to each other in SSL mode, but that seems to be working now.

    What's confusing is that if one of the sides is not set to SSL mode, it doesn't seem to fail via disconnect. Either I'm missing a signal listener, or I don't actually have SSL mode working.

    It would seem that if either side is set to SSL and the other is not, either a disconnect should happen, or a signal is sent that I can create a handler for. The side that is set to SSL should not like the data from the non-SSL side during handshake, and something should happen.

    I admit, I'm not sending anything over the line yet, and maybe that is the moment that a disconnect happens?

    Any ideas what I'm missing?

  • @healermagnus it would be great if you share your code as how you're using QTcpSocket or QSslSocket.

    For the later, I guess it's mandatory that you connect to the sslErrors signal

  • Moderators

    @healermagnus said in QSslSocket and QTcpSocket ... how to know if the connection is incorrect:

    Any ideas what I'm missing?

    You want a delayed handshake. Ideologically it goes like this:
    You create the QSslSocket object, but operate it as a QTcpSocket. The server and client exchange TCP messages (as per your liking) to try and negotiate whether they should stay in plain TCP or in SSL mode. When the connection is decided to be used over SSL the client calls startClientEncryption, while the server socket calls startServerEncryption to begin the actual SSL handshake. Connecting the TCP error and sslErrors() signals is a must.

Log in to reply