diff options
author | Robey Pointer <robey@lag.net> | 2005-07-10 09:56:00 +0000 |
---|---|---|
committer | Robey Pointer <robey@lag.net> | 2005-07-10 09:56:00 +0000 |
commit | 0ac7b0dcbd43b5077b74bb5072d5f5e2423371d7 (patch) | |
tree | 09651c42bfa91989506104915b0d6d100e40c604 | |
parent | 5ba8b47a458560e6170b5635daf9db1211eadf61 (diff) |
[project @ Arch-1:robey@lag.net--2005-master-shake%paramiko--dev--1--patch-29]
a bunch of silly changes where i was trying to fix pychecker warnings before i decided it wasnt worth the effort
-rw-r--r-- | paramiko/__init__.py | 4 | ||||
-rw-r--r-- | paramiko/auth_transport.py | 3 | ||||
-rw-r--r-- | paramiko/ber.py | 24 | ||||
-rw-r--r-- | paramiko/channel.py | 9 | ||||
-rw-r--r-- | paramiko/dsskey.py | 9 | ||||
-rw-r--r-- | paramiko/kex_gex.py | 30 | ||||
-rw-r--r-- | paramiko/kex_group1.py | 3 | ||||
-rw-r--r-- | paramiko/packet.py | 24 | ||||
-rw-r--r-- | paramiko/primes.py | 10 | ||||
-rw-r--r-- | paramiko/rsakey.py | 6 | ||||
-rw-r--r-- | paramiko/sftp.py | 2 | ||||
-rw-r--r-- | paramiko/sftp_handle.py | 12 |
12 files changed, 76 insertions, 60 deletions
diff --git a/paramiko/__init__.py b/paramiko/__init__.py index 3216765e..6224f4f9 100644 --- a/paramiko/__init__.py +++ b/paramiko/__init__.py @@ -66,7 +66,7 @@ __license__ = "GNU Lesser General Public License (LGPL)" import transport, auth_transport, channel, rsakey, dsskey, message import ssh_exception, file, packet, agent, server -import sftp, sftp_client, sftp_attr, sftp_file, sftp_handle, sftp_server, sftp_si +import sftp_client, sftp_attr, sftp_handle, sftp_server, sftp_si randpool = transport.randpool Transport = auth_transport.Transport @@ -80,7 +80,7 @@ BadAuthenticationType = ssh_exception.BadAuthenticationType SFTP = sftp_client.SFTP SFTPClient = sftp_client.SFTPClient SFTPServer = sftp_server.SFTPServer -SFTPError = sftp.SFTPError +from sftp import SFTPError SFTPAttributes = sftp_attr.SFTPAttributes SFTPHandle = sftp_handle.SFTPHandle SFTPServerInterface = sftp_si.SFTPServerInterface diff --git a/paramiko/auth_transport.py b/paramiko/auth_transport.py index 03e8f393..f9ecf70b 100644 --- a/paramiko/auth_transport.py +++ b/paramiko/auth_transport.py @@ -46,6 +46,9 @@ class Transport (BaseTransport): self.username = None self.authenticated = False self.auth_event = None + self.auth_method = '' + self.password = None + self.private_key = None # for server mode: self.auth_username = None self.auth_fail_count = 0 diff --git a/paramiko/ber.py b/paramiko/ber.py index d479233b..a28b4a73 100644 --- a/paramiko/ber.py +++ b/paramiko/ber.py @@ -45,15 +45,15 @@ class BER(object): def decode_next(self): if self.idx >= len(self.content): return None - id = ord(self.content[self.idx]) + ident = ord(self.content[self.idx]) self.idx += 1 - if (id & 31) == 31: + if (ident & 31) == 31: # identifier > 30 - id = 0 + ident = 0 while self.idx < len(self.content): t = ord(self.content[self.idx]) self.idx += 1 - id = (id << 7) | (t & 0x7f) + ident = (ident << 7) | (t & 0x7f) if not (t & 0x80): break if self.idx >= len(self.content): @@ -75,29 +75,29 @@ class BER(object): data = self.content[self.idx : self.idx + size] self.idx += size # now switch on id - if id == 0x30: + if ident == 0x30: # sequence return self.decode_sequence(data) - elif id == 2: + elif ident == 2: # int return util.inflate_long(data) else: # 1: boolean (00 false, otherwise true) - raise BERException('Unknown ber encoding type %d (robey is lazy)' % id) + raise BERException('Unknown ber encoding type %d (robey is lazy)' % ident) def decode_sequence(data): out = [] b = BER(data) - while 1: + while True: x = b.decode_next() - if x == None: + if x is None: return out out.append(x) decode_sequence = staticmethod(decode_sequence) - def encode_tlv(self, id, val): - # FIXME: support id > 31 someday - self.content += chr(id) + def encode_tlv(self, ident, val): + # no need to support ident > 31 here + self.content += chr(ident) if len(val) > 0x7f: lenstr = util.deflate_long(len(val)) self.content += chr(0x80 + len(lenstr)) + lenstr diff --git a/paramiko/channel.py b/paramiko/channel.py index 233f75c0..65e6bbf3 100644 --- a/paramiko/channel.py +++ b/paramiko/channel.py @@ -60,6 +60,7 @@ class Channel (object): @type chanid: int """ self.chanid = chanid + self.remote_chanid = 0 self.transport = None self.active = False self.eof_received = 0 @@ -73,6 +74,12 @@ class Channel (object): self.in_buffer_cv = threading.Condition(self.lock) self.in_stderr_buffer_cv = threading.Condition(self.lock) self.out_buffer_cv = threading.Condition(self.lock) + self.in_window_size = 0 + self.out_window_size = 0 + self.in_max_packet_size = 0 + self.out_max_packet_size = 0 + self.in_window_threshold = 0 + self.in_window_sofar = 0 self.status_event = threading.Event() self.name = str(chanid) self.logger = util.get_logger('paramiko.chan.' + str(chanid)) @@ -1115,6 +1122,8 @@ class ChannelFile (BufferedFile): def _write(self, data): self.channel.sendall(data) return len(data) + + seek = BufferedFile.seek class ChannelStderrFile (ChannelFile): diff --git a/paramiko/dsskey.py b/paramiko/dsskey.py index cd3edc52..d945e5f0 100644 --- a/paramiko/dsskey.py +++ b/paramiko/dsskey.py @@ -56,6 +56,7 @@ class DSSKey (PKey): self.g = msg.get_mpint() self.y = msg.get_mpint() self.size = util.bit_length(self.p) + self.x = 0L def __str__(self): m = Message() @@ -84,16 +85,16 @@ class DSSKey (PKey): def can_sign(self): return hasattr(self, 'x') - def sign_ssh_data(self, randpool, data): - hash = SHA.new(data).digest() + def sign_ssh_data(self, rpool, data): + digest = SHA.new(data).digest() dss = DSA.construct((long(self.y), long(self.g), long(self.p), long(self.q), long(self.x))) # generate a suitable k qsize = len(util.deflate_long(self.q, 0)) while 1: - k = util.inflate_long(randpool.get_bytes(qsize), 1) + k = util.inflate_long(rpool.get_bytes(qsize), 1) if (k > 2) and (k < self.q): break - r, s = dss.sign(util.inflate_long(hash, 1), k) + r, s = dss.sign(util.inflate_long(digest, 1), k) m = Message() m.add_string('ssh-dss') m.add_string(util.deflate_long(r, 0) + util.deflate_long(s, 0)) diff --git a/paramiko/kex_gex.py b/paramiko/kex_gex.py index cd03a7ce..902677d9 100644 --- a/paramiko/kex_gex.py +++ b/paramiko/kex_gex.py @@ -96,30 +96,30 @@ class KexGex (object): self.x = x def _parse_kexdh_gex_request(self, m): - min = m.get_int() - preferred = m.get_int() - max = m.get_int() + minbits = m.get_int() + preferredbits = m.get_int() + maxbits = m.get_int() # smoosh the user's preferred size into our own limits - if preferred > self.max_bits: - preferred = self.max_bits - if preferred < self.min_bits: - preferred = self.min_bits + if preferredbits > self.max_bits: + preferredbits = self.max_bits + if preferredbits < self.min_bits: + preferredbits = self.min_bits # fix min/max if they're inconsistent. technically, we could just pout # and hang up, but there's no harm in giving them the benefit of the # doubt and just picking a bitsize for them. - if min > preferred: - min = preferred - if max < preferred: - max = preferred + if minbits > preferredbits: + minbits = preferredbits + if maxbits < preferredbits: + maxbits = preferredbits # now save a copy - self.min_bits = min - self.preferred_bits = preferred - self.max_bits = max + self.min_bits = minbits + self.preferred_bits = preferredbits + self.max_bits = maxbits # generate prime pack = self.transport._get_modulus_pack() if pack is None: raise SSHException('Can\'t do server-side gex with no modulus pack') - self.g, self.p = pack.get_modulus(min, preferred, max) + self.g, self.p = pack.get_modulus(minbits, preferredbits, maxbits) m = Message() m.add_byte(chr(_MSG_KEXDH_GEX_GROUP)) m.add_mpint(self.p) diff --git a/paramiko/kex_group1.py b/paramiko/kex_group1.py index 12255aac..33713685 100644 --- a/paramiko/kex_group1.py +++ b/paramiko/kex_group1.py @@ -41,6 +41,9 @@ class KexGroup1(object): def __init__(self, transport): self.transport = transport + self.x = 0L + self.e = 0L + self.f = 0L def start_kex(self): self._generate_x() diff --git a/paramiko/packet.py b/paramiko/packet.py index 6619833a..b7a2793f 100644 --- a/paramiko/packet.py +++ b/paramiko/packet.py @@ -194,7 +194,7 @@ class Packetizer (object): n = 0 if self.__closed: n = -1 - except Exception, x: + except Exception: # could be: (32, 'Broken pipe') n = -1 if n < 0: @@ -210,14 +210,14 @@ class Packetizer (object): way, but is only used for initial banner negotiation so it's not worth optimising. """ - buffer = '' - while not '\n' in buffer: - buffer += self._read_timeout(timeout) - buffer = buffer[:-1] - if (len(buffer) > 0) and (buffer[-1] == '\r'): - buffer = buffer[:-1] - return buffer - + buf = '' + while not '\n' in buf: + buf += self._read_timeout(timeout) + buf = buf[:-1] + if (len(buf) > 0) and (buf[-1] == '\r'): + buf = buf[:-1] + return buf + def send_message(self, data): """ Write a block of data using the current cipher, as an SSH block. @@ -275,9 +275,9 @@ class Packetizer (object): leftover = header[4:] if (packet_size - len(leftover)) % self.__block_size_in != 0: raise SSHException('Invalid packet blocking') - buffer = self.read_all(packet_size + self.__mac_size_in - len(leftover)) - packet = buffer[:packet_size - len(leftover)] - post_packet = buffer[packet_size - len(leftover):] + buf = self.read_all(packet_size + self.__mac_size_in - len(leftover)) + packet = buf[:packet_size - len(leftover)] + post_packet = buf[packet_size - len(leftover):] if self.__block_engine_in != None: packet = self.__block_engine_in.decrypt(packet) if self.__dump_packets: diff --git a/paramiko/primes.py b/paramiko/primes.py index 73184a5f..3101c479 100644 --- a/paramiko/primes.py +++ b/paramiko/primes.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - # Copyright (C) 2003-2005 Robey Pointer <robey@lag.net> # # This file is part of paramiko. @@ -42,7 +40,7 @@ def _generate_prime(bits, randpool): if util.bit_length(n) == bits: return n -def _roll_random(randpool, n): +def _roll_random(rpool, n): "returns a random # from 0 to N-1" bits = util.bit_length(n-1) bytes = (bits + 7) // 8 @@ -55,7 +53,7 @@ def _roll_random(randpool, n): # fits, so i can't guarantee that this loop will ever finish, but the odds # of it looping forever should be infinitesimal. while True: - x = randpool.get_bytes(bytes) + x = rpool.get_bytes(bytes) if hbyte_mask > 0: x = chr(ord(x[0]) & hbyte_mask) + x[1:] num = util.inflate_long(x, 1) @@ -69,11 +67,11 @@ class ModulusPack (object): on systems that have such a file. """ - def __init__(self, randpool): + def __init__(self, rpool): # pack is a hash of: bits -> [ (generator, modulus) ... ] self.pack = {} self.discarded = [] - self.randpool = randpool + self.randpool = rpool def _parse_modulus(self, line): timestamp, type, tests, tries, size, generator, modulus = line.split() diff --git a/paramiko/rsakey.py b/paramiko/rsakey.py index 2e868563..3e9fb410 100644 --- a/paramiko/rsakey.py +++ b/paramiko/rsakey.py @@ -76,10 +76,10 @@ class RSAKey (PKey): def can_sign(self): return hasattr(self, 'd') - def sign_ssh_data(self, randpool, data): - hash = SHA.new(data).digest() + def sign_ssh_data(self, rpool, data): + digest = SHA.new(data).digest() rsa = RSA.construct((long(self.n), long(self.e), long(self.d))) - sig = util.deflate_long(rsa.sign(self._pkcs1imify(hash), '')[0], 0) + sig = util.deflate_long(rsa.sign(self._pkcs1imify(digest), '')[0], 0) m = Message() m.add_string('ssh-rsa') m.add_string(sig) diff --git a/paramiko/sftp.py b/paramiko/sftp.py index 6a1900a7..917d0eeb 100644 --- a/paramiko/sftp.py +++ b/paramiko/sftp.py @@ -92,6 +92,8 @@ class SFTPError (Exception): class BaseSFTP (object): def __init__(self): self.logger = util.get_logger('paramiko.sftp') + self.sock = None + self.ultra_debug = False ### internals... diff --git a/paramiko/sftp_handle.py b/paramiko/sftp_handle.py index f290e1f6..fc615965 100644 --- a/paramiko/sftp_handle.py +++ b/paramiko/sftp_handle.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - # Copyright (C) 2003-2005 Robey Pointer <robey@lag.net> # # This file is part of paramiko. @@ -54,10 +52,12 @@ class SFTPHandle (object): using the default implementations of L{read} and L{write}, this method's default implementation should be fine also. """ - if hasattr(self, 'readfile') and (self.readfile is not None): - self.readfile.close() - if hasattr(self, 'writefile') and (self.writefile is not None): - self.writefile.close() + readfile = getattr(self, 'readfile', None) + if readfile is not None: + readfile.close() + writefile = getattr(self, 'writefile', None) + if writefile is not None: + writefile.close() def read(self, offset, length): """ |