summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2017-12-29 00:29:14 +0000
committeriphydf <iphydf@users.noreply.github.com>2017-12-29 00:32:18 +0000
commit2c8fb05f6e1631403053ef8648d5860e0ec15cc3 (patch)
tree82dd81e89f1785126067c38ffedb7060d1835aef /testing
parentf2b6090eca42f4a364ef7517c5eec6d472e9b5f6 (diff)
Remove deprecated ToxDNS
Based on #331. Fixes #42.
Diffstat (limited to 'testing')
-rw-r--r--testing/Makefile.inc20
-rw-r--r--testing/dns3_test.c106
2 files changed, 1 insertions, 125 deletions
diff --git a/testing/Makefile.inc b/testing/Makefile.inc
index fda99a89..8f24b44f 100644
--- a/testing/Makefile.inc
+++ b/testing/Makefile.inc
@@ -23,8 +23,7 @@ endif
23if BUILD_TESTING 23if BUILD_TESTING
24 24
25noinst_PROGRAMS += DHT_test \ 25noinst_PROGRAMS += DHT_test \
26 Messenger_test \ 26 Messenger_test
27 dns3_test
28 27
29DHT_test_SOURCES = ../testing/DHT_test.c 28DHT_test_SOURCES = ../testing/DHT_test.c
30 29
@@ -56,23 +55,6 @@ Messenger_test_LDADD = $(LIBSODIUM_LDFLAGS) \
56 55
57 56
58 57
59dns3_test_SOURCES = \
60 ../testing/dns3_test.c
61
62dns3_test_CFLAGS = \
63 $(LIBSODIUM_CFLAGS) \
64 $(NACL_CFLAGS)
65
66dns3_test_LDADD = \
67 $(LIBSODIUM_LDFLAGS) \
68 $(NACL_LDFLAGS) \
69 libtoxdns.la \
70 libtoxcore.la \
71 $(LIBSODIUM_LIBS) \
72 $(NACL_OBJECTS) \
73 $(NACL_LIBS) \
74 $(WINSOCK2_LIBS)
75
76if !WIN32 58if !WIN32
77 59
78noinst_PROGRAMS += tox_sync 60noinst_PROGRAMS += tox_sync
diff --git a/testing/dns3_test.c b/testing/dns3_test.c
deleted file mode 100644
index 0df7ace2..00000000
--- a/testing/dns3_test.c
+++ /dev/null
@@ -1,106 +0,0 @@
1#include "../toxcore/network.h"
2#include "../toxcore/tox.h"
3#include "../toxdns/toxdns.h"
4#include "misc_tools.c"
5
6static uint32_t create_packet(uint8_t *packet, uint8_t *string, uint8_t str_len, uint8_t id)
7{
8 memset(packet, 0, str_len + 13 + 16);
9 packet[0] = id;
10 packet[1] = rand();
11 packet[5] = 1;
12 packet[11] = 1;
13 packet[12] = '.';
14 memcpy(packet + 13, string, str_len);
15 uint32_t i, c = 0;
16
17 for (i = str_len + 12; i != 11; --i) {
18 if (packet[i] == '.') {
19 packet[i] = c;
20 c = 0;
21 } else {
22 ++c;
23 }
24 }
25
26 packet[str_len + 13 + 2] = 16;
27 packet[str_len + 13 + 4] = 1;
28 packet[str_len + 13 + 7] = 0x29;
29 packet[str_len + 13 + 8] = 16;
30 packet[str_len + 13 + 12] = 0x80;
31 return str_len + 13 + 16;
32}
33
34int main(int argc, char *argv[])
35{
36 if (argc < 4) {
37 printf("Usage: %s domain domain_public_key queried_username\nEX: %s utox.org D3154F65D28A5B41A05D4AC7E4B39C6B1C233CC857FB365C56E8392737462A12 username\n",
38 argv[0], argv[0]);
39 exit(0);
40 }
41
42 IP ip = {0};
43 ip.family = TOX_AF_INET;
44 Socket sock = net_socket(ip.family, TOX_SOCK_DGRAM, TOX_PROTO_UDP);
45
46 if (!sock_valid(sock)) {
47 return -1;
48 }
49
50 if (!addr_resolve_or_parse_ip(argv[1], &ip, 0)) {
51 return -1;
52 }
53
54 uint32_t request_id;
55 uint8_t string[1024] = {0};
56 void *d = tox_dns3_new(hex_string_to_bin(argv[2]));
57 int len = tox_generate_dns3_string(d, string + 1, sizeof(string) - 1, &request_id, (uint8_t *)argv[3], strlen(argv[3]));
58
59 if (len == -1) {
60 return -1;
61 }
62
63 string[0] = '_';
64 memcpy(string + len + 1, "._tox.", sizeof("._tox."));
65 memcpy((char *)(string + len + 1 + sizeof("._tox.") - 1), argv[1], strlen(argv[1]));
66 uint8_t packet[512];
67 uint8_t id = rand();
68 uint32_t p_len = create_packet(packet, string, strlen((char *)string), id);
69
70 IP_Port ip_port;
71 ip_port.port = 53;
72 ip_port.ip = ip;
73
74 if (net_sendto_ip4(sock, (char *)packet, p_len, ip_port) != p_len) {
75 return -1;
76 }
77
78 uint8_t buffer[512] = {0};
79 int r_len = recv(sock, (char *)buffer, sizeof(buffer), 0);
80
81 if (r_len < (int)p_len) {
82 return -1;
83 }
84
85 unsigned int i;
86
87 for (i = r_len - 1; i != 0 && buffer[i] != '='; --i) {
88 ;
89 }
90
91 uint8_t tox_id[TOX_ADDRESS_SIZE];
92
93 if (tox_decrypt_dns3_TXT(d, tox_id, buffer + i + 1, r_len - (i + 1), request_id) != 0) {
94 return -1;
95 }
96
97 printf("The Tox id for username %s is:\n", argv[3]);
98
99 //unsigned int i;
100 for (i = 0; i < TOX_ADDRESS_SIZE; ++i) {
101 printf("%02hhX", tox_id[i]);
102 }
103
104 printf("\n");
105 return 0;
106}