Mercurial > dropbear
annotate cli-kex.c @ 49:cc59bfcdee17
Should be dropbearkey, rather than dropbearmulti, for the default targets
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 07 Aug 2004 15:50:58 +0000 |
parents | e2a1eaa19f22 |
children | 095d689fed16 |
rev | line source |
---|---|
26 | 1 /* |
2 * Dropbear - a SSH2 server | |
3 * | |
4 * Copyright (c) 2002,2003 Matt Johnston | |
5 * All rights reserved. | |
6 * | |
7 * Permission is hereby granted, free of charge, to any person obtaining a copy | |
8 * of this software and associated documentation files (the "Software"), to deal | |
9 * in the Software without restriction, including without limitation the rights | |
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
11 * copies of the Software, and to permit persons to whom the Software is | |
12 * furnished to do so, subject to the following conditions: | |
13 * | |
14 * The above copyright notice and this permission notice shall be included in | |
15 * all copies or substantial portions of the Software. | |
16 * | |
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
23 * SOFTWARE. */ | |
24 | |
25 #include "includes.h" | |
26 #include "session.h" | |
27 #include "dbutil.h" | |
28 #include "algo.h" | |
29 #include "buffer.h" | |
30 #include "session.h" | |
31 #include "kex.h" | |
32 #include "ssh.h" | |
33 #include "packet.h" | |
34 #include "bignum.h" | |
35 #include "random.h" | |
36 #include "runopts.h" | |
33 | 37 #include "signkey.h" |
26 | 38 |
39 | |
40 | |
41 void send_msg_kexdh_init() { | |
42 | |
43 cli_ses.dh_e = (mp_int*)m_malloc(sizeof(mp_int)); | |
44 cli_ses.dh_x = (mp_int*)m_malloc(sizeof(mp_int)); | |
45 | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
46 m_mp_init_multi(cli_ses.dh_e, cli_ses.dh_x, NULL); |
26 | 47 gen_kexdh_vals(cli_ses.dh_e, cli_ses.dh_x); |
48 | |
49 CHECKCLEARTOWRITE(); | |
50 buf_putbyte(ses.writepayload, SSH_MSG_KEXDH_INIT); | |
51 buf_putmpint(ses.writepayload, cli_ses.dh_e); | |
52 encrypt_packet(); | |
53 ses.requirenext = SSH_MSG_KEXDH_REPLY; | |
54 } | |
55 | |
56 /* Handle a diffie-hellman key exchange reply. */ | |
57 void recv_msg_kexdh_reply() { | |
58 | |
59 mp_int dh_f; | |
60 sign_key *hostkey = NULL; | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
61 int type, keylen; |
26 | 62 |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
63 TRACE(("enter recv_msg_kexdh_reply")); |
26 | 64 type = ses.newkeys->algo_hostkey; |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
65 TRACE(("type is %d", type)); |
26 | 66 |
67 hostkey = new_sign_key(); | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
68 keylen = buf_getint(ses.payload); |
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
69 |
26 | 70 if (buf_get_pub_key(ses.payload, hostkey, &type) != DROPBEAR_SUCCESS) { |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
71 TRACE(("failed getting pubkey")); |
26 | 72 dropbear_exit("Bad KEX packet"); |
73 } | |
74 | |
75 m_mp_init(&dh_f); | |
76 if (buf_getmpint(ses.payload, &dh_f) != DROPBEAR_SUCCESS) { | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
77 TRACE(("failed getting mpint")); |
26 | 78 dropbear_exit("Bad KEX packet"); |
79 } | |
80 | |
81 kexdh_comb_key(cli_ses.dh_e, cli_ses.dh_x, &dh_f, hostkey); | |
82 mp_clear(&dh_f); | |
83 | |
84 if (buf_verify(ses.payload, hostkey, ses.hash, SHA1_HASH_SIZE) | |
85 != DROPBEAR_SUCCESS) { | |
86 dropbear_exit("Bad hostkey signature"); | |
87 } | |
88 | |
89 /* XXX TODO */ | |
90 dropbear_log(LOG_WARNING,"Not checking hostkey fingerprint for the moment"); | |
91 | |
92 sign_key_free(hostkey); | |
93 hostkey = NULL; | |
94 | |
95 send_msg_newkeys(); | |
96 ses.requirenext = SSH_MSG_NEWKEYS; | |
97 TRACE(("leave recv_msg_kexdh_init")); | |
98 } |