forked from qt-creator/qt-creator
Ssh: Use FilePath for SshConnectionParameters::privateKeyFile
Change-Id: Ifaf97cc744f80e1fa0f4000aabf83671b2ffd972 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -130,7 +130,7 @@ struct SshConnection::SshConnectionPrivate
|
|||||||
SshConnectionParameters::AuthenticationTypeSpecificKey;
|
SshConnectionParameters::AuthenticationTypeSpecificKey;
|
||||||
if (keyOnly) {
|
if (keyOnly) {
|
||||||
args << "-o" << "IdentitiesOnly=yes";
|
args << "-o" << "IdentitiesOnly=yes";
|
||||||
args << "-i" << connParams.privateKeyFile;
|
args << "-i" << connParams.privateKeyFile.path();
|
||||||
}
|
}
|
||||||
if (keyOnly || SshSettings::askpassFilePath().isEmpty())
|
if (keyOnly || SshSettings::askpassFilePath().isEmpty())
|
||||||
args << "-o" << "BatchMode=yes";
|
args << "-o" << "BatchMode=yes";
|
||||||
|
|||||||
@@ -28,20 +28,19 @@
|
|||||||
#include "sftpdefs.h"
|
#include "sftpdefs.h"
|
||||||
#include "ssh_global.h"
|
#include "ssh_global.h"
|
||||||
|
|
||||||
|
#include <utils/filepath.h>
|
||||||
#include <utils/processutils.h>
|
#include <utils/processutils.h>
|
||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QFlags>
|
#include <QFlags>
|
||||||
|
#include <QHostAddress>
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QHostAddress>
|
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace Utils { class FilePath; }
|
|
||||||
|
|
||||||
namespace QSsh {
|
namespace QSsh {
|
||||||
class SshRemoteProcess;
|
class SshRemoteProcess;
|
||||||
|
|
||||||
@@ -69,7 +68,7 @@ public:
|
|||||||
void setUserName(const QString &name) { url.setUserName(name); }
|
void setUserName(const QString &name) { url.setUserName(name); }
|
||||||
|
|
||||||
QUrl url;
|
QUrl url;
|
||||||
QString privateKeyFile;
|
Utils::FilePath privateKeyFile;
|
||||||
QString x11DisplayName;
|
QString x11DisplayName;
|
||||||
int timeout = 0; // In seconds.
|
int timeout = 0; // In seconds.
|
||||||
AuthenticationType authenticationType = AuthenticationTypeAll;
|
AuthenticationType authenticationType = AuthenticationTypeAll;
|
||||||
|
|||||||
@@ -625,7 +625,8 @@ void IDevice::fromMap(const QVariantMap &map)
|
|||||||
? QSsh::SshConnectionParameters::AuthenticationTypeAll
|
? QSsh::SshConnectionParameters::AuthenticationTypeAll
|
||||||
: static_cast<AuthType>(storedAuthType);
|
: static_cast<AuthType>(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.timeout = map.value(QLatin1String(TimeoutKey), DefaultTimeout).toInt();
|
||||||
d->sshParameters.hostKeyCheckingMode = static_cast<QSsh::SshHostKeyCheckingMode>
|
d->sshParameters.hostKeyCheckingMode = static_cast<QSsh::SshHostKeyCheckingMode>
|
||||||
(map.value(QLatin1String(HostKeyCheckingKey), QSsh::SshHostKeyCheckingNone).toInt());
|
(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(SshPortKey), d->sshParameters.port());
|
||||||
map.insert(QLatin1String(UserNameKey), d->sshParameters.userName());
|
map.insert(QLatin1String(UserNameKey), d->sshParameters.userName());
|
||||||
map.insert(QLatin1String(AuthKey), d->sshParameters.authenticationType);
|
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(TimeoutKey), d->sshParameters.timeout);
|
||||||
map.insert(QLatin1String(HostKeyCheckingKey), d->sshParameters.hostKeyCheckingMode);
|
map.insert(QLatin1String(HostKeyCheckingKey), d->sshParameters.hostKeyCheckingMode);
|
||||||
|
|
||||||
|
|||||||
@@ -1067,7 +1067,7 @@ void DeviceKitAspect::addToMacroExpander(Kit *kit, Utils::MacroExpander *expande
|
|||||||
expander->registerVariable("Device:KeyFile", tr("Private key file"),
|
expander->registerVariable("Device:KeyFile", tr("Private key file"),
|
||||||
[kit]() -> QString {
|
[kit]() -> QString {
|
||||||
const IDevice::ConstPtr device = DeviceKitAspect::device(kit);
|
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"),
|
expander->registerVariable("Device:Name", tr("Device name"),
|
||||||
[kit]() -> QString {
|
[kit]() -> QString {
|
||||||
@@ -1294,7 +1294,7 @@ void BuildDeviceKitAspect::addToMacroExpander(Kit *kit, Utils::MacroExpander *ex
|
|||||||
expander->registerVariable("BuildDevice:KeyFile", tr("Build private key file"),
|
expander->registerVariable("BuildDevice:KeyFile", tr("Build private key file"),
|
||||||
[kit]() -> QString {
|
[kit]() -> QString {
|
||||||
const IDevice::ConstPtr device = BuildDeviceKitAspect::device(kit);
|
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"),
|
expander->registerVariable("BuildDevice:Name", tr("Build device name"),
|
||||||
[kit]() -> QString {
|
[kit]() -> QString {
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ void GenericLinuxDeviceConfigurationWidget::userNameEditingFinished()
|
|||||||
void GenericLinuxDeviceConfigurationWidget::keyFileEditingFinished()
|
void GenericLinuxDeviceConfigurationWidget::keyFileEditingFinished()
|
||||||
{
|
{
|
||||||
SshConnectionParameters sshParams = device()->sshParameters();
|
SshConnectionParameters sshParams = device()->sshParameters();
|
||||||
sshParams.privateKeyFile = m_ui->keyFileLineEdit->filePath().toString();
|
sshParams.privateKeyFile = m_ui->keyFileLineEdit->filePath();
|
||||||
device()->setSshParameters(sshParams);
|
device()->setSshParameters(sshParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,7 +211,7 @@ void GenericLinuxDeviceConfigurationWidget::initGui()
|
|||||||
m_ui->portsLineEdit->setText(device()->freePorts().toString());
|
m_ui->portsLineEdit->setText(device()->freePorts().toString());
|
||||||
m_ui->timeoutSpinBox->setValue(sshParams.timeout);
|
m_ui->timeoutSpinBox->setValue(sshParams.timeout);
|
||||||
m_ui->userLineEdit->setText(sshParams.userName());
|
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());
|
m_ui->gdbServerLineEdit->setText(device()->debugServerPath().toString());
|
||||||
updatePortsWarningLabel();
|
updatePortsWarningLabel();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ bool GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::validatePage()
|
|||||||
if (!d->defaultKeys().contains(d->keyFileChooser.filePath().toString())) {
|
if (!d->defaultKeys().contains(d->keyFileChooser.filePath().toString())) {
|
||||||
SshConnectionParameters sshParams = d->device->sshParameters();
|
SshConnectionParameters sshParams = d->device->sshParameters();
|
||||||
sshParams.authenticationType = SshConnectionParameters::AuthenticationTypeSpecificKey;
|
sshParams.authenticationType = SshConnectionParameters::AuthenticationTypeSpecificKey;
|
||||||
sshParams.privateKeyFile = d->keyFileChooser.filePath().toString();
|
sshParams.privateKeyFile = d->keyFileChooser.filePath();
|
||||||
d->device->setSshParameters(sshParams);
|
d->device->setSshParameters(sshParams);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ using namespace Internal;
|
|||||||
PublicKeyDeploymentDialog *PublicKeyDeploymentDialog::createDialog(
|
PublicKeyDeploymentDialog *PublicKeyDeploymentDialog::createDialog(
|
||||||
const IDevice::ConstPtr &deviceConfig, QWidget *parent)
|
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,
|
const FilePath publicKeyFileName = FileUtils::getOpenFilePath(nullptr,
|
||||||
tr("Choose Public Key File"), dir,
|
tr("Choose Public Key File"), dir,
|
||||||
tr("Public Key Files (*.pub);;All Files (*)"));
|
tr("Public Key Files (*.pub);;All Files (*)"));
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ static SshConnectionParameters getParameters()
|
|||||||
params.setPort(getPortFromEnvironment());
|
params.setPort(getPortFromEnvironment());
|
||||||
params.setUserName(getUserFromEnvironment());
|
params.setUserName(getUserFromEnvironment());
|
||||||
params.timeout = 10;
|
params.timeout = 10;
|
||||||
params.privateKeyFile = getKeyFileFromEnvironment();
|
params.privateKeyFile = Utils::FilePath::fromUserInput(getKeyFileFromEnvironment());
|
||||||
params.authenticationType = !params.privateKeyFile.isEmpty()
|
params.authenticationType = !params.privateKeyFile.isEmpty()
|
||||||
? SshConnectionParameters::AuthenticationTypeSpecificKey
|
? SshConnectionParameters::AuthenticationTypeSpecificKey
|
||||||
: SshConnectionParameters::AuthenticationTypeAll;
|
: SshConnectionParameters::AuthenticationTypeAll;
|
||||||
@@ -185,7 +185,7 @@ void tst_Ssh::errorHandling()
|
|||||||
params.setUserName(user);
|
params.setUserName(user);
|
||||||
params.timeout = 3;
|
params.timeout = 3;
|
||||||
params.authenticationType = authType;
|
params.authenticationType = authType;
|
||||||
params.privateKeyFile = keyFile;
|
params.privateKeyFile = Utils::FilePath::fromString(keyFile);
|
||||||
SshConnection connection(params);
|
SshConnection connection(params);
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
bool disconnected = false;
|
bool disconnected = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user