[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdeconnect-kde/sslrefactor] /: Merge branch 'master' into sslmaster
From:       Albert Vaca <albertvaka () gmail ! com>
Date:       2015-11-30 18:36:31
Message-ID: E1a3TJP-0004so-LI () scm ! kde ! org
[Download RAW message or body]

Git commit 30d2dd991b249118832382dd3564a7050efcc3de by Albert Vaca.
Committed on 30/11/2015 at 11:40.
Pushed by albertvaka into branch 'sslrefactor'.

Merge branch 'master' into sslmaster

M  +35   -7    cli/kdeconnect-cli.cpp
M  +28   -7    core/backends/lan/downloadjob.cpp
M  +4    -4    core/backends/lan/downloadjob.h
M  +2    -2    core/backends/lan/socketlinereader.cpp
M  +3    -2    core/backends/loopback/loopbackdevicelink.cpp
M  +2    -2    core/daemon.cpp
M  +1    -1    core/daemon.h
M  +25   -5    core/device.cpp
M  +10   -3    core/device.h
M  +7    -5    core/kdeconnectconfig.cpp
M  +6    -5    core/kdeconnectconfig.h
M  +2    -3    plugins/sftp/mounter.h
M  +3    -0    tests/CMakeLists.txt

http://commits.kde.org/kdeconnect-kde/30d2dd991b249118832382dd3564a7050efcc3de

diff --cc core/backends/lan/downloadjob.cpp
index f3e0276,b51ff6c..fd10103
--- a/core/backends/lan/downloadjob.cpp
+++ b/core/backends/lan/downloadjob.cpp
@@@ -18,47 -18,49 +18,69 @@@
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
  
 +#include <kdeconnectconfig.h>
  #include "downloadjob.h"
  
- DownloadJob::DownloadJob(QHostAddress address, QVariantMap transferInfo): KJob()
+ #include <core/core_debug.h>
+ 
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <netinet/tcp.h>
+ #include <netdb.h>
+ 
+ #include "lanlinkprovider.h"
+ 
+ DownloadJob::DownloadJob(const QHostAddress &address, const QVariantMap \
&transferInfo): KJob()  {
      mAddress = address;
      mPort = transferInfo["port"].toInt();
 -    mSocket = QSharedPointer<QTcpSocket>(new QTcpSocket());
 +    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()));
  +    }
  }
  
+ DownloadJob::~DownloadJob()
+ {
++
+ }
+ 
  void DownloadJob::start()
  {
-     //kDebug(kdeconnect_kded()) << "DownloadJob Start";
+     //TODO: Timeout?
+     connect(mSocket.data(), &QAbstractSocket::disconnected, this, \
&DownloadJob::done); +     connect(mSocket.data(), \
SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(done())); +     \
//connect(mSocket.data(), &QAbstractSocket::connected, [=](){ qDebug() << \
"Connected"; }); + 
 -    mSocket->connectToHost(mAddress, mPort, QIODevice::ReadOnly);
 +    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();
 +    }
-     connect(mSocket.data(), SIGNAL(disconnected()),
-             this, SLOT(disconnected()));
+ 
+     //mSocket->open(QIODevice::ReadOnly);
+ 
 -    //TODO: Implement payload encryption somehow (create an intermediate iodevice \
to encrypt the payload here?)  }
  
- void DownloadJob::disconnected()
+ void DownloadJob::done()
  {
-     //kDebug(kdeconnect_kded()) << "DownloadJob End";
+     if (mSocket->error()) {
+         qWarning(KDECONNECT_CORE) << mSocket->errorString();
+     }
      emitResult();
+     deleteLater();
  }
  
  QSharedPointer<QIODevice> DownloadJob::getPayload()
diff --cc core/backends/lan/downloadjob.h
index bd1d02f,ddc9c93..54ad86a
--- a/core/backends/lan/downloadjob.h
+++ b/core/backends/lan/downloadjob.h
@@@ -40,14 -40,12 +41,13 @@@ public
      QSharedPointer<QIODevice> getPayload();
  
  private:
 +    bool useSsl;
      QHostAddress mAddress;
      qint16 mPort;
 -    QSharedPointer<QTcpSocket> mSocket;
 +    QSharedPointer<QSslSocket> mSocket;
  
- 
  private Q_SLOTS:
-     void disconnected();
+     void done();
  
  };
  
diff --cc core/device.h
index 82ecd29,e692c44..c39c224
--- a/core/device.h
+++ b/core/device.h
@@@ -26,11 -26,11 +26,12 @@@
  #include <QVector>
  #include <QSet>
  #include <QSslKey>
 -#include <QTimer>
  #include <QtCrypto>
 +#include <QSslCertificate>
 +#include <QTimer>
  
  #include "networkpackage.h"
+ #include "backends/devicelink.h"
  
  class DeviceLink;
  class KdeConnectPlugin;
@@@ -49,8 -48,11 +50,9 @@@ class KDECONNECTCORE_EXPORT Devic
      Q_PROPERTY(bool isPaired READ isPaired NOTIFY pairingChanged)
      Q_PROPERTY(QStringList unsupportedPlugins READ unsupportedPlugins NOTIFY \
pluginsChanged)  
+ public:
      enum PairStatus {
          NotPaired,
 -        Requested,
 -        RequestedByPeer,
          Paired,
      };
  
