summaryrefslogtreecommitdiff
path: root/paramiko/kex_group1.py
diff options
context:
space:
mode:
authorScott Maxwell <scott@codecobblers.com>2013-10-30 17:09:34 -0700
committerScott Maxwell <scott@codecobblers.com>2013-10-30 17:09:34 -0700
commit0e4ce3762a5b25c5d3eb89335495d3bb9054e3e7 (patch)
treea77bfec4e3a29e9827d4e75de932e34947536181 /paramiko/kex_group1.py
parent339d73cc13765bea4dd5b683ca14b02c9baa589f (diff)
downloadparamiko-0e4ce3762a5b25c5d3eb89335495d3bb9054e3e7.tar.gz
Fix message sending
Create constants for byte messages, implement asbytes so many methods can take Message and key objects directly and split get_string into get_text and get_binary. Also, change int handling to use mpint with a flag whenever the int is greater than 32 bits.
Diffstat (limited to 'paramiko/kex_group1.py')
-rw-r--r--paramiko/kex_group1.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/paramiko/kex_group1.py b/paramiko/kex_group1.py
index 6e89b6dc..83fb87de 100644
--- a/paramiko/kex_group1.py
+++ b/paramiko/kex_group1.py
@@ -56,7 +56,7 @@ class KexGroup1(object):
# compute e = g^x mod p (where g=2), and send it
self.e = pow(G, self.x, P)
m = Message()
- m.add_byte(chr(_MSG_KEXDH_INIT))
+ m.add_byte(c_MSG_KEXDH_INIT)
m.add_mpint(self.e)
self.transport._send_message(m)
self.transport._expect_packet(_MSG_KEXDH_REPLY)
@@ -67,7 +67,7 @@ class KexGroup1(object):
elif not self.transport.server_mode and (ptype == _MSG_KEXDH_REPLY):
return self._parse_kexdh_reply(m)
raise SSHException('KexGroup1 asked to handle packet type %d' % ptype)
-
+
### internals...
@@ -92,7 +92,7 @@ class KexGroup1(object):
self.f = m.get_mpint()
if (self.f < 1) or (self.f > P - 1):
raise SSHException('Server kex "f" is out of range')
- sig = m.get_string()
+ sig = m.get_binary()
K = pow(self.f, self.x, P)
# okay, build up the hash H of (V_C || V_S || I_C || I_S || K_S || e || f || K)
hm = Message()
@@ -102,7 +102,7 @@ class KexGroup1(object):
hm.add_mpint(self.e)
hm.add_mpint(self.f)
hm.add_mpint(K)
- self.transport._set_K_H(K, SHA.new(str(hm)).digest())
+ self.transport._set_K_H(K, SHA.new(hm.asbytes()).digest())
self.transport._verify_key(host_key, sig)
self.transport._activate_outbound()
@@ -112,7 +112,7 @@ class KexGroup1(object):
if (self.e < 1) or (self.e > P - 1):
raise SSHException('Client kex "e" is out of range')
K = pow(self.e, self.x, P)
- key = str(self.transport.get_server_key())
+ key = self.transport.get_server_key().asbytes()
# okay, build up the hash H of (V_C || V_S || I_C || I_S || K_S || e || f || K)
hm = Message()
hm.add(self.transport.remote_version, self.transport.local_version,
@@ -121,15 +121,15 @@ class KexGroup1(object):
hm.add_mpint(self.e)
hm.add_mpint(self.f)
hm.add_mpint(K)
- H = SHA.new(str(hm)).digest()
+ H = SHA.new(hm.asbytes()).digest()
self.transport._set_K_H(K, H)
# sign it
sig = self.transport.get_server_key().sign_ssh_data(self.transport.rng, H)
# send reply
m = Message()
- m.add_byte(chr(_MSG_KEXDH_REPLY))
+ m.add_byte(c_MSG_KEXDH_REPLY)
m.add_string(key)
m.add_mpint(self.f)
- m.add_string(str(sig))
+ m.add_string(sig)
self.transport._send_message(m)
self.transport._activate_outbound()