Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 16f9af90 authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

WIP

parent 30d2dd99
......@@ -184,25 +184,9 @@ int main(int argc, char** argv)
}
} else if(parser.isSet("encryption-info")) {
DeviceDbusInterface dev(device);
QDBusPendingReply<QByteArray> devReply = dev.certificate(1); // QSsl::Der = 1
QDBusPendingReply<QByteArray> devReply = dev.encryptionInfo(); // 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
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) << devReply.value() << endl;
} else {
QTextStream(stderr) << i18n("Nothing to be done") << endl;
}
......
......@@ -25,10 +25,11 @@
#include <QtCrypto>
#include "core/networkpackage.h"
#include "pairinghandler.h"
class PairingHandler;
class NetworkPackage;
class LinkProvider;
class Device;
class DeviceLink
: public QObject
......
......@@ -35,18 +35,15 @@ DownloadJob::DownloadJob(const QHostAddress &address, const QVariantMap &transfe
mAddress = address;
mPort = transferInfo["port"].toInt();
mSocket = QSharedPointer<QSslSocket>(new QSslSocket);
useSsl = transferInfo.value("useSsl", false).toBool();
// Setting ssl related properties for socket when using ssl
if (useSsl) {
mSocket->setLocalCertificate(KdeConnectConfig::instance()->certificate());
mSocket->setPrivateKey(KdeConnectConfig::instance()->privateKeyPath());
mSocket->setProtocol(QSsl::TlsV1_2);
mSocket->setPeerVerifyName(transferInfo.value("deviceId").toString());
mSocket->setPeerVerifyMode(QSslSocket::VerifyPeer);
mSocket->addCaCertificate(QSslCertificate(KdeConnectConfig::instance()->getTrustedDevice(
transferInfo.value("deviceId").toString()).certificate.toLatin1()));
}
mSocket->setLocalCertificate(KdeConnectConfig::instance()->certificate());
mSocket->setPrivateKey(KdeConnectConfig::instance()->privateKeyPath());
mSocket->setProtocol(QSsl::TlsV1_2);
mSocket->setPeerVerifyName(transferInfo.value("deviceId").toString());
mSocket->setPeerVerifyMode(QSslSocket::VerifyPeer);
mSocket->addCaCertificate(QSslCertificate(KdeConnectConfig::instance()->getDeviceProperty(transferInfo.value("deviceId").toString(),"certificate").toLatin1()));
}
DownloadJob::~DownloadJob()
......@@ -61,14 +58,11 @@ void DownloadJob::start()
connect(mSocket.data(), SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(done()));
//connect(mSocket.data(), &QAbstractSocket::connected, [=](){ qDebug() << "Connected"; });
if (useSsl) {
// Cannot use read only, might be due to ssl handshake, getting QIODevice::ReadOnly error and no connection
mSocket->connectToHostEncrypted(mAddress.toString(), mPort, QIODevice::ReadWrite);
mSocket->waitForEncrypted();
} else {
mSocket->connectToHost(mAddress, mPort, QIODevice::ReadOnly);
mSocket->waitForConnected();
}
// Cannot use read only, might be due to ssl handshake, getting QIODevice::ReadOnly error and no connection
mSocket->connectToHostEncrypted(mAddress.toString(), mPort, QIODevice::ReadWrite);
mSocket->waitForEncrypted();
// mSocket->connectToHost(mAddress, mPort, QIODevice::ReadOnly);
// mSocket->waitForConnected();
//mSocket->open(QIODevice::ReadOnly);
......
......@@ -57,7 +57,7 @@ void LanDeviceLink::setOnSsl(bool value)
PairingHandler* LanDeviceLink::createPairingHandler(Device* device)
{
return new LanPairingHandler(device);
return new LanPairingHandler(device->id());
}
bool LanDeviceLink::sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& np)
......@@ -95,7 +95,7 @@ UploadJob* LanDeviceLink::sendPayload(NetworkPackage& np)
transferInfo.insert("useSsl", true);
transferInfo.insert("deviceId", deviceId());
}
UploadJob* job = new UploadJob(np.payload(), transferInfo);
UploadJob* job = new UploadJob(np.payload(), deviceId());
job->start();
return job;
}
......
......@@ -37,7 +37,6 @@
#include "../../daemon.h"
#include "landevicelink.h"
#include "lanpairinghandler.h"
#include <kdeconnectconfig.h>
#include <QDBusPendingReply>
#include <QtNetwork/qsslcipher.h>
......@@ -187,7 +186,6 @@ 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("");
......@@ -210,7 +208,7 @@ void LanLinkProvider::connected()
if (isDeviceTrusted) {
qDebug() << "Device trusted";
QString certString = KdeConnectConfig::instance()->getTrustedDevice(deviceId).certificate;
QString certString = KdeConnectConfig::instance()->getDeviceProperty(deviceId, "certificate", QString());
socket->addCaCertificate(QSslCertificate(certString.toLatin1()));
socket->setPeerVerifyMode(QSslSocket::VerifyPeer);
connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>)));
......@@ -225,7 +223,7 @@ void LanLinkProvider::connected()
socket->startServerEncryption();
return; // Return statement prevents from deleting received package, needed in slot "encrypted"
} else {
addLink(deviceId, socket, receivedPackage);
addLink(deviceId, socket, receivedPackage, DeviceLink::Remotely);
}
} else {
......@@ -256,7 +254,7 @@ void LanLinkProvider::encrypted()
receivedPackage->set("certificate", socket->peerCertificate().toPem());
addLink(deviceId, socket, receivedPackage);
addLink(deviceId, socket, receivedPackage, DeviceLink::Remotely);
// Copied from connected slot, now delete received package
delete receivedPackage;
......@@ -355,7 +353,7 @@ void LanLinkProvider::dataReceived()
if (isDeviceTrusted) {
qDebug() << "Device trusted";
QString certString = KdeConnectConfig::instance()->getTrustedDevice(deviceId).certificate;
QString certString = KdeConnectConfig::instance()->getDeviceProperty(deviceId, "certificate", QString());
socket->addCaCertificate(QSslCertificate(certString.toLatin1()));
socket->setPeerVerifyMode(QSslSocket::VerifyPeer);
connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>)));
......@@ -370,7 +368,7 @@ void LanLinkProvider::dataReceived()
socket->startClientEncryption();
return;
} else {
addLink(deviceId, socket, np);
addLink(deviceId, socket, np, DeviceLink::Locally);
}
delete np;
......@@ -420,9 +418,10 @@ void LanLinkProvider::configureSocket(QSslSocket* socket)
}
void LanLinkProvider::addLink(QString deviceId, QSslSocket* socket, NetworkPackage* receivedPackage) {
void LanLinkProvider::addLink(const QString& deviceId, QSslSocket* socket, NetworkPackage* receivedPackage, DeviceLink::ConnectionStarted connectionOrigin)
{
LanDeviceLink* deviceLink = new LanDeviceLink(deviceId, this, socket, DeviceLink::Locally);
LanDeviceLink* deviceLink = new LanDeviceLink(deviceId, this, socket, connectionOrigin);
connect(deviceLink, SIGNAL(destroyed(QObject*)), this, SLOT(deviceLinkDestroyed(QObject*)));
// Socket disconnection will now be handled by LanDeviceLink
......
......@@ -28,7 +28,6 @@
#include <QtNetwork/qsslsocket.h>
#include "../linkprovider.h"
#include "netaddress.h"
#include "server.h"
#include "landevicelink.h"
......@@ -43,7 +42,6 @@ public:
QString name() override { return "LanLinkProvider"; }
int priority() override { return PRIORITY_HIGH; }
void addLink(QString, QSslSocket*, NetworkPackage*);
public Q_SLOTS:
virtual void onNetworkChange() override;
......@@ -63,6 +61,7 @@ private Q_SLOTS:
private:
static void configureSocket(QSslSocket* socket);
void onNetworkConfigurationChanged(const QNetworkConfiguration &config);
void addLink(const QString& deviceId, QSslSocket* socket, NetworkPackage* receivedPackage, DeviceLink::ConnectionStarted connectionOrigin);
Server* mServer;
QUdpSocket* mUdpServer;
......
......@@ -27,28 +27,28 @@
#include "lanpairinghandler.h"
#include "networkpackagetypes.h"
LanPairingHandler::LanPairingHandler(Device* device)
: PairingHandler(device)
LanPairingHandler::LanPairingHandler(const QString& deviceId)
: PairingHandler()
, m_deviceId(deviceId)
{
m_pairingTimeout.setSingleShot(true);
m_pairingTimeout.setInterval(30 * 1000); //30 seconds of timeout
connect(&m_pairingTimeout, SIGNAL(timeout()),
this, SLOT(pairingTimeout()));
if (device->isPaired()) {
if (!KdeConnectConfig::instance()->getTrustedDevice(device->id()).publicKey.isNull()) {
m_pairStatus = PairStatus::Paired;
} else {
requestPairing(); // Request pairing if device is paired but public key is not there
}
/*
m_publicKey = KdeConnectConfig::instance()->getDeviceProperty(deviceId, "publicKey", QString());
m_certificate = KdeConnectConfig::instance()->getDeviceProperty(deviceId, "certificate", QString());
*/
if (!m_publicKey.isNull()) {
setPairStatus(PairStatus::Paired);
} else {
m_pairStatus = PairStatus::NotPaired;
setPairStatus(PairStatus::NotPaired);
}
}
void LanPairingHandler::createPairPackage(NetworkPackage& np)
{
np.set("link", m_deviceLink->name());
np.set("link", deviceLink()->name());
np.set("pair", true);
np.set("publicKey", KdeConnectConfig::instance()->publicKey().toPEM());
}
......@@ -56,7 +56,7 @@ void LanPairingHandler::createPairPackage(NetworkPackage& np)
void LanPairingHandler::packageReceived(const NetworkPackage& np)
{
if (np.get<QString>("link", m_deviceLink->name()).compare(m_deviceLink->name()) != 0) return; // If this package is not received by my type of link
if (np.get<QString>("link", deviceLink()->name()).compare(deviceLink()->name()) != 0) return; // If this package is not received by my type of link
m_pairingTimeout.stop();
......@@ -64,77 +64,75 @@ void LanPairingHandler::packageReceived(const NetworkPackage& np)
if (wantsPair == isPaired()) {
// qCDebug(KDECONNECT_CORE) << "Already" << (wantsPair? "paired":"unpaired");
if (m_pairStatus == PairStatus ::Requested) {
m_pairStatus = PairStatus ::NotPaired;
if (isPairRequested()) {
setPairStatus(PairStatus::NotPaired);
Q_EMIT pairingFailed(i18n("Canceled by other peer"));
return;
} else if (m_pairStatus == PairStatus ::Paired) {
} else if (isPaired()) {
/**
* If wants pair is true and is paired is true, this means other device is trying to pair again, might be because it unpaired this device somehow
* and we don't know it, unpair it internally
*/
Q_EMIT unpairingDone();
KdeConnectConfig::instance()->removeTrustedDevice(m_deviceId);
setPairStatus(PairingHandler::NotPaired);
}
}
if (wantsPair) {
QString keyString = np.get<QString>("publicKey");
m_device->setPublicKey(QCA::RSAPublicKey::fromPEM(keyString));
bool success = !m_device->publicKey().isNull();
if (!success) {
if (m_pairStatus == PairStatus ::Requested) {
m_pairStatus = PairStatus::NotPaired;
QString certificateString = np.get<QByteArray>("certificate");
if (QCA::RSAPublicKey::fromPEM(keyString).isNull()) {
if (isPairRequested()) {
setPairStatus(PairStatus::NotPaired);
}
Q_EMIT pairingFailed(i18n("Received incorrect key"));
return;
}
if (m_pairStatus == PairStatus::Requested) { //We started pairing
if (isPairRequested()) { //We started pairing
qCDebug(KDECONNECT_CORE) << "Pair answer";
setAsPaired();
KdeConnectConfig::instance()->setDeviceProperty(m_deviceId, "publicKey", keyString);
KdeConnectConfig::instance()->setDeviceProperty(m_deviceId, "certificate", certificateString);
} else {
qCDebug(KDECONNECT_CORE) << "Pair request";
if (m_device->isPaired()) {
if (isPaired()) {
acceptPairing();
return;
}
Daemon::instance()->requestPairing(m_device);
m_pairStatus = PairStatus ::RequestedByPeer;
//Daemon::instance()->requestPairing(m_device);
//m_pairStatus = PairStatus::RequestedByPeer;
setPairStatus(PairStatus::RequestedByPeer);
}
} else {
} else { //wantsPair == false
qCDebug(KDECONNECT_CORE) << "Unpair request";
PairStatus prevPairStatus = m_pairStatus;
m_pairStatus = PairStatus::NotPaired;
if (prevPairStatus == PairStatus ::Requested) {
if (isPairRequested()) {
Q_EMIT pairingFailed(i18n("Canceled by other peer"));
} else if (prevPairStatus == PairStatus::Paired) {
Q_EMIT (unpairingDone());
}
setPairStatus(PairStatus::NotPaired);
}
}
bool LanPairingHandler::requestPairing()
{
switch (m_pairStatus) {
switch (pairStatus()) {
case PairStatus::Paired:
Q_EMIT pairingFailed(i18n(m_deviceLink->name().append(" : Already paired").toLatin1().data()));
Q_EMIT pairingFailed(i18n(deviceLink()->name().append(" : Already paired").toLatin1().data()));
return false;
case PairStatus ::Requested:
Q_EMIT pairingFailed(i18n(m_deviceLink->name().append(" : Pairing already requested for this device").toLatin1().data()));
case PairStatus::Requested:
Q_EMIT pairingFailed(i18n(deviceLink()->name().append(" : Pairing already requested for this device").toLatin1().data()));
return false;
case PairStatus ::RequestedByPeer:
qCDebug(KDECONNECT_CORE) << m_deviceLink->name() << " : Pairing already started by the other end, accepting their request.";
case PairStatus::RequestedByPeer:
qCDebug(KDECONNECT_CORE) << deviceLink()->name() << " : Pairing already started by the other end, accepting their request.";
acceptPairing();
return false;
case PairStatus::NotPaired:
......@@ -144,9 +142,9 @@ bool LanPairingHandler::requestPairing()
NetworkPackage np(PACKAGE_TYPE_PAIR);
createPairPackage(np);
bool success;
success = m_deviceLink->sendPackage(np);
success = deviceLink()->sendPackage(np);
if (success) {
m_pairStatus = PairStatus::Requested;
setPairStatus(PairStatus::Requested);
m_pairingTimeout.start();
}
return success;
......@@ -154,14 +152,13 @@ bool LanPairingHandler::requestPairing()
bool LanPairingHandler::acceptPairing()
{
m_pairingTimeout.stop(); // Just in case it is started
NetworkPackage np(PACKAGE_TYPE_PAIR);
createPairPackage(np);
bool success;
success = m_deviceLink->sendPackage(np);
success = deviceLink()->sendPackage(np);
if (success) {
m_pairStatus = PairStatus::Paired;
setAsPaired();
Q_EMIT(pairingDone());
setPairStatus(PairStatus::Paired);
}
return success;
}
......@@ -170,36 +167,25 @@ void LanPairingHandler::rejectPairing()
{
NetworkPackage np(PACKAGE_TYPE_PAIR);
np.set("pair", false);
np.set("link", m_deviceLink->name());
m_deviceLink->sendPackage(np);
m_pairStatus = PairStatus::NotPaired;
np.set("link", deviceLink()->name());
deviceLink()->sendPackage(np);
setPairStatus(PairStatus::NotPaired);
}
void LanPairingHandler::unpair() {
NetworkPackage np(PACKAGE_TYPE_PAIR);
np.set("pair", false);
np.set("link", m_deviceLink->name());
m_deviceLink->sendPackage(np);
m_pairStatus = PairStatus::NotPaired;
np.set("link", deviceLink()->name());
deviceLink()->sendPackage(np);
setPairStatus(PairStatus::NotPaired);
}
void LanPairingHandler::pairingTimeout()
{
NetworkPackage np(PACKAGE_TYPE_PAIR);
np.set("pair", false);
np.set("name", m_deviceLink->name());
m_deviceLink->sendPackage(np);
m_pairStatus = PairStatus::NotPaired;
m_device->pairingTimeout(); // Use signal slot, or this is good ?
}
void LanPairingHandler::setAsPaired()
{
KdeConnectConfig::instance()->setDeviceProperty(m_device->id(), "publicKey", m_device->publicKey().toPEM());
KdeConnectConfig::instance()->setDeviceProperty(m_device->id(), "certificate", QString::fromLatin1(m_device->certificate().toPem()));
m_pairStatus = PairStatus::Paired;
m_pairingTimeout.stop(); // Just in case it is started
Q_EMIT(pairingDone());
np.set("name", deviceLink()->name());
deviceLink()->sendPackage(np);
setPairStatus(PairStatus::NotPaired); //Will emit the change as well
Q_EMIT pairingFailed(i18n("Timed out"));
}
......@@ -30,7 +30,7 @@ class LanPairingHandler
: public PairingHandler
{
public:
LanPairingHandler(Device* device);
LanPairingHandler(const QString& deviceId);
virtual ~LanPairingHandler() { }
virtual void createPairPackage(NetworkPackage& np) Q_DECL_OVERRIDE;
......@@ -40,12 +40,14 @@ public:
virtual void rejectPairing() Q_DECL_OVERRIDE;
virtual void unpair() Q_DECL_OVERRIDE;
public Q_SLOTS:
private Q_SLOTS:
virtual void pairingTimeout();
private:
virtual void setAsPaired() Q_DECL_OVERRIDE;
protected:
QTimer m_pairingTimeout;
QString m_deviceId;
QCA::PublicKey m_publicKey;
QSslCertificate m_certificate;
};
......
......@@ -26,7 +26,7 @@
#include "core_debug.h"
UploadJob::UploadJob(const QSharedPointer<QIODevice>& source, const QVariantMap& transferInfo): KJob()
UploadJob::UploadJob(const QSharedPointer<QIODevice>& source, const QString& deviceId): KJob()
{
// TODO: initialize in constructor
mInput = source;
......@@ -35,7 +35,7 @@ UploadJob::UploadJob(const QSharedPointer<QIODevice>& source, const QVariantMap&
mPort = 0;
// We will use this info if link is on ssl, to send encrypted payload
this->mTransferInfo = transferInfo;
this->mDeviceId = deviceId;
connect(mInput.data(), SIGNAL(readyRead()), this, SLOT(readyRead()));
connect(mInput.data(), SIGNAL(aboutToClose()), this, SLOT(aboutToClose()));
......@@ -69,15 +69,13 @@ void UploadJob::newConnection()
mSocket = server->nextPendingConnection();
connect(mSocket, SIGNAL(disconnected()), mSocket, SLOT(deleteLater()));
if (mTransferInfo.value("useSsl", false).toBool()) {
mSocket->setLocalCertificate(KdeConnectConfig::instance()->certificate());
mSocket->setPrivateKey(KdeConnectConfig::instance()->privateKeyPath());
mSocket->setProtocol(QSsl::TlsV1_2);
mSocket->setPeerVerifyName(mTransferInfo.value("deviceId").toString());
mSocket->addCaCertificate(QSslCertificate(KdeConnectConfig::instance()->getTrustedDevice(mTransferInfo.value("deviceId").toString()).certificate.toLatin1()));
mSocket->startServerEncryption();
mSocket->waitForEncrypted();
}
mSocket->setLocalCertificate(KdeConnectConfig::instance()->certificate());
mSocket->setPrivateKey(KdeConnectConfig::instance()->privateKeyPath());
mSocket->setProtocol(QSsl::TlsV1_2);
mSocket->setPeerVerifyName(mDeviceId);
mSocket->addCaCertificate(QSslCertificate(KdeConnectConfig::instance()->getDeviceProperty(mDeviceId, "certificate", QString()).toLatin1()));
mSocket->startServerEncryption();
mSocket->waitForEncrypted();
readyRead();
}
......
......@@ -34,7 +34,7 @@ class UploadJob
{
Q_OBJECT
public:
explicit UploadJob(const QSharedPointer<QIODevice>& source, const QVariantMap& sslInfo);
explicit UploadJob(const QSharedPointer<QIODevice>& source, const QString& deviceId);
virtual void start() override;
......@@ -45,7 +45,7 @@ private:
Server* mServer;
QSslSocket* mSocket;
quint16 mPort;
QVariantMap mTransferInfo;
QString mDeviceId;
private Q_SLOTS:
void readyRead();
......
......@@ -36,7 +36,7 @@ QString LoopbackDeviceLink::name()
PairingHandler* LoopbackDeviceLink::createPairingHandler(Device *device)
{
return new LoopbackPairingHandler(device);
return new LoopbackPairingHandler(device->id());
}
bool LoopbackDeviceLink::sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& input)
{
......
......@@ -27,23 +27,23 @@
#include "loopbackpairinghandler.h"
#include "networkpackagetypes.h"
LoopbackPairingHandler::LoopbackPairingHandler(Device* device)
: LanPairingHandler(device)
LoopbackPairingHandler::LoopbackPairingHandler(const QString& deviceId)
: LanPairingHandler(deviceId)
{
}
}
bool LoopbackPairingHandler::requestPairing()
{
switch (m_pairStatus) {
switch (pairStatus()) {
case PairStatus::Paired:
Q_EMIT pairingFailed(i18n(m_deviceLink->name().append(" : Already paired").toLatin1().data()));
Q_EMIT pairingFailed(deviceLink()->name().append(" : Already paired").toLatin1().data());
return false;
case PairStatus ::Requested:
Q_EMIT pairingFailed(i18n(m_deviceLink->name().append(" : Pairing already requested for this device").toLatin1().data()));
Q_EMIT pairingFailed(deviceLink()->name().append(" : Pairing already requested for this device").toLatin1().data());
return false;
case PairStatus ::RequestedByPeer:
qCDebug(KDECONNECT_CORE) << m_deviceLink->name() << " : Pairing already started by the other end, accepting their request.";
qCDebug(KDECONNECT_CORE) << deviceLink()->name() << " : Pairing already started by the other end, accepting their request.";
acceptPairing();
return false;
case PairStatus::NotPaired:
......@@ -52,9 +52,9 @@ bool LoopbackPairingHandler::requestPairing()
NetworkPackage np(PACKAGE_TYPE_PAIR);
createPairPackage(np);
m_pairStatus = PairStatus::Requested;
setPairStatus(PairStatus::Requested);
m_pairingTimeout.start();
bool success = m_deviceLink->sendPackage(np);
bool success = deviceLink()->sendPackage(np);
return success;
}
......@@ -62,20 +62,10 @@ bool LoopbackPairingHandler::acceptPairing()
{
NetworkPackage np(PACKAGE_TYPE_PAIR);
createPairPackage(np);
m_pairStatus = PairStatus::Paired;
setAsPaired();
bool success = m_deviceLink->sendPackage(np);
Q_EMIT(pairingDone());
setPairStatus(PairStatus::Paired);
bool success = deviceLink()->sendPackage(np);
KdeConnectConfig::instance()->setDeviceProperty(m_deviceId, "publicKey", QString::fromLatin1(KdeConnectConfig::instance()->certificate().toPem()));
KdeConnectConfig::instance()->setDeviceProperty(m_deviceId, "certificate", QString::fromLatin1(KdeConnectConfig::instance()->certificate().toPem()));
return success;
}
void LoopbackPairingHandler::setAsPaired()
{
KdeConnectConfig::instance()->setDeviceProperty(m_device->id(), "publicKey", m_device->publicKey().toPEM());
KdeConnectConfig::instance()->setDeviceProperty(m_device->id(), "certificate", QString::fromLatin1(m_device->certificate().toPem()));
m_pairStatus = PairStatus::Paired;
m_pairingTimeout.stop(); // Just in case it is started
Q_EMIT(pairingDone());
}
......@@ -30,15 +30,12 @@ class LoopbackPairingHandler
: public LanPairingHandler
{
public:
LoopbackPairingHandler(Device* device);
LoopbackPairingHandler(const QString& deviceId);
virtual ~LoopbackPairingHandler() { }
virtual bool requestPairing() Q_DECL_OVERRIDE;
virtual bool acceptPairing() Q_DECL_OVERRIDE;
private:
virtual void setAsPaired() Q_DECL_OVERRIDE;
};
......
......@@ -20,9 +20,11 @@
#include "pairinghandler.h"
PairingHandler::PairingHandler(Device* device)
PairingHandler::PairingHandler()
: m_pairStatus(NotPaired)
, m_deviceLink(nullptr)
{
m_device = device;
}
void PairingHandler::setLink(DeviceLink *dl)
......@@ -37,4 +39,13 @@ void PairingHandler::linkDestroyed(QObject* o)
m_deviceLink = Q_NULLPTR;
Q_EMIT linkNull();
}
}
\ No newline at end of file
}
void PairingHandler::setPairStatus(PairingHandler::PairStatus status)
{
if (m_pairStatus != status) {
PairStatus oldStatus = m_pairStatus;
m_pairStatus = status;
Q_EMIT pairStatusChanged(status, oldStatus);
}
}
......@@ -21,7 +21,6 @@
#ifndef KDECONNECT_PAIRINGHANDLER_H
#define KDECONNECT_PAIRINGHANDLER_H
#include "device.h"
#include "networkpackage.h"
#include "devicelink.h"
......@@ -41,8 +40,10 @@
class PairingHandler : public QObject
{
Q_OBJECT
protected:
public: