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.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/ProjectTox-Core/AUTHORS +0 -0
  3. data/ProjectTox-Core/ChangeLog +0 -0
  4. data/ProjectTox-Core/INSTALL +370 -0
  5. data/ProjectTox-Core/INSTALL.md +455 -56
  6. data/ProjectTox-Core/Makefile.am +35 -0
  7. data/ProjectTox-Core/NEWS +0 -0
  8. data/ProjectTox-Core/README +43 -0
  9. data/ProjectTox-Core/README.md +34 -44
  10. data/ProjectTox-Core/auto_tests/Makefile.inc +110 -0
  11. data/ProjectTox-Core/auto_tests/TCP_test.c +519 -0
  12. data/ProjectTox-Core/auto_tests/assoc_test.c +160 -0
  13. data/ProjectTox-Core/auto_tests/crypto_test.c +302 -0
  14. data/ProjectTox-Core/auto_tests/dht_test.c +362 -0
  15. data/ProjectTox-Core/auto_tests/encryptsave_test.c +104 -0
  16. data/ProjectTox-Core/auto_tests/friends_test.c +238 -0
  17. data/ProjectTox-Core/auto_tests/helpers.h +15 -0
  18. data/ProjectTox-Core/auto_tests/messenger_test.c +365 -0
  19. data/ProjectTox-Core/auto_tests/network_test.c +171 -0
  20. data/ProjectTox-Core/auto_tests/onion_test.c +363 -0
  21. data/ProjectTox-Core/auto_tests/skeleton_test.c +49 -0
  22. data/ProjectTox-Core/auto_tests/tox_test.c +454 -0
  23. data/ProjectTox-Core/auto_tests/toxav_basic_test.c +597 -0
  24. data/ProjectTox-Core/auto_tests/toxav_many_test.c +402 -0
  25. data/ProjectTox-Core/autogen.sh +6 -0
  26. data/ProjectTox-Core/build/Makefile.am +14 -0
  27. data/ProjectTox-Core/configure.ac +694 -0
  28. data/ProjectTox-Core/dist-build/android-arm.sh +3 -0
  29. data/ProjectTox-Core/dist-build/android-armv7.sh +3 -0
  30. data/ProjectTox-Core/dist-build/android-build.sh +59 -0
  31. data/ProjectTox-Core/dist-build/android-mips.sh +3 -0
  32. data/ProjectTox-Core/dist-build/android-x86.sh +3 -0
  33. data/ProjectTox-Core/docs/Group-Chats.md +71 -0
  34. data/ProjectTox-Core/docs/Hardening.txt +60 -0
  35. data/ProjectTox-Core/docs/Hardening_docs.txt +30 -0
  36. data/ProjectTox-Core/docs/Prevent_Tracking.txt +160 -0
  37. data/ProjectTox-Core/docs/TCP_Network.txt +154 -0
  38. data/ProjectTox-Core/docs/TODO +62 -0
  39. data/ProjectTox-Core/docs/Tox_middle_level_network_protocol.txt +120 -0
  40. data/ProjectTox-Core/docs/av_api.md +194 -0
  41. data/ProjectTox-Core/libtoxav.pc.in +11 -0
  42. data/ProjectTox-Core/libtoxcore.pc.in +11 -0
  43. data/ProjectTox-Core/m4/ax_have_epoll.m4 +104 -0
  44. data/ProjectTox-Core/m4/ax_pthread.m4 +317 -0
  45. data/ProjectTox-Core/m4/pkg.m4 +199 -0
  46. data/ProjectTox-Core/other/DHT_bootstrap.c +121 -58
  47. data/ProjectTox-Core/other/DHTnodes +3 -0
  48. data/ProjectTox-Core/other/Makefile.inc +20 -0
  49. data/ProjectTox-Core/other/bootstrap_node_packets.c +65 -0
  50. data/ProjectTox-Core/other/tox.png +0 -0
  51. data/ProjectTox-Core/testing/DHT_test.c +170 -98
  52. data/ProjectTox-Core/testing/Makefile.inc +112 -0
  53. data/ProjectTox-Core/testing/Messenger_test.c +133 -69
  54. data/ProjectTox-Core/testing/dns3_test.c +115 -0
  55. data/ProjectTox-Core/testing/misc_tools.c +59 -13
  56. data/ProjectTox-Core/testing/nTox.c +1127 -264
  57. data/ProjectTox-Core/testing/nTox.h +10 -19
  58. data/ProjectTox-Core/testing/tox_shell.c +159 -0
  59. data/ProjectTox-Core/testing/tox_sync.c +299 -0
  60. data/ProjectTox-Core/tools/README +11 -0
  61. data/ProjectTox-Core/tools/astylerc +11 -0
  62. data/ProjectTox-Core/tools/pre-commit +17 -0
  63. data/ProjectTox-Core/toxav/Makefile.inc +36 -0
  64. data/ProjectTox-Core/toxav/codec.c +357 -0
  65. data/ProjectTox-Core/toxav/codec.h +116 -0
  66. data/ProjectTox-Core/toxav/msi.c +1949 -0
  67. data/ProjectTox-Core/toxav/msi.h +267 -0
  68. data/ProjectTox-Core/toxav/rtp.c +600 -0
  69. data/ProjectTox-Core/toxav/rtp.h +196 -0
  70. data/ProjectTox-Core/toxav/toxav.c +1148 -0
  71. data/ProjectTox-Core/toxav/toxav.h +389 -0
  72. data/ProjectTox-Core/toxcore/DHT.c +2521 -0
  73. data/ProjectTox-Core/toxcore/DHT.h +412 -0
  74. data/ProjectTox-Core/toxcore/LAN_discovery.c +322 -0
  75. data/ProjectTox-Core/{core → toxcore}/LAN_discovery.h +17 -12
  76. data/ProjectTox-Core/toxcore/Makefile.inc +67 -0
  77. data/ProjectTox-Core/toxcore/Messenger.c +3006 -0
  78. data/ProjectTox-Core/toxcore/Messenger.h +818 -0
  79. data/ProjectTox-Core/toxcore/TCP_client.c +858 -0
  80. data/ProjectTox-Core/toxcore/TCP_client.h +156 -0
  81. data/ProjectTox-Core/toxcore/TCP_server.c +1332 -0
  82. data/ProjectTox-Core/toxcore/TCP_server.h +181 -0
  83. data/ProjectTox-Core/toxcore/assoc.c +1033 -0
  84. data/ProjectTox-Core/toxcore/assoc.h +104 -0
  85. data/ProjectTox-Core/toxcore/crypto_core.c +278 -0
  86. data/ProjectTox-Core/toxcore/crypto_core.h +151 -0
  87. data/ProjectTox-Core/toxcore/friend_requests.c +175 -0
  88. data/ProjectTox-Core/toxcore/friend_requests.h +83 -0
  89. data/ProjectTox-Core/toxcore/group_chats.c +837 -0
  90. data/ProjectTox-Core/toxcore/group_chats.h +199 -0
  91. data/ProjectTox-Core/toxcore/list.c +256 -0
  92. data/ProjectTox-Core/toxcore/list.h +85 -0
  93. data/ProjectTox-Core/toxcore/logger.c +153 -0
  94. data/ProjectTox-Core/toxcore/logger.h +84 -0
  95. data/ProjectTox-Core/toxcore/misc_tools.h +70 -0
  96. data/ProjectTox-Core/toxcore/net_crypto.c +2753 -0
  97. data/ProjectTox-Core/toxcore/net_crypto.h +410 -0
  98. data/ProjectTox-Core/toxcore/network.c +979 -0
  99. data/ProjectTox-Core/toxcore/network.h +367 -0
  100. data/ProjectTox-Core/toxcore/onion.c +540 -0
  101. data/ProjectTox-Core/toxcore/onion.h +150 -0
  102. data/ProjectTox-Core/toxcore/onion_announce.c +433 -0
  103. data/ProjectTox-Core/toxcore/onion_announce.h +139 -0
  104. data/ProjectTox-Core/toxcore/onion_client.c +1347 -0
  105. data/ProjectTox-Core/toxcore/onion_client.h +253 -0
  106. data/ProjectTox-Core/toxcore/ping.c +346 -0
  107. data/ProjectTox-Core/toxcore/ping.h +47 -0
  108. data/ProjectTox-Core/toxcore/ping_array.c +162 -0
  109. data/ProjectTox-Core/toxcore/ping_array.h +75 -0
  110. data/ProjectTox-Core/toxcore/tox.c +940 -0
  111. data/ProjectTox-Core/toxcore/tox.h +734 -0
  112. data/ProjectTox-Core/toxcore/util.c +193 -0
  113. data/ProjectTox-Core/toxcore/util.h +63 -0
  114. data/ProjectTox-Core/toxdns/Makefile.inc +29 -0
  115. data/ProjectTox-Core/toxdns/toxdns.c +238 -0
  116. data/ProjectTox-Core/toxdns/toxdns.h +88 -0
  117. data/ProjectTox-Core/toxencryptsave/Makefile.inc +45 -0
  118. data/ProjectTox-Core/toxencryptsave/toxencryptsave.c +179 -0
  119. data/ProjectTox-Core/toxencryptsave/toxencryptsave.h +74 -0
  120. data/interfaces/libtox.i +2 -6
  121. data/lib/ffi-tox/libtox.rb +406 -28
  122. metadata +124 -46
  123. data/ProjectTox-Core/CMakeLists.txt +0 -50
  124. data/ProjectTox-Core/cmake/FindLIBCONFIG.cmake +0 -15
  125. data/ProjectTox-Core/cmake/FindNaCl.cmake +0 -17
  126. data/ProjectTox-Core/cmake/FindSODIUM.cmake +0 -15
  127. data/ProjectTox-Core/core/CMakeLists.txt +0 -19
  128. data/ProjectTox-Core/core/DHT.c +0 -1104
  129. data/ProjectTox-Core/core/DHT.h +0 -111
  130. data/ProjectTox-Core/core/LAN_discovery.c +0 -79
  131. data/ProjectTox-Core/core/Lossless_UDP.c +0 -755
  132. data/ProjectTox-Core/core/Lossless_UDP.h +0 -106
  133. data/ProjectTox-Core/core/Messenger.c +0 -596
  134. data/ProjectTox-Core/core/Messenger.h +0 -165
  135. data/ProjectTox-Core/core/friend_requests.c +0 -131
  136. data/ProjectTox-Core/core/friend_requests.h +0 -51
  137. data/ProjectTox-Core/core/net_crypto.c +0 -575
  138. data/ProjectTox-Core/core/net_crypto.h +0 -134
  139. data/ProjectTox-Core/core/network.c +0 -205
  140. data/ProjectTox-Core/core/network.h +0 -134
  141. data/ProjectTox-Core/docs/commands.md +0 -25
  142. data/ProjectTox-Core/docs/start_guide.de.md +0 -40
  143. data/ProjectTox-Core/docs/start_guide.md +0 -38
  144. data/ProjectTox-Core/other/CMakeLists.txt +0 -9
  145. data/ProjectTox-Core/testing/CMakeLists.txt +0 -18
  146. data/ProjectTox-Core/testing/DHT_cryptosendfiletest.c +0 -228
  147. data/ProjectTox-Core/testing/DHT_sendfiletest.c +0 -176
  148. data/ProjectTox-Core/testing/Lossless_UDP_testclient.c +0 -214
  149. data/ProjectTox-Core/testing/Lossless_UDP_testserver.c +0 -201
  150. data/ProjectTox-Core/testing/misc_tools.h +0 -29
  151. data/ProjectTox-Core/testing/nTox_win32.c +0 -387
  152. data/ProjectTox-Core/testing/nTox_win32.h +0 -40
  153. data/ProjectTox-Core/testing/rect.py +0 -45
