/** * Copyright 2015 Vineet Garg * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include "lanpairinghandler.h" #include "networkpackagetypes.h" LanPairingHandler::LanPairingHandler() { } void LanPairingHandler::createPairPackage(NetworkPackage& np) { np.set("pair", true); np.set("publicKey", KdeConnectConfig::instance()->publicKey().toPEM()); } bool LanPairingHandler::packageReceived(Device *device,const NetworkPackage& np) { //Retrieve their public key QString keyString = np.get("publicKey"); device->setPublicKey(QCA::RSAPublicKey::fromPEM(keyString)); if (device->publicKey().isNull()) { return false; } return true; } bool LanPairingHandler::requestPairing(Device *device) { NetworkPackage np(PACKAGE_TYPE_PAIR); createPairPackage(np); bool success = device->sendPackage(np); return success; } bool LanPairingHandler::acceptPairing(Device *device) { NetworkPackage np(PACKAGE_TYPE_PAIR); createPairPackage(np); bool success = device->sendPackage(np); return success; } void LanPairingHandler::rejectPairing(Device *device) { // TODO : check status of reject pairing NetworkPackage np(PACKAGE_TYPE_PAIR); np.set("pair", false); device->sendPackage(np); } void LanPairingHandler::pairingDone(Device *device) { // 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(), "certificate", QString(device->certificate().toPem())); } void LanPairingHandler::unpair(Device *device) { NetworkPackage np(PACKAGE_TYPE_PAIR); np.set("pair", false); bool success = device->sendPackage(np); Q_UNUSED(success); }