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 82bc73dd authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

WIPx2

parent 16f9af90
......@@ -184,7 +184,7 @@ int main(int argc, char** argv)
}
} else if(parser.isSet("encryption-info")) {
DeviceDbusInterface dev(device);
QDBusPendingReply<QByteArray> devReply = dev.encryptionInfo(); // QSsl::Der = 1
QDBusPendingReply<QString> devReply = dev.encryptionInfo(); // QSsl::Der = 1
devReply.waitForFinished();
QTextStream(stderr) << devReply.value() << endl;
} else {
......
......@@ -49,7 +49,7 @@ public:
virtual PairingHandler* createPairingHandler(Device* device) = 0;
virtual bool sendPackage(NetworkPackage& np) = 0;
virtual bool sendPackageEncrypted(QCA::PublicKey& publicKey, NetworkPackage& np) = 0;
virtual bool sendPackageEncrypted(NetworkPackage& np) = 0;
ConnectionStarted connectionSource() const {
return mConnectionSource;
......
......@@ -30,7 +30,6 @@
LanDeviceLink::LanDeviceLink(const QString& deviceId, LinkProvider* parent, QSslSocket* socket, ConnectionStarted connectionSource)
: DeviceLink(deviceId, parent, connectionSource)
, mSocketLineReader(new SocketLineReader(socket))
, onSsl(false)
{
connect(mSocketLineReader, SIGNAL(readyRead()),
this, SLOT(dataReceived()));
......@@ -50,26 +49,17 @@ QString LanDeviceLink::name()
return "LanLink"; // Should be same in both android and kde version
}
void LanDeviceLink::setOnSsl(bool value)
{
onSsl = value;
}
PairingHandler* LanDeviceLink::createPairingHandler(Device* device)
{
return new LanPairingHandler(device->id());
}
bool LanDeviceLink::sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& np)
bool LanDeviceLink::sendPackageEncrypted(NetworkPackage& np)
{
if (np.hasPayload()) {
np.setPayloadTransferInfo(sendPayload(np)->transferInfo());
}
if (!onSsl) {
np.encrypt(key);
}
int written = mSocketLineReader->write(np.serialize());
//TODO: Actually detect if a package is received or not, now we keep TCP
......@@ -91,10 +81,9 @@ bool LanDeviceLink::sendPackage(NetworkPackage& np)
UploadJob* LanDeviceLink::sendPayload(NetworkPackage& np)
{
QVariantMap transferInfo;
if (onSsl) {
transferInfo.insert("useSsl", true);
transferInfo.insert("deviceId", deviceId());
}
//FIXME: The next two lines shouldn't be needed! Why are they here?
transferInfo.insert("useSsl", true);
transferInfo.insert("deviceId", deviceId());
UploadJob* job = new UploadJob(np.payload(), deviceId());
job->start();
return job;
......@@ -120,10 +109,9 @@ void LanDeviceLink::dataReceived()
if (unserialized.hasPayloadTransferInfo()) {
//qCDebug(KDECONNECT_CORE) << "HasPayloadTransferInfo";
QVariantMap transferInfo = unserialized.payloadTransferInfo();
if (onSsl) {
transferInfo.insert("useSsl", true);
transferInfo.insert("deviceId", deviceId());
}
//FIXME: The next two lines shouldn't be needed! Why are they here?
transferInfo.insert("useSsl", true);
transferInfo.insert("deviceId", deviceId());
DownloadJob* job = new DownloadJob(mSocketLineReader->peerAddress(), transferInfo);
job->start();
unserialized.setPayload(job->getPayload(), unserialized.payloadSize());
......
......@@ -39,11 +39,10 @@ public:
LanDeviceLink(const QString& deviceId, LinkProvider* parent, QSslSocket* socket, ConnectionStarted connectionSource);
virtual QString name() Q_DECL_OVERRIDE;
void setOnSsl(bool value);
virtual PairingHandler* createPairingHandler(Device* device) Q_DECL_OVERRIDE;
bool sendPackage(NetworkPackage& np) override;
bool sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& np) override;
UploadJob* sendPayload(NetworkPackage&);
bool sendPackageEncrypted(NetworkPackage& np) override;
UploadJob* sendPayload(NetworkPackage& np);
private Q_SLOTS:
void dataReceived();
......
......@@ -427,10 +427,6 @@ void LanLinkProvider::addLink(const QString& deviceId, QSslSocket* socket, Netwo
// Socket disconnection will now be handled by LanDeviceLink
disconnect(socket, SIGNAL(disconnected()), socket, SLOT(deleteLater()));
if (socket->isEncrypted()) {
deviceLink->setOnSsl(true);
}
//We kill any possible link from this same device
QMap< QString, DeviceLink* >::iterator oldLinkIterator = mLinks.find(deviceLink->deviceId());
if (oldLinkIterator != mLinks.end()) {
......
......@@ -38,33 +38,9 @@ PairingHandler* LoopbackDeviceLink::createPairingHandler(Device *device)
{
return new LoopbackPairingHandler(device->id());
}
bool LoopbackDeviceLink::sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& input)
bool LoopbackDeviceLink::sendPackageEncrypted(NetworkPackage& input)
{
if (mPrivateKey.isNull() || key.isNull()) {
return false;
}
input.encrypt(key);
QByteArray serialized = input.serialize();
NetworkPackage unserialized(QString::null);
NetworkPackage::unserialize(serialized, &unserialized);
NetworkPackage output(QString::null);
unserialized.decrypt(mPrivateKey, &output);
bool b = true;
//LoopbackDeviceLink does not need deviceTransferInfo
if (input.hasPayload()) {
b = input.payload()->open(QIODevice::ReadOnly);
Q_ASSERT(b);
output.setPayload(input.payload(), input.payloadSize());
}
Q_EMIT receivedPackage(output);
return b;
return sendPackage(input);
}
bool LoopbackDeviceLink::sendPackage(NetworkPackage& input)
......
......@@ -35,7 +35,7 @@ public:
virtual QString name() override;
virtual PairingHandler* createPairingHandler(Device* device) override;
virtual bool sendPackage(NetworkPackage& np) override;
virtual bool sendPackageEncrypted(QCA::PublicKey& publicKey, NetworkPackage& np) override;
virtual bool sendPackageEncrypted(NetworkPackage& np) override;
};
......
......@@ -21,17 +21,22 @@
#include "pairinghandler.h"
PairingHandler::PairingHandler()
: m_pairStatus(NotPaired)
, m_deviceLink(nullptr)
: m_deviceLink(nullptr)
, m_pairStatus(NotPaired)
{
}
void PairingHandler::setLink(DeviceLink *dl)
void PairingHandler::setDeviceLink(DeviceLink *dl)
{
m_deviceLink = dl;
}
DeviceLink* PairingHandler::deviceLink() const
{
return m_deviceLink;
}
void PairingHandler::linkDestroyed(QObject* o)
{
DeviceLink* dl = static_cast<DeviceLink*>(o);
......@@ -49,3 +54,9 @@ void PairingHandler::setPairStatus(PairingHandler::PairStatus status)
Q_EMIT pairStatusChanged(status, oldStatus);
}
}
PairingHandler::PairStatus PairingHandler::pairStatus() const
{
return m_pairStatus;
}
......@@ -54,7 +54,7 @@ public:
PairingHandler();
virtual ~PairingHandler() { }
void setLink(DeviceLink* dl);
void setDeviceLink(DeviceLink* dl);
bool isPaired() const { return m_pairStatus == PairStatus::Paired; }
bool isPairRequested() const { return m_pairStatus == PairStatus::Requested; }
......
......@@ -34,6 +34,7 @@
#include <QIcon>
#include <QDir>
#include <QJsonArray>
#include <qstringbuilder.h>
#include "core_debug.h"
#include "kdeconnectplugin.h"
......@@ -288,7 +289,7 @@ void Device::addLink(const NetworkPackage& identityPackage, DeviceLink* link)
connect(m_pairingHandlers[link->name()], SIGNAL(pairStatusChanged(PairStatus, PairStatus)), this, SLOT(pairStatusChanged(PairStatus, PairStatus)));
connect(m_pairingHandlers[link->name()], SIGNAL(pairingFailed(const QString&)), this, SIGNAL(pairingFailed(const QString&)));
}
m_pairingHandlers[link->name()]->setLink(link);
m_pairingHandlers[link->name()]->setDeviceLink(link);
connect(link, SIGNAL(destroyed(QObject*)), m_pairingHandlers[link->name()], SLOT(linkDestroyed(QObject*)));
}
......@@ -320,7 +321,7 @@ bool Device::sendPackage(NetworkPackage& np)
{
if (np.type() != PACKAGE_TYPE_PAIR && isPaired()) {
Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
if (dl->sendPackageEncrypted(m_publicKey, np)) return true;
if (dl->sendPackageEncrypted(np)) return true;
}
} else {
//Maybe we could block here any package that is not an identity or a pairing package to prevent sending non encrypted data
......@@ -366,8 +367,6 @@ void Device::rejectPairing()
{
qCDebug(KDECONNECT_CORE) << "Rejected pairing";
m_pairStatus = PairingHandler::NotPaired;
Q_FOREACH(PairingHandler* ph, m_pairingHandlers.values()) {
ph->rejectPairing();
}
......@@ -387,7 +386,8 @@ void Device::acceptPairing()
}
void Device::isPaired() {
bool Device::isPaired() const
{
Q_FOREACH(PairingHandler* ph, m_pairingHandlers) {
if (ph->isPaired()) return true;
}
......@@ -466,9 +466,9 @@ void Device::setName(const QString &name)
}
}
Device::PairStatus Device::pairStatus() const
PairingHandler::PairStatus Device::pairStatus() const
{
return m_pairStatus;
return isPaired()? PairingHandler::Paired : PairingHandler::NotPaired;
}
KdeConnectPlugin* Device::plugin(const QString& pluginName) const
......@@ -499,17 +499,17 @@ QString Device::encryptionInfo() const
{
QString result;
QByteArray myCertificate = KdeConnectConfig::instance()->certificate().toDer();
QString myCertificate = QString::fromLatin1(KdeConnectConfig::instance()->certificate().toDer());
for (int i=2 ; i<myCertificate.size() ; i+=3) {
myCertificate.insert(i, ':'); // Improve readability
}
result += i18n("SHA1 fingerprint of your device certificate is : ") + myCertificate + endl;
result += i18n("SHA1 fingerprint of your device certificate is: ") + myCertificate + "\n";
QString remoteCertificate = KdeConnectConfig::instance()->getDeviceProperty(id(), "certificate");
for (int i=2 ; i<remoteCertificate.size() ; i+=3) {
remoteCertificate.insert(i, ':'); // Improve readability
}
result += i18n("SHA1 fingerprint of remote device certificate is : ") << remoteCertificate << endl;
result += i18n("SHA1 fingerprint of remote device certificate is: ") + remoteCertificate + "\n";
return result;
}
......
......@@ -83,7 +83,7 @@ public:
QString iconName() const;
QString statusIconName() const;
QStringList unsupportedPlugins() const { return m_unsupportedPlugins; }
QString encryptionInfo() const;
Q_SCRIPTABLE QString encryptionInfo() const;
//Add and remove links
void addLink(const NetworkPackage& identityPackage, DeviceLink*);
......
......@@ -286,7 +286,7 @@ void KdeConnectKcm::pairingChanged(bool paired)
kcmUi->pair_button->setVisible(!paired);
kcmUi->unpair_button->setVisible(paired);
kcmUi->progressBar->setVisible(senderDevice->pairRequested());
kcmUi->progressBar->setVisible(senderDevice->isPairRequested());
kcmUi->ping_button->setVisible(paired);
kcmUi->status_label->setText(paired ? i18n("(paired)") : i18n("(unpaired)"));
}
......
......@@ -18,6 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../core/device.h"
#include "../core/backends/lan/lanlinkprovider.h"
#include "../core/kdeconnectconfig.h"
......@@ -68,15 +69,8 @@ void DeviceTest::testPairedDevice()
QCOMPARE(device.name(), deviceName);
QCOMPARE(device.type(), deviceType);
QVERIFY2(!device.publicKey().isNull(), "Public key for device is null");
QCOMPARE(device.publicKey(), kcc->publicKey());
QVERIFY2(device.certificate().isNull(), "Certificate should be null before initialisation");
// TODO : Set certificate via identity package
QCOMPARE(device.isPaired(), true);
QCOMPARE(device.pairRequested(), false);
QCOMPARE(device.isPairRequested(), false);
QCOMPARE(device.isReachable(), false);
......@@ -112,11 +106,8 @@ void DeviceTest::testUnpairedDevice()
QCOMPARE(device.name(), deviceName);
QCOMPARE(device.type(), deviceType);
QVERIFY2(device.publicKey().isNull(), "Public key for unpaired device should be null");
QVERIFY2(device.certificate().isNull(), "Certificate for unpaired device should be null");
QCOMPARE(device.isPaired(), false);
QCOMPARE(device.pairRequested(), false);
QCOMPARE(device.isPairRequested(), false);
QCOMPARE(device.isReachable(), true);
QCOMPARE(device.availableLinks().contains(linkProvider.name()), true);
......
......@@ -34,9 +34,9 @@ Q_OBJECT
private Q_SLOTS:
void initTestCase();
void addTrustedDevice();
/*
void remoteCertificateTest();
*/
void removeTrustedDevice();
private:
......@@ -46,13 +46,6 @@ private:
void KdeConnectConfigTest::initTestCase()
{
kcc = KdeConnectConfig::instance();
QVERIFY2(!kcc->publicKey().isNull(), "Public key not generated, is null");
QVERIFY2(!kcc->privateKey().isNull(), "Private key not generated, is null");
QVERIFY2(!kcc->certificate().isNull(), "Certificate not generated, is null");
QVERIFY2(QFile::exists(kcc->privateKeyPath()), "Private key file does not exists, private key not saved properly");
QVERIFY2(QFile::exists(kcc->certificatePath()), "Certificate file does not exists, certificate not saved properly");
}
void KdeConnectConfigTest::addTrustedDevice()
......@@ -63,6 +56,7 @@ void KdeConnectConfigTest::addTrustedDevice()
QCOMPARE(devInfo.deviceType, QString("phone"));
}
/*
// This checks whether certificate is generated correctly and stored correctly or not
void KdeConnectConfigTest::remoteCertificateTest()
{
......@@ -84,6 +78,7 @@ void KdeConnectConfigTest::remoteCertificateTest()
QCOMPARE(devCertificate.subjectInfo(QSslCertificate::OrganizationalUnitName).first(), QString("Kde connect"));
}
*/
void KdeConnectConfigTest::removeTrustedDevice()
......
......@@ -29,6 +29,7 @@
#include <QAbstractSocket>
#include <QSslSocket>
#include <QtTest>
#include <QSslKey>
#include <QUdpSocket>
/*
......@@ -322,11 +323,10 @@ QSslCertificate LanLinkProviderTest::generateCertificate(QString& commonName, QC
return certificate;
}
void LanLinkProviderTest::setSocketAttributes(QSslSocket *socket) {
void LanLinkProviderTest::setSocketAttributes(QSslSocket *socket)
{
socket->setPrivateKey(QSslKey(privateKey.toPEM().toLatin1(), QSsl::Rsa));
socket->setLocalCertificate(certificate);
}
void LanLinkProviderTest::addTrustedDevice()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment