diff options
-rw-r--r-- | build/Makefile.am | 1 | ||||
-rw-r--r-- | libtoxcore.pc.in | 2 | ||||
-rw-r--r-- | testing/Makefile.inc | 21 | ||||
-rw-r--r-- | testing/dns3_test.c | 51 | ||||
-rw-r--r-- | testing/nToxAudio.h | 55 | ||||
-rw-r--r-- | toxdns/Makefile.inc | 28 | ||||
-rw-r--r-- | toxdns/toxdns.c | 233 | ||||
-rw-r--r-- | toxdns/toxdns.h | 85 |
8 files changed, 419 insertions, 57 deletions
diff --git a/build/Makefile.am b/build/Makefile.am index aa004388..c2667d5d 100644 --- a/build/Makefile.am +++ b/build/Makefile.am | |||
@@ -5,6 +5,7 @@ noinst_bindir = $(top_builddir)/build | |||
5 | EXTRA_DIST= | 5 | EXTRA_DIST= |
6 | 6 | ||
7 | include ../toxcore/Makefile.inc | 7 | include ../toxcore/Makefile.inc |
8 | include ../toxdns/Makefile.inc | ||
8 | include ../toxav/Makefile.inc | 9 | include ../toxav/Makefile.inc |
9 | include ../other/Makefile.inc | 10 | include ../other/Makefile.inc |
10 | include ../testing/Makefile.inc | 11 | include ../testing/Makefile.inc |
diff --git a/libtoxcore.pc.in b/libtoxcore.pc.in index e05e51cd..a91a1fb7 100644 --- a/libtoxcore.pc.in +++ b/libtoxcore.pc.in | |||
@@ -7,5 +7,5 @@ Name: libtoxcore | |||
7 | Description: Tox protocol library | 7 | Description: Tox protocol library |
8 | Requires: | 8 | Requires: |
9 | Version: @PACKAGE_VERSION@ | 9 | Version: @PACKAGE_VERSION@ |
10 | Libs: @NACL_OBJECTS_PKGCONFIG@ -L${libdir} @NACL_LDFLAGS@ -ltoxcore @NACL_LIBS@ @LIBS@ @MATH_LDFLAGS@ | 10 | Libs: @NACL_OBJECTS_PKGCONFIG@ -L${libdir} @NACL_LDFLAGS@ -ltoxdns -ltoxcore @NACL_LIBS@ @LIBS@ @MATH_LDFLAGS@ |
11 | Cflags: -I${includedir} | 11 | Cflags: -I${includedir} |
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 | ||
25 | noinst_PROGRAMS += DHT_test \ | 25 | noinst_PROGRAMS += DHT_test \ |
26 | Messenger_test \ | 26 | Messenger_test \ |
27 | crypto_speed_test | 27 | crypto_speed_test \ |
28 | dns3_test | ||
28 | 29 | ||
29 | DHT_test_SOURCES = ../testing/DHT_test.c | 30 | DHT_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 | |||
76 | dns3_test_SOURCES = \ | ||
77 | ../testing/dns3_test.c | ||
78 | |||
79 | dns3_test_CFLAGS = \ | ||
80 | $(LIBSODIUM_CFLAGS) \ | ||
81 | $(NACL_CFLAGS) | ||
82 | |||
83 | dns3_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 | |||
74 | if !WIN32 | 93 | if !WIN32 |
75 | 94 | ||
76 | noinst_PROGRAMS += tox_sync | 95 | 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 @@ | |||
1 | |||
2 | |||
3 | #include "../toxdns/toxdns.h" | ||
4 | #include "../toxcore/tox.h" | ||
5 | #include "misc_tools.c" | ||
6 | |||
7 | |||
8 | int 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 | |||
45 | void new_lines(char *line); | ||
46 | void line_eval(char *line); | ||
47 | void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) ; | ||
48 | int count_lines(char *string) ; | ||
49 | char *appender(char *str, const char c); | ||
50 | void do_refresh(); | ||
51 | |||
52 | |||
53 | |||
54 | |||
55 | #endif | ||
diff --git a/toxdns/Makefile.inc b/toxdns/Makefile.inc new file mode 100644 index 00000000..1e66ab3f --- /dev/null +++ b/toxdns/Makefile.inc | |||
@@ -0,0 +1,28 @@ | |||
1 | lib_LTLIBRARIES += libtoxdns.la | ||
2 | |||
3 | libtoxdns_la_include_HEADERS = \ | ||
4 | ../toxdns/toxdns.h | ||
5 | |||
6 | libtoxdns_la_includedir = $(includedir)/tox | ||
7 | |||
8 | libtoxdns_la_SOURCES = ../toxdns/toxdns.h \ | ||
9 | ../toxdns/toxdns.c | ||
10 | |||
11 | libtoxdns_la_CFLAGS = -I$(top_srcdir) \ | ||
12 | -I$(top_srcdir)/toxcore \ | ||
13 | $(LIBSODIUM_CFLAGS) \ | ||
14 | $(NACL_CFLAGS) \ | ||
15 | $(PTHREAD_CFLAGS) | ||
16 | |||
17 | libtoxdns_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \ | ||
18 | $(EXTRA_LT_LDFLAGS) \ | ||
19 | $(LIBSODIUM_LDFLAGS) \ | ||
20 | $(NACL_LDFLAGS) \ | ||
21 | $(MATH_LDFLAGS) \ | ||
22 | $(RT_LIBS) \ | ||
23 | $(WINSOCK2_LIBS) | ||
24 | |||
25 | libtoxdns_la_LIBADD = $(LIBSODIUM_LIBS) \ | ||
26 | $(NACL_OBJECTS) \ | ||
27 | $(NAC_LIBS) \ | ||
28 | $(PTHREAD_LIBS) | ||
diff --git a/toxdns/toxdns.c b/toxdns/toxdns.c new file mode 100644 index 00000000..31269c15 --- /dev/null +++ b/toxdns/toxdns.c | |||
@@ -0,0 +1,233 @@ | |||
1 | /* toxdns.c | ||
2 | * | ||
3 | * Tox secure username DNS toxid resolving functions. | ||
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 | #ifdef HAVE_CONFIG_H | ||
25 | #include "config.h" | ||
26 | #endif | ||
27 | |||
28 | #include "../toxcore/Messenger.h" | ||
29 | |||
30 | static const char base32[32] = {"abcdefghijklmnopqrstuvwxyz012345"}; | ||
31 | |||
32 | #define _encode(a, b, c) \ | ||
33 | { \ | ||
34 | uint8_t i = 0; \ | ||
35 | while(i != c) { \ | ||
36 | *a++ = base32[((b[0] >> bits) | (b[1] << (8 - bits))) & 0x1F]; \ | ||
37 | bits += 5; \ | ||
38 | if(bits >= 8) { \ | ||
39 | bits -= 8; \ | ||
40 | b++; \ | ||
41 | i++; \ | ||
42 | } \ | ||
43 | } \ | ||
44 | } \ | ||
45 | |||
46 | typedef struct { | ||
47 | uint8_t temp_pk[crypto_box_PUBLICKEYBYTES]; | ||
48 | uint8_t temp_sk[crypto_box_SECRETKEYBYTES]; | ||
49 | uint8_t server_public_key[crypto_box_PUBLICKEYBYTES]; | ||
50 | uint8_t shared_key[crypto_box_KEYBYTES]; | ||
51 | uint32_t nonce; | ||
52 | uint32_t nonce_start; | ||
53 | } DNS_Object; | ||
54 | |||
55 | static void dns_new_temp_keys(DNS_Object *d) | ||
56 | { | ||
57 | d->nonce = d->nonce_start = random_int(); | ||
58 | crypto_box_keypair(d->temp_pk, d->temp_sk); | ||
59 | encrypt_precompute(d->server_public_key, d->temp_sk, d->shared_key); | ||
60 | } | ||
61 | |||
62 | /* Create a new tox_dns3 object for server with server_public_key. | ||
63 | * | ||
64 | * return Null on failure. | ||
65 | * return pointer object on success. | ||
66 | */ | ||
67 | void *tox_dns3_new(uint8_t *server_public_key) | ||
68 | { | ||
69 | DNS_Object *d = malloc(sizeof(DNS_Object)); | ||
70 | |||
71 | if (d == NULL) | ||
72 | return NULL; | ||
73 | |||
74 | memcpy(d->server_public_key, server_public_key, crypto_box_PUBLICKEYBYTES); | ||
75 | dns_new_temp_keys(d); | ||
76 | return d; | ||
77 | } | ||
78 | |||
79 | /* Destroy the tox dns3 object. | ||
80 | */ | ||
81 | void tox_dns3_kill(void *dns3_object) | ||
82 | { | ||
83 | memset(dns3_object, 0, sizeof(DNS_Object)); | ||
84 | free(dns3_object); | ||
85 | } | ||
86 | |||
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. | ||
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 | * | ||
93 | * This is what the string returned looks like: | ||
94 | * 4haaaaipr1o3mz0bxweox541airydbovqlbju51mb4p0ebxq.rlqdj4kkisbep2ks3fj2nvtmk4daduqiueabmexqva1jc | ||
95 | * | ||
96 | * returns length of string on sucess. | ||
97 | * returns -1 on failure. | ||
98 | */ | ||
99 | int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string_max_len, uint32_t *request_id, | ||
100 | uint8_t *name, uint8_t name_len) | ||
101 | { | ||
102 | #define DOT_INTERVAL (6 * 5) | ||
103 | int base = (sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES + name_len + crypto_box_MACBYTES); | ||
104 | int end_len = ((base * 8) / 5) + (base / DOT_INTERVAL) + !!(base % 5); | ||
105 | end_len -= !(base % DOT_INTERVAL); | ||
106 | |||
107 | if (end_len > string_max_len) | ||
108 | return -1; | ||
109 | |||
110 | DNS_Object *d = dns3_object; | ||
111 | uint8_t buffer[1024]; | ||
112 | uint8_t nonce[crypto_box_NONCEBYTES] = {0}; | ||
113 | memcpy(nonce, &d->nonce, sizeof(uint32_t)); | ||
114 | memcpy(buffer, &d->nonce, sizeof(uint32_t)); | ||
115 | memcpy(buffer + sizeof(uint32_t), d->temp_pk, crypto_box_PUBLICKEYBYTES); | ||
116 | int len = encrypt_data_symmetric(d->shared_key, nonce, name, name_len, | ||
117 | buffer + sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES); | ||
118 | |||
119 | if (len == -1) | ||
120 | return -1; | ||
121 | |||
122 | int total_len = len + sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES; | ||
123 | uint8_t *buff = buffer, *old_str = string; | ||
124 | buffer[total_len] = 0; | ||
125 | uint8_t bits = 0; | ||
126 | int i; | ||
127 | |||
128 | for (i = !(total_len % DOT_INTERVAL); i < (total_len / DOT_INTERVAL); ++i) { | ||
129 | _encode(string, buff, DOT_INTERVAL); | ||
130 | *string = '.'; | ||
131 | ++string; | ||
132 | } | ||
133 | |||
134 | int left = total_len - (buff - buffer); | ||
135 | _encode(string, buff, left); | ||
136 | #undef DOT_INTERVAL | ||
137 | *request_id = d->nonce; | ||
138 | ++d->nonce; | ||
139 | |||
140 | if (d->nonce == d->nonce_start) { | ||
141 | dns_new_temp_keys(d); | ||
142 | } | ||
143 | |||
144 | if (end_len != string - old_str) { | ||
145 | printf("tox_generate_dns3_string Fail, %u != %u\n", end_len, string - old_str); | ||
146 | return -1; | ||
147 | } | ||
148 | |||
149 | return string - old_str; | ||
150 | } | ||
151 | |||
152 | |||
153 | static int decode(uint8_t *dest, uint8_t *src) | ||
154 | { | ||
155 | uint8_t *p = src, *op = dest, bits = 0; | ||
156 | *op = 0; | ||
157 | |||
158 | while (*p) { | ||
159 | uint8_t ch = *p++; | ||
160 | |||
161 | switch (ch) { | ||
162 | case 'A' ... 'Z': { | ||
163 | ch = ch - 'A'; | ||
164 | break; | ||
165 | } | ||
166 | |||
167 | case 'a' ... 'z': { | ||
168 | ch = ch - 'a'; | ||
169 | break; | ||
170 | } | ||
171 | |||
172 | case '0' ... '5': { | ||
173 | ch = ch - '0' + 26; | ||
174 | break; | ||
175 | } | ||
176 | |||
177 | default: { | ||
178 | return - 1; | ||
179 | } | ||
180 | } | ||
181 | |||
182 | *op |= (ch << bits); | ||
183 | bits += 5; | ||
184 | |||
185 | if (bits >= 8) { | ||
186 | bits -= 8; | ||
187 | ++op; | ||
188 | *op = (ch >> (5 - bits)); | ||
189 | } | ||
190 | } | ||
191 | |||
192 | return op - dest; | ||
193 | } | ||
194 | |||
195 | /* Decode and decrypt the id_record returned of length id_record_len into | ||
196 | * tox_id (needs to be at least TOX_FRIEND_ADDRESS_SIZE). | ||
197 | * | ||
198 | * request_id is the request id given by tox_generate_dns3_string() when creating the request. | ||
199 | * | ||
200 | * the id_record passed to this function should look somewhat like this: | ||
201 | * 2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp | ||
202 | * | ||
203 | * returns -1 on failure. | ||
204 | * returns 0 on success. | ||
205 | * | ||
206 | */ | ||
207 | int 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) | ||
209 | { | ||
210 | DNS_Object *d = dns3_object; | ||
211 | |||
212 | if (id_record_len != 87) | ||
213 | return -1; | ||
214 | |||
215 | /*if (id_record_len > 255 || id_record_len <= (sizeof(uint32_t) + crypto_box_MACBYTES)) | ||
216 | return -1;*/ | ||
217 | |||
218 | uint8_t data[id_record_len]; | ||
219 | int length = decode(data, id_record); | ||
220 | |||
221 | if (length == -1) | ||
222 | return -1; | ||
223 | |||
224 | uint8_t nonce[crypto_box_NONCEBYTES] = {0}; | ||
225 | memcpy(nonce, &request_id, sizeof(uint32_t)); | ||
226 | nonce[sizeof(uint32_t)] = 1; | ||
227 | int len = decrypt_data_symmetric(d->shared_key, nonce, data, length, tox_id); | ||
228 | |||
229 | if (len != FRIEND_ADDRESS_SIZE) | ||
230 | return -1; | ||
231 | |||
232 | return 0; | ||
233 | } | ||
diff --git a/toxdns/toxdns.h b/toxdns/toxdns.h new file mode 100644 index 00000000..a570e7ea --- /dev/null +++ b/toxdns/toxdns.h | |||
@@ -0,0 +1,85 @@ | |||
1 | /* toxdns.h | ||
2 | * | ||
3 | * Tox secure username DNS toxid resolving functions. | ||
4 | * | ||
5 | * Copyright (C) 2014 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 TOXDNS_H | ||
25 | #define TOXDNS_H | ||
26 | |||
27 | #include <stdint.h> | ||
28 | |||
29 | /* How to use this api to make secure tox dns3 requests: | ||
30 | * | ||
31 | * 1. Get the public key of a server that supports tox dns3. | ||
32 | * 2. use tox_dns3_new() to create a new object to create DNS requests | ||
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 and a request_id | ||
35 | * that must be stored somewhere for when we want to decrypt the response. | ||
36 | * 4. take the string and use it for your DNS request like this: | ||
37 | * _4haaaaipr1o3mz0bxweox541airydbovqlbju51mb4p0ebxq.rlqdj4kkisbep2ks3fj2nvtmk4daduqiueabmexqva1jc._tox.utox.org | ||
38 | * 5. The TXT in the DNS you receive should look like this: | ||
39 | * v=tox3;id=2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp | ||
40 | * 6. Take the id string and use it with tox_decrypt_dns3_TXT() and the request_id corresponding to the | ||
41 | * request we stored earlier to get the Tox id returned by the DNS server. | ||
42 | */ | ||
43 | |||
44 | /* Create a new tox_dns3 object for server with server_public_key of size TOX_CLIENT_ID_SIZE. | ||
45 | * | ||
46 | * return Null on failure. | ||
47 | * return pointer object on success. | ||
48 | */ | ||
49 | void *tox_dns3_new(uint8_t *server_public_key); | ||
50 | |||
51 | /* Destroy the tox dns3 object. | ||
52 | */ | ||
53 | void tox_dns3_kill(void *dns3_object); | ||
54 | |||
55 | /* Generate a dns3 string of string_max_len used to query the dns server referred to by to | ||
56 | * dns3_object for a tox id registered to user with name of name_len. | ||
57 | * | ||
58 | * the uint32_t pointed by request_id will be set to the request id which must be passed to | ||
59 | * tox_decrypt_dns3_TXT() to correctly decode the response. | ||
60 | * | ||
61 | * This is what the string returned looks like: | ||
62 | * 4haaaaipr1o3mz0bxweox541airydbovqlbju51mb4p0ebxq.rlqdj4kkisbep2ks3fj2nvtmk4daduqiueabmexqva1jc | ||
63 | * | ||
64 | * returns length of string on sucess. | ||
65 | * returns -1 on failure. | ||
66 | */ | ||
67 | int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string_max_len, uint32_t *request_id, | ||
68 | uint8_t *name, uint8_t name_len); | ||
69 | |||
70 | /* Decode and decrypt the id_record returned of length id_record_len into | ||
71 | * tox_id (needs to be at least TOX_FRIEND_ADDRESS_SIZE). | ||
72 | * | ||
73 | * request_id is the request id given by tox_generate_dns3_string() when creating the request. | ||
74 | * | ||
75 | * the id_record passed to this function should look somewhat like this: | ||
76 | * 2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp | ||
77 | * | ||
78 | * returns -1 on failure. | ||
79 | * returns 0 on success. | ||
80 | * | ||
81 | */ | ||
82 | int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record, uint32_t id_record_len, | ||
83 | uint32_t request_id); | ||
84 | |||
85 | #endif | ||