Do not store certificate and key in landevicelink

The socket already stores the certificate, and the public key is only used
in the sftp plugin, so it should be moved there or dropped.
This commit is contained in:
Albert Vaca 2015-12-17 07:45:53 -08:00
parent 4c84499e6a
commit 918bb82ffa
5 changed files with 5 additions and 44 deletions

View file

@ -53,17 +53,8 @@ void LanDeviceLink::reset(QSslSocket* socket, DeviceLink::ConnectionStarted conn
setConnectionSource(connectionSource);
if (m_certificate.isNull()) {
QString certString = KdeConnectConfig::instance()->getDeviceProperty(deviceId(), "certificate");
m_certificate = QSslCertificate(certString.toLatin1());
QString keyString = KdeConnectConfig::instance()->getDeviceProperty(deviceId(), "publicKey");
m_publicKey = QCA::PublicKey::fromPEM(keyString.toLatin1());
DeviceLink::setPairStatus(m_certificate.isNull()? PairStatus::NotPaired : PairStatus::Paired);
}
DeviceLink::setPairStatus(certString.isEmpty()? PairStatus::NotPaired : PairStatus::Paired);
}
QString LanDeviceLink::name()
@ -145,19 +136,10 @@ void LanDeviceLink::setPairStatus(PairStatus status)
{
if (status == Paired) {
Q_ASSERT(KdeConnectConfig::instance()->trustedDevices().contains(deviceId()));
Q_ASSERT(!m_certificate.isNull());
Q_ASSERT(!m_publicKey.isNull());
KdeConnectConfig::instance()->setDeviceProperty(deviceId(), "certificate", m_certificate.toPem());
KdeConnectConfig::instance()->setDeviceProperty(deviceId(), "publicKey", m_publicKey.toPEM());
Q_ASSERT(!mSocketLineReader->peerCertificate().isNull());
KdeConnectConfig::instance()->setDeviceProperty(deviceId(), "certificate", mSocketLineReader->peerCertificate().toPem());
}
DeviceLink::setPairStatus(status);
}
void LanDeviceLink::setCertificate(QSslCertificate certificate, QCA::PublicKey publicKey)
{
Q_ASSERT(!m_certificate.isNull());
Q_ASSERT(!m_publicKey.isNull());
m_certificate = certificate;
m_publicKey = publicKey;
}

View file

@ -42,15 +42,11 @@ public:
virtual QString name() Q_DECL_OVERRIDE;
bool sendPackage(NetworkPackage& np) override;
bool sendPackageEncrypted(NetworkPackage& np) override;
UploadJob* sendPayload(NetworkPackage& np);
virtual void userRequestsPair() override;
virtual void userRequestsUnpair() override;
void setCertificate(QSslCertificate certificate, QCA::PublicKey publicKey);
QSslCertificate certificate() { return m_certificate; }
virtual void setPairStatus(PairStatus status) override;
private Q_SLOTS:
@ -58,9 +54,6 @@ private Q_SLOTS:
private:
SocketLineReader* mSocketLineReader;
QCA::PublicKey m_publicKey;
QSslCertificate m_certificate;
};
#endif

View file

@ -264,8 +264,6 @@ void LanLinkProvider::encrypted()
const QString& deviceId = receivedPackage->get<QString>("deviceId");
//qCDebug(KDECONNECT_CORE) << "Connected" << socket->isWritable();
receivedPackage->set("certificate", socket->peerCertificate().toPem());
addLink(deviceId, socket, receivedPackage, DeviceLink::Remotely);
// Copied from connected slot, now delete received package

View file

@ -59,19 +59,6 @@ void LanPairingHandler::packageReceived(const NetworkPackage& np)
if (wantsPair) {
QString keyString = np.get<QString>("publicKey");
QString certificateString = np.get<QByteArray>("certificate");
QCA::PublicKey publicKey = QCA::PublicKey::fromPEM(keyString);
QSslCertificate certificate(keyString.toLatin1());
if (certificate.isNull()) {
if (isPairRequested()) {
setInternalPairStatus(NotPaired);
}
Q_EMIT pairingError(i18n("Received incorrect certificate"));
return;
}
qobject_cast<LanDeviceLink*>(deviceLink())->setCertificate(certificate, publicKey);
if (isPairRequested()) { //We started pairing
qCDebug(KDECONNECT_CORE) << "Pair answer";

View file

@ -42,6 +42,7 @@ public:
QByteArray readLine() { return mPackages.dequeue(); }
qint64 write(const QByteArray& data) { return mSocket->write(data); }
QHostAddress peerAddress() const { return mSocket->peerAddress(); }
QSslCertificate peerCertificate() const { return mSocket->peerCertificate(); }
qint64 bytesAvailable() const { return mPackages.size(); }
Q_SIGNALS: