[SCM] kdeconnect packaging branch, master, updated. debian/0.9g-1-1183-g9d69498

Maximiliano Curia maxy at moszumanska.debian.org
Fri Oct 14 14:29:28 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/kdeconnect.git;a=commitdiff;h=ddca4d6

The following commit has been merged in the master branch:
commit ddca4d6d635808bb187fc8ba97c7484d76f5b180
Author: Albert Vaca <albertvaka at gmail.com>
Date:   Thu Dec 17 04:41:10 2015 -0800

    Store and restore certificate and public key in lan link
---
 core/backends/devicelink.h              |  7 ++---
 core/backends/lan/landevicelink.cpp     | 46 ++++++++++++++++++++++++++-------
 core/backends/lan/landevicelink.h       |  6 ++++-
 core/backends/lan/lanlinkprovider.cpp   | 16 +++++-------
 core/backends/lan/lanpairinghandler.cpp | 31 +++++++++-------------
 5 files changed, 65 insertions(+), 41 deletions(-)

diff --git a/core/backends/devicelink.h b/core/backends/devicelink.h
index 5982272..c588579 100644
--- a/core/backends/devicelink.h
+++ b/core/backends/devicelink.h
@@ -55,10 +55,11 @@ public:
     virtual void userRequestsPair() = 0;
     virtual void userRequestsUnpair() = 0;
 
-    ConnectionStarted connectionSource() const { return mConnectionSource; }
+    ConnectionStarted connectionSource() const { return mConnectionSource; } //TODO: Move this down to landevicelink and create an abstraction like "bool keepConnectionOpen()" here.
+    void setConnectionSource(ConnectionStarted source) { mConnectionSource = source; }
 
     PairStatus pairStatus() const { return mPairStatus; }
-    void setPairStatus(PairStatus status);
+    virtual void setPairStatus(PairStatus status);
 
 Q_SIGNALS:
     void receivedPackage(const NetworkPackage& np);
@@ -70,7 +71,7 @@ protected:
 
 private:
     const QString mDeviceId;
-    const ConnectionStarted mConnectionSource;
+    ConnectionStarted mConnectionSource;
     LinkProvider* mLinkProvider;
     PairStatus mPairStatus;
 
diff --git a/core/backends/lan/landevicelink.cpp b/core/backends/lan/landevicelink.cpp
index c172dbb..8fc2b26 100644
--- a/core/backends/lan/landevicelink.cpp
+++ b/core/backends/lan/landevicelink.cpp
@@ -20,7 +20,7 @@
 
 #include "landevicelink.h"
 #include "core_debug.h"
-
+#include <kdeconnectconfig.h>
 #include "../linkprovider.h"
 #include "uploadjob.h"
 #include "downloadjob.h"
@@ -36,21 +36,34 @@ LanDeviceLink::LanDeviceLink(const QString& deviceId, LinkProvider* parent, QSsl
 
 void LanDeviceLink::reset(QSslSocket* socket, DeviceLink::ConnectionStarted connectionSource)
 {
-    //We take ownership of the socket.
-    //When the link provider destroys us,
-    //the socket (and the reader) will be
-    //destroyed as well
-
     if (mSocketLineReader) {
         delete mSocketLineReader;
     }
 
-    mSocketLineReader = new SocketLineReader(socket);
+    mSocketLineReader = new SocketLineReader(socket, this);
 
     connect(socket, SIGNAL(disconnected()), this, SLOT(deleteLater()));
     connect(mSocketLineReader, SIGNAL(readyRead()), this, SLOT(dataReceived()));
-    mSocketLineReader->setParent(this);
+
+    //We take ownership of the socket.
+    //When the link provider destroys us,
+    //the socket (and the reader) will be
+    //destroyed as well
     socket->setParent(this);
+
+    setConnectionSource(connectionSource);
+
+    if (m_certificate.isNull()) {
+
+        QString certString = KdeConnectConfig::instance()->getDeviceProperty(deviceId(), "certificate");
+        m_certificate = QSslCertificate(certString.toLatin1());
+
+        QString keyString = KdeConnectConfig::instance()->getDeviceProperty(deviceId(), "publicKey");
+        m_publicKey = QCA::PublicKey::fromPEM(keyString.toLatin1());
+
+        DeviceLink::setPairStatus(m_certificate.isNull()? PairStatus::NotPaired : PairStatus::Paired);
+    }
+
 }
 
 QString LanDeviceLink::name()
@@ -137,8 +150,23 @@ void LanDeviceLink::userRequestsUnpair()
     setPairStatus(NotPaired);
 }
 
