Commit 656da460 authored by Niels Möller's avatar Niels Möller

* (practically every file): Adapted to new gc and object system.

Rev: ChangeLog:1.2
Rev: doc/TODO:1.11
Rev: src/Makefile.am.in:1.6
Rev: src/abstract_crypto.h:1.14
Rev: src/abstract_io.h:1.19
Rev: src/alist.c:1.12
Rev: src/alist.h:1.7
Rev: src/blocking_write.c:1.7
Rev: src/channel.c:1.14
Rev: src/channel.h:1.17
Rev: src/client.c:1.36
Rev: src/client_keyexchange.c:1.17
Rev: src/client_keyexchange.h:1.9
Rev: src/client_userauth.c:1.5
Rev: src/connection.c:1.18
Rev: src/crypto.c:1.13
Rev: src/debug.c:1.16
Rev: src/disconnect.c:1.8
Rev: src/encrypt.c:1.15
Rev: src/format.c:1.20
Rev: src/format.h:1.15
Rev: src/gc.c:1.2
Rev: src/io.c:1.31
Rev: src/io.h:1.21
Rev: src/keyexchange.c:1.25
Rev: src/keyexchange.h:1.24
Rev: src/list.c:1.2
Rev: src/list.h:1.2
Rev: src/lsh.c:1.24
Rev: src/lshd.c:1.21
Rev: src/make_class:1.6
Rev: src/packet_ignore.c:1.6
Rev: src/pad.c:1.18
Rev: src/parse.c:1.19
Rev: src/parse.h:1.14
Rev: src/password.c:1.1
Rev: src/password.h:1.7
Rev: src/publickey_crypto.c:1.19
Rev: src/publickey_crypto.h:1.12
Rev: src/randomness.c:1.8
Rev: src/randomness.h:1.5
Rev: src/read_data.c:1.13
Rev: src/read_line.c:1.14
Rev: src/read_line.h:1.9
Rev: src/read_packet.c:1.25
Rev: src/reaper.c:1.4
Rev: src/reaper.h:1.3
Rev: src/server.c:1.24
Rev: src/server_keyexchange.c:1.15
Rev: src/server_keyexchange.h:1.6
Rev: src/server_password.c:1.7
Rev: src/server_userauth.c:1.6
Rev: src/session.h:1.10
Rev: src/unpad.c:1.14
Rev: src/userauth.c:1.1
Rev: src/userauth.h:1.7
Rev: src/write_buffer.c:1.12
Rev: src/write_buffer.h:1.11
Rev: src/xalloc.c:1.14
Rev: src/xalloc.h:1.14
Rev: src/zlib.c:1.9
parent 9efec583
Fri Dec 4 02:30:28 1998 <nisse@puck>
* (practically every file): Adapted to new gc and object system.
* xalloc.c (lsh_object_check_subtype): Allow NULL pointers. They
are occasionally permissible (for instance, the NULL crypto
algorithm), and when they aren't the error will be detected early
anyway.
(lsh_object_check): -"-
* keyexchange.c (do_handle_kexinit): Use an object_list for
passing around the selected algorithms. The void ** that was used
earlier was unfriendly to the gc.
Sun Nov 22 00:57:16 1998 <nisse@puck>
* lsh.c (main): Bug fix (pass *address* of crypto_rc4_algorithm).
......
......@@ -61,6 +61,8 @@ lssh_space_alloc.
Make lists of integers (usually atoms) its own type. Can this be done
in such a way that they can also be allocated statically?
Have the allocator initialize all objects automatically.
CHANNELS
......
......@@ -31,13 +31,13 @@ bin_PROGRAMS = lsh lshd
generated_sources = atoms_defines.h atoms_gperf.c atoms_table.c
common_sources = abstract_io.c alist.c atoms.c bignum.c channel.c \
charset.c connection.c crypto.c \
debug.c disconnect.c encrypt.c format.c getopt.c io.c keyexchange.c \
packet_ignore.c pad.c parse.c publickey_crypto.c \
common_sources = abstract_io.c abstract_crypto.c alist.c atoms.c \
bignum.c channel.c charset.c connection.c crypto.c \
debug.c disconnect.c encrypt.c format.c gc.c getopt.c io.c keyexchange.c \
list.c packet_ignore.c pad.c parse.c password.c publickey_crypto.c \
randomness.c \
read_data.c read_line.c read_packet.c service.c \
translate_signal.c unpad.c \
translate_signal.c unpad.c userauth.c \
werror.c write_buffer.c xalloc.c
lsh_SOURCES = $(common_sources) lsh.c client.c client_keyexchange.c \
......
......@@ -28,6 +28,12 @@
#include "lsh_types.h"
/* Use the same instance struct for both hash functions and macs. This
* is a little ugly. */
#define mac_instance_class hash_instance_class
#define mac_instance hash_instance
#define mac_size hash_size
#define CLASS_DECLARE
#include "abstract_crypto.h.x"
#undef CLASS_DECLARE
......@@ -65,7 +71,7 @@ struct crypto_instance
(block_size simple UINT32)
(key_size simple UINT32)
(make_crypt method (object crypto_instance)
"int mode" "UIINT8 *key")))
"int mode" "UINT8 *key")))
*/
#if 0
......@@ -87,6 +93,8 @@ struct crypto_algorithm
#define MAKE_DECRYPT(crypto, key) \
((crypto)->make_crypt((crypto), CRYPTO_DECRYPT, (key)))
/* FIXME: Hashes could use non-virtual methods. */
/* CLASS:
(class
(name hash_instance)
......@@ -120,10 +128,6 @@ struct hash_instance
#define HASH_COPY(instance) ((instance)->copy((instance)))
/* Used for both hash functions ad macs */
#define mac_instance hash_instance
#define mac_size hash_size
/* CLASS:
(class
(name hash_algorithm)
......
......@@ -46,7 +46,7 @@
(class
(name abstract_read)
(vars
(read method int
(read indirect-method int
"UINT32 length" "UINT8 *buffer")))
*/
#if 0
......@@ -67,7 +67,7 @@ struct abstract_read
(class
(name read_handler)
(vars
(handler method int "struct abstract_read *read")))
(handler indirect-method int "struct abstract_read *read")))
*/
#if 0
......
......@@ -33,6 +33,10 @@
#include "werror.h"
#include "xalloc.h"
#define CLASS_DEFINE
#include "alist.h.x"
#undef CLASS_DEFINE
struct alist_node
{
struct alist_node *next;
......
......@@ -28,6 +28,13 @@
#include "lsh_types.h"
/* Forward declaration */
struct alist;
#define CLASS_DECLARE
#include "alist.h.x"
#undef CLASS_DECLARE
/* Not supported anymore */
/* #define ALIST_USE_SIZE 0 */
......@@ -88,6 +95,4 @@ struct alist *make_linked_alist(int n, ...);
#define make_alist make_linear_alist
#include "alist.h.x"
#endif /* LSH_ALIST_H_INCLUDED */
......@@ -11,13 +11,11 @@
static int do_write(struct abstract_write *w,
struct lsh_string *packet)
{
struct packet_blocking_write *closure
= (struct packet_blocking_write *) w;
CAST(packet_blocking_write, closure, w);
UINT32 left = packet->length;
UINT8 *p = packet->data;
MDEBUG(closure);
while(left)
{
int written = write(closure->fd, p, left);
......
This diff is collapsed.
......@@ -93,6 +93,7 @@
; Reply from SSH_MSG_CHANNEL_REQUEST
(channel_success method int)
(channel_failure method int)))
*/
#if 0
struct ssh_channel
......
This diff is collapsed.
......@@ -30,14 +30,43 @@
#include "werror.h"
#include "xalloc.h"
#define CLASS_DEFINE
#include "client_keyexchange.h.x"
#undef CLASS_DEFINE
#include "client_keyexchange.c.x"
/* CLASS:
(class
(name dh_client_exchange)
(super keyexchange_algorithm)
(vars
(dh object diffie_hellman_method)
(verifier object lookup_verifier)))
*/
#if 0
struct dh_client_exchange
{
struct keyexchange_algorithm super;
struct diffie_hellman_method *dh;
struct lookup_verifier *verifier;
};
#endif
/* Handler for the kex_dh_reply message */
/* CLASS:
(class
(name dh_client)
(super packet_handler)
(vars
(dh struct diffie_hellman_instance)
(verifier object lookup_verifier)
(install object install_keys)
(finished object ssh_service)))
*/
#if 0
struct dh_client
{
struct packet_handler super;
......@@ -47,19 +76,18 @@ struct dh_client
struct ssh_service *finished;
};
#endif
static int do_handle_dh_reply(struct packet_handler *c,
struct ssh_connection *connection,
struct lsh_string *packet)
{
struct dh_client *closure = (struct dh_client *) c;
CAST(dh_client, closure, c);
struct verifier *v;
struct hash_instance *hash;
struct lsh_string *s;
int res;
MDEBUG(closure);
verbose("handle_dh_reply()\n");
if (!dh_process_server_msg(&closure->dh, packet))
......@@ -105,7 +133,7 @@ static int do_handle_dh_reply(struct packet_handler *c,
/* FIXME: Return value is ignored */
(void) INSTALL_KEYS(closure->install, connection, hash);
lsh_object_free(hash);
KILL(hash);
connection->dispatch[SSH_MSG_KEXDH_REPLY] = connection->fail;
connection->kex_state = KEX_STATE_NEWKEYS;
......@@ -122,18 +150,15 @@ static int do_init_dh(struct keyexchange_algorithm *c,
struct ssh_service *finished,
int hostkey_algorithm_atom,
struct signature_algorithm *ignored,
void **algorithms)
struct object_list *algorithms)
{
struct dh_client_exchange *closure = (struct dh_client_exchange *) c;
struct dh_client *dh;
CAST(dh_client_exchange, closure, c);
NEW(dh_client, dh);
int res;
MDEBUG(closure);
MDEBUG_SUBTYPE(connection);
MDEBUG_SUBTYPE(ignored);
NEW(dh);
CHECK_SUBTYPE(ssh_connection, connection);
CHECK_SUBTYPE(signature_algorithm, ignored);
/* FIXME: Use this value to choose a verifier function */
if (hostkey_algorithm_atom != ATOM_SSH_DSS)
......@@ -171,11 +196,9 @@ struct keyexchange_algorithm *
make_dh_client(struct diffie_hellman_method *dh,
struct lookup_verifier *verifier)
{
struct dh_client_exchange *self;
NEW(self);
NEW(dh_client_exchange, self);
MDEBUG(dh);
CHECK_TYPE(diffie_hellman_method, dh);
self->super.init = do_init_dh;
self->dh = dh;
......@@ -184,11 +207,24 @@ make_dh_client(struct diffie_hellman_method *dh,
return &self->super;
}
/* FIXME: This is identical to the server_install_keys structure in
* server_keyexchange.c. It should probably be moved somewhere else. */
/* CLASS:
(class
(name client_install_keys)
(super install_keys)
(vars
(algorithms object object_list)))
*/
#if 0
struct client_install_keys
{
struct install_keys super;
void **algorithms;
struct object_list *algorithms;
};
#endif
static int do_install(struct install_keys *c,
struct ssh_connection *connection,
......@@ -198,9 +234,7 @@ static int do_install(struct install_keys *c,
* happens to be weak. */
/* FIXME: No IV:s */
struct client_install_keys *closure = (struct client_install_keys *) c;
MDEBUG(closure);
CAST(client_install_keys, closure, c);
/* Keys for recieving */
connection->dispatch[SSH_MSG_NEWKEYS] = make_newkeys_handler
......@@ -223,11 +257,9 @@ static int do_install(struct install_keys *c,
return 1;
}
struct install_keys *make_client_install_keys(void **algorithms)
struct install_keys *make_client_install_keys(struct object_list *algorithms)
{
struct client_install_keys *self;
NEW(self);
NEW(client_install_keys, self);
self->super.install = do_install;
self->algorithms = algorithms;
......
......@@ -29,6 +29,10 @@
#include "keyexchange.h"
#include "publickey_crypto.h"
#define CLASS_DECLARE
#include "client_keyexchange.h.x"
#undef CLASS_DECLARE
/* Maps a key blob to a signature verifier, using some signature
* algorithm and some method to determine the authenticity of the key.
* Returns NULL If the key is invalid or not trusted. */
......@@ -57,6 +61,6 @@ struct keyexchange_algorithm *
make_dh_client(struct diffie_hellman_method *dh,
struct lookup_verifier *verifier);
struct install_keys *make_client_install_keys(void **algorithms);
struct install_keys *make_client_install_keys(struct object_list *algorithms);
#endif /* LSH_CLIENT_KEYEXCHANGE_H_INCLUDED */
......@@ -46,9 +46,26 @@
* the lock and turning it around).
*
* If none of the keys were recognized, or if no keys were available
*from the start, we ask the user for a password and attempts to log
*in using that. */
* from the start, we ask the user for a password and attempts to log
* in using that. */
#include "client_userauth.c.x"
/* CLASS:
(class
(name client_userauth)
(super ssh_service)
(vars
(username string) ; Remote user name to authenticate as.
(service_name simple int) ; Service we want to access .
(service object ssh_service)
; FIXME: Keys to try
))
*/
#if 0
struct client_userauth
{
struct ssh_service super;
......@@ -59,20 +76,41 @@ struct client_userauth
/* FIXME: Keys to try */
};
#endif
/* CLASS:
(class
(name success_handler)
(super packet_handler)
(vars
(service object ssh_service)))
*/
#if 0
struct success_handler
{
struct packet_handler super;
struct ssh_service *service;
};
#endif
/* CLASS:
(class
(name failure_handler)
(super packet_handler)
(vars
(userauth object client_userauth)))
*/
#if 0
struct failure_handler
{
struct packet_handler super;
struct client_userauth *userauth;
};
#endif
static struct lsh_string *format_userauth_password(struct lsh_string *name,
int service,
......@@ -112,13 +150,11 @@ static int do_userauth_success(struct packet_handler *c,
struct ssh_connection *connection,
struct lsh_string *packet)
{
struct success_handler *closure = (struct success_handler *) c;
CAST(success_handler, closure, c);
struct simple_buffer buffer;
int msg_number;
MDEBUG(closure);
simple_buffer_init(&buffer, packet->length, packet->data);
if (parse_uint8(&buffer, &msg_number)
......@@ -144,15 +180,13 @@ static int do_userauth_failure(struct packet_handler *c,
struct ssh_connection *connection,
struct lsh_string *packet)
{
struct failure_handler *closure = (struct failure_handler *) c;
CAST(failure_handler, closure, c);
struct simple_buffer buffer;
int msg_number;
int *methods = NULL;
struct int_list *methods = NULL;
int partial_success;
MDEBUG(closure);
simple_buffer_init(&buffer, packet->length, packet->data);
if (parse_uint8(&buffer, &msg_number)
......@@ -169,24 +203,24 @@ static int do_userauth_failure(struct packet_handler *c,
{ /* Doesn't help us */
werror("Recieved SSH_MSH_USERAUTH_FAILURE "
"indicating partial success.\n");
lsh_space_free(methods);
KILL(methods);
return LSH_FAIL | LSH_DIE;
}
for(i = 0; methods[i] >= 0; i++)
if (methods[i] == ATOM_PASSWORD)
for(i = 0; i < LIST_LENGTH(methods); i++)
if (LIST(methods)[i] == ATOM_PASSWORD)
{
/* Try again */
lsh_space_free(methods);
KILL(methods);
return send_passwd(closure->userauth, connection);
}
/* No methods that we can use */
lsh_space_free(methods);
KILL(methods);
return LSH_FAIL | LSH_DIE;
}
if (methods)
lsh_space_free(methods);
KILL(methods);
lsh_string_free(packet);
return LSH_FAIL | LSH_DIE;
......@@ -205,7 +239,7 @@ static int do_userauth_banner(struct packet_handler *closure,
UINT32 language_length;
UINT8 *language;
MDEBUG(closure);
CHECK_TYPE(packet_handler, closure);
simple_buffer_init(&buffer, packet->length, packet->data);
......@@ -227,9 +261,8 @@ static int do_userauth_banner(struct packet_handler *closure,
static struct packet_handler *make_success_handler(struct ssh_service *service)
{
struct success_handler *self;
NEW(success_handler, self);
NEW(self);
self->super.handler = do_userauth_success;
self->service = service;
......@@ -239,9 +272,8 @@ static struct packet_handler *make_success_handler(struct ssh_service *service)
static struct packet_handler *
make_failure_handler(struct client_userauth *userauth)
{
struct failure_handler *self;
NEW(failure_handler, self);
NEW(self);
self->super.handler = do_userauth_failure;
self->userauth = userauth;
......@@ -250,9 +282,8 @@ make_failure_handler(struct client_userauth *userauth)
static struct packet_handler *make_banner_handler()
{
struct packet_handler *self;
NEW(packet_handler, self);
NEW(self);
self->handler = do_userauth_banner;
return self;
......@@ -261,9 +292,7 @@ static struct packet_handler *make_banner_handler()
static int init_client_userauth(struct ssh_service *c,
struct ssh_connection *connection)
{
struct client_userauth *closure = (struct client_userauth *) c;
MDEBUG(closure);
CAST(client_userauth, closure, c);
connection->dispatch[SSH_MSG_USERAUTH_SUCCESS]
= make_success_handler(closure->service);
......@@ -279,9 +308,7 @@ struct ssh_service *make_client_userauth(struct lsh_string *username,
int service_name,
struct ssh_service *service)
{
struct client_userauth *closure;
NEW(closure);
NEW(client_userauth, closure);
closure->super.init = init_client_userauth;
closure->username = username;
......
......@@ -41,7 +41,7 @@
static int handle_connection(struct abstract_write *w,
struct lsh_string *packet)
{
CAST(closure, ssh_connection, w);
CAST(ssh_connection, closure, w);
UINT8 msg;
if (!packet->length)
......
......@@ -33,6 +33,9 @@
#include "werror.h"
#include "xalloc.h"
#include "crypto.c.x"
#if 0
/* No crypto */
static void do_crypt_none(struct crypto_instance *ignored,
UINT32 length, UINT8 *dst, UINT8 *src)
......@@ -49,20 +52,29 @@ struct crypto_instance crypto_none_instance =
8,
do_crypt_none
};
#endif
/* CLASS:
(class
(name rc4_instance)
(super crypto_instance)
(vars
(ctx simple "struct rc4_ctx")))
*/
#if 0
struct rc4_instance
{
struct crypto_instance super;
struct rc4_ctx ctx;
};
#endif
static void do_crypt_rc4(struct crypto_instance *s,
UINT32 length, UINT8 *src, UINT8 *dst)
{
struct rc4_instance *self = (struct rc4_instance *) s;
CAST(rc4_instance, self, s);
MDEBUG(self);
if (length % 8)
fatal("Internal error\n");
......@@ -72,9 +84,7 @@ static void do_crypt_rc4(struct crypto_instance *s,
static struct crypto_instance *
make_rc4_instance(struct crypto_algorithm *ignored, int mode, UINT8 *key)
{
struct rc4_instance *self;
NEW(self);
NEW(rc4_instance, self);
self->super.block_size = 8;
self->super.crypt = do_crypt_rc4;
......@@ -89,29 +99,35 @@ struct crypto_algorithm crypto_rc4_algorithm =
8, 16, make_rc4_instance };
/* SHA1 hash */
/* CLASS:
(class
(name sha_instance)
(super hash_instance)
(vars
(ctx simple "struct sha_ctx")))
*/
#if 0
struct sha_instance
{
struct hash_instance super;
struct sha_ctx ctx;
};
#endif
static void do_sha_update(struct hash_instance *s,
UINT32 length, UINT8 *data)
{
struct sha_instance *self = (struct sha_instance *) s;
CAST(sha_instance, self, s);
MDEBUG(self);
sha_update(&self->ctx, data, length);
}
static void do_sha_digest(struct hash_instance *s,
UINT8 *dst)
{
struct sha_instance *self = (struct sha_instance *) s;
CAST(sha_instance, self, s);
MDEBUG(self);
sha_final(&self->ctx);
sha_digest(&self->ctx, dst);
sha_init(&self->ctx);
......@@ -119,12 +135,8 @@ static void do_sha_digest(struct hash_instance *s,
static struct hash_instance *do_sha_copy(struct hash_instance *s)
{
struct sha_instance *self = (struct sha_instance *) s;
struct sha_instance *new;