Commit 834fdc43 authored by Niels Möller's avatar Niels Möller

Cleanup and trivial bugfixes.

Rev: src/abstract_io.h:1.7
Rev: src/client.c:1.7
Rev: src/client.h:1.5
Rev: src/connection.h:1.3
Rev: src/io.h:1.7
Rev: src/lsh.c:1.6
Rev: src/pad.c:1.9
Rev: src/pad.h:1.7
Rev: src/parse.h:1.5
Rev: src/read_line.h:1.5
Rev: src/transport.c:1.5
parent 48134a74
...@@ -8,12 +8,6 @@ ...@@ -8,12 +8,6 @@
#include "lsh_types.h" #include "lsh_types.h"
#if 0
struct abstract_read;
typedef int (*abstract_read_f)(struct abstract_read *r,
UINT8 *buffer, UINT32 length);
#endif
/* A read-function returning n means: /* A read-function returning n means:
* *
* n > 0: n bytes were read successfully. * n > 0: n bytes were read successfully.
...@@ -32,12 +26,6 @@ struct abstract_read ...@@ -32,12 +26,6 @@ struct abstract_read
#define A_READ(f, buffer, length) (f)->read(&(f), (buffer), (length)) #define A_READ(f, buffer, length) (f)->read(&(f), (buffer), (length))
#if 0
struct read_handler;
typedef struct read_handler * (*read_handler_f)(struct read_handler *closure,
struct abstract_read *read);
#endif
/* May store a new handler into *h. */ /* May store a new handler into *h. */
struct read_handler struct read_handler
{ {
...@@ -50,11 +38,6 @@ struct read_handler ...@@ -50,11 +38,6 @@ struct read_handler
/* FIXME: What should writers return? Perhaps a new writer, /* FIXME: What should writers return? Perhaps a new writer,
* analogous to read-handlers? */ * analogous to read-handlers? */
#if 0
struct abstract_write;
typedef int (*abstract_write_f)(struct abstract_write *closure,
struct lsh_string *packet);
#endif
/* May store a new handler into *w. */ /* May store a new handler into *w. */
struct abstract_write struct abstract_write
{ {
......
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
#include "werror.h" #include "werror.h"
#include "void.h" #include "void.h"
#include "xalloc.h" #include "xalloc.h"
#include "encrypt.h"
#include "pad.h"
#include "crypto.h"
struct read_handler *make_client_read_line(); struct read_handler *make_client_read_line();
struct callback *make_client_close_handler(); struct callback *make_client_close_handler();
...@@ -26,7 +29,7 @@ static int client_initiate(struct fd_callback **c, ...@@ -26,7 +29,7 @@ static int client_initiate(struct fd_callback **c,
= (struct client_callback *) *c; = (struct client_callback *) *c;
struct ssh_connection *connection = ssh_connection_alloc(); struct ssh_connection *connection = ssh_connection_alloc();
struct abstract_write *write = connection->raw =
io_read_write(closure->backend, fd, io_read_write(closure->backend, fd,
make_client_read_line(), make_client_read_line(),
closure->block_size, closure->block_size,
...@@ -38,7 +41,16 @@ static int client_initiate(struct fd_callback **c, ...@@ -38,7 +41,16 @@ static int client_initiate(struct fd_callback **c,
SOFTWARE_CLIENT_VERSION, SOFTWARE_CLIENT_VERSION,
closure->id_comment); closure->id_comment);
return A_WRITE(write, ssh_format("%lS\r\n", connection->client_version)); /* 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));
} }
struct client_line_handler struct client_line_handler
...@@ -117,7 +129,8 @@ struct read_handler *make_client_read_line(struct ssh_connection *s) ...@@ -117,7 +129,8 @@ struct read_handler *make_client_read_line(struct ssh_connection *s)
struct fd_callback *make_client_callback(struct io_backend *b, struct fd_callback *make_client_callback(struct io_backend *b,
char *comment, char *comment,
UINT32 block_size) UINT32 block_size,
struct randomness *r)
{ {
struct client_callback *connected = xalloc(sizeof(struct client_callback)); struct client_callback *connected = xalloc(sizeof(struct client_callback));
...@@ -126,7 +139,7 @@ struct fd_callback *make_client_callback(struct io_backend *b, ...@@ -126,7 +139,7 @@ struct fd_callback *make_client_callback(struct io_backend *b,
connected->backend = b; connected->backend = b;
connected->block_size = block_size; connected->block_size = block_size;
connected->id_comment = comment; connected->id_comment = comment;
connected->random = r;
return &connected->super; return &connected->super;
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define LSH_CLIENT_H_INCLUDED #define LSH_CLIENT_H_INCLUDED
#include "io.h" #include "io.h"
#include "abstract_crypto.h"
struct client_callback struct client_callback
{ {
...@@ -13,11 +14,13 @@ struct client_callback ...@@ -13,11 +14,13 @@ struct client_callback
struct io_backend *backend; struct io_backend *backend;
UINT32 block_size; UINT32 block_size;
char *id_comment; char *id_comment;
struct randomness *random;
}; };
struct fd_callback *make_client_callback(struct io_backend *b, struct fd_callback *make_client_callback(struct io_backend *b,
char *comment, char *comment,
UINT32 block_size); UINT32 block_size,
struct randomness *r);
#if 0 #if 0
struct client_session struct client_session
......
...@@ -15,8 +15,11 @@ struct ssh_connection ...@@ -15,8 +15,11 @@ struct ssh_connection
struct lsh_string *server_version; struct lsh_string *server_version;
struct lsh_string *session_id; struct lsh_string *session_id;
struct abstract_write *write; /* Socket connected to the other end */ struct abstract_write *raw; /* Socket connected to the other end */
struct abstract_write *write; /* Where to send packets throw the
* pipeline */
UINT32 max_packet; UINT32 max_packet;
int provides_privacy; int provides_privacy;
......
...@@ -28,10 +28,6 @@ struct io_fd ...@@ -28,10 +28,6 @@ struct io_fd
}; };
/* A closed function with a file descriptor as argument */ /* A closed function with a file descriptor as argument */
#if 0
struct fd_callback;
typedef int (*fd_callback_f)(struct fd_callback *closure, int fd);
#endif
struct fd_callback struct fd_callback
{ {
......
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
#include "io.h" #include "io.h"
#include "werror.h" #include "werror.h"
#include "client.h" #include "client.h"
#include "format.h"
#include "crypto.h"
#include "xalloc.h"
#define BLOCK_SIZE 32768 #define BLOCK_SIZE 32768
...@@ -30,6 +33,8 @@ int main(int argc, char **argv) ...@@ -30,6 +33,8 @@ int main(int argc, char **argv)
char *port = "ssh"; char *port = "ssh";
int option; int option;
struct lsh_string *random_seed;
struct sockaddr_in remote; struct sockaddr_in remote;
/* For filtering messages. Could perhaps also be used when converting /* For filtering messages. Could perhaps also be used when converting
...@@ -66,10 +71,16 @@ int main(int argc, char **argv) ...@@ -66,10 +71,16 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
random_seed = ssh_format("%z", "gazonk");
io_connect(&backend, &remote, NULL, io_connect(&backend, &remote, NULL,
make_client_callback(&backend, make_client_callback(&backend,
"lsh - a free ssh", "lsh - a free ssh",
BLOCK_SIZE)); BLOCK_SIZE,
make_poor_random(&sha_algorithm,
random_seed)));
lsh_string_free(random_seed);
io_run(&backend); io_run(&backend);
......
...@@ -17,10 +17,6 @@ static int do_pad(struct abstract_write **w, ...@@ -17,10 +17,6 @@ static int do_pad(struct abstract_write **w,
struct lsh_string *new; struct lsh_string *new;
#if 0
struct ssh_packet *ssh;
#endif
new_size = 1 + closure->block_size new_size = 1 + closure->block_size
* ( (8 + packet->length) / closure->block_size); * ( (8 + packet->length) / closure->block_size);
...@@ -34,8 +30,8 @@ static int do_pad(struct abstract_write **w, ...@@ -34,8 +30,8 @@ static int do_pad(struct abstract_write **w,
new->data[4] = padding; new->data[4] = padding;
memcpy(new->data + 5, packet->data, packet->length); memcpy(new->data + 5, packet->data, packet->length);
closure->random(closure->state, padding, new->data + 5 + packet->length); RANDOM(closure->random, padding, new->data + 5 + packet->length);
lsh_string_free(packet); lsh_string_free(packet);
return A_WRITE(closure->super.next, new); return A_WRITE(closure->super.next, new);
...@@ -44,7 +40,7 @@ static int do_pad(struct abstract_write **w, ...@@ -44,7 +40,7 @@ static int do_pad(struct abstract_write **w,
struct abstract_write * struct abstract_write *
make_packet_pad(struct abstract_write *continuation, make_packet_pad(struct abstract_write *continuation,
unsigned block_size, unsigned block_size,
random_function random) struct randomness *random)
{ {
struct packet_pad *closure = xalloc(sizeof(struct packet_pad)); struct packet_pad *closure = xalloc(sizeof(struct packet_pad));
......
...@@ -7,8 +7,7 @@ ...@@ -7,8 +7,7 @@
#define LSH_PAD_H_INCLUDED #define LSH_PAD_H_INCLUDED
#include "abstract_io.h" #include "abstract_io.h"
#include "abstract_crypto.h"
typedef void (*random_function)(void *state, UINT32 length, UINT8 *dst);
/* Input to the processor is a packet with the payload. Output is a /* Input to the processor is a packet with the payload. Output is a
* packet containing a formatted ssh packet (with correct byte order, * packet containing a formatted ssh packet (with correct byte order,
...@@ -19,27 +18,13 @@ struct packet_pad ...@@ -19,27 +18,13 @@ struct packet_pad
unsigned block_size; /* At least 8, even for stream ciphers */ unsigned block_size; /* At least 8, even for stream ciphers */
random_function random; struct randomness *random;
void *state; void *state;
}; };
struct abstract_write * struct abstract_write *
make_pad_processor(struct abstract_write *continuation, make_packet_pad(struct abstract_write *continuation,
unsigned block_size, unsigned block_size,
random_function random, struct randomness *random);
void *state);
#if 0
/* Input to the processor is a packet with the payload. Output is a
* packet containing a formatted ssh packet (with correct byte order,
* etc). No padding is done. */
struct format_processor
{
struct abstract_write_pipe c;
};
struct abstract_write *make_packet_pad(abstract_write *continuation);
#endif
#endif /* LSH_PAD_H_INCLUDED */ #endif /* LSH_PAD_H_INCLUDED */
...@@ -39,13 +39,4 @@ int parse_next_atom(struct simple_buffer *buffer, int *result); ...@@ -39,13 +39,4 @@ int parse_next_atom(struct simple_buffer *buffer, int *result);
/* Returns success (i.e. 1) iff there is no data left */ /* Returns success (i.e. 1) iff there is no data left */
int parse_eod(struct simple_buffer *buffer); int parse_eod(struct simple_buffer *buffer);
#if 0
/* Returns the number of octets that were actually written into the buffer */
UINT32 simple_buffer_write(struct simple_buffer *buffer,
UINT32 length, UINT32 *data);
UINT32 simple_buffer_avail(struct simple_buffer *buffer);
#endif
#endif /* LSH_PARSE_H_INCLUDED */ #endif /* LSH_PARSE_H_INCLUDED */
...@@ -11,14 +11,6 @@ ...@@ -11,14 +11,6 @@
/* This limit follows the ssh specification */ /* This limit follows the ssh specification */
#define MAX_LINE 255 #define MAX_LINE 255
#if 0
struct line_handler;
typedef struct read_handler * (*line_handler_f)(struct line_handler *closure,
UINT32 length,
UINT8 *line);
#endif
/* May store a new handler into *h. */ /* May store a new handler into *h. */
struct line_handler struct line_handler
{ {
......
...@@ -5,31 +5,6 @@ ...@@ -5,31 +5,6 @@
#include "transport.h" #include "transport.h"
#include "xalloc.h" #include "xalloc.h"
#if 0
void simple_buffer_init(struct simple_buffer *buffer,
UINT32 capacity, UINT8 *data)
{
buffer->capacity = capacity;
buffer->pos = 0;
buffer->data = data;
}
UINT32 simple_buffer_write(struct simple_buffer *buffer,
UINT32 length, UINT32 *data)
{
UINT32 left = buffer->capacity - buffer->pos;
UINT32 copy = MIN(left, length);
memcpy(buffer->data + buffer->pos, data, copy);
return copy;
}
UINT32 simple_buffer_avail(struct simple_buffer *buffer)
{
return buffer->capacity - buffer->pos;
}
#endif
int apply_processor(struct abstract_write *closure, int apply_processor(struct abstract_write *closure,
struct lsh_string *packet) struct lsh_string *packet)
{ {
......
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