-void LanDeviceLink::storeTrustedDeviceInformation()
+void LanDeviceLink::setPairStatus(PairStatus status)
+{
+    if (status == Paired) {
+        Q_ASSERT(KdeConnectConfig::instance()->trustedDevices().contains(deviceId()));
+        Q_ASSERT(!m_certificate.isNull());
+        Q_ASSERT(!m_publicKey.isNull());
+        KdeConnectConfig::instance()->setDeviceProperty(deviceId(), "certificate", m_certificate.toPem());
+        KdeConnectConfig::instance()->setDeviceProperty(deviceId(), "publicKey", m_publicKey.toPEM());
+    }
+
+    DeviceLink::setPairStatus(status);
+}
+
+void LanDeviceLink::setCertificate(QSslCertificate certificate, QCA::PublicKey publicKey)
 {
     Q_ASSERT(!m_certificate.isNull());
     Q_ASSERT(!m_publicKey.isNull());
+    m_certificate = certificate;
+    m_publicKey = publicKey;
 }
diff --git a/core/backends/lan/landevicelink.h b/core/backends/lan/landevicelink.h
index fa6667b..07b3959 100644
--- a/core/backends/lan/landevicelink.h
+++ b/core/backends/lan/landevicelink.h
@@ -24,6 +24,7 @@
 #include <QObject>
 #include <QString>
 #include <QSslSocket>
+#include <QSslCertificate>
 
 #include "../devicelink.h"
 #include "uploadjob.h"
@@ -47,7 +48,10 @@ public:
     virtual void userRequestsPair() override;
     virtual void userRequestsUnpair() override;
 
-    void storeTrustedDeviceInformation();
+    void setCertificate(QSslCertificate certificate, QCA::PublicKey publicKey);
+    QSslCertificate certificate() { return m_certificate; }
+
+    virtual void setPairStatus(PairStatus status) override;
 
 private Q_SLOTS:
     void dataReceived();
diff --git a/core/backends/lan/lanlinkprovider.cpp b/core/backends/lan/lanlinkprovider.cpp
index 347b7e1..e574775 100644
--- a/core/backends/lan/lanlinkprovider.cpp
+++ b/core/backends/lan/lanlinkprovider.cpp
@@ -211,17 +211,15 @@ void LanLinkProvider::connected()
         qCDebug(KDECONNECT_CORE) << "Handshaking done (i'm the existing device)";
 
         // if ssl supported
-        if (NetworkPackage::ProtocolVersion <= receivedPackage->get<int>("protocolVersion")) {
+        if (receivedPackage->get<int>("protocolVersion") >= NetworkPackage::ProtocolVersion) {
             // since I support ssl and remote device support ssl
 	        qCDebug(KDECONNECT_CORE) << "Setting up ssl server";
 
-            bool isDeviceTrusted = KdeConnectConfig::instance()->trustedDevices().contains(deviceId);
-
             socket->setPeerVerifyName(receivedPackage->get<QString>("deviceId"));
 
-            if (isDeviceTrusted) {
+            QString certString = KdeConnectConfig::instance()->getDeviceProperty(deviceId, "certificate", QString());
+            if (!certString.isEmpty()) {
                 qDebug() << "Device trusted";
-                QString certString = KdeConnectConfig::instance()->getDeviceProperty(deviceId, "certificate", QString());
                 socket->addCaCertificate(QSslCertificate(certString.toLatin1()));
                 socket->setPeerVerifyMode(QSslSocket::VerifyPeer);
                 connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>)));
@@ -236,6 +234,7 @@ void LanLinkProvider::connected()
             socket->startServerEncryption();
             return; // Return statement prevents from deleting received package, needed in slot "encrypted"
         } else {
+            qWarning() << "Incompatible protocol version, this won't work";
             addLink(deviceId, socket, receivedPackage, DeviceLink::Remotely);
         }
 
