summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testing/Makefile.inc21
-rw-r--r--testing/dns3_test.c51
-rw-r--r--testing/nToxAudio.h55
-rw-r--r--toxdns/toxdns.c33
-rw-r--r--toxdns/toxdns.h24
5 files changed, 107 insertions, 77 deletions
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
24 24
25noinst_PROGRAMS += DHT_test \ 25noinst_PROGRAMS += DHT_test \
26 Messenger_test \ 26 Messenger_test \
27 crypto_speed_test 27 crypto_speed_test \
28 dns3_test
28 29
29DHT_test_SOURCES = ../testing/DHT_test.c 30DHT_test_SOURCES = ../testing/DHT_test.c
30 31
@@ -71,6 +72,24 @@ crypto_speed_test_LDADD = \
71 $(NACL_LIBS) \ 72 $(NACL_LIBS) \
72 $(WINSOCK2_LIBS) 73 $(WINSOCK2_LIBS)
73 74
75
76dns3_test_SOURCES = \
77 ../testing/dns3_test.c
78
79dns3_test_CFLAGS = \
80 $(LIBSODIUM_CFLAGS) \
81 $(NACL_CFLAGS)
82
83dns3_test_LDADD = \
84 $(LIBSODIUM_LDFLAGS) \
85 $(NACL_LDFLAGS) \
86 libtoxdns.la \
87 libtoxcore.la \
88 $(LIBSODIUM_LIBS) \
89 $(NACL_OBJECTS) \
90 $(NACL_LIBS) \
91 $(WINSOCK2_LIBS)
92
74if !WIN32 93if !WIN32
75 94
76noinst_PROGRAMS += tox_sync 95noinst_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 @@
1
2
3#include "../toxdns/toxdns.h"
4#include "../toxcore/tox.h"
5#include "misc_tools.c"
6
7
8int main(int argc, char *argv[])
9{
10 if (argc < 4) {
11 printf("Usage: %s domain domain_public_key queried_username\nEX: %s utox.org D3154F65D28A5B41A05D4AC7E4B39C6B1C233CC857FB365C56E8392737462A12 username\n",
12 argv[0], argv[0]);
13 exit(0);
14 }
15
16 uint8_t string[1024] = {0};
17 void *d = tox_dns3_new(hex_string_to_bin(argv[2]));
18 unsigned int i;
19 uint32_t request_id;
20 /*
21 for (i = 0; i < 255; ++i) {
22 tox_generate_dns3_string(d, string, sizeof(string), &request_id, string, i);
23 printf("%s\n", string);
24 }*/
25 int len = tox_generate_dns3_string(d, string + 1, sizeof(string) - 1, &request_id, (uint8_t *)argv[3], strlen(argv[3]));
26
27 if (len == -1)
28 return -1;
29
30 string[0] = '_';
31 memcpy(string + len + 1, "._tox.", sizeof("._tox."));
32 memcpy((char *)(string + len + 1 + sizeof("._tox.") - 1), argv[1], strlen(argv[1]));
33 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",
34 string);
35
36 scanf("%s", string);
37 uint8_t tox_id[TOX_FRIEND_ADDRESS_SIZE];
38
39 if (tox_decrypt_dns3_TXT(d, tox_id, string, strlen((char *)string), request_id) != 0)
40 return -1;
41
42 printf("The Tox id for username %s is:\n", argv[3]);
43
44 //unsigned int i;
45 for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; ++i) {
46 printf("%02hhX", tox_id[i]);
47 }
48
49 printf("\n");
50 return 0;
51}
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 @@
1/* nTox.h
2 *
3 *Textual frontend for Tox.
4 *
5 * Copyright (C) 2013 Tox project All Rights Reserved.
6 *
7 * This file is part of Tox.
8 *
9 * Tox is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * Tox is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
24#ifndef NTOX_H
25#define NTOX_H
26
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30#include <ncurses.h>
31#include <curses.h>
32#include <ctype.h>
33#include <sys/socket.h>
34#include <netinet/in.h>
35#include <arpa/inet.h>
36#include <sys/types.h>
37#include <netdb.h>
38#include "../core/Messenger.h"
39#include "../core/network.h"
40
41#define STRING_LENGTH 256
42#define HISTORY 50
43#define PUB_KEY_BYTES 32
44
45void new_lines(char *line);
46void line_eval(char *line);
47void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) ;
48int count_lines(char *string) ;
49char *appender(char *str, const char c);
50void do_refresh();
51
52
53
54
55#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)
84 free(dns3_object); 84 free(dns3_object);
85} 85}
86 86
87/* Generate a dns3 string of string_max_len used to query the dns server reffered to by to 87/* Generate a dns3 string of string_max_len used to query the dns server referred to by to
88 * dns3_object for a tox id registered to user with name of name_len. 88 * dns3_object for a tox id registered to user with name of name_len.
89 * 89 *
90 * the uint32_t pointed by request_id will be set to the request id which must be passed to
91 * tox_decrypt_dns3_TXT() to correctly decode the response.
92 *
90 * This is what the string returned looks like: 93 * This is what the string returned looks like:
91 * 4haaaaipr1o3mz0bxweox541airydbovqlbju51mb4p0ebxq.rlqdj4kkisbep2ks3fj2nvtmk4daduqiueabmexqva1jc 94 * 4haaaaipr1o3mz0bxweox541airydbovqlbju51mb4p0ebxq.rlqdj4kkisbep2ks3fj2nvtmk4daduqiueabmexqva1jc
92 * 95 *
93 * returns length of string on sucess. 96 * returns length of string on sucess.
94 * returns -1 on failure. 97 * returns -1 on failure.
95 */ 98 */
96int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string_max_len, uint8_t *name, 99int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string_max_len, uint32_t *request_id,
97 uint8_t name_len) 100 uint8_t *name, uint8_t name_len)
98{ 101{
99#define DOT_INTERVAL (6 * 5) 102#define DOT_INTERVAL (6 * 5)
100 int base = (sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES + name_len + crypto_box_MACBYTES); 103 int base = (sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES + name_len + crypto_box_MACBYTES);
101 int end_len = ((base * 8) / 5) + (base / DOT_INTERVAL) + !!(base % 5); 104 int end_len = ((base * 8) / 5) + (base / DOT_INTERVAL) + !!(base % 5);
105 end_len -= !(base % DOT_INTERVAL);
102 106
103 if (end_len > string_max_len) 107 if (end_len > string_max_len)
104 return -1; 108 return -1;
@@ -121,14 +125,16 @@ int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string
121 uint8_t bits = 0; 125 uint8_t bits = 0;
122 int i; 126 int i;
123 127
124 for (i = 0; i < (total_len / DOT_INTERVAL); ++i) { 128 for (i = !(total_len % DOT_INTERVAL); i < (total_len / DOT_INTERVAL); ++i) {
125 _encode(string, buff, DOT_INTERVAL); 129 _encode(string, buff, DOT_INTERVAL);
126 *string = '.'; 130 *string = '.';
127 ++string; 131 ++string;
128 } 132 }
129 133
130 _encode(string, buff, total_len % DOT_INTERVAL); 134 int left = total_len - (buff - buffer);
135 _encode(string, buff, left);
131#undef DOT_INTERVAL 136#undef DOT_INTERVAL
137 *request_id = d->nonce;
132 ++d->nonce; 138 ++d->nonce;
133 139
134 if (d->nonce == d->nonce_start) { 140 if (d->nonce == d->nonce_start) {
@@ -136,7 +142,7 @@ int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string
136 } 142 }
137 143
138 if (end_len != string - old_str) { 144 if (end_len != string - old_str) {
139 printf("tox_generate_dns3_string Fail\n"); 145 printf("tox_generate_dns3_string Fail, %u != %u\n", end_len, string - old_str);
140 return -1; 146 return -1;
141 } 147 }
142 148
@@ -189,18 +195,21 @@ static int decode(uint8_t *dest, uint8_t *src)
189/* Decode and decrypt the id_record returned of length id_record_len into 195/* Decode and decrypt the id_record returned of length id_record_len into
190 * tox_id (needs to be at least TOX_FRIEND_ADDRESS_SIZE). 196 * tox_id (needs to be at least TOX_FRIEND_ADDRESS_SIZE).
191 * 197 *
198 * request_id is the request id given by tox_generate_dns3_string() when creating the request.
199 *
192 * the id_record passed to this function should look somewhat like this: 200 * the id_record passed to this function should look somewhat like this:
193 * 4haaaa2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp 201 * 2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp
194 * 202 *
195 * returns -1 on failure. 203 * returns -1 on failure.
196 * returns 0 on success. 204 * returns 0 on success.
197 * 205 *
198 */ 206 */
199int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record, uint32_t id_record_len) 207int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record, uint32_t id_record_len,
208 uint32_t request_id)
200{ 209{
201 DNS_Object *d = dns3_object; 210 DNS_Object *d = dns3_object;
202 211
203 if (id_record_len != 93) 212 if (id_record_len != 87)
204 return -1; 213 return -1;
205 214
206 /*if (id_record_len > 255 || id_record_len <= (sizeof(uint32_t) + crypto_box_MACBYTES)) 215 /*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,
213 return -1; 222 return -1;
214 223
215 uint8_t nonce[crypto_box_NONCEBYTES] = {0}; 224 uint8_t nonce[crypto_box_NONCEBYTES] = {0};
216 memcpy(nonce, data, sizeof(uint32_t)); 225 memcpy(nonce, &request_id, sizeof(uint32_t));
217 nonce[sizeof(uint32_t)] = 1; 226 nonce[sizeof(uint32_t)] = 1;
218 int len = decrypt_data_symmetric(d->shared_key, nonce, data + sizeof(uint32_t), length - sizeof(uint32_t), tox_id); 227 int len = decrypt_data_symmetric(d->shared_key, nonce, data, length, tox_id);
219 228
220 if (len != FRIEND_ADDRESS_SIZE) 229 if (len != FRIEND_ADDRESS_SIZE)
221 return -1; 230 return -1;
222 231
223 return 0; 232 return 0;
224} \ No newline at end of file 233}
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 @@
2 * 2 *
3 * Tox secure username DNS toxid resolving functions. 3 * Tox secure username DNS toxid resolving functions.
4 * 4 *
5 * Copyright (C) 2013 Tox project All Rights Reserved. 5 * Copyright (C) 2014 Tox project All Rights Reserved.
6 * 6 *
7 * This file is part of Tox. 7 * This file is part of Tox.
8 * 8 *
@@ -33,10 +33,10 @@
33 * and handle responses for that server. 33 * and handle responses for that server.
34 * 3. Use tox_generate_dns3_string() to generate a string based on the name we want to query. 34 * 3. Use tox_generate_dns3_string() to generate a string based on the name we want to query.
35 * 4. take the string and use it for your DNS request like this: 35 * 4. take the string and use it for your DNS request like this:
36 * _4haaaaipr1o3mz0bxweox541airydbovqlbju51mb4p0ebxq.rlqdj4kkisbep2ks3fj2nvtmk4daduqiueabmexqva1jc_._tox.utox.org 36 * _4haaaaipr1o3mz0bxweox541airydbovqlbju51mb4p0ebxq.rlqdj4kkisbep2ks3fj2nvtmk4daduqiueabmexqva1jc._tox.utox.org
37 * 37 *
38 * 5. The TXT in the DNS you recieve should look like this: 38 * 5. The TXT in the DNS you receive should look like this:
39 * v=tox3;id=4haaaa2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp 39 * v=tox3;id=2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp
40 * 6. Take the id string and use it with tox_decrypt_dns3_TXT() to get the Tox id returned by the DNS server. 40 * 6. Take the id string and use it with tox_decrypt_dns3_TXT() to get the Tox id returned by the DNS server.
41 */ 41 */
42 42
@@ -51,28 +51,34 @@ void *tox_dns3_new(uint8_t *server_public_key);
51 */ 51 */
52void tox_dns3_kill(void *dns3_object); 52void tox_dns3_kill(void *dns3_object);
53 53
54/* Generate a dns3 string of string_max_len used to query the dns server reffered to by to 54/* Generate a dns3 string of string_max_len used to query the dns server referred to by to
55 * dns3_object for a tox id registered to user with name of name_len. 55 * dns3_object for a tox id registered to user with name of name_len.
56 * 56 *
57 * the uint32_t pointed by request_id will be set to the request id which must be passed to
58 * tox_decrypt_dns3_TXT() to correctly decode the response.
59 *
57 * This is what the string returned looks like: 60 * This is what the string returned looks like:
58 * 4haaaaipr1o3mz0bxweox541airydbovqlbju51mb4p0ebxq.rlqdj4kkisbep2ks3fj2nvtmk4daduqiueabmexqva1jc 61 * 4haaaaipr1o3mz0bxweox541airydbovqlbju51mb4p0ebxq.rlqdj4kkisbep2ks3fj2nvtmk4daduqiueabmexqva1jc
59 * 62 *
60 * returns length of string on sucess. 63 * returns length of string on sucess.
61 * returns -1 on failure. 64 * returns -1 on failure.
62 */ 65 */
63int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string_max_len, uint8_t *name, 66int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string_max_len, uint32_t *request_id,
64 uint8_t name_len); 67 uint8_t *name, uint8_t name_len);
65 68
66/* Decode and decrypt the id_record returned of length id_record_len into 69/* Decode and decrypt the id_record returned of length id_record_len into
67 * tox_id (needs to be at least TOX_FRIEND_ADDRESS_SIZE). 70 * tox_id (needs to be at least TOX_FRIEND_ADDRESS_SIZE).
68 * 71 *
72 * request_id is the request id given by tox_generate_dns3_string() when creating the request.
73 *
69 * the id_record passed to this function should look somewhat like this: 74 * the id_record passed to this function should look somewhat like this:
70 * 4haaaa2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp 75 * 2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp
71 * 76 *
72 * returns -1 on failure. 77 * returns -1 on failure.
73 * returns 0 on success. 78 * returns 0 on success.
74 * 79 *
75 */ 80 */
76int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record, uint32_t id_record_len); 81int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record, uint32_t id_record_len,
82 uint32_t request_id);
77 83
78#endif 84#endif