Commit 60f843f7 authored by Niels Möller's avatar Niels Möller
Browse files

Start keyexchange.

Rev: src/client.c:1.16
Rev: src/client.h:1.7
Rev: src/server.c:1.8
Rev: src/server.h:1.5
parent 25c6ed94
......@@ -41,18 +41,17 @@
#include "werror.h"
#include "xalloc.h"
struct read_handler *make_client_read_line(struct ssh_connection *c);
struct callback *make_client_close_handler();
static int client_initiate(struct fd_callback **c,
int fd)
{
struct client_callback *closure
= (struct client_callback *) *c;
int res;
/* FIXME: Should pass a key exchange handler, not NULL! */
struct ssh_connection *connection
= make_ssh_connection(NULL);
= make_ssh_connection(closure->kexinit_handler);
connection_init_io(connection,
io_read_write(closure->backend, fd,
......@@ -67,8 +66,14 @@ static int client_initiate(struct fd_callback **c,
SOFTWARE_CLIENT_VERSION,
closure->id_comment);
return A_WRITE(connection->raw,
ssh_format("%lS\r\n", connection->client_version));
res = A_WRITE(connection->raw,
ssh_format("%lS\r\n", connection->client_version));
if (res != WRITE_OK)
return res;
return initiate_keyexchange(connection, CONNECTION_CLIENT,
MAKE_KEXINIT(closure->init),
NULL);
}
struct client_line_handler
......@@ -146,11 +151,14 @@ struct read_handler *make_client_read_line(struct ssh_connection *c)
return make_read_line(&closure->super);
}
struct fd_callback *make_client_callback(struct io_backend *b,
char *comment,
UINT32 block_size,
struct randomness *r)
struct fd_callback *
make_client_callback(struct io_backend *b,
char *comment,
UINT32 block_size,
struct randomness *random,
struct make_kexinit *init,
struct packet_handler *kexinit_handler)
{
struct client_callback *connected = xalloc(sizeof(struct client_callback));
......@@ -158,7 +166,11 @@ struct fd_callback *make_client_callback(struct io_backend *b,
connected->backend = b;
connected->block_size = block_size;
connected->id_comment = comment;
connected->random = r;
connected->random = random;
connected->init = init;
connected->kexinit_handler = kexinit_handler;
return &connected->super;
}
......@@ -168,7 +180,7 @@ static int client_die(struct callback *closure)
exit(1);
}
struct callback *make_client_close_handler()
struct callback *make_client_close_handler(void)
{
struct callback *c = xalloc(sizeof(struct callback));
......@@ -176,26 +188,3 @@ struct callback *make_client_close_handler()
return c;
}
#if 0
/* FIXME: HERE */
struct abstract_write *make_client_dispatch(struct ssh_connection *c)
{
struct abstract_write *ignore = make_packet_void();
struct abstract_write *fail = make_disconnect(connection);
struct abstract_write *kex = make_client_key_exchange(connection);
struct dispatch_assoc table[] = {
{ SSH_MSG_DISCONNECT, make_handle_disconnect(connection) },
{ SSH_MSG_IGNORE, ignore },
{ SSH_MSG_UNIMPLEMENTED, ignore },
{ SSH_MSG_DEBUG, make_handle_debug(connection) },
{ SSH_MSG_SERVICE_REQUEST, fail },
{ SSH_MSG_SERVICE_ACCEPT, fail },
{ SSH_MSG_KEXINIT, kex },
{ SSH_MSG_NEWKEYS, fail },
{ SSH_MSG
#endif
......@@ -27,7 +27,7 @@
#define LSH_CLIENT_H_INCLUDED
#include "io.h"
#include "abstract_crypto.h"
#include "keyexchange.h"
struct client_callback
{
......@@ -35,13 +35,22 @@ struct client_callback
struct io_backend *backend;
UINT32 block_size;
char *id_comment;
struct randomness *random;
struct make_kexinit *init;
struct packet_handler *kexinit_handler;
};
struct fd_callback *make_client_callback(struct io_backend *b,
char *comment,
UINT32 block_size,
struct randomness *r);
struct fd_callback *
make_client_callback(struct io_backend *b,
char *comment,
UINT32 block_size,
struct randomness *random,
struct make_kexinit *init,
struct packet_handler *kexinit_handler);
struct read_handler *make_client_read_line(struct ssh_connection *c);
struct callback *make_client_close_handler(void);
#if 0
struct client_session
......
......@@ -36,9 +36,6 @@
#include "werror.h"
#include "xalloc.h"
struct read_handler *make_server_read_line();
struct callback *make_server_close_handler();
static int server_initiate(struct fd_callback **c,
int fd)
{
......@@ -46,13 +43,18 @@ static int server_initiate(struct fd_callback **c,
struct ssh_connection *connection
= make_ssh_connection(closure->kexinit_handler);
struct abstract_write *write =
io_read_write(closure->backend, fd,
make_server_read_line(),
closure->block_size,
make_server_close_handler());
int res;
verbose("server_initiate()\n");
connection_init_io(connection,
io_read_write(closure->backend, fd,
make_server_read_line(connection),
closure->block_size,
make_server_close_handler()),
closure->random);
connection->server_version
= ssh_format("SSH-%lz-%lz %lz",
......@@ -60,7 +62,14 @@ static int server_initiate(struct fd_callback **c,
SOFTWARE_SERVER_VERSION,
closure->id_comment);
return A_WRITE(write, ssh_format("%lS\r\n", connection->server_version));
res = A_WRITE(connection->raw,
ssh_format("%lS\r\n", connection->server_version));
if (res != WRITE_OK)
return res;
return initiate_keyexchange(connection, CONNECTION_SERVER,
MAKE_KEXINIT(closure->init),
NULL);
}
struct server_line_handler
......@@ -121,13 +130,13 @@ static struct read_handler *do_line(struct line_handler **h,
}
}
struct read_handler *make_server_read_line(struct ssh_connection *s)
struct read_handler *make_server_read_line(struct ssh_connection *c)
{
struct server_line_handler *closure
= xalloc(sizeof(struct server_line_handler));
closure->super.handler = do_line;
closure->connection = s;
closure->connection = c;
return make_read_line(&closure->super);
}
......@@ -136,6 +145,8 @@ struct fd_callback *
make_server_callback(struct io_backend *b,
char *comment,
UINT32 block_size,
struct randomness *random,
struct make_kexinit *init,
struct packet_handler *kexinit_handler)
{
struct server_callback *connected = xalloc(sizeof(struct server_callback));
......@@ -145,6 +156,8 @@ make_server_callback(struct io_backend *b,
connected->block_size = block_size;
connected->id_comment = comment;
connected->random = random;
connected->init = init;
connected->kexinit_handler = kexinit_handler;
return &connected->super;
......@@ -157,7 +170,7 @@ static int server_die(struct callback *closure)
return 0; /* Ignored */
}
struct callback *make_server_close_handler()
struct callback *make_server_close_handler(void)
{
struct callback *c = xalloc(sizeof(struct callback));
......
......@@ -41,6 +41,8 @@ struct server_callback
UINT32 block_size;
char *id_comment;
struct randomness *random;
struct make_kexinit *init;
struct packet_handler *kexinit_handler;
};
......@@ -48,6 +50,11 @@ struct fd_callback *
make_server_callback(struct io_backend *b,
char *comment,
UINT32 block_size,
struct randomness *random,
struct make_kexinit *init,
struct packet_handler *kexinit_handler);
struct read_handler *make_server_read_line(struct ssh_connection *c);
struct callback *make_server_close_handler(void);
#endif /* LSH_SERVER_H_INCLUDED */
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