Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSL/TLS connection to the broker #86

Closed
requinham opened this issue Jan 5, 2017 · 4 comments
Closed

SSL/TLS connection to the broker #86

requinham opened this issue Jan 5, 2017 · 4 comments

Comments

@requinham
Copy link

Hi,

Is SSL/TLS is supported in QMQTT or not yet ?
How can we use it and set certificate and other information ? Is there an example ?

Regards,
Mohamed

@ejvr
Copy link
Contributor

ejvr commented Jan 5, 2017

There is some work done, but the implementation is not perfect yet (in my opinion).

Use the constructor of QMQTT::Client with the ssl flag set to true. If you want to make adjustments to the SSL connection, you could use QSslConfiguration::defaultConfiguration to retrieve the global SSL settings, which will return a QSslConfiguration object. Adjust that object to your liking, and put it back using QSslConfiguration::setDefaultConfiguration.
This is not a perfect solution, because it will apply to all SSL connections you'll make, but it worked for me.

It would be nice to be able to pass a QSslConfiguration directly to the QMQTT::Client constructor.

@mwallnoefer
Copy link
Collaborator

Please consider also issue #83.

@mwallnoefer
Copy link
Collaborator

Pull request #90 fixed this.

@KishoreRavih
Copy link

I am having a problem in connecting to host using qmqtt. below is my code
QFile certFile("YOURPFXFILE.pfx");
bool rt = certFile.open(QFile::ReadOnly);
qDebug()<<"certificate opened succ"<<rt;
QSslCertificate certificate;
QSslKey key;
QList importedCerts;
QString passphrase = "virtual";
bool imported = QSslCertificate::importPkcs12(&certFile, &key, &certificate, &importedCerts, QByteArray::fromStdString(passphrase.toStdString()));

   certFile.close();

   qDebug() << "Imported cert:" << imported;
   QSslConfiguration sslConfig = QSslConfiguration::defaultConfiguration();

   if (imported) {
       QList<QSslCertificate> certs = sslConfig.caCertificates();
       QList<QSslCertificate> localCerts = sslConfig.localCertificateChain();
       localCerts.append(certificate);
       certs.append(importedCerts);

       sslConfig.setLocalCertificateChain(localCerts);
       sslConfig.setCaCertificates(certs);
       sslConfig.setPrivateKey(key);
       
       sslConfig.setProtocol(QSsl::TlsV1_2);
       sslConfig.setPeerVerifyMode(QSslSocket::AutoVerifyPeer);
       QSslConfiguration::setDefaultConfiguration(sslConfig);
   }

QMQTT::Client *client = new QMQTT::Client("xxxxx.us-east-1.amazonaws.com", 8883, sslConfig, false);
connect(client, SIGNAL(connected()), this, SLOT(onConnected()));
connect(client,SIGNAL(received(QMQTT::Message)), this, SLOT(onReceived(QMQTT::Message)));
connect(client, SIGNAL(subscribed(QString,quint8)), this, SLOT(onSubscribed(QString,quint8)));
connect(client,SIGNAL(error(QMQTT::ClientError)), this, SLOT(onClientError(QMQTT::ClientError)));

client->setKeepAlive(true);
client->setAutoReconnect(true);

client->connectToHost();

I am getting QMQTT::ClientError as SocketSslHandshakeFailedError.

Can you please help me to check what am I missing??
Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants