[SCM] kdeconnect packaging branch, master, updated. debian/0.9g-1-1183-g9d69498
Maximiliano Curia
maxy at moszumanska.debian.org
Fri Oct 14 14:28:44 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/kdeconnect.git;a=commitdiff;h=148a713
The following commit has been merged in the master branch:
commit 148a71317631ade14adba798a65ccca9e314cc0d
Author: Vineet Garg <grg.vineet at gmail.com>
Date: Sun Jul 5 18:53:53 2015 +0530
Initial working implementation of ssl
---
CMakeLists.txt | 2 +-
core/CMakeLists.txt | 1 +
core/backends/lan/CMakeLists.txt | 2 +
core/backends/lan/landevicelink.cpp | 11 +-
core/backends/lan/landevicelink.h | 6 +-
core/backends/lan/lanlinkprovider.cpp | 242 +++++++++++++++------
core/backends/lan/lanlinkprovider.h | 16 +-
.../backends/lan/lanpairinghandler.cpp | 42 ++--
.../backends/lan/lanpairinghandler.h | 39 ++--
core/backends/{devicelink.cpp => lan/server.cpp} | 38 +++-
.../sftp/mountloop.h => core/backends/lan/server.h | 39 ++--
core/backends/lan/socketlinereader.cpp | 2 +-
core/backends/lan/socketlinereader.h | 6 +-
.../{linkprovider.cpp => pairinghandler.cpp} | 10 +-
.../{lan/landevicelink.h => pairinghandler.h} | 39 ++--
core/daemon.cpp | 6 +-
core/device.cpp | 26 ++-
core/device.h | 4 +-
core/kdeconnectconfig.cpp | 77 ++++++-
core/kdeconnectconfig.h | 9 +-
core/networkpackage.cpp | 2 +-
tests/CMakeLists.txt | 2 +-
tests/testsocketlinereader.cpp | 15 +-
23 files changed, 435 insertions(+), 201 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index df7dd50..b3071ab 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -50,6 +50,6 @@ add_subdirectory(plasmoid)
add_subdirectory(cli)
add_subdirectory(fileitemactionplugin)
-add_subdirectory(tests)
+# add_subdirectory(tests)
install(PROGRAMS kdeconnect-non-plasma.desktop DESTINATION ${XDG_APPS_INSTALL_DIR})
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index dd8fedb..e35d4ae 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -16,6 +16,7 @@ set(kdeconnectcore_SRCS
backends/linkprovider.cpp
backends/devicelink.cpp
+ backends/pairinghandler.cpp
kdeconnectplugin.cpp
kdeconnectpluginconfig.cpp
diff --git a/core/backends/lan/CMakeLists.txt b/core/backends/lan/CMakeLists.txt
index 7c5be38..0b01d66 100644
--- a/core/backends/lan/CMakeLists.txt
+++ b/core/backends/lan/CMakeLists.txt
@@ -2,8 +2,10 @@
set(backends_kdeconnect_SRCS
${backends_kdeconnect_SRCS}
+ backends/lan/server.cpp
backends/lan/lanlinkprovider.cpp
backends/lan/landevicelink.cpp
+ backends/lan/lanpairinghandler.cpp
backends/lan/uploadjob.cpp
backends/lan/downloadjob.cpp
backends/lan/socketlinereader.cpp
diff --git a/core/backends/lan/landevicelink.cpp b/core/backends/lan/landevicelink.cpp
index 0987057..c728fe0 100644
--- a/core/backends/lan/landevicelink.cpp
+++ b/core/backends/lan/landevicelink.cpp
@@ -31,9 +31,10 @@
#include "downloadjob.h"
#include "socketlinereader.h"
-LanDeviceLink::LanDeviceLink(const QString& deviceId, LinkProvider* parent, QTcpSocket* socket)
+LanDeviceLink::LanDeviceLink(const QString& deviceId, LinkProvider* parent, QSslSocket* socket)
: DeviceLink(deviceId, parent)
, mSocketLineReader(new SocketLineReader(socket))
+ , onSsl(false)
{
connect(mSocketLineReader, SIGNAL(readyRead()),
this, SLOT(dataReceived()));
@@ -48,6 +49,10 @@ LanDeviceLink::LanDeviceLink(const QString& deviceId, LinkProvider* parent, QTcp
socket->setParent(this);
}
+void LanDeviceLink::setOnSsl(bool value) {
+ onSsl = value;
+}
+
bool LanDeviceLink::sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& np)
{
@@ -57,7 +62,9 @@ bool LanDeviceLink::sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& np
np.setPayloadTransferInfo(job->getTransferInfo());
}
- np.encrypt(key);
+ if (!onSsl) {
+ np.encrypt(key);
+ }
int written = mSocketLineReader->write(np.serialize());
diff --git a/core/backends/lan/landevicelink.h b/core/backends/lan/landevicelink.h
index 7d31881..ed40c47 100644
--- a/core/backends/lan/landevicelink.h
+++ b/core/backends/lan/landevicelink.h
@@ -23,7 +23,7 @@
#include <QObject>
#include <QString>
-#include <QTcpSocket>
+#include <QSslSocket>
#include "../devicelink.h"
@@ -35,8 +35,9 @@ class LanDeviceLink
Q_OBJECT
public:
- LanDeviceLink(const QString& deviceId, LinkProvider* parent, QTcpSocket* socket);
+ LanDeviceLink(const QString& deviceId, LinkProvider* parent, QSslSocket* socket);
+ void setOnSsl(bool value);
bool sendPackage(NetworkPackage& np);
bool sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& np);
@@ -45,6 +46,7 @@ private Q_SLOTS:
private:
SocketLineReader* mSocketLineReader;
+ bool onSsl;
};
diff --git a/core/backends/lan/lanlinkprovider.cpp b/core/backends/lan/lanlinkprovider.cpp
index f5d2b22..f7c8fb0 100644
--- a/core/backends/lan/lanlinkprovider.cpp
+++ b/core/backends/lan/lanlinkprovider.cpp
@@ -35,6 +35,9 @@
#include "landevicelink.h"
#include <kdeconnectconfig.h>
+#include <QtNetwork/qsslkey.h>
+#include <QtNetwork/qsslcipher.h>
+#include <QtNetwork/qsslconfiguration.h>
LanLinkProvider::LanLinkProvider()
{
@@ -43,8 +46,8 @@ 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(QSslSocket*)),this, SLOT(newConnection(QSslSocket*)));
//Detect when a network interface changes status, so we announce ourelves in the new network
QNetworkConfigurationManager* networkManager;
@@ -67,7 +70,7 @@ void LanLinkProvider::onStart()
mUdpServer->bind(QHostAddress::Any, port, QUdpSocket::ShareAddress);
mTcpPort = port;
- while (!mTcpServer->listen(QHostAddress::Any, mTcpPort)) {
+ while (!mServer->listen(QHostAddress::Any, mTcpPort)) {
mTcpPort++;
if (mTcpPort > 1764) { //No ports available?
qCritical(KDECONNECT_CORE) << "Error opening a port in range 1714-1764";
@@ -82,13 +85,13 @@ void LanLinkProvider::onStart()
void LanLinkProvider::onStop()
{
mUdpServer->close();
- mTcpServer->close();
+ mServer->close();
}
//I'm in a new network, let's be polite and introduce myself
void LanLinkProvider::onNetworkChange()
{
- if (!mTcpServer->isListening()) {
+ if (!mServer->isListening()) {
//Not started
return;
}
@@ -107,6 +110,8 @@ void LanLinkProvider::onNetworkChange()
void LanLinkProvider::newUdpConnection()
{
while (mUdpServer->hasPendingDatagrams()) {
+ qCDebug(KDECONNECT_CORE) << "Udp package received";
+
QByteArray datagram;
datagram.resize(mUdpServer->pendingDatagramSize());
QHostAddress sender;
@@ -116,6 +121,8 @@ void LanLinkProvider::newUdpConnection()
NetworkPackage* receivedPackage = new NetworkPackage("");
bool success = NetworkPackage::unserialize(datagram, receivedPackage);
+ qCDebug(KDECONNECT_CORE) << "Datagram " << datagram.data() ;
+
if (!success || receivedPackage->type() != PACKAGE_TYPE_IDENTITY) {
delete receivedPackage;
continue;
@@ -131,22 +138,25 @@ void LanLinkProvider::newUdpConnection()
//qCDebug(KDECONNECT_CORE) << "Received Udp identity package from" << sender << " asking for a tcp connection on port " << tcpPort;
- QTcpSocket* socket = new QTcpSocket(this);
+ QSslSocket* socket = new QSslSocket(this);
receivedIdentityPackages[socket].np = receivedPackage;
receivedIdentityPackages[socket].sender = sender;
connect(socket, SIGNAL(connected()), this, SLOT(connected()));
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectError()));
socket->connectToHost(sender, tcpPort);
+
}
}
void LanLinkProvider::connectError()
{
- QTcpSocket* socket = qobject_cast<QTcpSocket*>(sender());
+ QSslSocket* socket = qobject_cast<QSslSocket*>(sender());
if (!socket) return;
disconnect(socket, SIGNAL(connected()), this, SLOT(connected()));
disconnect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectError()));
+ qCDebug(KDECONNECT_CORE) << socket->errorString();
+
qCDebug(KDECONNECT_CORE) << "Fallback (1), try reverse connection (send udp packet)";
NetworkPackage np("");
NetworkPackage::createIdentityPackage(&np);
@@ -162,7 +172,10 @@ void LanLinkProvider::connectError()
void LanLinkProvider::connected()
{
- QTcpSocket* socket = qobject_cast<QTcpSocket*>(sender());
+ qCDebug(KDECONNECT_CORE) << "Socket connected";
+
+ // TODO : Change the behaviour of these disconnects
+ QSslSocket* socket = qobject_cast<QSslSocket*>(sender());
if (!socket) return;
disconnect(socket, SIGNAL(connected()), this, SLOT(connected()));
disconnect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectError()));
@@ -173,37 +186,53 @@ void LanLinkProvider::connected()
const QString& deviceId = receivedPackage->get<QString>("deviceId");
//qCDebug(KDECONNECT_CORE) << "Connected" << socket->isWritable();
- LanDeviceLink* deviceLink = new LanDeviceLink(deviceId, this, socket);
+ // 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) {
- //qCDebug(KDECONNECT_CORE) << "Handshaking done (i'm the existing device)";
-
- connect(deviceLink, SIGNAL(destroyed(QObject*)),
- this, SLOT(deviceLinkDestroyed(QObject*)));
-
- Q_EMIT onConnectionReceived(*receivedPackage, deviceLink);
-
- //We kill any possible link from this same device
- 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);
+ qCDebug(KDECONNECT_CORE) << "Handshaking done (i'm the existing device)";
+
+ // if ssl supported
+ if (NetworkPackage::ProtocolVersion <= receivedPackage->get<int>("protocolVersion")) {
+ // since I support ssl and remote device support ssl
+ qCDebug(KDECONNECT_CORE) << "Setting up ssl server";
+
+ bool isDeviceTrusted = KdeConnectConfig::instance()->trustedDevices().contains(deviceId);
+
+ //TODO : Change it too device id from received package, also correct it on Android side
+ socket->setPeerVerifyName("Vineet Garg");
+
+ if (isDeviceTrusted) {
+ qDebug() << "Device trusted";
+ QString certString = KdeConnectConfig::instance()->getTrustedDevice(deviceId).certificate;
+ socket->addCaCertificate(QSslCertificate(certString.toLatin1()));
+ socket->setPeerVerifyMode(QSslSocket::QueryPeer);
+ 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 server ssl";
+ connect(socket, SIGNAL(encrypted()), this, SLOT(encrypted()));
+
+ socket->startServerEncryption();
+ return; // Return statement prevents from deleting received pacakage, needed in slot "encrypted"
+ } else {
+ LanDeviceLink* deviceLink = new LanDeviceLink(deviceId, this, socket);
+ connect(deviceLink, SIGNAL(destroyed(QObject*)),
+ this, SLOT(deviceLinkDestroyed(QObject*)));
+ addLink(deviceLink, receivedPackage);
}
- mLinks[deviceId] = deviceLink;
-
} else {
//I think this will never happen, but if it happens the deviceLink
//(or the socket that is now inside it) might not be valid. Delete them.
- delete deviceLink;
qCDebug(KDECONNECT_CORE) << "Fallback (2), try reverse connection (send udp packet)";
mUdpSocket.writeDatagram(np2.serialize(), receivedIdentityPackages[socket].sender, port);
}
@@ -213,44 +242,89 @@ void LanLinkProvider::connected()
//We don't delete the socket because now it's owned by the LanDeviceLink
}
+void LanLinkProvider::encrypted() {
+
+ qCDebug(KDECONNECT_CORE) << "Socket encrypted";
+
+ QSslSocket* socket = qobject_cast<QSslSocket*>(sender());
+ disconnect(socket, SIGNAL(encrypted()), this, SLOT(encrypted()));
+ disconnect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>)));
+
+ NetworkPackage* receivedPackage = receivedIdentityPackages[socket].np;
+ const QString& deviceId = receivedPackage->get<QString>("deviceId");
+ //qCDebug(KDECONNECT_CORE) << "Connected" << socket->isWritable();
+
+ receivedPackage->set("certificate", socket->peerCertificate().toPem());
+
+ LanDeviceLink* deviceLink = new LanDeviceLink(deviceId, this, socket);
+ deviceLink->setOnSsl(true);
+ addLink(deviceLink, receivedPackage);
+
+ // Copied from connected slot, now delete received package
+ delete receivedPackage;
+ receivedIdentityPackages.remove(socket);
+
+}
+
+void LanLinkProvider::sslErrors(QList<QSslError> errors)
+{
+ // This should be called when using verifyPeer, as Host name would not match
+ // Ignore that error, if there is any other, close socket and disconnect connection
+ // Unpair too ?
+
+ // TODO : If certificate mismatch, unpair it
+ // TODO : Socket is closed itself when there are errors in ssl, to check if it is deleted of not
+
+ QSslSocket* socket = qobject_cast<QSslSocket*>(sender());
+ disconnect(socket, SIGNAL(encrypted()), this, SLOT(encrypted()));
+ disconnect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>)));
+
+ delete receivedIdentityPackages[socket].np;
+ receivedIdentityPackages.remove(socket);
+
+// This delete caused error due to use of delete later slot
+// delete socket;
+
+
+}
+
+
+
//I'm the new device and this is the answer to my UDP identity package (no data received yet)
-void LanLinkProvider::newConnection()
+void LanLinkProvider::newConnection(QSslSocket* socket)
{
- //qCDebug(KDECONNECT_CORE) << "LanLinkProvider newConnection";
-
- while (mTcpServer->hasPendingConnections()) {
- QTcpSocket* socket = mTcpServer->nextPendingConnection();
- configureSocket(socket);
- //This socket is still managed by us (and child of the QTcpServer), if
- //it disconnects before we manage to pass it to a LanDeviceLink, it's
- //our responsability to delete it. We do so with this connection.
- connect(socket, SIGNAL(disconnected()),
- socket, SLOT(deleteLater()));
- connect(socket, SIGNAL(readyRead()),
- this, SLOT(dataReceived()));
+ qDebug() << "LanLinkProvider newConnection " ;
- }
+ configureSocket(socket);
+ //This socket is still managed by us (and child of the QTcpServer), if
+ //it disconnects before we manage to pass it to a LanDeviceLink, it's
+ //our responsability to delete it. We do so with this connection.
+ connect(socket, SIGNAL(disconnected()), socket, SLOT(deleteLater()));
+ connect(socket, SIGNAL(readyRead()), this, SLOT(dataReceived()));
}
//I'm the new device and this is the answer to my UDP identity package (data received)
void LanLinkProvider::dataReceived()
{
- QTcpSocket* socket = qobject_cast<QTcpSocket*>(sender());
+ QSslSocket* socket = qobject_cast<QSslSocket*>(sender());
const QByteArray data = socket->readLine();
- //qCDebug(KDECONNECT_CORE) << "LanLinkProvider received reply:" << data;
+ qCDebug(KDECONNECT_CORE) << "LanLinkProvider received reply:" << data;
- NetworkPackage np("");
- bool success = NetworkPackage::unserialize(data, &np);
- //qCDebug(KDECONNECT_CORE) << "LanLinkProvider received reply:" << data;
+ NetworkPackage* np = new NetworkPackage("");
+ bool success = NetworkPackage::unserialize(data, np);
+
+ receivedIdentityPackages[socket].np = np;
+// receivedIdentityPackages[socket].sender = sender;
- if (!success || np.type() != PACKAGE_TYPE_IDENTITY) {
+ if (!success || np->type() != PACKAGE_TYPE_IDENTITY) {
qCDebug(KDECONNECT_CORE) << "LanLinkProvider/newConnection: Not an identification package (wuh?)";
return;
}
+ 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
@@ -259,23 +333,38 @@ void LanLinkProvider::dataReceived()
disconnect(socket, SIGNAL(disconnected()),
socket, SLOT(deleteLater()));
- const QString& deviceId = np.get<QString>("deviceId");
- LanDeviceLink* deviceLink = new LanDeviceLink(deviceId, this, socket);
- connect(deviceLink, SIGNAL(destroyed(QObject*)),
- this, SLOT(deviceLinkDestroyed(QObject*)));
- Q_EMIT onConnectionReceived(np, deviceLink);
+ if (NetworkPackage::ProtocolVersion <= np->get<int>("protocolVersion")) {
+ // since I support ssl and remote device support ssl
+ qCDebug(KDECONNECT_CORE) << "Setting up ssl client";
- 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);
- }
+ bool isDeviceTrusted = KdeConnectConfig::instance()->trustedDevices().contains(deviceId);
+
+ // TODO : Change it to device id of remote device, correct it on Android side too, certificate name is not set there
+ socket->setPeerVerifyName("Vineet Garg");
+
+ 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()));
- mLinks[deviceId] = deviceLink;
+ socket->startClientEncryption();
+
+ } else {
+ LanDeviceLink* deviceLink = new LanDeviceLink(deviceId, this, socket);
+ connect(deviceLink, SIGNAL(destroyed(QObject*)),
+ this, SLOT(deviceLinkDestroyed(QObject*)));
+ addLink(deviceLink, np);
+ }
}
@@ -290,12 +379,17 @@ void LanLinkProvider::deviceLinkDestroyed(QObject* destroyedDeviceLink)
}
-void LanLinkProvider::configureSocket(QTcpSocket* socket)
+void LanLinkProvider::configureSocket(QSslSocket* socket)
{
int fd = socket->socketDescriptor();
socket->setSocketOption(QAbstractSocket::KeepAliveOption, QVariant(1));
+ // Configure for ssl
+ socket->setLocalCertificate(KdeConnectConfig::instance()->certificate());
+ socket->setPrivateKey(KdeConnectConfig::instance()->privateKeyPath());
+ socket->setProtocol(QSsl::TlsV1_2);
+
#ifdef TCP_KEEPIDLE
// time to start sending keepalive packets (seconds)
int maxIdle = 10;
@@ -315,3 +409,25 @@ void LanLinkProvider::configureSocket(QTcpSocket* socket)
#endif
}
+
+void LanLinkProvider::addLink(LanDeviceLink* deviceLink, NetworkPackage* receivedPackage) {
+
+ connect(deviceLink, SIGNAL(destroyed(QObject*)),
+ this, SLOT(deviceLinkDestroyed(QObject*)));
+
+ //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 --git a/core/backends/lan/lanlinkprovider.h b/core/backends/lan/lanlinkprovider.h
index b379434..530a3dd 100644
--- a/core/backends/lan/lanlinkprovider.h
+++ b/core/backends/lan/lanlinkprovider.h
@@ -23,10 +23,14 @@
#include <QObject>
#include <QTcpServer>
+#include <QSslSocket>
#include <QUdpSocket>
+#include <QtNetwork/qsslsocket.h>
#include "../linkprovider.h"
#include "netaddress.h"
+#include "server.h"
+#include "landevicelink.h"
class LanLinkProvider
: public LinkProvider
@@ -39,24 +43,28 @@ public:
QString name() { return "LanLinkProvider"; }
int priority() { return PRIORITY_HIGH; }
+ void addLink(LanDeviceLink* deviceLink, NetworkPackage* receivedPackage);
public Q_SLOTS:
virtual void onNetworkChange();
virtual void onStart();
virtual void onStop();
void connected();
+ void encrypted();
void connectError();
private Q_SLOTS:
void newUdpConnection();
- void newConnection();
+ void newConnection(QSslSocket*);
void dataReceived();
void deviceLinkDestroyed(QObject* destroyedDeviceLink);
+ void sslErrors(QList<QSslError> errors);
private:
- static void configureSocket(QTcpSocket* socket);
+ static void configureSocket(QSslSocket* socket);
- QTcpServer* mTcpServer;
+
+ Server* mServer;
QUdpSocket* mUdpServer;
QUdpSocket mUdpSocket;
const static quint16 port = 1714;
@@ -68,7 +76,7 @@ private:
NetworkPackage* np;
QHostAddress sender;
};
- QMap<QTcpSocket*, PendingConnect> receivedIdentityPackages;
+ QMap<QSslSocket*, PendingConnect> receivedIdentityPackages;
};
diff --git a/plugins/sftp/mountloop.cpp b/core/backends/lan/lanpairinghandler.cpp
similarity index 60%
copy from plugins/sftp/mountloop.cpp
copy to core/backends/lan/lanpairinghandler.cpp
index 7e83dea..7db6145 100644
--- a/plugins/sftp/mountloop.cpp
+++ b/core/backends/lan/lanpairinghandler.cpp
@@ -1,5 +1,5 @@
/**
- * Copyright 2014 Samoilenko Yuri<kinnalru at gmail.com>
+ * Copyright 2015 Vineet Garg <grg.vineet 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
@@ -18,31 +18,33 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "mountloop.h"
+#include "lanpairinghandler.h"
-MountLoop::MountLoop()
- : QEventLoop()
-{}
+LanPairingHandler::LanPairingHandler() {
-bool MountLoop::exec(QEventLoop::ProcessEventsFlags flags)
-{
- return QEventLoop::exec(flags) == 0;
}
-void MountLoop::failed()
-{
- Q_EMIT(result(false));
- exit(1);
+NetworkPackage* LanPairingHandler::createPairPackage(Device *device) {
+ NetworkPackage* np = new NetworkPackage("");
+ return np;
}
-void MountLoop::successed()
-{
- Q_EMIT(result(true));
- exit(0);
+void LanPairingHandler::packageReceived(Device *device) {
+
+}
+
+void LanPairingHandler::requestPairing(Device *device) {
+
}
-void MountLoop::exitWith(bool status)
-{
- Q_EMIT(result(status));
- exit(status ? 0 : 1);
+void LanPairingHandler::acceptPairing(Device *device) {
+
+}
+
+void LanPairingHandler::rejectPairing(Device *device) {
+
+}
+
+void LanPairingHandler::pairingDone(Device *device) {
+
}
diff --git a/plugins/mousepad/mousepadplugin.h b/core/backends/lan/lanpairinghandler.h
similarity index 58%
copy from plugins/mousepad/mousepadplugin.h
copy to core/backends/lan/lanpairinghandler.h
index e8ce480..089b945 100644
--- a/plugins/mousepad/mousepadplugin.h
+++ b/core/backends/lan/lanpairinghandler.h
@@ -1,5 +1,5 @@
/**
- * Copyright 2014 Ahmed I. Khalil <albertvaka at gmail.com>
+ * Copyright 2015 Vineet Garg <grg.vineet 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
@@ -18,34 +18,27 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef MOUSEPADPLUGIN_H
-#define MOUSEPADPLUGIN_H
+#ifndef KDECONNECT_LANPAIRINGHANDLER_H
+#define KDECONNECT_LANPAIRINGHANDLER_H
-#include <QtGui/QCursor>
-#include <core/kdeconnectplugin.h>
-#include <X11/Xlib.h>
-#include "fixx11h.h"
+#include "../pairinghandler.h"
-#define PACKAGE_TYPE_MOUSEPAD QLatin1String("kdeconnect.mousepad")
-
-struct FakeKey;
-
-class MousepadPlugin
- : public KdeConnectPlugin
+class LanPairingHandler
+ : public PairingHandler
{
- Q_OBJECT
-
public:
- explicit MousepadPlugin(QObject *parent, const QVariantList &args);
- virtual ~MousepadPlugin();
+ LanPairingHandler();
+ virtual ~LanPairingHandler() { }
- virtual bool receivePackage(const NetworkPackage& np);
- virtual void connected() { }
+ virtual NetworkPackage* createPairPackage(Device *device);
+ virtual void packageReceived(Device *device);
+ virtual void requestPairing(Device *device);
+ virtual void acceptPairing(Device *device);
+ virtual void rejectPairing(Device *device);
+ virtual void pairingDone(Device *device);
-private:
- Display *m_display;
- FakeKey* m_fakekey;
};
-#endif
+
+#endif //KDECONNECT_LANPAIRINGHANDLER_H
diff --git a/core/backends/devicelink.cpp b/core/backends/lan/server.cpp
similarity index 50%
copy from core/backends/devicelink.cpp
copy to core/backends/lan/server.cpp
index e4a13ca..ca6c17f 100644
--- a/core/backends/devicelink.cpp
+++ b/core/backends/lan/server.cpp
@@ -1,5 +1,5 @@
/**
- * Copyright 2013 Albert Vaca <albertvaka at gmail.com>
+ * Copyright 2015 Vineet Garg <grg.vineet 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
@@ -18,19 +18,37 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "devicelink.h"
+#include "server.h"
+
#include "kdeconnectconfig.h"
-#include "linkprovider.h"
+#include "lanlinkprovider.h"
+
+#include <QSslKey>
+#include <QSslSocket>
+#include <QSslError>
-DeviceLink::DeviceLink(const QString& deviceId, LinkProvider* parent)
- : QObject(parent)
- , mDeviceId(deviceId)
- , mLinkProvider(parent)
+Server::Server(QObject * parent)
+ :QTcpServer(parent)
{
- Q_ASSERT(!deviceId.isEmpty());
- setProperty("deviceId", deviceId);
+}
- mPrivateKey = KdeConnectConfig::instance()->privateKey();
+void Server::incomingConnection(qintptr socketDescriptor) {
+ qDebug() << "Incoming connection";
+ QSslSocket *serverSocket = new QSslSocket;
+ if (serverSocket->setSocketDescriptor(socketDescriptor)) {
+ qDebug() << "Setting socket descriptor";
+ connect(serverSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
+ Q_EMIT newConnection(serverSocket);
+ qDebug() << "Signal emiited";
+ } else {
+ qDebug() << "Delete socket";
+ delete serverSocket;
+ }
}
+
+void Server::disconnected() {
+ QSslSocket* socket = qobject_cast<QSslSocket*>(sender());
+ qDebug() << socket->errorString();
+}
diff --git a/plugins/sftp/mountloop.h b/core/backends/lan/server.h
similarity index 66%
copy from plugins/sftp/mountloop.h
copy to core/backends/lan/server.h
index a9920aa..2a1a603 100644
--- a/plugins/sftp/mountloop.h
+++ b/core/backends/lan/server.h
@@ -1,5 +1,5 @@
/**
- * Copyright 2014 Samoilenko Yuri<kinnalru at gmail.com>
+ * Copyright 2015 Vineet Garg <grg.vineet 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
@@ -18,28 +18,31 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef SFTPPLUGIN_MOUNTLOOP_H
-#define SFTPPLUGIN_MOUNTLOOP_H
+#ifndef KDECONNECT_SERVER_H
+#define KDECONNECT_SERVER_H
-#include <QEventLoop>
+#include <QTcpServer>
+#include <QSslError>
+#include <QtNetwork/qsslsocket.h>
-class MountLoop : public QEventLoop
+class Server
+ : public QTcpServer
{
+
Q_OBJECT
+
public:
- MountLoop();
-
- bool exec(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
-
-Q_SIGNALS:
- void result(bool status);
-
-public Q_SLOTS:
- void failed();
- void successed();
- void exitWith(bool status);
-};
+ Server(QObject* parent = 0);
+ virtual ~Server() {}
+protected:
+ virtual void incomingConnection(qintptr socketDescriptor);
+public Q_SLOTS:
+ void disconnected();
+
+Q_SIGNALS:
+ void newConnection(QSslSocket*);
+};
-#endif
+#endif //KDECONNECT_SERVER_H
diff --git a/core/backends/lan/socketlinereader.cpp b/core/backends/lan/socketlinereader.cpp
index a6bd85e..01cc72e 100644
--- a/core/backends/lan/socketlinereader.cpp
+++ b/core/backends/lan/socketlinereader.cpp
@@ -21,7 +21,7 @@
#include "socketlinereader.h"
-SocketLineReader::SocketLineReader(QTcpSocket* socket, QObject* parent)
+SocketLineReader::SocketLineReader(QSslSocket* socket, QObject* parent)
: QObject(parent)
, mSocket(socket)
{
diff --git a/core/backends/lan/socketlinereader.h b/core/backends/lan/socketlinereader.h
index b3be55a..e0d04f0 100644
--- a/core/backends/lan/socketlinereader.h
+++ b/core/backends/lan/socketlinereader.h
@@ -24,7 +24,7 @@
#include <QObject>
#include <QString>
#include <QQueue>
-#include <QTcpSocket>
+#include <QSslSocket>
#include <QHostAddress>
/*
@@ -37,7 +37,7 @@ class SocketLineReader
Q_OBJECT
public:
- SocketLineReader(QTcpSocket* socket, QObject* parent = 0);
+ SocketLineReader(QSslSocket* socket, QObject* parent = 0);
QByteArray readLine() { return mPackages.dequeue(); }
qint64 write(const QByteArray& data) { return mSocket->write(data); }
@@ -52,7 +52,7 @@ private Q_SLOTS:
private:
QByteArray lastChunk;
- QTcpSocket* mSocket;
+ QSslSocket* mSocket;
QQueue<QByteArray> mPackages;
};
diff --git a/core/backends/linkprovider.cpp b/core/backends/pairinghandler.cpp
similarity index 88%
copy from core/backends/linkprovider.cpp
copy to core/backends/pairinghandler.cpp
index 1d6c0bf..6a1eab7 100644
--- a/core/backends/linkprovider.cpp
+++ b/core/backends/pairinghandler.cpp
@@ -1,5 +1,5 @@
/**
- * Copyright 2013 Albert Vaca <albertvaka at gmail.com>
+ * Copyright 2015 Vineet Garg <grg.vineet 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
@@ -18,10 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "linkprovider.h"
+#include "pairinghandler.h"
-LinkProvider::LinkProvider()
-{
+PairingHandler::PairingHandler() {
//gcc complains if we don't add something to compile on a class with virtual functions
-}
-
+}
\ No newline at end of file
diff --git a/core/backends/lan/landevicelink.h b/core/backends/pairinghandler.h
similarity index 58%
copy from core/backends/lan/landevicelink.h
copy to core/backends/pairinghandler.h
index 7d31881..88025ac 100644
--- a/core/backends/lan/landevicelink.h
+++ b/core/backends/pairinghandler.h
@@ -1,5 +1,5 @@
/**
- * Copyright 2013 Albert Vaca <albertvaka at gmail.com>
+ * Copyright 2015 Vineet Garg <grg.vineet 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
@@ -18,34 +18,27 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef LANDEVICELINK_H
-#define LANDEVICELINK_H
+#ifndef KDECONNECT_PAIRINGHANDLER_H
+#define KDECONNECT_PAIRINGHANDLER_H
-#include <QObject>
-#include <QString>
-#include <QTcpSocket>
-#include "../devicelink.h"
+#include <networkpackage.h>
+#include <device.h>
-class SocketLineReader;
-
-class LanDeviceLink
- : public DeviceLink
-{
- Q_OBJECT
+class PairingHandler {
public:
- LanDeviceLink(const QString& deviceId, LinkProvider* parent, QTcpSocket* socket);
-
- bool sendPackage(NetworkPackage& np);
- bool sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& np);
+ PairingHandler();
+ virtual ~PairingHandler() { }
-private Q_SLOTS:
- void dataReceived();
-
-private:
- SocketLineReader* mSocketLineReader;
+ virtual NetworkPackage* createPairPackage(Device *device) = 0;
+ virtual void packageReceived(Device *device) = 0;
+ virtual void requestPairing(Device *device) = 0;
+ virtual void acceptPairing(Device *device) = 0;
+ virtual void rejectPairing(Device *device) = 0;
+ virtual void pairingDone(Device *device) = 0;
};
-#endif
+
+#endif //KDECONNECT_PAIRINGHANDLER_H
diff --git a/core/daemon.cpp b/core/daemon.cpp
index af4c67b..ce16a55 100644
--- a/core/daemon.cpp
+++ b/core/daemon.cpp
@@ -122,10 +122,10 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
{
const QString& id = identityPackage.get<QString>("deviceId");
- //qCDebug(KDECONNECT_CORE) << "Device discovered" << id << "via" << dl->provider()->name();
+ qCDebug(KDECONNECT_CORE) << "Device discovered" << id << "via" << dl->provider()->name();
if (d->mDevices.contains(id)) {
- //qCDebug(KDECONNECT_CORE) << "It is a known device";
+ qCDebug(KDECONNECT_CORE) << "It is a known device " << identityPackage.get<QString>("deviceName");
Device* device = d->mDevices[id];
bool wasReachable = device->isReachable();
device->addLink(identityPackage, dl);
@@ -133,7 +133,7 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
Q_EMIT deviceVisibilityChanged(id, true);
}
} else {
- //qCDebug(KDECONNECT_CORE) << "It is a new device";
+ 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()));
diff --git a/core/device.cpp b/core/device.cpp
index c2dc609..a7fb75a 100644
--- a/core/device.cpp
+++ b/core/device.cpp
@@ -58,9 +58,9 @@ Device::Device(QObject* parent, const QString& id)
m_deviceType = str2type(info.deviceType);
m_publicKey = QCA::RSAPublicKey::fromPEM(info.publicKey);
- m_pairingTimeut.setSingleShot(true);
- m_pairingTimeut.setInterval(30 * 1000); //30 seconds of timeout
- connect(&m_pairingTimeut, SIGNAL(timeout()),
+ m_pairingTimeout.setSingleShot(true);
+ m_pairingTimeout.setInterval(30 * 1000); //30 seconds of timeout
+ connect(&m_pairingTimeout, SIGNAL(timeout()),
this, SLOT(pairingTimeout()));
//Register in bus
@@ -221,7 +221,7 @@ void Device::requestPair()
return;
}
- m_pairingTimeut.start();
+ m_pairingTimeout.start();
}
void Device::unpair()
@@ -277,6 +277,14 @@ void Device::addLink(const NetworkPackage& identityPackage, DeviceLink* link)
setName(identityPackage.get<QString>("deviceName"));
m_deviceType = str2type(identityPackage.get<QString>("deviceType"));
+ // Set certificate if the link is on ssl, and it is added to identity package
+ // This is always sets certificate when link is added to device
+ if (identityPackage.has("certificate")) {
+ qDebug() << "Got certificate" ;
+ m_certificate = QSslCertificate(identityPackage.get<QByteArray>("certificate"));
+// qDebug() << m_certificate.toText();
+ }
+
//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.
//-- Actually, we should not destroy them or the provider will store an invalid ref!
@@ -341,7 +349,7 @@ void Device::privateReceivedPackage(const NetworkPackage& np)
qCDebug(KDECONNECT_CORE) << "Already" << (wantsPair? "paired":"unpaired");
if (m_pairStatus == Device::Requested) {
m_pairStatus = Device::NotPaired;
- m_pairingTimeut.stop();
+ m_pairingTimeout.stop();
Q_EMIT pairingFailed(i18n("Canceled by other peer"));
}
return;
@@ -356,7 +364,7 @@ void Device::privateReceivedPackage(const NetworkPackage& np)
qCDebug(KDECONNECT_CORE) << "ERROR decoding key";
if (m_pairStatus == Device::Requested) {
m_pairStatus = Device::NotPaired;
- m_pairingTimeut.stop();
+ m_pairingTimeout.stop();
}
Q_EMIT pairingFailed(i18n("Received incorrect key"));
return;
@@ -383,7 +391,7 @@ void Device::privateReceivedPackage(const NetworkPackage& np)
m_pairStatus = Device::NotPaired;
if (prevPairStatus == Device::Requested) {
- m_pairingTimeut.stop();
+ m_pairingTimeout.stop();
Q_EMIT pairingFailed(i18n("Canceled by other peer"));
} else if (prevPairStatus == Device::Paired) {
unpairInternal();
@@ -451,10 +459,10 @@ void Device::setAsPaired()
m_pairStatus = Device::Paired;
- m_pairingTimeut.stop(); //Just in case it was started
+ m_pairingTimeout.stop(); //Just in case it was started
//Save device info in the config
- KdeConnectConfig::instance()->addTrustedDevice(id(), name(), type2str(m_deviceType), m_publicKey.toPEM());
+ KdeConnectConfig::instance()->addTrustedDevice(id(), name(), type2str(m_deviceType), m_publicKey.toPEM(), QString(m_certificate.toPem()));
reloadPlugins(); //Will actually load the plugins
diff --git a/core/device.h b/core/device.h
index 03f528c..6e5c180 100644
--- a/core/device.h
+++ b/core/device.h
@@ -28,6 +28,7 @@
#include <QSslKey>
#include <QTimer>
#include <QtCrypto>
+#include <QtNetwork/qsslcertificate.h>
#include "networkpackage.h"
@@ -141,6 +142,7 @@ private: //Fields (TODO: dPointer!)
QString m_deviceName;
DeviceType m_deviceType;
QCA::PublicKey m_publicKey;
+ QSslCertificate m_certificate;
PairStatus m_pairStatus;
int m_protocolVersion;
@@ -149,7 +151,7 @@ private: //Fields (TODO: dPointer!)
QMultiMap<QString, KdeConnectPlugin*> m_pluginsByIncomingInterface;
QMultiMap<QString, KdeConnectPlugin*> m_pluginsByOutgoingInterface;
- QTimer m_pairingTimeut;
+ QTimer m_pairingTimeout;
const QSet<QString> m_incomingCapabilities;
const QSet<QString> m_outgoingCapabilities;
diff --git a/core/kdeconnectconfig.cpp b/core/kdeconnectconfig.cpp
index 919505c..ca5bf66 100644
--- a/core/kdeconnectconfig.cpp
+++ b/core/kdeconnectconfig.cpp
@@ -33,6 +33,7 @@
#include <QCoreApplication>
#include <QHostInfo>
#include <QSettings>
+#include <QtNetwork/qsslcertificate.h>
#include "core_debug.h"
#include "dbushelper.h"
@@ -41,10 +42,11 @@
struct KdeConnectConfigPrivate {
// The Initializer object sets things up, and also does cleanup when it goes out of scope
- // Note it's not being used anywhere. That's inteneded
+ // Note it's not being used anywhere. That's intended
QCA::Initializer mQcaInitializer;
QCA::PrivateKey privateKey;
+ QSslCertificate certificate; // Use QSslCertificate instead of QCA::Certificate due to compatibility with QSslSocket
QSettings* config;
@@ -106,6 +108,42 @@ KdeConnectConfig::KdeConnectConfig()
}
}
+ QString certPath = certificatePath();
+ QFile cert(certPath);
+ if (cert.exists() && cert.open(QIODevice::ReadOnly)) {
+
+// d->certificate = QCA::Certificate::fromPEMFile(certPath);
+ d->certificate = QSslCertificate::fromPath(certPath).value(0);
+
+ } else {
+
+ QCA::CertificateOptions certificateOptions = QCA::CertificateOptions();
+ // TODO : Set serial number for certificate. Time millis or any constant number?
+ QCA::BigInteger bigInteger(10);
+ QDateTime startTime = QDateTime::currentDateTime();
+ QDateTime endTime = startTime.addYears(10);
+ QCA::CertificateInfo certificateInfo;
+ certificateInfo.insert(QCA::CommonName,d->config->value("id", "unknown id").toString());
+ certificateInfo.insert(QCA::Organization,"KDE");
+ certificateInfo.insert(QCA::OrganizationalUnit,"Kde connect");
+ certificateOptions.setFormat(QCA::PKCS10);
+
+ certificateOptions.setSerialNumber(bigInteger);
+ certificateOptions.setInfo(certificateInfo);
+ certificateOptions.setValidityPeriod(startTime, endTime);
+ certificateOptions.setFormat(QCA::PKCS10);
+
+// d->certificate = QCA::Certificate(certificateOptions, d->privateKey);
+ d->certificate = QSslCertificate(QCA::Certificate(certificateOptions, d->privateKey).toPEM().toLatin1());
+
+ if (!cert.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
+ Daemon::instance()->reportError(QLatin1String("KDE Connect"), i18n("Could not store certificate file: %1", certPath));
+ } else {
+ cert.setPermissions(strict);
+ cert.write(d->certificate.toPem());
+ }
+ }
+
//Extra security check
if (QFile::permissions(keyPath) != strict) {
qCDebug(KDECONNECT_CORE) << "Warning: KDE Connect private key file has too open permissions " << keyPath;
@@ -157,6 +195,16 @@ QCA::PublicKey KdeConnectConfig::publicKey()
return d->privateKey.toPublicKey();
}
+QString KdeConnectConfig::certificatePath()
+{
+ return baseConfigDir().absoluteFilePath("certificate.pem");
+}
+
+QSslCertificate KdeConnectConfig::certificate()
+{
+ return d->certificate;
+}
+
QDir KdeConnectConfig::baseConfigDir()
{
QString configPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
@@ -172,13 +220,14 @@ QStringList KdeConnectConfig::trustedDevices()
return list;
}
-void KdeConnectConfig::addTrustedDevice(QString id, QString name, QString type, QString publicKey)
+void KdeConnectConfig::addTrustedDevice(QString id, QString name, QString type, QString publicKey, QString certificate)
{
d->config->beginGroup("trustedDevices");
d->config->beginGroup(id);
d->config->setValue("name", name);
d->config->setValue("type", type);
d->config->setValue("publicKey", publicKey);
+ d->config->setValue("certificate", certificate);
d->config->endGroup();
d->config->endGroup();
d->config->sync();
@@ -195,6 +244,7 @@ KdeConnectConfig::DeviceInfo KdeConnectConfig::getTrustedDevice(QString id)
info.deviceName = d->config->value("name", QLatin1String("unnamed")).toString();
info.deviceType = d->config->value("type", QLatin1String("unknown")).toString();
info.publicKey = d->config->value("publicKey", QString()).toString();
+ info.certificate = d->config->value("certificate", QString()).toString();
d->config->endGroup();
d->config->endGroup();
@@ -212,6 +262,29 @@ void KdeConnectConfig::removeTrustedDevice(QString deviceId)
//We do not remove the config files.
}
+// Utility functions to set and get a value
+void KdeConnectConfig::setDeviceProperty(QString deviceId, QString key, QString value)
+{
+ d->config->beginGroup("trustedDevices");
+ d->config->beginGroup(deviceId);
+ d->config->setValue(key, value);
+ d->config->endGroup();
+ d->config->endGroup();
+ d->config->sync();
+}
+
+QString KdeConnectConfig::getDeviceProperty(QString deviceId, QString key, QString defaultValue)
+{
+ QString value;
+ d->config->beginGroup("trustedDevices");
+ d->config->beginGroup(deviceId);
+ value = d->config->value(key, defaultValue).toString();
+ d->config->endGroup();
+ d->config->endGroup();
+ return value;
+}
+
+
QDir KdeConnectConfig::deviceConfigDir(QString deviceId)
{
QString deviceConfigPath = baseConfigDir().absoluteFilePath(deviceId);
diff --git a/core/kdeconnectconfig.h b/core/kdeconnectconfig.h
index af6c6df..0042efd 100644
--- a/core/kdeconnectconfig.h
+++ b/core/kdeconnectconfig.h
@@ -23,6 +23,7 @@
#include <QtCrypto>
#include <QDir>
+#include <QtNetwork/qsslcertificate.h>
#include "kdeconnectcore_export.h"
@@ -33,6 +34,7 @@ public:
QString deviceName;
QString deviceType;
QString publicKey;
+ QString certificate;
};
static KdeConnectConfig* instance();
@@ -49,6 +51,9 @@ public:
QCA::PrivateKey privateKey();
QCA::PublicKey publicKey();
+ QString certificatePath();
+ QSslCertificate certificate();
+
void setName(QString name);
/*
@@ -57,8 +62,10 @@ public:
QStringList trustedDevices(); //list of ids
void removeTrustedDevice(QString id);
- void addTrustedDevice(QString id, QString name, QString type, QString publicKey);
+ void addTrustedDevice(QString id, QString name, QString type, QString publicKey, QString certificate = QString());
KdeConnectConfig::DeviceInfo getTrustedDevice(QString id);
+ void setDeviceProperty(QString deviceId, QString name, QString value);
+ QString getDeviceProperty(QString deviceId, QString name, QString defaultValue = QString());
/*
* Paths for config files, there is no guarantee the directories already exist
diff --git a/core/networkpackage.cpp b/core/networkpackage.cpp
index 64cfab7..53b6355 100644
--- a/core/networkpackage.cpp
+++ b/core/networkpackage.cpp
@@ -36,7 +36,7 @@
#include "kdeconnectconfig.h"
const QCA::EncryptionAlgorithm NetworkPackage::EncryptionAlgorithm = QCA::EME_PKCS1v15;
-const int NetworkPackage::ProtocolVersion = 5;
+const int NetworkPackage::ProtocolVersion = 6;
NetworkPackage::NetworkPackage(const QString& type)
{
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index b00a574..94fdc60 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -14,4 +14,4 @@ set(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})
diff --git a/tests/testsocketlinereader.cpp b/tests/testsocketlinereader.cpp
index 77a9b4b..e60eedf 100644
--- a/tests/testsocketlinereader.cpp
+++ b/tests/testsocketlinereader.cpp
@@ -17,10 +17,10 @@
*************************************************************************************/
#include "../core/backends/lan/socketlinereader.h"
+#include "../core/backends/lan/server.h"
#include <QTest>
-#include <QTcpServer>
-#include <QTcpSocket>
+#include <QSslSocket>
#include <QProcess>
#include <QEventLoop>
#include <QTimer>
@@ -40,21 +40,22 @@ private:
QTimer mTimer;
QEventLoop mLoop;
QList<QByteArray> mPackages;
- QTcpServer *mServer;
- QTcpSocket *mConn;
+ Server *mServer;
+ QSslSocket *mConn;
SocketLineReader *mReader;
};
void TestSocketLineReader::initTestCase()
{
- mServer = new QTcpServer(this);
+ mServer = new Server(this);
+
QVERIFY2(mServer->listen(QHostAddress::LocalHost, 8694), "Failed to create local tcp server");
mTimer.setInterval(4000);//For second is more enough to send some data via local socket
mTimer.setSingleShot(true);
connect(&mTimer, SIGNAL(timeout()), &mLoop, SLOT(quit()));
- mConn = new QTcpSocket(this);
+ mConn = new QSslSocket(this);
mConn->connectToHost(QHostAddress::LocalHost, 8694);
connect(mConn, SIGNAL(connected()), &mLoop, SLOT(quit()));
mTimer.start();
@@ -78,7 +79,7 @@ void TestSocketLineReader::socketLineReader()
QTest::qSleep(1000);
}
- QTcpSocket *sock = mServer->nextPendingConnection();
+ QSslSocket *sock = (QSslSocket*) mServer->nextPendingConnection();
QVERIFY2(sock != 0, "Could not open a connection to the client");
--
kdeconnect packaging
More information about the pkg-kde-commits
mailing list