ffi-tox 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ProjectTox-Core/AUTHORS +0 -0
- data/ProjectTox-Core/ChangeLog +0 -0
- data/ProjectTox-Core/INSTALL +370 -0
- data/ProjectTox-Core/INSTALL.md +455 -56
- data/ProjectTox-Core/Makefile.am +35 -0
- data/ProjectTox-Core/NEWS +0 -0
- data/ProjectTox-Core/README +43 -0
- data/ProjectTox-Core/README.md +34 -44
- data/ProjectTox-Core/auto_tests/Makefile.inc +110 -0
- data/ProjectTox-Core/auto_tests/TCP_test.c +519 -0
- data/ProjectTox-Core/auto_tests/assoc_test.c +160 -0
- data/ProjectTox-Core/auto_tests/crypto_test.c +302 -0
- data/ProjectTox-Core/auto_tests/dht_test.c +362 -0
- data/ProjectTox-Core/auto_tests/encryptsave_test.c +104 -0
- data/ProjectTox-Core/auto_tests/friends_test.c +238 -0
- data/ProjectTox-Core/auto_tests/helpers.h +15 -0
- data/ProjectTox-Core/auto_tests/messenger_test.c +365 -0
- data/ProjectTox-Core/auto_tests/network_test.c +171 -0
- data/ProjectTox-Core/auto_tests/onion_test.c +363 -0
- data/ProjectTox-Core/auto_tests/skeleton_test.c +49 -0
- data/ProjectTox-Core/auto_tests/tox_test.c +454 -0
- data/ProjectTox-Core/auto_tests/toxav_basic_test.c +597 -0
- data/ProjectTox-Core/auto_tests/toxav_many_test.c +402 -0
- data/ProjectTox-Core/autogen.sh +6 -0
- data/ProjectTox-Core/build/Makefile.am +14 -0
- data/ProjectTox-Core/configure.ac +694 -0
- data/ProjectTox-Core/dist-build/android-arm.sh +3 -0
- data/ProjectTox-Core/dist-build/android-armv7.sh +3 -0
- data/ProjectTox-Core/dist-build/android-build.sh +59 -0
- data/ProjectTox-Core/dist-build/android-mips.sh +3 -0
- data/ProjectTox-Core/dist-build/android-x86.sh +3 -0
- data/ProjectTox-Core/docs/Group-Chats.md +71 -0
- data/ProjectTox-Core/docs/Hardening.txt +60 -0
- data/ProjectTox-Core/docs/Hardening_docs.txt +30 -0
- data/ProjectTox-Core/docs/Prevent_Tracking.txt +160 -0
- data/ProjectTox-Core/docs/TCP_Network.txt +154 -0
- data/ProjectTox-Core/docs/TODO +62 -0
- data/ProjectTox-Core/docs/Tox_middle_level_network_protocol.txt +120 -0
- data/ProjectTox-Core/docs/av_api.md +194 -0
- data/ProjectTox-Core/libtoxav.pc.in +11 -0
- data/ProjectTox-Core/libtoxcore.pc.in +11 -0
- data/ProjectTox-Core/m4/ax_have_epoll.m4 +104 -0
- data/ProjectTox-Core/m4/ax_pthread.m4 +317 -0
- data/ProjectTox-Core/m4/pkg.m4 +199 -0
- data/ProjectTox-Core/other/DHT_bootstrap.c +121 -58
- data/ProjectTox-Core/other/DHTnodes +3 -0
- data/ProjectTox-Core/other/Makefile.inc +20 -0
- data/ProjectTox-Core/other/bootstrap_node_packets.c +65 -0
- data/ProjectTox-Core/other/tox.png +0 -0
- data/ProjectTox-Core/testing/DHT_test.c +170 -98
- data/ProjectTox-Core/testing/Makefile.inc +112 -0
- data/ProjectTox-Core/testing/Messenger_test.c +133 -69
- data/ProjectTox-Core/testing/dns3_test.c +115 -0
- data/ProjectTox-Core/testing/misc_tools.c +59 -13
- data/ProjectTox-Core/testing/nTox.c +1127 -264
- data/ProjectTox-Core/testing/nTox.h +10 -19
- data/ProjectTox-Core/testing/tox_shell.c +159 -0
- data/ProjectTox-Core/testing/tox_sync.c +299 -0
- data/ProjectTox-Core/tools/README +11 -0
- data/ProjectTox-Core/tools/astylerc +11 -0
- data/ProjectTox-Core/tools/pre-commit +17 -0
- data/ProjectTox-Core/toxav/Makefile.inc +36 -0
- data/ProjectTox-Core/toxav/codec.c +357 -0
- data/ProjectTox-Core/toxav/codec.h +116 -0
- data/ProjectTox-Core/toxav/msi.c +1949 -0
- data/ProjectTox-Core/toxav/msi.h +267 -0
- data/ProjectTox-Core/toxav/rtp.c +600 -0
- data/ProjectTox-Core/toxav/rtp.h +196 -0
- data/ProjectTox-Core/toxav/toxav.c +1148 -0
- data/ProjectTox-Core/toxav/toxav.h +389 -0
- data/ProjectTox-Core/toxcore/DHT.c +2521 -0
- data/ProjectTox-Core/toxcore/DHT.h +412 -0
- data/ProjectTox-Core/toxcore/LAN_discovery.c +322 -0
- data/ProjectTox-Core/{core → toxcore}/LAN_discovery.h +17 -12
- data/ProjectTox-Core/toxcore/Makefile.inc +67 -0
- data/ProjectTox-Core/toxcore/Messenger.c +3006 -0
- data/ProjectTox-Core/toxcore/Messenger.h +818 -0
- data/ProjectTox-Core/toxcore/TCP_client.c +858 -0
- data/ProjectTox-Core/toxcore/TCP_client.h +156 -0
- data/ProjectTox-Core/toxcore/TCP_server.c +1332 -0
- data/ProjectTox-Core/toxcore/TCP_server.h +181 -0
- data/ProjectTox-Core/toxcore/assoc.c +1033 -0
- data/ProjectTox-Core/toxcore/assoc.h +104 -0
- data/ProjectTox-Core/toxcore/crypto_core.c +278 -0
- data/ProjectTox-Core/toxcore/crypto_core.h +151 -0
- data/ProjectTox-Core/toxcore/friend_requests.c +175 -0
- data/ProjectTox-Core/toxcore/friend_requests.h +83 -0
- data/ProjectTox-Core/toxcore/group_chats.c +837 -0
- data/ProjectTox-Core/toxcore/group_chats.h +199 -0
- data/ProjectTox-Core/toxcore/list.c +256 -0
- data/ProjectTox-Core/toxcore/list.h +85 -0
- data/ProjectTox-Core/toxcore/logger.c +153 -0
- data/ProjectTox-Core/toxcore/logger.h +84 -0
- data/ProjectTox-Core/toxcore/misc_tools.h +70 -0
- data/ProjectTox-Core/toxcore/net_crypto.c +2753 -0
- data/ProjectTox-Core/toxcore/net_crypto.h +410 -0
- data/ProjectTox-Core/toxcore/network.c +979 -0
- data/ProjectTox-Core/toxcore/network.h +367 -0
- data/ProjectTox-Core/toxcore/onion.c +540 -0
- data/ProjectTox-Core/toxcore/onion.h +150 -0
- data/ProjectTox-Core/toxcore/onion_announce.c +433 -0
- data/ProjectTox-Core/toxcore/onion_announce.h +139 -0
- data/ProjectTox-Core/toxcore/onion_client.c +1347 -0
- data/ProjectTox-Core/toxcore/onion_client.h +253 -0
- data/ProjectTox-Core/toxcore/ping.c +346 -0
- data/ProjectTox-Core/toxcore/ping.h +47 -0
- data/ProjectTox-Core/toxcore/ping_array.c +162 -0
- data/ProjectTox-Core/toxcore/ping_array.h +75 -0
- data/ProjectTox-Core/toxcore/tox.c +940 -0
- data/ProjectTox-Core/toxcore/tox.h +734 -0
- data/ProjectTox-Core/toxcore/util.c +193 -0
- data/ProjectTox-Core/toxcore/util.h +63 -0
- data/ProjectTox-Core/toxdns/Makefile.inc +29 -0
- data/ProjectTox-Core/toxdns/toxdns.c +238 -0
- data/ProjectTox-Core/toxdns/toxdns.h +88 -0
- data/ProjectTox-Core/toxencryptsave/Makefile.inc +45 -0
- data/ProjectTox-Core/toxencryptsave/toxencryptsave.c +179 -0
- data/ProjectTox-Core/toxencryptsave/toxencryptsave.h +74 -0
- data/interfaces/libtox.i +2 -6
- data/lib/ffi-tox/libtox.rb +406 -28
- metadata +124 -46
- data/ProjectTox-Core/CMakeLists.txt +0 -50
- data/ProjectTox-Core/cmake/FindLIBCONFIG.cmake +0 -15
- data/ProjectTox-Core/cmake/FindNaCl.cmake +0 -17
- data/ProjectTox-Core/cmake/FindSODIUM.cmake +0 -15
- data/ProjectTox-Core/core/CMakeLists.txt +0 -19
- data/ProjectTox-Core/core/DHT.c +0 -1104
- data/ProjectTox-Core/core/DHT.h +0 -111
- data/ProjectTox-Core/core/LAN_discovery.c +0 -79
- data/ProjectTox-Core/core/Lossless_UDP.c +0 -755
- data/ProjectTox-Core/core/Lossless_UDP.h +0 -106
- data/ProjectTox-Core/core/Messenger.c +0 -596
- data/ProjectTox-Core/core/Messenger.h +0 -165
- data/ProjectTox-Core/core/friend_requests.c +0 -131
- data/ProjectTox-Core/core/friend_requests.h +0 -51
- data/ProjectTox-Core/core/net_crypto.c +0 -575
- data/ProjectTox-Core/core/net_crypto.h +0 -134
- data/ProjectTox-Core/core/network.c +0 -205
- data/ProjectTox-Core/core/network.h +0 -134
- data/ProjectTox-Core/docs/commands.md +0 -25
- data/ProjectTox-Core/docs/start_guide.de.md +0 -40
- data/ProjectTox-Core/docs/start_guide.md +0 -38
- data/ProjectTox-Core/other/CMakeLists.txt +0 -9
- data/ProjectTox-Core/testing/CMakeLists.txt +0 -18
- data/ProjectTox-Core/testing/DHT_cryptosendfiletest.c +0 -228
- data/ProjectTox-Core/testing/DHT_sendfiletest.c +0 -176
- data/ProjectTox-Core/testing/Lossless_UDP_testclient.c +0 -214
- data/ProjectTox-Core/testing/Lossless_UDP_testserver.c +0 -201
- data/ProjectTox-Core/testing/misc_tools.h +0 -29
- data/ProjectTox-Core/testing/nTox_win32.c +0 -387
- data/ProjectTox-Core/testing/nTox_win32.h +0 -40
- data/ProjectTox-Core/testing/rect.py +0 -45
@@ -0,0 +1,362 @@
|
|
1
|
+
#ifdef HAVE_CONFIG_H
|
2
|
+
#include "config.h"
|
3
|
+
#endif
|
4
|
+
|
5
|
+
#include <sys/param.h>
|
6
|
+
#include <time.h>
|
7
|
+
|
8
|
+
#include "../toxcore/tox.h"
|
9
|
+
#include "../toxcore/DHT.c"
|
10
|
+
|
11
|
+
#include "helpers.h"
|
12
|
+
|
13
|
+
#define swap(x,y) do \
|
14
|
+
{ unsigned char swap_temp[sizeof(x) == sizeof(y) ? (signed)sizeof(x) : -1]; \
|
15
|
+
memcpy(swap_temp,&y,sizeof(x)); \
|
16
|
+
memcpy(&y,&x, sizeof(x)); \
|
17
|
+
memcpy(&x,swap_temp,sizeof(x)); \
|
18
|
+
} while(0)
|
19
|
+
|
20
|
+
|
21
|
+
void mark_bad(IPPTsPng *ipptp)
|
22
|
+
{
|
23
|
+
ipptp->timestamp = unix_time() - 2 * BAD_NODE_TIMEOUT;
|
24
|
+
ipptp->hardening.routes_requests_ok = 0;
|
25
|
+
ipptp->hardening.send_nodes_ok = 0;
|
26
|
+
ipptp->hardening.testing_requests = 0;
|
27
|
+
}
|
28
|
+
|
29
|
+
void mark_possible_bad(IPPTsPng *ipptp)
|
30
|
+
{
|
31
|
+
ipptp->timestamp = unix_time();
|
32
|
+
ipptp->hardening.routes_requests_ok = 0;
|
33
|
+
ipptp->hardening.send_nodes_ok = 0;
|
34
|
+
ipptp->hardening.testing_requests = 0;
|
35
|
+
}
|
36
|
+
|
37
|
+
void mark_good(IPPTsPng *ipptp)
|
38
|
+
{
|
39
|
+
ipptp->timestamp = unix_time();
|
40
|
+
ipptp->hardening.routes_requests_ok = (HARDENING_ALL_OK >> 0) & 1;
|
41
|
+
ipptp->hardening.send_nodes_ok = (HARDENING_ALL_OK >> 1) & 1;
|
42
|
+
ipptp->hardening.testing_requests = (HARDENING_ALL_OK >> 2) & 1;
|
43
|
+
}
|
44
|
+
|
45
|
+
void mark_all_good(Client_data *list, uint32_t length, uint8_t ipv6)
|
46
|
+
{
|
47
|
+
uint32_t i;
|
48
|
+
for (i = 0; i < length; ++i) {
|
49
|
+
if (ipv6)
|
50
|
+
mark_good(&list[i].assoc6);
|
51
|
+
else
|
52
|
+
mark_good(&list[i].assoc4);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
/* Returns 1 if client_id has a furthest distance to comp_client_id
|
57
|
+
than all client_id's in the list */
|
58
|
+
uint8_t is_furthest(const uint8_t *comp_client_id, Client_data *list, uint32_t length, const uint8_t *client_id)
|
59
|
+
{
|
60
|
+
uint32_t i;
|
61
|
+
for (i = 0; i < length; ++i)
|
62
|
+
if (id_closest(comp_client_id, client_id, list[i].client_id) == 1)
|
63
|
+
return 0;
|
64
|
+
return 1;
|
65
|
+
}
|
66
|
+
|
67
|
+
int client_in_list(Client_data *list, uint32_t length, const uint8_t *client_id)
|
68
|
+
{
|
69
|
+
int i;
|
70
|
+
for (i = 0; i < (int)length; ++i)
|
71
|
+
if (id_equal(client_id, list[i].client_id))
|
72
|
+
return i;
|
73
|
+
return -1;
|
74
|
+
}
|
75
|
+
|
76
|
+
void test_addto_lists_update(DHT *dht,
|
77
|
+
Client_data *list,
|
78
|
+
uint32_t length,
|
79
|
+
IP_Port *ip_port)
|
80
|
+
{
|
81
|
+
int used, test, test1, test2, found;
|
82
|
+
IP_Port test_ipp;
|
83
|
+
uint8_t test_id[CLIENT_ID_SIZE];
|
84
|
+
uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0;
|
85
|
+
|
86
|
+
// check id update for existing ip_port
|
87
|
+
test = rand() % length;
|
88
|
+
ipport_copy(&test_ipp, ipv6 ? &list[test].assoc6.ip_port : &list[test].assoc4.ip_port);
|
89
|
+
|
90
|
+
randombytes(test_id, sizeof(test_id));
|
91
|
+
used = addto_lists(dht, test_ipp, test_id);
|
92
|
+
ck_assert_msg(used >= 1, "Wrong number of added clients");
|
93
|
+
// it is possible to have ip_port duplicates in the list, so ip_port @ found not always equal to ip_port @ test
|
94
|
+
found = client_in_list(list, length, test_id);
|
95
|
+
ck_assert_msg(found >= 0, "Client id is not in the list");
|
96
|
+
ck_assert_msg(ipport_equal(&test_ipp, ipv6 ? &list[found].assoc6.ip_port : &list[found].assoc4.ip_port), "Client IP_Port is incorrect");
|
97
|
+
|
98
|
+
// check ip_port update for existing id
|
99
|
+
test = rand() % length;
|
100
|
+
test_ipp.port = rand() % TOX_PORT_DEFAULT;
|
101
|
+
id_copy(test_id, list[test].client_id);
|
102
|
+
|
103
|
+
used = addto_lists(dht, test_ipp, test_id);
|
104
|
+
ck_assert_msg(used >= 1, "Wrong number of added clients");
|
105
|
+
// it is not possible to have id duplicates in the list, so id @ found must be equal id @ test
|
106
|
+
ck_assert_msg(client_in_list(list, length, test_id) == test, "Client id is not in the list");
|
107
|
+
ck_assert_msg(ipport_equal(&test_ipp, ipv6 ? &list[test].assoc6.ip_port : &list[test].assoc4.ip_port), "Client IP_Port is incorrect");
|
108
|
+
|
109
|
+
// check ip_port update for existing id and ip_port (... port ... id ...)
|
110
|
+
test1 = rand() % (length / 2);
|
111
|
+
test2 = rand() % (length / 2) + length / 2;
|
112
|
+
|
113
|
+
ipport_copy(&test_ipp, ipv6 ? &list[test1].assoc6.ip_port : &list[test1].assoc4.ip_port);
|
114
|
+
id_copy(test_id, list[test2].client_id);
|
115
|
+
if (ipv6) list[test2].assoc6.ip_port.port = -1; else list[test2].assoc4.ip_port.port = -1;
|
116
|
+
used = addto_lists(dht, test_ipp, test_id);
|
117
|
+
ck_assert_msg(used >= 1, "Wrong number of added clients");
|
118
|
+
ck_assert_msg(client_in_list(list, length, test_id) == test2, "Client id is not in the list");
|
119
|
+
ck_assert_msg(ipport_equal(&test_ipp, ipv6 ? &list[test2].assoc6.ip_port : &list[test2].assoc4.ip_port), "Client IP_Port is incorrect");
|
120
|
+
|
121
|
+
// check ip_port update for existing id and ip_port (... id ... port ...)
|
122
|
+
test1 = rand() % (length / 2);
|
123
|
+
test2 = rand() % (length / 2) + length / 2;
|
124
|
+
|
125
|
+
ipport_copy(&test_ipp, ipv6 ? &list[test2].assoc6.ip_port : &list[test2].assoc4.ip_port);
|
126
|
+
id_copy(test_id, list[test1].client_id);
|
127
|
+
if (ipv6) list[test1].assoc6.ip_port.port = -1; else list[test1].assoc4.ip_port.port = -1;
|
128
|
+
used = addto_lists(dht, test_ipp, test_id);
|
129
|
+
ck_assert_msg(used >= 1, "Wrong number of added clients");
|
130
|
+
ck_assert_msg(client_in_list(list, length, test_id) == test1, "Client id is not in the list");
|
131
|
+
ck_assert_msg(ipport_equal(&test_ipp, ipv6 ? &list[test1].assoc6.ip_port : &list[test1].assoc4.ip_port), "Client IP_Port is incorrect");
|
132
|
+
}
|
133
|
+
|
134
|
+
void test_addto_lists_bad(DHT *dht,
|
135
|
+
Client_data *list,
|
136
|
+
uint32_t length,
|
137
|
+
IP_Port *ip_port)
|
138
|
+
{
|
139
|
+
// check "bad" clients replacement
|
140
|
+
int used, test1, test2, test3;
|
141
|
+
uint8_t client_id[CLIENT_ID_SIZE], test_id1[CLIENT_ID_SIZE], test_id2[CLIENT_ID_SIZE], test_id3[CLIENT_ID_SIZE];
|
142
|
+
uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0;
|
143
|
+
|
144
|
+
randombytes(client_id, sizeof(client_id));
|
145
|
+
mark_all_good(list, length, ipv6);
|
146
|
+
|
147
|
+
test1 = rand() % (length / 3);
|
148
|
+
test2 = rand() % (length / 3) + length / 3;
|
149
|
+
test3 = rand() % (length / 3) + 2 * length / 3;
|
150
|
+
ck_assert_msg(!(test1 == test2 || test1 == test3 || test2 == test3), "Wrong test indices are chosen");
|
151
|
+
|
152
|
+
id_copy((uint8_t*)&test_id1, list[test1].client_id);
|
153
|
+
id_copy((uint8_t*)&test_id2, list[test2].client_id);
|
154
|
+
id_copy((uint8_t*)&test_id3, list[test3].client_id);
|
155
|
+
|
156
|
+
// mark nodes as "bad"
|
157
|
+
if (ipv6) {
|
158
|
+
mark_bad(&list[test1].assoc6);
|
159
|
+
mark_bad(&list[test2].assoc6);
|
160
|
+
mark_bad(&list[test3].assoc6);
|
161
|
+
} else {
|
162
|
+
mark_bad(&list[test1].assoc4);
|
163
|
+
mark_bad(&list[test2].assoc4);
|
164
|
+
mark_bad(&list[test3].assoc4);
|
165
|
+
}
|
166
|
+
|
167
|
+
ip_port->port += 1;
|
168
|
+
used = addto_lists(dht, *ip_port, client_id);
|
169
|
+
ck_assert_msg(used >= 1, "Wrong number of added clients");
|
170
|
+
|
171
|
+
ck_assert_msg(client_in_list(list, length, client_id) >= 0, "Client id is not in the list");
|
172
|
+
ck_assert_msg(id_equal(client_id, list[test1].client_id), "Wrong bad client removed");
|
173
|
+
ck_assert_msg(id_equal(test_id2, list[test2].client_id), "Wrong bad client removed");
|
174
|
+
ck_assert_msg(id_equal(test_id3, list[test3].client_id), "Wrong bad client removed");
|
175
|
+
}
|
176
|
+
|
177
|
+
void test_addto_lists_possible_bad(DHT *dht,
|
178
|
+
Client_data *list,
|
179
|
+
uint32_t length,
|
180
|
+
IP_Port *ip_port,
|
181
|
+
const uint8_t *comp_client_id)
|
182
|
+
{
|
183
|
+
// check "possibly bad" clients replacement
|
184
|
+
int used, test1, test2, test3;
|
185
|
+
uint8_t client_id[CLIENT_ID_SIZE], test_id1[CLIENT_ID_SIZE], test_id2[CLIENT_ID_SIZE], test_id3[CLIENT_ID_SIZE];
|
186
|
+
uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0;
|
187
|
+
|
188
|
+
randombytes(client_id, sizeof(client_id));
|
189
|
+
mark_all_good(list, length, ipv6);
|
190
|
+
|
191
|
+
test1 = rand() % (length / 3);
|
192
|
+
test2 = rand() % (length / 3) + length / 3;
|
193
|
+
test3 = rand() % (length / 3) + 2 * length / 3;
|
194
|
+
ck_assert_msg(!(test1 == test2 || test1 == test3 || test2 == test3), "Wrong test indices are chosen");
|
195
|
+
|
196
|
+
id_copy((uint8_t*)&test_id1, list[test1].client_id);
|
197
|
+
id_copy((uint8_t*)&test_id2, list[test2].client_id);
|
198
|
+
id_copy((uint8_t*)&test_id3, list[test3].client_id);
|
199
|
+
|
200
|
+
// mark nodes as "possibly bad"
|
201
|
+
if (ipv6) {
|
202
|
+
mark_possible_bad(&list[test1].assoc6);
|
203
|
+
mark_possible_bad(&list[test2].assoc6);
|
204
|
+
mark_possible_bad(&list[test3].assoc6);
|
205
|
+
} else {
|
206
|
+
mark_possible_bad(&list[test1].assoc4);
|
207
|
+
mark_possible_bad(&list[test2].assoc4);
|
208
|
+
mark_possible_bad(&list[test3].assoc4);
|
209
|
+
}
|
210
|
+
|
211
|
+
ip_port->port += 1;
|
212
|
+
used = addto_lists(dht, *ip_port, client_id);
|
213
|
+
ck_assert_msg(used >= 1, "Wrong number of added clients");
|
214
|
+
|
215
|
+
ck_assert_msg(client_in_list(list, length, client_id) >= 0, "Client id is not in the list");
|
216
|
+
|
217
|
+
int inlist_id1 = client_in_list(list, length, test_id1) >= 0;
|
218
|
+
int inlist_id2 = client_in_list(list, length, test_id2) >= 0;
|
219
|
+
int inlist_id3 = client_in_list(list, length, test_id3) >= 0;
|
220
|
+
|
221
|
+
ck_assert_msg(inlist_id1 + inlist_id2 + inlist_id3 == 2, "Wrong client removed");
|
222
|
+
|
223
|
+
if (!inlist_id1) {
|
224
|
+
ck_assert_msg(id_closest(comp_client_id, test_id2, test_id1) == 1, "Id has been removed but is closer to than another one");
|
225
|
+
ck_assert_msg(id_closest(comp_client_id, test_id3, test_id1) == 1, "Id has been removed but is closer to than another one");
|
226
|
+
} else if (!inlist_id2) {
|
227
|
+
ck_assert_msg(id_closest(comp_client_id, test_id1, test_id2) == 1, "Id has been removed but is closer to than another one");
|
228
|
+
ck_assert_msg(id_closest(comp_client_id, test_id3, test_id2) == 1, "Id has been removed but is closer to than another one");
|
229
|
+
} else if (!inlist_id3) {
|
230
|
+
ck_assert_msg(id_closest(comp_client_id, test_id1, test_id3) == 1, "Id has been removed but is closer to than another one");
|
231
|
+
ck_assert_msg(id_closest(comp_client_id, test_id2, test_id3) == 1, "Id has been removed but is closer to than another one");
|
232
|
+
}
|
233
|
+
}
|
234
|
+
|
235
|
+
void test_addto_lists_good(DHT *dht,
|
236
|
+
Client_data *list,
|
237
|
+
uint32_t length,
|
238
|
+
IP_Port *ip_port,
|
239
|
+
const uint8_t *comp_client_id)
|
240
|
+
{
|
241
|
+
uint8_t client_id[CLIENT_ID_SIZE];
|
242
|
+
uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0;
|
243
|
+
|
244
|
+
mark_all_good(list, length, ipv6);
|
245
|
+
|
246
|
+
// check "good" client id replacement
|
247
|
+
do {
|
248
|
+
randombytes(client_id, sizeof(client_id));
|
249
|
+
} while (is_furthest(comp_client_id, list, length, client_id));
|
250
|
+
ip_port->port += 1;
|
251
|
+
addto_lists(dht, *ip_port, client_id);
|
252
|
+
ck_assert_msg(client_in_list(list, length, client_id) >= 0, "Good client id is not in the list");
|
253
|
+
|
254
|
+
// check "good" client id skip
|
255
|
+
do {
|
256
|
+
randombytes(client_id, sizeof(client_id));
|
257
|
+
} while (!is_furthest(comp_client_id, list, length, client_id));
|
258
|
+
|
259
|
+
ip_port->port += 1;
|
260
|
+
addto_lists(dht, *ip_port, client_id);
|
261
|
+
ck_assert_msg(client_in_list(list, length, client_id) == -1, "Good client id is in the list");
|
262
|
+
}
|
263
|
+
|
264
|
+
void test_addto_lists(IP ip)
|
265
|
+
{
|
266
|
+
Networking_Core* net = new_networking(ip, TOX_PORT_DEFAULT);
|
267
|
+
ck_assert_msg(net != 0, "Failed to create Networking_Core");
|
268
|
+
|
269
|
+
DHT* dht = new_DHT(net);
|
270
|
+
ck_assert_msg(dht != 0, "Failed to create DHT");
|
271
|
+
|
272
|
+
IP_Port ip_port = { .ip = ip, .port = TOX_PORT_DEFAULT };
|
273
|
+
uint8_t client_id[CLIENT_ID_SIZE];
|
274
|
+
int i, used;
|
275
|
+
|
276
|
+
// check lists filling
|
277
|
+
for (i = 0; i < MAX(LCLIENT_LIST, MAX_FRIEND_CLIENTS); ++i) {
|
278
|
+
randombytes(client_id, sizeof(client_id));
|
279
|
+
used = addto_lists(dht, ip_port, client_id);
|
280
|
+
ck_assert_msg(used == dht->num_friends + 1, "Wrong number of added clients with existing ip_port");
|
281
|
+
}
|
282
|
+
|
283
|
+
for (i = 0; i < MAX(LCLIENT_LIST, MAX_FRIEND_CLIENTS); ++i) {
|
284
|
+
ip_port.port += 1;
|
285
|
+
used = addto_lists(dht, ip_port, client_id);
|
286
|
+
ck_assert_msg(used == dht->num_friends + 1, "Wrong number of added clients with existing client_id");
|
287
|
+
}
|
288
|
+
|
289
|
+
for (i = 0; i < MAX(LCLIENT_LIST, MAX_FRIEND_CLIENTS); ++i) {
|
290
|
+
ip_port.port += 1;
|
291
|
+
randombytes(client_id, sizeof(client_id));
|
292
|
+
used = addto_lists(dht, ip_port, client_id);
|
293
|
+
ck_assert_msg(used >= 1, "Wrong number of added clients");
|
294
|
+
}
|
295
|
+
|
296
|
+
/*check: Current behavior if there are two clients with the same id is
|
297
|
+
* to replace the first ip by the second. */
|
298
|
+
test_addto_lists_update(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port);
|
299
|
+
for (i = 0; i < dht->num_friends; ++i)
|
300
|
+
test_addto_lists_update(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port);
|
301
|
+
|
302
|
+
// check "bad" entries
|
303
|
+
test_addto_lists_bad(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port);
|
304
|
+
for (i = 0; i < dht->num_friends; ++i)
|
305
|
+
test_addto_lists_bad(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port);
|
306
|
+
|
307
|
+
// check "possibly bad" entries
|
308
|
+
test_addto_lists_possible_bad(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port, dht->self_public_key);
|
309
|
+
for (i = 0; i < dht->num_friends; ++i)
|
310
|
+
test_addto_lists_possible_bad(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port, dht->friends_list[i].client_id);
|
311
|
+
|
312
|
+
// check "good" entries
|
313
|
+
test_addto_lists_good(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port, dht->self_public_key);
|
314
|
+
for (i = 0; i < dht->num_friends; ++i)
|
315
|
+
test_addto_lists_good(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port, dht->friends_list[i].client_id);
|
316
|
+
|
317
|
+
kill_DHT(dht);
|
318
|
+
kill_networking(net);
|
319
|
+
}
|
320
|
+
|
321
|
+
START_TEST(test_addto_lists_ipv4)
|
322
|
+
{
|
323
|
+
IP ip;
|
324
|
+
ip_init(&ip, 0);
|
325
|
+
test_addto_lists(ip);
|
326
|
+
|
327
|
+
}
|
328
|
+
END_TEST
|
329
|
+
|
330
|
+
START_TEST(test_addto_lists_ipv6)
|
331
|
+
{
|
332
|
+
IP ip;
|
333
|
+
ip_init(&ip, 1);
|
334
|
+
test_addto_lists(ip);
|
335
|
+
|
336
|
+
}
|
337
|
+
END_TEST
|
338
|
+
|
339
|
+
Suite *dht_suite(void)
|
340
|
+
{
|
341
|
+
Suite *s = suite_create("DHT");
|
342
|
+
|
343
|
+
DEFTESTCASE(addto_lists_ipv4);
|
344
|
+
DEFTESTCASE(addto_lists_ipv6);
|
345
|
+
return s;
|
346
|
+
}
|
347
|
+
|
348
|
+
int main(int argc, char *argv[])
|
349
|
+
{
|
350
|
+
srand((unsigned int) time(NULL));
|
351
|
+
|
352
|
+
Suite *dht = dht_suite();
|
353
|
+
SRunner *test_runner = srunner_create(dht);
|
354
|
+
|
355
|
+
int number_failed = 0;
|
356
|
+
srunner_run_all(test_runner, CK_NORMAL);
|
357
|
+
number_failed = srunner_ntests_failed(test_runner);
|
358
|
+
|
359
|
+
srunner_free(test_runner);
|
360
|
+
|
361
|
+
return number_failed;
|
362
|
+
}
|
@@ -0,0 +1,104 @@
|
|
1
|
+
#ifdef HAVE_CONFIG_H
|
2
|
+
#include "config.h"
|
3
|
+
#endif
|
4
|
+
|
5
|
+
#include <sys/types.h>
|
6
|
+
#include <stdint.h>
|
7
|
+
#include <string.h>
|
8
|
+
#include <check.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <time.h>
|
11
|
+
|
12
|
+
#include "helpers.h"
|
13
|
+
|
14
|
+
#include "../toxcore/tox.h"
|
15
|
+
|
16
|
+
#include "../toxencryptsave/toxencryptsave.h"
|
17
|
+
#include "../toxcore/crypto_core.h"
|
18
|
+
#ifdef VANILLA_NACL
|
19
|
+
#include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h"
|
20
|
+
#include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.h" /* sodium_memzero */
|
21
|
+
#endif
|
22
|
+
|
23
|
+
unsigned char salt[32] = {0xB1,0xC2,0x09,0xEE,0x50,0x6C,0xF0,0x20,0xC4,0xD6,0xEB,0xC0,0x44,0x51,0x3B,0x60,0x4B,0x39,0x4A,0xCF,0x09,0x53,0x4F,0xEA,0x08,0x41,0xFA,0xCA,0x66,0xD2,0x68,0x7F};
|
24
|
+
unsigned char key[crypto_box_BEFORENMBYTES] = {0xd1, 0x7, 0x4e, 0xfc, 0x49, 0x2d, 0x99, 0x16, 0xba, 0x4a, 0x4c, 0xc4, 0x92, 0x9, 0xb0, 0x9a, 0xa1, 0xa2, 0xe8, 0xe3, 0x45, 0xe7, 0xf5, 0x50, 0x54, 0x61, 0xd7, 0x3e, 0x2, 0x38, 0xe6, 0xa4};
|
25
|
+
char* pw = "hunter2";
|
26
|
+
unsigned int pwlen = 7;
|
27
|
+
|
28
|
+
/* cause I'm shameless */
|
29
|
+
void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
|
30
|
+
{
|
31
|
+
if (*((uint32_t *)userdata) != 974536)
|
32
|
+
return;
|
33
|
+
|
34
|
+
if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
|
35
|
+
tox_add_friend_norequest(m, public_key);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
START_TEST(test_known_kdf)
|
40
|
+
{
|
41
|
+
unsigned char out[crypto_box_BEFORENMBYTES];
|
42
|
+
crypto_pwhash_scryptsalsa208sha256(out,
|
43
|
+
crypto_box_BEFORENMBYTES,
|
44
|
+
pw,
|
45
|
+
pwlen,
|
46
|
+
salt,
|
47
|
+
crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE,
|
48
|
+
crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE);
|
49
|
+
ck_assert_msg(memcmp(out, key, crypto_box_BEFORENMBYTES) == 0, "derived key is wrong");
|
50
|
+
}
|
51
|
+
END_TEST
|
52
|
+
|
53
|
+
START_TEST(test_save_friend)
|
54
|
+
{
|
55
|
+
Tox *tox1 = tox_new(0);
|
56
|
+
Tox *tox2 = tox_new(0);
|
57
|
+
ck_assert_msg(tox1 || tox2, "Failed to create 2 tox instances");
|
58
|
+
uint32_t to_compare = 974536;
|
59
|
+
tox_callback_friend_request(tox2, accept_friend_request, &to_compare);
|
60
|
+
uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
|
61
|
+
tox_get_address(tox2, address);
|
62
|
+
int test = tox_add_friend(tox1, address, (uint8_t *)"Gentoo", 7);
|
63
|
+
ck_assert_msg(test == 0, "Failed to add friend error code: %i", test);
|
64
|
+
uint32_t size = tox_encrypted_size(tox1);
|
65
|
+
uint8_t data[size];
|
66
|
+
test = tox_encrypted_save(tox1, data, "correcthorsebatterystaple", 25);
|
67
|
+
ck_assert_msg(test == 0, "failed to encrypted save");
|
68
|
+
ck_assert_msg(tox_is_data_encrypted(data) == 1, "magic number missing");
|
69
|
+
Tox *tox3 = tox_new(0);
|
70
|
+
test = tox_encrypted_load(tox3, data, size, "correcthorsebatterystaple", 25);
|
71
|
+
ck_assert_msg(test == 0, "failed to encrypted load");
|
72
|
+
uint8_t address2[TOX_CLIENT_ID_SIZE];
|
73
|
+
test = tox_get_client_id(tox3, 0, address2);
|
74
|
+
ck_assert_msg(test == 0, "no friends!");
|
75
|
+
ck_assert_msg(memcmp(address, address2, TOX_CLIENT_ID_SIZE) == 0, "addresses don't match!");
|
76
|
+
}
|
77
|
+
END_TEST
|
78
|
+
|
79
|
+
Suite * encryptsave_suite(void)
|
80
|
+
{
|
81
|
+
Suite *s = suite_create("encryptsave");
|
82
|
+
|
83
|
+
DEFTESTCASE_SLOW(known_kdf, 60); /* is 5-10 seconds on my computer, but is directly dependent on CPU */
|
84
|
+
DEFTESTCASE(save_friend);
|
85
|
+
|
86
|
+
return s;
|
87
|
+
}
|
88
|
+
|
89
|
+
int main(int argc, char *argv[])
|
90
|
+
{
|
91
|
+
srand((unsigned int) time(NULL));
|
92
|
+
|
93
|
+
Suite * encryptsave = encryptsave_suite();
|
94
|
+
SRunner *test_runner = srunner_create(encryptsave);
|
95
|
+
|
96
|
+
int number_failed = 0;
|
97
|
+
srunner_run_all(test_runner, CK_NORMAL);
|
98
|
+
number_failed = srunner_ntests_failed(test_runner);
|
99
|
+
|
100
|
+
srunner_free(test_runner);
|
101
|
+
|
102
|
+
return number_failed;
|
103
|
+
}
|
104
|
+
|