diff --git a/core/device.cpp b/core/device.cpp index 429ab75d6..29982e70a 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -57,11 +57,7 @@ Device::Device(QObject* parent, const QString& id) const QString& key = data.readEntry("publicKey", QString()); m_publicKey = QCA::RSAPublicKey::fromPEM(key); - //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 = KStandardDirs::locateLocal("appdata", "key.pem", true, KComponentData("kdeconnect", "kdeconnect")); - QFile privKey(privateKeyPath); - privKey.open(QIODevice::ReadOnly); - m_privateKey = QCA::PrivateKey::fromPEM(privKey.readAll()); + initPrivateKey(); //Register in bus QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors); @@ -75,11 +71,7 @@ Device::Device(QObject* parent, const NetworkPackage& identityPackage, DeviceLin , m_pairStatus(Device::NotPaired) , m_protocolVersion(identityPackage.get("protocolVersion")) { - //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 = KStandardDirs::locateLocal("appdata", "key.pem", true, KComponentData("kdeconnect", "kdeconnect")); - QFile privKey(privateKeyPath); - privKey.open(QIODevice::ReadOnly); - m_privateKey = QCA::PrivateKey::fromPEM(privKey.readAll()); + initPrivateKey(); addLink(identityPackage, dl); @@ -87,6 +79,15 @@ Device::Device(QObject* parent, const NetworkPackage& identityPackage, DeviceLin 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 = KStandardDirs::locateLocal("appdata", "key.pem", true, KComponentData("kdeconnect", "kdeconnect")); + QFile privKey(privateKeyPath); + privKey.open(QIODevice::ReadOnly); + m_privateKey = QCA::PrivateKey::fromPEM(privKey.readAll()); +} + Device::~Device() { diff --git a/core/device.h b/core/device.h index bfff08518..ec757b8de 100644 --- a/core/device.h +++ b/core/device.h @@ -140,6 +140,7 @@ private: void setAsPaired(); void storeAsTrusted(); bool sendOwnPublicKey(); + void initPrivateKey(); };