summaryrefslogtreecommitdiff
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
parentf2b6090eca42f4a364ef7517c5eec6d472e9b5f6 (diff)
Remove deprecated ToxDNS
Based on #331. Fixes #42.
-rw-r--r--CMakeLists.txt18
-rw-r--r--INSTALL.md2
-rw-r--r--build/Makefile.am1
-rw-r--r--libtoxcore.pc.in2
-rw-r--r--other/astyle/README.md2
-rw-r--r--testing/Makefile.inc20
-rw-r--r--testing/dns3_test.c106
-rw-r--r--toxcore/network.c14
-rw-r--r--toxcore/network.h2
-rw-r--r--toxdns/Makefile.inc35
-rw-r--r--toxdns/toxdns.c243
-rw-r--r--toxdns/toxdns.h96
12 files changed, 8 insertions, 533 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f794982f..2ee15b95 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,11 +6,11 @@
6# - A number of small libraries (.a/.so/...) containing independent components 6# - A number of small libraries (.a/.so/...) containing independent components
7# of toxcore. E.g. the DHT has its own library, and the system/network 7# of toxcore. E.g. the DHT has its own library, and the system/network
8# abstractions are in their own library as well. These libraries are not 8# abstractions are in their own library as well. These libraries are not
9# installed on `make install`. The toxdns, toxav, and toxencryptsave 9# installed on `make install`. The toxav, and toxencryptsave libraries are
10# libraries are also not installed. 10# also not installed.
11# - A number of small programs, statically linked if possible. 11# - A number of small programs, statically linked if possible.
12# - One big library containing all of the toxcore, toxav, toxdns, and 12# - One big library containing all of the toxcore, toxav, and toxencryptsave
13# toxencryptsave code. 13# code.
14# 14#
15################################################################################ 15################################################################################
16 16
@@ -328,15 +328,10 @@ endif()
328 328
329################################################################################ 329################################################################################
330# 330#
331# :: ToxDNS and block encryption libraries 331# :: Block encryption libraries
332# 332#
333################################################################################ 333################################################################################
334 334
335add_submodule(toxcore toxdns
336 toxdns/toxdns.c)
337target_link_modules(toxdns toxnetwork)
338set(toxdns_API_HEADERS ${toxcore_SOURCE_DIR}/toxdns/toxdns.h^tox)
339
340apidsl(toxencryptsave/toxencryptsave.api.h) 335apidsl(toxencryptsave/toxencryptsave.api.h)
341add_submodule(toxcore toxencryptsave 336add_submodule(toxcore toxencryptsave
342 toxencryptsave/toxencryptsave.c 337 toxencryptsave/toxencryptsave.c
@@ -570,9 +565,6 @@ target_link_modules(DHT_test toxdht)
570add_c_executable(Messenger_test testing/Messenger_test.c) 565add_c_executable(Messenger_test testing/Messenger_test.c)
571target_link_modules(Messenger_test toxmessenger) 566target_link_modules(Messenger_test toxmessenger)
572 567
573add_c_executable(dns3_test testing/dns3_test.c)
574target_link_modules(dns3_test toxdns)
575
576if(NOT WIN32) 568if(NOT WIN32)
577 add_c_executable(tox_sync testing/tox_sync.c) 569 add_c_executable(tox_sync testing/tox_sync.c)
578 target_link_modules(tox_sync toxcore) 570 target_link_modules(tox_sync toxcore)
diff --git a/INSTALL.md b/INSTALL.md
index 78cfa830..818edf06 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -243,7 +243,6 @@ If it worked, you should have all the toxcore dylibs in /usr/local/lib: (besides
243$ ls -la /usr/local/lib/libtox*.dylib 243$ ls -la /usr/local/lib/libtox*.dylib
244libtoxav.0.dylib 244libtoxav.0.dylib
245libtoxcore.0.dylib 245libtoxcore.0.dylib
246libtoxdns.0.dylib
247libtoxencryptsave.0.dylib 246libtoxencryptsave.0.dylib
248to check what CPU architecture they're compiled for: 247to check what CPU architecture they're compiled for:
249$ lipo -i /usr/local/lib/libtoxencryptsave.0.dylib 248$ lipo -i /usr/local/lib/libtoxencryptsave.0.dylib
@@ -414,7 +413,6 @@ mkdir tmp
414cd tmp 413cd tmp
415$WINDOWS_TOOLCHAIN-ar x ../lib/libtoxcore.a 414$WINDOWS_TOOLCHAIN-ar x ../lib/libtoxcore.a
416$WINDOWS_TOOLCHAIN-ar x ../lib/libtoxav.a 415$WINDOWS_TOOLCHAIN-ar x ../lib/libtoxav.a
417$WINDOWS_TOOLCHAIN-ar x ../lib/libtoxdns.a
418$WINDOWS_TOOLCHAIN-ar x ../lib/libtoxencryptsave.a 416$WINDOWS_TOOLCHAIN-ar x ../lib/libtoxencryptsave.a
419$WINDOWS_TOOLCHAIN-gcc -Wl,--export-all-symbols -Wl,--out-implib=libtox.dll.a -shared -o libtox.dll *.o ../lib/*.a /usr/$WINDOWS_TOOLCHAIN/lib/libwinpthread.a -liphlpapi -lws2_32 -static-libgcc 417$WINDOWS_TOOLCHAIN-gcc -Wl,--export-all-symbols -Wl,--out-implib=libtox.dll.a -shared -o libtox.dll *.o ../lib/*.a /usr/$WINDOWS_TOOLCHAIN/lib/libwinpthread.a -liphlpapi -lws2_32 -static-libgcc
420``` 418```
diff --git a/build/Makefile.am b/build/Makefile.am
index e4f36509..c5c170a3 100644
--- a/build/Makefile.am
+++ b/build/Makefile.am
@@ -17,7 +17,6 @@ LT_LDFLAGS=-avoid-version
17endif 17endif
18 18
19include ../toxcore/Makefile.inc 19include ../toxcore/Makefile.inc
20include ../toxdns/Makefile.inc
21include ../toxencryptsave/Makefile.inc 20include ../toxencryptsave/Makefile.inc
22include ../toxav/Makefile.inc 21include ../toxav/Makefile.inc
23include ../other/Makefile.inc 22include ../other/Makefile.inc
diff --git a/libtoxcore.pc.in b/libtoxcore.pc.in
index 90bb6c28..d9d7fb79 100644
--- a/libtoxcore.pc.in
+++ b/libtoxcore.pc.in
@@ -7,5 +7,5 @@ Name: libtoxcore
7Description: Tox protocol library 7Description: Tox protocol library
8Requires: 8Requires:
9Version: @PACKAGE_VERSION@ 9Version: @PACKAGE_VERSION@
10Libs: @NACL_OBJECTS_PKGCONFIG@ -L${libdir} -ltoxcore @NACL_LDFLAGS@ -ltoxdns -ltoxencryptsave @NACL_LIBS@ @LIBS@ @MATH_LDFLAGS@ @PTHREAD_LDFLAGS@ 10Libs: @NACL_OBJECTS_PKGCONFIG@ -L${libdir} -ltoxcore @NACL_LDFLAGS@ -ltoxencryptsave @NACL_LIBS@ @LIBS@ @MATH_LDFLAGS@ @PTHREAD_LDFLAGS@
11Cflags: -I${includedir} 11Cflags: -I${includedir}
diff --git a/other/astyle/README.md b/other/astyle/README.md
index 9ce34b8e..e86cc40f 100644
--- a/other/astyle/README.md
+++ b/other/astyle/README.md
@@ -8,7 +8,7 @@ This directory can house various tools and utilities.
8 8
9Run from ``toxcore`` directory: 9Run from ``toxcore`` directory:
10```bash 10```bash
11astyle --options=./other/astyle/astylerc ./toxcore/*.c ./toxcore/*.h ./toxdns/*.c ./toxdns/*.h ./testing/*.c ./toxav/*.c ./toxav/*.h ./other/*.c ./other/bootstrap_daemon/*.c ./toxencryptsave/*.c ./toxencryptsave/*.h ./auto_tests/*.c 11astyle --options=./other/astyle/astylerc ./toxcore/*.c ./toxcore/*.h ./testing/*.c ./toxav/*.c ./toxav/*.h ./other/*.c ./other/bootstrap_daemon/*.c ./toxencryptsave/*.c ./toxencryptsave/*.h ./auto_tests/*.c
12``` 12```
13 13
14### For selected file 14### For selected file
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}
diff --git a/toxcore/network.c b/toxcore/network.c
index 5c43bf57..7587826b 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -1411,20 +1411,6 @@ Socket net_socket(int domain, int type, int protocol)
1411 return socket(platform_domain, platform_type, platform_prot); 1411 return socket(platform_domain, platform_type, platform_prot);
1412} 1412}
1413 1413
1414/* TODO: Remove, when tox DNS support will be removed.
1415 * Used only by dns3_test.c
1416 */
1417size_t net_sendto_ip4(Socket sock, const char *buf, size_t n, IP_Port ip_port)
1418{
1419 struct sockaddr_in target;
1420 size_t addrsize = sizeof(target);
1421 target.sin_family = make_family(ip_port.ip.family);
1422 target.sin_port = net_htons(ip_port.port);
1423 fill_addr4(ip_port.ip.ip4, &target.sin_addr);
1424
1425 return (size_t)sendto(sock, buf, n, 0, (struct sockaddr *)&target, addrsize);
1426}
1427
1428uint32_t net_htonl(uint32_t hostlong) 1414uint32_t net_htonl(uint32_t hostlong)
1429{ 1415{
1430 return htonl(hostlong); 1416 return htonl(hostlong);
diff --git a/toxcore/network.h b/toxcore/network.h
index 0b9da5a4..41d1307a 100644
--- a/toxcore/network.h
+++ b/toxcore/network.h
@@ -403,8 +403,6 @@ void net_freeipport(IP_Port *ip_ports);
403 */ 403 */
404int bind_to_port(Socket sock, int family, uint16_t port); 404int bind_to_port(Socket sock, int family, uint16_t port);
405 405
406size_t net_sendto_ip4(Socket sock, const char *buf, size_t n, IP_Port ip_port);
407
408/* Initialize networking. 406/* Initialize networking.
409 * bind to ip and port. 407 * bind to ip and port.
410 * ip must be in network order EX: 127.0.0.1 = (7F000001). 408 * ip must be in network order EX: 127.0.0.1 = (7F000001).
diff --git a/toxdns/Makefile.inc b/toxdns/Makefile.inc
deleted file mode 100644
index 5b7c0123..00000000
--- a/toxdns/Makefile.inc
+++ /dev/null
@@ -1,35 +0,0 @@
1lib_LTLIBRARIES += libtoxdns.la
2
3libtoxdns_la_include_HEADERS = \
4 ../toxdns/toxdns.h
5
6libtoxdns_la_includedir = $(includedir)/tox
7
8libtoxdns_la_SOURCES = ../toxdns/toxdns.h \
9 ../toxdns/toxdns.c
10
11libtoxdns_la_CFLAGS = -I$(top_srcdir) \
12 -I$(top_srcdir)/toxcore \
13 $(LIBSODIUM_CFLAGS) \
14 $(NACL_CFLAGS) \
15 $(PTHREAD_CFLAGS)
16
17libtoxdns_la_LDFLAGS = $(LT_LDFLAGS) \
18 $(EXTRA_LT_LDFLAGS) \
19 $(LIBSODIUM_LDFLAGS) \
20 $(NACL_LDFLAGS) \
21 $(MATH_LDFLAGS) \
22 $(RT_LIBS) \
23 $(WINSOCK2_LIBS)
24
25libtoxdns_la_LIBADD = $(LIBSODIUM_LIBS) \
26 $(NACL_OBJECTS) \
27 $(NAC_LIBS) \
28 $(PTHREAD_LIBS) \
29 libtoxcore.la
30
31if SET_SO_VERSION
32
33EXTRA_libtoxdns_la_DEPENDENCIES = ../so.version
34
35endif
diff --git a/toxdns/toxdns.c b/toxdns/toxdns.c
deleted file mode 100644
index 96f3081f..00000000
--- a/toxdns/toxdns.c
+++ /dev/null
@@ -1,243 +0,0 @@
1/*
2 * Tox secure username DNS toxid resolving functions.
3 */
4
5/*
6 * Copyright © 2016-2017 The TokTok team.
7 * Copyright © 2013 Tox project.
8 *
9 * This file is part of Tox, the free peer to peer instant messenger.
10 *
11 * Tox is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * Tox is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
23 */
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28#include "../toxcore/Messenger.h"
29#include "../toxcore/logger.h"
30#include "toxdns.h"
31
32static const char base32[32] = {
33 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
34 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
35 '0', '1', '2', '3', '4', '5',
36};
37
38#define _encode(a, b, c) \
39{ \
40 uint8_t _i = 0; \
41 while (_i != c) { \
42 *a++ = base32[((b[0] >> bits) | (b[1] << (8 - bits))) & 0x1F]; \
43 bits += 5; \
44 if(bits >= 8) { \
45 bits -= 8; \
46 b++; \
47 _i++; \
48 } \
49 } \
50}
51
52typedef struct {
53 uint8_t temp_pk[CRYPTO_PUBLIC_KEY_SIZE];
54 uint8_t temp_sk[CRYPTO_SECRET_KEY_SIZE];
55 uint8_t server_public_key[CRYPTO_PUBLIC_KEY_SIZE];
56 uint8_t shared_key[CRYPTO_SYMMETRIC_KEY_SIZE];
57 uint32_t nonce;
58 uint32_t nonce_start;
59} DNS_Object;
60
61static void dns_new_temp_keys(DNS_Object *d)
62{
63 d->nonce = d->nonce_start = random_int();
64 crypto_new_keypair(d->temp_pk, d->temp_sk);
65 encrypt_precompute(d->server_public_key, d->temp_sk, d->shared_key);
66}
67
68/* Create a new tox_dns3 object for server with server_public_key.
69 *
70 * return Null on failure.
71 * return pointer object on success.
72 */
73void *tox_dns3_new(uint8_t *server_public_key)
74{
75 DNS_Object *d = (DNS_Object *)malloc(sizeof(DNS_Object));
76
77 if (d == NULL) {
78 return NULL;
79 }
80
81 memcpy(d->server_public_key, server_public_key, CRYPTO_PUBLIC_KEY_SIZE);
82 dns_new_temp_keys(d);
83 return d;
84}
85
86/* Destroy the tox dns3 object.
87 */
88void tox_dns3_kill(void *dns3_object)
89{
90 memset(dns3_object, 0, sizeof(DNS_Object));
91 free(dns3_object);
92}
93
94/* Generate a dns3 string of string_max_len used to query the dns server referred to by to
95 * dns3_object for a tox id registered to user with name of name_len.
96 *
97 * the uint32_t pointed by request_id will be set to the request id which must be passed to
98 * tox_decrypt_dns3_TXT() to correctly decode the response.
99 *
100 * This is what the string returned looks like:
101 * 4haaaaipr1o3mz0bxweox541airydbovqlbju51mb4p0ebxq.rlqdj4kkisbep2ks3fj2nvtmk4daduqiueabmexqva1jc
102 *
103 * returns length of string on success.
104 * returns -1 on failure.
105 */
106int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string_max_len, uint32_t *request_id,
107 uint8_t *name, uint8_t name_len)
108{
109#define DOT_INTERVAL (6 * 5)
110 int base = (sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE + name_len + CRYPTO_MAC_SIZE);
111 int end_len = ((base * 8) / 5) + (base / DOT_INTERVAL) + !!(base % 5);
112 end_len -= !(base % DOT_INTERVAL);
113
114 if (end_len > string_max_len) {
115 return -1;
116 }
117
118 DNS_Object *d = (DNS_Object *)dns3_object;
119 uint8_t buffer[1024];
120 uint8_t nonce[CRYPTO_NONCE_SIZE] = {0};
121 memcpy(nonce, &d->nonce, sizeof(uint32_t));
122 memcpy(buffer, &d->nonce, sizeof(uint32_t));
123 memcpy(buffer + sizeof(uint32_t), d->temp_pk, CRYPTO_PUBLIC_KEY_SIZE);
124 int len = encrypt_data_symmetric(d->shared_key, nonce, name, name_len,
125 buffer + sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE);
126
127 if (len == -1) {
128 return -1;
129 }
130
131 int total_len = len + sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE;
132 uint8_t *buff = buffer, *old_str = string;
133 buffer[total_len] = 0;
134 uint8_t bits = 0;
135 int i;
136
137 for (i = !(total_len % DOT_INTERVAL); i < (total_len / DOT_INTERVAL); ++i) {
138 _encode(string, buff, DOT_INTERVAL);
139 *string = '.';
140 ++string;
141 }
142
143 int left = total_len - (buff - buffer);
144 _encode(string, buff, left);
145#undef DOT_INTERVAL
146 *request_id = d->nonce;
147 ++d->nonce;
148
149 if (d->nonce == d->nonce_start) {
150 dns_new_temp_keys(d);
151 }
152
153 if (end_len != string - old_str) {
154 // TODO(iphydf): This currently has no access to a logger.
155 LOGGER_ERROR(NULL, "tox_generate_dns3_string Fail, %u != %lu\n", end_len, string - old_str);
156 return -1;
157 }
158
159 return string - old_str;
160}
161
162
163static int decode(uint8_t *dest, uint8_t *src)
164{
165 uint8_t *p = src, *op = dest, bits = 0;
166 *op = 0;
167
168 while (*p) {
169 uint8_t ch = *p++;
170
171 if ('A' <= ch && ch <= 'Z') {
172 ch = ch - 'A';
173 } else if ('a' <= ch && ch <= 'z') {
174 ch = ch - 'a';
175 } else if ('0' <= ch && ch <= '5') {
176 ch = ch - '0' + 26;
177 } else {
178 return - 1;
179 }
180
181 *op |= (ch << bits);
182 bits += 5;
183
184 if (bits >= 8) {
185 bits -= 8;
186 ++op;
187 *op = (ch >> (5 - bits));
188 }
189 }
190
191 return op - dest;
192}
193
194/* Decode and decrypt the id_record returned of length id_record_len into
195 * tox_id (needs to be at least TOX_FRIEND_ADDRESS_SIZE).
196 *
197 * request_id is the request id given by tox_generate_dns3_string() when creating the request.
198 *
199 * the id_record passed to this function should look somewhat like this:
200 * 2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp
201 *
202 * returns -1 on failure.
203 * returns 0 on success.
204 *
205 */
206int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record, uint32_t id_record_len,
207 uint32_t request_id)
208{
209 DNS_Object *d = (DNS_Object *)dns3_object;
210
211 if (id_record_len != 87) {
212 return -1;
213 }
214
215#if 0
216
217 if (id_record_len > 255 || id_record_len <= (sizeof(uint32_t) + CRYPTO_MAC_SIZE)) {
218 return -1;
219 }
220
221#endif
222
223 VLA(uint8_t, id_record_null, id_record_len + 1);
224 memcpy(id_record_null, id_record, id_record_len);
225 id_record_null[id_record_len] = 0;
226 VLA(uint8_t, data, id_record_len);
227 int length = decode(data, id_record_null);
228
229 if (length == -1) {
230 return -1;
231 }
232
233 uint8_t nonce[CRYPTO_NONCE_SIZE] = {0};
234 memcpy(nonce, &request_id, sizeof(uint32_t));
235 nonce[sizeof(uint32_t)] = 1;
236 int len = decrypt_data_symmetric(d->shared_key, nonce, data, length, tox_id);
237
238 if (len != FRIEND_ADDRESS_SIZE) {
239 return -1;
240 }
241
242 return 0;
243}
diff --git a/toxdns/toxdns.h b/toxdns/toxdns.h
deleted file mode 100644
index b280925e..00000000
--- a/toxdns/toxdns.h
+++ /dev/null
@@ -1,96 +0,0 @@
1/*
2 * Tox secure username DNS toxid resolving functions.
3 */
4
5/*
6 * Copyright © 2016-2017 The TokTok team.
7 * Copyright © 2014 Tox project.
8 *
9 * This file is part of Tox, the free peer to peer instant messenger.
10 *
11 * Tox is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * Tox is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
23 */
24#ifndef TOXDNS_H
25#define TOXDNS_H
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#include <stdint.h>
32
33/* Clients are encouraged to set this as the maximum length names can have. */
34#define TOXDNS_MAX_RECOMMENDED_NAME_LENGTH 32
35
36/* How to use this api to make secure tox dns3 requests:
37 *
38 * 1. Get the public key of a server that supports tox dns3.
39 * 2. use tox_dns3_new() to create a new object to create DNS requests
40 * and handle responses for that server.
41 * 3. Use tox_generate_dns3_string() to generate a string based on the name we want to query and a request_id
42 * that must be stored somewhere for when we want to decrypt the response.
43 * 4. take the string and use it for your DNS request like this:
44 * _4haaaaipr1o3mz0bxweox541airydbovqlbju51mb4p0ebxq.rlqdj4kkisbep2ks3fj2nvtmk4daduqiueabmexqva1jc._tox.utox.org
45 * 5. The TXT in the DNS you receive should look like this:
46 * v=tox3;id=2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp
47 * 6. Take the id string and use it with tox_decrypt_dns3_TXT() and the request_id corresponding to the
48 * request we stored earlier to get the Tox id returned by the DNS server.
49 */
50
51/* Create a new tox_dns3 object for server with server_public_key of size TOX_CLIENT_ID_SIZE.
52 *
53 * return Null on failure.
54 * return pointer object on success.
55 */
56void *tox_dns3_new(uint8_t *server_public_key);
57
58/* Destroy the tox dns3 object.
59 */
60void tox_dns3_kill(void *dns3_object);
61
62/* Generate a dns3 string of string_max_len used to query the dns server referred to by to
63 * dns3_object for a tox id registered to user with name of name_len.
64 *
65 * the uint32_t pointed by request_id will be set to the request id which must be passed to
66 * tox_decrypt_dns3_TXT() to correctly decode the response.
67 *
68 * This is what the string returned looks like:
69 * 4haaaaipr1o3mz0bxweox541airydbovqlbju51mb4p0ebxq.rlqdj4kkisbep2ks3fj2nvtmk4daduqiueabmexqva1jc
70 *
71 * returns length of string on success.
72 * returns -1 on failure.
73 */
74int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string_max_len, uint32_t *request_id,
75 uint8_t *name, uint8_t name_len);
76
77/* Decode and decrypt the id_record returned of length id_record_len into
78 * tox_id (needs to be at least TOX_FRIEND_ADDRESS_SIZE).
79 *
80 * request_id is the request id given by tox_generate_dns3_string() when creating the request.
81 *
82 * the id_record passed to this function should look somewhat like this:
83 * 2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp
84 *
85 * returns -1 on failure.
86 * returns 0 on success.
87 *
88 */
89int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record, uint32_t id_record_len,
90 uint32_t request_id);
91
92#ifdef __cplusplus
93}
94#endif
95
96#endif