diff options
Diffstat (limited to 'packet.c')
-rw-r--r-- | packet.c | 80 |
1 files changed, 40 insertions, 40 deletions
@@ -37,7 +37,7 @@ | |||
37 | */ | 37 | */ |
38 | 38 | ||
39 | #include "includes.h" | 39 | #include "includes.h" |
40 | RCSID("$OpenBSD: packet.c,v 1.39 2000/12/06 22:58:15 markus Exp $"); | 40 | RCSID("$OpenBSD: packet.c,v 1.40 2000/12/19 23:17:57 markus Exp $"); |
41 | 41 | ||
42 | #include "xmalloc.h" | 42 | #include "xmalloc.h" |
43 | #include "buffer.h" | 43 | #include "buffer.h" |
@@ -84,7 +84,7 @@ static int connection_out = -1; | |||
84 | static int cipher_type = SSH_CIPHER_NONE; | 84 | static int cipher_type = SSH_CIPHER_NONE; |
85 | 85 | ||
86 | /* Protocol flags for the remote side. */ | 86 | /* Protocol flags for the remote side. */ |
87 | static unsigned int remote_protocol_flags = 0; | 87 | static u_int remote_protocol_flags = 0; |
88 | 88 | ||
89 | /* Encryption context for receiving data. This is only used for decryption. */ | 89 | /* Encryption context for receiving data. This is only used for decryption. */ |
90 | static CipherContext receive_context; | 90 | static CipherContext receive_context; |
@@ -167,8 +167,8 @@ packet_set_connection(int fd_in, int fd_out) | |||
167 | connection_in = fd_in; | 167 | connection_in = fd_in; |
168 | connection_out = fd_out; | 168 | connection_out = fd_out; |
169 | cipher_type = SSH_CIPHER_NONE; | 169 | cipher_type = SSH_CIPHER_NONE; |
170 | cipher_init(&send_context, none, (unsigned char *) "", 0, NULL, 0); | 170 | cipher_init(&send_context, none, (u_char *) "", 0, NULL, 0); |
171 | cipher_init(&receive_context, none, (unsigned char *) "", 0, NULL, 0); | 171 | cipher_init(&receive_context, none, (u_char *) "", 0, NULL, 0); |
172 | if (!initialized) { | 172 | if (!initialized) { |
173 | initialized = 1; | 173 | initialized = 1; |
174 | buffer_init(&input); | 174 | buffer_init(&input); |
@@ -281,7 +281,7 @@ packet_close() | |||
281 | /* Sets remote side protocol flags. */ | 281 | /* Sets remote side protocol flags. */ |
282 | 282 | ||
283 | void | 283 | void |
284 | packet_set_protocol_flags(unsigned int protocol_flags) | 284 | packet_set_protocol_flags(u_int protocol_flags) |
285 | { | 285 | { |
286 | remote_protocol_flags = protocol_flags; | 286 | remote_protocol_flags = protocol_flags; |
287 | channel_set_options((protocol_flags & SSH_PROTOFLAG_HOST_IN_FWD_OPEN) != 0); | 287 | channel_set_options((protocol_flags & SSH_PROTOFLAG_HOST_IN_FWD_OPEN) != 0); |
@@ -289,7 +289,7 @@ packet_set_protocol_flags(unsigned int protocol_flags) | |||
289 | 289 | ||
290 | /* Returns the remote protocol flags set earlier by the above function. */ | 290 | /* Returns the remote protocol flags set earlier by the above function. */ |
291 | 291 | ||
292 | unsigned int | 292 | u_int |
293 | packet_get_protocol_flags() | 293 | packet_get_protocol_flags() |
294 | { | 294 | { |
295 | return remote_protocol_flags; | 295 | return remote_protocol_flags; |
@@ -318,7 +318,7 @@ packet_start_compression(int level) | |||
318 | 318 | ||
319 | void | 319 | void |
320 | packet_encrypt(CipherContext * cc, void *dest, void *src, | 320 | packet_encrypt(CipherContext * cc, void *dest, void *src, |
321 | unsigned int bytes) | 321 | u_int bytes) |
322 | { | 322 | { |
323 | cipher_encrypt(cc, dest, src, bytes); | 323 | cipher_encrypt(cc, dest, src, bytes); |
324 | } | 324 | } |
@@ -329,7 +329,7 @@ packet_encrypt(CipherContext * cc, void *dest, void *src, | |||
329 | */ | 329 | */ |
330 | 330 | ||
331 | void | 331 | void |
332 | packet_decrypt(CipherContext *context, void *dest, void *src, unsigned int bytes) | 332 | packet_decrypt(CipherContext *context, void *dest, void *src, u_int bytes) |
333 | { | 333 | { |
334 | /* | 334 | /* |
335 | * Cryptographic attack detector for ssh - Modifications for packet.c | 335 | * Cryptographic attack detector for ssh - Modifications for packet.c |
@@ -350,7 +350,7 @@ packet_decrypt(CipherContext *context, void *dest, void *src, unsigned int bytes | |||
350 | */ | 350 | */ |
351 | 351 | ||
352 | void | 352 | void |
353 | packet_set_encryption_key(const unsigned char *key, unsigned int keylen, | 353 | packet_set_encryption_key(const u_char *key, u_int keylen, |
354 | int number) | 354 | int number) |
355 | { | 355 | { |
356 | Cipher *cipher = cipher_by_number(number); | 356 | Cipher *cipher = cipher_by_number(number); |
@@ -410,7 +410,7 @@ packet_put_char(int value) | |||
410 | /* Appends an integer to the packet data. */ | 410 | /* Appends an integer to the packet data. */ |
411 | 411 | ||
412 | void | 412 | void |
413 | packet_put_int(unsigned int value) | 413 | packet_put_int(u_int value) |
414 | { | 414 | { |
415 | buffer_put_int(&outgoing_packet, value); | 415 | buffer_put_int(&outgoing_packet, value); |
416 | } | 416 | } |
@@ -418,7 +418,7 @@ packet_put_int(unsigned int value) | |||
418 | /* Appends a string to packet data. */ | 418 | /* Appends a string to packet data. */ |
419 | 419 | ||
420 | void | 420 | void |
421 | packet_put_string(const char *buf, unsigned int len) | 421 | packet_put_string(const char *buf, u_int len) |
422 | { | 422 | { |
423 | buffer_put_string(&outgoing_packet, buf, len); | 423 | buffer_put_string(&outgoing_packet, buf, len); |
424 | } | 424 | } |
@@ -429,7 +429,7 @@ packet_put_cstring(const char *str) | |||
429 | } | 429 | } |
430 | 430 | ||
431 | void | 431 | void |
432 | packet_put_raw(const char *buf, unsigned int len) | 432 | packet_put_raw(const char *buf, u_int len) |
433 | { | 433 | { |
434 | buffer_append(&outgoing_packet, buf, len); | 434 | buffer_append(&outgoing_packet, buf, len); |
435 | } | 435 | } |
@@ -458,7 +458,7 @@ packet_send1() | |||
458 | { | 458 | { |
459 | char buf[8], *cp; | 459 | char buf[8], *cp; |
460 | int i, padding, len; | 460 | int i, padding, len; |
461 | unsigned int checksum; | 461 | u_int checksum; |
462 | u_int32_t rand = 0; | 462 | u_int32_t rand = 0; |
463 | 463 | ||
464 | /* | 464 | /* |
@@ -493,7 +493,7 @@ packet_send1() | |||
493 | buffer_consume(&outgoing_packet, 8 - padding); | 493 | buffer_consume(&outgoing_packet, 8 - padding); |
494 | 494 | ||
495 | /* Add check bytes. */ | 495 | /* Add check bytes. */ |
496 | checksum = ssh_crc32((unsigned char *) buffer_ptr(&outgoing_packet), | 496 | checksum = ssh_crc32((u_char *) buffer_ptr(&outgoing_packet), |
497 | buffer_len(&outgoing_packet)); | 497 | buffer_len(&outgoing_packet)); |
498 | PUT_32BIT(buf, checksum); | 498 | PUT_32BIT(buf, checksum); |
499 | buffer_append(&outgoing_packet, buf, 4); | 499 | buffer_append(&outgoing_packet, buf, 4); |
@@ -530,12 +530,12 @@ packet_send1() | |||
530 | void | 530 | void |
531 | packet_send2() | 531 | packet_send2() |
532 | { | 532 | { |
533 | unsigned char *macbuf = NULL; | 533 | u_char *macbuf = NULL; |
534 | char *cp; | 534 | char *cp; |
535 | unsigned int packet_length = 0; | 535 | u_int packet_length = 0; |
536 | unsigned int i, padlen, len; | 536 | u_int i, padlen, len; |
537 | u_int32_t rand = 0; | 537 | u_int32_t rand = 0; |
538 | static unsigned int seqnr = 0; | 538 | static u_int seqnr = 0; |
539 | int type; | 539 | int type; |
540 | Enc *enc = NULL; | 540 | Enc *enc = NULL; |
541 | Mac *mac = NULL; | 541 | Mac *mac = NULL; |
@@ -604,7 +604,7 @@ packet_send2() | |||
604 | /* compute MAC over seqnr and packet(length fields, payload, padding) */ | 604 | /* compute MAC over seqnr and packet(length fields, payload, padding) */ |
605 | if (mac && mac->enabled) { | 605 | if (mac && mac->enabled) { |
606 | macbuf = hmac( mac->md, seqnr, | 606 | macbuf = hmac( mac->md, seqnr, |
607 | (unsigned char *) buffer_ptr(&outgoing_packet), | 607 | (u_char *) buffer_ptr(&outgoing_packet), |
608 | buffer_len(&outgoing_packet), | 608 | buffer_len(&outgoing_packet), |
609 | mac->key, mac->key_len | 609 | mac->key, mac->key_len |
610 | ); | 610 | ); |
@@ -742,16 +742,16 @@ packet_read_expect(int *payload_len_ptr, int expected_type) | |||
742 | int | 742 | int |
743 | packet_read_poll1(int *payload_len_ptr) | 743 | packet_read_poll1(int *payload_len_ptr) |
744 | { | 744 | { |
745 | unsigned int len, padded_len; | 745 | u_int len, padded_len; |
746 | unsigned char *ucp; | 746 | u_char *ucp; |
747 | char buf[8], *cp; | 747 | char buf[8], *cp; |
748 | unsigned int checksum, stored_checksum; | 748 | u_int checksum, stored_checksum; |
749 | 749 | ||
750 | /* Check if input size is less than minimum packet size. */ | 750 | /* Check if input size is less than minimum packet size. */ |
751 | if (buffer_len(&input) < 4 + 8) | 751 | if (buffer_len(&input) < 4 + 8) |
752 | return SSH_MSG_NONE; | 752 | return SSH_MSG_NONE; |
753 | /* Get length of incoming packet. */ | 753 | /* Get length of incoming packet. */ |
754 | ucp = (unsigned char *) buffer_ptr(&input); | 754 | ucp = (u_char *) buffer_ptr(&input); |
755 | len = GET_32BIT(ucp); | 755 | len = GET_32BIT(ucp); |
756 | if (len < 1 + 2 + 2 || len > 256 * 1024) | 756 | if (len < 1 + 2 + 2 || len > 256 * 1024) |
757 | packet_disconnect("Bad packet length %d.", len); | 757 | packet_disconnect("Bad packet length %d.", len); |
@@ -778,7 +778,7 @@ packet_read_poll1(int *payload_len_ptr) | |||
778 | #endif | 778 | #endif |
779 | 779 | ||
780 | /* Compute packet checksum. */ | 780 | /* Compute packet checksum. */ |
781 | checksum = ssh_crc32((unsigned char *) buffer_ptr(&incoming_packet), | 781 | checksum = ssh_crc32((u_char *) buffer_ptr(&incoming_packet), |
782 | buffer_len(&incoming_packet) - 4); | 782 | buffer_len(&incoming_packet) - 4); |
783 | 783 | ||
784 | /* Skip padding. */ | 784 | /* Skip padding. */ |
@@ -790,7 +790,7 @@ packet_read_poll1(int *payload_len_ptr) | |||
790 | packet_disconnect("packet_read_poll: len %d != buffer_len %d.", | 790 | packet_disconnect("packet_read_poll: len %d != buffer_len %d.", |
791 | len, buffer_len(&incoming_packet)); | 791 | len, buffer_len(&incoming_packet)); |
792 | 792 | ||
793 | ucp = (unsigned char *) buffer_ptr(&incoming_packet) + len - 4; | 793 | ucp = (u_char *) buffer_ptr(&incoming_packet) + len - 4; |
794 | stored_checksum = GET_32BIT(ucp); | 794 | stored_checksum = GET_32BIT(ucp); |
795 | if (checksum != stored_checksum) | 795 | if (checksum != stored_checksum) |
796 | packet_disconnect("Corrupted check bytes on input."); | 796 | packet_disconnect("Corrupted check bytes on input."); |
@@ -811,18 +811,18 @@ packet_read_poll1(int *payload_len_ptr) | |||
811 | *payload_len_ptr = buffer_len(&incoming_packet); | 811 | *payload_len_ptr = buffer_len(&incoming_packet); |
812 | 812 | ||
813 | /* Return type. */ | 813 | /* Return type. */ |
814 | return (unsigned char) buf[0]; | 814 | return (u_char) buf[0]; |
815 | } | 815 | } |
816 | 816 | ||
817 | int | 817 | int |
818 | packet_read_poll2(int *payload_len_ptr) | 818 | packet_read_poll2(int *payload_len_ptr) |
819 | { | 819 | { |
820 | unsigned int padlen, need; | 820 | u_int padlen, need; |
821 | unsigned char buf[8], *macbuf; | 821 | u_char buf[8], *macbuf; |
822 | unsigned char *ucp; | 822 | u_char *ucp; |
823 | char *cp; | 823 | char *cp; |
824 | static unsigned int packet_length = 0; | 824 | static u_int packet_length = 0; |
825 | static unsigned int seqnr = 0; | 825 | static u_int seqnr = 0; |
826 | int type; | 826 | int type; |
827 | int maclen, block_size; | 827 | int maclen, block_size; |
828 | Enc *enc = NULL; | 828 | Enc *enc = NULL; |
@@ -848,7 +848,7 @@ packet_read_poll2(int *payload_len_ptr) | |||
848 | buffer_append_space(&incoming_packet, &cp, block_size); | 848 | buffer_append_space(&incoming_packet, &cp, block_size); |
849 | packet_decrypt(&receive_context, cp, buffer_ptr(&input), | 849 | packet_decrypt(&receive_context, cp, buffer_ptr(&input), |
850 | block_size); | 850 | block_size); |
851 | ucp = (unsigned char *) buffer_ptr(&incoming_packet); | 851 | ucp = (u_char *) buffer_ptr(&incoming_packet); |
852 | packet_length = GET_32BIT(ucp); | 852 | packet_length = GET_32BIT(ucp); |
853 | if (packet_length < 1 + 4 || packet_length > 256 * 1024) { | 853 | if (packet_length < 1 + 4 || packet_length > 256 * 1024) { |
854 | buffer_dump(&incoming_packet); | 854 | buffer_dump(&incoming_packet); |
@@ -883,7 +883,7 @@ packet_read_poll2(int *payload_len_ptr) | |||
883 | */ | 883 | */ |
884 | if (mac && mac->enabled) { | 884 | if (mac && mac->enabled) { |
885 | macbuf = hmac( mac->md, seqnr, | 885 | macbuf = hmac( mac->md, seqnr, |
886 | (unsigned char *) buffer_ptr(&incoming_packet), | 886 | (u_char *) buffer_ptr(&incoming_packet), |
887 | buffer_len(&incoming_packet), | 887 | buffer_len(&incoming_packet), |
888 | mac->key, mac->key_len | 888 | mac->key, mac->key_len |
889 | ); | 889 | ); |
@@ -926,7 +926,7 @@ packet_read_poll2(int *payload_len_ptr) | |||
926 | packet_length = 0; | 926 | packet_length = 0; |
927 | 927 | ||
928 | /* extract packet type */ | 928 | /* extract packet type */ |
929 | type = (unsigned char)buf[0]; | 929 | type = (u_char)buf[0]; |
930 | 930 | ||
931 | if (type == SSH2_MSG_NEWKEYS) { | 931 | if (type == SSH2_MSG_NEWKEYS) { |
932 | if (kex==NULL || mac==NULL || enc==NULL || comp==NULL) | 932 | if (kex==NULL || mac==NULL || enc==NULL || comp==NULL) |
@@ -949,7 +949,7 @@ packet_read_poll2(int *payload_len_ptr) | |||
949 | fprintf(stderr, "read/plain[%d]:\r\n",type); | 949 | fprintf(stderr, "read/plain[%d]:\r\n",type); |
950 | buffer_dump(&incoming_packet); | 950 | buffer_dump(&incoming_packet); |
951 | #endif | 951 | #endif |
952 | return (unsigned char)type; | 952 | return (u_char)type; |
953 | } | 953 | } |
954 | 954 | ||
955 | int | 955 | int |
@@ -1018,24 +1018,24 @@ packet_read_poll(int *payload_len_ptr) | |||
1018 | */ | 1018 | */ |
1019 | 1019 | ||
1020 | void | 1020 | void |
1021 | packet_process_incoming(const char *buf, unsigned int len) | 1021 | packet_process_incoming(const char *buf, u_int len) |
1022 | { | 1022 | { |
1023 | buffer_append(&input, buf, len); | 1023 | buffer_append(&input, buf, len); |
1024 | } | 1024 | } |
1025 | 1025 | ||
1026 | /* Returns a character from the packet. */ | 1026 | /* Returns a character from the packet. */ |
1027 | 1027 | ||
1028 | unsigned int | 1028 | u_int |
1029 | packet_get_char() | 1029 | packet_get_char() |
1030 | { | 1030 | { |
1031 | char ch; | 1031 | char ch; |
1032 | buffer_get(&incoming_packet, &ch, 1); | 1032 | buffer_get(&incoming_packet, &ch, 1); |
1033 | return (unsigned char) ch; | 1033 | return (u_char) ch; |
1034 | } | 1034 | } |
1035 | 1035 | ||
1036 | /* Returns an integer from the packet data. */ | 1036 | /* Returns an integer from the packet data. */ |
1037 | 1037 | ||
1038 | unsigned int | 1038 | u_int |
1039 | packet_get_int() | 1039 | packet_get_int() |
1040 | { | 1040 | { |
1041 | return buffer_get_int(&incoming_packet); | 1041 | return buffer_get_int(&incoming_packet); |
@@ -1081,7 +1081,7 @@ packet_remaining(void) | |||
1081 | */ | 1081 | */ |
1082 | 1082 | ||
1083 | char * | 1083 | char * |
1084 | packet_get_string(unsigned int *length_ptr) | 1084 | packet_get_string(u_int *length_ptr) |
1085 | { | 1085 | { |
1086 | return buffer_get_string(&incoming_packet, length_ptr); | 1086 | return buffer_get_string(&incoming_packet, length_ptr); |
1087 | } | 1087 | } |