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

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


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

The following commit has been merged in the master branch:
commit ef70772f7014118f392567accd2c55c76b18bd2e
Author: Aleix Pol <aleixpol at kde.org>
Date:   Mon Mar 2 00:42:50 2015 +0100

    Clean up generation of the host's private key
    
    Only look for it in the writable path, as it won't ever be installed in a
    common place.
    Don't look for the path in the config file either.
    Don't make it depend on the application name.
    
    REVIEW: 122744
---
 core/daemon.cpp | 24 +++++++-----------------
 core/device.cpp | 45 +++++++++++++++++++++------------------------
 core/device.h   |  4 +---
 3 files changed, 29 insertions(+), 44 deletions(-)

diff --git a/core/daemon.cpp b/core/daemon.cpp
index 3688b4b..bbdc073 100644
--- a/core/daemon.cpp
+++ b/core/daemon.cpp
@@ -84,10 +84,11 @@ Daemon::Daemon(QObject *parent)
     }
 
     const QFile::Permissions strict = QFile::ReadOwner | QFile::WriteOwner | QFile::ReadUser | QFile::WriteUser;
-    if (!config->group("myself").hasKey("privateKeyPath"))
+
+    const QString privateKeyPath = Device::privateKeyPath();
+    if (!QFile::exists(privateKeyPath))
     {
-        QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
-        const QString privateKeyPath = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QStringLiteral("/key.pem");
+        QDir::root().mkpath(QFileInfo(privateKeyPath).dir().path());
 
         QFile privKey(privateKeyPath);
 
@@ -102,23 +103,12 @@ Daemon::Daemon(QObject *parent)
             qCDebug(KDECONNECT_CORE) << "Error: KDE Connect could not set permissions for private file: " << privateKeyPath;
         }
 
-        //http://delta.affinix.com/docs/qca/rsatest_8cpp-example.html
-        if (config->group("myself").hasKey("privateKey")) {
-            //Migration from older versions of KDE Connect
-            privKey.write(config->group("myself").readEntry<QString>("privateKey",QCA::KeyGenerator().createRSA(2048).toPEM()).toLatin1());
-        } else {
-            privKey.write(QCA::KeyGenerator().createRSA(2048).toPEM().toLatin1());
-        }
-        privKey.close();
-
-        //TODO: This should not store an absolute path: it will cause problems if the home folder changes, .kde4 becomes .kde (debian?), or similar...
-        config->group("myself").writeEntry("privateKeyPath", privateKeyPath);
-        config->sync();
+        privKey.write(QCA::KeyGenerator().createRSA(2048).toPEM().toLatin1());
     }
 
-    if (QFile::permissions(config->group("myself").readEntry("privateKeyPath")) != strict)
+    if (QFile::permissions(privateKeyPath) != strict)
     {
-        qCDebug(KDECONNECT_CORE) << "Error: KDE Connect detects wrong permissions for private file " << config->group("myself").readEntry("privateKeyPath");
+        qCDebug(KDECONNECT_CORE) << "Error: KDE Connect detects wrong permissions for private file " << privateKeyPath;
     }
 
     //Register on DBus
diff --git a/core/device.cpp b/core/device.cpp
index e8412b7..530bb09 100644
--- a/core/device.cpp
+++ b/core/device.cpp
@@ -43,6 +43,22 @@
 
 Q_LOGGING_CATEGORY(KDECONNECT_CORE, "kdeconnect.core")
 
+QCA::PrivateKey initPrivateKey()
+{
+    QCA::PrivateKey ret;
+    QFile privKey(Device::privateKeyPath());
+    if (privKey.open(QIODevice::ReadOnly))
+        ret = QCA::PrivateKey::fromPEM(privKey.readAll());
+    else {
+        qWarning() << "Could not open the private key" << Device::privateKeyPath();
+    }
+
+    Q_ASSERT(!ret.isNull());
+
+    return ret;
+}
+Q_GLOBAL_STATIC_WITH_ARGS(QCA::PrivateKey, s_privateKey, (initPrivateKey()))
+
 Device::Device(QObject* parent, const QString& id)
     : QObject(parent)
     , m_deviceId(id)
