annotate cli-kex.c @ 33:f789045062e6

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