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 /src/connection.c | |
parent | b53fa04f47b54e08733ba3859bfaac171ab1c7af (diff) | |
download | cmumble-5838d820581221a4166f3e1df0b2608a6952359e.tar.gz cmumble-5838d820581221a4166f3e1df0b2608a6952359e.tar.bz2 cmumble-5838d820581221a4166f3e1df0b2608a6952359e.zip |
wip
Diffstat (limited to 'src/connection.c')
-rw-r--r-- | src/connection.c | 71 |
1 files changed, 46 insertions, 25 deletions
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); } |