From e3225a143053f143879418bb45b8c6810d89770b Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Fri, 7 Aug 2020 14:29:17 +0530 Subject: [PATCH] fix QSslKey::ca-certificate deprecated warning --- core/backends/lan/lanlinkprovider.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/core/backends/lan/lanlinkprovider.cpp b/core/backends/lan/lanlinkprovider.cpp index d9a7d8fa3..5ec8cad7b 100644 --- a/core/backends/lan/lanlinkprovider.cpp +++ b/core/backends/lan/lanlinkprovider.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include "daemon.h" #include "landevicelink.h" @@ -472,19 +473,26 @@ void LanLinkProvider::configureSslSocket(QSslSocket* socket, const QString& devi // Configure for ssl QSslConfiguration sslConfig; sslConfig.setCiphers(socketCiphers); + sslConfig.setLocalCertificate(KdeConnectConfig::instance().certificate()); - socket->setSslConfiguration(sslConfig); - socket->setLocalCertificate(KdeConnectConfig::instance().certificate()); - socket->setPrivateKey(KdeConnectConfig::instance().privateKeyPath()); - socket->setPeerVerifyName(deviceId); + QFile privateKeyFile(KdeConnectConfig::instance().privateKeyPath()); + QSslKey privateKey; + if (privateKeyFile.open(QIODevice::ReadOnly)) { + privateKey = QSslKey(privateKeyFile.readAll(), QSsl::Rsa); + } + privateKeyFile.close(); + sslConfig.setPrivateKey(privateKey); if (isDeviceTrusted) { QString certString = KdeConnectConfig::instance().getDeviceProperty(deviceId, QStringLiteral("certificate"), QString()); - socket->addCaCertificate(QSslCertificate(certString.toLatin1())); - socket->setPeerVerifyMode(QSslSocket::VerifyPeer); + sslConfig.setCaCertificates({QSslCertificate(certString.toLatin1())}); + sslConfig.setPeerVerifyMode(QSslSocket::VerifyPeer); } else { - socket->setPeerVerifyMode(QSslSocket::QueryPeer); + sslConfig.setPeerVerifyMode(QSslSocket::QueryPeer); } + socket->setSslConfiguration(sslConfig); + socket->setPeerVerifyName(deviceId); + //Usually SSL errors are only bad for trusted devices. Uncomment this section to log errors in any case, for debugging. //QObject::connect(socket, static_cast&)>(&QSslSocket::sslErrors), [](const QList& errors)