void
packet_set_ssh2_format(void)
{
- debug("use_ssh2_packet_format");
+ DBG(debug("use_ssh2_packet_format"));
use_ssh2_packet_format = 1;
}
/* Compute packet length without padding (add checksum, remove padding). */
len = buffer_len(&outgoing_packet) + 4 - 8;
- /* Insert padding. */
+ /* Insert padding. Initialized to zero in packet_start1() */
padding = 8 - len % 8;
if (cipher_type != SSH_CIPHER_NONE) {
cp = buffer_ptr(&outgoing_packet);
padlen += block_size;
buffer_append_space(&outgoing_packet, &cp, padlen);
if (enc && enc->type != SSH_CIPHER_NONE) {
+ /* random padding */
for (i = 0; i < padlen; i++) {
if (i % 4 == 0)
rand = arc4random();
cp[i] = rand & 0xff;
rand <<= 8;
}
+ } else {
+ /* clear padding */
+ memset(cp, 0, padlen);
}
/* packet_length includes payload, padding and padding length field */
packet_length = buffer_len(&outgoing_packet) - 4;
fatal("packet_send2: no KEX");
if (mac->md != NULL)
mac->enabled = 1;
- debug("cipher_set_key_iv send_context");
+ DBG(debug("cipher_set_key_iv send_context"));
cipher_set_key_iv(&send_context, enc->type,
enc->key, enc->key_len,
enc->iv, enc->iv_len);
DBG(debug("packet_send done"));
}
-void
-packet_send_and_wait()
-{
- packet_send();
- packet_write_wait();
-}
-
/*
* Waits until a packet has been received, and returns its type. Note that
* no other data is processed until this returns, so this function should not
for (;;) {
/* Try to read a packet from the buffer. */
type = packet_read_poll(payload_len_ptr);
- if (type == SSH_SMSG_SUCCESS
+ if (!use_ssh2_packet_format && (
+ type == SSH_SMSG_SUCCESS
|| type == SSH_SMSG_FAILURE
|| type == SSH_CMSG_EOF
- || type == SSH_CMSG_EXIT_CONFIRMATION)
+ || type == SSH_CMSG_EXIT_CONFIRMATION))
packet_integrity_check(*payload_len_ptr, 0, type);
/* If we got a packet, return it. */
if (type != SSH_MSG_NONE)
fatal("packet_read_poll2: no KEX");
if (mac->md != NULL)
mac->enabled = 1;
- debug("cipher_set_key_iv receive_context");
+ DBG(debug("cipher_set_key_iv receive_context"));
cipher_set_key_iv(&receive_context, enc->type,
enc->key, enc->key_len,
enc->iv, enc->iv_len);
vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
- packet_start(SSH_MSG_DEBUG);
- packet_put_string(buf, strlen(buf));
+ if (compat20) {
+ packet_start(SSH2_MSG_DEBUG);
+ packet_put_char(0); /* bool: always display */
+ packet_put_cstring(buf);
+ packet_put_cstring("");
+ } else {
+ packet_start(SSH_MSG_DEBUG);
+ packet_put_cstring(buf);
+ }
packet_send();
packet_write_wait();
}
* Set IP options for an interactive connection. Use
* IPTOS_LOWDELAY and TCP_NODELAY.
*/
+#ifdef IP_TOS
int lowdelay = IPTOS_LOWDELAY;
if (setsockopt(connection_in, IPPROTO_IP, IP_TOS, (void *) &lowdelay,
sizeof(lowdelay)) < 0)
error("setsockopt IPTOS_LOWDELAY: %.100s", strerror(errno));
+#endif
if (setsockopt(connection_in, IPPROTO_TCP, TCP_NODELAY, (void *) &on,
sizeof(on)) < 0)
error("setsockopt TCP_NODELAY: %.100s", strerror(errno));
* Set IP options for a non-interactive connection. Use
* IPTOS_THROUGHPUT.
*/
+#ifdef IP_TOS
int throughput = IPTOS_THROUGHPUT;
if (setsockopt(connection_in, IPPROTO_IP, IP_TOS, (void *) &throughput,
sizeof(throughput)) < 0)
error("setsockopt IPTOS_THROUGHPUT: %.100s", strerror(errno));
+#endif
}
}