@@ -58,8 +74,6 @@ Device::Device(QObject* parent, const QString& id)
     const QString& key = data.readEntry<QString>("publicKey", QString());
     m_publicKey = QCA::RSAPublicKey::fromPEM(key);
     
-    initPrivateKey();
-
     //Register in bus
     QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors);
 }
@@ -74,29 +88,12 @@ Device::Device(QObject* parent, const NetworkPackage& identityPackage, DeviceLin
     , m_incomingCapabilities(identityPackage.get<QStringList>("SupportedIncomingInterfaces", QStringList()).toSet())
     , m_outgoingCapabilities(identityPackage.get<QStringList>("SupportedOutgoingInterfaces", QStringList()).toSet())
 {
-    initPrivateKey();
-
     addLink(identityPackage, dl);
     
     //Register in bus
     QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors);
 }
 
-void Device::initPrivateKey()
-{
-    //TODO: It is redundant to have our own private key in every instance of Device, move this to a singleton somewhere (Daemon?)
-    const QString privateKeyPath = QStandardPaths::locate(QStandardPaths::QStandardPaths::DataLocation, QStringLiteral("key.pem"));
-
-    QFile privKey(privateKeyPath);
-    if (privKey.open(QIODevice::ReadOnly))
-        m_privateKey = QCA::PrivateKey::fromPEM(privKey.readAll());
-    else {
-        qWarning() << "Could not open the private key" << privateKeyPath;
-    }
-
-    Q_ASSERT(!m_privateKey.isNull());
-}
-
 Device::~Device()
 {
 
@@ -274,8 +271,8 @@ void Device::addLink(const NetworkPackage& identityPackage, DeviceLink* link)
     m_deviceName = identityPackage.get<QString>("deviceName");
     m_deviceType = str2type(identityPackage.get<QString>("deviceType"));
 
-    Q_ASSERT(!m_privateKey.isNull());
-    link->setPrivateKey(m_privateKey);
+    Q_ASSERT(!s_privateKey->isNull());
+    link->setPrivateKey(*s_privateKey);
 
     //Theoretically we will never add two links from the same provider (the provider should destroy
     //the old one before this is called), so we do not have to worry about destroying old links.
@@ -313,9 +310,9 @@ void Device::removeLink(DeviceLink* link)
     }
 }
 
-QString Device::privateKeyPath() const
+QString Device::privateKeyPath()
 {
-    return KSharedConfig::openConfig("kdeconnectrc")->group("myself").readEntry("privateKeyPath");
+    return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/org.kde.kdeconnect/key.pem");
 }
 
 bool Device::sendPackage(NetworkPackage& np)
@@ -426,7 +423,7 @@ bool Device::sendOwnPublicKey()
 {
     NetworkPackage np(PACKAGE_TYPE_PAIR);
     np.set("pair", true);
-    np.set("publicKey", m_privateKey.toPublicKey().toPEM());
+    np.set("publicKey", s_privateKey->toPublicKey().toPEM());
     bool success = sendPackage(np);
     return success;
 }
diff --git a/core/device.h b/core/device.h
index 2ebb403..5ced32d 100644
--- a/core/device.h
+++ b/core/device.h
@@ -86,7 +86,7 @@ public:
     void addLink(const NetworkPackage& identityPackage, DeviceLink*);
     void removeLink(DeviceLink*);
 
-    QString privateKeyPath() const;
+    static QString privateKeyPath();
     
     Q_SCRIPTABLE bool isPaired() const { return m_pairStatus==Device::Paired; }
     Q_SCRIPTABLE bool pairRequested() const { return m_pairStatus==Device::Requested; }
@@ -125,7 +125,6 @@ private:
     const QString m_deviceId;
     QString m_deviceName;
     DeviceType m_deviceType;
-    QCA::PrivateKey m_privateKey;
     QCA::PublicKey m_publicKey;
     PairStatus m_pairStatus;
     int m_protocolVersion;
@@ -142,7 +141,6 @@ private:
     void setAsPaired();
     void storeAsTrusted();
     bool sendOwnPublicKey();
-    void initPrivateKey();
 
 };
 

-- 
kdeconnect packaging



More information about the pkg-kde-commits mailing list