[dh.c kex.c packet.c]
     clear+free keys,iv for rekeying.
     + fix DH mem leaks. ok niels@
This commit is contained in:
Ben Lindstrom 2001-04-05 02:05:21 +00:00
parent 8e312f3db0
commit 5ba23b39bf
4 changed files with 30 additions and 21 deletions

View File

@ -24,6 +24,10 @@
[kex.c kexgex.c serverloop.c]
parse full kexinit packet.
make server-side more robust, too.
- markus@cvs.openbsd.org 2001/04/04 23:09:18
[dh.c kex.c packet.c]
clear+free keys,iv for rekeying.
+ fix DH mem leaks. ok niels@
20010404
- OpenBSD CVS Sync
@ -4863,4 +4867,4 @@
- Wrote replacements for strlcpy and mkdtemp
- Released 1.0pre1
$Id: ChangeLog,v 1.1060 2001/04/04 23:50:21 mouring Exp $
$Id: ChangeLog,v 1.1061 2001/04/05 02:05:21 mouring Exp $

13
dh.c
View File

@ -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));
}

5
kex.c
View File

@ -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

View File

@ -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"
@ -123,16 +123,6 @@ int use_ssh2_packet_format = 0;
/* Session key information for Encryption and MAC */
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)
{
@ -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)