summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--cipher.c37
-rw-r--r--monitor.c15
-rw-r--r--monitor_wrap.c14
-rw-r--r--packet.c21
-rw-r--r--packet.h3
6 files changed, 55 insertions, 42 deletions
diff --git a/ChangeLog b/ChangeLog
index 568477786..664f86266 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -30,6 +30,11 @@
30 ssh-keysign.c ssh.1 sshconnect.c sshconnect.h sshconnect2.c ttymodes.c 30 ssh-keysign.c ssh.1 sshconnect.c sshconnect.h sshconnect2.c ttymodes.c
31 xmalloc.h] 31 xmalloc.h]
32 KNF done automatically while reading.... 32 KNF done automatically while reading....
33 - markus@cvs.openbsd.org 2002/06/19 18:01:00
34 [cipher.c monitor.c monitor_wrap.c packet.c packet.h]
35 make the monitor sync the transfer ssh1 session key;
36 transfer keycontext only for RC4 (this is still depends on EVP
37 implementation details and is broken).
33 - (bal) Cygwin special handling of empty passwords wrong. Patch by 38 - (bal) Cygwin special handling of empty passwords wrong. Patch by
34 vinschen@redhat.com 39 vinschen@redhat.com
35 40
@@ -960,4 +965,4 @@
960 - (stevesk) entropy.c: typo in debug message 965 - (stevesk) entropy.c: typo in debug message
961 - (djm) ssh-keygen -i needs seeded RNG; report from markus@ 966 - (djm) ssh-keygen -i needs seeded RNG; report from markus@
962 967
963$Id: ChangeLog,v 1.2225 2002/06/21 00:41:51 mouring Exp $ 968$Id: ChangeLog,v 1.2226 2002/06/21 00:43:42 mouring Exp $
diff --git a/cipher.c b/cipher.c
index 39807d5c2..b18c701fb 100644
--- a/cipher.c
+++ b/cipher.c
@@ -35,7 +35,7 @@
35 */ 35 */
36 36
37#include "includes.h" 37#include "includes.h"
38RCSID("$OpenBSD: cipher.c,v 1.58 2002/06/04 23:05:49 markus Exp $"); 38RCSID("$OpenBSD: cipher.c,v 1.59 2002/06/19 18:01:00 markus Exp $");
39 39
40#include "xmalloc.h" 40#include "xmalloc.h"
41#include "log.h" 41#include "log.h"
@@ -689,28 +689,14 @@ int
689cipher_get_keycontext(CipherContext *cc, u_char *dat) 689cipher_get_keycontext(CipherContext *cc, u_char *dat)
690{ 690{
691 Cipher *c = cc->cipher; 691 Cipher *c = cc->cipher;
692 int plen; 692 int plen = 0;
693 693
694 if (c->number == SSH_CIPHER_3DES) { 694 if (c->evptype == EVP_rc4) {
695 struct ssh1_3des_ctx *desc; 695 plen = EVP_X_STATE_LEN(cc->evp);
696 desc = EVP_CIPHER_CTX_get_app_data(&cc->evp);
697 if (desc == NULL)
698 fatal("%s: no 3des context", __func__);
699 plen = EVP_X_STATE_LEN(desc->k1);
700 if (dat == NULL) 696 if (dat == NULL)
701 return (3*plen); 697 return (plen);
702 memcpy(dat, EVP_X_STATE(desc->k1), plen); 698 memcpy(dat, EVP_X_STATE(cc->evp), plen);
703 memcpy(dat + plen, EVP_X_STATE(desc->k2), plen);
704 memcpy(dat + 2*plen, EVP_X_STATE(desc->k3), plen);
705 return (3*plen);
706 } 699 }
707
708 /* Generic EVP */
709 plen = EVP_X_STATE_LEN(cc->evp);
710 if (dat == NULL)
711 return (plen);
712
713 memcpy(dat, EVP_X_STATE(cc->evp), plen);
714 return (plen); 700 return (plen);
715} 701}
716 702
@@ -720,16 +706,7 @@ cipher_set_keycontext(CipherContext *cc, u_char *dat)
720 Cipher *c = cc->cipher; 706 Cipher *c = cc->cipher;
721 int plen; 707 int plen;
722 708
723 if (c->number == SSH_CIPHER_3DES) { 709 if (c->evptype == EVP_rc4) {
724 struct ssh1_3des_ctx *desc;
725 desc = EVP_CIPHER_CTX_get_app_data(&cc->evp);
726 if (desc == NULL)
727 fatal("%s: no 3des context", __func__);
728 plen = EVP_X_STATE_LEN(desc->k1);
729 memcpy(EVP_X_STATE(desc->k1), dat, plen);
730 memcpy(EVP_X_STATE(desc->k2), dat + plen, plen);
731 memcpy(EVP_X_STATE(desc->k3), dat + 2*plen, plen);
732 } else {
733 plen = EVP_X_STATE_LEN(cc->evp); 710 plen = EVP_X_STATE_LEN(cc->evp);
734 memcpy(EVP_X_STATE(cc->evp), dat, plen); 711 memcpy(EVP_X_STATE(cc->evp), dat, plen);
735 } 712 }
diff --git a/monitor.c b/monitor.c
index 39009f703..c769f12e7 100644
--- a/monitor.c
+++ b/monitor.c
@@ -25,7 +25,7 @@
25 */ 25 */
26 26
27#include "includes.h" 27#include "includes.h"
28RCSID("$OpenBSD: monitor.c,v 1.14 2002/06/04 23:05:49 markus Exp $"); 28RCSID("$OpenBSD: monitor.c,v 1.15 2002/06/19 18:01:00 markus Exp $");
29 29
30#include <openssl/dh.h> 30#include <openssl/dh.h>
31 31
@@ -83,6 +83,8 @@ struct {
83 u_int ivinlen; 83 u_int ivinlen;
84 u_char *ivout; 84 u_char *ivout;
85 u_int ivoutlen; 85 u_int ivoutlen;
86 u_char *ssh1key;
87 u_int ssh1keylen;
86 int ssh1cipher; 88 int ssh1cipher;
87 int ssh1protoflags; 89 int ssh1protoflags;
88 u_char *input; 90 u_char *input;
@@ -1303,14 +1305,13 @@ monitor_apply_keystate(struct monitor *pmonitor)
1303 set_newkeys(MODE_IN); 1305 set_newkeys(MODE_IN);
1304 set_newkeys(MODE_OUT); 1306 set_newkeys(MODE_OUT);
1305 } else { 1307 } else {
1306 u_char key[SSH_SESSION_KEY_LENGTH];
1307
1308 memset(key, 'a', sizeof(key));
1309 packet_set_protocol_flags(child_state.ssh1protoflags); 1308 packet_set_protocol_flags(child_state.ssh1protoflags);
1310 packet_set_encryption_key(key, SSH_SESSION_KEY_LENGTH, 1309 packet_set_encryption_key(child_state.ssh1key,
1311 child_state.ssh1cipher); 1310 child_state.ssh1keylen, child_state.ssh1cipher);
1311 xfree(child_state.ssh1key);
1312 } 1312 }
1313 1313
1314 /* for rc4 and other stateful ciphers */
1314 packet_set_keycontext(MODE_OUT, child_state.keyout); 1315 packet_set_keycontext(MODE_OUT, child_state.keyout);
1315 xfree(child_state.keyout); 1316 xfree(child_state.keyout);
1316 packet_set_keycontext(MODE_IN, child_state.keyin); 1317 packet_set_keycontext(MODE_IN, child_state.keyin);
@@ -1396,6 +1397,8 @@ mm_get_keystate(struct monitor *pmonitor)
1396 if (!compat20) { 1397 if (!compat20) {
1397 child_state.ssh1protoflags = buffer_get_int(&m); 1398 child_state.ssh1protoflags = buffer_get_int(&m);
1398 child_state.ssh1cipher = buffer_get_int(&m); 1399 child_state.ssh1cipher = buffer_get_int(&m);
1400 child_state.ssh1key = buffer_get_string(&m,
1401 &child_state.ssh1keylen);
1399 child_state.ivout = buffer_get_string(&m, 1402 child_state.ivout = buffer_get_string(&m,
1400 &child_state.ivoutlen); 1403 &child_state.ivoutlen);
1401 child_state.ivin = buffer_get_string(&m, &child_state.ivinlen); 1404 child_state.ivin = buffer_get_string(&m, &child_state.ivinlen);
diff --git a/monitor_wrap.c b/monitor_wrap.c
index e40874627..f7e332d8e 100644
--- a/monitor_wrap.c
+++ b/monitor_wrap.c
@@ -25,7 +25,7 @@
25 */ 25 */
26 26
27#include "includes.h" 27#include "includes.h"
28RCSID("$OpenBSD: monitor_wrap.c,v 1.10 2002/06/19 00:27:55 deraadt Exp $"); 28RCSID("$OpenBSD: monitor_wrap.c,v 1.11 2002/06/19 18:01:00 markus Exp $");
29 29
30#include <openssl/bn.h> 30#include <openssl/bn.h>
31#include <openssl/dh.h> 31#include <openssl/dh.h>
@@ -520,13 +520,21 @@ mm_send_keystate(struct monitor *pmonitor)
520 520
521 if (!compat20) { 521 if (!compat20) {
522 u_char iv[24]; 522 u_char iv[24];
523 int ivlen; 523 u_char *key;
524 u_int ivlen, keylen;
524 525
525 buffer_put_int(&m, packet_get_protocol_flags()); 526 buffer_put_int(&m, packet_get_protocol_flags());
526 527
527 buffer_put_int(&m, packet_get_ssh1_cipher()); 528 buffer_put_int(&m, packet_get_ssh1_cipher());
528 529
529 debug3("%s: Sending ssh1 IV", __func__); 530 debug3("%s: Sending ssh1 KEY+IV", __func__);
531 keylen = packet_get_encryption_key(NULL);
532 key = xmalloc(keylen+1); /* add 1 if keylen == 0 */
533 keylen = packet_get_encryption_key(key);
534 buffer_put_string(&m, key, keylen);
535 memset(key, 0, keylen);
536 xfree(key);
537
530 ivlen = packet_get_keyiv_len(MODE_OUT); 538 ivlen = packet_get_keyiv_len(MODE_OUT);
531 packet_get_keyiv(MODE_OUT, iv, ivlen); 539 packet_get_keyiv(MODE_OUT, iv, ivlen);
532 buffer_put_string(&m, iv, ivlen); 540 buffer_put_string(&m, iv, ivlen);
diff --git a/packet.c b/packet.c
index abc89e76c..86511276f 100644
--- a/packet.c
+++ b/packet.c
@@ -37,7 +37,7 @@
37 */ 37 */
38 38
39#include "includes.h" 39#include "includes.h"
40RCSID("$OpenBSD: packet.c,v 1.94 2002/06/04 23:02:06 markus Exp $"); 40RCSID("$OpenBSD: packet.c,v 1.95 2002/06/19 18:01:00 markus Exp $");
41 41
42#include "xmalloc.h" 42#include "xmalloc.h"
43#include "buffer.h" 43#include "buffer.h"
@@ -60,6 +60,7 @@ RCSID("$OpenBSD: packet.c,v 1.94 2002/06/04 23:02:06 markus Exp $");
60#include "log.h" 60#include "log.h"
61#include "canohost.h" 61#include "canohost.h"
62#include "misc.h" 62#include "misc.h"
63#include "ssh.h"
63 64
64#ifdef PACKET_DEBUG 65#ifdef PACKET_DEBUG
65#define DBG(x) x 66#define DBG(x) x
@@ -118,6 +119,10 @@ Newkeys *newkeys[MODE_MAX];
118static u_int32_t read_seqnr = 0; 119static u_int32_t read_seqnr = 0;
119static u_int32_t send_seqnr = 0; 120static u_int32_t send_seqnr = 0;
120 121
122/* Session key for protocol v1 */
123static u_char ssh1_key[SSH_SESSION_KEY_LENGTH];
124static u_int ssh1_keylen;
125
121/* roundup current message to extra_pad bytes */ 126/* roundup current message to extra_pad bytes */
122static u_char extra_pad = 0; 127static u_char extra_pad = 0;
123 128
@@ -391,6 +396,7 @@ packet_start_compression(int level)
391 * key is used for both sending and reception. However, both directions are 396 * key is used for both sending and reception. However, both directions are
392 * encrypted independently of each other. 397 * encrypted independently of each other.
393 */ 398 */
399
394void 400void
395packet_set_encryption_key(const u_char *key, u_int keylen, 401packet_set_encryption_key(const u_char *key, u_int keylen,
396 int number) 402 int number)
@@ -400,10 +406,23 @@ packet_set_encryption_key(const u_char *key, u_int keylen,
400 fatal("packet_set_encryption_key: unknown cipher number %d", number); 406 fatal("packet_set_encryption_key: unknown cipher number %d", number);
401 if (keylen < 20) 407 if (keylen < 20)
402 fatal("packet_set_encryption_key: keylen too small: %d", keylen); 408 fatal("packet_set_encryption_key: keylen too small: %d", keylen);
409 if (keylen > SSH_SESSION_KEY_LENGTH)
410 fatal("packet_set_encryption_key: keylen too big: %d", keylen);
411 memcpy(ssh1_key, key, keylen);
412 ssh1_keylen = keylen;
403 cipher_init(&send_context, cipher, key, keylen, NULL, 0, CIPHER_ENCRYPT); 413 cipher_init(&send_context, cipher, key, keylen, NULL, 0, CIPHER_ENCRYPT);
404 cipher_init(&receive_context, cipher, key, keylen, NULL, 0, CIPHER_DECRYPT); 414 cipher_init(&receive_context, cipher, key, keylen, NULL, 0, CIPHER_DECRYPT);
405} 415}
406 416
417u_int
418packet_get_encryption_key(u_char *key)
419{
420 if (key == NULL)
421 return (ssh1_keylen);
422 memcpy(key, ssh1_key, ssh1_keylen);
423 return (ssh1_keylen);
424}
425
407/* Start constructing a packet to send. */ 426/* Start constructing a packet to send. */
408void 427void
409packet_start(u_char type) 428packet_start(u_char type)
diff --git a/packet.h b/packet.h
index 151ca74a1..3ff75593a 100644
--- a/packet.h
+++ b/packet.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: packet.h,v 1.34 2002/03/18 17:16:38 markus Exp $ */ 1/* $OpenBSD: packet.h,v 1.35 2002/06/19 18:01:00 markus Exp $ */
2 2
3/* 3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -24,6 +24,7 @@ int packet_get_connection_in(void);
24int packet_get_connection_out(void); 24int packet_get_connection_out(void);
25void packet_close(void); 25void packet_close(void);
26void packet_set_encryption_key(const u_char *, u_int, int); 26void packet_set_encryption_key(const u_char *, u_int, int);
27u_int packet_get_encryption_key(u_char *);
27void packet_set_protocol_flags(u_int); 28void packet_set_protocol_flags(u_int);
28u_int packet_get_protocol_flags(void); 29u_int packet_get_protocol_flags(void);
29void packet_start_compression(int); 30void packet_start_compression(int);