diff options
author | Markus Friedl <markus@cvs.openbsd.org> | 2002-06-19 18:01:01 +0000 |
---|---|---|
committer | Markus Friedl <markus@cvs.openbsd.org> | 2002-06-19 18:01:01 +0000 |
commit | 171ba25c335bf855de91621f9b8c35c4dad20fc9 (patch) | |
tree | 3644c73127cb86b94e7a4ddb9c3a4cb5db8c3d42 | |
parent | 8de5c0bca7d16bd7925451896f1d82a4c1147282 (diff) |
make the monitor sync the transfer ssh1 session key;
transfer keycontext only for RC4 (this is still depends on EVP
implementation details and is broken).
-rw-r--r-- | usr.bin/ssh/cipher.c | 37 | ||||
-rw-r--r-- | usr.bin/ssh/monitor.c | 15 | ||||
-rw-r--r-- | usr.bin/ssh/monitor_wrap.c | 14 | ||||
-rw-r--r-- | usr.bin/ssh/packet.c | 21 | ||||
-rw-r--r-- | usr.bin/ssh/packet.h | 3 |
5 files changed, 49 insertions, 41 deletions
diff --git a/usr.bin/ssh/cipher.c b/usr.bin/ssh/cipher.c index 11d2b41663b..36d616a311c 100644 --- a/usr.bin/ssh/cipher.c +++ b/usr.bin/ssh/cipher.c @@ -35,7 +35,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: cipher.c,v 1.58 2002/06/04 23:05:49 markus Exp $"); +RCSID("$OpenBSD: cipher.c,v 1.59 2002/06/19 18:01:00 markus Exp $"); #include "xmalloc.h" #include "log.h" @@ -646,28 +646,14 @@ int cipher_get_keycontext(CipherContext *cc, u_char *dat) { Cipher *c = cc->cipher; - int plen; + int plen = 0; - if (c->number == SSH_CIPHER_3DES) { - struct ssh1_3des_ctx *desc; - desc = EVP_CIPHER_CTX_get_app_data(&cc->evp); - if (desc == NULL) - fatal("%s: no 3des context", __func__); - plen = EVP_X_STATE_LEN(desc->k1); + if (c->evptype == EVP_rc4) { + plen = EVP_X_STATE_LEN(cc->evp); if (dat == NULL) - return (3*plen); - memcpy(dat, EVP_X_STATE(desc->k1), plen); - memcpy(dat + plen, EVP_X_STATE(desc->k2), plen); - memcpy(dat + 2*plen, EVP_X_STATE(desc->k3), plen); - return (3*plen); + return (plen); + memcpy(dat, EVP_X_STATE(cc->evp), plen); } - - /* Generic EVP */ - plen = EVP_X_STATE_LEN(cc->evp); - if (dat == NULL) - return (plen); - - memcpy(dat, EVP_X_STATE(cc->evp), plen); return (plen); } @@ -677,16 +663,7 @@ cipher_set_keycontext(CipherContext *cc, u_char *dat) Cipher *c = cc->cipher; int plen; - if (c->number == SSH_CIPHER_3DES) { - struct ssh1_3des_ctx *desc; - desc = EVP_CIPHER_CTX_get_app_data(&cc->evp); - if (desc == NULL) - fatal("%s: no 3des context", __func__); - plen = EVP_X_STATE_LEN(desc->k1); - memcpy(EVP_X_STATE(desc->k1), dat, plen); - memcpy(EVP_X_STATE(desc->k2), dat + plen, plen); - memcpy(EVP_X_STATE(desc->k3), dat + 2*plen, plen); - } else { + if (c->evptype == EVP_rc4) { plen = EVP_X_STATE_LEN(cc->evp); memcpy(EVP_X_STATE(cc->evp), dat, plen); } diff --git a/usr.bin/ssh/monitor.c b/usr.bin/ssh/monitor.c index d0479d00bc1..c6c452668ee 100644 --- a/usr.bin/ssh/monitor.c +++ b/usr.bin/ssh/monitor.c @@ -25,7 +25,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: monitor.c,v 1.14 2002/06/04 23:05:49 markus Exp $"); +RCSID("$OpenBSD: monitor.c,v 1.15 2002/06/19 18:01:00 markus Exp $"); #include <openssl/dh.h> @@ -83,6 +83,8 @@ struct { u_int ivinlen; u_char *ivout; u_int ivoutlen; + u_char *ssh1key; + u_int ssh1keylen; int ssh1cipher; int ssh1protoflags; u_char *input; @@ -1265,14 +1267,13 @@ monitor_apply_keystate(struct monitor *pmonitor) set_newkeys(MODE_IN); set_newkeys(MODE_OUT); } else { - u_char key[SSH_SESSION_KEY_LENGTH]; - - memset(key, 'a', sizeof(key)); packet_set_protocol_flags(child_state.ssh1protoflags); - packet_set_encryption_key(key, SSH_SESSION_KEY_LENGTH, - child_state.ssh1cipher); + packet_set_encryption_key(child_state.ssh1key, + child_state.ssh1keylen, child_state.ssh1cipher); + xfree(child_state.ssh1key); } + /* for rc4 and other stateful ciphers */ packet_set_keycontext(MODE_OUT, child_state.keyout); xfree(child_state.keyout); packet_set_keycontext(MODE_IN, child_state.keyin); @@ -1358,6 +1359,8 @@ mm_get_keystate(struct monitor *pmonitor) if (!compat20) { child_state.ssh1protoflags = buffer_get_int(&m); child_state.ssh1cipher = buffer_get_int(&m); + child_state.ssh1key = buffer_get_string(&m, + &child_state.ssh1keylen); child_state.ivout = buffer_get_string(&m, &child_state.ivoutlen); child_state.ivin = buffer_get_string(&m, &child_state.ivinlen); diff --git a/usr.bin/ssh/monitor_wrap.c b/usr.bin/ssh/monitor_wrap.c index e6faffc7cbb..faad6c2a7e3 100644 --- a/usr.bin/ssh/monitor_wrap.c +++ b/usr.bin/ssh/monitor_wrap.c @@ -25,7 +25,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: monitor_wrap.c,v 1.10 2002/06/19 00:27:55 deraadt Exp $"); +RCSID("$OpenBSD: monitor_wrap.c,v 1.11 2002/06/19 18:01:00 markus Exp $"); #include <openssl/bn.h> #include <openssl/dh.h> @@ -518,13 +518,21 @@ mm_send_keystate(struct monitor *pmonitor) if (!compat20) { u_char iv[24]; - int ivlen; + u_char *key; + u_int ivlen, keylen; buffer_put_int(&m, packet_get_protocol_flags()); buffer_put_int(&m, packet_get_ssh1_cipher()); - debug3("%s: Sending ssh1 IV", __func__); + debug3("%s: Sending ssh1 KEY+IV", __func__); + keylen = packet_get_encryption_key(NULL); + key = xmalloc(keylen+1); /* add 1 if keylen == 0 */ + keylen = packet_get_encryption_key(key); + buffer_put_string(&m, key, keylen); + memset(key, 0, keylen); + xfree(key); + ivlen = packet_get_keyiv_len(MODE_OUT); packet_get_keyiv(MODE_OUT, iv, ivlen); buffer_put_string(&m, iv, ivlen); diff --git a/usr.bin/ssh/packet.c b/usr.bin/ssh/packet.c index 7e5b30a7ff7..759361bc59a 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.94 2002/06/04 23:02:06 markus Exp $"); +RCSID("$OpenBSD: packet.c,v 1.95 2002/06/19 18:01:00 markus Exp $"); #include "xmalloc.h" #include "buffer.h" @@ -60,6 +60,7 @@ RCSID("$OpenBSD: packet.c,v 1.94 2002/06/04 23:02:06 markus Exp $"); #include "log.h" #include "canohost.h" #include "misc.h" +#include "ssh.h" #ifdef PACKET_DEBUG #define DBG(x) x @@ -118,6 +119,10 @@ Newkeys *newkeys[MODE_MAX]; static u_int32_t read_seqnr = 0; static u_int32_t send_seqnr = 0; +/* Session key for protocol v1 */ +static u_char ssh1_key[SSH_SESSION_KEY_LENGTH]; +static u_int ssh1_keylen; + /* roundup current message to extra_pad bytes */ static u_char extra_pad = 0; @@ -386,6 +391,7 @@ packet_start_compression(int level) * key is used for both sending and reception. However, both directions are * encrypted independently of each other. */ + void packet_set_encryption_key(const u_char *key, u_int keylen, int number) @@ -395,10 +401,23 @@ packet_set_encryption_key(const u_char *key, u_int keylen, fatal("packet_set_encryption_key: unknown cipher number %d", number); if (keylen < 20) fatal("packet_set_encryption_key: keylen too small: %d", keylen); + if (keylen > SSH_SESSION_KEY_LENGTH) + fatal("packet_set_encryption_key: keylen too big: %d", keylen); + memcpy(ssh1_key, key, keylen); + ssh1_keylen = keylen; cipher_init(&send_context, cipher, key, keylen, NULL, 0, CIPHER_ENCRYPT); cipher_init(&receive_context, cipher, key, keylen, NULL, 0, CIPHER_DECRYPT); } +u_int +packet_get_encryption_key(u_char *key) +{ + if (key == NULL) + return (ssh1_keylen); + memcpy(key, ssh1_key, ssh1_keylen); + return (ssh1_keylen); +} + /* Start constructing a packet to send. */ void packet_start(u_char type) diff --git a/usr.bin/ssh/packet.h b/usr.bin/ssh/packet.h index 151ca74a10f..3ff75593adb 100644 --- a/usr.bin/ssh/packet.h +++ b/usr.bin/ssh/packet.h @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.h,v 1.34 2002/03/18 17:16:38 markus Exp $ */ +/* $OpenBSD: packet.h,v 1.35 2002/06/19 18:01:00 markus Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> @@ -24,6 +24,7 @@ int packet_get_connection_in(void); int packet_get_connection_out(void); void packet_close(void); void packet_set_encryption_key(const u_char *, u_int, int); +u_int packet_get_encryption_key(u_char *); void packet_set_protocol_flags(u_int); u_int packet_get_protocol_flags(void); void packet_start_compression(int); |