diff --git a/atest/login.robot b/atest/login.robot index b3bfdfdd8..2774db852 100644 --- a/atest/login.robot +++ b/atest/login.robot @@ -11,6 +11,7 @@ ${KEY} ${KEY DIR}${/}id_rsa ${INVALID USERNAME} invalidusername ${INVALID PASSWORD} invalidpassword ${INVALID KEY} ${KEY DIR}${/}id_rsa_invalid +${PASSPHRASE} ${EMPTY} *** Test Cases *** Login With Valid Username And Password @@ -25,6 +26,10 @@ Login With Public Key When Valid Username And Key [Setup] Open Connection ${HOST} prompt=${PROMPT} Login With Public Key ${KEY USERNAME} ${KEY} +Login With Public Key When Valid Credentials + [Setup] Open Connection ${HOST} prompt=${PROMPT} + Login With Public Key ${KEY USERNAME} ${KEY} ${PASSPHRASE} + Login With Public Key When Invalid Username Run Keyword And Expect Error Login with public key failed for user '${INVALID USERNAME}'. ... Login With Public Key ${INVALID USERNAME} ${KEY} @@ -33,6 +38,10 @@ Login With Public Key When Invalid Key Run Keyword And Expect Error Login with public key failed for user '${KEY USERNAME}'. ... Login With Public Key ${KEY USERNAME} ${INVALID KEY} +Login With Public Key When Invalid Key And Valid Password + Run Keyword And Expect Error Login with public key failed for user '${USERNAME}'. + ... Login With Public Key ${USERNAME} ${INVALID KEY} ${PASSWORD} + Login With Public Key When Non-Existing Key Run Keyword And Expect Error Given key file 'not_existing_key' does not exist. ... Login With Public Key ${KEY USERNAME} not_existing_key diff --git a/src/SSHLibrary/abstractclient.py b/src/SSHLibrary/abstractclient.py index 484bce41c..0f73528b0 100644 --- a/src/SSHLibrary/abstractclient.py +++ b/src/SSHLibrary/abstractclient.py @@ -170,7 +170,7 @@ def _read_login_output(self, delay): return self.read_until_regexp(self.config.prompt[7:]) return self.read_until_prompt() - def login_with_public_key(self, username, keyfile, password, allow_agent=False, + def login_with_public_key(self, username, keyfile, passphrase, allow_agent=False, look_for_keys=False, delay=None): """Logs into the remote host using the public key authentication. @@ -184,7 +184,7 @@ def login_with_public_key(self, username, keyfile, password, allow_agent=False, :param str keyfile: Path to the valid OpenSSH private key file. - :param str password: Password (if needed) for unlocking the `keyfile`. + :param str passphrase: Passphrase (if needed) for unlocking the `keyfile`. :param boolean allow_agent: enables the connection to the SSH agent. This option does not work when using Jython. @@ -204,7 +204,7 @@ def login_with_public_key(self, username, keyfile, password, allow_agent=False, username = self._encode(username) self._verify_key_file(keyfile) try: - self._login_with_public_key(username, keyfile, password, + self._login_with_public_key(username, keyfile, passphrase, allow_agent, look_for_keys) except SSHClientException: raise SSHClientException("Login with public key failed for user " @@ -220,7 +220,7 @@ def _verify_key_file(self, keyfile): except IOError: raise SSHClientException("Could not read key file '%s'." % keyfile) - def _login_with_public_key(self, username, keyfile, password, + def _login_with_public_key(self, username, keyfile, passphrase, allow_agent, look_for_keys): raise NotImplementedError diff --git a/src/SSHLibrary/javaclient.py b/src/SSHLibrary/javaclient.py index 7ba41021f..2af8924d2 100644 --- a/src/SSHLibrary/javaclient.py +++ b/src/SSHLibrary/javaclient.py @@ -50,7 +50,7 @@ def _login(self, username, password, look_for_keys='ignored'): if not self.client.authenticateWithPassword(username, password): raise SSHClientException - def _login_with_public_key(self, username, key_file, password, + def _login_with_public_key(self, username, key_file, passphrase, allow_agent='ignored', look_for_keys='ignored'): if allow_agent or look_for_keys: raise JavaSSHClientException("Arguments 'allow_agent' and " @@ -58,7 +58,7 @@ def _login_with_public_key(self, username, key_file, password, try: success = self.client.authenticateWithPublicKey(username, File(key_file), - password) + passphrase) if not success: raise SSHClientException except IOError: diff --git a/src/SSHLibrary/library.py b/src/SSHLibrary/library.py index 582d71f51..9f8c3c606 100644 --- a/src/SSHLibrary/library.py +++ b/src/SSHLibrary/library.py @@ -841,7 +841,7 @@ def login(self, username, password, delay='0.5 seconds'): """ return self._login(self.current.login, username, password, delay) - def login_with_public_key(self, username, keyfile, password='', + def login_with_public_key(self, username, keyfile, passphrase='', allow_agent=False, look_for_keys=False, delay='0.5 seconds'): """Logs into the SSH server using key-based authentication. @@ -853,7 +853,7 @@ def login_with_public_key(self, username, keyfile, password='', ``keyfile`` is a path to a valid OpenSSH private key file on the local filesystem. - ``password`` is used to unlock the ``keyfile`` if needed. + ``passphrase`` is used to unlock the ``keyfile`` if needed. This keyword reads, returns and logs the server output after logging in. If the `prompt` is set, everything until the prompt is read. @@ -881,7 +881,7 @@ def login_with_public_key(self, username, keyfile, password='', *Note:* ``allow_agent`` and ``look_for_keys`` do not work when using Jython. """ return self._login(self.current.login_with_public_key, username, - keyfile, password, is_truthy(allow_agent), + keyfile, passphrase, is_truthy(allow_agent), is_truthy(look_for_keys), delay) def _login(self, login_method, username, *args): diff --git a/src/SSHLibrary/pythonclient.py b/src/SSHLibrary/pythonclient.py index 2b93d4147..81b93a88a 100644 --- a/src/SSHLibrary/pythonclient.py +++ b/src/SSHLibrary/pythonclient.py @@ -75,14 +75,14 @@ def _login(self, username, password, look_for_keys=False): except paramiko.AuthenticationException: raise SSHClientException - def _login_with_public_key(self, username, key_file, password, allow_agent, look_for_keys): + def _login_with_public_key(self, username, key_file, passphrase, allow_agent, look_for_keys): try: self.client.connect(self.config.host, self.config.port, username, - password, key_filename=key_file, + passphrase=passphrase, key_filename=key_file, allow_agent=allow_agent, look_for_keys=look_for_keys, timeout=float(self.config.timeout)) - except paramiko.AuthenticationException: + except (paramiko.AuthenticationException, paramiko.SSHException): raise SSHClientException def get_banner(self):