summaryrefslogtreecommitdiff
path: root/kex.c
diff options
context:
space:
mode:
Diffstat (limited to 'kex.c')
-rw-r--r--kex.c50
1 files changed, 28 insertions, 22 deletions
diff --git a/kex.c b/kex.c
index 3d6f3ab54..8cd851d23 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.60 2004/06/21 17:36:31 avsm Exp $"); 26RCSID("$OpenBSD: kex.c,v 1.64 2005/07/25 11:59:39 markus Exp $");
27 27
28#include <openssl/crypto.h> 28#include <openssl/crypto.h>
29 29
@@ -56,7 +56,7 @@ static void kex_choose_conf(Kex *);
56static void 56static void
57kex_prop2buf(Buffer *b, char *proposal[PROPOSAL_MAX]) 57kex_prop2buf(Buffer *b, char *proposal[PROPOSAL_MAX])
58{ 58{
59 int i; 59 u_int i;
60 60
61 buffer_clear(b); 61 buffer_clear(b);
62 /* 62 /*
@@ -105,7 +105,7 @@ kex_buf2prop(Buffer *raw, int *first_kex_follows)
105static void 105static void
106kex_prop_free(char **proposal) 106kex_prop_free(char **proposal)
107{ 107{
108 int i; 108 u_int i;
109 109
110 for (i = 0; i < PROPOSAL_MAX; i++) 110 for (i = 0; i < PROPOSAL_MAX; i++)
111 xfree(proposal[i]); 111 xfree(proposal[i]);
@@ -154,7 +154,7 @@ kex_send_kexinit(Kex *kex)
154{ 154{
155 u_int32_t rnd = 0; 155 u_int32_t rnd = 0;
156 u_char *cookie; 156 u_char *cookie;
157 int i; 157 u_int i;
158 158
159 if (kex == NULL) { 159 if (kex == NULL) {
160 error("kex_send_kexinit: no kex, cannot rekey"); 160 error("kex_send_kexinit: no kex, cannot rekey");
@@ -187,8 +187,7 @@ void
187kex_input_kexinit(int type, u_int32_t seq, void *ctxt) 187kex_input_kexinit(int type, u_int32_t seq, void *ctxt)
188{ 188{
189 char *ptr; 189 char *ptr;
190 int dlen; 190 u_int i, dlen;
191 int i;
192 Kex *kex = (Kex *)ctxt; 191 Kex *kex = (Kex *)ctxt;
193 192
194 debug("SSH2_MSG_KEXINIT received"); 193 debug("SSH2_MSG_KEXINIT received");
@@ -280,10 +279,12 @@ choose_comp(Comp *comp, char *client, char *server)
280 char *name = match_list(client, server, NULL); 279 char *name = match_list(client, server, NULL);
281 if (name == NULL) 280 if (name == NULL)
282 fatal("no matching comp found: client %s server %s", client, server); 281 fatal("no matching comp found: client %s server %s", client, server);
283 if (strcmp(name, "zlib") == 0) { 282 if (strcmp(name, "zlib@openssh.com") == 0) {
284 comp->type = 1; 283 comp->type = COMP_DELAYED;
284 } else if (strcmp(name, "zlib") == 0) {
285 comp->type = COMP_ZLIB;
285 } else if (strcmp(name, "none") == 0) { 286 } else if (strcmp(name, "none") == 0) {
286 comp->type = 0; 287 comp->type = COMP_NONE;
287 } else { 288 } else {
288 fatal("unsupported comp %s", name); 289 fatal("unsupported comp %s", name);
289 } 290 }
@@ -302,8 +303,11 @@ choose_kex(Kex *k, char *client, char *server)
302 } else if (strcmp(k->name, KEX_DHGEX) == 0) { 303 } else if (strcmp(k->name, KEX_DHGEX) == 0) {
303 k->kex_type = KEX_DH_GEX_SHA1; 304 k->kex_type = KEX_DH_GEX_SHA1;
304#ifdef GSSAPI 305#ifdef GSSAPI
305 } else if (strncmp(k->name, KEX_GSS_SHA1, 306 } else if (strncmp(k->name, KEX_GSS_GEX_SHA1_ID,
306 sizeof(KEX_GSS_SHA1)-1) == 0) { 307 sizeof(KEX_GSS_GEX_SHA1_ID)-1) == 0) {
308 k->kex_type = KEX_GSS_GEX_SHA1;
309 } else if (strncmp(k->name, KEX_GSS_GRP1_SHA1_ID,
310 sizeof(KEX_GSS_GRP1_SHA1_ID)-1) == 0) {
307 k->kex_type = KEX_GSS_GRP1_SHA1; 311 k->kex_type = KEX_GSS_GRP1_SHA1;
308#endif 312#endif
309 } else 313 } else
@@ -352,9 +356,7 @@ kex_choose_conf(Kex *kex)
352 char **my, **peer; 356 char **my, **peer;
353 char **cprop, **sprop; 357 char **cprop, **sprop;
354 int nenc, nmac, ncomp; 358 int nenc, nmac, ncomp;
355 int mode; 359 u_int mode, ctos, need;
356 int ctos; /* direction: if true client-to-server */
357 int need;
358 int first_kex_follows, type; 360 int first_kex_follows, type;
359 361
360 my = kex_buf2prop(&kex->my, NULL); 362 my = kex_buf2prop(&kex->my, NULL);
@@ -404,7 +406,7 @@ kex_choose_conf(Kex *kex)
404 406
405 /* ignore the next message if the proposals do not match */ 407 /* ignore the next message if the proposals do not match */
406 if (first_kex_follows && !proposals_match(my, peer) && 408 if (first_kex_follows && !proposals_match(my, peer) &&
407 !(datafellows & SSH_BUG_FIRSTKEX)) { 409 !(datafellows & SSH_BUG_FIRSTKEX)) {
408 type = packet_read(); 410 type = packet_read();
409 debug2("skipping next packet (type %u)", type); 411 debug2("skipping next packet (type %u)", type);
410 } 412 }
@@ -414,15 +416,19 @@ kex_choose_conf(Kex *kex)
414} 416}
415 417
416static u_char * 418static u_char *
417derive_key(Kex *kex, int id, int need, u_char *hash, BIGNUM *shared_secret) 419derive_key(Kex *kex, int id, u_int need, u_char *hash, BIGNUM *shared_secret)
418{ 420{
419 Buffer b; 421 Buffer b;
420 const EVP_MD *evp_md = EVP_sha1(); 422 const EVP_MD *evp_md = EVP_sha1();
421 EVP_MD_CTX md; 423 EVP_MD_CTX md;
422 char c = id; 424 char c = id;
423 int have; 425 u_int have;
424 int mdsz = EVP_MD_size(evp_md); 426 int mdsz = EVP_MD_size(evp_md);
425 u_char *digest = xmalloc(roundup(need, mdsz)); 427 u_char *digest;
428
429 if (mdsz < 0)
430 fatal("derive_key: mdsz < 0");
431 digest = xmalloc(roundup(need, mdsz));
426 432
427 buffer_init(&b); 433 buffer_init(&b);
428 buffer_put_bignum2(&b, shared_secret); 434 buffer_put_bignum2(&b, shared_secret);
@@ -464,7 +470,7 @@ void
464kex_derive_keys(Kex *kex, u_char *hash, BIGNUM *shared_secret) 470kex_derive_keys(Kex *kex, u_char *hash, BIGNUM *shared_secret)
465{ 471{
466 u_char *keys[NKEYS]; 472 u_char *keys[NKEYS];
467 int i, mode, ctos; 473 u_int i, mode, ctos;
468 474
469 for (i = 0; i < NKEYS; i++) 475 for (i = 0; i < NKEYS; i++)
470 keys[i] = derive_key(kex, 'A'+i, kex->we_need, hash, shared_secret); 476 keys[i] = derive_key(kex, 'A'+i, kex->we_need, hash, shared_secret);
@@ -502,13 +508,13 @@ derive_ssh1_session_id(BIGNUM *host_modulus, BIGNUM *server_modulus,
502 EVP_DigestInit(&md, evp_md); 508 EVP_DigestInit(&md, evp_md);
503 509
504 len = BN_num_bytes(host_modulus); 510 len = BN_num_bytes(host_modulus);
505 if (len < (512 / 8) || len > sizeof(nbuf)) 511 if (len < (512 / 8) || (u_int)len > sizeof(nbuf))
506 fatal("%s: bad host modulus (len %d)", __func__, len); 512 fatal("%s: bad host modulus (len %d)", __func__, len);
507 BN_bn2bin(host_modulus, nbuf); 513 BN_bn2bin(host_modulus, nbuf);
508 EVP_DigestUpdate(&md, nbuf, len); 514 EVP_DigestUpdate(&md, nbuf, len);
509 515
510 len = BN_num_bytes(server_modulus); 516 len = BN_num_bytes(server_modulus);
511 if (len < (512 / 8) || len > sizeof(nbuf)) 517 if (len < (512 / 8) || (u_int)len > sizeof(nbuf))
512 fatal("%s: bad server modulus (len %d)", __func__, len); 518 fatal("%s: bad server modulus (len %d)", __func__, len);
513 BN_bn2bin(server_modulus, nbuf); 519 BN_bn2bin(server_modulus, nbuf);
514 EVP_DigestUpdate(&md, nbuf, len); 520 EVP_DigestUpdate(&md, nbuf, len);
@@ -527,7 +533,7 @@ derive_ssh1_session_id(BIGNUM *host_modulus, BIGNUM *server_modulus,
527void 533void
528dump_digest(char *msg, u_char *digest, int len) 534dump_digest(char *msg, u_char *digest, int len)
529{ 535{
530 int i; 536 u_int i;
531 537
532 fprintf(stderr, "%s\n", msg); 538 fprintf(stderr, "%s\n", msg);
533 for (i = 0; i< len; i++) { 539 for (i = 0; i< len; i++) {