diff options
author | hjk <hjk@qt.io> | 2017-12-19 12:45:46 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2017-12-19 14:19:31 +0000 |
commit | 21c66ce5fdaf9fcf91b4ba72adba691fc64be4a3 (patch) | |
tree | 06c49f98300874a2b40bfa7800373679804a217b /src/libs/ssh | |
parent | b64c1a96b8b9218a903c7993d58c64f8ca387243 (diff) |
Combine some SshConnectionParameter members
Combine host, port, username and password into a 'url' member and
add some convenience accessors.
Change-Id: Iddc26ff00dad1285c96aa56f196dbc4febe8e974
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/libs/ssh')
-rw-r--r-- | src/libs/ssh/sshconnection.cpp | 26 | ||||
-rw-r--r-- | src/libs/ssh/sshconnection.h | 15 | ||||
-rw-r--r-- | src/libs/ssh/sshkeyexchange.cpp | 8 |
3 files changed, 28 insertions, 21 deletions
diff --git a/src/libs/ssh/sshconnection.cpp b/src/libs/ssh/sshconnection.cpp index d6d5b5cf059..e1f98da06dc 100644 --- a/src/libs/ssh/sshconnection.cpp +++ b/src/libs/ssh/sshconnection.cpp @@ -63,21 +63,21 @@ namespace QSsh { const QByteArray ClientId("SSH-2.0-QtCreator\r\n"); SshConnectionParameters::SshConnectionParameters() : - timeout(0), authenticationType(AuthenticationTypePublicKey), port(0), + timeout(0), authenticationType(AuthenticationTypePublicKey), hostKeyCheckingMode(SshHostKeyCheckingNone) { + url.setPort(0); options |= SshIgnoreDefaultProxy; options |= SshEnableStrictConformanceChecks; } static inline bool equals(const SshConnectionParameters &p1, const SshConnectionParameters &p2) { - return p1.host == p2.host && p1.userName == p2.userName + return p1.url == p2.url && p1.authenticationType == p2.authenticationType - && (p1.authenticationType == SshConnectionParameters::AuthenticationTypePassword ? - p1.password == p2.password : p1.privateKeyFile == p2.privateKeyFile) + && p1.privateKeyFile == p2.privateKeyFile && p1.hostKeyCheckingMode == p2.hostKeyCheckingMode - && p1.timeout == p2.timeout && p1.port == p2.port; + && p1.timeout == p2.timeout; } bool operator==(const SshConnectionParameters &p1, const SshConnectionParameters &p2) @@ -521,11 +521,11 @@ void SshConnectionPrivate::handleServiceAcceptPacket() m_triedAllPasswordBasedMethods = false; // Fall-through. case SshConnectionParameters::AuthenticationTypePassword: - m_sendFacility.sendUserAuthByPasswordRequestPacket(m_connParams.userName.toUtf8(), - SshCapabilities::SshConnectionService, m_connParams.password.toUtf8()); + m_sendFacility.sendUserAuthByPasswordRequestPacket(m_connParams.userName().toUtf8(), + SshCapabilities::SshConnectionService, m_connParams.password().toUtf8()); break; case SshConnectionParameters::AuthenticationTypeKeyboardInteractive: - m_sendFacility.sendUserAuthByKeyboardInteractiveRequestPacket(m_connParams.userName.toUtf8(), + m_sendFacility.sendUserAuthByKeyboardInteractiveRequestPacket(m_connParams.userName().toUtf8(), SshCapabilities::SshConnectionService); break; case SshConnectionParameters::AuthenticationTypePublicKey: @@ -575,7 +575,7 @@ void SshConnectionPrivate::handleUserAuthInfoRequestPacket() // Not very interactive, admittedly, but we don't want to be for now. for (int i = 0; i < requestPacket.prompts.count(); ++i) - responses << m_connParams.password; + responses << m_connParams.password(); m_sendFacility.sendUserAuthInfoResponsePacket(responses); } @@ -626,7 +626,7 @@ void SshConnectionPrivate::handleUserAuthFailurePacket() && !m_triedAllPasswordBasedMethods) { m_triedAllPasswordBasedMethods = true; m_sendFacility.sendUserAuthByKeyboardInteractiveRequestPacket( - m_connParams.userName.toUtf8(), + m_connParams.userName().toUtf8(), SshCapabilities::SshConnectionService); return; } @@ -840,7 +840,7 @@ void SshConnectionPrivate::tryAllAgentKeys() qCDebug(sshLog) << "trying authentication with" << keys.count() << "public keys received from agent"; foreach (const QByteArray &key, keys) { - m_sendFacility.sendQueryPublicKeyPacket(m_connParams.userName.toUtf8(), + m_sendFacility.sendQueryPublicKeyPacket(m_connParams.userName().toUtf8(), SshCapabilities::SshConnectionService, key); m_pendingKeyChecks.enqueue(key); } @@ -860,7 +860,7 @@ void SshConnectionPrivate::authenticateWithPublicKey() signature = m_agentSignature; } - m_sendFacility.sendUserAuthByPublicKeyRequestPacket(m_connParams.userName.toUtf8(), + m_sendFacility.sendUserAuthByPublicKeyRequestPacket(m_connParams.userName().toUtf8(), SshCapabilities::SshConnectionService, key, signature); } @@ -929,7 +929,7 @@ void SshConnectionPrivate::connectToHost() m_state = SocketConnecting; m_keyExchangeState = NoKeyExchange; m_timeoutTimer.start(); - m_socket->connectToHost(m_connParams.host, m_connParams.port); + m_socket->connectToHost(m_connParams.host(), m_connParams.port()); } void SshConnectionPrivate::closeConnection(SshErrorCode sshError, diff --git a/src/libs/ssh/sshconnection.h b/src/libs/ssh/sshconnection.h index 0e90dce3f85..0fbbbcdf8a8 100644 --- a/src/libs/ssh/sshconnection.h +++ b/src/libs/ssh/sshconnection.h @@ -36,6 +36,7 @@ #include <QSharedPointer> #include <QString> #include <QHostAddress> +#include <QUrl> namespace QSsh { class SftpChannel; @@ -75,13 +76,19 @@ public: SshConnectionParameters(); - QString host; - QString userName; - QString password; + QString host() const { return url.host(); } + quint16 port() const { return url.port(); } + QString userName() const { return url.userName(); } + QString password() const { return url.password(); } + void setHost(const QString &host) { url.setHost(host); } + void setPort(int port) { url.setPort(port); } + void setUserName(const QString &name) { url.setUserName(name); } + void setPassword(const QString &password) { url.setPassword(password); } + + QUrl url; QString privateKeyFile; int timeout; // In seconds. AuthenticationType authenticationType; - quint16 port; SshConnectionOptions options; SshHostKeyCheckingMode hostKeyCheckingMode; SshHostKeyDatabasePtr hostKeyDatabase; diff --git a/src/libs/ssh/sshkeyexchange.cpp b/src/libs/ssh/sshkeyexchange.cpp index cdcb45556c5..f513454d456 100644 --- a/src/libs/ssh/sshkeyexchange.cpp +++ b/src/libs/ssh/sshkeyexchange.cpp @@ -237,7 +237,7 @@ void SshKeyExchange::checkHostKey(const QByteArray &hostKey) { if (m_connParams.hostKeyCheckingMode == SshHostKeyCheckingNone) { if (m_connParams.hostKeyDatabase) - m_connParams.hostKeyDatabase->insertHostKey(m_connParams.host, hostKey); + m_connParams.hostKeyDatabase->insertHostKey(m_connParams.host(), hostKey); return; } @@ -247,7 +247,7 @@ void SshKeyExchange::checkHostKey(const QByteArray &hostKey) "if host key checking is enabled.")); } - switch (m_connParams.hostKeyDatabase->matchHostKey(m_connParams.host, hostKey)) { + switch (m_connParams.hostKeyDatabase->matchHostKey(m_connParams.host(), hostKey)) { case SshHostKeyDatabase::KeyLookupMatch: return; // Nothing to do. case SshHostKeyDatabase::KeyLookupMismatch: @@ -259,14 +259,14 @@ void SshKeyExchange::checkHostKey(const QByteArray &hostKey) throwHostKeyException(); break; } - m_connParams.hostKeyDatabase->insertHostKey(m_connParams.host, hostKey); + m_connParams.hostKeyDatabase->insertHostKey(m_connParams.host(), hostKey); } void SshKeyExchange::throwHostKeyException() { throw SshServerException(SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE, "Host key changed", SSH_TR("Host key of machine \"%1\" has changed.") - .arg(m_connParams.host)); + .arg(m_connParams.host())); } } // namespace Internal |