@@ -440,7 +439,7 @@ void LanLinkProvider::addLink(const QString& deviceId, QSslSocket* socket, Netwo
 
     LanDeviceLink* deviceLink;
     //Do we have a link for this device already?
-    QMap< QString, LanDeviceLink* >::iterator linkIterator = mLinks.find(deviceLink->deviceId());
+    QMap< QString, LanDeviceLink* >::iterator linkIterator = mLinks.find(deviceId);
     if (linkIterator != mLinks.end()) {
         deviceLink = linkIterator.value();
         deviceLink->reset(socket, connectionOrigin);
@@ -476,10 +475,9 @@ void LanLinkProvider::refreshPairingHandler(const QString& deviceId) {
         connect(ph, &LanPairingHandler::pairingError, link, &DeviceLink::pairingError);
     }
 }
-
-void LanLinkProvider::incomingPairPackage(DeviceLink* device, const NetworkPackage& np)
+void LanLinkProvider::incomingPairPackage(DeviceLink* deviceLink, const NetworkPackage& np)
 {
-    const QString deviceId = device->deviceId();
+    const QString deviceId = deviceLink->deviceId();
     LanPairingHandler* ph = mPairingHandlers.value(deviceId);
     if (!ph) {
         ph = new LanPairingHandler(deviceId);
diff --git a/core/backends/lan/lanpairinghandler.cpp b/core/backends/lan/lanpairinghandler.cpp
index d3f66db..a3dba16 100644
--- a/core/backends/lan/lanpairinghandler.cpp
+++ b/core/backends/lan/lanpairinghandler.cpp
@@ -53,20 +53,11 @@ void LanPairingHandler::packageReceived(const NetworkPackage& np)
 
     bool wantsPair = np.get<bool>("pair");
 
-    if (wantsPair == isPaired()) {
+    if (wantsPair == isPaired() && isPairRequested()) {
 //        qCDebug(KDECONNECT_CORE) << "Already" << (wantsPair? "paired":"unpaired");
-        if (isPairRequested()) {
-            setInternalPairStatus(NotPaired);
-            Q_EMIT pairingError(i18n("Canceled by other peer"));
-            return;
-        } else if (isPaired()) {
-            /**
-             * If wants pair is true and is paired is true, this means other device is trying to pair again, might be because it unpaired this device somehow
-             * and we don't know it, unpair it internally
-             */
-            KdeConnectConfig::instance()->removeTrustedDevice(m_deviceId);
-            setInternalPairStatus(NotPaired);
-        }
+        setInternalPairStatus(NotPaired);
+        Q_EMIT pairingError(i18n("Canceled by other peer"));
+        return;
     }
 
     if (wantsPair) {
@@ -74,19 +65,23 @@ void LanPairingHandler::packageReceived(const NetworkPackage& np)
         QString keyString = np.get<QString>("publicKey");
         QString certificateString = np.get<QByteArray>("certificate");
 
-        if (QCA::RSAPublicKey::fromPEM(keyString).isNull()) {
+        QCA::PublicKey publicKey = QCA::PublicKey::fromPEM(keyString);
+        QSslCertificate certificate(keyString.toLatin1());
+
+        if (certificate.isNull()) {
             if (isPairRequested()) {
                 setInternalPairStatus(NotPaired);
             }
-            Q_EMIT pairingError(i18n("Received incorrect key"));
+            Q_EMIT pairingError(i18n("Received incorrect certificate"));
             return;
         }
 
+        qobject_cast<LanDeviceLink*>(deviceLink())->setCertificate(certificate, publicKey);
+
         if (isPairRequested())  { //We started pairing
 
             qCDebug(KDECONNECT_CORE) << "Pair answer";
-            KdeConnectConfig::instance()->setDeviceProperty(m_deviceId, "publicKey", keyString);
-            KdeConnectConfig::instance()->setDeviceProperty(m_deviceId, "certificate", certificateString);
+            deviceLink()->setPairStatus(DeviceLink::PairStatus::Paired);
             
         } else {
             qCDebug(KDECONNECT_CORE) << "Pair request";
@@ -188,6 +183,4 @@ void LanPairingHandler::setInternalPairStatus(LanPairingHandler::InternalPairSta
     } else {
         deviceLink()->setPairStatus(DeviceLink::NotPaired);
     }
-    qobject_cast<LanDeviceLink*>(deviceLink())->storeTrustedDeviceInformation();
-    //TODO: Tell link to store certificate and key
 }

-- 
kdeconnect packaging



More information about the pkg-kde-commits mailing list