From aa4b825809ba941d9f997a1aed26acd88a81270b Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 27 Sep 2021 18:23:27 +0200 Subject: [PATCH] Ssh: Use FilePath for SshConnectionParameters::privateKeyFile Change-Id: Ifaf97cc744f80e1fa0f4000aabf83671b2ffd972 Reviewed-by: Qt CI Bot Reviewed-by: Christian Kandeler --- src/libs/ssh/sshconnection.cpp | 2 +- src/libs/ssh/sshconnection.h | 7 +++---- src/plugins/projectexplorer/devicesupport/idevice.cpp | 5 +++-- src/plugins/projectexplorer/kitinformation.cpp | 4 ++-- .../remotelinux/genericlinuxdeviceconfigurationwidget.cpp | 4 ++-- .../genericlinuxdeviceconfigurationwizardpages.cpp | 2 +- src/plugins/remotelinux/publickeydeploymentdialog.cpp | 2 +- tests/auto/ssh/tst_ssh.cpp | 4 ++-- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/libs/ssh/sshconnection.cpp b/src/libs/ssh/sshconnection.cpp index df548099917..5b1dc86d7d3 100644 --- a/src/libs/ssh/sshconnection.cpp +++ b/src/libs/ssh/sshconnection.cpp @@ -130,7 +130,7 @@ struct SshConnection::SshConnectionPrivate SshConnectionParameters::AuthenticationTypeSpecificKey; if (keyOnly) { args << "-o" << "IdentitiesOnly=yes"; - args << "-i" << connParams.privateKeyFile; + args << "-i" << connParams.privateKeyFile.path(); } if (keyOnly || SshSettings::askpassFilePath().isEmpty()) args << "-o" << "BatchMode=yes"; diff --git a/src/libs/ssh/sshconnection.h b/src/libs/ssh/sshconnection.h index 2778be02e08..cecd9999753 100644 --- a/src/libs/ssh/sshconnection.h +++ b/src/libs/ssh/sshconnection.h @@ -28,20 +28,19 @@ #include "sftpdefs.h" #include "ssh_global.h" +#include #include #include #include +#include #include #include #include -#include #include #include -namespace Utils { class FilePath; } - namespace QSsh { class SshRemoteProcess; @@ -69,7 +68,7 @@ public: void setUserName(const QString &name) { url.setUserName(name); } QUrl url; - QString privateKeyFile; + Utils::FilePath privateKeyFile; QString x11DisplayName; int timeout = 0; // In seconds. AuthenticationType authenticationType = AuthenticationTypeAll; diff --git a/src/plugins/projectexplorer/devicesupport/idevice.cpp b/src/plugins/projectexplorer/devicesupport/idevice.cpp index 03f7e8b281c..3f03478dba7 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.cpp +++ b/src/plugins/projectexplorer/devicesupport/idevice.cpp @@ -625,7 +625,8 @@ void IDevice::fromMap(const QVariantMap &map) ? QSsh::SshConnectionParameters::AuthenticationTypeAll : static_cast(storedAuthType); - d->sshParameters.privateKeyFile = map.value(QLatin1String(KeyFileKey), defaultPrivateKeyFilePath()).toString(); + d->sshParameters.privateKeyFile = + FilePath::fromVariant(map.value(QLatin1String(KeyFileKey), defaultPrivateKeyFilePath())); d->sshParameters.timeout = map.value(QLatin1String(TimeoutKey), DefaultTimeout).toInt(); d->sshParameters.hostKeyCheckingMode = static_cast (map.value(QLatin1String(HostKeyCheckingKey), QSsh::SshHostKeyCheckingNone).toInt()); @@ -661,7 +662,7 @@ QVariantMap IDevice::toMap() const map.insert(QLatin1String(SshPortKey), d->sshParameters.port()); map.insert(QLatin1String(UserNameKey), d->sshParameters.userName()); map.insert(QLatin1String(AuthKey), d->sshParameters.authenticationType); - map.insert(QLatin1String(KeyFileKey), d->sshParameters.privateKeyFile); + map.insert(QLatin1String(KeyFileKey), d->sshParameters.privateKeyFile.toVariant()); map.insert(QLatin1String(TimeoutKey), d->sshParameters.timeout); map.insert(QLatin1String(HostKeyCheckingKey), d->sshParameters.hostKeyCheckingMode); diff --git a/src/plugins/projectexplorer/kitinformation.cpp b/src/plugins/projectexplorer/kitinformation.cpp index eb02496a326..4e14bbc6f53 100644 --- a/src/plugins/projectexplorer/kitinformation.cpp +++ b/src/plugins/projectexplorer/kitinformation.cpp @@ -1067,7 +1067,7 @@ void DeviceKitAspect::addToMacroExpander(Kit *kit, Utils::MacroExpander *expande expander->registerVariable("Device:KeyFile", tr("Private key file"), [kit]() -> QString { const IDevice::ConstPtr device = DeviceKitAspect::device(kit); - return device ? device->sshParameters().privateKeyFile : QString(); + return device ? device->sshParameters().privateKeyFile.toString() : QString(); }); expander->registerVariable("Device:Name", tr("Device name"), [kit]() -> QString { @@ -1294,7 +1294,7 @@ void BuildDeviceKitAspect::addToMacroExpander(Kit *kit, Utils::MacroExpander *ex expander->registerVariable("BuildDevice:KeyFile", tr("Build private key file"), [kit]() -> QString { const IDevice::ConstPtr device = BuildDeviceKitAspect::device(kit); - return device ? device->sshParameters().privateKeyFile : QString(); + return device ? device->sshParameters().privateKeyFile.toString() : QString(); }); expander->registerVariable("BuildDevice:Name", tr("Build device name"), [kit]() -> QString { diff --git a/src/plugins/remotelinux/genericlinuxdeviceconfigurationwidget.cpp b/src/plugins/remotelinux/genericlinuxdeviceconfigurationwidget.cpp index 5550368430e..7187799790f 100644 --- a/src/plugins/remotelinux/genericlinuxdeviceconfigurationwidget.cpp +++ b/src/plugins/remotelinux/genericlinuxdeviceconfigurationwidget.cpp @@ -123,7 +123,7 @@ void GenericLinuxDeviceConfigurationWidget::userNameEditingFinished() void GenericLinuxDeviceConfigurationWidget::keyFileEditingFinished() { SshConnectionParameters sshParams = device()->sshParameters(); - sshParams.privateKeyFile = m_ui->keyFileLineEdit->filePath().toString(); + sshParams.privateKeyFile = m_ui->keyFileLineEdit->filePath(); device()->setSshParameters(sshParams); } @@ -211,7 +211,7 @@ void GenericLinuxDeviceConfigurationWidget::initGui() m_ui->portsLineEdit->setText(device()->freePorts().toString()); m_ui->timeoutSpinBox->setValue(sshParams.timeout); m_ui->userLineEdit->setText(sshParams.userName()); - m_ui->keyFileLineEdit->setPath(sshParams.privateKeyFile); + m_ui->keyFileLineEdit->setFilePath(sshParams.privateKeyFile); m_ui->gdbServerLineEdit->setText(device()->debugServerPath().toString()); updatePortsWarningLabel(); } diff --git a/src/plugins/remotelinux/genericlinuxdeviceconfigurationwizardpages.cpp b/src/plugins/remotelinux/genericlinuxdeviceconfigurationwizardpages.cpp index 173e6c33468..be6b6743e2b 100644 --- a/src/plugins/remotelinux/genericlinuxdeviceconfigurationwizardpages.cpp +++ b/src/plugins/remotelinux/genericlinuxdeviceconfigurationwizardpages.cpp @@ -235,7 +235,7 @@ bool GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::validatePage() if (!d->defaultKeys().contains(d->keyFileChooser.filePath().toString())) { SshConnectionParameters sshParams = d->device->sshParameters(); sshParams.authenticationType = SshConnectionParameters::AuthenticationTypeSpecificKey; - sshParams.privateKeyFile = d->keyFileChooser.filePath().toString(); + sshParams.privateKeyFile = d->keyFileChooser.filePath(); d->device->setSshParameters(sshParams); } return true; diff --git a/src/plugins/remotelinux/publickeydeploymentdialog.cpp b/src/plugins/remotelinux/publickeydeploymentdialog.cpp index 76e0add6db2..cdec2239a20 100644 --- a/src/plugins/remotelinux/publickeydeploymentdialog.cpp +++ b/src/plugins/remotelinux/publickeydeploymentdialog.cpp @@ -49,7 +49,7 @@ using namespace Internal; PublicKeyDeploymentDialog *PublicKeyDeploymentDialog::createDialog( const IDevice::ConstPtr &deviceConfig, QWidget *parent) { - const FilePath dir = FilePath::fromString(deviceConfig->sshParameters().privateKeyFile).parentDir(); + const FilePath dir = deviceConfig->sshParameters().privateKeyFile.parentDir(); const FilePath publicKeyFileName = FileUtils::getOpenFilePath(nullptr, tr("Choose Public Key File"), dir, tr("Public Key Files (*.pub);;All Files (*)")); diff --git a/tests/auto/ssh/tst_ssh.cpp b/tests/auto/ssh/tst_ssh.cpp index 597d035e509..d1d53adf7d3 100644 --- a/tests/auto/ssh/tst_ssh.cpp +++ b/tests/auto/ssh/tst_ssh.cpp @@ -95,7 +95,7 @@ static SshConnectionParameters getParameters() params.setPort(getPortFromEnvironment()); params.setUserName(getUserFromEnvironment()); params.timeout = 10; - params.privateKeyFile = getKeyFileFromEnvironment(); + params.privateKeyFile = Utils::FilePath::fromUserInput(getKeyFileFromEnvironment()); params.authenticationType = !params.privateKeyFile.isEmpty() ? SshConnectionParameters::AuthenticationTypeSpecificKey : SshConnectionParameters::AuthenticationTypeAll; @@ -185,7 +185,7 @@ void tst_Ssh::errorHandling() params.setUserName(user); params.timeout = 3; params.authenticationType = authType; - params.privateKeyFile = keyFile; + params.privateKeyFile = Utils::FilePath::fromString(keyFile); SshConnection connection(params); QEventLoop loop; bool disconnected = false;