4

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);
sashoalm
  • 75,001
  • 122
  • 434
  • 781

2 Answers2

4

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.

alexisdm
  • 29,448
  • 6
  • 64
  • 99
  • Thanks, I had thought that connecting `sslErrors` was enough. I connected the `error` signal, and it is emitted with a `QAbstractSocket::UnknownSocketError` error. – sashoalm Jan 06 '13 at 16:06
  • I found out more about the error, using QSslSocket::errorString. I've edited my question now. – sashoalm Jan 06 '13 at 16:31
0

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.

Nickolay Olshevsky
  • 13,706
  • 1
  • 34
  • 48
  • Thanks for pointing that out. I've edited my question, now I'm testing with a `QSslSocket::connectToHostEncrypted` instead, but the problem is still there. Also, now I'm sure the client does send data, because I'm logging all the data from the TCP connection. – sashoalm Jan 06 '13 at 13:43