Problem with a QTcpSocket
-
I already did that; the problem is with my with slot because it's not called.
So with this code
void Connection::sslErrors(const QList<QSslError> &errors){ std::cout << "SSL error !"; }
The error message is not written. Here's my connect :
connect(m_socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &)));
As I said only de error signal is called
What did I do wrong ?
-
@moffa13
Yeah, I'm talking nonsense.sslErrors()
will not be emitted before the handshake has completed, which in your case it doesn't. See instead QSslSocket::startClientEncryption and QSslSocket::startServerEncryption, which are specifically tailored for delayed handshakes.Kind regards.
-
@moffa13
As far as understand it (I haven't done this) you create your socket as usual. But instead of callingQSslSocket::connectToHostEncrypted
, you call the regularconnectToHost
. And at one point, when you want to upgrade to an encrypted connection you call theQSslSocket::startClientEncryption
. There are a few notes in the docs of how to do it for the server side too. However, I'm not that convinced that is what you want to do ... am I misunderstand you?Kind regards.
-
Actually I am the server so I'm calling QSslSocket::startServerEncryption then the error is thrown. See the code:
void SSLServer::incomingConnection(qintptr socketDescriptor) { QScopedPointer<QSslSocket> socket(new QSslSocket(this)); if (socket->setSocketDescriptor(socketDescriptor)) { socket->addCaCertificate(certificate); socket->setLocalCertificate(certificate); socket->setPrivateKey(key); socket->startServerEncryption(); queue.enqueue(socket.take()); } }
Maybe I can do something with the slot(error) because at this point I can see the ssl error (handshake failed) and if I sleep the program the connection is closed yet. So, with this:
void Connection::error(QAbstractSocket::SocketError e){ std::cout << "SSL error ! code : " << e; }
This is written "SSL error ! code : 13" and if I add _sleep(1000) the connection is not dropped yet so maybe I can do something with it.
-
@moffa13
If you get "SSL error ! code : 13" then you should also get thesslErrors()
signal. You could try callingignoreSslErrors()
inside the error handler and this will hopefully prevent the socket from closing the connection.Kind regards.
-
I wrote this :
connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error(QAbstractSocket::SocketError))); connect(m_socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &))); ... void Connection::error(QAbstractSocket::SocketError e){ std::cout << "SSL error ! code : " << e; m_socket->ignoreSslErrors(); write("Please use SSL"); } void Connection::sslErrors(const QList<QSslError> &errors){ std::cout << "Fuck it "; std::cout << "SSL error " << errors.length(); m_socket->ignoreSslErrors(); write("Please use SSL"); }
Only the first works and the ignoreSslErrors() doesn't change anything.
-
-
Hello,
I'm sending to you a short version my code, maybe you can try something ? If you want me to write it here, I'll do it.
https://mega.nz/#!0AQxzYjZ!PDXxC-QgsWlBJYnwtQEk16jNdQiXy-d-S4AfkRWeoPc
-
I currently have a very similar problem. I'm implementing a send mail client which should gracefully fall back to an unencrypted connection if encryption fails (and the user has decided to go ahead anyway). For that purpose I've connected to the QAbstractSocket::error() signal.
While I do get the signal it's ultimately moot since the code in question (QSslSocketBackendPrivate::startHandshake() in qsslsocket_openssl.cpp) immediately closes the socket by calling QSslSocket::abort() after emitting the signal. Because of that calling QSslSocket::ignoreSslErrors() is never an option.
I currently have no workaround in place. Maybe the only solution is to connect to the disconnected() signal and then check whether the connection was closed because of a handshake error. If it was, then open a new unencrypted socket/connection. I'm open to suggestions, though... :-)