@@ -195,9 +195,12 @@ cdef class Session(object):
195
195
:param private_key_password: A password for the private key.
196
196
:type private_key_password: bytes
197
197
198
- :param password: The password to authenticate the ssh session
198
+ :param password: The password to authenticate the ssh session.
199
199
:type password: str
200
200
201
+ :param password_prompt: The prompt to look for when using password authentication.
202
+ :type password_prompt: str
203
+
201
204
:param gssapi_server_identity: The service principal hostname to use.
202
205
For example for principal ``host/[email protected] ``, the hostname
203
206
would be ``file.example.com``. Not required for GSSAPI authentication.
@@ -280,7 +283,7 @@ cdef class Session(object):
280
283
# This will be neither user-interactive nor involve a keyboard,
281
284
# but rather emulate the exchange using the provided password
282
285
try :
283
- self .authenticate_interactive(kwargs[" password" ])
286
+ self .authenticate_interactive(kwargs[" password" ], expected_prompt = kwargs.get( " password_prompt " ) )
284
287
except LibsshSessionException as ex:
285
288
saved_exception = ex
286
289
else :
@@ -442,19 +445,25 @@ cdef class Session(object):
442
445
if rc == libssh.SSH_AUTH_ERROR or rc == libssh.SSH_AUTH_DENIED:
443
446
raise LibsshSessionException(" Failed to authenticate with password: %s " % self ._get_session_error_str())
444
447
445
- def authenticate_interactive (self , password ):
448
+ def authenticate_interactive (self , password , expected_prompt = None ):
446
449
""" Authenticate this session using keyboard-interactive authentication.
447
450
448
451
:param password: The password to authenticate with.
449
452
:type password: str
450
453
454
+ :param expected_prompt: The expected password prompt.
455
+ :type expected_prompt: str
456
+
451
457
:raises LibsshSessionException: If authentication failed.
452
458
453
459
:return: Nothing.
454
460
:rtype: NoneType
455
461
"""
456
462
cdef int rc
457
463
cdef char should_echo
464
+ if expected_prompt is None :
465
+ expected_prompt = " password:"
466
+ expected_prompt = expected_prompt.lower().strip()
458
467
rc = libssh.ssh_userauth_kbdint(self ._libssh_session, NULL , NULL )
459
468
460
469
while rc == libssh.SSH_AUTH_INFO:
@@ -463,8 +472,9 @@ cdef class Session(object):
463
472
if prompt_count > 0 :
464
473
for prompt in range (prompt_count):
465
474
prompt_text = libssh.ssh_userauth_kbdint_getprompt(self ._libssh_session, prompt, & should_echo)
475
+ prompt_text = prompt_text.decode().lower().strip()
466
476
prompt_text_list.append(prompt_text)
467
- if prompt_text.lower().strip().endswith(b " password: " ):
477
+ if prompt_text.lower().strip().endswith(expected_prompt ):
468
478
break
469
479
else :
470
480
raise LibsshSessionException(" None of the prompts looked like password prompts: {err}" .format(err = prompt_text_list))
0 commit comments