~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/ssh.py

  • Committer: Vincent Ladeuil
  • Date: 2007-10-17 20:47:40 UTC
  • mto: (2961.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 2962.
  • Revision ID: v.ladeuil+lp@free.fr-20071017204740-71pnib4rh910c4ss
Make sftp and bzr+ssh aware of authentication config.

* doc/developers/authentication-ring.txt: 
Add a remark about ssh being the scheme used for authentication
for sftp and bzr+ssh.

* bzrlib/transport/ssh.py:
(_paramiko_auth): Add a 'port' parameter. Try the authentication
config before prompting the user.

Show diffs side-by-side

added added

removed removed

Lines of Context:
263
263
 
264
264
    def _connect(self, username, password, host, port):
265
265
        global SYSTEM_HOSTKEYS, BZR_HOSTKEYS
266
 
        
 
266
 
267
267
        load_host_keys()
268
268
 
269
269
        try:
272
272
            t.start_client()
273
273
        except (paramiko.SSHException, socket.error), e:
274
274
            self._raise_connection_error(host, port=port, orig_error=e)
275
 
            
 
275
 
276
276
        server_key = t.get_remote_server_key()
277
277
        server_key_hex = paramiko.util.hexify(server_key.get_fingerprint())
278
278
        keytype = server_key.get_name()
299
299
                (host, our_server_key_hex, server_key_hex),
300
300
                ['Try editing %s or %s' % (filename1, filename2)])
301
301
 
302
 
        _paramiko_auth(username, password, host, t)
 
302
        _paramiko_auth(username, password, host, port, t)
303
303
        return t
304
 
        
 
304
 
305
305
    def connect_sftp(self, username, password, host, port):
306
306
        t = self._connect(username, password, host, port)
307
307
        try:
454
454
register_ssh_vendor('plink', PLinkSubprocessVendor())
455
455
 
456
456
 
457
 
def _paramiko_auth(username, password, host, paramiko_transport):
 
457
def _paramiko_auth(username, password, host, port, paramiko_transport):
458
458
    # paramiko requires a username, but it might be none if nothing was supplied
459
459
    # use the local username, just in case.
460
460
    # We don't override username, because if we aren't using paramiko,
487
487
            pass
488
488
 
489
489
    # give up and ask for a password
490
 
    password = bzrlib.ui.ui_factory.get_password(
 
490
    auth = config.AuthenticationConfig()
 
491
    config_credentials = auth.get_credentials('ssh', host, port=port,
 
492
                                              user=username)
 
493
    if config_credentials is not None:
 
494
        password = config_credentials['password']
 
495
    else:
 
496
        password = bzrlib.ui.ui_factory.get_password(
491
497
            prompt='SSH %(user)s@%(host)s password',
492
498
            user=username, host=host)
493
499
    try: