Commit 701aecb0 authored by Niels Möller's avatar Niels Möller

More debug functions in werror.[ch].

Rev: src/client.c:1.19
Rev: src/client_keyexchange.c:1.10
Rev: src/connection.c:1.11
Rev: src/debug.c:1.11
Rev: src/debug.h:1.8
Rev: src/disconnect.c:1.3
Rev: src/keyexchange.c:1.15
Rev: src/server.c:1.12
Rev: src/server_keyexchange.c:1.8
Rev: src/werror.c:1.10
Rev: src/werror.h:1.9
parent fbc19bff
......@@ -113,7 +113,7 @@ static struct read_handler *do_line(struct line_handler **h,
(make_packet_unpad
(make_packet_debug
(&closure->connection->super,
stderr)),
"")),
closure->connection);
closure->connection->server_version
......
......@@ -24,6 +24,7 @@
#include "client_keyexchange.h"
#include "atoms.h"
#include "debug.h"
#include "format.h"
#include "ssh.h"
#include "werror.h"
......@@ -106,7 +107,7 @@ static int do_handle_dh_reply(struct packet_handler *c,
connection->dispatch[SSH_MSG_KEXDH_REPLY] = connection->fail;
connection->kex_state = KEX_STATE_NEWKEYS;
return res;
return send_verbose(connection->write, "Key exchange successful!", 0);
}
static int do_init_dh(struct keyexchange_algorithm *c,
......
......@@ -4,6 +4,7 @@
#include "connection.h"
#include "debug.h"
#include "encrypt.h"
#include "format.h"
#include "disconnect.h"
......@@ -166,7 +167,7 @@ struct ssh_connection *make_ssh_connection(struct packet_handler *kex_handler)
connection->dispatch[SSH_MSG_UNIMPLEMENTED] = connection->ignore;
/* FIXME: Write a debug handler */
connection->dispatch[SSH_MSG_DEBUG] = connection->ignore;
connection->dispatch[SSH_MSG_DEBUG] = make_rec_debug_handler();
connection->dispatch[SSH_MSG_KEXINIT] = kex_handler;
......
......@@ -24,12 +24,18 @@
*/
#include "debug.h"
#include "connection.h"
#include "format.h"
#include "parse.h"
#include "ssh.h"
#include "xalloc.h"
#include "werror.h"
struct packet_debug
{
struct abstract_write_pipe super;
FILE *output;
char *prefix;
};
static int do_debug(struct abstract_write **w,
......@@ -38,36 +44,98 @@ static int do_debug(struct abstract_write **w,
struct packet_debug *closure
= (struct packet_debug *) *w;
UINT32 i;
MDEBUG(closure);
fprintf(closure->output, "DEBUG: (packet size %d = 0x%x)\n",
packet->length, packet->length);
for(i=0; i<packet->length; i++)
{
if (! (i%16))
fprintf(closure->output, "\n%08x: ", i);
fprintf(closure->output, "%02x ", packet->data[i]);
}
fprintf(closure->output, "\n");
debug("DEBUG: recieved packet");
debug_hex(packet->length, packet->data);
debug("\n");
return A_WRITE(closure->super.next, packet);
}
struct abstract_write *
make_packet_debug(struct abstract_write *continuation, FILE *output)
make_packet_debug(struct abstract_write *continuation, char *prefix)
{
struct packet_debug *closure = xalloc(sizeof(struct packet_debug));
closure->super.super.write = do_debug;
closure->super.next = continuation;
closure->output = output;
closure->prefix = prefix;
return &closure->super.super;
}
static struct lsh_string *make_debug_packet(char *msg, int always_display)
{
return ssh_format("%c%c%z%z",
SSH_MSG_DEBUG,
always_display,
msg,
/* Empty language tag */
"");
}
/* Send a debug message to the other end. */
int send_debug(struct abstract_write *write, char *msg, int always_display)
{
return (debug_flag)
? A_WRITE(write, make_debug_packet(msg, always_display))
: WRITE_OK;
}
int send_verbose(struct abstract_write *write, char *msg, int always_display)
{
return (verbose_flag)
? A_WRITE(write, make_debug_packet(msg, always_display))
: WRITE_OK;
}
static int do_rec_debug(struct packet_handler *self,
struct ssh_connection *connection,
struct lsh_string *packet)
{
struct simple_buffer buffer;
UINT8 msg_number;
UINT8 always_display;
UINT32 length;
UINT8 *msg;
int language;
simple_buffer_init(&buffer, packet->length, packet->data);
if (!(parse_uint8(&buffer, &msg_number)
&& parse_uint8(&buffer, &always_display)
&& parse_string(&buffer, &length, &msg)
&& parse_atom(&buffer, &language)
&& parse_eod(&buffer)))
{
lsh_string_free(packet);
return WRITE_CLOSED;
}
if (always_display)
{
werror("Recieved debug: ");
werror_utf8(length, msg);
werror("\n");
}
else
{
verbose("Recieved debug: ");
verbose_utf8(length, msg);
verbose("\n");
}
lsh_string_free(packet);
return WRITE_OK;
}
struct packet_handler *make_rec_debug_handler(void)
{
struct packet_handler *self = xalloc(sizeof(struct packet_handler));
self->handler = do_rec_debug;
return self;
}
......@@ -30,7 +30,12 @@
#include "abstract_io.h"
struct abstract_write *
make_packet_debug(struct abstract_write *continuation, FILE *output);
make_packet_debug(struct abstract_write *continuation, char *prefix);
int send_debug(struct abstract_write *write, char *msg, int always_display);
int send_verbose(struct abstract_write *write, char *msg, int always_display);
struct packet_handler *make_rec_debug_handler(void);
#endif */ LSH_DEBUG_H_INCLUDED */
......@@ -58,7 +58,7 @@ static int do_disconnect(struct packet_handler *closure,
{
/* FIXME: Display a better message */
werror("Disconnect for reason %d\n", reason);
werror_safe_utf8(length, msg);
werror_utf8(length, msg);
}
else
werror("Invalid disconnect message!\n");
......
......@@ -313,6 +313,8 @@ static struct lsh_string *kex_make_key(struct hash_instance *secret,
key = lsh_string_alloc(key_length);
debug("Constructing session key of type %d\n", type);
if (!key_length)
return key;
......@@ -328,6 +330,8 @@ static struct lsh_string *kex_make_key(struct hash_instance *secret,
memcpy(key->data, digest, key_length);
lsh_free(hash);
debug_hex(key->length, key->data);
return key;
}
......
......@@ -110,7 +110,7 @@ static struct read_handler *do_line(struct line_handler **h,
struct read_handler *new = make_read_packet
(make_packet_unpad
(make_packet_debug(&closure->connection->super,
stderr)),
"recieved")),
closure->connection);
closure->connection->client_version
......
......@@ -24,6 +24,7 @@
#include "server_keyexchange.h"
#include "atoms.h"
#include "debug.h"
#include "format.h"
#include "ssh.h"
#include "werror.h"
......@@ -79,7 +80,7 @@ static int do_handle_dh_init(struct packet_handler *c,
res = A_WRITE(connection->write, ssh_format("%c", SSH_MSG_NEWKEYS));
if (res != WRITE_OK)
return res;
/* Record session id */
if (!connection->session_id)
{
......@@ -101,7 +102,7 @@ static int do_handle_dh_init(struct packet_handler *c,
connection->kex_state = KEX_STATE_NEWKEYS;
connection->dispatch[SSH_MSG_KEXDH_INIT] = connection->fail;
return res;
return send_verbose(connection->write, "Key exchange successful!", 0);
}
static int do_init_dh(struct keyexchange_algorithm *c,
......
......@@ -93,7 +93,7 @@ static void wash_char(UINT8 c)
}
/* Escape non-printable characters. */
static void werror_washed(UINT32 length, UINT8 *msg)
static void write_washed(UINT32 length, UINT8 *msg)
{
int i;
......@@ -105,68 +105,74 @@ static void werror_washed(UINT32 length, UINT8 *msg)
void werror_safe(UINT32 length, UINT8 *msg)
{
if (!quiet_flag)
werror_washed(length, msg);
write_washed(length, msg);
}
void debug_safe(UINT32 length, UINT8 *msg)
{
if (debug_flag)
werror_washed(length, msg);
write_washed(length, msg);
}
void verbose_safe(UINT32 length, UINT8 *msg)
{
if (verbose_flag)
werror_washed(length, msg);
write_washed(length, msg);
}
void werror_safe_utf8(UINT32 length, UINT8 *msg)
/* Limited utf8-support */
static void write_utf8(UINT32 length, UINT8 *msg)
{
/* FIXME: This function assumes that the system charset is
* iso-8859-1, aka latin1. */
if (!quiet_flag)
{
int i=0;
int i=0;
while(i<length)
{
UINT8 c = msg[i++];
if (!(c & 0x80))
wash_char(c);
else
{
if ( (c & 0xd0) != 0xc0)
{
/* Unicode value >= 0x800 */
fputs("\\?", stderr);
while ( (i < length) & (msg[i] & 0x80) )
i++;
}
else
{
if (i == length)
/* String ends with a partial character! */
fputs("\\!", stderr);
else
wash_char( ((c & 3) << 6) || (msg[i++] & 0x3f) );
}
}
}
while(i<length)
{
UINT8 c = msg[i++];
if (!(c & 0x80))
wash_char(c);
else
{
if ( (c & 0xd0) != 0xc0)
{
/* Unicode value >= 0x800 */
fputs("\\?", stderr);
while ( (i < length) & (msg[i] & 0x80) )
i++;
}
else
{
if (i == length)
/* String ends with a partial character! */
fputs("\\!", stderr);
else
wash_char( ((c & 3) << 6) || (msg[i++] & 0x3f) );
}
}
}
}
void fatal(char *format, ...)
void werror_utf8(UINT32 length, UINT8 *msg)
{
va_list args;
if (!quiet_flag)
write_utf8(length, msg);
}
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
void verbose_utf8(UINT32 length, UINT8 *msg)
{
if (verbose_flag)
write_utf8(length, msg);
}
abort();
void debug_utf8(UINT32 length, UINT8 *msg)
{
if (debug_flag)
write_utf8(length, msg);
}
/* Bignums */
void werror_mpz(mpz_t n)
{
if (!quiet_flag)
......@@ -184,3 +190,50 @@ void verbose_mpz(mpz_t n)
if (verbose_flag)
mpz_out_str(stderr, 16, n);
}
/* hex dumps */
static void write_hex(UINT32 length, UINT8 *data)
{
int i;
fprintf(stderr, "(size %d = 0x%x)",
length, length);
for(i=0; i<length; i++)
{
if (! (i%16))
fprintf(stderr, "\n%08x: ", i);
fprintf(stderr, "%02x ", data[i]);
}
fprintf(stderr, "\n");
}
void werror_hex(UINT32 length, UINT8 *data)
{
if (!quiet_flag)
write_hex(length, data);
}
void debug_hex(UINT32 length, UINT8 *data)
{
if (debug_flag)
write_hex(length, data);
}
void verbose_hex(UINT32 length, UINT8 *data)
{
if (verbose_flag)
write_hex(length, data);
}
void fatal(char *format, ...)
{
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
abort();
}
......@@ -44,10 +44,16 @@ void werror_safe(UINT32 length, UINT8 *msg);
void debug_safe(UINT32 length, UINT8 *msg);
void verbose_safe(UINT32 length, UINT8 *msg);
void werror_safe_utf8(UINT32 length, UINT8 *msg);
void werror_utf8(UINT32 length, UINT8 *msg);
void debug_utf8(UINT32 length, UINT8 *msg);
void verbose_utf8(UINT32 length, UINT8 *msg);
void fatal(char *format, ...) PRINTF_STYLE(1,2) NORETURN;
void werror_hex(UINT32 length, UINT8 *data);
void debug_hex(UINT32 length, UINT8 *data);
void verbose_hex(UINT32 length, UINT8 *data);
void werror_mpz(mpz_t n);
void debug_mpz(mpz_t n);
void verbose_mpz(mpz_t n);
......
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