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