Mercurial > dropbear
annotate common-kex.c @ 1500:35f38af1238b
Remove accidentally committed DROPBEAR_FUZZ
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 16 Feb 2018 23:17:15 +0800 |
parents | 06d52bcb8094 |
children | 5916af64acd4 |
rev | line source |
---|---|
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 /* |
74
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
36
diff
changeset
|
2 * Dropbear SSH |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
3 * |
33 | 4 * Copyright (c) 2002-2004 Matt Johnston |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
5 * Portions Copyright (c) 2004 by Mihnea Stoenescu |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
6 * All rights reserved. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
7 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
8 * Permission is hereby granted, free of charge, to any person obtaining a copy |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
9 * of this software and associated documentation files (the "Software"), to deal |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
10 * in the Software without restriction, including without limitation the rights |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
12 * copies of the Software, and to permit persons to whom the Software is |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
13 * furnished to do so, subject to the following conditions: |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
14 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
15 * The above copyright notice and this permission notice shall be included in |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
16 * all copies or substantial portions of the Software. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
17 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 * SOFTWARE. */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
25 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
26 #include "includes.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
27 #include "dbutil.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 #include "algo.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 #include "buffer.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 #include "session.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 #include "kex.h" |
1224
82e2037d34ea
Move dh group constants to a separate file
Matt Johnston <matt@ucc.asn.au>
parents:
1175
diff
changeset
|
32 #include "dh_groups.h" |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
33 #include "ssh.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 #include "packet.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
35 #include "bignum.h" |
858
220f55d540ae
rename random.h to dbrandom.h since some OSes have a system random.h
Matt Johnston <matt@ucc.asn.au>
parents:
857
diff
changeset
|
36 #include "dbrandom.h" |
575
f9b5dc0cba61
- Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents:
555
diff
changeset
|
37 #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
|
38 #include "ecc.h" |
766 | 39 #include "crypto_desc.h" |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
40 |
1276
9169e4e7cbee
fix empty C prototypes
Francois Perrad <francois.perrad@gadz.org>
parents:
1251
diff
changeset
|
41 static void kexinitialise(void); |
9169e4e7cbee
fix empty C prototypes
Francois Perrad <francois.perrad@gadz.org>
parents:
1251
diff
changeset
|
42 static void gen_new_keys(void); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
43 #ifndef DISABLE_ZLIB |
1276
9169e4e7cbee
fix empty C prototypes
Francois Perrad <francois.perrad@gadz.org>
parents:
1251
diff
changeset
|
44 static void gen_new_zstream_recv(void); |
9169e4e7cbee
fix empty C prototypes
Francois Perrad <francois.perrad@gadz.org>
parents:
1251
diff
changeset
|
45 static void gen_new_zstream_trans(void); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
46 #endif |
1276
9169e4e7cbee
fix empty C prototypes
Francois Perrad <francois.perrad@gadz.org>
parents:
1251
diff
changeset
|
47 static void read_kex_algos(void); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
48 /* helper function for gen_new_keys */ |
762
a78a38e402d1
- Fix various hardcoded uses of SHA1
Matt Johnston <matt@ucc.asn.au>
parents:
761
diff
changeset
|
49 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
|
50 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
|
51 static void finish_kexhashbuf(void); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
52 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
53 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
54 /* Send our list of algorithms we can use */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
55 void send_msg_kexinit() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
56 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
57 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
58 buf_putbyte(ses.writepayload, SSH_MSG_KEXINIT); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
59 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
60 /* cookie */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
61 genrandom(buf_getwriteptr(ses.writepayload, 16), 16); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
62 buf_incrwritepos(ses.writepayload, 16); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
63 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
64 /* kex algos */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
65 buf_put_algolist(ses.writepayload, sshkex); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
66 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
67 /* server_host_key_algorithms */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
68 buf_put_algolist(ses.writepayload, sshhostkey); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
69 |
683
63f8d6c469cf
ENABLE_USER_ALGO_LIST should work for the client
Matt Johnston <matt@ucc.asn.au>
parents:
682
diff
changeset
|
70 /* 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
|
71 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
|
72 |
63f8d6c469cf
ENABLE_USER_ALGO_LIST should work for the client
Matt Johnston <matt@ucc.asn.au>
parents:
682
diff
changeset
|
73 /* 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
|
74 buf_put_algolist(ses.writepayload, sshciphers); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
75 |
683
63f8d6c469cf
ENABLE_USER_ALGO_LIST should work for the client
Matt Johnston <matt@ucc.asn.au>
parents:
682
diff
changeset
|
76 /* 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
|
77 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
|
78 |
63f8d6c469cf
ENABLE_USER_ALGO_LIST should work for the client
Matt Johnston <matt@ucc.asn.au>
parents:
682
diff
changeset
|
79 /* 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
|
80 buf_put_algolist(ses.writepayload, sshhashes); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
81 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
82 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
83 /* compression_algorithms_client_to_server */ |
575
f9b5dc0cba61
- Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents:
555
diff
changeset
|
84 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
|
85 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
86 /* compression_algorithms_server_to_client */ |
575
f9b5dc0cba61
- Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents:
555
diff
changeset
|
87 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
|
88 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
89 /* languages_client_to_server */ |
1122
aaf576b27a10
Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents:
1108
diff
changeset
|
90 buf_putstring(ses.writepayload, "", 0); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
91 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
92 /* languages_server_to_client */ |
1122
aaf576b27a10
Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents:
1108
diff
changeset
|
93 buf_putstring(ses.writepayload, "", 0); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
94 |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
95 /* first_kex_packet_follows */ |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
96 buf_putbyte(ses.writepayload, (ses.send_kex_first_guess != NULL)); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
97 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
98 /* reserved unit32 */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
99 buf_putint(ses.writepayload, 0); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
100 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
101 /* set up transmitted kex packet buffer for hashing. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
102 * 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
|
103 ses.transkexinit = buf_newcopy(ses.writepayload); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
104 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
105 encrypt_packet(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
106 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
|
107 |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
108 ses.kexstate.sentkexinit = 1; |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
109 |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
110 ses.newkeys = (struct key_context*)m_malloc(sizeof(struct key_context)); |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
111 |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
112 if (ses.send_kex_first_guess) { |
801 | 113 ses.newkeys->algo_kex = sshkex[0].data; |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
114 ses.newkeys->algo_hostkey = sshhostkey[0].val; |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
115 ses.send_kex_first_guess(); |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
116 } |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
117 |
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
|
118 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
|
119 TRACE(("-> KEXINIT")) |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
120 |
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 |
771 | 123 static void switch_keys() { |
753
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
124 TRACE2(("enter switch_keys")) |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
125 if (!(ses.kexstate.sentkexinit && ses.kexstate.recvkexinit)) { |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
126 dropbear_exit("Unexpected newkeys message"); |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
127 } |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
128 |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
129 if (!ses.keys) { |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
130 ses.keys = m_malloc(sizeof(*ses.newkeys)); |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
131 } |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
132 if (ses.kexstate.recvnewkeys && ses.newkeys->recv.valid) { |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
133 TRACE(("switch_keys recv")) |
781
f110d321fe7a
Fix build when zlib is disabled, from
Matt Johnston <matt@ucc.asn.au>
parents:
775
diff
changeset
|
134 #ifndef DISABLE_ZLIB |
771 | 135 gen_new_zstream_recv(); |
781
f110d321fe7a
Fix build when zlib is disabled, from
Matt Johnston <matt@ucc.asn.au>
parents:
775
diff
changeset
|
136 #endif |
753
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
137 ses.keys->recv = ses.newkeys->recv; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
138 m_burn(&ses.newkeys->recv, sizeof(ses.newkeys->recv)); |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
139 ses.newkeys->recv.valid = 0; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
140 } |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
141 if (ses.kexstate.sentnewkeys && ses.newkeys->trans.valid) { |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
142 TRACE(("switch_keys trans")) |
781
f110d321fe7a
Fix build when zlib is disabled, from
Matt Johnston <matt@ucc.asn.au>
parents:
775
diff
changeset
|
143 #ifndef DISABLE_ZLIB |
771 | 144 gen_new_zstream_trans(); |
781
f110d321fe7a
Fix build when zlib is disabled, from
Matt Johnston <matt@ucc.asn.au>
parents:
775
diff
changeset
|
145 #endif |
753
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
146 ses.keys->trans = ses.newkeys->trans; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
147 m_burn(&ses.newkeys->trans, sizeof(ses.newkeys->trans)); |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
148 ses.newkeys->trans.valid = 0; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
149 } |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
150 if (ses.kexstate.sentnewkeys && ses.kexstate.recvnewkeys) |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
151 { |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
152 TRACE(("switch_keys done")) |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
153 ses.keys->algo_kex = ses.newkeys->algo_kex; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
154 ses.keys->algo_hostkey = ses.newkeys->algo_hostkey; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
155 ses.keys->allow_compress = 0; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
156 m_free(ses.newkeys); |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
157 ses.newkeys = NULL; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
158 kexinitialise(); |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
159 } |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
160 TRACE2(("leave switch_keys")) |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
161 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
162 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
163 /* 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
|
164 void send_msg_newkeys() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
165 |
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
|
166 TRACE(("enter send_msg_newkeys")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
167 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
168 /* generate the kexinit request */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
169 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
170 buf_putbyte(ses.writepayload, SSH_MSG_NEWKEYS); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
171 encrypt_packet(); |
753
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
172 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
173 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
174 /* set up our state */ |
753
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
175 ses.kexstate.sentnewkeys = 1; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
176 ses.kexstate.donefirstkex = 1; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
177 ses.dataallowed = 1; /* we can send other packets again now */ |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
178 gen_new_keys(); |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
179 switch_keys(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
180 |
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
|
181 TRACE(("leave send_msg_newkeys")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
182 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
183 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
184 /* 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
|
185 void recv_msg_newkeys() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
186 |
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
|
187 TRACE(("enter recv_msg_newkeys")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
188 |
753
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
189 ses.kexstate.recvnewkeys = 1; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
190 switch_keys(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
191 |
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
|
192 TRACE(("leave recv_msg_newkeys")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
193 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
194 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
195 |
33 | 196 /* Set up the kex for the first time */ |
197 void kexfirstinitialise() { | |
575
f9b5dc0cba61
- Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents:
555
diff
changeset
|
198 ses.kexstate.donefirstkex = 0; |
33 | 199 |
996
47643024fc90
Disable non-delayed zlib for server
Matt Johnston <matt@ucc.asn.au>
parents:
987
diff
changeset
|
200 #ifdef DISABLE_ZLIB |
47643024fc90
Disable non-delayed zlib for server
Matt Johnston <matt@ucc.asn.au>
parents:
987
diff
changeset
|
201 ses.compress_algos = ssh_nocompress; |
47643024fc90
Disable non-delayed zlib for server
Matt Johnston <matt@ucc.asn.au>
parents:
987
diff
changeset
|
202 #else |
47643024fc90
Disable non-delayed zlib for server
Matt Johnston <matt@ucc.asn.au>
parents:
987
diff
changeset
|
203 switch (opts.compress_mode) |
47643024fc90
Disable non-delayed zlib for server
Matt Johnston <matt@ucc.asn.au>
parents:
987
diff
changeset
|
204 { |
47643024fc90
Disable non-delayed zlib for server
Matt Johnston <matt@ucc.asn.au>
parents:
987
diff
changeset
|
205 case DROPBEAR_COMPRESS_DELAYED: |
47643024fc90
Disable non-delayed zlib for server
Matt Johnston <matt@ucc.asn.au>
parents:
987
diff
changeset
|
206 ses.compress_algos = ssh_delaycompress; |
47643024fc90
Disable non-delayed zlib for server
Matt Johnston <matt@ucc.asn.au>
parents:
987
diff
changeset
|
207 break; |
47643024fc90
Disable non-delayed zlib for server
Matt Johnston <matt@ucc.asn.au>
parents:
987
diff
changeset
|
208 |
47643024fc90
Disable non-delayed zlib for server
Matt Johnston <matt@ucc.asn.au>
parents:
987
diff
changeset
|
209 case DROPBEAR_COMPRESS_ON: |
47643024fc90
Disable non-delayed zlib for server
Matt Johnston <matt@ucc.asn.au>
parents:
987
diff
changeset
|
210 ses.compress_algos = ssh_compress; |
47643024fc90
Disable non-delayed zlib for server
Matt Johnston <matt@ucc.asn.au>
parents:
987
diff
changeset
|
211 break; |
47643024fc90
Disable non-delayed zlib for server
Matt Johnston <matt@ucc.asn.au>
parents:
987
diff
changeset
|
212 |
47643024fc90
Disable non-delayed zlib for server
Matt Johnston <matt@ucc.asn.au>
parents:
987
diff
changeset
|
213 case DROPBEAR_COMPRESS_OFF: |
47643024fc90
Disable non-delayed zlib for server
Matt Johnston <matt@ucc.asn.au>
parents:
987
diff
changeset
|
214 ses.compress_algos = ssh_nocompress; |
47643024fc90
Disable non-delayed zlib for server
Matt Johnston <matt@ucc.asn.au>
parents:
987
diff
changeset
|
215 break; |
47643024fc90
Disable non-delayed zlib for server
Matt Johnston <matt@ucc.asn.au>
parents:
987
diff
changeset
|
216 } |
575
f9b5dc0cba61
- Disable compression for non-final multihops
Matt Johnston <matt@ucc.asn.au>
parents:
555
diff
changeset
|
217 #endif |
33 | 218 kexinitialise(); |
219 } | |
220 | |
221 /* Reset the kex state, ready for a new negotiation */ | |
222 static void kexinitialise() { | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
223 |
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
|
224 TRACE(("kexinitialise()")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
225 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
226 /* sent/recv'd MSG_KEXINIT */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
227 ses.kexstate.sentkexinit = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
228 ses.kexstate.recvkexinit = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
229 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
230 /* sent/recv'd MSG_NEWKEYS */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
231 ses.kexstate.recvnewkeys = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
232 ses.kexstate.sentnewkeys = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
233 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
234 /* first_packet_follows */ |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
235 ses.kexstate.them_firstfollows = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
236 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
237 ses.kexstate.datatrans = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
238 ses.kexstate.datarecv = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
239 |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
240 ses.kexstate.our_first_follows_matches = 0; |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
241 |
928
7cd89d4e0335
Add new monotonic_now() wrapper so that timeouts are unaffected by
Matt Johnston <matt@ucc.asn.au>
parents:
907
diff
changeset
|
242 ses.kexstate.lastkextime = monotonic_now(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
243 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
244 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
245 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
246 /* 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
|
247 * 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
|
248 * 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
|
249 * 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
|
250 * |
409
0e69e948caba
Add comments about requiring keysize <= 2*SHA1_HASH_SIZE
Matt Johnston <matt@ucc.asn.au>
parents:
257
diff
changeset
|
251 * 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
|
252 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
|
253 const hash_state * hs, const unsigned char X) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
254 |
793
70625eed40c9
A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents:
766
diff
changeset
|
255 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
|
256 hash_state hs2; |
762
a78a38e402d1
- Fix various hardcoded uses of SHA1
Matt Johnston <matt@ucc.asn.au>
parents:
761
diff
changeset
|
257 unsigned int offset; |
855
04ede40a529a
- Some fixes for old compilers like tru64 v4 from Daniel Richard G.
Matt Johnston <matt@ucc.asn.au>
parents:
852
diff
changeset
|
258 unsigned char tmpout[MAX_HASH_SIZE]; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
259 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 offset < outlen; |
793
70625eed40c9
A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents:
766
diff
changeset
|
267 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
|
268 { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
269 /* need to extend */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
270 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
|
271 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
|
272 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
|
273 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
|
274 } |
987
ed85797bbc85
clear hash state memory after use
Matt Johnston <matt@ucc.asn.au>
parents:
928
diff
changeset
|
275 m_burn(&hs2, sizeof(hash_state)); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
276 } |
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 /* 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
|
279 * 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
|
280 * This occurs after the DH key-exchange. |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
281 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
282 * 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
|
283 * 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
|
284 |
753
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
285 static void gen_new_keys() { |
4
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 unsigned char C2S_IV[MAX_IV_LEN]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
288 unsigned char C2S_key[MAX_KEY_LEN]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
289 unsigned char S2C_IV[MAX_IV_LEN]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
290 unsigned char S2C_key[MAX_KEY_LEN]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
291 /* unsigned char key[MAX_KEY_LEN]; */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
292 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
|
293 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
294 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
|
295 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
|
296 char mactransletter, macrecvletter; /* Client or server specific */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
297 |
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
|
298 TRACE(("enter gen_new_keys")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
299 /* 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
|
300 |
793
70625eed40c9
A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents:
766
diff
changeset
|
301 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
|
302 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
|
303 mp_clear(ses.dh_K); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
304 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
|
305 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
|
306 buf_burn(ses.hash); |
ac2158e3e403
ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents:
759
diff
changeset
|
307 buf_free(ses.hash); |
ac2158e3e403
ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents:
759
diff
changeset
|
308 ses.hash = NULL; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
309 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
310 if (IS_DROPBEAR_CLIENT) { |
1250 | 311 trans_IV = C2S_IV; |
312 recv_IV = S2C_IV; | |
313 trans_key = C2S_key; | |
314 recv_key = S2C_key; | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
315 mactransletter = 'E'; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
316 macrecvletter = 'F'; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
317 } else { |
1250 | 318 trans_IV = S2C_IV; |
319 recv_IV = C2S_IV; | |
320 trans_key = S2C_key; | |
321 recv_key = C2S_key; | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
322 mactransletter = 'F'; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
323 macrecvletter = 'E'; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
324 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
325 |
762
a78a38e402d1
- Fix various hardcoded uses of SHA1
Matt Johnston <matt@ucc.asn.au>
parents:
761
diff
changeset
|
326 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
|
327 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
|
328 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
|
329 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
|
330 |
681
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
331 if (ses.newkeys->recv.algo_crypt->cipherdesc != NULL) { |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
332 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
|
333 if (recv_cipher < 0) |
681
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
334 dropbear_exit("Crypto error"); |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
335 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
|
336 recv_IV, recv_key, |
681
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
337 ses.newkeys->recv.algo_crypt->keysize, 0, |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
338 &ses.newkeys->recv.cipher_state) != CRYPT_OK) { |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
339 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
|
340 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
341 } |
502 | 342 |
681
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
343 if (ses.newkeys->trans.algo_crypt->cipherdesc != NULL) { |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
344 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
|
345 if (trans_cipher < 0) |
681
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
346 dropbear_exit("Crypto error"); |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
347 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
|
348 trans_IV, trans_key, |
681
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
349 ses.newkeys->trans.algo_crypt->keysize, 0, |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
350 &ses.newkeys->trans.cipher_state) != CRYPT_OK) { |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
351 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
|
352 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
353 } |
512
0129fd8ccc71
Update nocrypto branch to current head
Matt Johnston <matt@ucc.asn.au>
parents:
511
diff
changeset
|
354 |
793
70625eed40c9
A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents:
766
diff
changeset
|
355 if (ses.newkeys->trans.algo_mac->hash_desc != NULL) { |
681
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
356 hashkeys(ses.newkeys->trans.mackey, |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
357 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
|
358 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
|
359 } |
712
bf0ac0512ef7
Fix "-m none" case and ugly typo
Matt Johnston <matt@ucc.asn.au>
parents:
684
diff
changeset
|
360 |
793
70625eed40c9
A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents:
766
diff
changeset
|
361 if (ses.newkeys->recv.algo_mac->hash_desc != NULL) { |
681
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
362 hashkeys(ses.newkeys->recv.mackey, |
a4b7627b3157
Update insecure-nocrypto to current head
Matt Johnston <matt@ucc.asn.au>
diff
changeset
|
363 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
|
364 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
|
365 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
366 |
753
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
367 /* Ready to switch over */ |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
368 ses.newkeys->trans.valid = 1; |
d63ef1e211ea
Take transmit and receive keys into use separately
Matt Johnston <matt@ucc.asn.au>
parents:
746
diff
changeset
|
369 ses.newkeys->recv.valid = 1; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
370 |
648
4222a1039b06
Clear a few buffers when possible
Matt Johnston <matt@ucc.asn.au>
parents:
603
diff
changeset
|
371 m_burn(C2S_IV, sizeof(C2S_IV)); |
4222a1039b06
Clear a few buffers when possible
Matt Johnston <matt@ucc.asn.au>
parents:
603
diff
changeset
|
372 m_burn(C2S_key, sizeof(C2S_key)); |
4222a1039b06
Clear a few buffers when possible
Matt Johnston <matt@ucc.asn.au>
parents:
603
diff
changeset
|
373 m_burn(S2C_IV, sizeof(S2C_IV)); |
4222a1039b06
Clear a few buffers when possible
Matt Johnston <matt@ucc.asn.au>
parents:
603
diff
changeset
|
374 m_burn(S2C_key, sizeof(S2C_key)); |
987
ed85797bbc85
clear hash state memory after use
Matt Johnston <matt@ucc.asn.au>
parents:
928
diff
changeset
|
375 m_burn(&hs, sizeof(hash_state)); |
648
4222a1039b06
Clear a few buffers when possible
Matt Johnston <matt@ucc.asn.au>
parents:
603
diff
changeset
|
376 |
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
|
377 TRACE(("leave gen_new_keys")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
378 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
379 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
380 #ifndef DISABLE_ZLIB |
501
d58c478bd399
Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
381 |
d58c478bd399
Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
382 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
|
383 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
|
384 || (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
|
385 && 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
|
386 } |
d58c478bd399
Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
387 |
d58c478bd399
Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
388 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
|
389 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
|
390 || (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
|
391 && 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
|
392 } |
d58c478bd399
Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
393 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
394 /* 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
|
395 * called from gen_new_keys() */ |
771 | 396 static void gen_new_zstream_recv() { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
397 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
398 /* 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
|
399 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
|
400 || 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
|
401 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
|
402 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
|
403 ses.newkeys->recv.zstream->zfree = Z_NULL; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
404 |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
405 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
|
406 dropbear_exit("zlib error"); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
407 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
408 } else { |
534
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 = NULL; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
410 } |
771 | 411 /* clean up old keys */ |
412 if (ses.keys->recv.zstream != NULL) { | |
413 if (inflateEnd(ses.keys->recv.zstream) == Z_STREAM_ERROR) { | |
414 /* Z_DATA_ERROR is ok, just means that stream isn't ended */ | |
415 dropbear_exit("Crypto error"); | |
416 } | |
417 m_free(ses.keys->recv.zstream); | |
418 } | |
419 } | |
420 | |
421 static void gen_new_zstream_trans() { | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
422 |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
423 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
|
424 || 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
|
425 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
|
426 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
|
427 ses.newkeys->trans.zstream->zfree = Z_NULL; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
428 |
555
daf52f813328
- Add option to change zlib windowBits/memLevel
Matt Johnston <matt@ucc.asn.au>
parents:
534
diff
changeset
|
429 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
|
430 Z_DEFLATED, DROPBEAR_ZLIB_WINDOW_BITS, |
daf52f813328
- Add option to change zlib windowBits/memLevel
Matt Johnston <matt@ucc.asn.au>
parents:
534
diff
changeset
|
431 DROPBEAR_ZLIB_MEM_LEVEL, Z_DEFAULT_STRATEGY) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
432 != Z_OK) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
433 dropbear_exit("zlib error"); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
434 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
435 } else { |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
436 ses.newkeys->trans.zstream = NULL; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
437 } |
501
d58c478bd399
Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
438 |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
439 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
|
440 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
|
441 /* 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
|
442 dropbear_exit("Crypto error"); |
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 m_free(ses.keys->trans.zstream); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
445 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
446 } |
501
d58c478bd399
Add support for [email protected] delayed compression.
Matt Johnston <matt@ucc.asn.au>
parents:
454
diff
changeset
|
447 #endif /* DISABLE_ZLIB */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
448 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
449 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
450 /* 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
|
451 * 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
|
452 * 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
|
453 * 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
|
454 * 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
|
455 * initiate the diffie-hellman key exchange */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
456 void recv_msg_kexinit() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
457 |
257
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
458 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
|
459 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
|
460 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
|
461 |
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
|
462 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
|
463 TRACE(("enter recv_msg_kexinit")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
464 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
465 if (!ses.kexstate.sentkexinit) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
466 /* we need to send a kex packet */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
467 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
|
468 TRACE(("continue recv_msg_kexinit: sent kexinit")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
469 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
470 |
257
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
471 /* 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
|
472 local_ident_len = strlen(LOCAL_IDENT); |
1108
2ebf450edc2d
Turn sshsession's remoteident attribute into char *
Gaël PORTAY <gael.portay@gmail.com>
parents:
1094
diff
changeset
|
473 remote_ident_len = strlen(ses.remoteident); |
257
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
474 |
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
475 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
|
476 + 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
|
477 + 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
|
478 |
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
479 ses.kexhashbuf = buf_new(kexhashbuf_len); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
480 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
481 if (IS_DROPBEAR_CLIENT) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
482 |
26 | 483 /* read the peer's choice of algos */ |
33 | 484 read_kex_algos(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
485 |
26 | 486 /* V_C, the client's version string (CR and NL excluded) */ |
1250 | 487 buf_putstring(ses.kexhashbuf, LOCAL_IDENT, local_ident_len); |
26 | 488 /* V_S, the server's version string (CR and NL excluded) */ |
1250 | 489 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
|
490 |
26 | 491 /* I_C, the payload of the client's SSH_MSG_KEXINIT */ |
1250 | 492 buf_putstring(ses.kexhashbuf, |
1122
aaf576b27a10
Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents:
1108
diff
changeset
|
493 (const char*)ses.transkexinit->data, ses.transkexinit->len); |
26 | 494 /* I_S, the payload of the server's SSH_MSG_KEXINIT */ |
1250 | 495 buf_setpos(ses.payload, ses.payload_beginning); |
496 buf_putstring(ses.kexhashbuf, | |
497 (const char*)buf_getptr(ses.payload, ses.payload->len-ses.payload->pos), | |
498 ses.payload->len-ses.payload->pos); | |
886
cbc73a5aefb0
requirenext doesn't need two values
Matt Johnston <matt@ucc.asn.au>
parents:
885
diff
changeset
|
499 ses.requirenext = SSH_MSG_KEXDH_REPLY; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
500 } else { |
26 | 501 /* SERVER */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
502 |
26 | 503 /* read the peer's choice of algos */ |
33 | 504 read_kex_algos(); |
26 | 505 /* V_C, the client's version string (CR and NL excluded) */ |
1250 | 506 buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len); |
26 | 507 /* V_S, the server's version string (CR and NL excluded) */ |
1250 | 508 buf_putstring(ses.kexhashbuf, LOCAL_IDENT, local_ident_len); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
509 |
26 | 510 /* I_C, the payload of the client's SSH_MSG_KEXINIT */ |
1250 | 511 buf_setpos(ses.payload, ses.payload_beginning); |
512 buf_putstring(ses.kexhashbuf, | |
513 (const char*)buf_getptr(ses.payload, ses.payload->len-ses.payload->pos), | |
514 ses.payload->len-ses.payload->pos); | |
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 |
26 | 516 /* I_S, the payload of the server's SSH_MSG_KEXINIT */ |
1250 | 517 buf_putstring(ses.kexhashbuf, |
1122
aaf576b27a10
Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents:
1108
diff
changeset
|
518 (const char*)ses.transkexinit->data, ses.transkexinit->len); |
257
63601217f5ab
* options.h, common-kex.c: fix support of 4096 byte host keys
Matt Johnston <matt@ucc.asn.au>
parents:
228
diff
changeset
|
519 |
886
cbc73a5aefb0
requirenext doesn't need two values
Matt Johnston <matt@ucc.asn.au>
parents:
885
diff
changeset
|
520 ses.requirenext = SSH_MSG_KEXDH_INIT; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
521 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
522 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
523 buf_free(ses.transkexinit); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
524 ses.transkexinit = NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
525 /* 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
|
526 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
527 ses.kexstate.recvkexinit = 1; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
528 |
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
|
529 TRACE(("leave recv_msg_kexinit")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
530 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
531 |
595
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
532 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
|
533 { |
756 | 534 bytes_to_mp(dh_p, ses.newkeys->algo_kex->dh_p_bytes, |
535 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
|
536 } |
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
537 |
26 | 538 /* 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
|
539 * 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
|
540 /* 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
|
541 struct kex_dh_param *gen_kexdh_param() { |
855
04ede40a529a
- Some fixes for old compilers like tru64 v4 from Daniel Richard G.
Matt Johnston <matt@ucc.asn.au>
parents:
852
diff
changeset
|
542 struct kex_dh_param *param = NULL; |
26 | 543 |
84
29a5c7c62350
default initialisers for mp_ints
Matt Johnston <matt@ucc.asn.au>
parents:
79
diff
changeset
|
544 DEF_MP_INT(dh_p); |
29a5c7c62350
default initialisers for mp_ints
Matt Johnston <matt@ucc.asn.au>
parents:
79
diff
changeset
|
545 DEF_MP_INT(dh_q); |
29a5c7c62350
default initialisers for mp_ints
Matt Johnston <matt@ucc.asn.au>
parents:
79
diff
changeset
|
546 DEF_MP_INT(dh_g); |
26 | 547 |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
548 TRACE(("enter gen_kexdh_vals")) |
755
b07eb3dc23ec
refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
549 |
855
04ede40a529a
- Some fixes for old compilers like tru64 v4 from Daniel Richard G.
Matt Johnston <matt@ucc.asn.au>
parents:
852
diff
changeset
|
550 param = m_malloc(sizeof(*param)); |
852
7540c0822374
Various cleanups and fixes for warnings
Matt Johnston <matt@ucc.asn.au>
parents:
848
diff
changeset
|
551 m_mp_init_multi(¶m->pub, ¶m->priv, &dh_g, &dh_p, &dh_q, NULL); |
26 | 552 |
553 /* read the prime and generator*/ | |
595
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
554 load_dh_p(&dh_p); |
26 | 555 |
556 if (mp_set_int(&dh_g, DH_G_VAL) != MP_OKAY) { | |
557 dropbear_exit("Diffie-Hellman error"); | |
558 } | |
559 | |
560 /* calculate q = (p-1)/2 */ | |
561 /* 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
|
562 if (mp_sub_d(&dh_p, 1, ¶m->priv) != MP_OKAY) { |
26 | 563 dropbear_exit("Diffie-Hellman error"); |
564 } | |
755
b07eb3dc23ec
refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
565 if (mp_div_2(¶m->priv, &dh_q) != MP_OKAY) { |
26 | 566 dropbear_exit("Diffie-Hellman error"); |
567 } | |
568 | |
188
c9483550701b
- refactored random mp_int generation and byte->mp_int code
Matt Johnston <matt@ucc.asn.au>
parents:
179
diff
changeset
|
569 /* 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
|
570 gen_random_mpint(&dh_q, ¶m->priv); |
26 | 571 |
572 /* 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
|
573 if (mp_exptmod(&dh_g, ¶m->priv, &dh_p, ¶m->pub) != MP_OKAY) { |
26 | 574 dropbear_exit("Diffie-Hellman error"); |
575 } | |
576 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
|
577 return param; |
b07eb3dc23ec
refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
578 } |
b07eb3dc23ec
refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
579 |
b07eb3dc23ec
refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
580 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
|
581 { |
b07eb3dc23ec
refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
582 mp_clear_multi(¶m->pub, ¶m->priv, NULL); |
b07eb3dc23ec
refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
583 m_free(param); |
26 | 584 } |
585 | |
586 /* This function is fairly common between client/server, with some substitution | |
587 * of dh_e/dh_f etc. Hence these arguments: | |
588 * dh_pub_us is 'e' for the client, 'f' for the server. dh_pub_them is | |
589 * 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
|
590 void kexdh_comb_key(struct kex_dh_param *param, mp_int *dh_pub_them, |
26 | 591 sign_key *hostkey) { |
592 | |
1013
a1e79ffa5862
Tighten validation of DH values. Odds of x==0 being generated are
Matt Johnston <matt@ucc.asn.au>
parents:
996
diff
changeset
|
593 DEF_MP_INT(dh_p); |
a1e79ffa5862
Tighten validation of DH values. Odds of x==0 being generated are
Matt Johnston <matt@ucc.asn.au>
parents:
996
diff
changeset
|
594 DEF_MP_INT(dh_p_min1); |
26 | 595 mp_int *dh_e = NULL, *dh_f = NULL; |
596 | |
1013
a1e79ffa5862
Tighten validation of DH values. Odds of x==0 being generated are
Matt Johnston <matt@ucc.asn.au>
parents:
996
diff
changeset
|
597 m_mp_init_multi(&dh_p, &dh_p_min1, NULL); |
595
2895626d864f
Add diffie-hellman-group14-sha1 KEX method
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
598 load_dh_p(&dh_p); |
26 | 599 |
1013
a1e79ffa5862
Tighten validation of DH values. Odds of x==0 being generated are
Matt Johnston <matt@ucc.asn.au>
parents:
996
diff
changeset
|
600 if (mp_sub_d(&dh_p, 1, &dh_p_min1) != MP_OKAY) { |
a1e79ffa5862
Tighten validation of DH values. Odds of x==0 being generated are
Matt Johnston <matt@ucc.asn.au>
parents:
996
diff
changeset
|
601 dropbear_exit("Diffie-Hellman error"); |
a1e79ffa5862
Tighten validation of DH values. Odds of x==0 being generated are
Matt Johnston <matt@ucc.asn.au>
parents:
996
diff
changeset
|
602 } |
a1e79ffa5862
Tighten validation of DH values. Odds of x==0 being generated are
Matt Johnston <matt@ucc.asn.au>
parents:
996
diff
changeset
|
603 |
a1e79ffa5862
Tighten validation of DH values. Odds of x==0 being generated are
Matt Johnston <matt@ucc.asn.au>
parents:
996
diff
changeset
|
604 /* Check that dh_pub_them (dh_e or dh_f) is in the range [2, p-2] */ |
a1e79ffa5862
Tighten validation of DH values. Odds of x==0 being generated are
Matt Johnston <matt@ucc.asn.au>
parents:
996
diff
changeset
|
605 if (mp_cmp(dh_pub_them, &dh_p_min1) != MP_LT |
a1e79ffa5862
Tighten validation of DH values. Odds of x==0 being generated are
Matt Johnston <matt@ucc.asn.au>
parents:
996
diff
changeset
|
606 || mp_cmp_d(dh_pub_them, 1) != MP_GT) { |
26 | 607 dropbear_exit("Diffie-Hellman error"); |
608 } | |
609 | |
610 /* K = e^y mod p = f^x mod p */ | |
805
724c3e0c8734
Add m_mp_alloc_init_multi() helper
Matt Johnston <matt@ucc.asn.au>
parents:
801
diff
changeset
|
611 m_mp_alloc_init_multi(&ses.dh_K, NULL); |
755
b07eb3dc23ec
refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
612 if (mp_exptmod(dh_pub_them, ¶m->priv, &dh_p, ses.dh_K) != MP_OKAY) { |
26 | 613 dropbear_exit("Diffie-Hellman error"); |
614 } | |
615 | |
616 /* clear no longer needed vars */ | |
1013
a1e79ffa5862
Tighten validation of DH values. Odds of x==0 being generated are
Matt Johnston <matt@ucc.asn.au>
parents:
996
diff
changeset
|
617 mp_clear_multi(&dh_p, &dh_p_min1, NULL); |
26 | 618 |
619 /* From here on, the code needs to work with the _same_ vars on each side, | |
620 * not vice-versaing for client/server */ | |
621 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
|
622 dh_e = ¶m->pub; |
26 | 623 dh_f = dh_pub_them; |
624 } else { | |
625 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
|
626 dh_f = ¶m->pub; |
26 | 627 } |
628 | |
629 /* Create the remainder of the hash buffer, to generate the exchange hash */ | |
630 /* K_S, the host key */ | |
631 buf_put_pub_key(ses.kexhashbuf, hostkey, ses.newkeys->algo_hostkey); | |
632 /* e, exchange value sent by the client */ | |
633 buf_putmpint(ses.kexhashbuf, dh_e); | |
634 /* f, exchange value sent by the server */ | |
635 buf_putmpint(ses.kexhashbuf, dh_f); | |
636 /* K, the shared secret */ | |
637 buf_putmpint(ses.kexhashbuf, ses.dh_K); | |
638 | |
639 /* 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
|
640 finish_kexhashbuf(); |
26 | 641 } |
642 | |
1295
750ec4ec4cbe
Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents:
1276
diff
changeset
|
643 #if DROPBEAR_ECDH |
755
b07eb3dc23ec
refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
644 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
|
645 struct kex_ecdh_param *param = m_malloc(sizeof(*param)); |
756 | 646 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
|
647 ¶m->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
|
648 dropbear_exit("ECC error"); |
756 | 649 } |
650 return param; | |
651 } | |
652 | |
653 void free_kexecdh_param(struct kex_ecdh_param *param) { | |
654 ecc_free(¶m->key); | |
655 m_free(param); | |
656 | |
755
b07eb3dc23ec
refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
657 } |
b07eb3dc23ec
refactor kexdh code a bit, start working on ecdh etc
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
658 void kexecdh_comb_key(struct kex_ecdh_param *param, buffer *pub_them, |
756 | 659 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
|
660 const struct dropbear_kex *algo_kex = ses.newkeys->algo_kex; |
857 | 661 /* public keys from client and server */ |
756 | 662 ecc_key *Q_C, *Q_S, *Q_them; |
663 | |
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
|
664 Q_them = buf_get_ecc_raw_pubkey(pub_them, algo_kex->ecc_curve); |
1128
a9e074b78cd5
check ecc key return, fix null pointer crash
Matt Johnston <matt@ucc.asn.au>
parents:
1124
diff
changeset
|
665 if (Q_them == NULL) { |
a9e074b78cd5
check ecc key return, fix null pointer crash
Matt Johnston <matt@ucc.asn.au>
parents:
1124
diff
changeset
|
666 dropbear_exit("ECC error"); |
a9e074b78cd5
check ecc key return, fix null pointer crash
Matt Johnston <matt@ucc.asn.au>
parents:
1124
diff
changeset
|
667 } |
757 | 668 |
761
ac2158e3e403
ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents:
759
diff
changeset
|
669 ses.dh_K = dropbear_ecc_shared_secret(Q_them, ¶m->key); |
756 | 670 |
848 | 671 /* Create the remainder of the hash buffer, to generate the exchange hash |
672 See RFC5656 section 4 page 7 */ | |
756 | 673 if (IS_DROPBEAR_CLIENT) { |
761
ac2158e3e403
ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents:
759
diff
changeset
|
674 Q_C = ¶m->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
|
675 Q_S = Q_them; |
756 | 676 } 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
|
677 Q_C = Q_them; |
761
ac2158e3e403
ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents:
759
diff
changeset
|
678 Q_S = ¶m->key; |
756 | 679 } |
680 | |
681 /* K_S, the host key */ | |
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 | 687 /* K, the shared secret */ |
688 buf_putmpint(ses.kexhashbuf, ses.dh_K); | |
689 | |
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 } |
848 | 693 #endif /* DROPBEAR_ECDH */ |
694 | |
1295
750ec4ec4cbe
Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents:
1276
diff
changeset
|
695 #if DROPBEAR_CURVE25519 |
848 | 696 struct kex_curve25519_param *gen_kexcurve25519_param () { |
697 /* Per http://cr.yp.to/ecdh.html */ | |
698 struct kex_curve25519_param *param = m_malloc(sizeof(*param)); | |
699 const unsigned char basepoint[32] = {9}; | |
700 | |
701 genrandom(param->priv, CURVE25519_LEN); | |
702 param->priv[0] &= 248; | |
703 param->priv[31] &= 127; | |
704 param->priv[31] |= 64; | |
705 | |
706 curve25519_donna(param->pub, param->priv, basepoint); | |
707 | |
708 return param; | |
709 } | |
710 | |
711 void free_kexcurve25519_param(struct kex_curve25519_param *param) | |
712 { | |
713 m_burn(param->priv, CURVE25519_LEN); | |
714 m_free(param); | |
715 } | |
716 | |
1459
06d52bcb8094
Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents:
1402
diff
changeset
|
717 void kexcurve25519_comb_key(const struct kex_curve25519_param *param, const buffer *buf_pub_them, |
848 | 718 sign_key *hostkey) { |
852
7540c0822374
Various cleanups and fixes for warnings
Matt Johnston <matt@ucc.asn.au>
parents:
848
diff
changeset
|
719 unsigned char out[CURVE25519_LEN]; |
848 | 720 const unsigned char* Q_C = NULL; |
721 const unsigned char* Q_S = NULL; | |
1175
1b8afc698e39
check for zero K value from curve25519
Matt Johnston <matt@ucc.asn.au>
parents:
1128
diff
changeset
|
722 char zeroes[CURVE25519_LEN] = {0}; |
848 | 723 |
724 if (buf_pub_them->len != CURVE25519_LEN) | |
725 { | |
726 dropbear_exit("Bad curve25519"); | |
727 } | |
728 | |
729 curve25519_donna(out, param->priv, buf_pub_them->data); | |
1175
1b8afc698e39
check for zero K value from curve25519
Matt Johnston <matt@ucc.asn.au>
parents:
1128
diff
changeset
|
730 |
1b8afc698e39
check for zero K value from curve25519
Matt Johnston <matt@ucc.asn.au>
parents:
1128
diff
changeset
|
731 if (constant_time_memcmp(zeroes, out, CURVE25519_LEN) == 0) { |
1b8afc698e39
check for zero K value from curve25519
Matt Johnston <matt@ucc.asn.au>
parents:
1128
diff
changeset
|
732 dropbear_exit("Bad curve25519"); |
1b8afc698e39
check for zero K value from curve25519
Matt Johnston <matt@ucc.asn.au>
parents:
1128
diff
changeset
|
733 } |
1b8afc698e39
check for zero K value from curve25519
Matt Johnston <matt@ucc.asn.au>
parents:
1128
diff
changeset
|
734 |
852
7540c0822374
Various cleanups and fixes for warnings
Matt Johnston <matt@ucc.asn.au>
parents:
848
diff
changeset
|
735 m_mp_alloc_init_multi(&ses.dh_K, NULL); |
848 | 736 bytes_to_mp(ses.dh_K, out, CURVE25519_LEN); |
852
7540c0822374
Various cleanups and fixes for warnings
Matt Johnston <matt@ucc.asn.au>
parents:
848
diff
changeset
|
737 m_burn(out, sizeof(out)); |
848 | 738 |
739 /* Create the remainder of the hash buffer, to generate the exchange hash. | |
740 See RFC5656 section 4 page 7 */ | |
741 if (IS_DROPBEAR_CLIENT) { | |
742 Q_C = param->pub; | |
743 Q_S = buf_pub_them->data; | |
744 } else { | |
745 Q_S = param->pub; | |
746 Q_C = buf_pub_them->data; | |
747 } | |
748 | |
749 /* K_S, the host key */ | |
750 buf_put_pub_key(ses.kexhashbuf, hostkey, ses.newkeys->algo_hostkey); | |
751 /* Q_C, client's ephemeral public key octet string */ | |
1122
aaf576b27a10
Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents:
1108
diff
changeset
|
752 buf_putstring(ses.kexhashbuf, (const char*)Q_C, CURVE25519_LEN); |
848 | 753 /* Q_S, server's ephemeral public key octet string */ |
1122
aaf576b27a10
Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents:
1108
diff
changeset
|
754 buf_putstring(ses.kexhashbuf, (const char*)Q_S, CURVE25519_LEN); |
848 | 755 /* K, the shared secret */ |
756 buf_putmpint(ses.kexhashbuf, ses.dh_K); | |
757 | |
758 /* calculate the hash H to sign */ | |
759 finish_kexhashbuf(); | |
760 } | |
761 #endif /* DROPBEAR_CURVE25519 */ | |
762 | |
763 | |
761
ac2158e3e403
ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents:
759
diff
changeset
|
764 |
ac2158e3e403
ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents:
759
diff
changeset
|
765 static void finish_kexhashbuf(void) { |
ac2158e3e403
ecc kind of works, needs fixing/testing
Matt Johnston <matt@ucc.asn.au>
parents:
759
diff
changeset
|
766 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
|
767 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
|
768 |
793
70625eed40c9
A bit of work on ecdsa for host/auth keys
Matt Johnston <matt@ucc.asn.au>
parents:
766
diff
changeset
|
769 hash_desc->init(&hs); |
26 | 770 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
|
771 hash_desc->process(&hs, buf_getptr(ses.kexhashbuf, ses.kexhashbuf->len), |
26 | 772 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
|
773 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
|
774 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
|
775 buf_setlen(ses.hash, hash_desc->hashsize); |
35
0ad5fb979f42
set the isserver flag (oops)
Matt Johnston <matt@ucc.asn.au>
parents:
34
diff
changeset
|
776 |
1402
553c6bb80265
fix DEBUG_* condition
Francois Perrad <francois.perrad@gadz.org>
parents:
1295
diff
changeset
|
777 #if defined(DEBUG_KEXHASH) && DEBUG_TRACE |
907
4a74c58e11fc
Make some debug info conditional
Matt Johnston <matt@ucc.asn.au>
parents:
886
diff
changeset
|
778 if (!debug_trace) { |
4a74c58e11fc
Make some debug info conditional
Matt Johnston <matt@ucc.asn.au>
parents:
886
diff
changeset
|
779 printhex("kexhashbuf", ses.kexhashbuf->data, ses.kexhashbuf->len); |
4a74c58e11fc
Make some debug info conditional
Matt Johnston <matt@ucc.asn.au>
parents:
886
diff
changeset
|
780 printhex("kexhash", ses.hash->data, ses.hash->len); |
4a74c58e11fc
Make some debug info conditional
Matt Johnston <matt@ucc.asn.au>
parents:
886
diff
changeset
|
781 } |
883
ff597bf2cfb0
DROPBEAR_CLI_AUTH_IMMEDIATE fixed, now enabled by default
Matt Johnston <matt@ucc.asn.au>
parents:
858
diff
changeset
|
782 #endif |
ff597bf2cfb0
DROPBEAR_CLI_AUTH_IMMEDIATE fixed, now enabled by default
Matt Johnston <matt@ucc.asn.au>
parents:
858
diff
changeset
|
783 |
35
0ad5fb979f42
set the isserver flag (oops)
Matt Johnston <matt@ucc.asn.au>
parents:
34
diff
changeset
|
784 buf_burn(ses.kexhashbuf); |
26 | 785 buf_free(ses.kexhashbuf); |
987
ed85797bbc85
clear hash state memory after use
Matt Johnston <matt@ucc.asn.au>
parents:
928
diff
changeset
|
786 m_burn(&hs, sizeof(hash_state)); |
26 | 787 ses.kexhashbuf = NULL; |
788 | |
789 /* first time around, we set the session_id to H */ | |
790 if (ses.session_id == NULL) { | |
791 /* 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
|
792 ses.session_id = buf_newcopy(ses.hash); |
26 | 793 } |
794 } | |
795 | |
796 /* read the other side's algo list. buf_match_algo is a callback to match | |
797 * algos for the client or server. */ | |
33 | 798 static void read_kex_algos() { |
26 | 799 |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
800 /* for asymmetry */ |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
801 algo_type * c2s_hash_algo = NULL; |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
802 algo_type * s2c_hash_algo = NULL; |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
803 algo_type * c2s_cipher_algo = NULL; |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
804 algo_type * s2c_cipher_algo = NULL; |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
805 algo_type * c2s_comp_algo = NULL; |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
806 algo_type * s2c_comp_algo = NULL; |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
807 /* the generic one */ |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
808 algo_type * algo = NULL; |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
809 |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
810 /* which algo couldn't match */ |
26 | 811 char * erralgo = NULL; |
812 | |
813 int goodguess = 0; | |
814 int allgood = 1; /* we AND this with each goodguess and see if its still | |
815 true after */ | |
816 | |
1295
750ec4ec4cbe
Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents:
1276
diff
changeset
|
817 #if DROPBEAR_KEXGUESS2 |
740 | 818 enum kexguess2_used kexguess2 = KEXGUESS2_LOOK; |
746
465fefc4f6e0
Put some #ifdef options around first-follows options in case they
Matt Johnston <matt@ucc.asn.au>
parents:
741
diff
changeset
|
819 #else |
465fefc4f6e0
Put some #ifdef options around first-follows options in case they
Matt Johnston <matt@ucc.asn.au>
parents:
741
diff
changeset
|
820 enum kexguess2_used kexguess2 = KEXGUESS2_NO; |
465fefc4f6e0
Put some #ifdef options around first-follows options in case they
Matt Johnston <matt@ucc.asn.au>
parents:
741
diff
changeset
|
821 #endif |
740 | 822 |
855
04ede40a529a
- Some fixes for old compilers like tru64 v4 from Daniel Richard G.
Matt Johnston <matt@ucc.asn.au>
parents:
852
diff
changeset
|
823 buf_incrpos(ses.payload, 16); /* start after the cookie */ |
04ede40a529a
- Some fixes for old compilers like tru64 v4 from Daniel Richard G.
Matt Johnston <matt@ucc.asn.au>
parents:
852
diff
changeset
|
824 |
04ede40a529a
- Some fixes for old compilers like tru64 v4 from Daniel Richard G.
Matt Johnston <matt@ucc.asn.au>
parents:
852
diff
changeset
|
825 memset(ses.newkeys, 0x0, sizeof(*ses.newkeys)); |
04ede40a529a
- Some fixes for old compilers like tru64 v4 from Daniel Richard G.
Matt Johnston <matt@ucc.asn.au>
parents:
852
diff
changeset
|
826 |
26 | 827 /* kex_algorithms */ |
741
eafdf8b363f5
Get rid of client/server specific buf_match_algo, use single
Matt Johnston <matt@ucc.asn.au>
parents:
740
diff
changeset
|
828 algo = buf_match_algo(ses.payload, sshkex, &kexguess2, &goodguess); |
26 | 829 allgood &= goodguess; |
740 | 830 if (algo == NULL || algo->val == KEXGUESS2_ALGO_ID) { |
26 | 831 erralgo = "kex"; |
832 goto error; | |
833 } | |
740 | 834 TRACE(("kexguess2 %d", kexguess2)) |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
116
diff
changeset
|
835 TRACE(("kex algo %s", algo->name)) |
756 | 836 ses.newkeys->algo_kex = algo->data; |
26 | 837 |
838 /* server_host_key_algorithms */ | |
741
eafdf8b363f5
Get rid of client/server specific buf_match_algo, use single
Matt Johnston <matt@ucc.asn.au>
parents:
740
diff
changeset
|
839 algo = buf_match_algo(ses.payload, sshhostkey, &kexguess2, &goodguess); |
26 | 840 allgood &= goodguess; |
841 if (algo == NULL) { | |
842 erralgo = "hostkey"; | |
843 goto error; | |
844 } | |
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
|
845 TRACE(("hostkey algo %s", algo->name)) |
26 | 846 ses.newkeys->algo_hostkey = algo->val; |
847 | |
848 /* encryption_algorithms_client_to_server */ | |
741
eafdf8b363f5
Get rid of client/server specific buf_match_algo, use single
Matt Johnston <matt@ucc.asn.au>
parents:
740
diff
changeset
|
849 c2s_cipher_algo = buf_match_algo(ses.payload, sshciphers, NULL, NULL); |
116
2010f4119c1a
Check for non-matching algos properly
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
850 if (c2s_cipher_algo == NULL) { |
26 | 851 erralgo = "enc c->s"; |
852 goto error; | |
853 } | |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
854 TRACE(("enc c2s is %s", c2s_cipher_algo->name)) |
26 | 855 |
856 /* encryption_algorithms_server_to_client */ | |
741
eafdf8b363f5
Get rid of client/server specific buf_match_algo, use single
Matt Johnston <matt@ucc.asn.au>
parents:
740
diff
changeset
|
857 s2c_cipher_algo = buf_match_algo(ses.payload, sshciphers, NULL, NULL); |
116
2010f4119c1a
Check for non-matching algos properly
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
858 if (s2c_cipher_algo == NULL) { |
26 | 859 erralgo = "enc s->c"; |
860 goto error; | |
861 } | |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
862 TRACE(("enc s2c is %s", s2c_cipher_algo->name)) |
26 | 863 |
864 /* mac_algorithms_client_to_server */ | |
741
eafdf8b363f5
Get rid of client/server specific buf_match_algo, use single
Matt Johnston <matt@ucc.asn.au>
parents:
740
diff
changeset
|
865 c2s_hash_algo = buf_match_algo(ses.payload, sshhashes, NULL, NULL); |
116
2010f4119c1a
Check for non-matching algos properly
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
866 if (c2s_hash_algo == NULL) { |
26 | 867 erralgo = "mac c->s"; |
868 goto error; | |
869 } | |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
870 TRACE(("hash c2s is %s", c2s_hash_algo->name)) |
26 | 871 |
872 /* mac_algorithms_server_to_client */ | |
741
eafdf8b363f5
Get rid of client/server specific buf_match_algo, use single
Matt Johnston <matt@ucc.asn.au>
parents:
740
diff
changeset
|
873 s2c_hash_algo = buf_match_algo(ses.payload, sshhashes, NULL, NULL); |
116
2010f4119c1a
Check for non-matching algos properly
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
874 if (s2c_hash_algo == NULL) { |
26 | 875 erralgo = "mac s->c"; |
876 goto error; | |
877 } | |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
878 TRACE(("hash s2c is %s", s2c_hash_algo->name)) |
26 | 879 |
880 /* compression_algorithms_client_to_server */ | |
741
eafdf8b363f5
Get rid of client/server specific buf_match_algo, use single
Matt Johnston <matt@ucc.asn.au>
parents:
740
diff
changeset
|
881 c2s_comp_algo = buf_match_algo(ses.payload, ses.compress_algos, NULL, NULL); |
116
2010f4119c1a
Check for non-matching algos properly
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
882 if (c2s_comp_algo == NULL) { |
26 | 883 erralgo = "comp c->s"; |
884 goto error; | |
885 } | |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
886 TRACE(("hash c2s is %s", c2s_comp_algo->name)) |
26 | 887 |
888 /* compression_algorithms_server_to_client */ | |
741
eafdf8b363f5
Get rid of client/server specific buf_match_algo, use single
Matt Johnston <matt@ucc.asn.au>
parents:
740
diff
changeset
|
889 s2c_comp_algo = buf_match_algo(ses.payload, ses.compress_algos, NULL, NULL); |
116
2010f4119c1a
Check for non-matching algos properly
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
890 if (s2c_comp_algo == NULL) { |
26 | 891 erralgo = "comp s->c"; |
892 goto error; | |
893 } | |
228
5e4110bb753a
- Fixed twofish algorithm naming so it actually works.
Matt Johnston <matt@ucc.asn.au>
parents:
227
diff
changeset
|
894 TRACE(("hash s2c is %s", s2c_comp_algo->name)) |
26 | 895 |
896 /* languages_client_to_server */ | |
897 buf_eatstring(ses.payload); | |
898 | |
899 /* languages_server_to_client */ | |
900 buf_eatstring(ses.payload); | |
901 | |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
902 /* their first_kex_packet_follows */ |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
903 if (buf_getbool(ses.payload)) { |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
904 TRACE(("them kex firstfollows. allgood %d", allgood)) |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
905 ses.kexstate.them_firstfollows = 1; |
26 | 906 /* if the guess wasn't good, we ignore the packet sent */ |
907 if (!allgood) { | |
908 ses.ignorenext = 1; | |
909 } | |
910 } | |
911 | |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
912 /* Handle the asymmetry */ |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
913 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
|
914 ses.newkeys->recv.algo_crypt = |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
915 (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
|
916 ses.newkeys->trans.algo_crypt = |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
917 (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
|
918 ses.newkeys->recv.crypt_mode = |
502 | 919 (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
|
920 ses.newkeys->trans.crypt_mode = |
502 | 921 (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
|
922 ses.newkeys->recv.algo_mac = |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
923 (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
|
924 ses.newkeys->trans.algo_mac = |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
925 (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
|
926 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
|
927 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
|
928 } else { |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
929 /* SERVER */ |
534
0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
Matt Johnston <matt@ucc.asn.au>
parents:
502
diff
changeset
|
930 ses.newkeys->recv.algo_crypt = |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
931 (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
|
932 ses.newkeys->trans.algo_crypt = |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
933 (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
|
934 ses.newkeys->recv.crypt_mode = |
502 | 935 (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
|
936 ses.newkeys->trans.crypt_mode = |
502 | 937 (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
|
938 ses.newkeys->recv.algo_mac = |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
939 (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
|
940 ses.newkeys->trans.algo_mac = |
36
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
941 (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
|
942 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
|
943 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
|
944 } |
a600c015562d
Handle differing c2s and s2c algorithms properly
Matt Johnston <matt@ucc.asn.au>
parents:
35
diff
changeset
|
945 |
26 | 946 /* reserved for future extensions */ |
947 buf_getint(ses.payload); | |
739
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
948 |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
949 if (ses.send_kex_first_guess && allgood) { |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
950 TRACE(("our_first_follows_matches 1")) |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
951 ses.kexstate.our_first_follows_matches = 1; |
d44325108d0e
first_kex_packet_follows working, needs tidying
Matt Johnston <matt@ucc.asn.au>
parents:
712
diff
changeset
|
952 } |
26 | 953 return; |
954 | |
955 error: | |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
575
diff
changeset
|
956 dropbear_exit("No matching algo %s", erralgo); |
26 | 957 } |