121
123
elif 'SSH Secure Shell' in version:
122
124
trace.mutter('ssh implementation is SSH Corp.')
123
125
vendor = SSHCorpSubprocessVendor()
124
elif 'plink' in version and args[0] == 'plink':
125
# Checking if "plink" was the executed argument as Windows
126
# sometimes reports 'ssh -V' incorrectly with 'plink' in it's
127
# version. See https://bugs.launchpad.net/bzr/+bug/107155
128
trace.mutter("ssh implementation is Putty's plink.")
129
vendor = PLinkSubprocessVendor()
126
# Auto-detect of plink vendor disabled, on Windows recommended
127
# default ssh-client is paramiko
128
# see https://bugs.launchpad.net/bugs/414743
129
#~elif 'plink' in version and args[0] == 'plink':
130
#~ # Checking if "plink" was the executed argument as Windows
131
#~ # sometimes reports 'ssh -V' incorrectly with 'plink' in it's
132
#~ # version. See https://bugs.launchpad.net/bzr/+bug/107155
133
#~ trace.mutter("ssh implementation is Putty's plink.")
134
#~ vendor = PLinkSubprocessVendor()
132
137
def _get_vendor_by_inspection(self):
461
466
# paramiko requires a username, but it might be none if nothing was
462
467
# supplied. If so, use the local username.
463
468
if username is None:
464
username = auth.get_user('ssh', host, port=port)
469
username = auth.get_user('ssh', host, port=port,
470
default=getpass.getuser())
466
471
if _use_ssh_agent:
467
472
agent = paramiko.Agent()
468
473
for key in agent.get_keys():
480
485
if _try_pkey_auth(paramiko_transport, paramiko.DSSKey, username, 'id_dsa'):
488
# If we have gotten this far, we are about to try for passwords, do an
489
# auth_none check to see if it is even supported.
490
supported_auth_types = []
492
# Note that with paramiko <1.7.5 this logs an INFO message:
493
# Authentication type (none) not permitted.
494
# So we explicitly disable the logging level for this action
495
old_level = paramiko_transport.logger.level
496
paramiko_transport.logger.setLevel(logging.WARNING)
498
paramiko_transport.auth_none(username)
500
paramiko_transport.logger.setLevel(old_level)
501
except paramiko.BadAuthenticationType, e:
502
# Supported methods are in the exception
503
supported_auth_types = e.allowed_types
504
except paramiko.SSHException, e:
505
# Don't know what happened, but just ignore it
507
# We treat 'keyboard-interactive' and 'password' auth methods identically,
508
# because Paramiko's auth_password method will automatically try
509
# 'keyboard-interactive' auth (using the password as the response) if
510
# 'password' auth is not available. Apparently some Debian and Gentoo
511
# OpenSSH servers require this.
512
# XXX: It's possible for a server to require keyboard-interactive auth that
513
# requires something other than a single password, but we currently don't
515
if ('password' not in supported_auth_types and
516
'keyboard-interactive' not in supported_auth_types):
517
raise errors.ConnectionError('Unable to authenticate to SSH host as'
518
'\n %s@%s\nsupported auth types: %s'
519
% (username, host, supported_auth_types))
485
523
paramiko_transport.auth_password(username, password)
490
528
# give up and ask for a password
491
529
password = auth.get_password('ssh', host, username, port=port)
493
paramiko_transport.auth_password(username, password)
494
except paramiko.SSHException, e:
495
raise errors.ConnectionError(
496
'Unable to authenticate to SSH host as %s@%s' % (username, host), e)
530
# get_password can still return None, which means we should not prompt
531
if password is not None:
533
paramiko_transport.auth_password(username, password)
534
except paramiko.SSHException, e:
535
raise errors.ConnectionError(
536
'Unable to authenticate to SSH host as'
537
'\n %s@%s\n' % (username, host), e)
539
raise errors.ConnectionError('Unable to authenticate to SSH host as'
540
' %s@%s' % (username, host))
499
543
def _try_pkey_auth(paramiko_transport, pkey_class, username, filename):