Skip to content

Commit

Permalink
Merge pull request #118 from xxh/key_pass_refactor
Browse files Browse the repository at this point in the history
Cleaning around #102
  • Loading branch information
anki-code committed Apr 1, 2021
2 parents f81bac8 + c8cb57f commit 5b94be3
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions xxh/xxh_xxh/xxh.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def pssh(self, cmd, accept_host=None, host_password=None, key_password=None):
if self.vverbose:
self.eprint(f'Pexpect caught pattern: {patterns[pattern]}')

if pattern in [0,1]:
if pattern in [0, 1]:
# Expected:
# The authenticity of host '<...>' can't be established.
# ECDSA key fingerprint is <...>
Expand All @@ -154,13 +154,15 @@ def pssh(self, cmd, accept_host=None, host_password=None, key_password=None):
if pattern == 2:
# Expected:
# Enter passphrase for key '<keyfile>':
if key_password is None:
user_key_password = getpass.getpass(prompt=(sess.before + sess.after).decode("utf-8")+' ')
if user_key_password:
sess.sendline(user_key_password)
else:
elif key_password:
sess.sendline(key_password)
else:
user_key_password = getpass.getpass(prompt=(sess.before + sess.after).decode("utf-8")+' ')
sess.sendline(user_key_password)

if pattern in [3,4]:
if pattern in [3, 4]:
# Expected:
# <host>`s password:
if host_password is None:
Expand All @@ -177,22 +179,22 @@ def pssh(self, cmd, accept_host=None, host_password=None, key_password=None):
output = output[3:] if output.startswith(' \r\n') else output
result = {
'user_host_accept': user_host_accept,
'user_host_password':user_host_password,
'user_key_password':user_key_password,
'user_host_password': user_host_password,
'user_key_password': user_key_password,
'output':output
}

return result

if pattern in [6,7]:
if pattern in [6, 7]:
# Prompt
print(sess.before.decode("utf-8"))
sess.interact()

result = {
'user_host_accept': user_host_accept,
'user_host_password':user_host_password,
'user_key_password':user_key_password
'user_host_password': user_host_password,
'user_key_password': user_key_password
}
return result

Expand Down

0 comments on commit 5b94be3

Please sign in to comment.