[SCM] kdeconnect packaging branch, master, updated. debian/0.9g-1-1183-g9d69498
Maximiliano Curia
maxy at moszumanska.debian.org
Fri Oct 14 14:29:05 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/kdeconnect.git;a=commitdiff;h=5e0a7a3
The following commit has been merged in the master branch:
commit 5e0a7a34b960ca4c44b5f1ed31246044f5f30a56
Merge: 78e9c08732981402b69e6a5263e9eb4f895d4f17 b62349cae6caa5a8edc910af0663a609c6d16fda
Author: Aleix Pol <aleixpol at kde.org>
Date: Fri Sep 11 17:25:23 2015 +0200
Merge branch 'master' into ssl
# Conflicts:
# cli/kdeconnect-cli.cpp
# core/backends/lan/landevicelink.cpp
# core/backends/lan/landevicelink.h
# core/backends/lan/lanlinkprovider.cpp
# core/backends/lan/lanlinkprovider.h
# core/backends/lan/socketlinereader.h
# core/backends/lan/uploadjob.cpp
# core/backends/lan/uploadjob.h
# core/backends/loopback/loopbackdevicelink.h
# core/daemon.cpp
# core/daemon.h
# core/device.cpp
# core/device.h
CMakeLists.txt | 14 +-
README.md | 2 +-
app/main.cpp | 6 +-
app/org.kde.kdeconnect.app.desktop | 9 +
app/qml/main.qml | 2 +-
cli/CMakeLists.txt | 1 +
cli/kdeconnect-cli.cpp | 44 +--
core/CMakeLists.txt | 2 +-
core/backends/devicelink.cpp | 6 +-
core/backends/devicelink.h | 11 +-
core/backends/lan/downloadjob.h | 2 +-
core/backends/lan/landevicelink.cpp | 9 +-
core/backends/lan/landevicelink.h | 6 +-
core/backends/lan/lanlinkprovider.cpp | 29 +-
core/backends/lan/lanlinkprovider.h | 14 +-
core/backends/lan/socketlinereader.h | 3 +-
core/backends/lan/uploadjob.cpp | 9 +-
core/backends/lan/uploadjob.h | 4 +-
core/backends/loopback/loopbackdevicelink.cpp | 6 +-
core/backends/loopback/loopbackdevicelink.h | 8 +-
core/backends/loopback/loopbacklinkprovider.cpp | 2 -
core/backends/loopback/loopbacklinkprovider.h | 13 +-
core/daemon.cpp | 93 ++++--
core/daemon.h | 26 +-
core/default_args.h | 61 ----
core/device.cpp | 113 +++++--
core/device.h | 15 +-
core/filetransferjob.cpp | 10 +-
core/filetransferjob.h | 4 +-
core/kdeconnectplugin.cpp | 8 +-
core/kdeconnectpluginconfig.h | 3 +-
core/networkpackage.cpp | 4 +-
core/networkpackage.h | 3 +-
core/networkpackagetypes.h | 1 +
core/pluginloader.cpp | 2 +-
daemon/CMakeLists.txt | 6 +
daemon/kdeconnect.desktop | 4 +-
daemon/kdeconnectd.cpp | 27 +-
daemon/kdeconnectd.desktop.cmake | 7 +-
daemon/org.kde.kdeconnect.service.in | 2 +-
fileitemactionplugin/kdeconnectsendfile.desktop | 2 +
fileitemactionplugin/sendfileitemaction.h | 2 +-
interfaces/dbusinterfaces.cpp | 3 +
interfaces/dbusinterfaces.h | 18 +-
interfaces/devicesmodel.cpp | 17 +-
interfaces/devicesmodel.h | 8 +-
interfaces/devicessortproxymodel.h | 6 +-
interfaces/notificationsmodel.cpp | 6 +-
interfaces/notificationsmodel.h | 8 +-
kcm/kcm.cpp | 52 ++--
kcm/kcm.h | 1 +
kcm/kcm_kdeconnect.desktop | 7 +-
kcm/kdeconnect.desktop | 42 +--
kcmplugin/CMakeLists.txt | 2 +-
kcmplugin/kdeconnectpluginkcm.h | 4 +-
kdeconnect-non-plasma.desktop | 75 ++---
kio/kiokdeconnect.h | 8 +-
.../kdeconnectdeclarativeplugin.h | 4 +-
plasmoid/declarativeplugin/objectfactory.h | 12 +-
plasmoid/declarativeplugin/processrunner.h | 2 +-
plasmoid/declarativeplugin/responsewaiter.cpp | 4 +-
plasmoid/declarativeplugin/responsewaiter.h | 2 +-
plasmoid/package/metadata.desktop | 4 +-
plugins/CMakeLists.txt | 14 +-
plugins/battery/batterydbusinterface.cpp | 1 +
plugins/battery/batteryplugin.cpp | 4 +-
plugins/battery/batteryplugin.h | 4 +-
plugins/battery/kdeconnect_battery.json | 2 +
plugins/clipboard/clipboardplugin.h | 4 +-
plugins/clipboard/kdeconnect_clipboard.json | 2 +
plugins/kdeconnect.notifyrc | 20 +-
plugins/kdeconnect_plugin.desktop | 1 +
plugins/lockdevice/kdeconnect_lockdevice.json | 4 +
plugins/mousepad/kdeconnect_mousepad.json | 2 +
plugins/mousepad/mousepadplugin.cpp | 11 +-
plugins/mousepad/mousepadplugin.h | 4 +-
plugins/mpriscontrol/kdeconnect_mpriscontrol.json | 2 +
plugins/mpriscontrol/mpriscontrolplugin.cpp | 28 +-
plugins/mpriscontrol/mpriscontrolplugin.h | 7 +-
plugins/mprisremote/kdeconnect_mprisremote.json | 4 +
.../notifications/kdeconnect_notifications.json | 4 +
.../notifications/notificationsdbusinterface.cpp | 3 -
plugins/notifications/notificationsplugin.h | 4 +-
plugins/pausemusic/kdeconnect_pausemusic.json | 2 +
.../kdeconnect_pausemusic_config.desktop | 1 +
plugins/pausemusic/pausemusic_config.h | 6 +-
plugins/pausemusic/pausemusicplugin.h | 4 +-
plugins/ping/kdeconnect_ping.json | 2 +
plugins/ping/pingplugin.h | 4 +-
.../remotecontrol/kdeconnect_remotecontrol.json | 4 +
.../kdeconnect_screensaver_inhibit.json | 2 +
.../screensaverinhibitplugin.cpp | 2 +-
.../screensaver-inhibit/screensaverinhibitplugin.h | 4 +-
plugins/sftp/kdeconnect_sftp.json | 2 +
plugins/sftp/mounter.cpp | 11 +-
plugins/sftp/sftpplugin.cpp | 6 +-
plugins/sftp/sftpplugin.h | 4 +-
plugins/share/kdeconnect_share.json | 2 +
plugins/share/kdeconnect_share_config.desktop | 1 +
plugins/share/share_config.cpp | 3 +-
plugins/share/share_config.h | 6 +-
plugins/share/shareplugin.cpp | 6 +-
plugins/share/shareplugin.h | 7 +-
plugins/telephony/CMakeLists.txt | 7 +
plugins/telephony/kdeconnect_telephony.json | 2 +
plugins/telephony/sendsmsdialog.cpp | 64 ++++
.../telephony/sendsmsdialog.h | 46 ++-
plugins/telephony/telephonyplugin.cpp | 78 +++--
plugins/telephony/telephonyplugin.h | 17 +-
telepathy-cm/CMakeLists.txt | 24 ++
telepathy-cm/README | 1 +
telepathy-cm/connectcm_export.h | 12 +
telepathy-cm/connection.cpp | 344 +++++++++++++++++++++
telepathy-cm/connection.h | 71 +++++
telepathy-cm/kdeconnect.manager | 6 +
.../kdeconnecttelepathyprotocolfactory.cpp | 71 +++++
telepathy-cm/kdeconnecttelepathyprotocolfactory.h | 18 ++
telepathy-cm/protocol.cpp | 116 +++++++
telepathy-cm/protocol.h | 68 ++++
telepathy-cm/textchannel.cpp | 73 +++++
telepathy-cm/textchannel.h | 46 +++
tests/CMakeLists.txt | 3 +
tests/devicetest.cpp | 4 +-
tests/networkpackagetests.cpp | 2 +-
tests/pluginloadtest.cpp | 104 +++++++
tests/sendfiletest.cpp | 118 +++++++
tests/testsocketlinereader.cpp | 2 +-
127 files changed, 1889 insertions(+), 492 deletions(-)
diff --cc cli/kdeconnect-cli.cpp
index cfcb70d,f8f6fec..05a62dc
--- a/cli/kdeconnect-cli.cpp
+++ b/cli/kdeconnect-cli.cpp
@@@ -18,7 -18,7 +18,8 @@@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <QCryptographicHash>
+ #include <QIODevice>
#include <QDBusMessage>
#include <QDBusConnection>
#include <QCoreApplication>
@@@ -148,25 -152,6 +154,27 @@@ int main(int argc, char** argv
QTextStream(stdout) << "- " << idx.data(NotificationsModel::AppNameModelRole).toString()
<< ": " << idx.data(NotificationsModel::NameModelRole).toString() << endl;
}
+ } else if(parser.isSet("encryption-info")) {
- DeviceDbusInterface dev(device);
- QDBusPendingReply<QByteArray> devReply = dev.certificate(1); // QSsl::Der = 1
- devReply.waitForFinished();
- if (devReply.value().isEmpty()) {
- QTextStream(stderr) << i18n("The other device doesn\'t use a recent version of KDE Connect, using the legacy encryption method.") << endl;
- } else {
- QByteArray remoteCertificate = QCryptographicHash::hash(devReply.value(), QCryptographicHash::Sha1).toHex();
- for (int i=2 ; i<remoteCertificate.size() ; i+=3) remoteCertificate.insert(i, ':'); // Improve readability
++ DeviceDbusInterface dev(device);
++ QDBusPendingReply<QByteArray> devReply = dev.certificate(1); // QSsl::Der = 1
++ devReply.waitForFinished();
++ if (devReply.value().isEmpty()) {
++ QTextStream(stderr) << i18n("The other device doesn\'t use a recent version of KDE Connect, using the legacy encryption method.") << endl;
++ } else {
++ QByteArray remoteCertificate = QCryptographicHash::hash(devReply.value(), QCryptographicHash::Sha1).toHex();
++ for (int i=2 ; i<remoteCertificate.size() ; i+=3)
++ remoteCertificate.insert(i, ':'); // Improve readability
+
- DaemonDbusInterface iface;
- QDBusPendingReply<QByteArray> ifaceReply = iface.certificate(1); // QSsl::Der = 1
- ifaceReply.waitForFinished();
- QByteArray myCertificate = QCryptographicHash::hash(ifaceReply.value(), QCryptographicHash::Sha1).toHex();
- for (int i=2 ; i<myCertificate.size() ; i+=3) myCertificate.insert(i, ':'); // Improve readability
++ DaemonDbusInterface iface;
++ QDBusPendingReply<QByteArray> ifaceReply = iface.certificate(1); // QSsl::Der = 1
++ ifaceReply.waitForFinished();
++ QByteArray myCertificate = QCryptographicHash::hash(ifaceReply.value(), QCryptographicHash::Sha1).toHex();
++ for (int i=2 ; i<myCertificate.size() ; i+=3)
++ myCertificate.insert(i, ':'); // Improve readability
+
- QTextStream(stderr) << i18n("SHA1 fingerprint of your device certificate is : ") << myCertificate << endl;
- QTextStream(stderr) << i18n("SHA1 fingerprint of remote device certificate is : ") << remoteCertificate << endl;
- }
++ QTextStream(stderr) << i18n("SHA1 fingerprint of your device certificate is : ") << myCertificate << endl;
++ QTextStream(stderr) << i18n("SHA1 fingerprint of remote device certificate is : ") << remoteCertificate << endl;
++ }
} else {
QTextStream(stderr) << i18n("Nothing to be done") << endl;
}
diff --cc core/backends/devicelink.h
index e072507,158db8d..e7682b0
--- a/core/backends/devicelink.h
+++ b/core/backends/devicelink.h
@@@ -36,11 -35,11 +36,13 @@@ class DeviceLin
Q_OBJECT
public:
- DeviceLink(const QString& deviceId, LinkProvider* parent);
+ enum ConnectionStarted : bool { Locally, Remotely };
+
+ DeviceLink(const QString& deviceId, LinkProvider* parent, ConnectionStarted connectionSource);
virtual ~DeviceLink() { };
+ virtual QString name() = 0;
+
const QString& deviceId() { return mDeviceId; }
LinkProvider* provider() { return mLinkProvider; }
diff --cc core/backends/lan/landevicelink.cpp
index d293cd6,65f7d7e..98d67bf
--- a/core/backends/lan/landevicelink.cpp
+++ b/core/backends/lan/landevicelink.cpp
@@@ -30,12 -25,10 +25,12 @@@
#include "uploadjob.h"
#include "downloadjob.h"
#include "socketlinereader.h"
+#include "lanpairinghandler.h"
- LanDeviceLink::LanDeviceLink(const QString& deviceId, LinkProvider* parent, QSslSocket* socket)
- : DeviceLink(deviceId, parent)
-LanDeviceLink::LanDeviceLink(const QString& deviceId, LinkProvider* parent, QTcpSocket* socket, ConnectionStarted connectionSource)
++LanDeviceLink::LanDeviceLink(const QString& deviceId, LinkProvider* parent, QSslSocket* socket, ConnectionStarted connectionSource)
+ : DeviceLink(deviceId, parent, connectionSource)
, mSocketLineReader(new SocketLineReader(socket))
+ , onSsl(false)
{
connect(mSocketLineReader, SIGNAL(readyRead()),
this, SLOT(dataReceived()));
diff --cc core/backends/lan/landevicelink.h
index 1931ce9,35a83eb..271e12a
--- a/core/backends/lan/landevicelink.h
+++ b/core/backends/lan/landevicelink.h
@@@ -36,14 -35,10 +36,14 @@@ class LanDeviceLin
Q_OBJECT
public:
- LanDeviceLink(const QString& deviceId, LinkProvider* parent, QSslSocket* socket);
- LanDeviceLink(const QString& deviceId, LinkProvider* parent, QTcpSocket* socket, ConnectionStarted connectionSource);
++ LanDeviceLink(const QString& deviceId, LinkProvider* parent, QSslSocket* socket, ConnectionStarted connectionSource);
+ virtual QString name() Q_DECL_OVERRIDE;
+ void setOnSsl(bool value);
+ virtual PairingHandler* createPairingHandler(Device* device) Q_DECL_OVERRIDE;
- bool sendPackage(NetworkPackage& np);
- bool sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& np);
+ bool sendPackage(NetworkPackage& np) override;
+ bool sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& np) override;
+ UploadJob* sendPayload(NetworkPackage&);
private Q_SLOTS:
void dataReceived();
diff --cc core/backends/lan/lanlinkprovider.cpp
index e12338a,03f429c..3bf7752
--- a/core/backends/lan/lanlinkprovider.cpp
+++ b/core/backends/lan/lanlinkprovider.cpp
@@@ -48,18 -45,20 +50,20 @@@ LanLinkProvider::LanLinkProvider(
mUdpServer = new QUdpSocket(this);
connect(mUdpServer, SIGNAL(readyRead()), this, SLOT(newUdpConnection()));
- mTcpServer = new QTcpServer(this);
- connect(mTcpServer,SIGNAL(newConnection()),this, SLOT(newConnection()));
+ mServer = new Server(this);
+ connect(mServer,SIGNAL(newConnection()),this, SLOT(newConnection()));
//Detect when a network interface changes status, so we announce ourelves in the new network
- QNetworkConfigurationManager* networkManager;
- networkManager = new QNetworkConfigurationManager(this);
- connect(networkManager, &QNetworkConfigurationManager::configurationChanged, [this, networkManager](QNetworkConfiguration config) {
- Q_UNUSED(config);
- //qCDebug(KDECONNECT_CORE) << config.name() << " state changed to " << config.state();
- //qCDebug(KDECONNECT_CORE) << "Online status: " << (networkManager->isOnline()? "online":"offline");
+ QNetworkConfigurationManager* networkManager = new QNetworkConfigurationManager(this);
+ connect(networkManager, &QNetworkConfigurationManager::configurationChanged, this, &LanLinkProvider::onNetworkConfigurationChanged);
+ }
+
+ void LanLinkProvider::onNetworkConfigurationChanged(const QNetworkConfiguration &config)
+ {
+ if (m_lastConfig != config) {
+ m_lastConfig = config;
onNetworkChange();
- });
+ }
}
LanLinkProvider::~LanLinkProvider()
@@@ -108,10 -108,9 +112,10 @@@ void LanLinkProvider::onNetworkChange(
//I'm the existing device, a new device is kindly introducing itself.
//I will create a TcpSocket and try to connect. This can result in either connected() or connectError().
- void LanLinkProvider::newUdpConnection()
+ void LanLinkProvider::newUdpConnection() //udpBroadcastReceived
{
while (mUdpServer->hasPendingDatagrams()) {
+
QByteArray datagram;
datagram.resize(mUdpServer->pendingDatagramSize());
QHostAddress sender;
@@@ -183,13 -176,12 +187,13 @@@ void LanLinkProvider::connected(
NetworkPackage* receivedPackage = receivedIdentityPackages[socket].np;
const QString& deviceId = receivedPackage->get<QString>("deviceId");
//qCDebug(KDECONNECT_CORE) << "Connected" << socket->isWritable();
+ LanDeviceLink* deviceLink = new LanDeviceLink(deviceId, this, socket, DeviceLink::Remotely);
-
+ // If network is on ssl, do not believe when they are connected, believe when handshake is completed
-
NetworkPackage np2("");
NetworkPackage::createIdentityPackage(&np2);
- bool success = deviceLink->sendPackage(np2);
+ socket->write(np2.serialize());
+ bool success = socket->waitForBytesWritten();
if (success) {
@@@ -332,46 -255,31 +336,45 @@@ void LanLinkProvider::dataReceived(
return;
}
+ // Needed in "encrypted" if ssl is used, similar to "connected"
+ receivedIdentityPackages[socket].np = np;
+
+ const QString& deviceId = np->get<QString>("deviceId");
//qCDebug(KDECONNECT_CORE) << "Handshaking done (i'm the new device)";
- //This socket will now be owned by the LanDeviceLink, forget about it
- disconnect(socket, SIGNAL(readyRead()),
- this, SLOT(dataReceived()));
- disconnect(socket, SIGNAL(disconnected()),
- socket, SLOT(deleteLater()));
+ //This socket will now be owned by the LanDeviceLink or we don't want more data to be received, forget about it
+ disconnect(socket, SIGNAL(readyRead()), this, SLOT(dataReceived()));
-
- const QString& deviceId = np.get<QString>("deviceId");
- LanDeviceLink* deviceLink = new LanDeviceLink(deviceId, this, socket, DeviceLink::Locally);
- connect(deviceLink, SIGNAL(destroyed(QObject*)),
- this, SLOT(deviceLinkDestroyed(QObject*)));
+ if (NetworkPackage::ProtocolVersion <= np->get<int>("protocolVersion")) {
+ // since I support ssl and remote device support ssl
+ qCDebug(KDECONNECT_CORE) << "Setting up ssl client";
- Q_EMIT onConnectionReceived(np, deviceLink);
+ bool isDeviceTrusted = KdeConnectConfig::instance()->trustedDevices().contains(deviceId);
- QMap< QString, DeviceLink* >::iterator oldLinkIterator = mLinks.find(deviceId);
- if (oldLinkIterator != mLinks.end()) {
- DeviceLink* oldLink = oldLinkIterator.value();
- disconnect(oldLink, SIGNAL(destroyed(QObject*)),
- this, SLOT(deviceLinkDestroyed(QObject*)));
- oldLink->deleteLater();
- mLinks.erase(oldLinkIterator);
+ socket->setPeerVerifyName(deviceId);
+
+ if (isDeviceTrusted) {
+ qDebug() << "Device trusted";
+ QString certString = KdeConnectConfig::instance()->getTrustedDevice(deviceId).certificate;
+ socket->addCaCertificate(QSslCertificate(certString.toLatin1()));
+ socket->setPeerVerifyMode(QSslSocket::VerifyPeer);
+ connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>)));
+ } else {
+ qDebug() << "Device untrusted";
+ // Do not care about ssl errors here, socket will not be closed due to errors because of query peer
+ socket->setPeerVerifyMode(QSslSocket::QueryPeer);
+ }
+ qCDebug(KDECONNECT_CORE) << "Starting client ssl";
+ connect(socket, SIGNAL(encrypted()), this, SLOT(encrypted()));
+
+ socket->startClientEncryption();
+ return;
+ } else {
+ addLink(deviceId, socket, np);
}
- mLinks[deviceId] = deviceLink;
+ delete np;
+ receivedIdentityPackages.remove(socket);
}
@@@ -416,31 -319,3 +419,31 @@@ void LanLinkProvider::configureSocket(Q
#endif
}
+
+void LanLinkProvider::addLink(QString deviceId, QSslSocket* socket, NetworkPackage* receivedPackage) {
+
- LanDeviceLink* deviceLink = new LanDeviceLink(deviceId, this, socket);
++ LanDeviceLink* deviceLink = new LanDeviceLink(deviceId, this, socket, DeviceLink::Locally);
+ connect(deviceLink, SIGNAL(destroyed(QObject*)), this, SLOT(deviceLinkDestroyed(QObject*)));
+
+ // Socket disconnection will now be handled by LanDeviceLink
+ disconnect(socket, SIGNAL(disconnected()), socket, SLOT(deleteLater()));
+
+ if (socket->isEncrypted()) {
+ deviceLink->setOnSsl(true);
+ }
+
+ //We kill any possible link from this same device
+ QMap< QString, DeviceLink* >::iterator oldLinkIterator = mLinks.find(deviceLink->deviceId());
+ if (oldLinkIterator != mLinks.end()) {
+ DeviceLink* oldLink = oldLinkIterator.value();
+ disconnect(oldLink, SIGNAL(destroyed(QObject*)),
+ this, SLOT(deviceLinkDestroyed(QObject*)));
+ oldLink->deleteLater();
+ mLinks.erase(oldLinkIterator);
+ }
+
+ mLinks[deviceLink->deviceId()] = deviceLink;
+
+ Q_EMIT onConnectionReceived(*receivedPackage, deviceLink);
+
- }
++}
diff --cc core/backends/lan/lanlinkprovider.h
index 6b525e5,88d3f1d..c62d998
--- a/core/backends/lan/lanlinkprovider.h
+++ b/core/backends/lan/lanlinkprovider.h
@@@ -41,16 -37,14 +41,16 @@@ public
LanLinkProvider();
~LanLinkProvider();
- QString name() { return "LanLinkProvider"; }
- int priority() { return PRIORITY_HIGH; }
+ QString name() override { return "LanLinkProvider"; }
+ int priority() override { return PRIORITY_HIGH; }
+ void addLink(QString, QSslSocket*, NetworkPackage*);
public Q_SLOTS:
- virtual void onNetworkChange();
- virtual void onStart();
- virtual void onStop();
+ virtual void onNetworkChange() override;
+ virtual void onStart() override;
+ virtual void onStop() override;
void connected();
+ void encrypted();
void connectError();
private Q_SLOTS:
@@@ -58,13 -52,12 +58,13 @@@
void newConnection();
void dataReceived();
void deviceLinkDestroyed(QObject* destroyedDeviceLink);
- void onNetworkConfigurationChanged(const QNetworkConfiguration &config);
+ void sslErrors(const QList<QSslError>& errors);
private:
- static void configureSocket(QTcpSocket* socket);
+ static void configureSocket(QSslSocket* socket);
-
++ void onNetworkConfigurationChanged(const QNetworkConfiguration &config);
- QTcpServer* mTcpServer;
+ Server* mServer;
QUdpSocket* mUdpServer;
QUdpSocket mUdpSocket;
const static quint16 port = 1714;
@@@ -76,8 -69,9 +76,8 @@@
NetworkPackage* np;
QHostAddress sender;
};
- QMap<QTcpSocket*, PendingConnect> receivedIdentityPackages;
+ QMap<QSslSocket*, PendingConnect> receivedIdentityPackages;
-
+ QNetworkConfiguration m_lastConfig;
-
};
#endif
diff --cc core/backends/lan/socketlinereader.h
index 79e4199,e021ea8..03f8a62
--- a/core/backends/lan/socketlinereader.h
+++ b/core/backends/lan/socketlinereader.h
@@@ -37,8 -37,7 +37,7 @@@ class SocketLineReade
Q_OBJECT
public:
-
- explicit SocketLineReader(QSslSocket* socket, QObject* parent = 0);
- explicit SocketLineReader(QTcpSocket* socket, QObject* parent = nullptr);
++ explicit SocketLineReader(QSslSocket* socket, QObject* parent = nullptr);
QByteArray readLine() { return mPackages.dequeue(); }
qint64 write(const QByteArray& data) { return mSocket->write(data); }
diff --cc core/backends/lan/uploadjob.cpp
index c426d2c,a0d31c9..d2646f4
--- a/core/backends/lan/uploadjob.cpp
+++ b/core/backends/lan/uploadjob.cpp
@@@ -26,16 -25,13 +26,17 @@@
#include "core_debug.h"
-UploadJob::UploadJob(const QSharedPointer<QIODevice>& source): KJob()
+UploadJob::UploadJob(const QSharedPointer<QIODevice>& source, const QVariantMap& transferInfo): KJob()
{
++// TODO: initialize in constructor
mInput = source;
- mServer = new QTcpServer(this);
+ mServer = new Server(this);
- mSocket = 0;
+ mSocket = nullptr;
mPort = 0;
+ // We will use this info if link is on ssl, to send encrypted payload
+ this->mTransferInfo = transferInfo;
+
connect(mInput.data(), SIGNAL(readyRead()), this, SLOT(readyRead()));
connect(mInput.data(), SIGNAL(aboutToClose()), this, SLOT(aboutToClose()));
}
@@@ -56,8 -52,11 +57,8 @@@ void UploadJob::start(
void UploadJob::newConnection()
{
-
- if (mSocket || !mServer->hasPendingConnections()) return;
-
if (!mInput->open(QIODevice::ReadOnly)) {
- qWarning() << "error when opening the input to upload";
+ qCWarning(KDECONNECT_CORE) << "error when opening the input to upload";
return; //TODO: Handle error, clean up...
}
diff --cc core/backends/lan/uploadjob.h
index 095381b,9722cc2..174d176
--- a/core/backends/lan/uploadjob.h
+++ b/core/backends/lan/uploadjob.h
@@@ -34,11 -34,9 +34,11 @@@ class UploadJo
{
Q_OBJECT
public:
- explicit UploadJob(const QSharedPointer<QIODevice>& source);
++ explicit UploadJob(const QSharedPointer<QIODevice>& source, const QVariantMap& sslInfo);
+
- explicit UploadJob(const QSharedPointer<QIODevice>& source,const QVariantMap& sslInfo);
+ virtual void start() override;
- QVariantMap getTransferInfo();
+
- virtual void start();
+ QVariantMap transferInfo();
private:
QSharedPointer<QIODevice> mInput;
diff --cc core/backends/loopback/loopbackdevicelink.cpp
index b5d181a,f975330..5440c34
--- a/core/backends/loopback/loopbackdevicelink.cpp
+++ b/core/backends/loopback/loopbackdevicelink.cpp
@@@ -21,10 -21,9 +21,10 @@@
#include "loopbackdevicelink.h"
#include "loopbacklinkprovider.h"
+#include "../lan/lanpairinghandler.h"
LoopbackDeviceLink::LoopbackDeviceLink(const QString& deviceId, LoopbackLinkProvider* provider)
- : DeviceLink(deviceId, provider)
+ : DeviceLink(deviceId, provider, Remotely)
{
}
diff --cc core/backends/loopback/loopbackdevicelink.h
index 906456a,84adeeb..3550b8f
--- a/core/backends/loopback/loopbackdevicelink.h
+++ b/core/backends/loopback/loopbackdevicelink.h
@@@ -32,10 -32,8 +32,10 @@@ class LoopbackDeviceLin
public:
LoopbackDeviceLink(const QString& d, LoopbackLinkProvider* a);
- virtual QString name();
- virtual PairingHandler* createPairingHandler(Device* device);
- virtual bool sendPackage(NetworkPackage& np);
- virtual bool sendPackageEncrypted(QCA::PublicKey& publicKey, NetworkPackage& np);
++ virtual QString name() override;
++ virtual PairingHandler* createPairingHandler(Device* device) override;
+ virtual bool sendPackage(NetworkPackage& np) override;
+ virtual bool sendPackageEncrypted(QCA::PublicKey& publicKey, NetworkPackage& np) override;
};
diff --cc core/daemon.cpp
index 6ddeecc,05a5641..fc4625a
--- a/core/daemon.cpp
+++ b/core/daemon.cpp
@@@ -106,18 -137,7 +137,18 @@@ void Daemon::forceOnNetworkChange(
}
}
+// I hate this, but not able to find an alternative now
+Device *Daemon::getDevice(QString deviceId) {
+
+ Q_FOREACH(Device* device, d->mDevices) {
+ if (device->id() == deviceId) {
+ return device;
+ }
+ }
+ return Q_NULLPTR;
+}
+
- QStringList Daemon::devices(bool onlyReachable, bool onlyVisible) const
+ QStringList Daemon::devices(bool onlyReachable, bool onlyPaired) const
{
QStringList ret;
Q_FOREACH(Device* device, d->mDevices) {
@@@ -153,14 -163,20 +184,20 @@@ void Daemon::onNewDeviceLink(const Netw
Q_EMIT deviceVisibilityChanged(id, true);
}
} else {
+ qCDebug(KDECONNECT_CORE) << "It is a new device " << identityPackage.get<QString>("deviceName");
-
Device* device = new Device(this, identityPackage, dl);
- connect(device, SIGNAL(reachableStatusChanged()), this, SLOT(onDeviceStatusChanged()));
- connect(device, SIGNAL(pairingChanged(bool)), this, SLOT(onDeviceStatusChanged()));
- d->mDevices[id] = device;
- //qCDebug(KDECONNECT_CORE) << "It is a new device";
- Q_EMIT deviceAdded(id);
+ //we discard the connections that we created but it's not paired.
+ //we keep the remotely initiated ones, since the remotes require them
+ if (!isDiscoveringDevices() && !device->isPaired() && dl->connectionSource() == DeviceLink::ConnectionStarted::Locally) {
+ device->deleteLater();
+ } else {
+ connect(device, SIGNAL(reachableStatusChanged()), this, SLOT(onDeviceStatusChanged()));
+ connect(device, SIGNAL(pairingChanged(bool)), this, SLOT(onDeviceStatusChanged()));
+ d->mDevices[id] = device;
+
+ Q_EMIT deviceAdded(id);
+ }
}
}
diff --cc core/daemon.h
index 7e1c710,dca3e07..e51285e
--- a/core/daemon.h
+++ b/core/daemon.h
@@@ -60,15 -67,8 +68,11 @@@ public Q_SLOTS
Q_SCRIPTABLE void setAnnouncedName(QString name);
//Returns a list of ids. The respective devices can be manipulated using the dbus path: "/modules/kdeconnect/Devices/"+id
- Q_SCRIPTABLE QStringList devices(bool onlyReachable = false, bool onlyVisible = false) const;
+ Q_SCRIPTABLE QStringList devices(bool onlyReachable = false, bool onlyPaired = false) const;
+ //Exposing kdeconnectconfig through daemon, needed to show certificate hash in cli, but this can be extended to name, id, public key etc. if needed
+ Q_SCRIPTABLE QByteArray certificate(int format) const;
+
- virtual void requestPairing(Device *d) = 0;
- virtual void reportError(const QString &title, const QString &description) = 0;
- virtual QNetworkAccessManager* networkAccessManager();
-
Q_SIGNALS:
Q_SCRIPTABLE void deviceAdded(const QString& id);
Q_SCRIPTABLE void deviceRemoved(const QString& id); //Note that paired devices will never be removed
@@@ -79,10 -79,11 +83,14 @@@ private Q_SLOTS
void onDeviceStatusChanged();
private:
+ bool isDiscoveringDevices() const;
+ void removeDevice(Device* d);
+ void cleanDevices();
+
QScopedPointer<struct DaemonPrivate> d;
+
+public:
+ Device* getDevice(QString deviceId);
};
#endif
diff --cc core/device.cpp
index 853d8d6,71c4d0c..c6b9b01
--- a/core/device.cpp
+++ b/core/device.cpp
@@@ -88,7 -91,7 +86,7 @@@ Device::Device(QObject* parent, const N
Device::~Device()
{
- Q_FOREACH(PairingHandler* ph, m_pairingHandlers) delete ph; // Delete all pairing handlers on deletion of device
- qDeleteAll(m_deviceLinks);
++ qDeleteAll(m_pairingHandlers);
}
bool Device::hasPlugin(const QString& name) const
@@@ -347,11 -346,73 +360,20 @@@ void Device::privateReceivedPackage(con
{
if (np.type() == PACKAGE_TYPE_PAIR) {
- //qCDebug(KDECONNECT_CORE) << "Pair package";
-
- bool wantsPair = np.get<bool>("pair");
-
- if (wantsPair == isPaired()) {
- qCDebug(KDECONNECT_CORE) << m_deviceName << "already" << (wantsPair? "paired":"unpaired");
- if (m_pairStatus == Device::Requested) {
- m_pairStatus = Device::NotPaired;
- m_pairingTimeut.stop();
- Q_EMIT pairingFailed(i18n("Canceled by other peer"));
- }
- return;
- }
-
- if (wantsPair) {
-
- //Retrieve their public key
- const QString& key = np.get<QString>("publicKey");
- m_publicKey = QCA::RSAPublicKey::fromPEM(key);
- if (m_publicKey.isNull()) {
- qCDebug(KDECONNECT_CORE) << "ERROR decoding key";
- if (m_pairStatus == Device::Requested) {
- m_pairStatus = Device::NotPaired;
- m_pairingTimeut.stop();
- }
- Q_EMIT pairingFailed(i18n("Received incorrect key"));
- return;
- }
-
- if (m_pairStatus == Device::Requested) { //We started pairing
-
- qCDebug(KDECONNECT_CORE) << "Pair answer";
- setAsPaired();
-
- } else {
- qCDebug(KDECONNECT_CORE) << "Pair request";
-
- Daemon::instance()->requestPairing(this);
-
- m_pairStatus = Device::RequestedByPeer;
- }
-
- } else {
-
- qCDebug(KDECONNECT_CORE) << "Unpair request";
-
- PairStatus prevPairStatus = m_pairStatus;
- m_pairStatus = Device::NotPaired;
-
- if (prevPairStatus == Device::Requested) {
- m_pairingTimeut.stop();
- Q_EMIT pairingFailed(i18n("Canceled by other peer"));
- } else if (prevPairStatus == Device::Paired) {
- unpairInternal();
- }
-
+ // If PACKAGE_TYPE_PAIR, send it to pairing handlers without thinking
+ Q_FOREACH(PairingHandler* ph, m_pairingHandlers) {
+ ph->packageReceived(np);
}
+ } else if (np.type() == PACKAGE_TYPE_CAPABILITIES) {
+ QSet<QString> newIncomingCapabilities = np.get<QStringList>("IncomingCapabilities", QStringList()).toSet();
+ QSet<QString> newOutgoingCapabilities = np.get<QStringList>("OutgoingCapabilities", QStringList()).toSet();
+
+ if (newOutgoingCapabilities != m_outgoingCapabilities || newIncomingCapabilities != m_incomingCapabilities) {
+ m_incomingCapabilities = newIncomingCapabilities;
+ m_outgoingCapabilities = newOutgoingCapabilities;
+ reloadPlugins();
+ }
} else if (isPaired()) {
QList<KdeConnectPlugin*> plugins = m_pluginsByIncomingInterface.values(np.type());
foreach(KdeConnectPlugin* plugin, plugins) {
diff --cc core/device.h
index 0c5b743,1291eae..82ecd29
--- a/core/device.h
+++ b/core/device.h
@@@ -26,8 -26,8 +26,9 @@@
#include <QVector>
#include <QSet>
#include <QSslKey>
-#include <QTimer>
#include <QtCrypto>
+#include <QSslCertificate>
++#include <QTimer>
#include "networkpackage.h"
@@@ -82,12 -84,10 +84,13 @@@ public
QString id() const { return m_deviceId; }
QString name() const { return m_deviceName; }
QString dbusPath() const { return "/modules/kdeconnect/devices/"+id(); }
- QString type() const { return type2str(m_deviceType); };
+ QString type() const { return type2str(m_deviceType); }
+ QCA::PublicKey publicKey() const { return m_publicKey; }
+ QSslCertificate certificate() const { return m_certificate; }
+ Q_SCRIPTABLE QByteArray certificate(int format) const { return (format == QSsl::Pem) ? m_certificate.toPem() : m_certificate.toDer() ;} // To expose certificate through dbus for cli
QString iconName() const;
QString statusIconName() const;
+ QStringList unsupportedPlugins() const { return m_unsupportedPlugins; }
//Add and remove links
void addLink(const NetworkPackage& identityPackage, DeviceLink*);
@@@ -107,8 -104,10 +110,12 @@@
Q_SCRIPTABLE QString pluginsConfigFile() const;
+ void pairingTimeout();
+
+ KdeConnectPlugin* plugin(const QString& pluginName) const;
+ void setPluginEnabled(const QString& pluginName, bool enabled);
+ bool isPluginEnabled(const QString& pluginName) const;
+
public Q_SLOTS:
///sends a @p np package to the device
virtual bool sendPackage(NetworkPackage& np);
diff --cc tests/CMakeLists.txt
index 20ddb67,0ebc919..927cddb
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@@ -15,37 -14,7 +16,39 @@@ set(kdeconnect_librarie
qca-qt5
)
+ ecm_add_test(pluginloadtest.cpp LINK_LIBRARIES ${kdeconnect_libraries})
+ ecm_add_test(sendfiletest.cpp LINK_LIBRARIES ${kdeconnect_libraries})
ecm_add_test(networkpackagetests.cpp LINK_LIBRARIES ${kdeconnect_libraries})
-ecm_add_test(testsocketlinereader.cpp ../core/backends/lan/socketlinereader.cpp TEST_NAME testsocketlinereader LINK_LIBRARIES ${kdeconnect_libraries})
+ecm_add_test(testsocketlinereader.cpp ../core/backends/lan/socketlinereader.cpp ../core/backends/lan/server.cpp TEST_NAME testsocketlinereader LINK_LIBRARIES ${kdeconnect_libraries})
+
+set(testsslsocketlinereader_sources
+ ../core/backends/lan/server.cpp
+ ../core/backends/lan/socketlinereader.cpp
+)
+ecm_add_test(testsslsocketlinereader.cpp ${testsslsocketlinereader_sources} TEST_NAME testsslsocketlinereader LINK_LIBRARIES ${kdeconnect_libraries})
+
+set(kdeconnectconfigtest_sources
+ ../core/backends/pairinghandler.cpp
+ ../core/dbushelper.cpp
+ ../core/device.cpp
+ ../core/pluginloader.cpp
+)
+ecm_add_test(kdeconnectconfigtest.cpp ${kdeconnectconfigtest_sources} TEST_NAME kdeconnectconfgtest LINK_LIBRARIES ${kdeconnect_libraries})
+
+set(lanlinkprovidertest_sources
+ ../core/backends/devicelink.cpp
+ ../core/backends/lan/downloadjob.cpp
+ ../core/backends/lan/landevicelink.cpp
+ ../core/backends/lan/lanlinkprovider.cpp
+ ../core/backends/lan/lanpairinghandler.cpp
+ ../core/backends/lan/server.cpp
+ ../core/backends/lan/socketlinereader.cpp
+ ../core/backends/lan/uploadjob.cpp
+ ../core/backends/linkprovider.cpp
+ ../core/backends/pairinghandler.cpp
+ ../core/device.cpp
+ ../core/pluginloader.cpp
+)
+ecm_add_test(lanlinkprovidertest.cpp ${lanlinkprovidertest_sources} TEST_NAME lanlinkprovidertest LINK_LIBRARIES ${kdeconnect_libraries})
+
+ecm_add_test(devicetest.cpp ${lanlinkprovidertest_sources} TEST_NAME devicetest LINK_LIBRARIES ${kdeconnect_libraries})
diff --cc tests/devicetest.cpp
index b976ead,0000000..82bccd6
mode 100644,000000..100644
--- a/tests/devicetest.cpp
+++ b/tests/devicetest.cpp
@@@ -1,137 -1,0 +1,137 @@@
+/**
+ * Copyright 2015 Vineet Garg <grgvineet at 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 "../core/backends/lan/lanlinkprovider.h"
+#include "../core/kdeconnectconfig.h"
+
+#include <QtTest>
+
+/**
+ * This class tests the working of device class
+ */
+class DeviceTest : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+
+ void initTestCase();
+ void testUnpairedDevice();
+ void testPairedDevice();
+ void cleanupTestCase();
+
+private:
+ QString deviceId;
+ QString deviceName;
+ QString deviceType;
+ NetworkPackage* identityPackage;
+
+};
+
+void DeviceTest::initTestCase()
+{
+ deviceId = QString("testdevice");
+ deviceName = QString("Test Device");
+ deviceType = QString("smartphone");
+ QString stringPackage = QString("{\"id\":1439365924847,\"type\":\"kdeconnect.identity\",\"body\":{\"deviceId\":\"testdevice\",\"deviceName\":\"Test Device\",\"protocolVersion\":6,\"deviceType\":\"phone\"}}");
+ identityPackage = new NetworkPackage("kdeconnect.identity");
+ NetworkPackage::unserialize(stringPackage.toLatin1(), identityPackage);
+}
+
+void DeviceTest::testPairedDevice()
+{
+ KdeConnectConfig* kcc = KdeConnectConfig::instance();
+ kcc->addTrustedDevice(deviceId, deviceName, deviceType);
+ kcc->setDeviceProperty(deviceId, QString("publicKey"), kcc->publicKey().toPEM()); // Using same public key from kcc, instead of creating new one
+ kcc->setDeviceProperty(deviceId, QString("certificate"), QString::fromLatin1(kcc->certificate().toPem())); // Using same certificate from kcc, instead of generating one
+
+ Device device(this, deviceId);
+
+ QCOMPARE(device.id(), deviceId);
+ QCOMPARE(device.name(), deviceName);
+ QCOMPARE(device.type(), deviceType);
+
+ QVERIFY2(!device.publicKey().isNull(), "Public key for device is null");
+ QCOMPARE(device.publicKey(), kcc->publicKey());
+
+ QVERIFY2(device.certificate().isNull(), "Certificate should be null before initialisation");
+
+ // TODO : Set certificate via identity package
+
+ QCOMPARE(device.isPaired(), true);
+ QCOMPARE(device.pairRequested(), false);
+
+ QCOMPARE(device.isReachable(), false);
+
+ // Add link
+ LanLinkProvider linkProvider;
+ QSslSocket socket;
- LanDeviceLink* link = new LanDeviceLink(deviceId, &linkProvider, &socket);
++ LanDeviceLink* link = new LanDeviceLink(deviceId, &linkProvider, &socket, DeviceLink::Locally);
+ device.addLink(*identityPackage, link);
+
+ QCOMPARE(device.isReachable(), true);
+ QCOMPARE(device.availableLinks().contains(linkProvider.name()), true);
+
+ // Remove link
+ device.removeLink(link);
+
+ QCOMPARE(device.isReachable(), false);
+ QCOMPARE(device.availableLinks().contains(linkProvider.name()), false);
+
+ device.unpair();
+ QCOMPARE(device.isPaired(), false);
+
+}
+
+void DeviceTest::testUnpairedDevice()
+{
+ LanLinkProvider linkProvider;
+ QSslSocket socket;
- LanDeviceLink* link = new LanDeviceLink(deviceId, &linkProvider, &socket);
++ LanDeviceLink* link = new LanDeviceLink(deviceId, &linkProvider, &socket, DeviceLink::Locally);
+
+ Device device(this, *identityPackage, link);
+
+ QCOMPARE(device.id(), deviceId);
+ QCOMPARE(device.name(), deviceName);
+ QCOMPARE(device.type(), deviceType);
+
+ QVERIFY2(device.publicKey().isNull(), "Public key for unpaired device should be null");
+ QVERIFY2(device.certificate().isNull(), "Certificate for unpaired device should be null");
+
+ QCOMPARE(device.isPaired(), false);
+ QCOMPARE(device.pairRequested(), false);
+
+ QCOMPARE(device.isReachable(), true);
+ QCOMPARE(device.availableLinks().contains(linkProvider.name()), true);
+
+ // Remove link
+ device.removeLink(link);
+
+ QCOMPARE(device.isReachable(), false);
+ QCOMPARE(device.availableLinks().contains(linkProvider.name()), false);
+}
+
+void DeviceTest::cleanupTestCase()
+{
+ delete identityPackage;
+}
+QTEST_GUILESS_MAIN(DeviceTest)
+
+#include "devicetest.moc"
diff --cc tests/testsocketlinereader.cpp
index 9ef2ba7,7894d69..a3e73af
--- a/tests/testsocketlinereader.cpp
+++ b/tests/testsocketlinereader.cpp
@@@ -79,9 -78,9 +79,9 @@@ void TestSocketLineReader::socketLineRe
QTest::qSleep(1000);
}
- QTcpSocket *sock = mServer->nextPendingConnection();
+ QSslSocket *sock = mServer->nextPendingConnection();
- QVERIFY2(sock != 0, "Could not open a connection to the client");
+ QVERIFY2(sock != nullptr, "Could not open a connection to the client");
mReader = new SocketLineReader(sock, this);
connect(mReader, SIGNAL(readyRead()), SLOT(newPackage()));
--
kdeconnect packaging
More information about the pkg-kde-commits
mailing list