Create a SSl Connection only with Slots and Signals ...
-
@SGaist
Which version of Qt are you using ? QT 5.9 (Free version)
On which platform ? Kubuntu 17.04
With which compiler ? gcc (64 bit)@J-Hilk
Yes, this is a Class Member variableI have already the error handling in place, but the program did not run into this function up to now.
After executing this code on the client, nothing happen.
m_StateMachineState=TryToConnect; m_sslSocket->connectToHostEncrypted(m_ServerTCPIPAddress, m_ServerTCPIPPort);
and the event "HostFound" is executed.
On the server, the code of "incomingConnection" is executed and the Connection Thread is created and the socket handle is also
handled over.
This code is also executed on the server.m_tcpSocket.setPrivateKey(sPrivatSSLKey); m_tcpSocket.setLocalCertificate(sLocalSSLCertificate); m_tcpSocket.startServerEncryption();
I changed the errorhandling into
{ m_LastErrorMessage=m_sslSocket->errorString(); m_sslSocket->ignoreSslErrors( ); }
I also updated the error installation for the signal to
connect(m_sslSocket,SIGNAL(sslErrors(const QList<QSslError> &errors)), this,SLOT(SSLError(const QList<QSslError> &errors)));
But i get this error during execution of the program:
QObject::connect: No such signal QSslSocket::sslErrors(const QList<QSslError> &error)
But the member m_sslSocket if type "QSslSocket".
I thought it should run at least into the error function, but it does not.
Best regards
R. -
You should use the new connect syntax, this will give you compile time error rather than runtime error.
-
@SGaist
Hi,
I try to find the new way of using the "Connection" command and failed.
I always used this documentation as a reference.
http://doc.qt.io/qt-5/signalsandslots.htmlIs there a other, better documentation for QT ?
Do you have an example, sorry asking for.Best regards
R. -
@SGaist
Hi,
I try to find the new way of using the "Connection" command and failed.
I always used this documentation as a reference.
http://doc.qt.io/qt-5/signalsandslots.htmlIs there a other, better documentation for QT ?
Do you have an example, sorry asking for.Best regards
R. -
@jsulm
But what is about thisYou should use the new connect syntax, this will give you compile time error rather than runtime error
Where is the "new connect syntax" descripted ?
Best regards
R. -
The signals and slots chapter might be of interest.
-
Thanks, that was a misunderstanding from my side.
When I use the following code:
m_sslSocket->connectToHostEncrypted(m_ServerTCPIPAddress, m_ServerTCPIPPort);
to start the SSL Communication, I do not get a "encrypted(void)" event.
But when I use the following lines
m_sslSocket->connectToHostEncrypted(m_ServerTCPIPAddress, m_ServerTCPIPPort); m_sslSocket->waitForEncrypted(-1);
I will get the "encrypted(void)" event. Additional line "waitForEncrypted(-1);", will start my communication. Why ?
I am using the following signals for the communication
connect(m_sslSocket,SIGNAL(disconnected(void)), this,SLOT(disconnected(void))); connect(m_sslSocket,SIGNAL(hostFound(void)), this,SLOT(hostFound(void))); connect(m_sslSocket,SIGNAL(encrypted(void)), this, SLOT(SSLReady(void))); connect(m_sslSocket,SIGNAL(connected(void)), this,SLOT(connected(void))); typedef void (QSslSocket::* sslErrorsSignal)(const QList<QSslError> &); connect(m_sslSocket, static_cast<sslErrorsSignal>(&QSslSocket::sslErrors),this, &DataThread::SSLError); connect(m_sslSocket,SIGNAL(readyRead(void)), this,SLOT(readyRead(void))); connect(m_sslSocket,SIGNAL(aboutToClose(void)), this,SLOT(aboutToClose(void))); connect(m_sslSocket,SIGNAL(bytesWritten(qint64)), this,SLOT(bytesWritten(qint64)));
Where is my failure, because I wouldn't like to use the command "waitForEncrypted(-1);", because this is the reason
of the SLOTS and SIGNALS.Best regards
R. -
I don't see a good reason for that.
Can you provide a minimal compilable example that shows the behaviour ?
-
@SGaist
Hi,Try the following, maybe You can understand the problem.
Download the sample ssl application from here
https://github.com/GuiTeK/Qt-SslServerModify the file "ClientExample.h"
public slots: void run(); void SSLReady(void); <-------- Add this line
Add the following function file "ClientExample.cpp"
void ClientExample::SSLReady(void) { qDebug() << "SSL Ready Connected"; }
Modify the void ClientExample::run()
connect(&sslSocket,SIGNAL(encrypted(void)), this, SLOT(SSLReady(void))); <---- Add // QThread::msleep(2000); // if (sslSocket.isEncrypted()) // Wait until encrypted connection is established, -1 means no timeout if (sslSocket.waitForEncrypted(-1)) // Wait until encrypted connection is established, -1 means no timeout { qDebug() << "isEncrypted Connected";
Remove and add the "//" depending on what you would like to see
This configuration show the The of the SSLReady
// QThread::msleep(2000); // if (sslSocket.isEncrypted()) // Wait until encrypted connection is established, -1 means no timeout if (sslSocket.waitForEncrypted(-1)) // Wait until encrypted connection is established, -1 means no timeout
This does not give a connection
QThread::msleep(2000); if (sslSocket.isEncrypted()) // Wait until encrypted connection is established, -1 means no timeout // if (sslSocket.waitForEncrypted(-1)) // Wait until encrypted connection is established, -1 means no timeout
But I am not sure, if the is a good sample, but it a base code to show the problem (hopefully).
Best regards
R. -
Hi,
still working on the problem.
Is this the correct way to ignore a error, when you are using a self registered ssl certficate ?
m_sslSocket=new QSslSocket(this); m_sslSocket->addCaCertificates(ApplicationPath + "../config/" + m_LocalSSLCertificate); m_sslSocket->ignoreSslErrors();
Is this enough for disable the failure ?
How can I disable only the certification error and not all ?
Is this the correct way ?
m_sslSocket=new QSslSocket(this); m_sslSocket->addCaCertificates(ApplicationPath + "../config/" + m_LocalSSLCertificate); QList<QSslCertificate> cert = QSslCertificate::fromPath(ApplicationPath + "../config/" + m_LocalSSLCertificate); QSslError error(QSslError::SelfSignedCertificate, cert.at(0)); QList<QSslError> expectedSslErrors; expectedSslErrors.append(error); m_sslSocket->ignoreSslErrors(expectedSslErrors);
I still did not get a event in the "sslErrors" and in the "encrypted".
And I get the Messages in the DebuggerConsole
"QSslSocket: cannot resolve SSLv2_client_method" "QSslSocket: cannot resolve SSLv2_server_method"
Best regards
R. -
What are you giving exactly to
addCaCertificates
?