PrivateKey field in KConfig is now PrivateKeyPath
It was causing errors on pre-existent installations, that used the field as if it contained the key. Relaxed permissions check, as it was silently return if they were wrong and this is very confusing for a user (that should open the log to see the error)
This commit is contained in:
parent
b0c9f48efc
commit
830dd34402
7 changed files with 44 additions and 25 deletions
|
@ -57,7 +57,7 @@ Daemon::Daemon(QObject *parent) : QObject(parent)
|
|||
}
|
||||
|
||||
const QFile::Permissions strict = QFile::ReadOwner | QFile::WriteOwner | QFile::ReadUser | QFile::WriteUser;
|
||||
if (!config->group("myself").hasKey("privateKey"))
|
||||
if (!config->group("myself").hasKey("privateKeyPath"))
|
||||
{
|
||||
const QString privateKeyPath = KStandardDirs::locateLocal("appdata", "key.pem", true, KComponentData("kdeconnect", "kdeconnect"));
|
||||
|
||||
|
@ -72,20 +72,21 @@ Daemon::Daemon(QObject *parent) : QObject(parent)
|
|||
if (!privKey.setPermissions(strict))
|
||||
{
|
||||
kWarning(kdeconnect_kded()) << "Error: KDE Connect could not set permissions for private file: " << privateKeyPath;
|
||||
return;
|
||||
//return;
|
||||
}
|
||||
|
||||
//http://delta.affinix.com/docs/qca/rsatest_8cpp-example.html
|
||||
privKey.write(QCA::KeyGenerator().createRSA(2048).toPEM().toAscii());
|
||||
privKey.close();
|
||||
|
||||
config->group("myself").writeEntry("privateKey", privateKeyPath);
|
||||
config->group("myself").writeEntry("privateKeyPath", privateKeyPath);
|
||||
}
|
||||
|
||||
if (QFile::permissions(config->group("myself").readEntry("privateKey")) != strict)
|
||||
if (QFile::permissions(config->group("myself").readEntry("privateKeyPath")) != strict)
|
||||
{
|
||||
kWarning(kdeconnect_kded()) << "Error: KDE Connect detects wrong permissions for private file " << config->group("myself").readEntry("privateKey");
|
||||
return;
|
||||
kWarning(kdeconnect_kded()) << "Error: KDE Connect detects wrong permissions for private file " << config->group("myself").readEntry("privateKeyPath");
|
||||
//FIXME: Do not silently fail, because user won't notice the problem
|
||||
//return;
|
||||
}
|
||||
|
||||
//Debugging
|
||||
|
|
|
@ -36,11 +36,11 @@ Device::Device(QObject* parent, const QString& id)
|
|||
const QString& key = data.readEntry<QString>("publicKey", QString());
|
||||
m_publicKey = QCA::RSAPublicKey::fromPEM(key);
|
||||
|
||||
QFile privKey(config->group("myself").readEntry("privateKey"));
|
||||
if (privKey.open(QIODevice::ReadOnly))
|
||||
{
|
||||
m_privateKey = QCA::PrivateKey::fromPEM(privKey.readAll());
|
||||
}
|
||||
//TODO: It is redundant to have our own private key in every instance of Device, move this to a signleton 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());
|
||||
|
||||
//Register in bus
|
||||
QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors);
|
||||
|
@ -54,11 +54,11 @@ Device::Device(QObject* parent, const NetworkPackage& identityPackage, DeviceLin
|
|||
, m_pairStatus(Device::NotPaired)
|
||||
, m_protocolVersion(identityPackage.get<int>("protocolVersion"))
|
||||
{
|
||||
QFile privKey(KSharedConfig::openConfig("kdeconnectrc")->group("myself").readEntry("privateKey"));
|
||||
if (privKey.open(QIODevice::ReadOnly))
|
||||
{
|
||||
m_privateKey = QCA::PrivateKey::fromPEM(privKey.readAll());
|
||||
}
|
||||
//TODO: It is redundant to have our own private key in every instance of Device, move this to a signleton 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());
|
||||
|
||||
addLink(identityPackage, dl);
|
||||
|
||||
|
@ -258,9 +258,9 @@ void Device::removeLink(DeviceLink* link)
|
|||
}
|
||||
}
|
||||
|
||||
QString Device::privateKey() const
|
||||
QString Device::privateKeyPath() const
|
||||
{
|
||||
return KSharedConfig::openConfig("kdeconnectrc")->group("myself").readEntry("privateKey");
|
||||
return KSharedConfig::openConfig("kdeconnectrc")->group("myself").readEntry("privateKeyPath");
|
||||
}
|
||||
|
||||
bool Device::sendPackage(NetworkPackage& np)
|
||||
|
|
|
@ -83,7 +83,7 @@ public:
|
|||
void addLink(const NetworkPackage& identityPackage, DeviceLink*);
|
||||
void removeLink(DeviceLink*);
|
||||
|
||||
QString privateKey() const;
|
||||
QString privateKeyPath() const;
|
||||
|
||||
Q_SCRIPTABLE bool isPaired() const { return m_pairStatus==Device::Paired; }
|
||||
Q_SCRIPTABLE bool pairRequested() const { return m_pairStatus==Device::Requested; }
|
||||
|
@ -120,7 +120,6 @@ Q_SIGNALS:
|
|||
Q_SCRIPTABLE void unpaired();
|
||||
|
||||
private:
|
||||
//TODO: Replace device id by public key
|
||||
const QString m_deviceId;
|
||||
QString m_deviceName;
|
||||
DeviceType m_deviceType;
|
||||
|
|
|
@ -1,7 +1,27 @@
|
|||
/**
|
||||
* Copyright 2014 Yuri Samoilenko <kinnalru@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License or (at your option) version 3 or any later version
|
||||
* accepted by the membership of KDE e.V. (or its successor approved
|
||||
* by the membership of KDE e.V.), which shall act as a proxy
|
||||
* defined in Section 14 of version 3 of the license.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QSocketNotifier>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
|
||||
* Copyright 2014 Yuri Samoilenko <kinnalru@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
|
@ -20,7 +20,6 @@
|
|||
|
||||
#include "kded.h"
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QTimer>
|
||||
|
||||
#include <KPluginFactory>
|
||||
|
@ -62,7 +61,7 @@ bool Kded::start()
|
|||
m_daemon->setProgram(daemon);
|
||||
m_daemon->setOutputChannelMode(KProcess::SeparateChannels);
|
||||
m_daemon->start();
|
||||
if (!m_daemon->waitForStarted(10000))
|
||||
if (!m_daemon->waitForStarted(2000)) //FIXME: KDEDs should be non-blocking, do we really need to wait for it to start?
|
||||
{
|
||||
kError(kdeconnect_kded()) << "Can't start " << daemon;
|
||||
return false;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
|
||||
* Copyright 2014 Yuri Samoilenko <kinnalru@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
|
|
|
@ -116,7 +116,7 @@ void Mounter::onPakcageReceived(const NetworkPackage& np)
|
|||
<< "-p" << np.get<QString>("port")
|
||||
<< "-d"
|
||||
<< "-f"
|
||||
<< "-o" << "IdentityFile=" + m_sftp->device()->privateKey();
|
||||
<< "-o" << "IdentityFile=" + m_sftp->device()->privateKeyPath();
|
||||
|
||||
m_proc->setProgram(program, arguments);
|
||||
|
||||
|
|
Loading…
Reference in a new issue