summaryrefslogtreecommitdiff
path: root/kex.c
diff options
context:
space:
mode:
Diffstat (limited to 'kex.c')
-rw-r--r--kex.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/kex.c b/kex.c
index 1314270d4..ee1e17e02 100644
--- a/kex.c
+++ b/kex.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include "includes.h" 25#include "includes.h"
26RCSID("$OpenBSD: kex.c,v 1.28 2001/04/04 09:48:34 markus Exp $"); 26RCSID("$OpenBSD: kex.c,v 1.29 2001/04/04 14:34:58 markus Exp $");
27 27
28#include <openssl/crypto.h> 28#include <openssl/crypto.h>
29 29
@@ -112,9 +112,21 @@ kex_protocol_error(int type, int plen, void *ctxt)
112} 112}
113 113
114void 114void
115kex_clear_dispatch(void)
116{
117 int i;
118
119 /* Numbers 30-49 are used for kex packets */
120 for (i = 30; i <= 49; i++)
121 dispatch_set(i, &kex_protocol_error);
122}
123
124void
115kex_finish(Kex *kex) 125kex_finish(Kex *kex)
116{ 126{
117 int i, plen; 127 int plen;
128
129 kex_clear_dispatch();
118 130
119 packet_start(SSH2_MSG_NEWKEYS); 131 packet_start(SSH2_MSG_NEWKEYS);
120 packet_send(); 132 packet_send();
@@ -125,8 +137,6 @@ kex_finish(Kex *kex)
125 packet_read_expect(&plen, SSH2_MSG_NEWKEYS); 137 packet_read_expect(&plen, SSH2_MSG_NEWKEYS);
126 debug("SSH2_MSG_NEWKEYS received"); 138 debug("SSH2_MSG_NEWKEYS received");
127 kex->newkeys = 1; 139 kex->newkeys = 1;
128 for (i = 30; i <= 49; i++)
129 dispatch_set(i, &kex_protocol_error);
130 buffer_clear(&kex->peer); 140 buffer_clear(&kex->peer);
131 /* buffer_clear(&kex->my); */ 141 /* buffer_clear(&kex->my); */
132 kex->flags &= ~KEX_INIT_SENT; 142 kex->flags &= ~KEX_INIT_SENT;
@@ -135,6 +145,10 @@ kex_finish(Kex *kex)
135void 145void
136kex_send_kexinit(Kex *kex) 146kex_send_kexinit(Kex *kex)
137{ 147{
148 if (kex == NULL) {
149 error("kex_send_kexinit: no kex, cannot rekey");
150 return;
151 }
138 if (kex->flags & KEX_INIT_SENT) { 152 if (kex->flags & KEX_INIT_SENT) {
139 debug("KEX_INIT_SENT"); 153 debug("KEX_INIT_SENT");
140 return; 154 return;
@@ -154,6 +168,8 @@ kex_input_kexinit(int type, int plen, void *ctxt)
154 Kex *kex = (Kex *)ctxt; 168 Kex *kex = (Kex *)ctxt;
155 169
156 debug("SSH2_MSG_KEXINIT received"); 170 debug("SSH2_MSG_KEXINIT received");
171 if (kex == NULL)
172 fatal("kex_input_kexinit: no kex, cannot rekey");
157 173
158 ptr = packet_get_raw(&dlen); 174 ptr = packet_get_raw(&dlen);
159 buffer_append(&kex->peer, ptr, dlen); 175 buffer_append(&kex->peer, ptr, dlen);
@@ -165,7 +181,6 @@ Kex *
165kex_setup(char *proposal[PROPOSAL_MAX]) 181kex_setup(char *proposal[PROPOSAL_MAX])
166{ 182{
167 Kex *kex; 183 Kex *kex;
168 int i;
169 184
170 kex = xmalloc(sizeof(*kex)); 185 kex = xmalloc(sizeof(*kex));
171 memset(kex, 0, sizeof(*kex)); 186 memset(kex, 0, sizeof(*kex));
@@ -175,11 +190,9 @@ kex_setup(char *proposal[PROPOSAL_MAX])
175 kex->newkeys = 0; 190 kex->newkeys = 0;
176 191
177 kex_send_kexinit(kex); /* we start */ 192 kex_send_kexinit(kex); /* we start */
178 /* Numbers 30-49 are used for kex packets */ 193 kex_clear_dispatch();
179 for (i = 30; i <= 49; i++)
180 dispatch_set(i, kex_protocol_error);
181
182 dispatch_set(SSH2_MSG_KEXINIT, &kex_input_kexinit); 194 dispatch_set(SSH2_MSG_KEXINIT, &kex_input_kexinit);
195
183 return kex; 196 return kex;
184} 197}
185 198