summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/Tox_middle_level_network_protocol.txt68
1 files changed, 34 insertions, 34 deletions
diff --git a/docs/Tox_middle_level_network_protocol.txt b/docs/Tox_middle_level_network_protocol.txt
index ca561474..69ab9858 100644
--- a/docs/Tox_middle_level_network_protocol.txt
+++ b/docs/Tox_middle_level_network_protocol.txt
@@ -3,58 +3,58 @@ feature complete. Why doesn't Tox support TCP yet even if those parts are
3complete? 3complete?
4 4
5The answer is that a way to ensure a smooth switchover between the TCP and UDP 5The answer is that a way to ensure a smooth switchover between the TCP and UDP
6needs to be added. If Tox first connects to the other user using TCP but then 6needs to be added. If Tox first connects to the other user using TCP but then,
7due to pure chance manages to connect using the faster direct UDP connection 7due to pure chance, manages to connect using the faster direct UDP connection,
8Tox must switch seamlessly from the TCP to the UDP connection without there 8Tox must switch seamlessly from the TCP to the UDP connection without there
9being any data loss or the other user going offline and then back online. The 9being any data loss or the other user going offline and then back online. The
10transition must be seamless whatever both connected users are doing be it 10transition must be seamless whatever both connected users are doing - be it
11transferring files or simply chatting together. 11transferring files or simply chatting together.
12 12
13Possible evil/bad or simply TCP relays going offline must not impact the 13Possible evil/bad or simply TCP relays going offline must not impact the
14connection between both clients. 14connection between both clients.
15 15
16Typically Tox will use more than one TCP relay to connect to other peers for 16Typically, Tox will use more than one TCP relay to connect to other peers for
17maximum connection stability which means there must be a way for Tox to take 17maximum connection stability, which means there must be a way for Tox to take
18advantage of multiple relays in a way that the user will never be aware if one 18advantage of multiple relays in a way that the user will never be aware of, if one
19of them goes offline/tries to slow down the connection/decides to corrupt 19of them goes offline/tries to slow down the connection/decides to corrupt
20packets/etc.. 20packets/etc.
21 21
22To accomplish this Tox needs something between the low level protocol (TCP) and 22To accomplish this, Tox needs something between the low level protocol (TCP) and
23high level Tox messaging protocol hence the name middle level. 23high level Tox messaging protocol; hence the name middle level.
24 24
25The plan is to move some functionality from lossless_UDP to a higher level: 25The plan is to move some functionality from lossless_UDP to a higher level:
26more specifically the functionality for detecting which packets a peer is 26more specifically, the functionality for detecting which packets a peer is
27missing and the ability to request and send them again. lossless UDP uses plain 27missing, and the ability to request and send them again. Lossless UDP uses plain
28text packets to request missing packets from the other peer while Tox is 28text packets to request missing packets from the other peer, while Tox is
29currently designed to kill the connection if any packet tampering is detected. 29currently designed to kill the connection if any packet tampering is detected.
30This works very well when connecting directly with someone because if the 30This works very well when connecting directly with someone because if the
31attacker can modify packets it means he can kill your connection anyways. With 31attacker can modify packets, it means he can kill your connection anyway. With
32TCP relays however that is not the case as such the packets used to request 32TCP relays, however, that is not the case. As such the packets used to request
33missing packets must be encrypted. If it is detected that a packet has been 33missing packets must be encrypted. If it is detected that a packet has been
34tampered, the connection must stay intact while the evil relay must be 34tampered, the connection must stay intact while the evil relay must be
35disconnected from and replaced with a good relay, the behavior must be the same 35disconnected from and replaced with a good relay; the behavior must be the same
36as if the relay had just suddenly gone online. Of course something to protect 36as if the relay had just suddenly gone offline. Of course, something to protect
37from evil "friends" framing relays must also be implemented. 37from evil "friends" framing relays must also be implemented.
38 38
39Detailed implementation details: 39Detailed implementation details:
40 40
41cookie request packet: 41cookie request packet:
42[uint8_t 24][Senders DHT Public key (32 bytes)][Random nonce (24 42[uint8_t 24][Sender's DHT Public key (32 bytes)][Random nonce (24
43bytes)][Encrypted message containing: [Senders real public key (32 43bytes)][Encrypted message containing: [Sender's real public key (32
44bytes)][padding (32 bytes)][uint64_t number (must be sent 44bytes)][padding (32 bytes)][uint64_t number (must be sent
45back untouched in cookie response)]] 45back untouched in cookie response)]]
46Encrypted message is encrypted with sender DHT private key, receivers DHT 46Encrypted message is encrypted with sender's DHT private key, receiver's DHT
47public key and the nonce. 47public key and the nonce.
48 48
49cookie response packet: 49cookie response packet:
50[uint8_t 25][Random nonce (24 bytes)][Encrypted message containing: 50[uint8_t 25][Random nonce (24 bytes)][Encrypted message containing:
51[Cookie][uint64_t number (that was sent in the request)]] 51[Cookie][uint64_t number (that was sent in the request)]]
52Encrypted message is encrypted with sender DHT private key, receivers DHT 52Encrypted message is encrypted with sender's DHT private key, receiver's DHT
53public key and the nonce. 53public key and the nonce.
54 54
55The Cookie should be basically: 55The Cookie should be basically:
56[nonce][encrypted data:[uint64_t time][Senders real public key (32 56[nonce][encrypted data:[uint64_t time][Sender's real public key (32
57bytes)][Senders dht public key (32 bytes)]] 57bytes)][Sender's DHT public key (32 bytes)]]
58 58
59Handshake packet: 59Handshake packet:
60[uint8_t 26][Cookie][nonce][Encrypted message containing: [random 24 bytes base 60[uint8_t 26][Cookie][nonce][Encrypted message containing: [random 24 bytes base
@@ -66,25 +66,25 @@ The handshake packet is encrypted using the real private key of the sender, the
66real public key of the receiver and the nonce. 66real public key of the receiver and the nonce.
67 67
68 68
69Alice wants to connect to bob. 69Alice wants to connect to Bob:
70 70
71Alice sends a cookie request packet to bob and gets a cookie response back. 71Alice sends a cookie request packet to Bob and gets a cookie response back.
72 72
73Alice then generates a nonce and a temporary public/private keypair. 73Alice then generates a nonce and a temporary public/private keypair.
74 74
75Alice then takes that nonce and just generated private key, the obtained 75Alice then takes that nonce and just generated private key, the obtained
76cookie, creates a new cookie and puts them in a handshake packet which she 76cookie, creates a new cookie and puts them in a handshake packet, which she
77sends to bob. 77sends to Bob.
78 78
79Bob gets the handshake packet, accepts the connection request, then generates a 79Bob gets the handshake packet, accepts the connection request, then generates a
80nonce and a temporary public/private keypair and sends a handshake packet back 80nonce and a temporary public/private keypair and sends a handshake packet back
81with this just generated information and with the cookie field being the Other 81with this just generated information and with the cookie field being the Other
82Cookie contained in the received handshake. 82Cookie contained in the received handshake.
83 83
84Both then use these temporary keys to generate the session key with which every 84Both then use these temporary keys to generate the session key, with which every
85data packet sent and received will be encrypted and decrypted. The nonce sent 85data packet sent and received will be encrypted and decrypted. The nonce sent
86in the handshake will be used to encrypt the first data packet sent, the nonce 86in the handshake will be used to encrypt the first data packet sent, the nonce
87+ 1 the second, the nonce + 2 the third and so on. 87+ 1 for the second, the nonce + 2 for the third, and so on.
88 88
89Data packets: 89Data packets:
90 90
@@ -109,12 +109,12 @@ data ids:
109packet request packet: [uint8_t (1)][uint8_t num][uint8_t num][uint8_t 109packet request packet: [uint8_t (1)][uint8_t num][uint8_t num][uint8_t
110num]...[uint8_t num] 110num]...[uint8_t num]
111 111
112the list of nums are a list of packet numbers the other is requesting. 112The list of nums are a list of packet numbers the other is requesting.
113to get the real packet numbers from this list take the recvbuffers buffer_start 113In order to get the real packet numbers from this list, take the recvbuffers buffer_start
114from the packet, subtract 1 to it and put it in packet_num then start from the 114from the packet, subtract 1 from it and put it in packet_num, then start from the
115beginning of the num list: if num is zero, add 255 to packet_num then do the 115beginning of the num list: if num is zero, add 255 to packet_num, then do the
116next num. if num isn't zero, add its value to packet_num, note that the other 116next num. If num isn't zero, add its value to packet_num, note that the other
117has requested we send this packet again to them then continue to the next num in 117has requested we send this packet again to them, then continue to the next num in
118the list. 118the list.
119 119
120 120