Commit 523e27c4 authored by Niels Möller's avatar Niels Möller
Browse files

Updated for the new role of the connection object.

Rev: src/client.c:1.12
Rev: src/encrypt.c:1.10
Rev: src/encrypt.h:1.8
Rev: src/pad.c:1.12
Rev: src/pad.h:1.9
Rev: src/read_packet.c:1.10
Rev: src/read_packet.h:1.7
parent 51bb172c
......@@ -26,20 +26,21 @@
#include <stdio.h>
#include "client.h"
#include "version.h"
#include "connection.h"
#include "abstract_io.h"
#include "read_line.h"
#include "read_packet.h"
#include "connection.h"
#include "crypto.h"
#include "debug.h"
#include "format.h"
#include "werror.h"
#include "void.h"
#include "xalloc.h"
#include "encrypt.h"
#include "format.h"
#include "pad.h"
#include "crypto.h"
#include "read_line.h"
#include "read_packet.h"
#include "unpad.h"
#include "version.h"
#include "void.h"
#include "werror.h"
#include "xalloc.h"
struct read_handler *make_client_read_line();
struct callback *make_client_close_handler();
......@@ -51,26 +52,21 @@ static int client_initiate(struct fd_callback **c,
= (struct client_callback *) *c;
/* FIXME: Should pass a key exchange handler, not NULL! */
struct ssh_connection *connection = make_ssh_connection(NULL);
connection->raw =
io_read_write(closure->backend, fd,
make_client_read_line(),
closure->block_size,
make_client_close_handler());
struct ssh_connection *connection
= make_ssh_connection(NULL);
connection_init_io(connection,
io_read_write(closure->backend, fd,
make_client_read_line(c),
closure->block_size,
make_client_close_handler()),
closure->random);
connection->client_version
= ssh_format("SSH-%lz-%lz %lz",
PROTOCOL_VERSION,
SOFTWARE_CLIENT_VERSION,
closure->id_comment);
/* Link in padding and encryption */
connection->write
= make_packet_pad(make_packet_encrypt(connection->raw,
NULL,
&crypto_none_instance),
crypto_none_instance.block_size,
closure->random);
return A_WRITE(connection->raw,
ssh_format("%lS\r\n", connection->client_version));
......@@ -95,12 +91,11 @@ static struct read_handler *do_line(struct line_handler **h,
if ( ((length >= 8) && !memcmp(line + 4, "2.0-", 4))
|| ((length >= 9) && !memcmp(line + 4, "1.99-", 5)))
{
struct read_handler *new
= make_read_packet
struct read_handler *new = make_read_packet
(make_packet_debug
(make_packet_unpad(&closure->connection->super),
stderr),
closure->connection->max_packet);
closure->connection);
closure->connection->server_version
= ssh_format("%ls", length, line);
......
......@@ -24,30 +24,37 @@
*/
#include "encrypt.h"
#include "format.h"
#include "xalloc.h"
static int do_encrypt(struct abstract_write **w,
struct lsh_string *packet)
{
struct packet_encrypt *closure
= (struct packet_encrypt *) *w;
/* FIXME: Use ssh_format() */
struct lsh_string *new
= lsh_string_alloc(packet->length + closure->mac->mac_size);
struct packet_encrypt *closure = (struct packet_encrypt *) *w;
struct ssh_connection *connection = closure->connection;
struct lsh_string *new;
UINT8 *mac;
CRYPT(closure->crypto, packet->length, packet->data, new->data);
new = ssh_format("%lr%lr", packet->length, NULL,
connection->send_mac ? connection->send_mac->mac_size : 0,
&mac);
if (closure->mac->mac_size)
if (connection->send_crypto)
CRYPT(connection->send_crypto, packet->length, packet->data, new->data);
else
memcpy(new->data, packet->data, packet->length);
if (connection->send_mac)
{
UINT8 s[4];
WRITE_UINT32(s, closure->sequence_number);
closure->sequence_number++;
HASH_UPDATE(closure->mac, 4, s);
HASH_UPDATE(closure->mac, packet->length, packet->data);
HASH_DIGEST(closure->mac, new->data + packet->length);
HASH_UPDATE(connection->send_mac, 4, s);
HASH_UPDATE(connection->send_mac, packet->length, packet->data);
HASH_DIGEST(connection->send_mac, mac);
}
lsh_string_free(packet);
......@@ -56,16 +63,14 @@ static int do_encrypt(struct abstract_write **w,
struct abstract_write *
make_packet_encrypt(struct abstract_write *continuation,
struct mac_instance *mac,
struct crypto_instance *crypto)
struct ssh_connection *connection)
{
struct packet_encrypt *closure = xalloc(sizeof(struct packet_encrypt));
closure->super.super.write = do_encrypt;
closure->super.next = continuation;
closure->sequence_number = 0;
closure->mac = mac;
closure->crypto = crypto;
closure->connection = connection;
return &closure->super.super;
}
......
......@@ -28,20 +28,18 @@
#include "abstract_io.h"
#include "abstract_crypto.h"
#include "connection.h"
struct packet_encrypt
{
struct abstract_write_pipe super;
UINT32 sequence_number;
struct mac_instance *mac;
struct crypto_instance *crypto;
struct ssh_connection *connection;
};
struct abstract_write *
make_packet_encrypt(struct abstract_write *continuation,
struct mac_instance *mac,
struct crypto_instance *crypto);
struct ssh_connection *connection);
#endif /* LSH_ENCRYPT_H_INCLUDED */
......@@ -26,6 +26,9 @@
#include <assert.h>
#include "pad.h"
#include "connection.h"
#include "format.h"
#include "randomness.h"
#include "xalloc.h"
......@@ -34,20 +37,23 @@ static int do_pad(struct abstract_write **w,
{
struct packet_pad *closure
= (struct packet_pad *) *w;
struct ssh_connection *connection = closure->connection;
struct lsh_string *new;
UINT32 new_size;
UINT8 padding;
struct lsh_string *new;
UINT32 block_size = connection->send_crypto
? connection->send_crypto->block_size : 8;
new_size = 1 + closure->block_size
* ( (8 + packet->length) / closure->block_size);
new_size = 1 + block_size
* ( (8 + packet->length) / block_size);
padding = new_size - packet->length - 5;
assert(padding >= 4);
/* FIXME: Use ssh_format() */
new = lsh_string_alloc(new_size);
new = ssh_format("%lr", new_size, NULL);
WRITE_UINT32(new->data, new_size - 4);
new->data[4] = padding;
......@@ -62,14 +68,14 @@ static int do_pad(struct abstract_write **w,
struct abstract_write *
make_packet_pad(struct abstract_write *continuation,
unsigned block_size,
struct ssh_connection *connection,
struct randomness *random)
{
struct packet_pad *closure = xalloc(sizeof(struct packet_pad));
closure->super.super.write = do_pad;
closure->super.next = continuation;
closure->block_size = block_size;
closure->connection = connection;
closure->random = random;
return &closure->super.super;
......
......@@ -36,15 +36,13 @@ struct packet_pad
{
struct abstract_write_pipe super;
unsigned block_size; /* At least 8, even for stream ciphers */
struct ssh_connection *connection;
struct randomness *random;
void *state;
};
struct abstract_write *
make_packet_pad(struct abstract_write *continuation,
unsigned block_size,
struct randomness *random);
struct abstract_write *make_packet_pad(struct abstract_write *continuation,
struct ssh_connection *connection,
struct randomness *random);
#endif /* LSH_PAD_H_INCLUDED */
......@@ -27,11 +27,13 @@
#include <string.h>
#include "read_packet.h"
#include "werror.h"
#include "connection.h"
#include "crypto.h"
#include "format.h"
#include "xalloc.h"
#include "io.h"
#include "crypto.h"
#include "werror.h"
#include "xalloc.h"
#define WAIT_HEADER 0
#define WAIT_CONTENTS 1
......@@ -52,10 +54,10 @@ int do_read_packet(struct read_handler **h,
crypto = &crypto_none_instance;
#endif
switch(closure->state)
{
{
case WAIT_HEADER:
{
UINT32 block_size = connection->rec_crypto
UINT32 block_size = closure->connection->rec_crypto
? closure->connection->rec_crypto->block_size : 8;
UINT32 left = block_size - closure->pos;
int n;
......@@ -110,7 +112,7 @@ int do_read_packet(struct read_handler **h,
}
/* Process this block before the length field is lost. */
if (closure->mac)
if (closure->connection->rec_mac)
{
UINT8 s[4];
WRITE_UINT32(s, closure->sequence_number);
......@@ -123,7 +125,7 @@ int do_read_packet(struct read_handler **h,
/* Allocate full packet */
closure->buffer = ssh_format("%ls%lr",
closure->crypto->block_size - 4,
block_size - 4,
closure->buffer->data + 4,
length, &closure->crypt_pos);
......@@ -164,7 +166,7 @@ int do_read_packet(struct read_handler **h,
closure->buffer->length - closure->crypt_pos,
closure->buffer->data + closure->crypt_pos,
closure->buffer->data + closure->crypt_pos);
if (closure->mac)
if (closure->connection->rec_mac)
{
HASH_UPDATE(closure->connection->rec_mac,
closure->buffer->length - closure->crypt_pos,
......@@ -215,7 +217,7 @@ int do_read_packet(struct read_handler **h,
break;
}
/* MAC was ok, send packet on */
if (connection_handle_packet(closure->connection, closure->buffer)
if (A_WRITE(closure->handler, closure->buffer)
!= WRITE_OK)
/* FIXME: What now? */
return 0;
......@@ -230,6 +232,7 @@ int do_read_packet(struct read_handler **h,
#if 0
}
#endif
return 1;
}
struct read_handler *make_read_packet(struct abstract_write *handler,
......@@ -240,6 +243,7 @@ struct read_handler *make_read_packet(struct abstract_write *handler,
closure->super.handler = do_read_packet;
closure->connection = connection;
closure->handler = handler;
closure->state = WAIT_HEADER;
closure->sequence_number = 0;
......@@ -248,10 +252,5 @@ struct read_handler *make_read_packet(struct abstract_write *handler,
closure->buffer = NULL;
/* closure->crypt_pos = 0; */
closure->mac = 0;
closure->crypto = &crypto_none_instance;
closure->handler = handler;
return &closure->super;
}
......@@ -34,10 +34,6 @@ struct read_packet
struct read_handler super; /* Super type */
int state;
#if 0
UINT32 max_packet;
#endif
UINT32 sequence_number; /* Attached to read packets */
......@@ -48,9 +44,7 @@ struct read_packet
UINT8 *computed_mac; /* Must point to an area large enough to hold a mac */
#if 0
struct abstract_write *handler;
#endif
struct ssh_connection *connection;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment