diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | packet.c | 124 | ||||
-rw-r--r-- | packet.h | 12 |
3 files changed, 124 insertions, 17 deletions
@@ -47,6 +47,9 @@ | |||
47 | - markus@cvs.openbsd.org 2002/03/18 17:13:15 | 47 | - markus@cvs.openbsd.org 2002/03/18 17:13:15 |
48 | [cipher.c cipher.h] | 48 | [cipher.c cipher.h] |
49 | export/import cipher states; needed by ssh-privsep | 49 | export/import cipher states; needed by ssh-privsep |
50 | - markus@cvs.openbsd.org 2002/03/18 17:16:38 | ||
51 | [packet.c packet.h] | ||
52 | export/import cipher state, iv and ssh2 seqnr; needed by ssh-privsep | ||
50 | 53 | ||
51 | 20020317 | 54 | 20020317 |
52 | - (tim) [configure.ac] Assume path given with --with-pid-dir=PATH is wanted, | 55 | - (tim) [configure.ac] Assume path given with --with-pid-dir=PATH is wanted, |
@@ -7893,4 +7896,4 @@ | |||
7893 | - Wrote replacements for strlcpy and mkdtemp | 7896 | - Wrote replacements for strlcpy and mkdtemp |
7894 | - Released 1.0pre1 | 7897 | - Released 1.0pre1 |
7895 | 7898 | ||
7896 | $Id: ChangeLog,v 1.1938 2002/03/22 01:39:44 mouring Exp $ | 7899 | $Id: ChangeLog,v 1.1939 2002/03/22 01:42:04 mouring Exp $ |
@@ -37,7 +37,7 @@ | |||
37 | */ | 37 | */ |
38 | 38 | ||
39 | #include "includes.h" | 39 | #include "includes.h" |
40 | RCSID("$OpenBSD: packet.c,v 1.90 2002/02/27 21:23:13 stevesk Exp $"); | 40 | RCSID("$OpenBSD: packet.c,v 1.91 2002/03/18 17:16:38 markus Exp $"); |
41 | 41 | ||
42 | #include "xmalloc.h" | 42 | #include "xmalloc.h" |
43 | #include "buffer.h" | 43 | #include "buffer.h" |
@@ -86,10 +86,10 @@ static CipherContext receive_context; | |||
86 | static CipherContext send_context; | 86 | static CipherContext send_context; |
87 | 87 | ||
88 | /* Buffer for raw input data from the socket. */ | 88 | /* Buffer for raw input data from the socket. */ |
89 | static Buffer input; | 89 | Buffer input; |
90 | 90 | ||
91 | /* Buffer for raw output data going to the socket. */ | 91 | /* Buffer for raw output data going to the socket. */ |
92 | static Buffer output; | 92 | Buffer output; |
93 | 93 | ||
94 | /* Buffer for the partial outgoing packet being constructed. */ | 94 | /* Buffer for the partial outgoing packet being constructed. */ |
95 | static Buffer outgoing_packet; | 95 | static Buffer outgoing_packet; |
@@ -115,6 +115,8 @@ static int interactive_mode = 0; | |||
115 | 115 | ||
116 | /* Session key information for Encryption and MAC */ | 116 | /* Session key information for Encryption and MAC */ |
117 | Newkeys *newkeys[MODE_MAX]; | 117 | Newkeys *newkeys[MODE_MAX]; |
118 | static u_int32_t read_seqnr = 0; | ||
119 | static u_int32_t send_seqnr = 0; | ||
118 | 120 | ||
119 | /* roundup current message to extra_pad bytes */ | 121 | /* roundup current message to extra_pad bytes */ |
120 | static u_char extra_pad = 0; | 122 | static u_char extra_pad = 0; |
@@ -171,6 +173,99 @@ packet_connection_is_on_socket(void) | |||
171 | return 1; | 173 | return 1; |
172 | } | 174 | } |
173 | 175 | ||
176 | /* | ||
177 | * Exports an IV from the CipherContext required to export the key | ||
178 | * state back from the unprivileged child to the privileged parent | ||
179 | * process. | ||
180 | */ | ||
181 | |||
182 | void | ||
183 | packet_get_keyiv(int mode, u_char *iv, u_int len) | ||
184 | { | ||
185 | CipherContext *cc; | ||
186 | |||
187 | if (mode == MODE_OUT) | ||
188 | cc = &send_context; | ||
189 | else | ||
190 | cc = &receive_context; | ||
191 | |||
192 | cipher_get_keyiv(cc, iv, len); | ||
193 | } | ||
194 | |||
195 | int | ||
196 | packet_get_keycontext(int mode, u_char *dat) | ||
197 | { | ||
198 | CipherContext *cc; | ||
199 | |||
200 | if (mode == MODE_OUT) | ||
201 | cc = &send_context; | ||
202 | else | ||
203 | cc = &receive_context; | ||
204 | |||
205 | return (cipher_get_keycontext(cc, dat)); | ||
206 | } | ||
207 | |||
208 | void | ||
209 | packet_set_keycontext(int mode, u_char *dat) | ||
210 | { | ||
211 | CipherContext *cc; | ||
212 | |||
213 | if (mode == MODE_OUT) | ||
214 | cc = &send_context; | ||
215 | else | ||
216 | cc = &receive_context; | ||
217 | |||
218 | cipher_set_keycontext(cc, dat); | ||
219 | } | ||
220 | |||
221 | int | ||
222 | packet_get_keyiv_len(int mode) | ||
223 | { | ||
224 | CipherContext *cc; | ||
225 | |||
226 | if (mode == MODE_OUT) | ||
227 | cc = &send_context; | ||
228 | else | ||
229 | cc = &receive_context; | ||
230 | |||
231 | return (cipher_get_keyiv_len(cc)); | ||
232 | } | ||
233 | void | ||
234 | packet_set_iv(int mode, u_char *dat) | ||
235 | { | ||
236 | CipherContext *cc; | ||
237 | |||
238 | if (mode == MODE_OUT) | ||
239 | cc = &send_context; | ||
240 | else | ||
241 | cc = &receive_context; | ||
242 | |||
243 | cipher_set_keyiv(cc, dat); | ||
244 | } | ||
245 | int | ||
246 | packet_get_ssh1_cipher() | ||
247 | { | ||
248 | return (cipher_get_number(receive_context.cipher)); | ||
249 | } | ||
250 | |||
251 | |||
252 | u_int32_t | ||
253 | packet_get_seqnr(int mode) | ||
254 | { | ||
255 | return (mode == MODE_IN ? read_seqnr : send_seqnr); | ||
256 | } | ||
257 | |||
258 | void | ||
259 | packet_set_seqnr(int mode, u_int32_t seqnr) | ||
260 | { | ||
261 | if (mode == MODE_IN) | ||
262 | read_seqnr = seqnr; | ||
263 | else if (mode == MODE_OUT) | ||
264 | send_seqnr = seqnr; | ||
265 | else | ||
266 | fatal("%s: bad mode %d", __FUNCTION__, mode); | ||
267 | } | ||
268 | |||
174 | /* returns 1 if connection is via ipv4 */ | 269 | /* returns 1 if connection is via ipv4 */ |
175 | 270 | ||
176 | int | 271 | int |
@@ -433,7 +528,7 @@ packet_send1(void) | |||
433 | */ | 528 | */ |
434 | } | 529 | } |
435 | 530 | ||
436 | static void | 531 | void |
437 | set_newkeys(int mode) | 532 | set_newkeys(int mode) |
438 | { | 533 | { |
439 | Enc *enc; | 534 | Enc *enc; |
@@ -477,8 +572,9 @@ set_newkeys(int mode) | |||
477 | DBG(debug("cipher_init_context: %d", mode)); | 572 | DBG(debug("cipher_init_context: %d", mode)); |
478 | cipher_init(cc, enc->cipher, enc->key, enc->key_len, | 573 | cipher_init(cc, enc->cipher, enc->key, enc->key_len, |
479 | enc->iv, enc->block_size, encrypt); | 574 | enc->iv, enc->block_size, encrypt); |
480 | memset(enc->iv, 0, enc->block_size); | 575 | /* Deleting the keys does not gain extra security */ |
481 | memset(enc->key, 0, enc->key_len); | 576 | /* memset(enc->iv, 0, enc->block_size); |
577 | memset(enc->key, 0, enc->key_len); */ | ||
482 | if (comp->type != 0 && comp->enabled == 0) { | 578 | if (comp->type != 0 && comp->enabled == 0) { |
483 | packet_init_compression(); | 579 | packet_init_compression(); |
484 | if (mode == MODE_OUT) | 580 | if (mode == MODE_OUT) |
@@ -495,7 +591,6 @@ set_newkeys(int mode) | |||
495 | static void | 591 | static void |
496 | packet_send2(void) | 592 | packet_send2(void) |
497 | { | 593 | { |
498 | static u_int32_t seqnr = 0; | ||
499 | u_char type, *cp, *macbuf = NULL; | 594 | u_char type, *cp, *macbuf = NULL; |
500 | u_char padlen, pad; | 595 | u_char padlen, pad; |
501 | u_int packet_length = 0; | 596 | u_int packet_length = 0; |
@@ -576,10 +671,10 @@ packet_send2(void) | |||
576 | 671 | ||
577 | /* compute MAC over seqnr and packet(length fields, payload, padding) */ | 672 | /* compute MAC over seqnr and packet(length fields, payload, padding) */ |
578 | if (mac && mac->enabled) { | 673 | if (mac && mac->enabled) { |
579 | macbuf = mac_compute(mac, seqnr, | 674 | macbuf = mac_compute(mac, send_seqnr, |
580 | buffer_ptr(&outgoing_packet), | 675 | buffer_ptr(&outgoing_packet), |
581 | buffer_len(&outgoing_packet)); | 676 | buffer_len(&outgoing_packet)); |
582 | DBG(debug("done calc MAC out #%d", seqnr)); | 677 | DBG(debug("done calc MAC out #%d", send_seqnr)); |
583 | } | 678 | } |
584 | /* encrypt packet and append to output buffer. */ | 679 | /* encrypt packet and append to output buffer. */ |
585 | cp = buffer_append_space(&output, buffer_len(&outgoing_packet)); | 680 | cp = buffer_append_space(&output, buffer_len(&outgoing_packet)); |
@@ -593,7 +688,7 @@ packet_send2(void) | |||
593 | buffer_dump(&output); | 688 | buffer_dump(&output); |
594 | #endif | 689 | #endif |
595 | /* increment sequence number for outgoing packets */ | 690 | /* increment sequence number for outgoing packets */ |
596 | if (++seqnr == 0) | 691 | if (++send_seqnr == 0) |
597 | log("outgoing seqnr wraps around"); | 692 | log("outgoing seqnr wraps around"); |
598 | buffer_clear(&outgoing_packet); | 693 | buffer_clear(&outgoing_packet); |
599 | 694 | ||
@@ -783,7 +878,6 @@ packet_read_poll1(void) | |||
783 | static int | 878 | static int |
784 | packet_read_poll2(u_int32_t *seqnr_p) | 879 | packet_read_poll2(u_int32_t *seqnr_p) |
785 | { | 880 | { |
786 | static u_int32_t seqnr = 0; | ||
787 | static u_int packet_length = 0; | 881 | static u_int packet_length = 0; |
788 | u_int padlen, need; | 882 | u_int padlen, need; |
789 | u_char *macbuf, *cp, type; | 883 | u_char *macbuf, *cp, type; |
@@ -845,17 +939,17 @@ packet_read_poll2(u_int32_t *seqnr_p) | |||
845 | * increment sequence number for incoming packet | 939 | * increment sequence number for incoming packet |
846 | */ | 940 | */ |
847 | if (mac && mac->enabled) { | 941 | if (mac && mac->enabled) { |
848 | macbuf = mac_compute(mac, seqnr, | 942 | macbuf = mac_compute(mac, read_seqnr, |
849 | buffer_ptr(&incoming_packet), | 943 | buffer_ptr(&incoming_packet), |
850 | buffer_len(&incoming_packet)); | 944 | buffer_len(&incoming_packet)); |
851 | if (memcmp(macbuf, buffer_ptr(&input), mac->mac_len) != 0) | 945 | if (memcmp(macbuf, buffer_ptr(&input), mac->mac_len) != 0) |
852 | packet_disconnect("Corrupted MAC on input."); | 946 | packet_disconnect("Corrupted MAC on input."); |
853 | DBG(debug("MAC #%d ok", seqnr)); | 947 | DBG(debug("MAC #%d ok", read_seqnr)); |
854 | buffer_consume(&input, mac->mac_len); | 948 | buffer_consume(&input, mac->mac_len); |
855 | } | 949 | } |
856 | if (seqnr_p != NULL) | 950 | if (seqnr_p != NULL) |
857 | *seqnr_p = seqnr; | 951 | *seqnr_p = read_seqnr; |
858 | if (++seqnr == 0) | 952 | if (++read_seqnr == 0) |
859 | log("incoming seqnr wraps around"); | 953 | log("incoming seqnr wraps around"); |
860 | 954 | ||
861 | /* get padlen */ | 955 | /* get padlen */ |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: packet.h,v 1.33 2002/03/04 17:27:39 stevesk Exp $ */ | 1 | /* $OpenBSD: packet.h,v 1.34 2002/03/18 17:16:38 markus Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
@@ -56,6 +56,16 @@ void *packet_get_string(u_int *length_ptr); | |||
56 | void packet_disconnect(const char *fmt,...) __attribute__((format(printf, 1, 2))); | 56 | void packet_disconnect(const char *fmt,...) __attribute__((format(printf, 1, 2))); |
57 | void packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2))); | 57 | void packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2))); |
58 | 58 | ||
59 | void set_newkeys(int mode); | ||
60 | int packet_get_keyiv_len(int); | ||
61 | void packet_get_keyiv(int, u_char *, u_int); | ||
62 | int packet_get_keycontext(int, u_char *); | ||
63 | void packet_set_keycontext(int, u_char *); | ||
64 | u_int32_t packet_get_seqnr(int); | ||
65 | void packet_set_seqnr(int, u_int32_t); | ||
66 | int packet_get_ssh1_cipher(void); | ||
67 | void packet_set_iv(int, u_char *); | ||
68 | |||
59 | void packet_write_poll(void); | 69 | void packet_write_poll(void); |
60 | void packet_write_wait(void); | 70 | void packet_write_wait(void); |
61 | int packet_have_data_to_write(void); | 71 | int packet_have_data_to_write(void); |