Fixed issues pointed out on CR
This commit is contained in:
parent
f36de70dec
commit
e6da860fb7
17 changed files with 81 additions and 88 deletions
|
@ -44,12 +44,10 @@ void DownloadJob::start()
|
||||||
{
|
{
|
||||||
//kDebug(kdeconnect_kded()) << "DownloadJob Start";
|
//kDebug(kdeconnect_kded()) << "DownloadJob Start";
|
||||||
if (useSsl) {
|
if (useSsl) {
|
||||||
qDebug() << "Connecting to host encrypted";
|
|
||||||
// Cannot use read only, might be due to ssl handshake, getting QIODevice::ReadOnly error and no connection
|
// 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->connectToHostEncrypted(mAddress.toString(), mPort, QIODevice::ReadWrite);
|
||||||
mSocket->waitForEncrypted();
|
mSocket->waitForEncrypted();
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Connectiong to host unencrypted";
|
|
||||||
mSocket->connectToHost(mAddress, mPort, QIODevice::ReadOnly);
|
mSocket->connectToHost(mAddress, mPort, QIODevice::ReadOnly);
|
||||||
mSocket->waitForConnected();
|
mSocket->waitForConnected();
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ void LanDeviceLink::setOnSsl(bool value) {
|
||||||
bool LanDeviceLink::sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& np)
|
bool LanDeviceLink::sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& np)
|
||||||
{
|
{
|
||||||
if (np.hasPayload()) {
|
if (np.hasPayload()) {
|
||||||
np.setPayloadTransferInfo(sendPayload(np)->getTransferInfo());
|
np.setPayloadTransferInfo(sendPayload(np)->transferInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!onSsl) {
|
if (!onSsl) {
|
||||||
|
@ -75,7 +75,7 @@ bool LanDeviceLink::sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& np
|
||||||
bool LanDeviceLink::sendPackage(NetworkPackage& np)
|
bool LanDeviceLink::sendPackage(NetworkPackage& np)
|
||||||
{
|
{
|
||||||
if (np.hasPayload()) {
|
if (np.hasPayload()) {
|
||||||
np.setPayloadTransferInfo(sendPayload(np)->getTransferInfo());
|
np.setPayloadTransferInfo(sendPayload(np)->transferInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
int written = mSocketLineReader->write(np.serialize());
|
int written = mSocketLineReader->write(np.serialize());
|
||||||
|
@ -107,13 +107,12 @@ void LanDeviceLink::dataReceived()
|
||||||
NetworkPackage::unserialize(package, &unserialized);
|
NetworkPackage::unserialize(package, &unserialized);
|
||||||
if (unserialized.isEncrypted()) {
|
if (unserialized.isEncrypted()) {
|
||||||
//mPrivateKey should always be set when device link is added to device, no null-checking done here
|
//mPrivateKey should always be set when device link is added to device, no null-checking done here
|
||||||
// TODO : Check this with old device since package thorough ssl in unencrypted
|
// TODO : Check this with old device since package through ssl in unencrypted
|
||||||
unserialized.decrypt(mPrivateKey, &unserialized);
|
unserialized.decrypt(mPrivateKey, &unserialized);
|
||||||
qDebug() << "Serialized " << unserialized.serialize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unserialized.hasPayloadTransferInfo()) {
|
if (unserialized.hasPayloadTransferInfo()) {
|
||||||
// qCDebug(KDECONNECT_CORE) << "HasPayloadTransferInfo";
|
//qCDebug(KDECONNECT_CORE) << "HasPayloadTransferInfo";
|
||||||
QVariantMap transferInfo = unserialized.payloadTransferInfo();
|
QVariantMap transferInfo = unserialized.payloadTransferInfo();
|
||||||
if (onSsl) {
|
if (onSsl) {
|
||||||
transferInfo.insert("useSsl", true);
|
transferInfo.insert("useSsl", true);
|
||||||
|
|
|
@ -51,7 +51,7 @@ LanLinkProvider::LanLinkProvider()
|
||||||
mServer = new Server(this);
|
mServer = new Server(this);
|
||||||
connect(mServer,SIGNAL(newConnection()),this, SLOT(newConnection()));
|
connect(mServer,SIGNAL(newConnection()),this, SLOT(newConnection()));
|
||||||
|
|
||||||
pairingHandler = new LanPairingHandler();
|
m_pairingHandler = new LanPairingHandler();
|
||||||
|
|
||||||
//Detect when a network interface changes status, so we announce ourelves in the new network
|
//Detect when a network interface changes status, so we announce ourelves in the new network
|
||||||
QNetworkConfigurationManager* networkManager;
|
QNetworkConfigurationManager* networkManager;
|
||||||
|
@ -114,7 +114,6 @@ void LanLinkProvider::onNetworkChange()
|
||||||
void LanLinkProvider::newUdpConnection()
|
void LanLinkProvider::newUdpConnection()
|
||||||
{
|
{
|
||||||
while (mUdpServer->hasPendingDatagrams()) {
|
while (mUdpServer->hasPendingDatagrams()) {
|
||||||
qCDebug(KDECONNECT_CORE) << "Udp package received";
|
|
||||||
|
|
||||||
QByteArray datagram;
|
QByteArray datagram;
|
||||||
datagram.resize(mUdpServer->pendingDatagramSize());
|
datagram.resize(mUdpServer->pendingDatagramSize());
|
||||||
|
@ -158,8 +157,6 @@ void LanLinkProvider::connectError()
|
||||||
disconnect(socket, SIGNAL(connected()), this, SLOT(connected()));
|
disconnect(socket, SIGNAL(connected()), this, SLOT(connected()));
|
||||||
disconnect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectError()));
|
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)";
|
qCDebug(KDECONNECT_CORE) << "Fallback (1), try reverse connection (send udp packet)";
|
||||||
NetworkPackage np("");
|
NetworkPackage np("");
|
||||||
NetworkPackage::createIdentityPackage(&np);
|
NetworkPackage::createIdentityPackage(&np);
|
||||||
|
@ -168,8 +165,7 @@ void LanLinkProvider::connectError()
|
||||||
|
|
||||||
//The socket we created didn't work, and we didn't manage
|
//The socket we created didn't work, and we didn't manage
|
||||||
//to create a LanDeviceLink from it, deleting everything.
|
//to create a LanDeviceLink from it, deleting everything.
|
||||||
delete receivedIdentityPackages[socket].np;
|
delete receivedIdentityPackages.take(socket).np;
|
||||||
receivedIdentityPackages.remove(socket);
|
|
||||||
delete socket;
|
delete socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +173,6 @@ void LanLinkProvider::connected()
|
||||||
{
|
{
|
||||||
qCDebug(KDECONNECT_CORE) << "Socket connected";
|
qCDebug(KDECONNECT_CORE) << "Socket connected";
|
||||||
|
|
||||||
// TODO : Change the behaviour of these disconnects
|
|
||||||
QSslSocket* socket = qobject_cast<QSslSocket*>(sender());
|
QSslSocket* socket = qobject_cast<QSslSocket*>(sender());
|
||||||
if (!socket) return;
|
if (!socket) return;
|
||||||
disconnect(socket, SIGNAL(connected()), this, SLOT(connected()));
|
disconnect(socket, SIGNAL(connected()), this, SLOT(connected()));
|
||||||
|
@ -244,7 +239,8 @@ void LanLinkProvider::connected()
|
||||||
//We don't delete the socket because now it's owned by the LanDeviceLink
|
//We don't delete the socket because now it's owned by the LanDeviceLink
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanLinkProvider::encrypted() {
|
void LanLinkProvider::encrypted()
|
||||||
|
{
|
||||||
|
|
||||||
qCDebug(KDECONNECT_CORE) << "Socket encrypted";
|
qCDebug(KDECONNECT_CORE) << "Socket encrypted";
|
||||||
|
|
||||||
|
@ -267,7 +263,7 @@ void LanLinkProvider::encrypted() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanLinkProvider::sslErrors(QList<QSslError> errors)
|
void LanLinkProvider::sslErrors(const QList<QSslError>& errors)
|
||||||
{
|
{
|
||||||
QSslSocket* socket = qobject_cast<QSslSocket*>(sender());
|
QSslSocket* socket = qobject_cast<QSslSocket*>(sender());
|
||||||
if (!socket) return;
|
if (!socket) return;
|
||||||
|
@ -293,8 +289,7 @@ void LanLinkProvider::sslErrors(QList<QSslError> errors)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete receivedIdentityPackages[socket].np;
|
delete receivedIdentityPackages.take(socket).np;
|
||||||
receivedIdentityPackages.remove(socket);
|
|
||||||
// Socket disconnects itself on ssl error and will be deleted by deleteLater slot, no need to delete manually
|
// Socket disconnects itself on ssl error and will be deleted by deleteLater slot, no need to delete manually
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +298,7 @@ void LanLinkProvider::sslErrors(QList<QSslError> errors)
|
||||||
//I'm the new device and this is the answer to my UDP identity package (no data received yet)
|
//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()
|
||||||
{
|
{
|
||||||
qDebug() << "LanLinkProvider newConnection " ;
|
//qCDebug(KDECONNECT_CORE) << "LanLinkProvider newConnection";
|
||||||
|
|
||||||
while (mServer->hasPendingConnections()) {
|
while (mServer->hasPendingConnections()) {
|
||||||
QSslSocket* socket = mServer->nextPendingConnection();
|
QSslSocket* socket = mServer->nextPendingConnection();
|
||||||
|
@ -331,14 +326,14 @@ void LanLinkProvider::dataReceived()
|
||||||
NetworkPackage* np = new NetworkPackage("");
|
NetworkPackage* np = new NetworkPackage("");
|
||||||
bool success = NetworkPackage::unserialize(data, np);
|
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?)";
|
qCDebug(KDECONNECT_CORE) << "LanLinkProvider/newConnection: Not an identification package (wuh?)";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Needed in "encrypted" if ssl is used, similar to "connected"
|
||||||
|
receivedIdentityPackages[socket].np = np;
|
||||||
|
|
||||||
const QString& deviceId = np->get<QString>("deviceId");
|
const QString& deviceId = np->get<QString>("deviceId");
|
||||||
//qCDebug(KDECONNECT_CORE) << "Handshaking done (i'm the new device)";
|
//qCDebug(KDECONNECT_CORE) << "Handshaking done (i'm the new device)";
|
||||||
|
|
||||||
|
@ -369,11 +364,14 @@ void LanLinkProvider::dataReceived()
|
||||||
connect(socket, SIGNAL(encrypted()), this, SLOT(encrypted()));
|
connect(socket, SIGNAL(encrypted()), this, SLOT(encrypted()));
|
||||||
|
|
||||||
socket->startClientEncryption();
|
socket->startClientEncryption();
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
addLink(deviceId, socket, np);
|
addLink(deviceId, socket, np);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete np;
|
||||||
|
receivedIdentityPackages.remove(socket);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanLinkProvider::deviceLinkDestroyed(QObject* destroyedDeviceLink)
|
void LanLinkProvider::deviceLinkDestroyed(QObject* destroyedDeviceLink)
|
||||||
|
|
|
@ -58,7 +58,7 @@ private Q_SLOTS:
|
||||||
void newConnection();
|
void newConnection();
|
||||||
void dataReceived();
|
void dataReceived();
|
||||||
void deviceLinkDestroyed(QObject* destroyedDeviceLink);
|
void deviceLinkDestroyed(QObject* destroyedDeviceLink);
|
||||||
void sslErrors(QList<QSslError> errors);
|
void sslErrors(const QList<QSslError>& errors);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void configureSocket(QSslSocket* socket);
|
static void configureSocket(QSslSocket* socket);
|
||||||
|
|
|
@ -22,20 +22,20 @@
|
||||||
#include "lanpairinghandler.h"
|
#include "lanpairinghandler.h"
|
||||||
#include "networkpackagetypes.h"
|
#include "networkpackagetypes.h"
|
||||||
|
|
||||||
LanPairingHandler::LanPairingHandler() {
|
LanPairingHandler::LanPairingHandler()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkPackage LanPairingHandler::createPairPackage() {
|
void LanPairingHandler::createPairPackage(NetworkPackage& np)
|
||||||
NetworkPackage np(PACKAGE_TYPE_PAIR);
|
{
|
||||||
np.set("pair", true);
|
np.set("pair", true);
|
||||||
np.set("publicKey", KdeConnectConfig::instance()->publicKey().toPEM());
|
np.set("publicKey", KdeConnectConfig::instance()->publicKey().toPEM());
|
||||||
return np;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LanPairingHandler::packageReceived(Device *device, NetworkPackage np) {
|
bool LanPairingHandler::packageReceived(Device *device,const NetworkPackage& np)
|
||||||
|
{
|
||||||
//Retrieve their public key
|
//Retrieve their public key
|
||||||
const QString& keyString = np.get<QString>("publicKey");
|
QString keyString = np.get<QString>("publicKey");
|
||||||
device->setPublicKey(QCA::RSAPublicKey::fromPEM(keyString));
|
device->setPublicKey(QCA::RSAPublicKey::fromPEM(keyString));
|
||||||
if (device->publicKey().isNull()) {
|
if (device->publicKey().isNull()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -43,28 +43,32 @@ bool LanPairingHandler::packageReceived(Device *device, NetworkPackage np) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LanPairingHandler::requestPairing(Device *device) {
|
bool LanPairingHandler::requestPairing(Device *device)
|
||||||
NetworkPackage np = createPairPackage();
|
{
|
||||||
|
NetworkPackage np(PACKAGE_TYPE_PAIR);
|
||||||
|
createPairPackage(np);
|
||||||
bool success = device->sendPackage(np);
|
bool success = device->sendPackage(np);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LanPairingHandler::acceptPairing(Device *device) {
|
bool LanPairingHandler::acceptPairing(Device *device)
|
||||||
NetworkPackage np = createPairPackage();
|
{
|
||||||
|
NetworkPackage np(PACKAGE_TYPE_PAIR);
|
||||||
|
createPairPackage(np);
|
||||||
bool success = device->sendPackage(np);
|
bool success = device->sendPackage(np);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanPairingHandler::rejectPairing(Device *device) {
|
void LanPairingHandler::rejectPairing(Device *device)
|
||||||
|
{
|
||||||
// TODO : check status of reject pairing
|
// TODO : check status of reject pairing
|
||||||
NetworkPackage np(PACKAGE_TYPE_PAIR);
|
NetworkPackage np(PACKAGE_TYPE_PAIR);
|
||||||
np.set("pair", false);
|
np.set("pair", false);
|
||||||
device->sendPackage(np);
|
device->sendPackage(np);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanPairingHandler::pairingDone(Device *device) {
|
void LanPairingHandler::pairingDone(Device *device)
|
||||||
// TODO : Save certificate and public key here
|
{
|
||||||
|
|
||||||
// No need to worry, if either of certificate or public key is null an empty qstring will be returned
|
// No need to worry, if either of certificate or public key is null an empty qstring will be returned
|
||||||
KdeConnectConfig::instance()->setDeviceProperty(device->id(), "key", device->publicKey().toPEM());
|
KdeConnectConfig::instance()->setDeviceProperty(device->id(), "key", device->publicKey().toPEM());
|
||||||
KdeConnectConfig::instance()->setDeviceProperty(device->id(), "certificate", QString(device->certificate().toPem()));
|
KdeConnectConfig::instance()->setDeviceProperty(device->id(), "certificate", QString(device->certificate().toPem()));
|
||||||
|
@ -74,4 +78,5 @@ void LanPairingHandler::unpair(Device *device) {
|
||||||
NetworkPackage np(PACKAGE_TYPE_PAIR);
|
NetworkPackage np(PACKAGE_TYPE_PAIR);
|
||||||
np.set("pair", false);
|
np.set("pair", false);
|
||||||
bool success = device->sendPackage(np);
|
bool success = device->sendPackage(np);
|
||||||
|
Q_UNUSED(success);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,8 @@ public:
|
||||||
LanPairingHandler();
|
LanPairingHandler();
|
||||||
virtual ~LanPairingHandler() { }
|
virtual ~LanPairingHandler() { }
|
||||||
|
|
||||||
virtual NetworkPackage createPairPackage() Q_DECL_OVERRIDE;
|
virtual void createPairPackage(NetworkPackage& np) Q_DECL_OVERRIDE;
|
||||||
virtual bool packageReceived(Device *device, NetworkPackage np) Q_DECL_OVERRIDE;
|
virtual bool packageReceived(Device *device,const NetworkPackage& np) Q_DECL_OVERRIDE;
|
||||||
virtual bool requestPairing(Device *device) Q_DECL_OVERRIDE;
|
virtual bool requestPairing(Device *device) Q_DECL_OVERRIDE;
|
||||||
virtual bool acceptPairing(Device *device) Q_DECL_OVERRIDE;
|
virtual bool acceptPairing(Device *device) Q_DECL_OVERRIDE;
|
||||||
virtual void rejectPairing(Device *device) Q_DECL_OVERRIDE;
|
virtual void rejectPairing(Device *device) Q_DECL_OVERRIDE;
|
||||||
|
|
|
@ -34,9 +34,9 @@ Server::Server(QObject * parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::incomingConnection(qintptr socketDescriptor) {
|
void Server::incomingConnection(qintptr socketDescriptor) {
|
||||||
QSslSocket *serverSocket = new QSslSocket;
|
QSslSocket *serverSocket = new QSslSocket(parent());
|
||||||
if (serverSocket->setSocketDescriptor(socketDescriptor)) {
|
if (serverSocket->setSocketDescriptor(socketDescriptor)) {
|
||||||
pendingConnections.push_back(serverSocket);
|
pendingConnections.append(serverSocket);
|
||||||
Q_EMIT newConnection();
|
Q_EMIT newConnection();
|
||||||
} else {
|
} else {
|
||||||
delete serverSocket;
|
delete serverSocket;
|
||||||
|
@ -44,15 +44,13 @@ void Server::incomingConnection(qintptr socketDescriptor) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QSslSocket* Server::nextPendingConnection() {
|
QSslSocket* Server::nextPendingConnection() {
|
||||||
if (pendingConnections.size() == 0) {
|
if (pendingConnections.isEmpty()) {
|
||||||
return Q_NULLPTR;
|
return Q_NULLPTR;
|
||||||
} else {
|
} else {
|
||||||
QSslSocket *socket = pendingConnections.first();
|
return pendingConnections.takeFirst();
|
||||||
pendingConnections.removeFirst();
|
|
||||||
return socket;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::hasPendingConnections() const {
|
bool Server::hasPendingConnections() const {
|
||||||
return pendingConnections.size() != 0;
|
return !pendingConnections.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include <QtNetwork/qsslsocket.h>
|
#include <QtNetwork/qsslsocket.h>
|
||||||
|
|
||||||
class Server
|
class Server
|
||||||
: public QTcpServers
|
: public QTcpServer
|
||||||
{
|
{
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -34,7 +34,7 @@ private:
|
||||||
QList<QSslSocket*> pendingConnections;
|
QList<QSslSocket*> pendingConnections;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Server(QObject* parent = 0);
|
Server(QObject* parent);
|
||||||
virtual ~Server() {}
|
virtual ~Server() {}
|
||||||
|
|
||||||
QSslSocket* nextPendingConnection() Q_DECL_OVERRIDE;
|
QSslSocket* nextPendingConnection() Q_DECL_OVERRIDE;
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include "uploadjob.h"
|
#include "uploadjob.h"
|
||||||
#include "core_debug.h"
|
#include "core_debug.h"
|
||||||
|
|
||||||
UploadJob::UploadJob(const QSharedPointer<QIODevice>& source, QVariantMap transferInfo): KJob()
|
UploadJob::UploadJob(const QSharedPointer<QIODevice>& source, const QVariantMap& transferInfo): KJob()
|
||||||
{
|
{
|
||||||
mInput = source;
|
mInput = source;
|
||||||
mServer = new Server(this);
|
mServer = new Server(this);
|
||||||
|
@ -33,7 +33,7 @@ UploadJob::UploadJob(const QSharedPointer<QIODevice>& source, QVariantMap transf
|
||||||
mPort = 0;
|
mPort = 0;
|
||||||
|
|
||||||
// We will use this info if link is on ssl, to send encrypted payload
|
// We will use this info if link is on ssl, to send encrypted payload
|
||||||
this->transferInfo = transferInfo;
|
this->mTransferInfo = transferInfo;
|
||||||
|
|
||||||
connect(mInput.data(), SIGNAL(readyRead()), this, SLOT(readyRead()));
|
connect(mInput.data(), SIGNAL(readyRead()), this, SLOT(readyRead()));
|
||||||
connect(mInput.data(), SIGNAL(aboutToClose()), this, SLOT(aboutToClose()));
|
connect(mInput.data(), SIGNAL(aboutToClose()), this, SLOT(aboutToClose()));
|
||||||
|
@ -50,24 +50,29 @@ void UploadJob::start()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
connect(mServer, SIGNAL(newConnection(QSslSocket*)), this, SLOT(newConnection(QSslSocket*)));
|
connect(mServer, SIGNAL(newConnection()), this, SLOT(newConnection()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UploadJob::newConnection(QSslSocket* socket)
|
void UploadJob::newConnection()
|
||||||
{
|
{
|
||||||
if (!mInput->open(QIODevice::ReadOnly)) {
|
if (!mInput->open(QIODevice::ReadOnly)) {
|
||||||
qWarning() << "error when opening the input to upload";
|
qWarning() << "error when opening the input to upload";
|
||||||
return; //TODO: Handle error, clean up...
|
return; //TODO: Handle error, clean up...
|
||||||
}
|
}
|
||||||
|
|
||||||
mSocket = socket;
|
Server* server = qobject_cast<Server*>(sender());
|
||||||
|
// FIXME : It is called again when payload sending is finished. Unsolved mystery :(
|
||||||
|
disconnect(mServer, SIGNAL(newConnection()), this, SLOT(newConnection()));
|
||||||
|
|
||||||
if (transferInfo.value("useSsl", false).toBool()) {
|
mSocket = server->nextPendingConnection();
|
||||||
|
connect(mSocket, SIGNAL(disconnected()), mSocket, SLOT(deleteLater()));
|
||||||
|
|
||||||
|
if (mTransferInfo.value("useSsl", false).toBool()) {
|
||||||
mSocket->setLocalCertificate(KdeConnectConfig::instance()->certificate());
|
mSocket->setLocalCertificate(KdeConnectConfig::instance()->certificate());
|
||||||
mSocket->setPrivateKey(KdeConnectConfig::instance()->privateKeyPath());
|
mSocket->setPrivateKey(KdeConnectConfig::instance()->privateKeyPath());
|
||||||
mSocket->setProtocol(QSsl::TlsV1_2);
|
mSocket->setProtocol(QSsl::TlsV1_2);
|
||||||
mSocket->setPeerVerifyName(transferInfo.value("deviceId").toString());
|
mSocket->setPeerVerifyName(mTransferInfo.value("deviceId").toString());
|
||||||
mSocket->addCaCertificate(QSslCertificate(KdeConnectConfig::instance()->getTrustedDevice(transferInfo.value("deviceId").toString()).certificate.toLatin1()));
|
mSocket->addCaCertificate(QSslCertificate(KdeConnectConfig::instance()->getTrustedDevice(mTransferInfo.value("deviceId").toString()).certificate.toLatin1()));
|
||||||
mSocket->startServerEncryption();
|
mSocket->startServerEncryption();
|
||||||
mSocket->waitForEncrypted();
|
mSocket->waitForEncrypted();
|
||||||
}
|
}
|
||||||
|
@ -101,7 +106,7 @@ void UploadJob::aboutToClose()
|
||||||
emitResult();
|
emitResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap UploadJob::getTransferInfo()
|
QVariantMap UploadJob::transferInfo()
|
||||||
{
|
{
|
||||||
Q_ASSERT(mPort != 0);
|
Q_ASSERT(mPort != 0);
|
||||||
|
|
||||||
|
|
|
@ -34,20 +34,20 @@ class UploadJob
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
UploadJob(const QSharedPointer<QIODevice>& source, QVariantMap sslInfo);
|
UploadJob(const QSharedPointer<QIODevice>& source,const QVariantMap& sslInfo);
|
||||||
virtual void start();
|
virtual void start();
|
||||||
QVariantMap getTransferInfo();
|
QVariantMap transferInfo();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSharedPointer<QIODevice> mInput;
|
QSharedPointer<QIODevice> mInput;
|
||||||
Server* mServer;
|
Server* mServer;
|
||||||
QSslSocket* mSocket;
|
QSslSocket* mSocket;
|
||||||
quint16 mPort;
|
quint16 mPort;
|
||||||
QVariantMap transferInfo;
|
QVariantMap mTransferInfo;
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void readyRead();
|
void readyRead();
|
||||||
void newConnection(QSslSocket*);
|
void newConnection();
|
||||||
void aboutToClose();
|
void aboutToClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,6 @@ class LinkProvider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
protected:
|
|
||||||
PairingHandler* pairingHandler;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
const static int PRIORITY_LOW = 0; //eg: 3g internet
|
const static int PRIORITY_LOW = 0; //eg: 3g internet
|
||||||
|
@ -49,7 +46,10 @@ public:
|
||||||
|
|
||||||
virtual QString name() = 0;
|
virtual QString name() = 0;
|
||||||
virtual int priority() = 0;
|
virtual int priority() = 0;
|
||||||
PairingHandler* getPairingHandler() { return pairingHandler;}
|
PairingHandler* pairingHandler() { return m_pairingHandler;}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
PairingHandler* m_pairingHandler;
|
||||||
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
|
|
@ -31,8 +31,8 @@ public:
|
||||||
PairingHandler();
|
PairingHandler();
|
||||||
virtual ~PairingHandler() { }
|
virtual ~PairingHandler() { }
|
||||||
|
|
||||||
virtual NetworkPackage createPairPackage() = 0;
|
virtual void createPairPackage(NetworkPackage& np) = 0;
|
||||||
virtual bool packageReceived(Device *device, NetworkPackage np) = 0;
|
virtual bool packageReceived(Device *device,const NetworkPackage& np) = 0;
|
||||||
virtual bool requestPairing(Device *device) = 0;
|
virtual bool requestPairing(Device *device) = 0;
|
||||||
virtual bool acceptPairing(Device *device) = 0;
|
virtual bool acceptPairing(Device *device) = 0;
|
||||||
virtual void rejectPairing(Device *device) = 0;
|
virtual void rejectPairing(Device *device) = 0;
|
||||||
|
|
|
@ -133,7 +133,7 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
|
||||||
{
|
{
|
||||||
const QString& id = identityPackage.get<QString>("deviceId");
|
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)) {
|
if (d->mDevices.contains(id)) {
|
||||||
qCDebug(KDECONNECT_CORE) << "It is a known device " << identityPackage.get<QString>("deviceName");
|
qCDebug(KDECONNECT_CORE) << "It is a known device " << identityPackage.get<QString>("deviceName");
|
||||||
|
|
|
@ -210,7 +210,7 @@ void Device::requestPair()
|
||||||
|
|
||||||
//Send our own public key
|
//Send our own public key
|
||||||
Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
|
Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
|
||||||
bool success = dl->provider()->getPairingHandler()->requestPairing(this);
|
bool success = dl->provider()->pairingHandler()->requestPairing(this);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
m_pairStatus = Device::NotPaired;
|
m_pairStatus = Device::NotPaired;
|
||||||
|
@ -230,7 +230,7 @@ void Device::unpair()
|
||||||
{
|
{
|
||||||
|
|
||||||
Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
|
Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
|
||||||
dl->provider()->getPairingHandler()->unpair(this);
|
dl->provider()->pairingHandler()->unpair(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
unpairInternal();
|
unpairInternal();
|
||||||
|
@ -282,9 +282,7 @@ void Device::addLink(const NetworkPackage& identityPackage, DeviceLink* link)
|
||||||
// Set certificate if the link is on ssl, and it is added to identity package
|
// 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
|
// This is always sets certificate when link is added to device
|
||||||
if (identityPackage.has("certificate")) {
|
if (identityPackage.has("certificate")) {
|
||||||
qDebug() << "Got certificate" ;
|
|
||||||
m_certificate = QSslCertificate(identityPackage.get<QByteArray>("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
|
//Theoretically we will never add two links from the same provider (the provider should destroy
|
||||||
|
@ -356,7 +354,7 @@ void Device::privateReceivedPackage(const NetworkPackage& np)
|
||||||
} else if (m_pairStatus == Device::Paired) {
|
} else if (m_pairStatus == Device::Paired) {
|
||||||
// If other request's pairing, and we have pair status Paired, send accept pairing
|
// If other request's pairing, and we have pair status Paired, send accept pairing
|
||||||
Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
|
Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
|
||||||
dl->provider()->getPairingHandler()->acceptPairing(this);
|
dl->provider()->pairingHandler()->acceptPairing(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -365,7 +363,7 @@ void Device::privateReceivedPackage(const NetworkPackage& np)
|
||||||
if (wantsPair) {
|
if (wantsPair) {
|
||||||
|
|
||||||
Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
|
Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
|
||||||
bool success = dl->provider()->getPairingHandler()->packageReceived(this, np);
|
bool success = dl->provider()->pairingHandler()->packageReceived(this, np);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
if (m_pairStatus == Device::Requested) {
|
if (m_pairStatus == Device::Requested) {
|
||||||
m_pairStatus = Device::NotPaired;
|
m_pairStatus = Device::NotPaired;
|
||||||
|
@ -434,7 +432,7 @@ void Device::rejectPairing()
|
||||||
m_pairStatus = Device::NotPaired;
|
m_pairStatus = Device::NotPaired;
|
||||||
|
|
||||||
Q_FOREACH(DeviceLink* link, m_deviceLinks) {
|
Q_FOREACH(DeviceLink* link, m_deviceLinks) {
|
||||||
link->provider()->getPairingHandler()->rejectPairing(this);
|
link->provider()->pairingHandler()->rejectPairing(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT pairingFailed(i18n("Canceled by the user"));
|
Q_EMIT pairingFailed(i18n("Canceled by the user"));
|
||||||
|
@ -449,7 +447,7 @@ void Device::acceptPairing()
|
||||||
|
|
||||||
bool success;
|
bool success;
|
||||||
Q_FOREACH(DeviceLink* link, m_deviceLinks) {
|
Q_FOREACH(DeviceLink* link, m_deviceLinks) {
|
||||||
success = link->provider()->getPairingHandler()->acceptPairing(this);
|
success = link->provider()->pairingHandler()->acceptPairing(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QHostInfo>
|
#include <QHostInfo>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QtNetwork/qsslcertificate.h>
|
#include <QSslCertificate>
|
||||||
|
|
||||||
#include "core_debug.h"
|
#include "core_debug.h"
|
||||||
#include "dbushelper.h"
|
#include "dbushelper.h"
|
||||||
|
|
|
@ -47,14 +47,6 @@ NetworkPackage::NetworkPackage(const QString& type)
|
||||||
mPayloadSize = 0;
|
mPayloadSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkPackage::NetworkPackage(const NetworkPackage &np) {
|
|
||||||
mId = np.id();
|
|
||||||
mType = np.type();
|
|
||||||
mBody = np.body();
|
|
||||||
mPayload = np.payload();
|
|
||||||
mPayloadSize = np.payloadSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkPackage::createIdentityPackage(NetworkPackage* np)
|
void NetworkPackage::createIdentityPackage(NetworkPackage* np)
|
||||||
{
|
{
|
||||||
KdeConnectConfig* config = KdeConnectConfig::instance();
|
KdeConnectConfig* config = KdeConnectConfig::instance();
|
||||||
|
|
|
@ -79,7 +79,7 @@ void TestSocketLineReader::socketLineReader()
|
||||||
QTest::qSleep(1000);
|
QTest::qSleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSslSocket *sock = (QSslSocket*) mServer->nextPendingConnection();
|
QSslSocket *sock = mServer->nextPendingConnection();
|
||||||
|
|
||||||
QVERIFY2(sock != 0, "Could not open a connection to the client");
|
QVERIFY2(sock != 0, "Could not open a connection to the client");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue