From c45636208870453d94c02dd67c64bec935abd9d5 Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Mon, 19 Aug 2024 00:45:12 +0200 Subject: [PATCH] Use key auth for SFTP on Windows --- plugins/sftp/sftpplugin-win.cpp | 14 +++++--------- plugins/sftp/sftpplugin-win.h | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/plugins/sftp/sftpplugin-win.cpp b/plugins/sftp/sftpplugin-win.cpp index 2f0d8ebef..a4313bd3d 100644 --- a/plugins/sftp/sftpplugin-win.cpp +++ b/plugins/sftp/sftpplugin-win.cpp @@ -7,14 +7,14 @@ #include #include -#include +#include #include #include -#include #include #include +#include "kdeconnectconfig.h" #include "plugin_sftp_debug.h" K_PLUGIN_CLASS_WITH_JSON(SftpPlugin, "kdeconnect_sftp.json") @@ -63,21 +63,17 @@ void SftpPlugin::receivePacket(const NetworkPacket &np) path += QChar::fromLatin1('/'); } - QString url_string = QStringLiteral("sftp://%1:%2@%3:%4%5") + QString url_string = QStringLiteral("sftp://%1;x-publickeyfile=%2@%3:%4%5") .arg(np.get(QStringLiteral("user")), - np.get(QStringLiteral("password")), + QLatin1StringView(QUrl::toPercentEncoding(KdeConnectConfig::instance().privateKeyPath())), np.get(QStringLiteral("ip")), np.get(QStringLiteral("port")), path); - static QRegularExpression uriRegex(QStringLiteral("^sftp://kdeconnect:\\w+@\\d+.\\d+.\\d+.\\d+:17[3-6][0-9]/$")); - if (!uriRegex.match(url_string).hasMatch()) { - qCWarning(KDECONNECT_PLUGIN_SFTP) << "Invalid URL invoked. If the problem persists, contact the developers."; - } if (!QDesktopServices::openUrl(QUrl(url_string))) { QMessageBox::critical(nullptr, i18n("KDE Connect"), - i18n("Cannot handle SFTP protocol. Apologies for the inconvenience"), + i18n("Couldn't find a program to handle sftp:// URLs, please install WinSCP or another SFTP client."), QMessageBox::Abort, QMessageBox::Abort); } diff --git a/plugins/sftp/sftpplugin-win.h b/plugins/sftp/sftpplugin-win.h index 61c2f6385..18490f735 100644 --- a/plugins/sftp/sftpplugin-win.h +++ b/plugins/sftp/sftpplugin-win.h @@ -12,7 +12,7 @@ #define PACKET_TYPE_SFTP_REQUEST QStringLiteral("kdeconnect.sftp.request") static const QSet expectedFields = QSet() - << QStringLiteral("ip") << QStringLiteral("port") << QStringLiteral("user") << QStringLiteral("password") << QStringLiteral("path"); + << QStringLiteral("ip") << QStringLiteral("port") << QStringLiteral("user") << QStringLiteral("path"); ; class SftpPlugin : public KdeConnectPlugin {