~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/ssh.py

  • Committer: Patch Queue Manager
  • Date: 2016-02-01 19:13:13 UTC
  • mfrom: (6614.2.2 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20160201191313-wdfvmfff1djde6oq
(vila) Release 2.7.0 (Vincent Ladeuil)

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
 
20
22
import errno
21
23
import getpass
22
24
import logging
24
26
import socket
25
27
import subprocess
26
28
import sys
 
29
from binascii import hexlify
27
30
 
28
31
from bzrlib import (
29
32
    config,
274
277
class ParamikoVendor(SSHVendor):
275
278
    """Vendor that uses paramiko."""
276
279
 
 
280
    def _hexify(self, s):
 
281
        return hexlify(s).upper()
 
282
 
277
283
    def _connect(self, username, password, host, port):
278
284
        global SYSTEM_HOSTKEYS, BZR_HOSTKEYS
279
285
 
287
293
            self._raise_connection_error(host, port=port, orig_error=e)
288
294
 
289
295
        server_key = t.get_remote_server_key()
290
 
        server_key_hex = paramiko.util.hexify(server_key.get_fingerprint())
 
296
        server_key_hex = self._hexify(server_key.get_fingerprint())
291
297
        keytype = server_key.get_name()
292
298
        if host in SYSTEM_HOSTKEYS and keytype in SYSTEM_HOSTKEYS[host]:
293
299
            our_server_key = SYSTEM_HOSTKEYS[host][keytype]
294
 
            our_server_key_hex = paramiko.util.hexify(
295
 
                our_server_key.get_fingerprint())
 
300
            our_server_key_hex = self._hexify(our_server_key.get_fingerprint())
296
301
        elif host in BZR_HOSTKEYS and keytype in BZR_HOSTKEYS[host]:
297
302
            our_server_key = BZR_HOSTKEYS[host][keytype]
298
 
            our_server_key_hex = paramiko.util.hexify(
299
 
                our_server_key.get_fingerprint())
 
303
            our_server_key_hex = self._hexify(our_server_key.get_fingerprint())
300
304
        else:
301
305
            trace.warning('Adding %s host key for %s: %s'
302
306
                          % (keytype, host, server_key_hex))
306
310
            else:
307
311
                BZR_HOSTKEYS.setdefault(host, {})[keytype] = server_key
308
312
            our_server_key = server_key
309
 
            our_server_key_hex = paramiko.util.hexify(
310
 
                our_server_key.get_fingerprint())
 
313
            our_server_key_hex = self._hexify(our_server_key.get_fingerprint())
311
314
            save_host_keys()
312
315
        if server_key != our_server_key:
313
316
            filename1 = os.path.expanduser('~/.ssh/known_hosts')
352
355
class SubprocessVendor(SSHVendor):
353
356
    """Abstract base class for vendors that use pipes to a subprocess."""
354
357
 
 
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
 
355
363
    def _connect(self, argv):
356
364
        # Attempt to make a socketpair to use as stdin/stdout for the SSH
357
365
        # subprocess.  We prefer sockets to pipes because they support
368
376
        else:
369
377
            stdin = stdout = subproc_sock
370
378
        proc = subprocess.Popen(argv, stdin=stdin, stdout=stdout,
 
379
                                stderr=self._stderr_target,
371
380
                                **os_specific_subprocess_params())
372
381
        if subproc_sock is not None:
373
382
            subproc_sock.close()
497
506
        agent = paramiko.Agent()
498
507
        for key in agent.get_keys():
499
508
            trace.mutter('Trying SSH agent key %s'
500
 
                         % paramiko.util.hexify(key.get_fingerprint()))
 
509
                         % self._hexify(key.get_fingerprint()))
501
510
            try:
502
511
                paramiko_transport.auth_publickey(username, key)
503
512
                return