~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/ssh.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 18:13:57 UTC
  • mfrom: (5268.7.29 transport-segments)
  • Revision ID: pqm@pqm.ubuntu.com-20110817181357-y5q5eth1hk8bl3om
(jelmer) Allow specifying the colocated branch to use in the branch URL,
 and retrieving the branch name using ControlDir._get_selected_branch.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Foundation SSH support for SFTP and smart server."""
19
19
 
20
 
from __future__ import absolute_import
21
 
 
22
20
import errno
23
21
import getpass
24
22
import logging
26
24
import socket
27
25
import subprocess
28
26
import sys
29
 
from binascii import hexlify
30
27
 
31
28
from bzrlib import (
32
29
    config,
277
274
class ParamikoVendor(SSHVendor):
278
275
    """Vendor that uses paramiko."""
279
276
 
280
 
    def _hexify(self, s):
281
 
        return hexlify(s).upper()
282
 
 
283
277
    def _connect(self, username, password, host, port):
284
278
        global SYSTEM_HOSTKEYS, BZR_HOSTKEYS
285
279
 
293
287
            self._raise_connection_error(host, port=port, orig_error=e)
294
288
 
295
289
        server_key = t.get_remote_server_key()
296
 
        server_key_hex = self._hexify(server_key.get_fingerprint())
 
290
        server_key_hex = paramiko.util.hexify(server_key.get_fingerprint())
297
291
        keytype = server_key.get_name()
298
292
        if host in SYSTEM_HOSTKEYS and keytype in SYSTEM_HOSTKEYS[host]:
299
293
            our_server_key = SYSTEM_HOSTKEYS[host][keytype]
300
 
            our_server_key_hex = self._hexify(our_server_key.get_fingerprint())
 
294
            our_server_key_hex = paramiko.util.hexify(
 
295
                our_server_key.get_fingerprint())
301
296
        elif host in BZR_HOSTKEYS and keytype in BZR_HOSTKEYS[host]:
302
297
            our_server_key = BZR_HOSTKEYS[host][keytype]
303
 
            our_server_key_hex = self._hexify(our_server_key.get_fingerprint())
 
298
            our_server_key_hex = paramiko.util.hexify(
 
299
                our_server_key.get_fingerprint())
304
300
        else:
305
301
            trace.warning('Adding %s host key for %s: %s'
306
302
                          % (keytype, host, server_key_hex))
310
306
            else:
311
307
                BZR_HOSTKEYS.setdefault(host, {})[keytype] = server_key
312
308
            our_server_key = server_key
313
 
            our_server_key_hex = self._hexify(our_server_key.get_fingerprint())
 
309
            our_server_key_hex = paramiko.util.hexify(
 
310
                our_server_key.get_fingerprint())
314
311
            save_host_keys()
315
312
        if server_key != our_server_key:
316
313
            filename1 = os.path.expanduser('~/.ssh/known_hosts')
355
352
class SubprocessVendor(SSHVendor):
356
353
    """Abstract base class for vendors that use pipes to a subprocess."""
357
354
 
358
 
    # In general stderr should be inherited from the parent process so prompts
359
 
    # are visible on the terminal. This can be overriden to another file for
360
 
    # tests, but beware of using PIPE which may hang due to not being read.
361
 
    _stderr_target = None
362
 
 
363
355
    def _connect(self, argv):
364
356
        # Attempt to make a socketpair to use as stdin/stdout for the SSH
365
357
        # subprocess.  We prefer sockets to pipes because they support
376
368
        else:
377
369
            stdin = stdout = subproc_sock
378
370
        proc = subprocess.Popen(argv, stdin=stdin, stdout=stdout,
379
 
                                stderr=self._stderr_target,
380
371
                                **os_specific_subprocess_params())
381
372
        if subproc_sock is not None:
382
373
            subproc_sock.close()
506
497
        agent = paramiko.Agent()
507
498
        for key in agent.get_keys():
508
499
            trace.mutter('Trying SSH agent key %s'
509
 
                         % self._hexify(key.get_fingerprint()))
 
500
                         % paramiko.util.hexify(key.get_fingerprint()))
510
501
            try:
511
502
                paramiko_transport.auth_publickey(username, key)
512
503
                return