diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-09-26 17:08:27 +0200 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-09-26 17:08:27 +0200 |
commit | 5838d820581221a4166f3e1df0b2608a6952359e (patch) | |
tree | 12da0065b9233187c8e0cb6c228d4372d5083082 | |
parent | b53fa04f47b54e08733ba3859bfaac171ab1c7af (diff) | |
download | cmumble-5838d820581221a4166f3e1df0b2608a6952359e.tar.gz cmumble-5838d820581221a4166f3e1df0b2608a6952359e.tar.bz2 cmumble-5838d820581221a4166f3e1df0b2608a6952359e.zip |
wip
-rw-r--r-- | src/Makefile.am | 6 | ||||
-rw-r--r-- | src/cmumble.c | 25 | ||||
-rw-r--r-- | src/cmumble.h | 3 | ||||
-rw-r--r-- | src/connection.c | 71 | ||||
-rw-r--r-- | src/ocb/ocb.c | 2 |
5 files changed, 77 insertions, 30 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 6a17f11..a32305c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,15 +3,15 @@ SUBDIRS = ocb bin_PROGRAMS = cmumble noinst_HEADERS = cmumble.h message.h varint.h io.h \ - connection.h audio.h commands.h util.h + connection.h audio.h commands.h util.h crypt.h nodist_noinst_HEADERS = mumble.pb-c.h message_list.h cmumble_SOURCES = cmumble.c message.c varint.c io.c \ - connection.c audio.c commands.c util.c + connection.c audio.c commands.c util.c crypt.c nodist_cmumble_SOURCES = mumble.pb-c.c cmumble_LDADD = $(PROTOBUF_LIBS) $(GLIB_LIBS) $(GIO_LIBS) \ - $(GSTREAMER_LIBS) $(CELT_LIBS) \ + $(GSTREAMER_LIBS) $(CELT_LIBS) -lssl\ ocb/libocb.a AM_CPPFLAGS = $(PROTOBUF_CFLAGS) $(GLIB_CFLAGS) $(GIO_CFLAGS) \ $(GSTREAMER_CFLAGS) $(CELT_CFLAGS) diff --git a/src/cmumble.c b/src/cmumble.c index 844a4d3..fb20e27 100644 --- a/src/cmumble.c +++ b/src/cmumble.c @@ -91,10 +91,24 @@ recv_server_sync(MumbleProto__ServerSync *sync, struct cmumble_context *ctx) } static void +print_hex(char *hex, int num) +{ + int i; + + for (i = 0; i < num; ++i) + printf("%02x", hex[i] & 0xff); + +} + +static void recv_crypt_setup(MumbleProto__CryptSetup *crypt, struct cmumble_context *ctx) { /* FIXME: require all data lengths to be 16? */ + if (crypt->key.len != 16 || crypt->client_nonce.len != 16 || + crypt->server_nonce.len != 16) + return; + ctx->ocb_key = g_memdup(crypt->key.data, crypt->key.len); ctx->ocb_client_nonce = g_memdup(crypt->client_nonce.data, @@ -102,8 +116,17 @@ recv_crypt_setup(MumbleProto__CryptSetup *crypt, struct cmumble_context *ctx) ctx->ocb_server_nonce = g_memdup(crypt->server_nonce.data, crypt->server_nonce.len); - ctx->ocb = ocb_aes_init(ctx->ocb_key, 16, NULL); +#if 1 + ctx->ocb = ocb_aes_init(ctx->ocb_key, 3, NULL); g_assert(ctx->ocb); +#endif +#if 1 + CryptState_init(&ctx->crypt); + CryptState_setKey(&ctx->crypt, + ctx->ocb_key, + ctx->ocb_client_nonce, + ctx->ocb_server_nonce); +#endif cmumble_connection_udp_init(ctx); } diff --git a/src/cmumble.h b/src/cmumble.h index 9e65ec2..4e43caf 100644 --- a/src/cmumble.h +++ b/src/cmumble.h @@ -13,6 +13,8 @@ #include "commands.h" #include "ocb/ocb.h" +#include "crypt.h" + typedef void (*callback_t)(ProtobufCMessage *msg, struct cmumble_context *); struct cmumble_context { @@ -35,6 +37,7 @@ struct cmumble_context { GList *channels; keystruct *ocb; + cryptState_t crypt; guchar *ocb_key; guchar *ocb_client_nonce; guchar *ocb_server_nonce; diff --git a/src/connection.c b/src/connection.c index 66b2cdd..fbb574b 100644 --- a/src/connection.c +++ b/src/connection.c @@ -24,7 +24,7 @@ read_udp(GSocket *socket, GIOCondition condition, gpointer user_data) { GError *error = NULL; gchar buf[1024]; - gssize size; + gssize size = 0; size = g_socket_receive(socket, buf, sizeof(buf), NULL, &error); @@ -33,14 +33,7 @@ read_udp(GSocket *socket, GIOCondition condition, gpointer user_data) return TRUE; } -static gboolean -read_udp_io(GIOChannel *source, GIOCondition condition, gpointer data) -{ - g_print("got udp data from channel\n"); - - return TRUE; -} - +#if 0 static void print_hex(char *hex, int num) { @@ -50,6 +43,7 @@ print_hex(char *hex, int num) printf("%02x", hex[i] & 0xff); } +#endif static void do_udp_ping(struct cmumble_context *ctx) @@ -59,28 +53,48 @@ do_udp_ping(struct cmumble_context *ctx) GTimeVal tv; GError *error = NULL; gssize sent; - int i; g_get_current_time(&tv); data[pos++] = (udp_ping << 5); encode_varint(&data[pos], &write, tv.tv_sec, 16-pos); pos += write; - g_print("write: %d\n", write); - char tag[16] = { 0 }; char foo[16] = { 0 }; +#if 0 + int i; + char tag[16] = { 0 }; + char bar[16] = { 0 }; + char ha[16] = {0}; +#if 1 /* Increase nonce, see: * http://www.cs.ucdavis.edu/~rogaway/ocb/ocb-back.htm#nonce */ for (i = 0; i < 16; ++i) if (++ctx->ocb_client_nonce[i]) break; +#endif + g_assert(CryptState_isValid(&ctx->crypt)); + +#if 1 + bar[0] = ctx->ocb_client_nonce[0]; ocb_aes_encrypt(ctx->ocb, ctx->ocb_client_nonce, data, pos, - foo+4, tag); + bar+4, bar+1); + ha[0] = ctx->ocb_client_nonce[0]; + ocb_aes_encrypt(ctx->ocb, ctx->ocb_client_nonce, + data, pos, + ha+4, ha+1); +#endif +#endif +#if 1 + CryptState_encrypt(&ctx->crypt, + data, (uint8_t *) foo, pos); +#endif + +#if 0 printf("\n"); printf("nonce: 0x"); print_hex(ctx->ocb_client_nonce, 16); @@ -97,8 +111,26 @@ do_udp_ping(struct cmumble_context *ctx) printf("foo: 0x"); print_hex(foo, pos+4); printf("\n"); + printf("foo decrypted: 0x"); + uint8_t lo[16], tag2[16]; + CryptState_ocb_decrypt(&ctx->crypt, (uint8_t *) foo+4, (uint8_t *) lo, pos, ctx->ocb_client_nonce, tag2); + print_hex(lo, pos); + printf("\n"); + printf("decrypted tag: 0x"); + print_hex(tag2, 3); + printf("\n"); + + printf("bar: 0x"); + print_hex(bar, pos+4); + printf("\n"); + printf("ha: 0x"); + print_hex(ha, pos+4); + printf("\n"); + + printf("length: %d\n", pos); //memset(tag, 0, 128); +#endif #if 0 ocb_aes_decrypt(ctx->ocb, ctx->ocb_client_nonce, @@ -110,11 +142,6 @@ do_udp_ping(struct cmumble_context *ctx) printf("\n"); #endif - foo[0] = ctx->ocb_client_nonce[0]; - foo[1] = tag[0]; - foo[2] = tag[1]; - foo[3] = tag[2]; - sent = g_socket_send(ctx->con.udp.sock, foo, pos+4, NULL, &error); g_print("udp sent: %ld\n", sent); @@ -132,7 +159,7 @@ cmumble_connection_udp_init(struct cmumble_context *ctx) &error); g_assert(error == NULL); - GInetAddress *addr = g_inet_address_new_from_string("192.168.2.232"); + GInetAddress *addr = g_inet_address_new_from_string("127.0.0.1"); g_assert(addr); GSocketAddress *saddr = g_inet_socket_address_new(addr, 64738); @@ -144,12 +171,6 @@ cmumble_connection_udp_init(struct cmumble_context *ctx) g_source_set_callback(ctx->con.udp.source, (GSourceFunc) read_udp, ctx, NULL); g_source_attach(ctx->con.udp.source, NULL); - int fd = g_socket_get_fd(ctx->con.udp.sock); - GIOChannel* channel = g_io_channel_unix_new(fd); - g_io_add_watch(channel, G_IO_IN, - (GIOFunc) read_udp_io, ctx); - g_io_channel_unref(channel); - do_udp_ping(ctx); } diff --git a/src/ocb/ocb.c b/src/ocb/ocb.c index 003eb5d..2583c08 100644 --- a/src/ocb/ocb.c +++ b/src/ocb/ocb.c @@ -269,7 +269,7 @@ ocb_aes_encrypt(keystruct *key, /* Initialized key struct */ memset(checksum, 0, 16); /* Zero the checksum */ /* Calculate R, aka Z[0] */ - xor_block(Offset, nonce, key->L); + xor_block(Offset, nonce, key->L); rijndaelEncrypt (key->rek, AES_ROUNDS, Offset, Offset); /* |