summaryrefslogtreecommitdiff
path: root/usr.bin/ssh
diff options
context:
space:
mode:
authorMarkus Friedl <markus@cvs.openbsd.org>2001-04-04 23:09:19 +0000
committerMarkus Friedl <markus@cvs.openbsd.org>2001-04-04 23:09:19 +0000
commit7c338865110f0cd220cc3e6beaaaff44ff0d5db0 (patch)
treedcf4c5a93521b195119910fefa4844c43dac4734 /usr.bin/ssh
parent70a654e9320395e2a4d3c07fd255feeffb9dbeb4 (diff)
clear+free keys,iv for rekeying.
+ fix DH mem leaks. ok niels@
Diffstat (limited to 'usr.bin/ssh')
-rw-r--r--usr.bin/ssh/dh.c13
-rw-r--r--usr.bin/ssh/kex.c5
-rw-r--r--usr.bin/ssh/packet.c27
3 files changed, 25 insertions, 20 deletions
diff --git a/usr.bin/ssh/dh.c b/usr.bin/ssh/dh.c
index 03b9fd1b84e..982064f54a1 100644
--- a/usr.bin/ssh/dh.c
+++ b/usr.bin/ssh/dh.c
@@ -23,7 +23,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: dh.c,v 1.12 2001/04/03 19:53:29 markus Exp $");
+RCSID("$OpenBSD: dh.c,v 1.13 2001/04/04 23:09:17 markus Exp $");
#include "xmalloc.h"
@@ -151,11 +151,9 @@ choose_dh(int min, int wantbits, int max)
while (fgets(line, sizeof(line), f)) {
if (!parse_prime(linenum, line, &dhg))
continue;
- if (dhg.size > max || dhg.size < min)
- continue;
- if (dhg.size != best)
- continue;
- if (linenum++ != which) {
+ if ((dhg.size > max || dhg.size < min) ||
+ dhg.size != best ||
+ linenum++ != which) {
BN_free(dhg.g);
BN_free(dhg.p);
continue;
@@ -163,6 +161,9 @@ choose_dh(int min, int wantbits, int max)
break;
}
fclose(f);
+ if (linenum != which+1)
+ fatal("WARNING: line %d disappeared in %s, giving up",
+ which, _PATH_DH_PRIMES);
return (dh_new_group(dhg.g, dhg.p));
}
diff --git a/usr.bin/ssh/kex.c b/usr.bin/ssh/kex.c
index 0720c073d4e..39f037b7474 100644
--- a/usr.bin/ssh/kex.c
+++ b/usr.bin/ssh/kex.c
@@ -23,7 +23,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: kex.c,v 1.31 2001/04/04 22:04:34 markus Exp $");
+RCSID("$OpenBSD: kex.c,v 1.32 2001/04/04 23:09:18 markus Exp $");
#include <openssl/crypto.h>
@@ -136,10 +136,13 @@ kex_finish(Kex *kex)
debug("waiting for SSH2_MSG_NEWKEYS");
packet_read_expect(&plen, SSH2_MSG_NEWKEYS);
debug("SSH2_MSG_NEWKEYS received");
+
kex->done = 1;
buffer_clear(&kex->peer);
/* buffer_clear(&kex->my); */
kex->flags &= ~KEX_INIT_SENT;
+ xfree(kex->name);
+ kex->name = NULL;
}
void
diff --git a/usr.bin/ssh/packet.c b/usr.bin/ssh/packet.c
index 4c5271c6a2c..229cd72b8f7 100644
--- a/usr.bin/ssh/packet.c
+++ b/usr.bin/ssh/packet.c
@@ -37,7 +37,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: packet.c,v 1.58 2001/04/04 09:48:34 markus Exp $");
+RCSID("$OpenBSD: packet.c,v 1.59 2001/04/04 23:09:18 markus Exp $");
#include "xmalloc.h"
#include "buffer.h"
@@ -124,16 +124,6 @@ int use_ssh2_packet_format = 0;
Newkeys *newkeys[MODE_MAX];
void
-clear_enc_keys(Enc *enc, int len)
-{
- memset(enc->iv, 0, len);
- memset(enc->key, 0, len);
- xfree(enc->iv);
- xfree(enc->key);
- enc->iv = NULL;
- enc->key = NULL;
-}
-void
packet_set_ssh2_format(void)
{
DBG(debug("use_ssh2_packet_format"));
@@ -524,8 +514,18 @@ set_newkeys(int mode)
cc = (mode == MODE_OUT) ? &send_context : &receive_context;
if (newkeys[mode] != NULL) {
debug("newkeys: rekeying");
- memset(cc, 0, sizeof(*cc));
/* todo: free old keys, reset compression/cipher-ctxt; */
+ memset(cc, 0, sizeof(*cc));
+ enc = &newkeys[mode]->enc;
+ mac = &newkeys[mode]->mac;
+ comp = &newkeys[mode]->comp;
+ memset(mac->key, 0, mac->key_len);
+ xfree(enc->name);
+ xfree(enc->iv);
+ xfree(enc->key);
+ xfree(mac->name);
+ xfree(mac->key);
+ xfree(comp->name);
xfree(newkeys[mode]);
}
newkeys[mode] = kex_get_newkeys(mode);
@@ -539,7 +539,8 @@ set_newkeys(int mode)
DBG(debug("cipher_init_context: %d", mode));
cipher_init(cc, enc->cipher, enc->key, enc->cipher->key_len,
enc->iv, enc->cipher->block_size);
- clear_enc_keys(enc, enc->cipher->key_len);
+ memset(enc->iv, 0, enc->cipher->block_size);
+ memset(enc->key, 0, enc->cipher->key_len);
if (comp->type != 0 && comp->enabled == 0) {
comp->enabled = 1;
if (! packet_compression)