@@@ -147,8 -139,14 +150,11 @@@ Q_SIGNALS
      QT_DEPRECATED Q_SCRIPTABLE void unpaired();
  
  private: //Methods
+     static DeviceType str2type(const QString &deviceType);
+     static QString type2str(DeviceType deviceType);
+ 
      void setName(const QString &name);
      QString iconForStatus(bool reachable, bool paired) const;
 -    void unpairInternal();
 -    void setAsPaired();
 -    bool sendOwnPublicKey();
  
  private: //Fields (TODO: dPointer!)
      const QString m_deviceId;
diff --cc core/kdeconnectconfig.cpp
index 8804353,7ad040d..ce62d5f
--- a/core/kdeconnectconfig.cpp
+++ b/core/kdeconnectconfig.cpp
@@@ -216,7 -171,7 +216,8 @@@ QStringList KdeConnectConfig::trustedDe
      return list;
  }
  
- void KdeConnectConfig::addTrustedDevice(QString id, QString name, QString type)
++
+ void KdeConnectConfig::addTrustedDevice(const QString &id, const QString &name, \
const QString &type, const QString &publicKey)  {
      d->config->beginGroup("trustedDevices");
      d->config->beginGroup(id);
@@@ -256,30 -211,7 +258,30 @@@ void KdeConnectConfig::removeTrustedDev
      //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)
+ QDir KdeConnectConfig::deviceConfigDir(const QString &deviceId)
  {
      QString deviceConfigPath = baseConfigDir().absoluteFilePath(deviceId);
      return QDir(deviceConfigPath);
diff --cc core/kdeconnectconfig.h
index c20d97c,76e25a4..8666eb2
--- a/core/kdeconnectconfig.h
+++ b/core/kdeconnectconfig.h
@@@ -61,12 -56,10 +61,13 @@@ public
       */
  
      QStringList trustedDevices(); //list of ids
-     void removeTrustedDevice(QString id);
-     void addTrustedDevice(QString id, QString name, QString type);
-     KdeConnectConfig::DeviceInfo getTrustedDevice(QString id);
+     void removeTrustedDevice(const QString &id);
+     void addTrustedDevice(const QString &id, const QString &name, const QString \
&type, const QString &publicKey); +     KdeConnectConfig::DeviceInfo \
getTrustedDevice(const 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 --cc tests/CMakeLists.txt
index 927cddb,d585d2b..f82e85d
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@@ -19,36 -17,5 +19,39 @@@ set(kdeconnect_librarie
  ecm_add_test(pluginloadtest.cpp LINK_LIBRARIES ${kdeconnect_libraries})
  ecm_add_test(sendfiletest.cpp LINK_LIBRARIES ${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(downloadjobtest.cpp ../core/backends/lan/downloadjob.cpp TEST_NAME \
downloadjobtest 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})  +
 +set(testsslsocketlinereader_sources
 +    ../core/backends/lan/server.cpp
 +    ../core/backends/lan/socketlinereader.cpp
 +)
 +ecm_add_test(testsslsocketlinereader.cpp ${testsslsocketlinereader_sources} \
TEST_NAME testsslsocketlinereader LINK_LIBRARIES ${kdeconnect_libraries})  +
 +set(kdeconnectconfigtest_sources
 +    ../core/backends/pairinghandler.cpp
 +    ../core/dbushelper.cpp
 +    ../core/device.cpp
 +    ../core/pluginloader.cpp
 +)
 +ecm_add_test(kdeconnectconfigtest.cpp ${kdeconnectconfigtest_sources} TEST_NAME \
kdeconnectconfgtest LINK_LIBRARIES ${kdeconnect_libraries})  +
 +set(lanlinkprovidertest_sources
 +    ../core/backends/devicelink.cpp
 +    ../core/backends/lan/downloadjob.cpp
 +    ../core/backends/lan/landevicelink.cpp
 +    ../core/backends/lan/lanlinkprovider.cpp
 +    ../core/backends/lan/lanpairinghandler.cpp
 +    ../core/backends/lan/server.cpp
 +    ../core/backends/lan/socketlinereader.cpp
 +    ../core/backends/lan/uploadjob.cpp
 +    ../core/backends/linkprovider.cpp
 +    ../core/backends/pairinghandler.cpp
 +    ../core/device.cpp
 +    ../core/pluginloader.cpp
 +)
 +ecm_add_test(lanlinkprovidertest.cpp  ${lanlinkprovidertest_sources}  TEST_NAME \
lanlinkprovidertest LINK_LIBRARIES ${kdeconnect_libraries})  +
 +ecm_add_test(devicetest.cpp ${lanlinkprovidertest_sources} TEST_NAME devicetest \
LINK_LIBRARIES ${kdeconnect_libraries}) ++
++ecm_add_test(downloadjobtest.cpp ../core/backends/lan/downloadjob.cpp TEST_NAME \
downloadjobtest LINK_LIBRARIES ${kdeconnect_libraries})


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic