diff --git a/testing/Makefile.inc b/testing/Makefile.inc index 2142b4ca..d29c5d55 100644 --- a/testing/Makefile.inc +++ b/testing/Makefile.inc @@ -24,7 +24,8 @@ if BUILD_TESTING noinst_PROGRAMS += DHT_test \ Messenger_test \ - crypto_speed_test + crypto_speed_test \ + dns3_test DHT_test_SOURCES = ../testing/DHT_test.c @@ -71,6 +72,24 @@ crypto_speed_test_LDADD = \ $(NACL_LIBS) \ $(WINSOCK2_LIBS) + +dns3_test_SOURCES = \ + ../testing/dns3_test.c + +dns3_test_CFLAGS = \ + $(LIBSODIUM_CFLAGS) \ + $(NACL_CFLAGS) + +dns3_test_LDADD = \ + $(LIBSODIUM_LDFLAGS) \ + $(NACL_LDFLAGS) \ + libtoxdns.la \ + libtoxcore.la \ + $(LIBSODIUM_LIBS) \ + $(NACL_OBJECTS) \ + $(NACL_LIBS) \ + $(WINSOCK2_LIBS) + if !WIN32 noinst_PROGRAMS += tox_sync diff --git a/testing/dns3_test.c b/testing/dns3_test.c new file mode 100644 index 00000000..69649f50 --- /dev/null +++ b/testing/dns3_test.c @@ -0,0 +1,51 @@ + + +#include "../toxdns/toxdns.h" +#include "../toxcore/tox.h" +#include "misc_tools.c" + + +int main(int argc, char *argv[]) +{ + if (argc < 4) { + printf("Usage: %s domain domain_public_key queried_username\nEX: %s utox.org D3154F65D28A5B41A05D4AC7E4B39C6B1C233CC857FB365C56E8392737462A12 username\n", + argv[0], argv[0]); + exit(0); + } + + uint8_t string[1024] = {0}; + void *d = tox_dns3_new(hex_string_to_bin(argv[2])); + unsigned int i; + uint32_t request_id; + /* + for (i = 0; i < 255; ++i) { + tox_generate_dns3_string(d, string, sizeof(string), &request_id, string, i); + printf("%s\n", string); + }*/ + int len = tox_generate_dns3_string(d, string + 1, sizeof(string) - 1, &request_id, (uint8_t *)argv[3], strlen(argv[3])); + + if (len == -1) + return -1; + + string[0] = '_'; + memcpy(string + len + 1, "._tox.", sizeof("._tox.")); + memcpy((char *)(string + len + 1 + sizeof("._tox.") - 1), argv[1], strlen(argv[1])); + printf("Do a DNS request and find the TXT record for:\n%s\nThen paste the contents of the data contained in the id field here:\n", + string); + + scanf("%s", string); + uint8_t tox_id[TOX_FRIEND_ADDRESS_SIZE]; + + if (tox_decrypt_dns3_TXT(d, tox_id, string, strlen((char *)string), request_id) != 0) + return -1; + + printf("The Tox id for username %s is:\n", argv[3]); + + //unsigned int i; + for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; ++i) { + printf("%02hhX", tox_id[i]); + } + + printf("\n"); + return 0; +} diff --git a/testing/nToxAudio.h b/testing/nToxAudio.h deleted file mode 100644 index 19b31f8b..00000000 --- a/testing/nToxAudio.h +++ /dev/null @@ -1,55 +0,0 @@ -/* nTox.h - * - *Textual frontend for Tox. - * - * Copyright (C) 2013 Tox project All Rights Reserved. - * - * This file is part of Tox. - * - * Tox is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Tox is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Tox. If not, see . - * - */ - -#ifndef NTOX_H -#define NTOX_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../core/Messenger.h" -#include "../core/network.h" - -#define STRING_LENGTH 256 -#define HISTORY 50 -#define PUB_KEY_BYTES 32 - -void new_lines(char *line); -void line_eval(char *line); -void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) ; -int count_lines(char *string) ; -char *appender(char *str, const char c); -void do_refresh(); - - - - -#endif diff --git a/toxdns/toxdns.c b/toxdns/toxdns.c index 20a4486c..31269c15 100644 --- a/toxdns/toxdns.c +++ b/toxdns/toxdns.c @@ -84,21 +84,25 @@ void tox_dns3_kill(void *dns3_object) free(dns3_object); } -/* Generate a dns3 string of string_max_len used to query the dns server reffered to by to +/* Generate a dns3 string of string_max_len used to query the dns server referred to by to * dns3_object for a tox id registered to user with name of name_len. * + * the uint32_t pointed by request_id will be set to the request id which must be passed to + * tox_decrypt_dns3_TXT() to correctly decode the response. + * * This is what the string returned looks like: * 4haaaaipr1o3mz0bxweox541airydbovqlbju51mb4p0ebxq.rlqdj4kkisbep2ks3fj2nvtmk4daduqiueabmexqva1jc * * returns length of string on sucess. * returns -1 on failure. */ -int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string_max_len, uint8_t *name, - uint8_t name_len) +int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string_max_len, uint32_t *request_id, + uint8_t *name, uint8_t name_len) { #define DOT_INTERVAL (6 * 5) int base = (sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES + name_len + crypto_box_MACBYTES); int end_len = ((base * 8) / 5) + (base / DOT_INTERVAL) + !!(base % 5); + end_len -= !(base % DOT_INTERVAL); if (end_len > string_max_len) return -1; @@ -121,14 +125,16 @@ int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string uint8_t bits = 0; int i; - for (i = 0; i < (total_len / DOT_INTERVAL); ++i) { + for (i = !(total_len % DOT_INTERVAL); i < (total_len / DOT_INTERVAL); ++i) { _encode(string, buff, DOT_INTERVAL); *string = '.'; ++string; } - _encode(string, buff, total_len % DOT_INTERVAL); + int left = total_len - (buff - buffer); + _encode(string, buff, left); #undef DOT_INTERVAL + *request_id = d->nonce; ++d->nonce; if (d->nonce == d->nonce_start) { @@ -136,7 +142,7 @@ int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string } if (end_len != string - old_str) { - printf("tox_generate_dns3_string Fail\n"); + printf("tox_generate_dns3_string Fail, %u != %u\n", end_len, string - old_str); return -1; } @@ -189,18 +195,21 @@ static int decode(uint8_t *dest, uint8_t *src) /* Decode and decrypt the id_record returned of length id_record_len into * tox_id (needs to be at least TOX_FRIEND_ADDRESS_SIZE). * + * request_id is the request id given by tox_generate_dns3_string() when creating the request. + * * the id_record passed to this function should look somewhat like this: - * 4haaaa2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp + * 2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp * * returns -1 on failure. * returns 0 on success. * */ -int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record, uint32_t id_record_len) +int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record, uint32_t id_record_len, + uint32_t request_id) { DNS_Object *d = dns3_object; - if (id_record_len != 93) + if (id_record_len != 87) return -1; /*if (id_record_len > 255 || id_record_len <= (sizeof(uint32_t) + crypto_box_MACBYTES)) @@ -213,12 +222,12 @@ int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record, return -1; uint8_t nonce[crypto_box_NONCEBYTES] = {0}; - memcpy(nonce, data, sizeof(uint32_t)); + memcpy(nonce, &request_id, sizeof(uint32_t)); nonce[sizeof(uint32_t)] = 1; - int len = decrypt_data_symmetric(d->shared_key, nonce, data + sizeof(uint32_t), length - sizeof(uint32_t), tox_id); + int len = decrypt_data_symmetric(d->shared_key, nonce, data, length, tox_id); if (len != FRIEND_ADDRESS_SIZE) return -1; return 0; -} \ No newline at end of file +} diff --git a/toxdns/toxdns.h b/toxdns/toxdns.h index ac84af9c..173c8b2f 100644 --- a/toxdns/toxdns.h +++ b/toxdns/toxdns.h @@ -2,7 +2,7 @@ * * Tox secure username DNS toxid resolving functions. * - * Copyright (C) 2013 Tox project All Rights Reserved. + * Copyright (C) 2014 Tox project All Rights Reserved. * * This file is part of Tox. * @@ -33,10 +33,10 @@ * and handle responses for that server. * 3. Use tox_generate_dns3_string() to generate a string based on the name we want to query. * 4. take the string and use it for your DNS request like this: - * _4haaaaipr1o3mz0bxweox541airydbovqlbju51mb4p0ebxq.rlqdj4kkisbep2ks3fj2nvtmk4daduqiueabmexqva1jc_._tox.utox.org + * _4haaaaipr1o3mz0bxweox541airydbovqlbju51mb4p0ebxq.rlqdj4kkisbep2ks3fj2nvtmk4daduqiueabmexqva1jc._tox.utox.org * - * 5. The TXT in the DNS you recieve should look like this: - * v=tox3;id=4haaaa2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp + * 5. The TXT in the DNS you receive should look like this: + * v=tox3;id=2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp * 6. Take the id string and use it with tox_decrypt_dns3_TXT() to get the Tox id returned by the DNS server. */ @@ -51,28 +51,34 @@ void *tox_dns3_new(uint8_t *server_public_key); */ void tox_dns3_kill(void *dns3_object); -/* Generate a dns3 string of string_max_len used to query the dns server reffered to by to +/* Generate a dns3 string of string_max_len used to query the dns server referred to by to * dns3_object for a tox id registered to user with name of name_len. * + * the uint32_t pointed by request_id will be set to the request id which must be passed to + * tox_decrypt_dns3_TXT() to correctly decode the response. + * * This is what the string returned looks like: * 4haaaaipr1o3mz0bxweox541airydbovqlbju51mb4p0ebxq.rlqdj4kkisbep2ks3fj2nvtmk4daduqiueabmexqva1jc * * returns length of string on sucess. * returns -1 on failure. */ -int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string_max_len, uint8_t *name, - uint8_t name_len); +int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string_max_len, uint32_t *request_id, + uint8_t *name, uint8_t name_len); /* Decode and decrypt the id_record returned of length id_record_len into * tox_id (needs to be at least TOX_FRIEND_ADDRESS_SIZE). * + * request_id is the request id given by tox_generate_dns3_string() when creating the request. + * * the id_record passed to this function should look somewhat like this: - * 4haaaa2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp + * 2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp * * returns -1 on failure. * returns 0 on success. * */ -int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record, uint32_t id_record_len); +int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record, uint32_t id_record_len, + uint32_t request_id); #endif