summaryrefslogtreecommitdiff
path: root/kex.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2015-01-30 00:22:25 +0000
committerDamien Miller <djm@mindrot.org>2015-01-30 12:16:33 +1100
commit25f5f78d8bf5c22d9cea8b49de24ebeee648a355 (patch)
tree5ce84c180ed0769333a62335bd1d10d785f190b8 /kex.c
parent9ce86c926dfa6e0635161b035e3944e611cbccf0 (diff)
upstream commit
fix ssh protocol 1, spotted by miod@
Diffstat (limited to 'kex.c')
-rw-r--r--kex.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/kex.c b/kex.c
index 7eb3185e6..2618e225d 100644
--- a/kex.c
+++ b/kex.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kex.c,v 1.104 2015/01/26 06:10:03 djm Exp $ */ 1/* $OpenBSD: kex.c,v 1.105 2015/01/30 00:22:25 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
4 * 4 *
@@ -785,17 +785,27 @@ int
785derive_ssh1_session_id(BIGNUM *host_modulus, BIGNUM *server_modulus, 785derive_ssh1_session_id(BIGNUM *host_modulus, BIGNUM *server_modulus,
786 u_int8_t cookie[8], u_int8_t id[16]) 786 u_int8_t cookie[8], u_int8_t id[16])
787{ 787{
788 u_int8_t nbuf[2048], obuf[SSH_DIGEST_MAX_LENGTH]; 788 u_int8_t hbuf[2048], sbuf[2048], obuf[SSH_DIGEST_MAX_LENGTH];
789 struct ssh_digest_ctx *hashctx = NULL; 789 struct ssh_digest_ctx *hashctx = NULL;
790 size_t len; 790 size_t hlen, slen;
791 int r; 791 int r;
792 792
793 len = BN_num_bytes(host_modulus); 793 hlen = BN_num_bytes(host_modulus);
794 if (len < (512 / 8) || (u_int)len > sizeof(nbuf)) 794 slen = BN_num_bytes(server_modulus);
795 if (hlen < (512 / 8) || (u_int)hlen > sizeof(hbuf) ||
796 slen < (512 / 8) || (u_int)slen > sizeof(sbuf))
795 return SSH_ERR_KEY_BITS_MISMATCH; 797 return SSH_ERR_KEY_BITS_MISMATCH;
796 if (BN_bn2bin(host_modulus, nbuf) <= 0 || 798 if (BN_bn2bin(host_modulus, hbuf) <= 0 ||
797 (hashctx = ssh_digest_start(SSH_DIGEST_MD5)) == NULL || 799 BN_bn2bin(server_modulus, sbuf) <= 0) {
798 ssh_digest_update(hashctx, nbuf, len) != 0 || 800 r = SSH_ERR_LIBCRYPTO_ERROR;
801 goto out;
802 }
803 if ((hashctx = ssh_digest_start(SSH_DIGEST_MD5)) == NULL) {
804 r = SSH_ERR_ALLOC_FAIL;
805 goto out;
806 }
807 if (ssh_digest_update(hashctx, hbuf, hlen) != 0 ||
808 ssh_digest_update(hashctx, sbuf, slen) != 0 ||
799 ssh_digest_update(hashctx, cookie, 8) != 0 || 809 ssh_digest_update(hashctx, cookie, 8) != 0 ||
800 ssh_digest_final(hashctx, obuf, sizeof(obuf)) != 0) { 810 ssh_digest_final(hashctx, obuf, sizeof(obuf)) != 0) {
801 r = SSH_ERR_LIBCRYPTO_ERROR; 811 r = SSH_ERR_LIBCRYPTO_ERROR;
@@ -805,7 +815,8 @@ derive_ssh1_session_id(BIGNUM *host_modulus, BIGNUM *server_modulus,
805 r = 0; 815 r = 0;
806 out: 816 out:
807 ssh_digest_free(hashctx); 817 ssh_digest_free(hashctx);
808 explicit_bzero(nbuf, sizeof(nbuf)); 818 explicit_bzero(hbuf, sizeof(hbuf));
819 explicit_bzero(sbuf, sizeof(sbuf));
809 explicit_bzero(obuf, sizeof(obuf)); 820 explicit_bzero(obuf, sizeof(obuf));
810 return r; 821 return r;
811} 822}