Mercurial > dropbear
annotate common-kex.c @ 815:35183e8a7851
Improve EOF handling for half-close. Patch from Catalin Patulea
Fixes the situation
$ ./dbclient [email protected] 'cat; echo foo'
^D
<no output>
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 21 Sep 2013 00:17:22 +0800 |
parents | f110d321fe7a |
children | 7dcb46da72d9 |
rev | line source |
---|---|
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 /* |
74
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
36
diff
changeset
|
2 * Dropbear SSH |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
3 * |
33 | 4 * Copyright (c) 2002-2004 Matt Johnston |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
5 * Portions Copyright (c) 2004 by Mihnea Stoenescu |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
6 * All rights reserved. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
7 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
8 * Permission is hereby granted, free of charge, to any person obtaining a copy |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
9 * of this software and associated documentation files (the "Software"), to deal |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
10 * in the Software without restriction, including without limitation the rights |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
12 * copies of the Software, and to permit persons to whom the Software is |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
13 * furnished to do so, subject to the following conditions: |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
14 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
15 * The above copyright notice and this permission notice shall be included in |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
16 * all copies or substantial portions of the Software. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
17 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 * SOFTWARE. */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
25 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
26 #include "includes.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
27 #include "dbutil.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 #include "algo.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 #include "buffer.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 #include "session.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 #include "kex.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
32 #include "ssh.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
33 #include "packet.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 #include "bignum.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
35 #include "random.h" |
575
f9b5dc0cba61
- Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents:
555
diff
changeset
|
36 #include "runopts.h" |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
37 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
38 /* diffie-hellman-group1-sha1 value for p */ |
595
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
39 #define DH_P_1_LEN 128 |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
40 static const unsigned char dh_p_1[DH_P_1_LEN] = { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
41 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
42 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
43 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
44 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
45 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
46 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
47 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
48 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
49 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
50 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE6, 0x53, 0x81, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
51 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
52 |
595
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
53 /* diffie-hellman-group14-sha1 value for p */ |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
54 #define DH_P_14_LEN 256 |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
55 static const unsigned char dh_p_14[DH_P_14_LEN] = { |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
56 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
57 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
58 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
59 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
60 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
61 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
62 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
63 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
64 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
65 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
66 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
67 0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
68 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
69 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
70 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
71 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
72 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
73 0xEC, 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
74 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
75 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
76 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68, 0xFF, 0xFF, 0xFF, 0xFF, |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
77 0xFF, 0xFF, 0xFF, 0xFF}; |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
78 |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
79 /* Same for group1 and group14 */ |
227 | 80 static const int DH_G_VAL = 2; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
81 |
33 | 82 static void kexinitialise(); |
753
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
83 static void gen_new_keys(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
84 #ifndef DISABLE_ZLIB |
771 | 85 static void gen_new_zstream_recv(); |
86 static void gen_new_zstream_trans(); | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
87 #endif |
33 | 88 static void read_kex_algos(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
89 /* helper function for gen_new_keys */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
90 static void hashkeys(unsigned char *out, int outlen, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
91 const hash_state * hs, unsigned const char X); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
92 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
93 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
94 /* Send our list of algorithms we can use */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
95 void send_msg_kexinit() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
96 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
97 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
98 buf_putbyte(ses.writepayload, SSH_MSG_KEXINIT); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
99 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
100 /* cookie */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
101 genrandom(buf_getwriteptr(ses.writepayload, 16), 16); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
102 buf_incrwritepos(ses.writepayload, 16); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
103 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
104 /* kex algos */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
105 buf_put_algolist(ses.writepayload, sshkex); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
106 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
107 /* server_host_key_algorithms */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
108 buf_put_algolist(ses.writepayload, sshhostkey); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
109 |
683
63f8d6c469cf
ENABLE_USER_ALGO_LIST should work for the client
Matt Johnston <matt@ucc.asn.au>
parents:
682
diff
changeset
|
110 /* encryption_algorithms_client_to_server */ |
63f8d6c469cf
ENABLE_USER_ALGO_LIST should work for the client
Matt Johnston <matt@ucc.asn.au>
parents:
682
diff
changeset
|
111 buf_put_algolist(ses.writepayload, sshciphers); |
63f8d6c469cf
ENABLE_USER_ALGO_LIST should work for the client
Matt Johnston <matt@ucc.asn.au>
parents:
682
diff
changeset
|
112 |
63f8d6c469cf
ENABLE_USER_ALGO_LIST should work for the client
Matt Johnston <matt@ucc.asn.au>
parents:
682
diff
changeset
|
113 /* encryption_algorithms_server_to_client */ |
63f8d6c469cf
ENABLE_USER_ALGO_LIST should work for the client
Matt Johnston <matt@ucc.asn.au>
parents:
682
diff
changeset
|
114 buf_put_algolist(ses.writepayload, sshciphers); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
115 |
683
63f8d6c469cf
ENABLE_USER_ALGO_LIST should work for the client
Matt Johnston <matt@ucc.asn.au>
parents:
682
diff
changeset
|
116 /* mac_algorithms_client_to_server */ |
63f8d6c469cf
ENABLE_USER_ALGO_LIST should work for the client
Matt Johnston <matt@ucc.asn.au>
parents:
682
diff
changeset
|
117 buf_put_algolist(ses.writepayload, sshhashes); |
63f8d6c469cf
ENABLE_USER_ALGO_LIST should work for the client
Matt Johnston <matt@ucc.asn.au>
parents:
682
diff
changeset
|
118 |
63f8d6c469cf
ENABLE_USER_ALGO_LIST should work for the client
Matt Johnston <matt@ucc.asn.au>
parents:
682
diff
changeset
|
119 /* mac_algorithms_server_to_client */ |
63f8d6c469cf
ENABLE_USER_ALGO_LIST should work for the client
Matt Johnston <matt@ucc.asn.au>
parents:
682
diff
changeset
|
120 buf_put_algolist(ses.writepayload, sshhashes); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
121 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
122 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
123 /* compression_algorithms_client_to_server */ |
575
f9b5dc0cba61
- Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents:
555
diff
changeset
|
124 buf_put_algolist(ses.writepayload, ses.compress_algos); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
125 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
126 /* compression_algorithms_server_to_client */ |
575
f9b5dc0cba61
- Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents:
555
diff
changeset
|
127 buf_put_algolist(ses.writepayload, ses.compress_algos); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
128 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
129 /* languages_client_to_server */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
130 buf_putstring(ses.writepayload, "", 0); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
131 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
132 /* languages_server_to_client */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
133 buf_putstring(ses.writepayload, "", 0); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
134 |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
135 /* first_kex_packet_follows */ |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
136 buf_putbyte(ses.writepayload, (ses.send_kex_first_guess != NULL)); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
137 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
138 /* reserved unit32 */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
139 buf_putint(ses.writepayload, 0); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
140 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
141 /* set up transmitted kex packet buffer for hashing. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
142 * This is freed after the end of the kex */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
143 ses.transkexinit = buf_newcopy(ses.writepayload); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
144 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
145 encrypt_packet(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
146 ses.dataallowed = 0; /* don't send other packets during kex */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
147 |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
148 ses.kexstate.sentkexinit = 1; |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
149 |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
150 ses.newkeys = (struct key_context*)m_malloc(sizeof(struct key_context)); |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
151 |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
152 if (ses.send_kex_first_guess) { |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
153 ses.newkeys->algo_kex = sshkex[0].val; |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
154 ses.newkeys->algo_hostkey = sshhostkey[0].val; |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
155 ses.send_kex_first_guess(); |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
156 } |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
157 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
116
diff
changeset
|
158 TRACE(("DATAALLOWED=0")) |
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
116
diff
changeset
|
159 TRACE(("-> KEXINIT")) |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
160 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
161 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
162 |
771 | 163 static void switch_keys() { |
753
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
164 TRACE2(("enter switch_keys")) |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
165 if (!(ses.kexstate.sentkexinit && ses.kexstate.recvkexinit)) { |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
166 dropbear_exit("Unexpected newkeys message"); |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
167 } |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
168 |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
169 if (!ses.keys) { |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
170 ses.keys = m_malloc(sizeof(*ses.newkeys)); |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
171 } |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
172 if (ses.kexstate.recvnewkeys && ses.newkeys->recv.valid) { |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
173 TRACE(("switch_keys recv")) |
781
f110d321fe7a
Fix build when zlib is disabled, from
Matt Johnston <matt@ucc.asn.au>
parents:
775
diff
changeset
|
174 #ifndef DISABLE_ZLIB |
771 | 175 gen_new_zstream_recv(); |
781
f110d321fe7a
Fix build when zlib is disabled, from
Matt Johnston <matt@ucc.asn.au>
parents:
775
diff
changeset
|
176 #endif |
753
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
177 ses.keys->recv = ses.newkeys->recv; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
178 m_burn(&ses.newkeys->recv, sizeof(ses.newkeys->recv)); |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
179 ses.newkeys->recv.valid = 0; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
180 } |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
181 if (ses.kexstate.sentnewkeys && ses.newkeys->trans.valid) { |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
182 TRACE(("switch_keys trans")) |
781
f110d321fe7a
Fix build when zlib is disabled, from
Matt Johnston <matt@ucc.asn.au>
parents:
775
diff
changeset
|
183 #ifndef DISABLE_ZLIB |
771 | 184 gen_new_zstream_trans(); |
781
f110d321fe7a
Fix build when zlib is disabled, from
Matt Johnston <matt@ucc.asn.au>
parents:
775
diff
changeset
|
185 #endif |
753
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
186 ses.keys->trans = ses.newkeys->trans; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
187 m_burn(&ses.newkeys->trans, sizeof(ses.newkeys->trans)); |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
188 ses.newkeys->trans.valid = 0; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
189 } |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
190 if (ses.kexstate.sentnewkeys && ses.kexstate.recvnewkeys) |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
191 { |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
192 TRACE(("switch_keys done")) |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
193 ses.keys->algo_kex = ses.newkeys->algo_kex; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
194 ses.keys->algo_hostkey = ses.newkeys->algo_hostkey; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
195 ses.keys->allow_compress = 0; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
196 m_free(ses.newkeys); |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
197 ses.newkeys = NULL; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
198 kexinitialise(); |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
199 } |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
200 TRACE2(("leave switch_keys")) |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
201 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
202 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
203 /* Bring new keys into use after a key exchange, and let the client know*/ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
204 void send_msg_newkeys() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
205 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
116
diff
changeset
|
206 TRACE(("enter send_msg_newkeys")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
207 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
208 /* generate the kexinit request */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
209 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
210 buf_putbyte(ses.writepayload, SSH_MSG_NEWKEYS); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
211 encrypt_packet(); |
753
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
212 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
213 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
214 /* set up our state */ |
753
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
215 ses.kexstate.sentnewkeys = 1; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
216 ses.kexstate.donefirstkex = 1; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
217 ses.dataallowed = 1; /* we can send other packets again now */ |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
218 gen_new_keys(); |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
219 switch_keys(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
220 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
116
diff
changeset
|
221 TRACE(("leave send_msg_newkeys")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
222 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
223 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
224 /* Bring the new keys into use after a key exchange */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
225 void recv_msg_newkeys() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
226 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
116
diff
changeset
|
227 TRACE(("enter recv_msg_newkeys")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
228 |
753
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
229 ses.kexstate.recvnewkeys = 1; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
230 switch_keys(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
231 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
116
diff
changeset
|
232 TRACE(("leave recv_msg_newkeys")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
233 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
234 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
235 |
33 | 236 /* Set up the kex for the first time */ |
237 void kexfirstinitialise() { | |
575
f9b5dc0cba61
- Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents:
555
diff
changeset
|
238 ses.kexstate.donefirstkex = 0; |
33 | 239 |
575
f9b5dc0cba61
- Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents:
555
diff
changeset
|
240 #ifndef DISABLE_ZLIB |
f9b5dc0cba61
- Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents:
555
diff
changeset
|
241 if (opts.enable_compress) { |
f9b5dc0cba61
- Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents:
555
diff
changeset
|
242 ses.compress_algos = ssh_compress; |
f9b5dc0cba61
- Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents:
555
diff
changeset
|
243 } else |
f9b5dc0cba61
- Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents:
555
diff
changeset
|
244 #endif |
f9b5dc0cba61
- Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents:
555
diff
changeset
|
245 { |
f9b5dc0cba61
- Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents:
555
diff
changeset
|
246 ses.compress_algos = ssh_nocompress; |
f9b5dc0cba61
- Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents:
555
diff
changeset
|
247 } |
33 | 248 kexinitialise(); |
249 } | |
250 | |
251 /* Reset the kex state, ready for a new negotiation */ | |
252 static void kexinitialise() { | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
253 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
116
diff
changeset
|
254 TRACE(("kexinitialise()")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
255 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
256 /* sent/recv'd MSG_KEXINIT */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
257 ses.kexstate.sentkexinit = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
258 ses.kexstate.recvkexinit = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
259 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
260 /* sent/recv'd MSG_NEWKEYS */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
261 ses.kexstate.recvnewkeys = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
262 ses.kexstate.sentnewkeys = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
263 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
264 /* first_packet_follows */ |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
265 ses.kexstate.them_firstfollows = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
266 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
267 ses.kexstate.datatrans = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
268 ses.kexstate.datarecv = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
269 |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
270 ses.kexstate.our_first_follows_matches = 0; |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
271 |
454
7e43f5e473b9
- Add -K keepalive flag for dropbear and dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
410
diff
changeset
|
272 ses.kexstate.lastkextime = time(NULL); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
273 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
274 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
275 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
276 /* Helper function for gen_new_keys, creates a hash. It makes a copy of the |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
277 * already initialised hash_state hs, which should already have processed |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
278 * the dh_K and hash, since these are common. X is the letter 'A', 'B' etc. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
279 * out must have at least min(SHA1_HASH_SIZE, outlen) bytes allocated. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
280 * |
409
0e69e948caba
Add comments about requiring keysize <= 2*SHA1_HASH_SIZE
Matt Johnston <matt@ucc.asn.au>
parents:
257
diff
changeset
|
281 * See Section 7.2 of rfc4253 (ssh transport) for details */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
282 static void hashkeys(unsigned char *out, int outlen, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
283 const hash_state * hs, const unsigned char X) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
284 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
285 hash_state hs2; |
679
03073a27abb3
- Add hmac-sha2-256 and hmac-sha2-512. Needs debugging, seems to be
Matt Johnston <matt@ucc.asn.au>
parents:
648
diff
changeset
|
286 int offset; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
287 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
288 memcpy(&hs2, hs, sizeof(hash_state)); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
289 sha1_process(&hs2, &X, 1); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
290 sha1_process(&hs2, ses.session_id, SHA1_HASH_SIZE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
291 sha1_done(&hs2, out); |
679
03073a27abb3
- Add hmac-sha2-256 and hmac-sha2-512. Needs debugging, seems to be
Matt Johnston <matt@ucc.asn.au>
parents:
648
diff
changeset
|
292 for (offset = SHA1_HASH_SIZE; |
03073a27abb3
- Add hmac-sha2-256 and hmac-sha2-512. Needs debugging, seems to be
Matt Johnston <matt@ucc.asn.au>
parents:
648
diff
changeset
|
293 offset < outlen; |
03073a27abb3
- Add hmac-sha2-256 and hmac-sha2-512. Needs debugging, seems to be
Matt Johnston <matt@ucc.asn.au>
parents:
648
diff
changeset
|
294 offset += SHA1_HASH_SIZE) |
03073a27abb3
- Add hmac-sha2-256 and hmac-sha2-512. Needs debugging, seems to be
Matt Johnston <matt@ucc.asn.au>
parents:
648
diff
changeset
|
295 { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
296 /* need to extend */ |
679
03073a27abb3
- Add hmac-sha2-256 and hmac-sha2-512. Needs debugging, seems to be
Matt Johnston <matt@ucc.asn.au>
parents:
648
diff
changeset
|
297 unsigned char k2[SHA1_HASH_SIZE]; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
298 memcpy(&hs2, hs, sizeof(hash_state)); |
679
03073a27abb3
- Add hmac-sha2-256 and hmac-sha2-512. Needs debugging, seems to be
Matt Johnston <matt@ucc.asn.au>
parents:
648
diff
changeset
|
299 sha1_process(&hs2, out, offset); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
300 sha1_done(&hs2, k2); |
679
03073a27abb3
- Add hmac-sha2-256 and hmac-sha2-512. Needs debugging, seems to be
Matt Johnston <matt@ucc.asn.au>
parents:
648
diff
changeset
|
301 memcpy(&out[offset], k2, MIN(outlen - offset, SHA1_HASH_SIZE)); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
302 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
303 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
304 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
305 /* Generate the actual encryption/integrity keys, using the results of the |
603
3aa74a4d83ae
Refer to RFCs rather than drafts, update some section references
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
306 * key exchange, as specified in section 7.2 of the transport rfc 4253. |
3aa74a4d83ae
Refer to RFCs rather than drafts, update some section references
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
307 * This occurs after the DH key-exchange. |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
308 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
309 * ses.newkeys is the new set of keys which are generated, these are only |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
310 * taken into use after both sides have sent a newkeys message */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
311 |
753
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
312 static void gen_new_keys() { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
313 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
314 unsigned char C2S_IV[MAX_IV_LEN]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
315 unsigned char C2S_key[MAX_KEY_LEN]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
316 unsigned char S2C_IV[MAX_IV_LEN]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
317 unsigned char S2C_key[MAX_KEY_LEN]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
318 /* unsigned char key[MAX_KEY_LEN]; */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
319 unsigned char *trans_IV, *trans_key, *recv_IV, *recv_key; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
320 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
321 hash_state hs; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
322 unsigned int C2S_keysize, S2C_keysize; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
323 char mactransletter, macrecvletter; /* Client or server specific */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
324 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
116
diff
changeset
|
325 TRACE(("enter gen_new_keys")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
326 /* the dh_K and hash are the start of all hashes, we make use of that */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
327 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
328 sha1_init(&hs); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
329 sha1_process_mp(&hs, ses.dh_K); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
330 mp_clear(ses.dh_K); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
331 m_free(ses.dh_K); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
332 sha1_process(&hs, ses.hash, SHA1_HASH_SIZE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
333 m_burn(ses.hash, SHA1_HASH_SIZE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
334 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
335 if (IS_DROPBEAR_CLIENT) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
336 trans_IV = C2S_IV; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
337 recv_IV = S2C_IV; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
338 trans_key = C2S_key; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
339 recv_key = S2C_key; |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
340 C2S_keysize = ses.newkeys->trans.algo_crypt->keysize; |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
341 S2C_keysize = ses.newkeys->recv.algo_crypt->keysize; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
342 mactransletter = 'E'; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
343 macrecvletter = 'F'; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
344 } else { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
345 trans_IV = S2C_IV; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
346 recv_IV = C2S_IV; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
347 trans_key = S2C_key; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
348 recv_key = C2S_key; |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
349 C2S_keysize = ses.newkeys->recv.algo_crypt->keysize; |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
350 S2C_keysize = ses.newkeys->trans.algo_crypt->keysize; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
351 mactransletter = 'F'; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
352 macrecvletter = 'E'; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
353 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
354 |
35
0ad5fb979f42
set the isserver flag (oops)
Matt Johnston <matt@ucc.asn.au>
parents:
34
diff
changeset
|
355 hashkeys(C2S_IV, SHA1_HASH_SIZE, &hs, 'A'); |
0ad5fb979f42
set the isserver flag (oops)
Matt Johnston <matt@ucc.asn.au>
parents:
34
diff
changeset
|
356 hashkeys(S2C_IV, SHA1_HASH_SIZE, &hs, 'B'); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
357 hashkeys(C2S_key, C2S_keysize, &hs, 'C'); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
358 hashkeys(S2C_key, S2C_keysize, &hs, 'D'); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
359 |
681
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
360 if (ses.newkeys->recv.algo_crypt->cipherdesc != NULL) { |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
361 int recv_cipher = find_cipher(ses.newkeys->recv.algo_crypt->cipherdesc->name); |
512
0129fd8ccc71
Update nocrypto branch to current head
Matt Johnston <matt@ucc.asn.au>
parents:
511
diff
changeset
|
362 if (recv_cipher < 0) |
681
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
363 dropbear_exit("Crypto error"); |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
364 if (ses.newkeys->recv.crypt_mode->start(recv_cipher, |
252
29afa62b5450
- a hack for grahame to run dropbear with "none" cipher.
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
365 recv_IV, recv_key, |
681
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
366 ses.newkeys->recv.algo_crypt->keysize, 0, |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
367 &ses.newkeys->recv.cipher_state) != CRYPT_OK) { |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
368 dropbear_exit("Crypto error"); |
252
29afa62b5450
- a hack for grahame to run dropbear with "none" cipher.
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
369 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
370 } |
502 | 371 |
681
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
372 if (ses.newkeys->trans.algo_crypt->cipherdesc != NULL) { |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
373 int trans_cipher = find_cipher(ses.newkeys->trans.algo_crypt->cipherdesc->name); |
512
0129fd8ccc71
Update nocrypto branch to current head
Matt Johnston <matt@ucc.asn.au>
parents:
511
diff
changeset
|
374 if (trans_cipher < 0) |
681
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
375 dropbear_exit("Crypto error"); |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
376 if (ses.newkeys->trans.crypt_mode->start(trans_cipher, |
252
29afa62b5450
- a hack for grahame to run dropbear with "none" cipher.
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
377 trans_IV, trans_key, |
681
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
378 ses.newkeys->trans.algo_crypt->keysize, 0, |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
379 &ses.newkeys->trans.cipher_state) != CRYPT_OK) { |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
380 dropbear_exit("Crypto error"); |
252
29afa62b5450
- a hack for grahame to run dropbear with "none" cipher.
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
381 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
382 } |
512
0129fd8ccc71
Update nocrypto branch to current head
Matt Johnston <matt@ucc.asn.au>
parents:
511
diff
changeset
|
383 |
681
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
384 if (ses.newkeys->trans.algo_mac->hashdesc != NULL) { |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
385 hashkeys(ses.newkeys->trans.mackey, |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
386 ses.newkeys->trans.algo_mac->keysize, &hs, mactransletter); |
712
bf0ac0512ef7
Fix "-m none" case and ugly typo
Matt Johnston <matt@ucc.asn.au>
parents:
684
diff
changeset
|
387 ses.newkeys->trans.hash_index = find_hash(ses.newkeys->trans.algo_mac->hashdesc->name); |
252
29afa62b5450
- a hack for grahame to run dropbear with "none" cipher.
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
388 } |
712
bf0ac0512ef7
Fix "-m none" case and ugly typo
Matt Johnston <matt@ucc.asn.au>
parents:
684
diff
changeset
|
389 |
681
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
390 if (ses.newkeys->recv.algo_mac->hashdesc != NULL) { |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
391 hashkeys(ses.newkeys->recv.mackey, |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
392 ses.newkeys->recv.algo_mac->keysize, &hs, macrecvletter); |
712
bf0ac0512ef7
Fix "-m none" case and ugly typo
Matt Johnston <matt@ucc.asn.au>
parents:
684
diff
changeset
|
393 ses.newkeys->recv.hash_index = find_hash(ses.newkeys->recv.algo_mac->hashdesc->name); |
252
29afa62b5450
- a hack for grahame to run dropbear with "none" cipher.
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
394 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
395 |
753
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
396 /* Ready to switch over */ |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
397 ses.newkeys->trans.valid = 1; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
398 ses.newkeys->recv.valid = 1; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
399 |
648
4222a1039b06
Clear a few buffers when possible
Matt Johnston <matt@ucc.asn.au>
parents:
603
diff
changeset
|
400 m_burn(C2S_IV, sizeof(C2S_IV)); |
4222a1039b06
Clear a few buffers when possible
Matt Johnston <matt@ucc.asn.au>
parents:
603
diff
changeset
|
401 m_burn(C2S_key, sizeof(C2S_key)); |
4222a1039b06
Clear a few buffers when possible
Matt Johnston <matt@ucc.asn.au>
parents:
603
diff
changeset
|
402 m_burn(S2C_IV, sizeof(S2C_IV)); |
4222a1039b06
Clear a few buffers when possible
Matt Johnston <matt@ucc.asn.au>
parents:
603
diff
changeset
|
403 m_burn(S2C_key, sizeof(S2C_key)); |
4222a1039b06
Clear a few buffers when possible
Matt Johnston <matt@ucc.asn.au>
parents:
603
diff
changeset
|
404 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
116
diff
changeset
|
405 TRACE(("leave gen_new_keys")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
406 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
407 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
408 #ifndef DISABLE_ZLIB |
501
d58c478bd399
Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
409 |
d58c478bd399
Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
410 int is_compress_trans() { |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
411 return ses.keys->trans.algo_comp == DROPBEAR_COMP_ZLIB |
501
d58c478bd399
Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
412 || (ses.authstate.authdone |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
413 && ses.keys->trans.algo_comp == DROPBEAR_COMP_ZLIB_DELAY); |
501
d58c478bd399
Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
414 } |
d58c478bd399
Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
415 |
d58c478bd399
Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
416 int is_compress_recv() { |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
417 return ses.keys->recv.algo_comp == DROPBEAR_COMP_ZLIB |
501
d58c478bd399
Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
418 || (ses.authstate.authdone |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
419 && ses.keys->recv.algo_comp == DROPBEAR_COMP_ZLIB_DELAY); |
501
d58c478bd399
Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
420 } |
d58c478bd399
Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
421 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
422 /* Set up new zlib compression streams, close the old ones. Only |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
423 * called from gen_new_keys() */ |
771 | 424 static void gen_new_zstream_recv() { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
425 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
426 /* create new zstreams */ |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
427 if (ses.newkeys->recv.algo_comp == DROPBEAR_COMP_ZLIB |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
428 || ses.newkeys->recv.algo_comp == DROPBEAR_COMP_ZLIB_DELAY) { |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
429 ses.newkeys->recv.zstream = (z_streamp)m_malloc(sizeof(z_stream)); |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
430 ses.newkeys->recv.zstream->zalloc = Z_NULL; |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
431 ses.newkeys->recv.zstream->zfree = Z_NULL; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
432 |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
433 if (inflateInit(ses.newkeys->recv.zstream) != Z_OK) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
434 dropbear_exit("zlib error"); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
435 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
436 } else { |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
437 ses.newkeys->recv.zstream = NULL; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
438 } |
771 | 439 /* clean up old keys */ |
440 if (ses.keys->recv.zstream != NULL) { | |
441 if (inflateEnd(ses.keys->recv.zstream) == Z_STREAM_ERROR) { | |
442 /* Z_DATA_ERROR is ok, just means that stream isn't ended */ | |
443 dropbear_exit("Crypto error"); | |
444 } | |
445 m_free(ses.keys->recv.zstream); | |
446 } | |
447 } | |
448 | |
449 static void gen_new_zstream_trans() { | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
450 |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
451 if (ses.newkeys->trans.algo_comp == DROPBEAR_COMP_ZLIB |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
452 || ses.newkeys->trans.algo_comp == DROPBEAR_COMP_ZLIB_DELAY) { |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
453 ses.newkeys->trans.zstream = (z_streamp)m_malloc(sizeof(z_stream)); |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
454 ses.newkeys->trans.zstream->zalloc = Z_NULL; |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
455 ses.newkeys->trans.zstream->zfree = Z_NULL; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
456 |
555
daf52f813328
- Add option to change zlib windowBits/memLevel
Matt Johnston <matt@ucc.asn.au>
parents:
534
diff
changeset
|
457 if (deflateInit2(ses.newkeys->trans.zstream, Z_DEFAULT_COMPRESSION, |
daf52f813328
- Add option to change zlib windowBits/memLevel
Matt Johnston <matt@ucc.asn.au>
parents:
534
diff
changeset
|
458 Z_DEFLATED, DROPBEAR_ZLIB_WINDOW_BITS, |
daf52f813328
- Add option to change zlib windowBits/memLevel
Matt Johnston <matt@ucc.asn.au>
parents:
534
diff
changeset
|
459 DROPBEAR_ZLIB_MEM_LEVEL, Z_DEFAULT_STRATEGY) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
460 != Z_OK) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
461 dropbear_exit("zlib error"); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
462 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
463 } else { |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
464 ses.newkeys->trans.zstream = NULL; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
465 } |
501
d58c478bd399
Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
466 |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
467 if (ses.keys->trans.zstream != NULL) { |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
468 if (deflateEnd(ses.keys->trans.zstream) == Z_STREAM_ERROR) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
469 /* Z_DATA_ERROR is ok, just means that stream isn't ended */ |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
575
diff
changeset
|
470 dropbear_exit("Crypto error"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
471 } |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
472 m_free(ses.keys->trans.zstream); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
473 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
474 } |
501
d58c478bd399
Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
475 #endif /* DISABLE_ZLIB */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
476 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
477 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
478 /* Executed upon receiving a kexinit message from the client to initiate |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
479 * key exchange. If we haven't already done so, we send the list of our |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
480 * preferred algorithms. The client's requested algorithms are processed, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
481 * and we calculate the first portion of the key-exchange-hash for used |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
482 * later in the key exchange. No response is sent, as the client should |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
483 * initiate the diffie-hellman key exchange */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
484 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
485 /* Originally from kex.c, generalized for cli/svr mode --mihnea */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
486 /* Belongs in common_kex.c where it should be moved after review */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
487 void recv_msg_kexinit() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
488 |
257
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
489 unsigned int kexhashbuf_len = 0; |
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
490 unsigned int remote_ident_len = 0; |
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
491 unsigned int local_ident_len = 0; |
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
492 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
116
diff
changeset
|
493 TRACE(("<- KEXINIT")) |
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
116
diff
changeset
|
494 TRACE(("enter recv_msg_kexinit")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
495 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
496 if (!ses.kexstate.sentkexinit) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
497 /* we need to send a kex packet */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
498 send_msg_kexinit(); |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
116
diff
changeset
|
499 TRACE(("continue recv_msg_kexinit: sent kexinit")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
500 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
501 |
257
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
502 /* start the kex hash */ |
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
503 local_ident_len = strlen(LOCAL_IDENT); |
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
504 remote_ident_len = strlen((char*)ses.remoteident); |
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
505 |
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
506 kexhashbuf_len = local_ident_len + remote_ident_len |
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
507 + ses.transkexinit->len + ses.payload->len |
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
508 + KEXHASHBUF_MAX_INTS; |
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
509 |
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
510 ses.kexhashbuf = buf_new(kexhashbuf_len); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
511 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
512 if (IS_DROPBEAR_CLIENT) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
513 |
26 | 514 /* read the peer's choice of algos */ |
33 | 515 read_kex_algos(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
516 |
26 | 517 /* V_C, the client's version string (CR and NL excluded) */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
518 buf_putstring(ses.kexhashbuf, |
257
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
519 (unsigned char*)LOCAL_IDENT, local_ident_len); |
26 | 520 /* V_S, the server's version string (CR and NL excluded) */ |
257
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
521 buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
522 |
26 | 523 /* I_C, the payload of the client's SSH_MSG_KEXINIT */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
524 buf_putstring(ses.kexhashbuf, |
257
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
525 ses.transkexinit->data, ses.transkexinit->len); |
26 | 526 /* I_S, the payload of the server's SSH_MSG_KEXINIT */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
527 buf_setpos(ses.payload, 0); |
257
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
528 buf_putstring(ses.kexhashbuf, ses.payload->data, ses.payload->len); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
529 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
530 } else { |
26 | 531 /* SERVER */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
532 |
26 | 533 /* read the peer's choice of algos */ |
33 | 534 read_kex_algos(); |
26 | 535 /* V_C, the client's version string (CR and NL excluded) */ |
257
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
536 buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len); |
26 | 537 /* V_S, the server's version string (CR and NL excluded) */ |
257
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
538 buf_putstring(ses.kexhashbuf, |
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
539 (unsigned char*)LOCAL_IDENT, local_ident_len); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
540 |
26 | 541 /* I_C, the payload of the client's SSH_MSG_KEXINIT */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
542 buf_setpos(ses.payload, 0); |
257
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
543 buf_putstring(ses.kexhashbuf, ses.payload->data, ses.payload->len); |
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
544 |
26 | 545 /* I_S, the payload of the server's SSH_MSG_KEXINIT */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
546 buf_putstring(ses.kexhashbuf, |
257
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
547 ses.transkexinit->data, ses.transkexinit->len); |
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
548 |
775
2f1c199b6e4b
requirenext fixup for firstkexfollows
Matt Johnston <matt@ucc.asn.au>
parents:
771
diff
changeset
|
549 ses.requirenext[0] = SSH_MSG_KEXDH_INIT; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
550 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
551 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
552 buf_free(ses.transkexinit); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
553 ses.transkexinit = NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
554 /* the rest of ses.kexhashbuf will be done after DH exchange */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
555 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
556 ses.kexstate.recvkexinit = 1; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
557 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
116
diff
changeset
|
558 TRACE(("leave recv_msg_kexinit")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
559 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
560 |
595
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
561 static void load_dh_p(mp_int * dh_p) |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
562 { |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
563 switch (ses.newkeys->algo_kex) { |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
564 case DROPBEAR_KEX_DH_GROUP1: |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
565 bytes_to_mp(dh_p, dh_p_1, DH_P_1_LEN); |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
566 break; |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
567 case DROPBEAR_KEX_DH_GROUP14: |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
568 bytes_to_mp(dh_p, dh_p_14, DH_P_14_LEN); |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
569 break; |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
570 } |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
571 } |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
572 |
26 | 573 /* Initialises and generate one side of the diffie-hellman key exchange values. |
603
3aa74a4d83ae
Refer to RFCs rather than drafts, update some section references
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
574 * See the transport rfc 4253 section 8 for details */ |
84
29a5c7c62350
default initialisers for mp_ints
Matt Johnston <matt@ucc.asn.au>
parents:
79
diff
changeset
|
575 /* dh_pub and dh_priv MUST be already initialised */ |
26 | 576 void gen_kexdh_vals(mp_int *dh_pub, mp_int *dh_priv) { |
577 | |
84
29a5c7c62350
default initialisers for mp_ints
Matt Johnston <matt@ucc.asn.au>
parents:
79
diff
changeset
|
578 DEF_MP_INT(dh_p); |
29a5c7c62350
default initialisers for mp_ints
Matt Johnston <matt@ucc.asn.au>
parents:
79
diff
changeset
|
579 DEF_MP_INT(dh_q); |
29a5c7c62350
default initialisers for mp_ints
Matt Johnston <matt@ucc.asn.au>
parents:
79
diff
changeset
|
580 DEF_MP_INT(dh_g); |
26 | 581 |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
582 TRACE(("enter gen_kexdh_vals")) |
26 | 583 |
84
29a5c7c62350
default initialisers for mp_ints
Matt Johnston <matt@ucc.asn.au>
parents:
79
diff
changeset
|
584 m_mp_init_multi(&dh_g, &dh_p, &dh_q, NULL); |
26 | 585 |
586 /* read the prime and generator*/ | |
595
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
587 load_dh_p(&dh_p); |
26 | 588 |
589 if (mp_set_int(&dh_g, DH_G_VAL) != MP_OKAY) { | |
590 dropbear_exit("Diffie-Hellman error"); | |
591 } | |
592 | |
593 /* calculate q = (p-1)/2 */ | |
594 /* dh_priv is just a temp var here */ | |
595 if (mp_sub_d(&dh_p, 1, dh_priv) != MP_OKAY) { | |
596 dropbear_exit("Diffie-Hellman error"); | |
597 } | |
598 if (mp_div_2(dh_priv, &dh_q) != MP_OKAY) { | |
599 dropbear_exit("Diffie-Hellman error"); | |
600 } | |
601 | |
188
c9483550701b
- refactored random mp_int generation and byte->mp_int code
Matt Johnston <matt@ucc.asn.au>
parents:
179
diff
changeset
|
602 /* Generate a private portion 0 < dh_priv < dh_q */ |
c9483550701b
- refactored random mp_int generation and byte->mp_int code
Matt Johnston <matt@ucc.asn.au>
parents:
179
diff
changeset
|
603 gen_random_mpint(&dh_q, dh_priv); |
26 | 604 |
605 /* f = g^y mod p */ | |
606 if (mp_exptmod(&dh_g, dh_priv, &dh_p, dh_pub) != MP_OKAY) { | |
607 dropbear_exit("Diffie-Hellman error"); | |
608 } | |
609 mp_clear_multi(&dh_g, &dh_p, &dh_q, NULL); | |
610 } | |
611 | |
612 /* This function is fairly common between client/server, with some substitution | |
613 * of dh_e/dh_f etc. Hence these arguments: | |
614 * dh_pub_us is 'e' for the client, 'f' for the server. dh_pub_them is | |
615 * vice-versa. dh_priv is the x/y value corresponding to dh_pub_us */ | |
616 void kexdh_comb_key(mp_int *dh_pub_us, mp_int *dh_priv, mp_int *dh_pub_them, | |
617 sign_key *hostkey) { | |
618 | |
619 mp_int dh_p; | |
620 mp_int *dh_e = NULL, *dh_f = NULL; | |
621 hash_state hs; | |
622 | |
623 /* read the prime and generator*/ | |
342 | 624 m_mp_init(&dh_p); |
595
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
625 load_dh_p(&dh_p); |
26 | 626 |
627 /* Check that dh_pub_them (dh_e or dh_f) is in the range [1, p-1] */ | |
628 if (mp_cmp(dh_pub_them, &dh_p) != MP_LT | |
629 || mp_cmp_d(dh_pub_them, 0) != MP_GT) { | |
630 dropbear_exit("Diffie-Hellman error"); | |
631 } | |
632 | |
633 /* K = e^y mod p = f^x mod p */ | |
634 ses.dh_K = (mp_int*)m_malloc(sizeof(mp_int)); | |
635 m_mp_init(ses.dh_K); | |
636 if (mp_exptmod(dh_pub_them, dh_priv, &dh_p, ses.dh_K) != MP_OKAY) { | |
637 dropbear_exit("Diffie-Hellman error"); | |
638 } | |
639 | |
640 /* clear no longer needed vars */ | |
641 mp_clear_multi(&dh_p, NULL); | |
642 | |
643 /* From here on, the code needs to work with the _same_ vars on each side, | |
644 * not vice-versaing for client/server */ | |
645 if (IS_DROPBEAR_CLIENT) { | |
646 dh_e = dh_pub_us; | |
647 dh_f = dh_pub_them; | |
648 } else { | |
649 dh_e = dh_pub_them; | |
650 dh_f = dh_pub_us; | |
651 } | |
652 | |
653 /* Create the remainder of the hash buffer, to generate the exchange hash */ | |
654 /* K_S, the host key */ | |
655 buf_put_pub_key(ses.kexhashbuf, hostkey, ses.newkeys->algo_hostkey); | |
656 /* e, exchange value sent by the client */ | |
657 buf_putmpint(ses.kexhashbuf, dh_e); | |
658 /* f, exchange value sent by the server */ | |
659 buf_putmpint(ses.kexhashbuf, dh_f); | |
660 /* K, the shared secret */ | |
661 buf_putmpint(ses.kexhashbuf, ses.dh_K); | |
662 | |
663 /* calculate the hash H to sign */ | |
664 sha1_init(&hs); | |
665 buf_setpos(ses.kexhashbuf, 0); | |
666 sha1_process(&hs, buf_getptr(ses.kexhashbuf, ses.kexhashbuf->len), | |
667 ses.kexhashbuf->len); | |
668 sha1_done(&hs, ses.hash); | |
35
0ad5fb979f42
set the isserver flag (oops)
Matt Johnston <matt@ucc.asn.au>
parents:
34
diff
changeset
|
669 |
0ad5fb979f42
set the isserver flag (oops)
Matt Johnston <matt@ucc.asn.au>
parents:
34
diff
changeset
|
670 buf_burn(ses.kexhashbuf); |
26 | 671 buf_free(ses.kexhashbuf); |
672 ses.kexhashbuf = NULL; | |
673 | |
674 /* first time around, we set the session_id to H */ | |
675 if (ses.session_id == NULL) { | |
676 /* create the session_id, this never needs freeing */ | |
677 ses.session_id = (unsigned char*)m_malloc(SHA1_HASH_SIZE); | |
678 memcpy(ses.session_id, ses.hash, SHA1_HASH_SIZE); | |
679 } | |
680 } | |
681 | |
682 /* read the other side's algo list. buf_match_algo is a callback to match | |
683 * algos for the client or server. */ | |
33 | 684 static void read_kex_algos() { |
26 | 685 |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
686 /* for asymmetry */ |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
687 algo_type * c2s_hash_algo = NULL; |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
688 algo_type * s2c_hash_algo = NULL; |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
689 algo_type * c2s_cipher_algo = NULL; |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
690 algo_type * s2c_cipher_algo = NULL; |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
691 algo_type * c2s_comp_algo = NULL; |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
692 algo_type * s2c_comp_algo = NULL; |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
693 /* the generic one */ |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
694 algo_type * algo = NULL; |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
695 |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
696 /* which algo couldn't match */ |
26 | 697 char * erralgo = NULL; |
698 | |
699 int goodguess = 0; | |
700 int allgood = 1; /* we AND this with each goodguess and see if its still | |
701 true after */ | |
702 | |
703 buf_incrpos(ses.payload, 16); /* start after the cookie */ | |
704 | |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
705 memset(ses.newkeys, 0x0, sizeof(*ses.newkeys)); |
26 | 706 |
746
465fefc4f6e0
Put some #ifdef options around first-follows options in case they
Matt Johnston <matt@ucc.asn.au>
parents:
741
diff
changeset
|
707 #ifdef USE_KEXGUESS2 |
740 | 708 enum kexguess2_used kexguess2 = KEXGUESS2_LOOK; |
746
465fefc4f6e0
Put some #ifdef options around first-follows options in case they
Matt Johnston <matt@ucc.asn.au>
parents:
741
diff
changeset
|
709 #else |
465fefc4f6e0
Put some #ifdef options around first-follows options in case they
Matt Johnston <matt@ucc.asn.au>
parents:
741
diff
changeset
|
710 enum kexguess2_used kexguess2 = KEXGUESS2_NO; |
465fefc4f6e0
Put some #ifdef options around first-follows options in case they
Matt Johnston <matt@ucc.asn.au>
parents:
741
diff
changeset
|
711 #endif |
740 | 712 |
26 | 713 /* kex_algorithms */ |
741
eafdf8b363f5
Get rid of client/server specific buf_match_algo, use single
Matt Johnston <matt@ucc.asn.au>
parents:
740
diff
changeset
|
714 algo = buf_match_algo(ses.payload, sshkex, &kexguess2, &goodguess); |
26 | 715 allgood &= goodguess; |
740 | 716 if (algo == NULL || algo->val == KEXGUESS2_ALGO_ID) { |
26 | 717 erralgo = "kex"; |
718 goto error; | |
719 } | |
740 | 720 TRACE(("kexguess2 %d", kexguess2)) |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
116
diff
changeset
|
721 TRACE(("kex algo %s", algo->name)) |
26 | 722 ses.newkeys->algo_kex = algo->val; |
723 | |
724 /* server_host_key_algorithms */ | |
741
eafdf8b363f5
Get rid of client/server specific buf_match_algo, use single
Matt Johnston <matt@ucc.asn.au>
parents:
740
diff
changeset
|
725 algo = buf_match_algo(ses.payload, sshhostkey, &kexguess2, &goodguess); |
26 | 726 allgood &= goodguess; |
727 if (algo == NULL) { | |
728 erralgo = "hostkey"; | |
729 goto error; | |
730 } | |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
116
diff
changeset
|
731 TRACE(("hostkey algo %s", algo->name)) |
26 | 732 ses.newkeys->algo_hostkey = algo->val; |
733 | |
734 /* encryption_algorithms_client_to_server */ | |
741
eafdf8b363f5
Get rid of client/server specific buf_match_algo, use single
Matt Johnston <matt@ucc.asn.au>
parents:
740
diff
changeset
|
735 c2s_cipher_algo = buf_match_algo(ses.payload, sshciphers, NULL, NULL); |
116
2010f4119c1a
Check for non-matching algos properly
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
736 if (c2s_cipher_algo == NULL) { |
26 | 737 erralgo = "enc c->s"; |
738 goto error; | |
739 } | |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
740 TRACE(("enc c2s is %s", c2s_cipher_algo->name)) |
26 | 741 |
742 /* encryption_algorithms_server_to_client */ | |
741
eafdf8b363f5
Get rid of client/server specific buf_match_algo, use single
Matt Johnston <matt@ucc.asn.au>
parents:
740
diff
changeset
|
743 s2c_cipher_algo = buf_match_algo(ses.payload, sshciphers, NULL, NULL); |
116
2010f4119c1a
Check for non-matching algos properly
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
744 if (s2c_cipher_algo == NULL) { |
26 | 745 erralgo = "enc s->c"; |
746 goto error; | |
747 } | |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
748 TRACE(("enc s2c is %s", s2c_cipher_algo->name)) |
26 | 749 |
750 /* mac_algorithms_client_to_server */ | |
741
eafdf8b363f5
Get rid of client/server specific buf_match_algo, use single
Matt Johnston <matt@ucc.asn.au>
parents:
740
diff
changeset
|
751 c2s_hash_algo = buf_match_algo(ses.payload, sshhashes, NULL, NULL); |
116
2010f4119c1a
Check for non-matching algos properly
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
752 if (c2s_hash_algo == NULL) { |
26 | 753 erralgo = "mac c->s"; |
754 goto error; | |
755 } | |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
756 TRACE(("hash c2s is %s", c2s_hash_algo->name)) |
26 | 757 |
758 /* mac_algorithms_server_to_client */ | |
741
eafdf8b363f5
Get rid of client/server specific buf_match_algo, use single
Matt Johnston <matt@ucc.asn.au>
parents:
740
diff
changeset
|
759 s2c_hash_algo = buf_match_algo(ses.payload, sshhashes, NULL, NULL); |
116
2010f4119c1a
Check for non-matching algos properly
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
760 if (s2c_hash_algo == NULL) { |
26 | 761 erralgo = "mac s->c"; |
762 goto error; | |
763 } | |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
764 TRACE(("hash s2c is %s", s2c_hash_algo->name)) |
26 | 765 |
766 /* compression_algorithms_client_to_server */ | |
741
eafdf8b363f5
Get rid of client/server specific buf_match_algo, use single
Matt Johnston <matt@ucc.asn.au>
parents:
740
diff
changeset
|
767 c2s_comp_algo = buf_match_algo(ses.payload, ses.compress_algos, NULL, NULL); |
116
2010f4119c1a
Check for non-matching algos properly
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
768 if (c2s_comp_algo == NULL) { |
26 | 769 erralgo = "comp c->s"; |
770 goto error; | |
771 } | |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
772 TRACE(("hash c2s is %s", c2s_comp_algo->name)) |
26 | 773 |
774 /* compression_algorithms_server_to_client */ | |
741
eafdf8b363f5
Get rid of client/server specific buf_match_algo, use single
Matt Johnston <matt@ucc.asn.au>
parents:
740
diff
changeset
|
775 s2c_comp_algo = buf_match_algo(ses.payload, ses.compress_algos, NULL, NULL); |
116
2010f4119c1a
Check for non-matching algos properly
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
776 if (s2c_comp_algo == NULL) { |
26 | 777 erralgo = "comp s->c"; |
778 goto error; | |
779 } | |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
780 TRACE(("hash s2c is %s", s2c_comp_algo->name)) |
26 | 781 |
782 /* languages_client_to_server */ | |
783 buf_eatstring(ses.payload); | |
784 | |
785 /* languages_server_to_client */ | |
786 buf_eatstring(ses.payload); | |
787 | |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
788 /* their first_kex_packet_follows */ |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
789 if (buf_getbool(ses.payload)) { |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
790 TRACE(("them kex firstfollows. allgood %d", allgood)) |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
791 ses.kexstate.them_firstfollows = 1; |
26 | 792 /* if the guess wasn't good, we ignore the packet sent */ |
793 if (!allgood) { | |
794 ses.ignorenext = 1; | |
795 } | |
796 } | |
797 | |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
798 /* Handle the asymmetry */ |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
799 if (IS_DROPBEAR_CLIENT) { |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
800 ses.newkeys->recv.algo_crypt = |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
801 (struct dropbear_cipher*)s2c_cipher_algo->data; |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
802 ses.newkeys->trans.algo_crypt = |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
803 (struct dropbear_cipher*)c2s_cipher_algo->data; |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
804 ses.newkeys->recv.crypt_mode = |
502 | 805 (struct dropbear_cipher_mode*)s2c_cipher_algo->mode; |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
806 ses.newkeys->trans.crypt_mode = |
502 | 807 (struct dropbear_cipher_mode*)c2s_cipher_algo->mode; |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
808 ses.newkeys->recv.algo_mac = |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
809 (struct dropbear_hash*)s2c_hash_algo->data; |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
810 ses.newkeys->trans.algo_mac = |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
811 (struct dropbear_hash*)c2s_hash_algo->data; |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
812 ses.newkeys->recv.algo_comp = s2c_comp_algo->val; |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
813 ses.newkeys->trans.algo_comp = c2s_comp_algo->val; |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
814 } else { |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
815 /* SERVER */ |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
816 ses.newkeys->recv.algo_crypt = |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
817 (struct dropbear_cipher*)c2s_cipher_algo->data; |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
818 ses.newkeys->trans.algo_crypt = |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
819 (struct dropbear_cipher*)s2c_cipher_algo->data; |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
820 ses.newkeys->recv.crypt_mode = |
502 | 821 (struct dropbear_cipher_mode*)c2s_cipher_algo->mode; |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
822 ses.newkeys->trans.crypt_mode = |
502 | 823 (struct dropbear_cipher_mode*)s2c_cipher_algo->mode; |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
824 ses.newkeys->recv.algo_mac = |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
825 (struct dropbear_hash*)c2s_hash_algo->data; |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
826 ses.newkeys->trans.algo_mac = |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
827 (struct dropbear_hash*)s2c_hash_algo->data; |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
828 ses.newkeys->recv.algo_comp = c2s_comp_algo->val; |
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
829 ses.newkeys->trans.algo_comp = s2c_comp_algo->val; |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
830 } |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
831 |
26 | 832 /* reserved for future extensions */ |
833 buf_getint(ses.payload); | |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
834 |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
835 if (ses.send_kex_first_guess && allgood) { |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
836 TRACE(("our_first_follows_matches 1")) |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
837 ses.kexstate.our_first_follows_matches = 1; |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
838 } |
26 | 839 return; |
840 | |
841 error: | |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
575
diff
changeset
|
842 dropbear_exit("No matching algo %s", erralgo); |
26 | 843 } |