Question

I'm trying to implement an SSL server using the sample code from Qt documentation.

But after serverSocket->startServerEncryption(); is called, nothing happens - neither the encrypted() nor the sslErrors() signals are emitted (I've put breakpoints in the slots connected to them).

I test it by connecting an QSslSocket using connectToHostEncrypted to the port I'm listening on. The socket sends data, but my server does not respond (I'm using a TCP sniffer/proxy to see all the data being sent from client to server and from server to client).

This is my code for the server:

void SslServer::incomingConnection(int socketDescriptor)
{
    qDebug() << "SslServer::incomingConnection()";
    QSslSocket *serverSocket = new QSslSocket(this);
    if (serverSocket->setSocketDescriptor(socketDescriptor)) {
        connect(serverSocket, SIGNAL(encrypted()), this, SLOT(ready()));
        connect(serverSocket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>)));
        serverSocket->startServerEncryption();
    } else {
        delete serverSocket;
    }
}

And this is how I connect to it:

server = new SslServer(this);
server->listen(QHostAddress::Any, 3333);
QSslSocket *socket = new QSslSocket(this);
socket->connectToHostEncrypted("127.0.0.1", 3333);
Was it helpful?

Solution

According to the documentation:

Both the key and the local certificate are required if you are creating an SSL server socket.

And if you don't provide them, a "regular" error(QAbstractSocket::SocketError) signal is emitted by the socket. As you found out, the server doesn't send any data in that case.

OTHER TIPS

SSH is not SSL. SSH client waits for initial data from server, while SSL client first sends data. So they both waiting for data from the other side.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top