@@ -0,0 +1,35 @@
1
+ SUBDIRS = build
2
+
3
+ ACLOCAL_AMFLAGS = -I m4
4
+
5
+ pkgconfigdir = $(libdir)/pkgconfig
6
+
7
+
8
+ pkgconfig_DATA = $(top_builddir)/libtoxcore.pc
9
+ BUILT_SOURCES = $(top_builddir)/libtoxcore.pc
10
+ CLEANFILES = $(top_builddir)/libtoxcore.pc
11
+
12
+
13
+ EXTRA_DIST = \
14
+ libtoxcore.pc.in \
15
+ dist-build/android-arm.sh \
16
+ dist-build/android-armv7.sh \
17
+ dist-build/android-x86.sh \
18
+ dist-build/android-mips.sh \
19
+ dist-build/android-build.sh \
20
+ $(top_srcdir)/docs/updates/Crypto.md \
21
+ $(top_srcdir)/docs/updates/Spam-Prevention.md \
22
+ $(top_srcdir)/docs/updates/Symmetric-NAT-Transversal.md \
23
+ $(top_srcdir)/tools/README \
24
+ $(top_srcdir)/tools/astylerc \
25
+ $(top_srcdir)/tools/pre-commit
26
+
27
+ if BUILD_AV
28
+
29
+ pkgconfig_DATA += $(top_builddir)/libtoxav.pc
30
+ BUILT_SOURCES += $(top_builddir)/libtoxav.pc
31
+ CLEANFILES += $(top_builddir)/libtoxav.pc
32
+
33
+ EXTRA_DIST += libtoxav.pc.in
34
+
35
+ endif
File without changes
@@ -0,0 +1,43 @@
1
+ ![Project Tox](https://raw.github.com/irungentoo/toxcore/master/other/tox.png "Project Tox")
2
+ ***
3
+
4
+ With the rise of governmental monitoring programs, Tox, a FOSS initiative, aims to be an easy to use, all-in-one communication platform that ensures their users full privacy and secure message delivery.<br /> <br />
5
+
6
+ [**Website**](https://tox.im) **|** [**Download**](https://wiki.tox.im/Binaries) **|** [**Wiki**](https://wiki.tox.im/) **|** [**Blog**](https://blog.libtoxcore.so/) **|** [**FAQ**](https://wiki.tox.im/FAQ) **|** [**Binaries**](https://wiki.tox.im/Binaries) **|** [**Clients**](https://wiki.tox.im/Client) **|** [**Compiling**](/INSTALL.md) **|**
7
+ [**API**](https://libtoxcore.so/) **|**
8
+ **IRC:** #tox@freenode
9
+
10
+
11
+ ## The Complex Stuff:
12
+ ### UDP vs. TCP
13
+ Tox must use UDP simply because [hole punching](https://en.wikipedia.org/wiki/UDP_hole_punching) with TCP is not as reliable.
14
+ However, Tox does use [TCP relays](/docs/TCP_Network.txt) as a fallback if it encounters a firewall that prevents UDP hole punching.
15
+
16
+ ### Connecting & Communicating
17
+ Every peer is represented as a [byte string][String] (the public key [Tox ID] of the peer). By using torrent-style DHT, peers can find the IP of other peers by using their Tox ID. Once the IP is obtained, peers can initiate a [secure](/docs/updates/Crypto.md) connection with each other. Once the connection is made, peers can exchange messages, send files, start video chats, etc. using encrypted communications.
18
+
19
+
20
+ **Current build status:** [![Build Status](https://travis-ci.org/irungentoo/toxcore.png?branch=master)](https://travis-ci.org/irungentoo/toxcore)
21
+
22
+
23
+ ## Q&A:
24
+
25
+ ### What are your goals of Tox?
26
+
27
+ We want Tox to be as simple as possible while remaining as secure as possible.
28
+
29
+ ### Why are you doing this? There are already a bunch of free Skype alternatives.
30
+ The goal of this project is to create a configuration-free P2P Skype replacement. “Configuration-free” means that the user will simply have to open the program and will be capable of adding people and communicating with them without having to set up an account. There are many so-called Skype replacements, but all of them are either hard to configure for the normal user or suffer from being way too centralized.
31
+
32
+ ## TODO:
33
+ - [TODO](/docs/TODO)
34
+
35
+
36
+ ## Documentation:
37
+
38
+ - [Compiling](/INSTALL.md)
39
+ - [DHT Protocol](/docs/updates/DHT.md)<br />
40
+ - [Crypto](/docs/updates/Crypto.md)<br />
41
+ - [Ideas](https://wiki.tox.im/index.php/Ideas)
42
+
43
+ [String]: https://en.wikipedia.org/wiki/String_(computer_science)
@@ -1,53 +1,43 @@
1
- ![Project Tox](https://rbt.asia/boards/g/img/0352/79/1373823047559.png "Project Tox")
2
- Project Tox, _also known as Tox_, is a FOSS (Free and Open Source Software) instant messaging application aimed to replace Skype.<br />
1
+ ![Project Tox](https://raw.github.com/irungentoo/toxcore/master/other/tox.png "Project Tox")
2
+ ***
3
3
 
4
- With the rise of governmental monitoring programs, Tox aims to be an easy to use, all-in-one communication platform (including audio, and videochats in the future) that ensures their users full privacy and secure message delivery.<br /> <br />
4
+ With the rise of governmental monitoring programs, Tox, a FOSS initiative, aims to be an easy to use, all-in-one communication platform that ensures their users full privacy and secure message delivery.<br /> <br />
5
5
 
6
+ [**Website**](https://tox.im) **|** [**Download**](https://wiki.tox.im/Binaries) **|** [**Wiki**](https://wiki.tox.im/) **|** [**Blog**](https://blog.libtoxcore.so/) **|** [**FAQ**](https://wiki.tox.im/FAQ) **|** [**Binaries**](https://wiki.tox.im/Binaries) **|** [**Clients**](https://wiki.tox.im/Client) **|** [**Compiling**](/INSTALL.md) **|**
7
+ [**API**](https://libtoxcore.so/) **|**
8
+ **IRC:** #tox@freenode
6
9
 
7
10
 
8
- **IRC**: #tox on freenode, alternatively, you can use the [webchat](http://webchat.freenode.net/?channels=#tox).<br />
9
- **Website**: [http://tox.im](http://tox.im)
11
+ ## The Complex Stuff:
12
+ ### UDP vs. TCP
13
+ Tox must use UDP simply because [hole punching](https://en.wikipedia.org/wiki/UDP_hole_punching) with TCP is not as reliable.
14
+ However, Tox does use [TCP relays](/docs/TCP_Network.txt) as a fallback if it encounters a firewall that prevents UDP hole punching.
10
15
 
11
- **Website translations**: [see stal888's repository](https://github.com/stal888/ProjectTox-Website)<br/>
12
- **Qt GUI**: [see nurupo's repository](https://github.com/nurupo/ProjectTox-Qt-GUI)
16
+ ### Connecting & Communicating
17
+ Every peer is represented as a [byte string][String] (the public key [Tox ID] of the peer). By using torrent-style DHT, peers can find the IP of other peers by using their Tox ID. Once the IP is obtained, peers can initiate a [secure](/docs/updates/Crypto.md) connection with each other. Once the connection is made, peers can exchange messages, send files, start video chats, etc. using encrypted communications.
13
18
 
14
- **How to build Tox on Linux**: [YouTube video](http://www.youtube.com/watch?v=M4WXE4VKmyg)<br />
15
- **How to use Tox on Windows**: [YouTube video](http://www.youtube.com/watch?v=qg_j_sDb6WQ)<br />
16
- **For Mac OSX read INSTALL.md**
17
19
 
18
- ### Objectives:
20
+ **Current build status:** [![Build Status](https://travis-ci.org/irungentoo/toxcore.png?branch=master)](https://travis-ci.org/irungentoo/toxcore)
19
21
 
20
- Keep everything really simple.
21
22
 
22
- ## The Complex Stuff:
23
- + Tox must use UDP simply because [hole punching](http://en.wikipedia.org/wiki/UDP_hole_punching) with TCP is not as reliable.
24
- + Every peer is represented as a [byte string](https://en.wikipedia.org/wiki/String_(computer_science)) (the public key of the peer [client ID]).
25
- + We're using torrent-style DHT so that peers can find the IP of the other peers when they have their ID.
26
- + Once the client has the IP of that peer, they start initiating a secure connection with each other. (See [Crypto](https://github.com/irungentoo/ProjectTox-Core/wiki/Crypto))
27
- + When both peers are securely connected, they can exchange messages, initiate a video chat, send files, etc, all using encrypted communications.
28
- + Current build status: [![Build Status](https://travis-ci.org/irungentoo/ProjectTox-Core.png?branch=master)](https://travis-ci.org/irungentoo/ProjectTox-Core)
29
-
30
- ## Roadmap:
31
- - [x] Get our DHT working perfectly. (Done, needs large scale testing though)
32
- - [x] Reliable connection (See Lossless UDP protocol) to other peers according to client ID. (Done, see `DHT_sendfiletest.c` for an example)
33
- - [x] Encryption. (Done)
34
- - [ ] Get a simple text only IM client working perfectly. (This is where we are)
35
- - [ ] Streaming media
36
- - [ ] ???
37
-
38
- For further information, check our [To-do list](https://github.com/irungentoo/ProjectTox-Core/wiki/TODO)
39
-
40
- ### Why are you doing this? There are already a bunch of free skype alternatives.
41
- The goal of this project is to create a configuration-free P2P skype
42
- replacement. Configuration-free means that the user will simply have to open the program and
43
- without any account configuration will be capable of adding people to his
44
- friends list and start conversing with them. There are many so-called skype replacements and all of them are either hard to
45
- configure for the normal user or suffer from being way too centralized.
46
-
47
- ### Documentation:
48
-
49
- - [Installation](/INSTALL.md)
50
- - [DHT Protocol](https://github.com/irungentoo/ProjectTox-Core/wiki/DHT)<br />
51
- - [Lossless UDP Protocol](https://github.com/irungentoo/ProjectTox-Core/wiki/Lossless-UDP)<br />
52
- - [Crypto](https://github.com/irungentoo/ProjectTox-Core/wiki/Crypto)<br />
53
- - [Ideas](https://github.com/irungentoo/ProjectTox-Core/wiki/Ideas)
23
+ ## Q&A:
24
+
25
+ ### What are your goals of Tox?
26
+
27
+ We want Tox to be as simple as possible while remaining as secure as possible.
28
+
29
+ ### Why are you doing this? There are already a bunch of free Skype alternatives.
30
+ The goal of this project is to create a configuration-free P2P Skype replacement. “Configuration-free” means that the user will simply have to open the program and will be capable of adding people and communicating with them without having to set up an account. There are many so-called Skype replacements, but all of them are either hard to configure for the normal user or suffer from being way too centralized.
31
+
32
+ ## TODO:
33
+ - [TODO](/docs/TODO)
34
+
35
+
36
+ ## Documentation:
37
+
38
+ - [Compiling](/INSTALL.md)
39
+ - [DHT Protocol](/docs/updates/DHT.md)<br />
40
+ - [Crypto](/docs/updates/Crypto.md)<br />
41
+ - [Ideas](https://wiki.tox.im/index.php/Ideas)
42
+
43
+ [String]: https://en.wikipedia.org/wiki/String_(computer_science)
@@ -0,0 +1,110 @@
1
+ if BUILD_TESTS
2
+
3
+ TESTS = encryptsave_test messenger_autotest crypto_test network_test assoc_test onion_test TCP_test tox_test dht_autotest
4
+ check_PROGRAMS = encryptsave_test messenger_autotest crypto_test network_test assoc_test onion_test TCP_test tox_test dht_autotest
5
+
6
+ AUTOTEST_CFLAGS = \
7
+ $(LIBSODIUM_CFLAGS) \
8
+ $(NACL_CFLAGS) \
9
+ $(CHECK_CFLAGS)
10
+
11
+ AUTOTEST_LDADD = \
12
+ $(LIBSODIUM_LDFLAGS) \
13
+ $(NACL_LDFLAGS) \
14
+ libtoxcore.la \
15
+ libtoxencryptsave.la \
16
+ $(LIBSODIUM_LIBS) \
17
+ $(NACL_OBJECTS) \
18
+ $(NACL_LIBS) \
19
+ $(CHECK_LIBS)
20
+
21
+
22
+
23
+ if BUILD_AV
24
+ TESTS += toxav_basic_test toxav_many_test
25
+ check_PROGRAMS += toxav_basic_test toxav_many_test
26
+ AUTOTEST_LDADD += libtoxav.la
27
+ endif
28
+
29
+ messenger_autotest_SOURCES = ../auto_tests/messenger_test.c
30
+
31
+ messenger_autotest_CFLAGS = $(AUTOTEST_CFLAGS)
32
+
33
+ messenger_autotest_LDADD = $(AUTOTEST_LDADD)
34
+
35
+
36
+ crypto_test_SOURCES = ../auto_tests/crypto_test.c
37
+
38
+ crypto_test_CFLAGS = $(AUTOTEST_CFLAGS)
39
+
40
+ crypto_test_LDADD = $(AUTOTEST_LDADD)
41
+
42
+
43
+ network_test_SOURCES = ../auto_tests/network_test.c
44
+
45
+ network_test_CFLAGS = $(AUTOTEST_CFLAGS)
46
+
47
+ network_test_LDADD = $(AUTOTEST_LDADD)
48
+
49
+
50
+ assoc_test_SOURCES = ../auto_tests/assoc_test.c
51
+
52
+ assoc_test_CFLAGS = $(AUTOTEST_CFLAGS)
53
+
54
+ assoc_test_LDADD = $(AUTOTEST_LDADD)
55
+
56
+
57
+ onion_test_SOURCES = ../auto_tests/onion_test.c
58
+
59
+ onion_test_CFLAGS = $(AUTOTEST_CFLAGS)
60
+
61
+ onion_test_LDADD = $(AUTOTEST_LDADD)
62
+
63
+
64
+ TCP_test_SOURCES = ../auto_tests/TCP_test.c
65
+
66
+ TCP_test_CFLAGS = $(AUTOTEST_CFLAGS)
67
+
68
+ TCP_test_LDADD = $(AUTOTEST_LDADD)
69
+
70
+
71
+ tox_test_SOURCES = ../auto_tests/tox_test.c
72
+
73
+ tox_test_CFLAGS = $(AUTOTEST_CFLAGS)
74
+
75
+ tox_test_LDADD = $(AUTOTEST_LDADD)
76
+
77
+
78
+ dht_autotest_SOURCES = ../auto_tests/dht_test.c
79
+
80
+ dht_autotest_CFLAGS = $(AUTOTEST_CFLAGS)
81
+
82
+ dht_autotest_LDADD = $(AUTOTEST_LDADD)
83
+
84
+
85
+ if BUILD_AV
86
+ toxav_basic_test_SOURCES = ../auto_tests/toxav_basic_test.c
87
+
88
+ toxav_basic_test_CFLAGS = $(AUTOTEST_CFLAGS)
89
+
90
+ toxav_basic_test_LDADD = $(AUTOTEST_LDADD) $(AV_LIBS)
91
+
92
+
93
+ toxav_many_test_SOURCES = ../auto_tests/toxav_many_test.c
94
+
95
+ toxav_many_test_CFLAGS = $(AUTOTEST_CFLAGS)
96
+
97
+ toxav_many_test_LDADD = $(AUTOTEST_LDADD)
98
+ endif
99
+
100
+ endif
101
+
102
+
103
+ encryptsave_test_SOURCES = ../auto_tests/encryptsave_test.c
104
+
105
+ encryptsave_test_CFLAGS = $(AUTOTEST_CFLAGS)
106
+
107
+ encryptsave_test_LDADD = $(AUTOTEST_LDADD)
108
+
109
+
110
+ EXTRA_DIST += $(top_srcdir)/auto_tests/friends_test.c
@@ -0,0 +1,519 @@
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 "../toxcore/TCP_server.h"
13
+ #include "../toxcore/TCP_client.h"
14
+
15
+ #include "../toxcore/util.h"
16
+
17
+ #include "helpers.h"
18
+
19
+ #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
20
+ #define c_sleep(x) Sleep(1*x)
21
+ #else
22
+ #include <unistd.h>
23
+ #define c_sleep(x) usleep(1000*x)
24
+ #endif
25
+
26
+ #define NUM_PORTS 3
27
+
28
+ uint16_t ports[NUM_PORTS] = {1234, 33445, 25643};
29
+
30
+ START_TEST(test_basic)
31
+ {
32
+ uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
33
+ uint8_t self_secret_key[crypto_box_SECRETKEYBYTES];
34
+ crypto_box_keypair(self_public_key, self_secret_key);
35
+ TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_public_key, self_secret_key, NULL);
36
+ ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server");
37
+ ck_assert_msg(tcp_s->num_listening_socks == NUM_PORTS, "Failed to bind to all ports");
38
+
39
+ sock_t sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
40
+ struct sockaddr_in6 addr6_loopback = {0};
41
+ addr6_loopback.sin6_family = AF_INET6;
42
+ addr6_loopback.sin6_port = htons(ports[rand() % NUM_PORTS]);
43
+ addr6_loopback.sin6_addr = in6addr_loopback;
44
+
45
+ int ret = connect(sock, (struct sockaddr *)&addr6_loopback, sizeof(addr6_loopback));
46
+ ck_assert_msg(ret == 0, "Failed to connect to TCP relay server");
47
+
48
+ uint8_t f_public_key[crypto_box_PUBLICKEYBYTES];
49
+ uint8_t f_secret_key[crypto_box_SECRETKEYBYTES];
50
+ uint8_t f_nonce[crypto_box_NONCEBYTES];
51
+ crypto_box_keypair(f_public_key, f_secret_key);
52
+ random_nonce(f_nonce);
53
+
54
+ uint8_t t_secret_key[crypto_box_SECRETKEYBYTES];
55
+ uint8_t handshake_plain[TCP_HANDSHAKE_PLAIN_SIZE];
56
+ crypto_box_keypair(handshake_plain, t_secret_key);
57
+ memcpy(handshake_plain + crypto_box_PUBLICKEYBYTES, f_nonce, crypto_box_NONCEBYTES);
58
+ uint8_t handshake[TCP_CLIENT_HANDSHAKE_SIZE];
59
+ memcpy(handshake, f_public_key, crypto_box_PUBLICKEYBYTES);
60
+ new_nonce(handshake + crypto_box_PUBLICKEYBYTES);
61
+
62
+ ret = encrypt_data(self_public_key, f_secret_key, handshake + crypto_box_PUBLICKEYBYTES, handshake_plain,
63
+ TCP_HANDSHAKE_PLAIN_SIZE, handshake + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES);
64
+ ck_assert_msg(ret == TCP_CLIENT_HANDSHAKE_SIZE - (crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES),
65
+ "Encrypt failed.");
66
+ ck_assert_msg(send(sock, handshake, TCP_CLIENT_HANDSHAKE_SIZE - 1, 0) == TCP_CLIENT_HANDSHAKE_SIZE - 1, "send Failed.");
67
+ c_sleep(50);
68
+ do_TCP_server(tcp_s);
69
+ c_sleep(50);
70
+ do_TCP_server(tcp_s);
71
+ c_sleep(50);
72
+ ck_assert_msg(send(sock, handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1), 1, 0) == 1, "send Failed.");
73
+ c_sleep(50);
74
+ do_TCP_server(tcp_s);
75
+ c_sleep(50);
76
+ do_TCP_server(tcp_s);
77
+ c_sleep(50);
78
+ uint8_t response[TCP_SERVER_HANDSHAKE_SIZE];
79
+ uint8_t response_plain[TCP_HANDSHAKE_PLAIN_SIZE];
80
+ ck_assert_msg(recv(sock, response, TCP_SERVER_HANDSHAKE_SIZE, 0) == TCP_SERVER_HANDSHAKE_SIZE, "recv Failed.");
81
+ ret = decrypt_data(self_public_key, f_secret_key, response, response + crypto_box_NONCEBYTES,
82
+ TCP_SERVER_HANDSHAKE_SIZE - crypto_box_NONCEBYTES, response_plain);
83
+ ck_assert_msg(ret == TCP_HANDSHAKE_PLAIN_SIZE, "Decrypt Failed.");
84
+ uint8_t f_nonce_r[crypto_box_NONCEBYTES];
85
+ uint8_t f_shared_key[crypto_box_BEFORENMBYTES];
86
+ encrypt_precompute(response_plain, t_secret_key, f_shared_key);
87
+ memcpy(f_nonce_r, response_plain + crypto_box_BEFORENMBYTES, crypto_box_NONCEBYTES);
88
+
89
+ uint8_t r_req_p[1 + crypto_box_PUBLICKEYBYTES] = {0};
90
+ memcpy(r_req_p + 1, f_public_key, crypto_box_PUBLICKEYBYTES);
91
+ uint8_t r_req[2 + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES];
92
+ uint16_t size = 1 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES;
93
+ size = htons(size);
94
+ ret = encrypt_data_symmetric(f_shared_key, f_nonce, r_req_p, 1 + crypto_box_PUBLICKEYBYTES, r_req + 2);
95
+ increment_nonce(f_nonce);
96
+ memcpy(r_req, &size, 2);
97
+ uint32_t i;
98
+
99
+ for (i = 0; i < sizeof(r_req); ++i) {
100
+ ck_assert_msg(send(sock, r_req + i, 1, 0) == 1, "send Failed.");
101
+ //ck_assert_msg(send(sock, r_req, sizeof(r_req), 0) == sizeof(r_req), "send Failed.");
102
+ do_TCP_server(tcp_s);
103
+ c_sleep(50);
104
+ }
105
+
106
+ do_TCP_server(tcp_s);
107
+ c_sleep(50);
108
+ uint8_t packet_resp[4096];
109
+ int recv_data_len;
110
+ ck_assert_msg((recv_data_len = recv(sock, packet_resp, 2 + 2 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES,
111
+ 0)) == 2 + 2 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES, "recv Failed. %u", recv_data_len);
112
+ memcpy(&size, packet_resp, 2);
113
+ ck_assert_msg(ntohs(size) == 2 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES, "Wrong packet size.");
114
+ uint8_t packet_resp_plain[4096];
115
+ ret = decrypt_data_symmetric(f_shared_key, f_nonce_r, packet_resp + 2, recv_data_len - 2, packet_resp_plain);
116
+ ck_assert_msg(ret != -1, "decryption failed");
117
+ increment_nonce(f_nonce_r);
118
+ ck_assert_msg(packet_resp_plain[0] == 1, "wrong packet id %u", packet_resp_plain[0]);
119
+ ck_assert_msg(packet_resp_plain[1] == 0, "connection not refused %u", packet_resp_plain[1]);
120
+ ck_assert_msg(memcmp(packet_resp_plain + 2, f_public_key, crypto_box_PUBLICKEYBYTES) == 0, "key in packet wrong");
121
+ }
122
+ END_TEST
123
+
124
+ struct sec_TCP_con {
125
+ sock_t sock;
126
+ uint8_t public_key[crypto_box_PUBLICKEYBYTES];
127
+ uint8_t recv_nonce[crypto_box_NONCEBYTES];
128
+ uint8_t sent_nonce[crypto_box_NONCEBYTES];
129
+ uint8_t shared_key[crypto_box_BEFORENMBYTES];
130
+ };
131
+
132
+ struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s)
133
+ {
134
+ struct sec_TCP_con *sec_c = malloc(sizeof(struct sec_TCP_con));
135
+ sock_t sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
136
+ struct sockaddr_in6 addr6_loopback = {0};
137
+ addr6_loopback.sin6_family = AF_INET6;
138
+ addr6_loopback.sin6_port = htons(ports[rand() % NUM_PORTS]);
139
+ addr6_loopback.sin6_addr = in6addr_loopback;
140
+
141
+ int ret = connect(sock, (struct sockaddr *)&addr6_loopback, sizeof(addr6_loopback));
142
+ ck_assert_msg(ret == 0, "Failed to connect to TCP relay server");
143
+
144
+ uint8_t f_secret_key[crypto_box_SECRETKEYBYTES];
145
+ crypto_box_keypair(sec_c->public_key, f_secret_key);
146
+ random_nonce(sec_c->sent_nonce);
147
+
148
+ uint8_t t_secret_key[crypto_box_SECRETKEYBYTES];
149
+ uint8_t handshake_plain[TCP_HANDSHAKE_PLAIN_SIZE];
150
+ crypto_box_keypair(handshake_plain, t_secret_key);
151
+ memcpy(handshake_plain + crypto_box_PUBLICKEYBYTES, sec_c->sent_nonce, crypto_box_NONCEBYTES);
152
+ uint8_t handshake[TCP_CLIENT_HANDSHAKE_SIZE];
153
+ memcpy(handshake, sec_c->public_key, crypto_box_PUBLICKEYBYTES);
154
+ new_nonce(handshake + crypto_box_PUBLICKEYBYTES);
155
+
156
+ ret = encrypt_data(tcp_s->public_key, f_secret_key, handshake + crypto_box_PUBLICKEYBYTES, handshake_plain,
157
+ TCP_HANDSHAKE_PLAIN_SIZE, handshake + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES);
158
+ ck_assert_msg(ret == TCP_CLIENT_HANDSHAKE_SIZE - (crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES),
159
+ "Encrypt failed.");
160
+ ck_assert_msg(send(sock, handshake, TCP_CLIENT_HANDSHAKE_SIZE - 1, 0) == TCP_CLIENT_HANDSHAKE_SIZE - 1, "send Failed.");
161
+ do_TCP_server(tcp_s);
162
+ c_sleep(50);
163
+ ck_assert_msg(send(sock, handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1), 1, 0) == 1, "send Failed.");
164
+ c_sleep(50);
165
+ do_TCP_server(tcp_s);
166
+ uint8_t response[TCP_SERVER_HANDSHAKE_SIZE];
167
+ uint8_t response_plain[TCP_HANDSHAKE_PLAIN_SIZE];
168
+ ck_assert_msg(recv(sock, response, TCP_SERVER_HANDSHAKE_SIZE, 0) == TCP_SERVER_HANDSHAKE_SIZE, "recv Failed.");
169
+ ret = decrypt_data(tcp_s->public_key, f_secret_key, response, response + crypto_box_NONCEBYTES,
170
+ TCP_SERVER_HANDSHAKE_SIZE - crypto_box_NONCEBYTES, response_plain);
171
+ ck_assert_msg(ret == TCP_HANDSHAKE_PLAIN_SIZE, "Decrypt Failed.");
172
+ encrypt_precompute(response_plain, t_secret_key, sec_c->shared_key);
173
+ memcpy(sec_c->recv_nonce, response_plain + crypto_box_BEFORENMBYTES, crypto_box_NONCEBYTES);
174
+ sec_c->sock = sock;
175
+ return sec_c;
176
+ }
177
+
178
+ int write_packet_TCP_secure_connection(struct sec_TCP_con *con, uint8_t *data, uint16_t length)
179
+ {
180
+ uint8_t packet[sizeof(uint16_t) + length + crypto_box_MACBYTES];
181
+
182
+ uint16_t c_length = htons(length + crypto_box_MACBYTES);
183
+ memcpy(packet, &c_length, sizeof(uint16_t));
184
+ int len = encrypt_data_symmetric(con->shared_key, con->sent_nonce, data, length, packet + sizeof(uint16_t));
185
+
186
+ if ((unsigned int)len != (sizeof(packet) - sizeof(uint16_t)))
187
+ return -1;
188
+
189
+ increment_nonce(con->sent_nonce);
190
+
191
+ ck_assert_msg(send(con->sock, packet, sizeof(packet), 0) == sizeof(packet), "send failed");
192
+ return 0;
193
+ }
194
+
195
+ int read_packet_sec_TCP(struct sec_TCP_con *con, uint8_t *data, uint16_t length)
196
+ {
197
+ int len;
198
+ ck_assert_msg((len = recv(con->sock, data, length, 0)) == length, "wrong len %i\n", len);
199
+ ck_assert_msg((len = decrypt_data_symmetric(con->shared_key, con->recv_nonce, data + 2, length - 2, data)) != -1,
200
+ "Decrypt failed");
201
+ increment_nonce(con->recv_nonce);
202
+ return len;
203
+ }
204
+
205
+ START_TEST(test_some)
206
+ {
207
+ uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
208
+ uint8_t self_secret_key[crypto_box_SECRETKEYBYTES];
209
+ crypto_box_keypair(self_public_key, self_secret_key);
210
+ TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_public_key, self_secret_key, NULL);
211
+ ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server");
212
+ ck_assert_msg(tcp_s->num_listening_socks == NUM_PORTS, "Failed to bind to all ports");
213
+
214
+ struct sec_TCP_con *con1 = new_TCP_con(tcp_s);
215
+ struct sec_TCP_con *con2 = new_TCP_con(tcp_s);
216
+ struct sec_TCP_con *con3 = new_TCP_con(tcp_s);
217
+
218
+ uint8_t requ_p[1 + crypto_box_PUBLICKEYBYTES];
219
+ requ_p[0] = 0;
220
+ memcpy(requ_p + 1, con3->public_key, crypto_box_PUBLICKEYBYTES);
221
+ write_packet_TCP_secure_connection(con1, requ_p, sizeof(requ_p));
222
+ memcpy(requ_p + 1, con1->public_key, crypto_box_PUBLICKEYBYTES);
223
+ write_packet_TCP_secure_connection(con3, requ_p, sizeof(requ_p));
224
+ do_TCP_server(tcp_s);
225
+ c_sleep(50);
226
+ uint8_t data[2048];
227
+ int len = read_packet_sec_TCP(con1, data, 2 + 1 + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES);
228
+ ck_assert_msg(len == 1 + 1 + crypto_box_PUBLICKEYBYTES, "wrong len %u", len);
229
+ ck_assert_msg(data[0] == 1, "wrong packet id %u", data[0]);
230
+ ck_assert_msg(data[1] == 16, "connection not refused %u", data[1]);
231
+ ck_assert_msg(memcmp(data + 2, con3->public_key, crypto_box_PUBLICKEYBYTES) == 0, "key in packet wrong");
232
+ len = read_packet_sec_TCP(con3, data, 2 + 1 + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES);
233
+ ck_assert_msg(len == 1 + 1 + crypto_box_PUBLICKEYBYTES, "wrong len %u", len);
234
+ ck_assert_msg(data[0] == 1, "wrong packet id %u", data[0]);
235
+ ck_assert_msg(data[1] == 16, "connection not refused %u", data[1]);
236
+ ck_assert_msg(memcmp(data + 2, con1->public_key, crypto_box_PUBLICKEYBYTES) == 0, "key in packet wrong");
237
+
238
+ uint8_t test_packet[512] = {16, 17, 16, 86, 99, 127, 255, 189, 78};
239
+ write_packet_TCP_secure_connection(con3, test_packet, sizeof(test_packet));
240
+ write_packet_TCP_secure_connection(con3, test_packet, sizeof(test_packet));
241
+ write_packet_TCP_secure_connection(con3, test_packet, sizeof(test_packet));
242
+ c_sleep(50);
243
+ do_TCP_server(tcp_s);
244
+ c_sleep(50);
245
+ len = read_packet_sec_TCP(con1, data, 2 + 2 + crypto_box_MACBYTES);
246
+ ck_assert_msg(len == 2, "wrong len %u", len);
247
+ ck_assert_msg(data[0] == 2, "wrong packet id %u", data[0]);
248
+ ck_assert_msg(data[1] == 16, "wrong peer id %u", data[1]);
249
+ len = read_packet_sec_TCP(con3, data, 2 + 2 + crypto_box_MACBYTES);
250
+ ck_assert_msg(len == 2, "wrong len %u", len);
251
+ ck_assert_msg(data[0] == 2, "wrong packet id %u", data[0]);
252
+ ck_assert_msg(data[1] == 16, "wrong peer id %u", data[1]);
253
+ len = read_packet_sec_TCP(con1, data, 2 + sizeof(test_packet) + crypto_box_MACBYTES);
254
+ ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len);
255
+ ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
256
+ data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
257
+ len = read_packet_sec_TCP(con1, data, 2 + sizeof(test_packet) + crypto_box_MACBYTES);
258
+ ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len);
259
+ ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
260
+ data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
261
+ len = read_packet_sec_TCP(con1, data, 2 + sizeof(test_packet) + crypto_box_MACBYTES);
262
+ ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len);
263
+ ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
264
+ data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
265
+ write_packet_TCP_secure_connection(con1, test_packet, sizeof(test_packet));
266
+ write_packet_TCP_secure_connection(con1, test_packet, sizeof(test_packet));
267
+ write_packet_TCP_secure_connection(con1, test_packet, sizeof(test_packet));
268
+ c_sleep(50);
269
+ do_TCP_server(tcp_s);
270
+ c_sleep(50);
271
+ len = read_packet_sec_TCP(con3, data, 2 + sizeof(test_packet) + crypto_box_MACBYTES);
272
+ ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len);
273
+ ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
274
+ data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
275
+ len = read_packet_sec_TCP(con3, data, 2 + sizeof(test_packet) + crypto_box_MACBYTES);
276
+ ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len);
277
+ ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
278
+ data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
279
+ len = read_packet_sec_TCP(con3, data, 2 + sizeof(test_packet) + crypto_box_MACBYTES);
280
+ ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len);
281
+ ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
282
+ data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
283
+
284
+ uint8_t ping_packet[1 + sizeof(uint64_t)] = {4, 8, 6, 9, 67};
285
+ write_packet_TCP_secure_connection(con1, ping_packet, sizeof(ping_packet));
286
+ c_sleep(50);
287
+ do_TCP_server(tcp_s);
288
+ c_sleep(50);
289
+ len = read_packet_sec_TCP(con1, data, 2 + sizeof(ping_packet) + crypto_box_MACBYTES);
290
+ ck_assert_msg(len == sizeof(ping_packet), "wrong len %u", len);
291
+ ck_assert_msg(data[0] == 5, "wrong packet id %u", data[0]);
292
+ ck_assert_msg(memcmp(ping_packet + 1, data + 1, sizeof(uint64_t)) == 0, "wrong packet data");
293
+ }
294
+ END_TEST
295
+
296
+ static int response_callback_good;
297
+ static uint8_t response_callback_connection_id;
298
+ static uint8_t response_callback_public_key[crypto_box_PUBLICKEYBYTES];
299
+ static int response_callback(void *object, uint8_t connection_id, const uint8_t *public_key)
300
+ {
301
+ if (set_tcp_connection_number(object - 2, connection_id, 7) != 0)
302
+ return 1;
303
+
304
+ response_callback_connection_id = connection_id;
305
+ memcpy(response_callback_public_key, public_key, crypto_box_PUBLICKEYBYTES);
306
+ response_callback_good++;
307
+ return 0;
308
+ }
309
+ static int status_callback_good;
310
+ static uint8_t status_callback_connection_id;
311
+ static uint8_t status_callback_status;
312
+ static int status_callback(void *object, uint32_t number, uint8_t connection_id, uint8_t status)
313
+ {
314
+ if (object != (void *)2)
315
+ return 1;
316
+
317
+ if (number != 7)
318
+ return 1;
319
+
320
+ status_callback_connection_id = connection_id;
321
+ status_callback_status = status;
322
+ status_callback_good++;
323
+ return 0;
324
+ }
325
+ static int data_callback_good;
326
+ static int data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length)
327
+ {
328
+ if (object != (void *)3)
329
+ return 1;
330
+
331
+ if (number != 7)
332
+ return 1;
333
+
334
+ if (length != 5)
335
+ return 1;
336
+
337
+ if (data[0] == 1 && data[1] == 2 && data[2] == 3 && data[3] == 4 && data[4] == 5) {
338
+ data_callback_good++;
339
+ return 0;
340
+ }
341
+
342
+ return 1;
343
+ }
344
+
345
+ static int oob_data_callback_good;
346
+ static uint8_t oob_pubkey[crypto_box_PUBLICKEYBYTES];
347
+ static int oob_data_callback(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length)
348
+ {
349
+ if (object != (void *)4)
350
+ return 1;
351
+
352
+ if (length != 5)
353
+ return 1;
354
+
355
+ if (memcmp(public_key, oob_pubkey, crypto_box_PUBLICKEYBYTES) != 0)
356
+ return 1;
357
+
358
+ if (data[0] == 1 && data[1] == 2 && data[2] == 3 && data[3] == 4 && data[4] == 5) {
359
+ oob_data_callback_good++;
360
+ return 0;
361
+ }
362
+
363
+ return 1;
364
+ }
365
+
366
+ START_TEST(test_client)
367
+ {
368
+ unix_time_update();
369
+ uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
370
+ uint8_t self_secret_key[crypto_box_SECRETKEYBYTES];
371
+ crypto_box_keypair(self_public_key, self_secret_key);
372
+ TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_public_key, self_secret_key, NULL);
373
+ ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server");
374
+ ck_assert_msg(tcp_s->num_listening_socks == NUM_PORTS, "Failed to bind to all ports");
375
+
376
+ uint8_t f_public_key[crypto_box_PUBLICKEYBYTES];
377
+ uint8_t f_secret_key[crypto_box_SECRETKEYBYTES];
378
+ crypto_box_keypair(f_public_key, f_secret_key);
379
+ IP_Port ip_port_tcp_s;
380
+
381
+ ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]);
382
+ ip_port_tcp_s.ip.family = AF_INET6;
383
+ ip_port_tcp_s.ip.ip6.in6_addr = in6addr_loopback;
384
+ TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, 0);
385
+ c_sleep(50);
386
+ do_TCP_connection(conn);
387
+ ck_assert_msg(conn->status == TCP_CLIENT_UNCONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_UNCONFIRMED,
388
+ conn->status);
389
+ c_sleep(50);
390
+ do_TCP_server(tcp_s);
391
+ c_sleep(50);
392
+ do_TCP_connection(conn);
393
+ ck_assert_msg(conn->status == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONFIRMED,
394
+ conn->status);
395
+ c_sleep(500);
396
+ do_TCP_connection(conn);
397
+ ck_assert_msg(conn->status == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONFIRMED,
398
+ conn->status);
399
+ c_sleep(500);
400
+ do_TCP_connection(conn);
401
+ ck_assert_msg(conn->status == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONFIRMED,
402
+ conn->status);
403
+ do_TCP_server(tcp_s);
404
+ c_sleep(50);
405
+ ck_assert_msg(conn->status == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONFIRMED,
406
+ conn->status);
407
+
408
+ uint8_t f2_public_key[crypto_box_PUBLICKEYBYTES];
409
+ uint8_t f2_secret_key[crypto_box_SECRETKEYBYTES];
410
+ crypto_box_keypair(f2_public_key, f2_secret_key);
411
+ TCP_Client_Connection *conn2 = new_TCP_connection(ip_port_tcp_s, self_public_key, f2_public_key, f2_secret_key, 0);
412
+ routing_response_handler(conn, response_callback, ((void *)conn) + 2);
413
+ routing_status_handler(conn, status_callback, (void *)2);
414
+ routing_data_handler(conn, data_callback, (void *)3);
415
+ oob_data_handler(conn, oob_data_callback, (void *)4);
416
+ oob_data_callback_good = response_callback_good = status_callback_good = data_callback_good = 0;
417
+ c_sleep(50);
418
+ do_TCP_connection(conn);
419
+ do_TCP_connection(conn2);
420
+ c_sleep(50);
421
+ do_TCP_server(tcp_s);
422
+ c_sleep(50);
423
+ do_TCP_connection(conn);
424
+ do_TCP_connection(conn2);
425
+ c_sleep(50);
426
+ uint8_t data[5] = {1, 2, 3, 4, 5};
427
+ memcpy(oob_pubkey, f2_public_key, crypto_box_PUBLICKEYBYTES);
428
+ send_oob_packet(conn2, f_public_key, data, 5);
429
+ send_routing_request(conn, f2_public_key);
430
+ send_routing_request(conn2, f_public_key);
431
+ c_sleep(50);
432
+ do_TCP_server(tcp_s);
433
+ c_sleep(50);
434
+ do_TCP_connection(conn);
435
+ do_TCP_connection(conn2);
436
+ ck_assert_msg(oob_data_callback_good == 1, "oob callback not called");
437
+ ck_assert_msg(response_callback_good == 1, "response callback not called");
438
+ ck_assert_msg(memcmp(response_callback_public_key, f2_public_key, crypto_box_PUBLICKEYBYTES) == 0, "wrong public key");
439
+ ck_assert_msg(status_callback_good == 1, "status callback not called");
440
+ ck_assert_msg(status_callback_status == 2, "wrong status");
441
+ ck_assert_msg(status_callback_connection_id == response_callback_connection_id, "connection ids not equal");
442
+ c_sleep(50);
443
+ do_TCP_server(tcp_s);
444
+ ck_assert_msg(send_data(conn2, 0, data, 5) == 1, "send data failed");
445
+ c_sleep(50);
446
+ do_TCP_server(tcp_s);
447
+ c_sleep(50);
448
+ do_TCP_connection(conn);
449
+ do_TCP_connection(conn2);
450
+ ck_assert_msg(data_callback_good == 1, "data callback not called");
451
+ status_callback_good = 0;
452
+ send_disconnect_request(conn2, 0);
453
+ c_sleep(50);
454
+ do_TCP_server(tcp_s);
455
+ c_sleep(50);
456
+ do_TCP_connection(conn);
457
+ do_TCP_connection(conn2);
458
+ ck_assert_msg(status_callback_good == 1, "status callback not called");
459
+ ck_assert_msg(status_callback_status == 1, "wrong status");
460
+ }
461
+ END_TEST
462
+
463
+ START_TEST(test_client_invalid)
464
+ {
465
+ unix_time_update();
466
+ uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
467
+ uint8_t self_secret_key[crypto_box_SECRETKEYBYTES];
468
+ crypto_box_keypair(self_public_key, self_secret_key);
469
+
470
+ uint8_t f_public_key[crypto_box_PUBLICKEYBYTES];
471
+ uint8_t f_secret_key[crypto_box_SECRETKEYBYTES];
472
+ crypto_box_keypair(f_public_key, f_secret_key);
473
+ IP_Port ip_port_tcp_s;
474
+
475
+ ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]);
476
+ ip_port_tcp_s.ip.family = AF_INET6;
477
+ ip_port_tcp_s.ip.ip6.in6_addr = in6addr_loopback;
478
+ TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, 0);
479
+ c_sleep(50);
480
+ do_TCP_connection(conn);
481
+ ck_assert_msg(conn->status == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONNECTING,
482
+ conn->status);
483
+ c_sleep(5000);
484
+ do_TCP_connection(conn);
485
+ ck_assert_msg(conn->status == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONNECTING,
486
+ conn->status);
487
+ c_sleep(6000);
488
+ do_TCP_connection(conn);
489
+ ck_assert_msg(conn->status == TCP_CLIENT_DISCONNECTED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_DISCONNECTED,
490
+ conn->status);
491
+ }
492
+ END_TEST
493
+
494
+ Suite *TCP_suite(void)
495
+ {
496
+ Suite *s = suite_create("TCP");
497
+
498
+ DEFTESTCASE_SLOW(basic, 5);
499
+ DEFTESTCASE_SLOW(some, 10);
500
+ DEFTESTCASE_SLOW(client, 10);
501
+ DEFTESTCASE_SLOW(client_invalid, 15);
502
+ return s;
503
+ }
504
+
505
+ int main(int argc, char *argv[])
506
+ {
507
+ srand((unsigned int) time(NULL));
508
+
509
+ Suite *TCP = TCP_suite();
510
+ SRunner *test_runner = srunner_create(TCP);
511
+
512
+ int number_failed = 0;
513
+ srunner_run_all(test_runner, CK_NORMAL);
514
+ number_failed = srunner_ntests_failed(test_runner);
515
+
516
+ srunner_free(test_runner);
517
+
518
+ return number_failed;
519
+ }