From 2857e6af8f8d5af82eb1b8cb3ae9142a34f58aae Mon Sep 17 00:00:00 2001 From: irungentoo Date: Tue, 13 Aug 2013 09:32:31 -0400 Subject: [PATCH] Fixed spam problem. (I broke the API so this will not build) The friend address is what the byte string that you give away for people to add you will be called. 1. Every friend address now contains a number set by the friend. This is to prevent someone from randomly spamming people in the DHT with friend requests and makes it so you need the person to actually give you the address in some way to send the friend request. This number is expected to be encrypted with the friend request. All requests that do not contain this number will be rejected. This means the spammer can no longer use the DHT to collect lists of valid addresses to spam. It also enables users to quickly change the number in case a spammer gets hold of the address and starts spamming it. 2. A 2 byte checksum will be added (not implemented yet) to prevent people from accidentally adding random strings as friends. (NOTE that this has nothing to do with the spam problem I just decided to add a placeholder for it now.) --- chat.c | 8 +++++--- prompt.c | 14 ++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/chat.c b/chat.c index 35be3bd..1b5e743 100644 --- a/chat.c +++ b/chat.c @@ -307,11 +307,13 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd) } else if (!strcmp(cmd, "/myid")) { - char id[KEY_SIZE_BYTES*2+1] = {0}; + char id[FRIEND_ADDRESS_SIZE*2+1] = {0}; int i; - for (i = 0; i < KEY_SIZE_BYTES; i++) { + uint8_t address[FRIEND_ADDRESS_SIZE]; + getaddress(m, address); + for (i = 0; i < FRIEND_ADDRESS_SIZE; i++) { char xx[3]; - snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff); + snprintf(xx, sizeof(xx), "%02X", address[i] & 0xff); strcat(id, xx); } wprintw(ctx->history, "Your ID: %s\n", id); diff --git a/prompt.c b/prompt.c index 67f80fe..e1a7d75 100644 --- a/prompt.c +++ b/prompt.c @@ -93,7 +93,7 @@ void cmd_accept(ToxWindow *self, Messenger *m, char **args) void cmd_add(ToxWindow *self, Messenger *m, char **args) { - uint8_t id_bin[KEY_SIZE_BYTES]; + uint8_t id_bin[FRIEND_ADDRESS_SIZE]; char xx[3]; uint32_t x; char *id = args[1]; @@ -106,12 +106,12 @@ void cmd_add(ToxWindow *self, Messenger *m, char **args) if (!msg) msg = ""; - if (strlen(id) != 2*KEY_SIZE_BYTES) { + if (strlen(id) != 2*FRIEND_ADDRESS_SIZE) { wprintw(self->window, "Invalid ID length.\n"); return; } int i; - for (i = 0; i < KEY_SIZE_BYTES; ++i) { + for (i = 0; i < FRIEND_ADDRESS_SIZE; ++i) { xx[0] = id[2*i]; xx[1] = id[2*i+1]; xx[2] = '\0'; @@ -217,11 +217,13 @@ void cmd_msg(ToxWindow *self, Messenger *m, char **args) void cmd_myid(ToxWindow *self, Messenger *m, char **args) { - char id[KEY_SIZE_BYTES*2 + 1] = {0}; + char id[FRIEND_ADDRESS_SIZE*2 + 1] = {0}; size_t i; - for (i = 0; i < KEY_SIZE_BYTES; ++i) { + uint8_t address[FRIEND_ADDRESS_SIZE]; + getaddress(m, address); + for (i = 0; i < FRIEND_ADDRESS_SIZE; ++i) { char xx[3]; - snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff); + snprintf(xx, sizeof(xx), "%02X", address[i] & 0xff); strcat(id, xx); } wprintw(self->window, "Your ID: %s\n", id);