comparison svr-kex.c @ 285:1b9e69c058d2

propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 20dccfc09627970a312d77fb41dc2970b62689c3) to branch 'au.asn.ucc.matt.dropbear' (head fdf4a7a3b97ae5046139915de7e40399cceb2c01)
author Matt Johnston <matt@ucc.asn.au>
date Wed, 08 Mar 2006 13:23:58 +0000
parents 0cfba3034be5
children 454a34b2dfd1
comparison
equal deleted inserted replaced
281:997e6f7dc01e 285:1b9e69c058d2
1 /*
2 * Dropbear - a SSH2 server
3 *
4 * Copyright (c) 2002,2003 Matt Johnston
5 * Copyright (c) 2004 by Mihnea Stoenescu
6 * All rights reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE. */
25
26 #include "includes.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"
37
38
39 static void send_msg_kexdh_reply(mp_int *dh_e);
40
41 /* Handle a diffie-hellman key exchange initialisation. This involves
42 * calculating a session key reply value, and corresponding hash. These
43 * are carried out by send_msg_kexdh_reply(). recv_msg_kexdh_init() calls
44 * that function, then brings the new keys into use */
45 void recv_msg_kexdh_init() {
46
47 DEF_MP_INT(dh_e);
48
49 TRACE(("enter recv_msg_kexdh_init"))
50 if (!ses.kexstate.recvkexinit) {
51 dropbear_exit("Premature kexdh_init message received");
52 }
53
54 m_mp_init(&dh_e);
55 buf_getmpint(ses.payload, &dh_e);
56
57 send_msg_kexdh_reply(&dh_e);
58
59 mp_clear(&dh_e);
60
61 send_msg_newkeys();
62 ses.requirenext = SSH_MSG_NEWKEYS;
63 TRACE(("leave recv_msg_kexdh_init"))
64 }
65
66 /* Generate our side of the diffie-hellman key exchange value (dh_f), and
67 * calculate the session key using the diffie-hellman algorithm. Following
68 * that, the session hash is calculated, and signed with RSA or DSS. The
69 * result is sent to the client.
70 *
71 * See the ietf-secsh-transport draft, section 6, for details */
72 static void send_msg_kexdh_reply(mp_int *dh_e) {
73
74 DEF_MP_INT(dh_y);
75 DEF_MP_INT(dh_f);
76
77 TRACE(("enter send_msg_kexdh_reply"))
78 m_mp_init_multi(&dh_y, &dh_f, NULL);
79
80 gen_kexdh_vals(&dh_f, &dh_y);
81
82 kexdh_comb_key(&dh_f, &dh_y, dh_e, svr_opts.hostkey);
83 mp_clear(&dh_y);
84
85 /* we can start creating the kexdh_reply packet */
86 CHECKCLEARTOWRITE();
87 buf_putbyte(ses.writepayload, SSH_MSG_KEXDH_REPLY);
88 buf_put_pub_key(ses.writepayload, svr_opts.hostkey,
89 ses.newkeys->algo_hostkey);
90
91 /* put f */
92 buf_putmpint(ses.writepayload, &dh_f);
93 mp_clear(&dh_f);
94
95 /* calc the signature */
96 buf_put_sign(ses.writepayload, svr_opts.hostkey,
97 ses.newkeys->algo_hostkey, ses.hash, SHA1_HASH_SIZE);
98
99 /* the SSH_MSG_KEXDH_REPLY is done */
100 encrypt_packet();
101
102 TRACE(("leave send_msg_kexdh_reply"))
103 }
104