diff options
author | Robey Pointer <robey@lag.net> | 2003-11-10 04:54:02 +0000 |
---|---|---|
committer | Robey Pointer <robey@lag.net> | 2003-11-10 04:54:02 +0000 |
commit | aad7b859f194451a0529c4d8aa20cdc724ae33a2 (patch) | |
tree | 24b19c05626e547f3f3bc4a12c7a8c64578dbed5 /kex_gex.py | |
parent | 0e1ef2c65c80bd76eb62f5dfd953cb987d36ce3a (diff) |
[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-7]
cleaned up server code, renamed some files & classes
renamed demo-server.py and demo-host-key to demo_server.py and
demo_host_key, just to be consistent.
renamed SSHException -> SecshException.
generalized the mechanism where Channel decides whether to allow
different channel requests: 4 of the main ones (pty, window-change,
shell, and subsystem) go through easily override-able methods now.
you could probably make an actual ssh shell server.
gave ChannelFile a repr().
turned off ultra debugging in the demos. demo_server creates a
subclass of Channel to allow pty/shell and sets an event when the
shell request is made, so that it knows when it can start sending
the fake bbs.
renamed to charmander and updated some of the distutils files.
Diffstat (limited to 'kex_gex.py')
-rw-r--r-- | kex_gex.py | 24 |
1 files changed, 7 insertions, 17 deletions
@@ -5,8 +5,8 @@ # LOT more on the server side). from message import Message -from util import inflate_long, deflate_long, generate_prime -from secsh import SSHException +from util import inflate_long, deflate_long, generate_prime, bit_length +from secsh import SecshException from transport import MSG_NEWKEYS from Crypto.Hash import SHA from Crypto.Util import number @@ -49,17 +49,7 @@ class KexGex(object): return self.parse_kexdh_gex_init(m) elif ptype == MSG_KEXDH_GEX_REPLY: return self.parse_kexdh_gex_reply(m) - raise SSHException('KexGex asked to handle packet type %d' % ptype) - - def bit_length(n): - norm = deflate_long(n, 0) - hbyte = ord(norm[0]) - bitlen = len(norm) * 8 - while not (hbyte & 0x80): - hbyte <<= 1 - bitlen -= 1 - return bitlen - bit_length = staticmethod(bit_length) + raise SecshException('KexGex asked to handle packet type %d' % ptype) def generate_x(self): # generate an "x" (1 < x < (p-1)/2). @@ -116,9 +106,9 @@ class KexGex(object): self.p = m.get_mpint() self.g = m.get_mpint() # reject if p's bit length < 1024 or > 8192 - bitlen = self.bit_length(self.p) + bitlen = bit_length(self.p) if (bitlen < 1024) or (bitlen > 8192): - raise SSHException('Server-generated gex p (don\'t ask) is out of range (%d bits)' % bitlen) + raise SecshException('Server-generated gex p (don\'t ask) is out of range (%d bits)' % bitlen) self.transport.log(DEBUG, 'Got server p (%d bits)' % bitlen) self.generate_x() # now compute e = g^x mod p @@ -132,7 +122,7 @@ class KexGex(object): def parse_kexdh_gex_init(self, m): self.e = m.get_mpint() if (self.e < 1) or (self.e > self.p - 1): - raise SSHException('Client kex "e" is out of range') + raise SecshException('Client kex "e" is out of range') self.generate_x() K = pow(self.e, self.x, P) key = str(self.transport.get_server_key()) @@ -164,7 +154,7 @@ class KexGex(object): self.f = m.get_mpint() sig = m.get_string() if (self.f < 1) or (self.f > self.p - 1): - raise SSHException('Server kex "f" is out of range') + raise SecshException('Server kex "f" is out of range') K = pow(self.f, self.x, self.p) # okay, build up the hash H of (V_C || V_S || I_C || I_S || K_S || min || n || max || p || g || e || f || K) hm = Message().add(self.transport.local_version).add(self.transport.remote_version) |