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

Adapted to gc and object system (won't work yet).

Rev: src/abstract_crypto.h:1.13
Rev: src/channel.c:1.13
Rev: src/channel.h:1.16
Rev: src/client_keyexchange.h:1.8
Rev: src/io.h:1.20
Rev: src/keyexchange.h:1.23
Rev: src/password.h:1.6
Rev: src/publickey_crypto.h:1.11
parent a30ecd21
......@@ -28,6 +28,20 @@
#include "lsh_types.h"
#define CLASS_DECLARE
#include "abstract_crypto.h.x"
#undef CLASS_DECLARE
/* CLASS:
(class
(name crypto_instance)
(vars
(block_size simple UINT32)
; Length must be a multiple of the block size
(crypt method void
"UINT32 length" "UINT8 *src" "UINT8 *dst")))
*/
#if 0
struct crypto_instance
{
struct lsh_object header;
......@@ -36,6 +50,7 @@ struct crypto_instance
void (*crypt)(struct crypto_instance *self,
UINT32 length, UINT8 *src, UINT8 *dst);
};
#endif
#define CRYPT(instance, length, src, dst) \
((instance)->crypt((instance), (length), (src), (dst)))
......@@ -43,6 +58,17 @@ struct crypto_instance
#define CRYPTO_ENCRYPT 0
#define CRYPTO_DECRYPT 1
/* CLASS:
(class
(name crypto_algorithm)
(vars
(block_size simple UINT32)
(key_size simple UINT32)
(make_crypt method (object crypto_instance)
"int mode" "UIINT8 *key")))
*/
#if 0
struct crypto_algorithm
{
struct lsh_object header;
......@@ -53,6 +79,7 @@ struct crypto_algorithm
int mode,
UINT8 *key);
};
#endif
#define MAKE_ENCRYPT(crypto, key) \
((crypto)->make_crypt((crypto), CRYPTO_ENCRYPT, (key)))
......@@ -60,6 +87,18 @@ struct crypto_algorithm
#define MAKE_DECRYPT(crypto, key) \
((crypto)->make_crypt((crypto), CRYPTO_DECRYPT, (key)))
/* CLASS:
(class
(name hash_instance)
(vars
(hash_size simple UINT32)
(update method void
"UINT32 length" "UINT8 *data")
(digest method void "UINT8 *result")
(copy method (object hash_instance))))
*/
#if 0
struct hash_instance
{
struct lsh_object header;
......@@ -71,6 +110,7 @@ struct hash_instance
UINT8 *result);
struct hash_instance * (*copy)(struct hash_instance *self);
};
#endif
#define HASH_UPDATE(instance, length, data) \
((instance)->update((instance), (length), (data)))
......@@ -83,7 +123,17 @@ struct hash_instance
/* Used for both hash functions ad macs */
#define mac_instance hash_instance
#define mac_size hash_size
/* CLASS:
(class
(name hash_algorithm)
(vars
(block_size simple UINT32)
(hash_size simple UINT32)
(make_hash method (object hash_instance))))
*/
#if 0
struct hash_algorithm
{
struct lsh_object header;
......@@ -91,9 +141,20 @@ struct hash_algorithm
UINT32 hash_size;
struct hash_instance * (*make_hash)(struct hash_algorithm *self);
};
#endif
#define MAKE_HASH(h) ((h)->make_hash((h)))
/* CLASS:
(class
(name mac_algorithm)
(vars
(hash_size simple UINT32)
(key_size simple UINT32)
(make_mac method (object mac_instance) "UINT8 *key")))
*/
#if 0
struct mac_algorithm
{
struct lsh_object header;
......@@ -102,9 +163,19 @@ struct mac_algorithm
struct mac_instance * (*make_mac)(struct mac_algorithm *self,
UINT8 *key);
};
#endif
#define MAKE_MAC(m, key) ((m)->make_mac((m), (key)))
/* CLASS:
(class
(name signer)
(vars
; Returns a signature string, *without* the length field
(sign method (string)
"UINT32 length" "UINT8 *data")))
*/
#if 0
struct signer
{
struct lsh_object header;
......@@ -113,9 +184,19 @@ struct signer
UINT32 length,
UINT8 *data);
};
#endif
#define SIGN(signer, length, data) ((signer)->sign((signer), (length), (data)))
/* CLASS:
(class
(name verifier)
(vars
(verify method int
"UINT32 length" "UINT8 *data"
"UINT32 signature_length" "UINT8 * signature_data")))
*/
#if 0
struct verifier
{
struct lsh_object header;
......@@ -125,10 +206,24 @@ struct verifier
UINT32 signature_length,
UINT8 * signature_data);
};
#endif
#define VERIFY(verifier, length, data, slength, sdata)\
((verifier)->verify((verifier), (length), (data), (slength), (sdata)))
/* CLASS:
(class
(name signature_algorithm)
(vars
(make_signer method (object signer)
"UINT32 public_length" "UINT8 *public"
"UINT32 secret_length" "UINT8 *secret")
(make_verifier method (object verifier)
"UINT32 public_length" "UINT8 *public")))
*/
#if 0
struct signature_algorithm
{
struct lsh_object header;
......@@ -141,6 +236,7 @@ struct signature_algorithm
UINT32 public_length,
UINT8 *public);
};
#endif
#define MAKE_SIGNER(a, pl, p, sl, s) \
((a)->make_signer((a), (pl), (p), (sl), (s)))
......
......@@ -34,6 +34,10 @@
#include <assert.h>
#define CLASS_DEFINE
#include "channel.h.x"
#undef CLASS_DEFINE
struct connection_service
{
struct ssh_service super;
......
......@@ -10,6 +10,10 @@
#include "connection.h"
#include "parse.h"
#define CLASS_DECLARE
#include "channel.h.x"
#undef CLASS_DECLARE
/* Channels are indexed by local channel number in some array. This
* index is not stored in the channel struct. When sending messages on
* the channel, it is identified by the *remote* sides index number,
......@@ -33,6 +37,64 @@
/* Means that we should send close immediately after sending eof. */
#define CHANNEL_CLOSE_AT_EOF 0x10
/* CLASS:
(class
(name ssh_channel)
(vars
; Remote channel number
(channel_number simple UINT32)
; We try to keep the rec_window_size ; between max_window / 2
; and max_window.
(max_window simple UINT32)
(rec_window_size simple UINT32)
(rec_max_packet simple UINT32)
(send_window_size simple UINT32)
(send_max_packet simple UINT32)
; FIXME: Perhaps this should be moved to the channel_table, and
; a pointer to that table be stored here instead?
(write object abstract_write)
(request_types object alist)
(flags simple int)
; Number of files connected to this channel. For instance,
; stdout and stderr can be multiplexed on the same channel. We
; should not close the channel until we have got an EOF on both
; sources.
(sources simple int)
; FIXME: What about return values from these functions? A
; channel may fail to process it's data. Is there some way to
; propagate a channel broken message to the other end?
; Type is CHANNEL_DATA or CHANNEL_STDERR_DATA
(recieve method int "int type" "struct lsh_string *data")
; Called when we are allowed to send data on the channel.
(send method int)
; Called when the channel is closed
(close method void)
; Called when eof is recieved on the channel (or when it is
; closed, whatever happens first).
(eof method int)
; Reply from SSH_MSG_CHANNEL_OPEN_REQUEST
(open_confirm method int)
(open_failure method int)
; Reply from SSH_MSG_CHANNEL_REQUEST
(channel_success method int)
(channel_failure method int)))
#if 0
struct ssh_channel
{
struct lsh_object header;
......@@ -86,6 +148,7 @@ struct ssh_channel
int (*channel_success)(struct ssh_channel *self);
int (*channel_failure)(struct ssh_channel *self);
};
#endif
#define CHANNEL_RECIEVE(s, t, d) \
((s)->recieve((s), (t), (d)))
......@@ -112,6 +175,38 @@ struct ssh_channel
/* FIXME: Perhaps, this information is better kept in the connection
* object? */
/* CLASS:
(class
(name channel_table)
(vars
; FIXME: This is relevant only for the server side. It's
; probably better to store this in the connection struct.
;; uid_t user; ; Authenticated user
; Channels are indexed by local number
(channels pointer (object ssh_channel) used_channels)
; Allocation of local channel numbers is managed using the same
; method as is traditionally used for allocation of unix file
; descriptors.
(allocated_channels simple UINT32)
(next_channel simple UINT32)
(used_channels simple UINT32)
(max_channels simple UINT32) ; Max number of channels allowed
; If non-zero, close connection after all active channels have
; died.
(pending_close simple int)
; FIXME: Perhaps we should use an flag to indicate whether or
; not new channels can be opened?
))
*/
#if 0
struct channel_table
{
struct lsh_object header;
......@@ -139,8 +234,17 @@ struct channel_table
/* FIXME: Perhaps we should use an flag to indicate whether or not
* new channels can be opened? */
};
#endif
/* SSH_MSG_GLOBAL_REQUEST */
/* CLASS:
(class
(name global_request)
(vars
(handler method int "int want_reply" "struct simple_buffer *args")))
*/
#if 0
struct global_request
{
struct lsh_object header;
......@@ -149,10 +253,22 @@ struct global_request
int want_reply,
struct simple_buffer *args);
};
#endif
#define GLOBAL_REQUEST(c, w, a) ((c)->handler((c), (w), (a)))
/* SSH_MSG_CHANNEL_OPEN */
/* CLASS:
(class
(name channel_open)
(vars
(handler method (object ssh_channel)
"struct simple_buffer *args"
"UINT32 *error" "char **error_msg"
"struct lsh_string **data")))
*/
#if 0
struct channel_open
{
struct lsh_object header;
......@@ -163,11 +279,23 @@ struct channel_open
char **error_msg,
struct lsh_string **data);
};
#endif
#define CHANNEL_OPEN(c, a, e, m, d) \
((c)->handler((c), (a), (e), (m), (d)))
/* SSH_MSH_CHANNEL_REQUEST */
/* CLASS:
(class
(name channel_request)
(vars
(handler method int
"struct ssh_channel *channel"
"int want_reply"
"struct simple_buffer *args")))
*/
#if 0
struct channel_request
{
struct lsh_object header;
......@@ -177,10 +305,22 @@ struct channel_request
int want_reply,
struct simple_buffer *args);
};
#endif
#define CHANNEL_REQUEST(s, c, w, a) \
((s)->handler((s), (c), (w), (a)))
/* CLASS:
(class
(name connection_startup)
(vars
(start method int
"struct channel_table *table"
"struct abstract_write *write")))
*/
#if 0
struct connection_startup
{
struct lsh_object header;
......@@ -189,6 +329,7 @@ struct connection_startup
struct channel_table *table,
struct abstract_write *write);
};
#endif
#define CONNECTION_START(c, s, w) ((c)->start((c), (s), (w)))
......
......@@ -34,12 +34,22 @@
* Returns NULL If the key is invalid or not trusted. */
/* FIXME: This function needs the hostname we are connecting to. */
/* CLASS:
(class
(name lookup_verifier)
(vars
(lookup method (object verifier) "struct lsh_string *key")))
*/
#if 0
struct lookup_verifier
{
struct lsh_object header;
struct verifier * (*lookup)(struct lookup_verifier *closure,
struct lsh_string *key);
};
#endif
#define LOOKUP_VERIFIER(l, key) ((l)->lookup((l), (key)))
......
......@@ -34,12 +34,21 @@
#include <netinet/in.h>
/* A closed function with a file descriptor as argument */
/* CLASS:
(class
(name fd_callback)
(vars
(f method int "int fd")))
*/
#if 0
struct fd_callback
{
struct lsh_object header;
int (*f)(struct fd_callback **closure, int fd);
};
#endif
#define FD_CALLBACK(c, fd) ((c)->f(&(c), (fd)))
......@@ -57,11 +66,20 @@ struct fd_callback
#define CLOSE_PROTOCOL_FAILURE 5
/* CLASS:
(class
(name close_callback)
(vars
(f method int "int reason")))
*/
#if 0
struct close_callback
{
struct lsh_object header;
int (*f)(struct close_callback *closure, int reason);
};
#endif
#define CLOSE_CALLBACK(c, r) ((c)->f((c), (r)))
......@@ -72,6 +90,33 @@ struct close_callback
#define FD_CONNECT 3
#endif
/* CLASS:
(class
(name lsh_fd)
(vars
(next object lsh_fd)
(fd int)
; User's close callback
(close_reason int)
(close_callback object close_callback)
; Called before poll
(prepare method void)
(want_read int)
; Called if poll indicates that data can be read.
(read method void)
(want_write int)
; Called if poll indicates that data can be written.
(write method void)
(close_now int)
(really_close method void)))
*/
#if 0
struct lsh_fd
{
struct lsh_object header;
......@@ -97,12 +142,25 @@ struct lsh_fd
int close_now;
void (*really_close)(struct lsh_fd *self);
};
#endif
#define PREPARE_FD(fd) ((fd)->prepare((fd)))
#define READ_FD(fd) ((fd)->read((fd)))
#define WRITE_FD(fd) ((fd)->write((fd)))
#define REALLY_CLOSE_FD(fd) ((fd)->really_close((fd)))
/* CLASS:
(class
(name io_fd)
(super lsh_fd)
(vars
; Reading
(handler object read_handler)
; Writing
(buffer object write_buffer)))
*/
#if 0
struct io_fd
{
struct lsh_fd super;
......@@ -113,13 +171,24 @@ struct io_fd
/* Writing */
struct write_buffer *buffer;
};
#endif
/* CLASS:
(class
(name io_fd)
(super lsh_fd)
(vars
(callback object fd_callback)))
*/
#if 0
struct listen_fd
{
struct lsh_fd super;
struct fd_callback *callback;
};
#endif
#define connect_fd listen_fd
......@@ -134,6 +203,17 @@ struct callout
};
#endif
/* CLASS:
(class
(name io_backend)
(vars
; Linked list of fds.
(files object lsh_fd)
; Callouts
;; (callouts object callout)))
*/
#if 0
struct io_backend
{
struct lsh_object header;
......@@ -146,6 +226,7 @@ struct io_backend
struct callout *callouts;
#endif
};
#endif
void init_backend(struct io_backend *b);
......
......@@ -68,7 +68,19 @@ struct keyexchange_finished
#define KEYEXCHANGE_FINISHED(f, c) ((f)->finished((f), (c)))
#endif
/* algorithms is an array indexed by the KEX_* values above */
/* CLASS:
(class
(name keyexchange_algorithm)
(vars
; Algorithms is an array indexed by the KEX_* values above
(init method void
"struct ssh_connection *connection"
"struct ssh_service *finished"
"int hostkey_algorithm_atom"
"struct signature_algorithm *hostkey_algorithm"
"void **algorithms")))
*/
#if 0
struct keyexchange_algorithm
{
struct lsh_object header;
......@@ -80,10 +92,26 @@ struct keyexchange_algorithm
struct signature_algorithm *hostkey_algorithm,
void **algorithms);
};
#endif
#define KEYEXCHANGE_INIT(kex, connection, f, ha, h, a) \
((kex)->init((kex), (connection), (f), (ha), (h), (a)))
/* CLASS:
(class
(name kexinit)
(vars
(cookie array UINT8 16);
; Lists of atoms
(kex_algorithms object lsh_list)
(server_hostkey_algorithms object lsh_list)
(parameters array (object lsh_list) KEX_PARAMETERS)
(languages_client_to_server object lsh_list)
(languages_server_to_client object lsh_list)
(first_kex_packet_follows simple int)))
*/
#if 0
struct kexinit
{
struct lsh_object header;
......@@ -97,6 +125,7 @@ struct kexinit
int *languages_server_to_client;
int first_kex_packet_follows;
};
#endif
/* This function generates a new kexinit message.
*
......@@ -104,16 +133,35 @@ struct kexinit
* the message, record it in the connection structure, and possibly
* send a first guessed message. */
/* CLASS:
(class
(name make_kexinit)
(vars
(make method (object kexinit))))
*/
#if 0
struct make_kexinit
{
struct lsh_object header;
struct kexinit * (*make)(struct make_kexinit *closure);
};
#endif
#define MAKE_KEXINIT(m) ((m)->make((m)))
/* Installs keys for use. */
/* CLASS:
(class
(name install_keys)
(vars