Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
shrapnel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
shrapnel
Commits
5af56582
Commit
5af56582
authored
May 06, 2013
by
Sam Rushing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hexdump: used in debugging - will remove
msg_kexdh_init(): calculate correct value for for f
parent
24756675
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
31 deletions
+33
-31
coro/ssh/key_exchange/diffie_hellman.py
coro/ssh/key_exchange/diffie_hellman.py
+33
-31
No files found.
coro/ssh/key_exchange/diffie_hellman.py
View file @
5af56582
...
...
@@ -38,6 +38,8 @@ from coro.ssh.key_exchange import SSH_Key_Exchange
from
coro.ssh.transport
import
constants
from
coro.ssh.keys
import
parse_public_key
from
coro.ssh.util.mpint
import
pack_mpint
# 2**1024 - 2**960 - 1 + 2**64 * floor( 2**894 Pi + 129093 )
DH_PRIME
=
179769313486231590770839156793787453197860296048756011706444423684197180216158519368947833795864925541502180565485980503646440548199239100050792877003355816639229553136239076508735759914822574862575007425302077447712589550957937778424442426617334727629299387668709205606050270810842907692932019128194467627007L
DH_GENERATOR
=
2L
...
...
@@ -45,6 +47,16 @@ DH_GENERATOR = 2L
SSH_MSG_KEXDH_INIT
=
30
SSH_MSG_KEXDH_REPLY
=
31
def
hexdump
(
src
,
length
=
16
):
FILTER
=
''
.
join
([(
len
(
repr
(
chr
(
x
)))
==
3
)
and
chr
(
x
)
or
'.'
for
x
in
range
(
256
)])
lines
=
[]
for
c
in
xrange
(
0
,
len
(
src
),
length
):
chars
=
src
[
c
:
c
+
length
]
hex
=
' '
.
join
([
"%02x"
%
ord
(
x
)
for
x
in
chars
])
printable
=
''
.
join
([
"%s"
%
((
ord
(
x
)
<=
127
and
FILTER
[
ord
(
x
)])
or
'.'
)
for
x
in
chars
])
lines
.
append
(
"%04x %-*s %s
\
n
"
%
(
c
,
length
*
3
,
hex
,
printable
))
return
''
.
join
(
lines
)
class
Diffie_Hellman_Group1_SHA1
(
SSH_Key_Exchange
):
name
=
'diffie-hellman-group1-sha1'
...
...
@@ -92,26 +104,18 @@ class Diffie_Hellman_Group1_SHA1(SSH_Key_Exchange):
self
.
transport
.
register_callbacks
(
self
.
name
,
callbacks
)
def
msg_kexdh_init
(
self
,
packet
):
# mpint e
msg
,
self
.
client_exchange_value
=
ssh_packet
.
unpack_payload
(
KEXDH_INIT_PAYLOAD
,
packet
)
# XXX make sure e is a valid number
W
(
'kexdh: self.client_exchange_value=%r
\
n
'
%
(
self
.
client_exchange_value
,))
# This is y.
self
.
server_random_value
=
ssh_random
.
get_random_number
(
512
)
# p is large safe prime (DH_PRIME)
# g is a generator for a subgroup of GF(p) (DH_GENERATOR)
# compute f=g**y mod p
self
.
server_exchange_value
=
pow
(
DH_GENERATOR
,
self
.
server_random_value
,
DH_PRIME
)
self
.
shared_secret
=
pow
(
self
.
server_exchange_value
,
self
.
client_exchange_value
,
DH_PRIME
)
# find my public key
for
key
in
self
.
transport
.
server_keys
:
if
key
.
name
==
'ssh-dss'
:
K_S
=
key
.
get_public_key_blob
()
break
else
:
raise
ValueError
(
"no dss key?"
)
W
(
'kexdh: K_S=%r
\
n
'
%
(
K_S
,))
H
=
ssh_packet
.
pack_payload
(
KEXDH_HASH_PAYLOAD
,
(
self
.
shared_secret
=
pow
(
self
.
client_exchange_value
,
self
.
server_random_value
,
DH_PRIME
)
K_S
=
self
.
transport
.
server_key
.
get_public_key_blob
()
payload_inputs
=
(
self
.
c2s_version_string
,
self
.
s2c_version_string
,
self
.
c2s_kexinit_packet
,
...
...
@@ -121,15 +125,13 @@ class Diffie_Hellman_Group1_SHA1(SSH_Key_Exchange):
self
.
server_exchange_value
,
self
.
shared_secret
)
)
H
=
ssh_packet
.
pack_payload
(
KEXDH_HASH_PAYLOAD
,
payload_inputs
)
self
.
exchange_hash
=
hashlib
.
sha1
(
H
).
digest
()
if
self
.
session_id
is
None
:
# The session id is the first exchange hash.
self
.
session_id
=
self
.
exchange_hash
H_sig
=
key
.
sign
(
self
.
exchange_hash
)
W
(
'kexdh: sending KEXDH_REPLY
\
n
'
)
self
.
transport
.
send_packet
(
ssh_packet
.
pack_payload
(
H_sig
=
self
.
transport
.
server_key
.
sign
(
self
.
exchange_hash
)
packet
=
ssh_packet
.
pack_payload
(
KEXDH_REPLY_PAYLOAD
,
(
SSH_MSG_KEXDH_REPLY
,
K_S
,
...
...
@@ -137,7 +139,7 @@ class Diffie_Hellman_Group1_SHA1(SSH_Key_Exchange):
H_sig
)
)
)
self
.
transport
.
send_packet
(
packet
)
def
msg_kexdh_reply
(
self
,
packet
):
# string server public host key and certificates (K_S)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment