annotate common-kex.c @ 793:70625eed40c9 ecc

A bit of work on ecdsa for host/auth keys
author Matt Johnston <matt@ucc.asn.au>
date Sun, 14 Apr 2013 00:50:03 +0800
parents d1575fdc29a6
children 7dcb46da72d9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
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"
759
76fba0856749 More changes for KEX and ECDH. Set up hash descriptors, make ECC code work,
Matt Johnston <matt@ucc.asn.au>
parents: 757
diff changeset
37 #include "ecc.h"
766
d1575fdc29a6 start on ecdsa keys
Matt Johnston <matt@ucc.asn.au>
parents: 765
diff changeset
38 #include "crypto_desc.h"
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 /* diffie-hellman-group1-sha1 value for p */
756
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
41 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
42 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
43 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
44 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
45 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
46 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
47 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
48 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
49 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
50 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
51 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
52 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53
595
2895626d864f Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
54 /* diffie-hellman-group14-sha1 value for p */
756
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
55 const unsigned char dh_p_14[DH_P_14_LEN] = {
595
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
ad1b24e39bf3 Make a variables static
Matt Johnston <matt@ucc.asn.au>
parents: 188
diff changeset
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
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
82 static void kexinitialise();
35
0ad5fb979f42 set the isserver flag (oops)
Matt Johnston <matt@ucc.asn.au>
parents: 34
diff changeset
83 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
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 static void gen_new_zstreams();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 #endif
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
87 static void read_kex_algos();
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 /* helper function for gen_new_keys */
762
a78a38e402d1 - Fix various hardcoded uses of SHA1
Matt Johnston <matt@ucc.asn.au>
parents: 761
diff changeset
89 static void hashkeys(unsigned char *out, unsigned int outlen,
a78a38e402d1 - Fix various hardcoded uses of SHA1
Matt Johnston <matt@ucc.asn.au>
parents: 761
diff changeset
90 const hash_state * hs, const unsigned char X);
761
ac2158e3e403 ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents: 759
diff changeset
91 static void finish_kexhashbuf(void);
4
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
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135 /* first_kex_packet_follows - unimplemented for now */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136 buf_putbyte(ses.writepayload, 0x00);
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
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
148 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
149 TRACE(("-> KEXINIT"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150 ses.kexstate.sentkexinit = 1;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
151 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
152
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
153 /* *** NOTE regarding (send|recv)_msg_newkeys ***
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
154 * Changed by mihnea from the original kex.c to set dataallowed after a
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
155 * completed key exchange, no matter the order in which it was performed.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
156 * This enables client mode without affecting server functionality.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
157 */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
158
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
159 /* 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
160 void send_msg_newkeys() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
161
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
162 TRACE(("enter send_msg_newkeys"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
163
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
164 /* generate the kexinit request */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
165 CHECKCLEARTOWRITE();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
166 buf_putbyte(ses.writepayload, SSH_MSG_NEWKEYS);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
167 encrypt_packet();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
168
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
169
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
170 /* set up our state */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
171 if (ses.kexstate.recvnewkeys) {
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
172 TRACE(("while RECVNEWKEYS=1"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
173 gen_new_keys();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
174 kexinitialise(); /* we've finished with this kex */
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
175 TRACE((" -> DATAALLOWED=1"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
176 ses.dataallowed = 1; /* we can send other packets again now */
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
177 ses.kexstate.donefirstkex = 1;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
178 } else {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
179 ses.kexstate.sentnewkeys = 1;
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
180 TRACE(("SENTNEWKEYS=1"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
181 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
182
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
183 TRACE(("-> MSG_NEWKEYS"))
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
184 TRACE(("leave send_msg_newkeys"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
185 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
186
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
187 /* 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
188 void recv_msg_newkeys() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
189
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
190 TRACE(("<- MSG_NEWKEYS"))
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
191 TRACE(("enter recv_msg_newkeys"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
192
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
193 /* simply check if we've sent SSH_MSG_NEWKEYS, and if so,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
194 * switch to the new keys */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
195 if (ses.kexstate.sentnewkeys) {
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
196 TRACE(("while SENTNEWKEYS=1"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
197 gen_new_keys();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
198 kexinitialise(); /* we've finished with this kex */
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
199 TRACE((" -> DATAALLOWED=1"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
200 ses.dataallowed = 1; /* we can send other packets again now */
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
201 ses.kexstate.donefirstkex = 1;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
202 } else {
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
203 TRACE(("RECVNEWKEYS=1"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
204 ses.kexstate.recvnewkeys = 1;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
205 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
206
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
207 TRACE(("leave recv_msg_newkeys"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
208 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
209
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
210
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
211 /* Set up the kex for the first time */
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
212 void kexfirstinitialise() {
575
f9b5dc0cba61 - Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents: 555
diff changeset
213 ses.kexstate.donefirstkex = 0;
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
214
575
f9b5dc0cba61 - Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents: 555
diff changeset
215 #ifndef DISABLE_ZLIB
f9b5dc0cba61 - Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents: 555
diff changeset
216 if (opts.enable_compress) {
f9b5dc0cba61 - Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents: 555
diff changeset
217 ses.compress_algos = ssh_compress;
f9b5dc0cba61 - Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents: 555
diff changeset
218 } else
f9b5dc0cba61 - Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents: 555
diff changeset
219 #endif
f9b5dc0cba61 - Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents: 555
diff changeset
220 {
f9b5dc0cba61 - Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents: 555
diff changeset
221 ses.compress_algos = ssh_nocompress;
f9b5dc0cba61 - Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents: 555
diff changeset
222 }
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
223 kexinitialise();
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
224 }
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
225
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
226 /* Reset the kex state, ready for a new negotiation */
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
227 static void kexinitialise() {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
228
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
229 TRACE(("kexinitialise()"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
230
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
231 /* sent/recv'd MSG_KEXINIT */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
232 ses.kexstate.sentkexinit = 0;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
233 ses.kexstate.recvkexinit = 0;
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 /* sent/recv'd MSG_NEWKEYS */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
236 ses.kexstate.recvnewkeys = 0;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
237 ses.kexstate.sentnewkeys = 0;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
238
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
239 /* first_packet_follows */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
240 ses.kexstate.firstfollows = 0;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
241
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
242 ses.kexstate.datatrans = 0;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
243 ses.kexstate.datarecv = 0;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
244
454
7e43f5e473b9 - Add -K keepalive flag for dropbear and dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 410
diff changeset
245 ses.kexstate.lastkextime = time(NULL);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
246
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
247 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
248
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
249 /* 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
250 * 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
251 * 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
252 * 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
253 *
409
0e69e948caba Add comments about requiring keysize <= 2*SHA1_HASH_SIZE
Matt Johnston <matt@ucc.asn.au>
parents: 257
diff changeset
254 * See Section 7.2 of rfc4253 (ssh transport) for details */
762
a78a38e402d1 - Fix various hardcoded uses of SHA1
Matt Johnston <matt@ucc.asn.au>
parents: 761
diff changeset
255 static void hashkeys(unsigned char *out, unsigned int outlen,
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
256 const hash_state * hs, const unsigned char X) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
257
793
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
258 const struct ltc_hash_descriptor *hash_desc = ses.newkeys->algo_kex->hash_desc;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
259 hash_state hs2;
762
a78a38e402d1 - Fix various hardcoded uses of SHA1
Matt Johnston <matt@ucc.asn.au>
parents: 761
diff changeset
260 unsigned int offset;
793
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
261 unsigned char tmpout[hash_desc->hashsize];
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
262
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
263 memcpy(&hs2, hs, sizeof(hash_state));
793
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
264 hash_desc->process(&hs2, &X, 1);
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
265 hash_desc->process(&hs2, ses.session_id->data, ses.session_id->len);
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
266 hash_desc->done(&hs2, tmpout);
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
267 memcpy(out, tmpout, MIN(hash_desc->hashsize, outlen));
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
268 for (offset = hash_desc->hashsize;
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
269 offset < outlen;
793
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
270 offset += hash_desc->hashsize)
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
271 {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
272 /* need to extend */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
273 memcpy(&hs2, hs, sizeof(hash_state));
793
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
274 hash_desc->process(&hs2, out, offset);
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
275 hash_desc->done(&hs2, tmpout);
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
276 memcpy(&out[offset], tmpout, MIN(outlen - offset, hash_desc->hashsize));
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
277 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
278 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
279
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
280 /* 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
281 * 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
282 * This occurs after the DH key-exchange.
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
283 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
284 * 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
285 * 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
286
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
287 /* Originally from kex.c, generalized for cli/svr mode --mihnea */
35
0ad5fb979f42 set the isserver flag (oops)
Matt Johnston <matt@ucc.asn.au>
parents: 34
diff changeset
288 void gen_new_keys() {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
289
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
290 unsigned char C2S_IV[MAX_IV_LEN];
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
291 unsigned char C2S_key[MAX_KEY_LEN];
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
292 unsigned char S2C_IV[MAX_IV_LEN];
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
293 unsigned char S2C_key[MAX_KEY_LEN];
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
294 /* unsigned char key[MAX_KEY_LEN]; */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
295 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
296
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
297 hash_state hs;
793
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
298 const struct ltc_hash_descriptor *hash_desc = ses.newkeys->algo_kex->hash_desc;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
299 char mactransletter, macrecvletter; /* Client or server specific */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
300
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
301 TRACE(("enter gen_new_keys"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
302 /* 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
303
793
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
304 hash_desc->init(&hs);
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
305 hash_process_mp(hash_desc, &hs, ses.dh_K);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
306 mp_clear(ses.dh_K);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
307 m_free(ses.dh_K);
793
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
308 hash_desc->process(&hs, ses.hash->data, ses.hash->len);
761
ac2158e3e403 ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents: 759
diff changeset
309 buf_burn(ses.hash);
ac2158e3e403 ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents: 759
diff changeset
310 buf_free(ses.hash);
ac2158e3e403 ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents: 759
diff changeset
311 ses.hash = NULL;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
312
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
313 if (IS_DROPBEAR_CLIENT) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
314 trans_IV = C2S_IV;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
315 recv_IV = S2C_IV;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
316 trans_key = C2S_key;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
317 recv_key = S2C_key;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
318 mactransletter = 'E';
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
319 macrecvletter = 'F';
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
320 } else {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
321 trans_IV = S2C_IV;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
322 recv_IV = C2S_IV;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
323 trans_key = S2C_key;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
324 recv_key = C2S_key;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
325 mactransletter = 'F';
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
326 macrecvletter = 'E';
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
762
a78a38e402d1 - Fix various hardcoded uses of SHA1
Matt Johnston <matt@ucc.asn.au>
parents: 761
diff changeset
329 hashkeys(C2S_IV, sizeof(C2S_IV), &hs, 'A');
a78a38e402d1 - Fix various hardcoded uses of SHA1
Matt Johnston <matt@ucc.asn.au>
parents: 761
diff changeset
330 hashkeys(S2C_IV, sizeof(S2C_IV), &hs, 'B');
a78a38e402d1 - Fix various hardcoded uses of SHA1
Matt Johnston <matt@ucc.asn.au>
parents: 761
diff changeset
331 hashkeys(C2S_key, sizeof(C2S_key), &hs, 'C');
a78a38e402d1 - Fix various hardcoded uses of SHA1
Matt Johnston <matt@ucc.asn.au>
parents: 761
diff changeset
332 hashkeys(S2C_key, sizeof(S2C_key), &hs, 'D');
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
333
681
a4b7627b3157 Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
parents: 679 512
diff changeset
334 if (ses.newkeys->recv.algo_crypt->cipherdesc != NULL) {
a4b7627b3157 Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
parents: 679 512
diff changeset
335 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
336 if (recv_cipher < 0)
681
a4b7627b3157 Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
parents: 679 512
diff changeset
337 dropbear_exit("Crypto error");
a4b7627b3157 Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
parents: 679 512
diff changeset
338 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
339 recv_IV, recv_key,
681
a4b7627b3157 Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
parents: 679 512
diff changeset
340 ses.newkeys->recv.algo_crypt->keysize, 0,
a4b7627b3157 Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
parents: 679 512
diff changeset
341 &ses.newkeys->recv.cipher_state) != CRYPT_OK) {
a4b7627b3157 Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
parents: 679 512
diff changeset
342 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
343 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
344 }
502
43bbe17d6ba0 - Add Counter Mode support
Matt Johnston <matt@ucc.asn.au>
parents: 501
diff changeset
345
681
a4b7627b3157 Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
parents: 679 512
diff changeset
346 if (ses.newkeys->trans.algo_crypt->cipherdesc != NULL) {
a4b7627b3157 Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
parents: 679 512
diff changeset
347 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
348 if (trans_cipher < 0)
681
a4b7627b3157 Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
parents: 679 512
diff changeset
349 dropbear_exit("Crypto error");
a4b7627b3157 Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
parents: 679 512
diff changeset
350 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
351 trans_IV, trans_key,
681
a4b7627b3157 Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
parents: 679 512
diff changeset
352 ses.newkeys->trans.algo_crypt->keysize, 0,
a4b7627b3157 Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
parents: 679 512
diff changeset
353 &ses.newkeys->trans.cipher_state) != CRYPT_OK) {
a4b7627b3157 Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
parents: 679 512
diff changeset
354 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
355 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
356 }
512
0129fd8ccc71 Update nocrypto branch to current head
Matt Johnston <matt@ucc.asn.au>
parents: 511
diff changeset
357
793
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
358 if (ses.newkeys->trans.algo_mac->hash_desc != NULL) {
681
a4b7627b3157 Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
parents: 679 512
diff changeset
359 hashkeys(ses.newkeys->trans.mackey,
a4b7627b3157 Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
parents: 679 512
diff changeset
360 ses.newkeys->trans.algo_mac->keysize, &hs, mactransletter);
793
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
361 ses.newkeys->trans.hash_index = find_hash(ses.newkeys->trans.algo_mac->hash_desc->name);
252
29afa62b5450 - a hack for grahame to run dropbear with "none" cipher.
Matt Johnston <matt@ucc.asn.au>
parents: 228
diff changeset
362 }
712
bf0ac0512ef7 Fix "-m none" case and ugly typo
Matt Johnston <matt@ucc.asn.au>
parents: 684
diff changeset
363
793
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
364 if (ses.newkeys->recv.algo_mac->hash_desc != NULL) {
681
a4b7627b3157 Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
parents: 679 512
diff changeset
365 hashkeys(ses.newkeys->recv.mackey,
a4b7627b3157 Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
parents: 679 512
diff changeset
366 ses.newkeys->recv.algo_mac->keysize, &hs, macrecvletter);
793
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
367 ses.newkeys->recv.hash_index = find_hash(ses.newkeys->recv.algo_mac->hash_desc->name);
252
29afa62b5450 - a hack for grahame to run dropbear with "none" cipher.
Matt Johnston <matt@ucc.asn.au>
parents: 228
diff changeset
368 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
369
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
370 #ifndef DISABLE_ZLIB
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
371 gen_new_zstreams();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
372 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
373
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
374 /* Switch over to the new keys */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
375 m_burn(ses.keys, sizeof(struct key_context));
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
376 m_free(ses.keys);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
377 ses.keys = ses.newkeys;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
378 ses.newkeys = NULL;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
379
648
4222a1039b06 Clear a few buffers when possible
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
380 m_burn(C2S_IV, sizeof(C2S_IV));
4222a1039b06 Clear a few buffers when possible
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
381 m_burn(C2S_key, sizeof(C2S_key));
4222a1039b06 Clear a few buffers when possible
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
382 m_burn(S2C_IV, sizeof(S2C_IV));
4222a1039b06 Clear a few buffers when possible
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
383 m_burn(S2C_key, sizeof(S2C_key));
4222a1039b06 Clear a few buffers when possible
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
384
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
385 TRACE(("leave gen_new_keys"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
386 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
387
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
388 #ifndef DISABLE_ZLIB
501
d58c478bd399 Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents: 454
diff changeset
389
d58c478bd399 Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents: 454
diff changeset
390 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
391 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
392 || (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
393 && 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
394 }
d58c478bd399 Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents: 454
diff changeset
395
d58c478bd399 Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents: 454
diff changeset
396 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
397 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
398 || (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
399 && 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
400 }
d58c478bd399 Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents: 454
diff changeset
401
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
402 /* 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
403 * called from gen_new_keys() */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
404 static void gen_new_zstreams() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
405
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
406 /* 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
407 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
408 || 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
409 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
410 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
411 ses.newkeys->recv.zstream->zfree = Z_NULL;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
412
534
0431915df79f - Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents: 502
diff changeset
413 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
414 dropbear_exit("zlib error");
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
415 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
416 } else {
534
0431915df79f - Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents: 502
diff changeset
417 ses.newkeys->recv.zstream = NULL;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
418 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
419
534
0431915df79f - Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents: 502
diff changeset
420 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
421 || 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
422 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
423 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
424 ses.newkeys->trans.zstream->zfree = Z_NULL;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
425
555
daf52f813328 - Add option to change zlib windowBits/memLevel
Matt Johnston <matt@ucc.asn.au>
parents: 534
diff changeset
426 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
427 Z_DEFLATED, DROPBEAR_ZLIB_WINDOW_BITS,
daf52f813328 - Add option to change zlib windowBits/memLevel
Matt Johnston <matt@ucc.asn.au>
parents: 534
diff changeset
428 DROPBEAR_ZLIB_MEM_LEVEL, Z_DEFAULT_STRATEGY)
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
429 != Z_OK) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
430 dropbear_exit("zlib error");
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
431 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
432 } else {
534
0431915df79f - Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents: 502
diff changeset
433 ses.newkeys->trans.zstream = NULL;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
434 }
501
d58c478bd399 Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents: 454
diff changeset
435
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
436 /* clean up old keys */
534
0431915df79f - Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents: 502
diff changeset
437 if (ses.keys->recv.zstream != NULL) {
0431915df79f - Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents: 502
diff changeset
438 if (inflateEnd(ses.keys->recv.zstream) == Z_STREAM_ERROR) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
439 /* 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
440 dropbear_exit("Crypto error");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
441 }
534
0431915df79f - Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents: 502
diff changeset
442 m_free(ses.keys->recv.zstream);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
443 }
534
0431915df79f - Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents: 502
diff changeset
444 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
445 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
446 /* 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
447 dropbear_exit("Crypto error");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
448 }
534
0431915df79f - Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents: 502
diff changeset
449 m_free(ses.keys->trans.zstream);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
450 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
451 }
501
d58c478bd399 Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents: 454
diff changeset
452 #endif /* DISABLE_ZLIB */
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
453
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
454
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
455 /* 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
456 * 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
457 * 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
458 * 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
459 * 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
460 * initiate the diffie-hellman key exchange */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
461
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
462 /* 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
463 /* 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
464 void recv_msg_kexinit() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
465
257
63601217f5ab * options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents: 228
diff changeset
466 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
467 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
468 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
469
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
470 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
471 TRACE(("enter recv_msg_kexinit"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
472
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
473 if (!ses.kexstate.sentkexinit) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
474 /* we need to send a kex packet */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
475 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
476 TRACE(("continue recv_msg_kexinit: sent kexinit"))
4
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
257
63601217f5ab * options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents: 228
diff changeset
479 /* 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
480 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
481 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
482
63601217f5ab * options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents: 228
diff changeset
483 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
484 + 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
485 + 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
486
63601217f5ab * options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents: 228
diff changeset
487 ses.kexhashbuf = buf_new(kexhashbuf_len);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
488
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
489 if (IS_DROPBEAR_CLIENT) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
490
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
491 /* read the peer's choice of algos */
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
492 read_kex_algos();
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
493
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
494 /* 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
495 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
496 (unsigned char*)LOCAL_IDENT, local_ident_len);
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
497 /* 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
498 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
499
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
500 /* 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
501 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
502 ses.transkexinit->data, ses.transkexinit->len);
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
503 /* 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
504 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
505 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
506
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
507 } else {
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
508 /* SERVER */
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
509
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
510 /* read the peer's choice of algos */
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
511 read_kex_algos();
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
512 /* 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
513 buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len);
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
514 /* 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
515 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
516 (unsigned char*)LOCAL_IDENT, local_ident_len);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
517
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
518 /* 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
519 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
520 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
521
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
522 /* 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
523 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
524 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
525
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
526 ses.requirenext = SSH_MSG_KEXDH_INIT;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
527 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
528
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
529 buf_free(ses.transkexinit);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
530 ses.transkexinit = NULL;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
531 /* 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
532
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
533 ses.kexstate.recvkexinit = 1;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
534
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
535 TRACE(("leave recv_msg_kexinit"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
536 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
537
595
2895626d864f Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
538 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
539 {
756
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
540 bytes_to_mp(dh_p, ses.newkeys->algo_kex->dh_p_bytes,
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
541 ses.newkeys->algo_kex->dh_p_len);
595
2895626d864f Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
542 }
2895626d864f Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
543
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
544 /* 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
545 * 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
546 /* dh_pub and dh_priv MUST be already initialised */
755
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
547 struct kex_dh_param *gen_kexdh_param() {
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
548
84
29a5c7c62350 default initialisers for mp_ints
Matt Johnston <matt@ucc.asn.au>
parents: 79
diff changeset
549 DEF_MP_INT(dh_p);
29a5c7c62350 default initialisers for mp_ints
Matt Johnston <matt@ucc.asn.au>
parents: 79
diff changeset
550 DEF_MP_INT(dh_q);
29a5c7c62350 default initialisers for mp_ints
Matt Johnston <matt@ucc.asn.au>
parents: 79
diff changeset
551 DEF_MP_INT(dh_g);
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
552
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
553 TRACE(("enter send_msg_kexdh_reply"))
755
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
554
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
555 struct kex_dh_param *param = m_malloc(sizeof(*param));
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
556 m_mp_init_multi(&param->pub, &param->priv, NULL);
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
557
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
558 /* read the prime and generator*/
595
2895626d864f Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
559 load_dh_p(&dh_p);
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
560
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
561 if (mp_set_int(&dh_g, DH_G_VAL) != MP_OKAY) {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
562 dropbear_exit("Diffie-Hellman error");
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
563 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
564
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
565 /* calculate q = (p-1)/2 */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
566 /* dh_priv is just a temp var here */
755
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
567 if (mp_sub_d(&dh_p, 1, &param->priv) != MP_OKAY) {
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
568 dropbear_exit("Diffie-Hellman error");
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
569 }
755
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
570 if (mp_div_2(&param->priv, &dh_q) != MP_OKAY) {
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
571 dropbear_exit("Diffie-Hellman error");
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
572 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
573
188
c9483550701b - refactored random mp_int generation and byte->mp_int code
Matt Johnston <matt@ucc.asn.au>
parents: 179
diff changeset
574 /* Generate a private portion 0 < dh_priv < dh_q */
755
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
575 gen_random_mpint(&dh_q, &param->priv);
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
576
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
577 /* f = g^y mod p */
755
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
578 if (mp_exptmod(&dh_g, &param->priv, &dh_p, &param->pub) != MP_OKAY) {
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
579 dropbear_exit("Diffie-Hellman error");
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
580 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
581 mp_clear_multi(&dh_g, &dh_p, &dh_q, NULL);
755
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
582 return param;
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
583 }
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
584
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
585 void free_kexdh_param(struct kex_dh_param *param)
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
586 {
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
587 mp_clear_multi(&param->pub, &param->priv, NULL);
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
588 m_free(param);
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
589 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
590
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
591 /* This function is fairly common between client/server, with some substitution
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
592 * of dh_e/dh_f etc. Hence these arguments:
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
593 * dh_pub_us is 'e' for the client, 'f' for the server. dh_pub_them is
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
594 * vice-versa. dh_priv is the x/y value corresponding to dh_pub_us */
755
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
595 void kexdh_comb_key(struct kex_dh_param *param, mp_int *dh_pub_them,
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
596 sign_key *hostkey) {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
597
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
598 mp_int dh_p;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
599 mp_int *dh_e = NULL, *dh_f = NULL;
755
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
600
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
601 /* read the prime and generator*/
342
3e098639b05f From Erik Hovland
Matt Johnston <matt@ucc.asn.au>
parents: 257
diff changeset
602 m_mp_init(&dh_p);
595
2895626d864f Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
603 load_dh_p(&dh_p);
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
604
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
605 /* Check that dh_pub_them (dh_e or dh_f) is in the range [1, p-1] */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
606 if (mp_cmp(dh_pub_them, &dh_p) != MP_LT
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
607 || mp_cmp_d(dh_pub_them, 0) != MP_GT) {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
608 dropbear_exit("Diffie-Hellman error");
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
609 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
610
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
611 /* K = e^y mod p = f^x mod p */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
612 ses.dh_K = (mp_int*)m_malloc(sizeof(mp_int));
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
613 m_mp_init(ses.dh_K);
755
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
614 if (mp_exptmod(dh_pub_them, &param->priv, &dh_p, ses.dh_K) != MP_OKAY) {
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
615 dropbear_exit("Diffie-Hellman error");
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
616 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
617
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
618 /* clear no longer needed vars */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
619 mp_clear_multi(&dh_p, NULL);
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
620
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
621 /* From here on, the code needs to work with the _same_ vars on each side,
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
622 * not vice-versaing for client/server */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
623 if (IS_DROPBEAR_CLIENT) {
755
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
624 dh_e = &param->pub;
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
625 dh_f = dh_pub_them;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
626 } else {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
627 dh_e = dh_pub_them;
755
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
628 dh_f = &param->pub;
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
629 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
630
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
631 /* Create the remainder of the hash buffer, to generate the exchange hash */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
632 /* K_S, the host key */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
633 buf_put_pub_key(ses.kexhashbuf, hostkey, ses.newkeys->algo_hostkey);
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
634 /* e, exchange value sent by the client */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
635 buf_putmpint(ses.kexhashbuf, dh_e);
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
636 /* f, exchange value sent by the server */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
637 buf_putmpint(ses.kexhashbuf, dh_f);
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
638 /* K, the shared secret */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
639 buf_putmpint(ses.kexhashbuf, ses.dh_K);
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
640
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
641 /* calculate the hash H to sign */
761
ac2158e3e403 ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents: 759
diff changeset
642 finish_kexhashbuf();
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
643 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
644
755
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
645 #ifdef DROPBEAR_ECDH
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
646 struct kex_ecdh_param *gen_kexecdh_param() {
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
647 struct kex_ecdh_param *param = m_malloc(sizeof(*param));
756
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
648 if (ecc_make_key_ex(NULL, dropbear_ltc_prng,
759
76fba0856749 More changes for KEX and ECDH. Set up hash descriptors, make ECC code work,
Matt Johnston <matt@ucc.asn.au>
parents: 757
diff changeset
649 &param->key, ses.newkeys->algo_kex->ecc_curve->dp) != CRYPT_OK) {
76fba0856749 More changes for KEX and ECDH. Set up hash descriptors, make ECC code work,
Matt Johnston <matt@ucc.asn.au>
parents: 757
diff changeset
650 dropbear_exit("ECC error");
756
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
651 }
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
652 return param;
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
653 }
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
654
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
655 void free_kexecdh_param(struct kex_ecdh_param *param) {
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
656 ecc_free(&param->key);
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
657 m_free(param);
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
658
755
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
659 }
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
660 void kexecdh_comb_key(struct kex_ecdh_param *param, buffer *pub_them,
756
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
661 sign_key *hostkey) {
759
76fba0856749 More changes for KEX and ECDH. Set up hash descriptors, make ECC code work,
Matt Johnston <matt@ucc.asn.au>
parents: 757
diff changeset
662 const struct dropbear_kex *algo_kex = ses.newkeys->algo_kex;
756
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
663 // public keys from client and server
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
664 ecc_key *Q_C, *Q_S, *Q_them;
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
665
765
5503e05ab3a4 - Rename buf_put_ecc_pubkey_string() to buf_put_ecc_raw_pubkey_string()
Matt Johnston <matt@ucc.asn.au>
parents: 763
diff changeset
666 Q_them = buf_get_ecc_raw_pubkey(pub_them, algo_kex->ecc_curve);
757
230666086711 ecc key import function
Matt Johnston <matt@ucc.asn.au>
parents: 756
diff changeset
667
761
ac2158e3e403 ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents: 759
diff changeset
668 ses.dh_K = dropbear_ecc_shared_secret(Q_them, &param->key);
756
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
669
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
670 /* From here on, the code needs to work with the _same_ vars on each side,
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
671 * not vice-versaing for client/server */
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
672 if (IS_DROPBEAR_CLIENT) {
761
ac2158e3e403 ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents: 759
diff changeset
673 Q_C = &param->key;
759
76fba0856749 More changes for KEX and ECDH. Set up hash descriptors, make ECC code work,
Matt Johnston <matt@ucc.asn.au>
parents: 757
diff changeset
674 Q_S = Q_them;
756
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
675 } else {
759
76fba0856749 More changes for KEX and ECDH. Set up hash descriptors, make ECC code work,
Matt Johnston <matt@ucc.asn.au>
parents: 757
diff changeset
676 Q_C = Q_them;
761
ac2158e3e403 ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents: 759
diff changeset
677 Q_S = &param->key;
756
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
678 }
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
679
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
680 /* Create the remainder of the hash buffer, to generate the exchange hash */
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
681 /* K_S, the host key */
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
682 buf_put_pub_key(ses.kexhashbuf, hostkey, ses.newkeys->algo_hostkey);
759
76fba0856749 More changes for KEX and ECDH. Set up hash descriptors, make ECC code work,
Matt Johnston <matt@ucc.asn.au>
parents: 757
diff changeset
683 /* Q_C, client's ephemeral public key octet string */
765
5503e05ab3a4 - Rename buf_put_ecc_pubkey_string() to buf_put_ecc_raw_pubkey_string()
Matt Johnston <matt@ucc.asn.au>
parents: 763
diff changeset
684 buf_put_ecc_raw_pubkey_string(ses.kexhashbuf, Q_C);
759
76fba0856749 More changes for KEX and ECDH. Set up hash descriptors, make ECC code work,
Matt Johnston <matt@ucc.asn.au>
parents: 757
diff changeset
685 /* Q_S, server's ephemeral public key octet string */
765
5503e05ab3a4 - Rename buf_put_ecc_pubkey_string() to buf_put_ecc_raw_pubkey_string()
Matt Johnston <matt@ucc.asn.au>
parents: 763
diff changeset
686 buf_put_ecc_raw_pubkey_string(ses.kexhashbuf, Q_S);
756
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
687 /* K, the shared secret */
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
688 buf_putmpint(ses.kexhashbuf, ses.dh_K);
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
689
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
690 /* calculate the hash H to sign */
761
ac2158e3e403 ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents: 759
diff changeset
691 finish_kexhashbuf();
ac2158e3e403 ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents: 759
diff changeset
692 }
ac2158e3e403 ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents: 759
diff changeset
693 #endif
ac2158e3e403 ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents: 759
diff changeset
694
ac2158e3e403 ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents: 759
diff changeset
695 static void finish_kexhashbuf(void) {
ac2158e3e403 ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents: 759
diff changeset
696 hash_state hs;
793
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
697 const struct ltc_hash_descriptor *hash_desc = ses.newkeys->algo_kex->hash_desc;
761
ac2158e3e403 ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents: 759
diff changeset
698
793
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
699 hash_desc->init(&hs);
761
ac2158e3e403 ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents: 759
diff changeset
700 buf_setpos(ses.kexhashbuf, 0);
793
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
701 hash_desc->process(&hs, buf_getptr(ses.kexhashbuf, ses.kexhashbuf->len),
761
ac2158e3e403 ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents: 759
diff changeset
702 ses.kexhashbuf->len);
793
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
703 ses.hash = buf_new(hash_desc->hashsize);
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
704 hash_desc->done(&hs, buf_getwriteptr(ses.hash, hash_desc->hashsize));
70625eed40c9 A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents: 766
diff changeset
705 buf_setlen(ses.hash, hash_desc->hashsize);
756
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
706
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
707 buf_burn(ses.kexhashbuf);
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
708 buf_free(ses.kexhashbuf);
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
709 ses.kexhashbuf = NULL;
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
710
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
711 /* first time around, we set the session_id to H */
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
712 if (ses.session_id == NULL) {
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
713 /* create the session_id, this never needs freeing */
761
ac2158e3e403 ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents: 759
diff changeset
714 ses.session_id = buf_newcopy(ses.hash);
756
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
715 }
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
716
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
717 }
755
b07eb3dc23ec refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents: 712
diff changeset
718
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
719 /* read the other side's algo list. buf_match_algo is a callback to match
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
720 * algos for the client or server. */
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
721 static void read_kex_algos() {
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
722
36
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
723 /* for asymmetry */
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
724 algo_type * c2s_hash_algo = NULL;
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
725 algo_type * s2c_hash_algo = NULL;
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
726 algo_type * c2s_cipher_algo = NULL;
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
727 algo_type * s2c_cipher_algo = NULL;
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
728 algo_type * c2s_comp_algo = NULL;
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
729 algo_type * s2c_comp_algo = NULL;
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
730 /* the generic one */
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
731 algo_type * algo = NULL;
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
732
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
733 /* which algo couldn't match */
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
734 char * erralgo = NULL;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
735
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
736 int goodguess = 0;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
737 int allgood = 1; /* we AND this with each goodguess and see if its still
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
738 true after */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
739
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
740 buf_incrpos(ses.payload, 16); /* start after the cookie */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
741
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
742 ses.newkeys = (struct key_context*)m_malloc(sizeof(struct key_context));
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
743
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
744 /* kex_algorithms */
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
745 algo = ses.buf_match_algo(ses.payload, sshkex, &goodguess);
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
746 allgood &= goodguess;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
747 if (algo == NULL) {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
748 erralgo = "kex";
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
749 goto error;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
750 }
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
751 TRACE(("kex algo %s", algo->name))
756
bf9dc2d9c2b1 more bits on ecc branch
Matt Johnston <matt@ucc.asn.au>
parents: 755
diff changeset
752 ses.newkeys->algo_kex = algo->data;
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
753
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
754 /* server_host_key_algorithms */
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
755 algo = ses.buf_match_algo(ses.payload, sshhostkey, &goodguess);
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
756 allgood &= goodguess;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
757 if (algo == NULL) {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
758 erralgo = "hostkey";
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
759 goto error;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
760 }
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
761 TRACE(("hostkey algo %s", algo->name))
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
762 ses.newkeys->algo_hostkey = algo->val;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
763
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
764 /* encryption_algorithms_client_to_server */
36
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
765 c2s_cipher_algo = ses.buf_match_algo(ses.payload, sshciphers, &goodguess);
116
2010f4119c1a Check for non-matching algos properly
Matt Johnston <matt@ucc.asn.au>
parents: 84
diff changeset
766 if (c2s_cipher_algo == NULL) {
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
767 erralgo = "enc c->s";
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
768 goto error;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
769 }
228
5e4110bb753a - Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents: 227
diff changeset
770 TRACE(("enc c2s is %s", c2s_cipher_algo->name))
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
771
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
772 /* encryption_algorithms_server_to_client */
36
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
773 s2c_cipher_algo = ses.buf_match_algo(ses.payload, sshciphers, &goodguess);
116
2010f4119c1a Check for non-matching algos properly
Matt Johnston <matt@ucc.asn.au>
parents: 84
diff changeset
774 if (s2c_cipher_algo == NULL) {
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
775 erralgo = "enc s->c";
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
776 goto error;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
777 }
228
5e4110bb753a - Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents: 227
diff changeset
778 TRACE(("enc s2c is %s", s2c_cipher_algo->name))
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
779
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
780 /* mac_algorithms_client_to_server */
36
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
781 c2s_hash_algo = ses.buf_match_algo(ses.payload, sshhashes, &goodguess);
116
2010f4119c1a Check for non-matching algos properly
Matt Johnston <matt@ucc.asn.au>
parents: 84
diff changeset
782 if (c2s_hash_algo == NULL) {
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
783 erralgo = "mac c->s";
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
784 goto error;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
785 }
228
5e4110bb753a - Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents: 227
diff changeset
786 TRACE(("hash c2s is %s", c2s_hash_algo->name))
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
787
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
788 /* mac_algorithms_server_to_client */
36
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
789 s2c_hash_algo = ses.buf_match_algo(ses.payload, sshhashes, &goodguess);
116
2010f4119c1a Check for non-matching algos properly
Matt Johnston <matt@ucc.asn.au>
parents: 84
diff changeset
790 if (s2c_hash_algo == NULL) {
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
791 erralgo = "mac s->c";
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
792 goto error;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
793 }
228
5e4110bb753a - Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents: 227
diff changeset
794 TRACE(("hash s2c is %s", s2c_hash_algo->name))
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
795
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
796 /* compression_algorithms_client_to_server */
575
f9b5dc0cba61 - Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents: 555
diff changeset
797 c2s_comp_algo = ses.buf_match_algo(ses.payload, ses.compress_algos, &goodguess);
116
2010f4119c1a Check for non-matching algos properly
Matt Johnston <matt@ucc.asn.au>
parents: 84
diff changeset
798 if (c2s_comp_algo == NULL) {
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
799 erralgo = "comp c->s";
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
800 goto error;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
801 }
228
5e4110bb753a - Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents: 227
diff changeset
802 TRACE(("hash c2s is %s", c2s_comp_algo->name))
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
803
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
804 /* compression_algorithms_server_to_client */
575
f9b5dc0cba61 - Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents: 555
diff changeset
805 s2c_comp_algo = ses.buf_match_algo(ses.payload, ses.compress_algos, &goodguess);
116
2010f4119c1a Check for non-matching algos properly
Matt Johnston <matt@ucc.asn.au>
parents: 84
diff changeset
806 if (s2c_comp_algo == NULL) {
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
807 erralgo = "comp s->c";
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
808 goto error;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
809 }
228
5e4110bb753a - Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents: 227
diff changeset
810 TRACE(("hash s2c is %s", s2c_comp_algo->name))
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
811
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
812 /* languages_client_to_server */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
813 buf_eatstring(ses.payload);
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
814
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
815 /* languages_server_to_client */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
816 buf_eatstring(ses.payload);
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
817
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
818 /* 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
819 if (buf_getbool(ses.payload)) {
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
820 ses.kexstate.firstfollows = 1;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
821 /* if the guess wasn't good, we ignore the packet sent */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
822 if (!allgood) {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
823 ses.ignorenext = 1;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
824 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
825 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
826
36
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
827 /* Handle the asymmetry */
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
828 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
829 ses.newkeys->recv.algo_crypt =
36
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
830 (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
831 ses.newkeys->trans.algo_crypt =
36
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
832 (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
833 ses.newkeys->recv.crypt_mode =
502
43bbe17d6ba0 - Add Counter Mode support
Matt Johnston <matt@ucc.asn.au>
parents: 501
diff changeset
834 (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
835 ses.newkeys->trans.crypt_mode =
502
43bbe17d6ba0 - Add Counter Mode support
Matt Johnston <matt@ucc.asn.au>
parents: 501
diff changeset
836 (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
837 ses.newkeys->recv.algo_mac =
36
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
838 (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
839 ses.newkeys->trans.algo_mac =
36
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
840 (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
841 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
842 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
843 } else {
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
844 /* SERVER */
534
0431915df79f - Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents: 502
diff changeset
845 ses.newkeys->recv.algo_crypt =
36
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
846 (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
847 ses.newkeys->trans.algo_crypt =
36
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
848 (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
849 ses.newkeys->recv.crypt_mode =
502
43bbe17d6ba0 - Add Counter Mode support
Matt Johnston <matt@ucc.asn.au>
parents: 501
diff changeset
850 (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
851 ses.newkeys->trans.crypt_mode =
502
43bbe17d6ba0 - Add Counter Mode support
Matt Johnston <matt@ucc.asn.au>
parents: 501
diff changeset
852 (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
853 ses.newkeys->recv.algo_mac =
36
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
854 (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
855 ses.newkeys->trans.algo_mac =
36
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
856 (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
857 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
858 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
859 }
a600c015562d Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents: 35
diff changeset
860
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
861 /* reserved for future extensions */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
862 buf_getint(ses.payload);
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
863 return;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
864
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
865 error:
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 575
diff changeset
866 dropbear_exit("No matching algo %s", erralgo);
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 22
diff changeset
867 }