]> andersk Git - openssh.git/blobdiff - packet.c
- markus@cvs.openbsd.org 2001/11/07 22:53:21
[openssh.git] / packet.c
index d3a43609ba94b4b54f5aa2e080eaa84fdf5c0326..f34593fe573b076709c14552b1ee51c147e51ca3 100644 (file)
--- a/packet.c
+++ b/packet.c
@@ -13,7 +13,7 @@
  *
  *
  * SSH2 packet format added by Markus Friedl.
- * Copyright (c) 2000 Markus Friedl.  All rights reserved.
+ * Copyright (c) 2000, 2001 Markus Friedl.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -37,7 +37,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: packet.c,v 1.65 2001/06/07 20:23:04 markus Exp $");
+RCSID("$OpenBSD: packet.c,v 1.71 2001/11/07 16:03:17 markus Exp $");
 
 #include "xmalloc.h"
 #include "buffer.h"
@@ -115,6 +115,9 @@ static int interactive_mode = 0;
 /* Session key information for Encryption and MAC */
 Newkeys *newkeys[MODE_MAX];
 
+/* roundup current message to extra_pad bytes */
+static u_char extra_pad = 0;
+
 /*
  * Sets the descriptors used for communication.  Disables encryption until
  * packet_set_encryption_key is called.
@@ -260,8 +263,8 @@ packet_get_protocol_flags()
  * Level is compression level 1 (fastest) - 9 (slow, best) as in gzip.
  */
 
-void
-packet_init_compression()
+static void
+packet_init_compression(void)
 {
        if (compression_buffer_ready == 1)
                return;
@@ -356,7 +359,7 @@ packet_put_bignum2(BIGNUM * value)
  * encrypts the packet before sending.
  */
 
-void
+static void
 packet_send1(void)
 {
        char buf[8], *cp;
@@ -427,7 +430,7 @@ packet_send1(void)
         */
 }
 
-void
+static void
 set_newkeys(int mode)
 {
        Enc *enc;
@@ -480,14 +483,15 @@ set_newkeys(int mode)
 /*
  * Finalize packet in SSH2 format (compress, mac, encrypt, enqueue)
  */
-void
+static void
 packet_send2(void)
 {
        static u_int32_t seqnr = 0;
        u_char type, *ucp, *macbuf = NULL;
+       u_char padlen, pad;
        char *cp;
        u_int packet_length = 0;
-       u_int i, padlen, len;
+       u_int i, len;
        u_int32_t rand = 0;
        Enc *enc   = NULL;
        Mac *mac   = NULL;
@@ -533,6 +537,15 @@ packet_send2(void)
        padlen = block_size - (len % block_size);
        if (padlen < 4)
                padlen += block_size;
+       if (extra_pad) {
+               /* will wrap if extra_pad+padlen > 255 */
+               extra_pad  = roundup(extra_pad, block_size);
+               pad = extra_pad - ((len + padlen) % extra_pad);
+               debug("packet_send2: adding %d (len %d padlen %d extra_pad %d)",
+                   pad, len, padlen, extra_pad);
+               padlen += pad;
+               extra_pad = 0;
+       }
        buffer_append_space(&outgoing_packet, &cp, padlen);
        if (enc && enc->cipher->number != SSH_CIPHER_NONE) {
                /* random padding */
@@ -683,7 +696,7 @@ packet_read_expect(int *payload_len_ptr, int expected_type)
  *     Check bytes
  */
 
-int
+static int
 packet_read_poll1(int *payload_len_ptr)
 {
        u_int len, padded_len;
@@ -761,7 +774,7 @@ packet_read_poll1(int *payload_len_ptr)
        return type;
 }
 
-int
+static int
 packet_read_poll2(int *payload_len_ptr)
 {
        static u_int32_t seqnr = 0;
@@ -1085,7 +1098,7 @@ packet_disconnect(const char *fmt,...)
        packet_write_wait();
 
        /* Stop listening for connections. */
-       channel_stop_listening();
+       channel_close_all();
 
        /* Close the connection. */
        packet_close();
@@ -1109,6 +1122,7 @@ packet_write_poll()
                        else
                                fatal("Write failed: %.100s", strerror(errno));
                }
+debug("packet_write_poll: sent %d bytes", len);
                buffer_consume(&output, len);
        }
 }
@@ -1232,11 +1246,19 @@ packet_set_maxsize(int s)
                log("packet_set_maxsize: bad size %d", s);
                return -1;
        }
-       log("packet_set_maxsize: setting to %d", s);
+       called = 1;
+       debug("packet_set_maxsize: setting to %d", s);
        max_packet_size = s;
        return s;
 }
 
+/* roundup current message to pad bytes */
+void
+packet_add_padding(u_char pad)
+{
+       extra_pad = pad;
+}
+
 /*
  * 9.2.  Ignored Data Message
  *
@@ -1248,41 +1270,6 @@ packet_set_maxsize(int s)
  * required to send them. This message can be used as an additional
  * protection measure against advanced traffic analysis techniques.
  */
-/* size of current + ignore message should be n*sumlen bytes (w/o mac) */
-void
-packet_inject_ignore(int sumlen)
-{
-       int blocksize, padlen, have, need, nb, mini, nbytes;
-       Enc *enc = NULL;
-
-       if (compat20 == 0)
-               return;
-
-       have = buffer_len(&outgoing_packet);
-       debug2("packet_inject_ignore: current %d", have);
-       if (newkeys[MODE_OUT] != NULL)
-               enc  = &newkeys[MODE_OUT]->enc;
-       blocksize = enc ? enc->cipher->block_size : 8;
-       padlen = blocksize - (have % blocksize);
-       if (padlen < 4)
-               padlen += blocksize;
-       have += padlen;
-       have /= blocksize;      /* # of blocks for current message */
-
-       nb   = roundup(sumlen,  blocksize) / blocksize; /* blocks for both */
-       mini = roundup(5+1+4+4, blocksize) / blocksize; /* minsize ignore msg */
-       need = nb - (have % nb);                        /* blocks for ignore */
-       if (need <= mini)
-               need += nb;
-       nbytes = (need - mini) * blocksize;     /* size of ignore payload */
-       debug2("packet_inject_ignore: block %d have %d nb %d mini %d need %d",
-           blocksize, have, nb, mini, need);
-
-       /* enqueue current message and append a ignore message */
-       packet_send();
-       packet_send_ignore(nbytes);
-}
-
 void
 packet_send_ignore(int nbytes)
 {
This page took 0.03411 seconds and 4 git commands to generate.