summaryrefslogtreecommitdiff
path: root/toxdns/toxdns.h
diff options
context:
space:
mode:
Diffstat (limited to 'toxdns/toxdns.h')
-rw-r--r--toxdns/toxdns.h85
1 files changed, 85 insertions, 0 deletions
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 */
49void *tox_dns3_new(uint8_t *server_public_key);
50
51/* Destroy the tox dns3 object.
52 */
53void 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 */
67int 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 */
82int 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