{% extends "_layout.html" %} {% block title %}NTCP{% endblock %} {% block content %} Updated December 2013 for release 0.9.9
NTCP is one of two transports currently implemented in I2P. The other is SSU. NTCP is a Java NIO-based transport introduced in I2P release 0.6.1.22. Java NIO (new I/O) does not suffer from the 1 thread per connection issues of the old TCP transport. NTCP-over-IPv6 is supported as of version 0.9.8.
By default, NTCP uses the IP/Port auto-detected by SSU. When enabled on config.jsp, SSU will notify/restart NTCP when the external address changes or when the firewall status changes. Now you can enable inbound TCP without a static IP or dyndns service.
The NTCP code within I2P is relatively lightweight (1/4 the size of the SSU code) because it uses the underlying Java TCP transport for reliable delivery.
After establishment, the NTCP transport sends individual I2NP messages, with a simple checksum. The unencrypted message is encoded as follows:
* +-------+-------+--//--+---//----+-------+-------+-------+-------+ * | sizeof(data) | data | padding | Adler checksum of sz+data+pad | * +-------+-------+--//--+---//----+-------+-------+-------+-------+The data is then AES/256/CBC encrypted. The session key for the encryption is negotiated during establishment (using Diffie-Hellman 2048 bit). The establishment between two routers is implemented in the EstablishState class and detailed below. The IV for AES/256/CBC encryption is the last 16 bytes of the previous encrypted message.
0-15 bytes of padding are required to bring the total message length (including the six size and checksum bytes) to a multiple of 16. The maximum message size is currently 16 KB. Therefore the maximum data size is currently 16 KB - 6, or 16378 bytes. The minimum data size is 1.
One special case is a metadata message where the sizeof(data) is 0. In that case, the unencrypted message is encoded as:
* +-------+-------+-------+-------+-------+-------+-------+-------+ * | 0 | timestamp in seconds | uninterpreted * +-------+-------+-------+-------+-------+-------+-------+-------+ * uninterpreted | Adler checksum of bytes 0-11 | * +-------+-------+-------+-------+-------+-------+-------+-------+Total length: 16 bytes. The time sync message is sent at approximately 15 minute intervals. The message is encrypted just as standard messages are.
* Alice contacts Bob * ========================================================= * X+(H(X) xor Bob.identHash)-----------------------------> * <----------------------------------------Y+E(H(X+Y)+tsB+padding, sk, Y[239:255]) * E(sz+Alice.identity+tsA+padding+S(X+Y+Bob.identHash+tsA+tsB), sk, hX_xor_Bob.identHash[16:31])---> * <----------------------E(S(X+Y+Alice.identHash+tsA+tsB)+padding, sk, prev)
Legend: X, Y: 256 byte DH public keys H(): 32 byte SHA256 Hash E(data, session key, IV): AES256 Encrypt S(): 40 byte DSA Signature tsA, tsB: timestamps (4 bytes, seconds since epoch) sk: 32 byte Session key sz: 2 byte size of Alice identity to follow
The initial 2048-bit DH key exchange uses the same shared prime (p) and generator (g) as that used for I2P's ElGamal encryption.
The DH key exchange consists of a number of steps, displayed below. The mapping between these steps and the messages sent between I2P routers, is marked in bold.
* X+(H(X) xor Bob.identHash)-----------------------------> Size: 288 bytesContents:
+----+----+----+----+----+----+----+----+ | X, as calculated from DH | + + | | ~ . . . ~ | | +----+----+----+----+----+----+----+----+ | | + + | HXxorHI | + + | | + + | | +----+----+----+----+----+----+----+----+ X: 256 byte X from Diffie Hellman HXxorHI: SHA256 Hash(X) xored with SHA256 Hash(Bob's Router Identity) (32 bytes)
Notes:
* <----------------------------------------Y+E(H(X+Y)+tsB+padding, sk, Y[239:255]) Size: 304 bytesUnencrypted Contents:
+----+----+----+----+----+----+----+----+ | Y as calculated from DH | + + | | ~ . . . ~ | | +----+----+----+----+----+----+----+----+ | | + + | HXY | + + | | + + | | +----+----+----+----+----+----+----+----+ | tsB | padding | +----+----+----+----+ + | | +----+----+----+----+----+----+----+----+ Y: 256 byte Y from Diffie Hellman HXY: SHA256 Hash(X concatenated with Y) (32 bytes) tsB: 4 byte timestamp (seconds since the epoch) padding: 12 bytes random dataEncrypted Contents:
+----+----+----+----+----+----+----+----+ | Y as calculated from DH | + + | | ~ . . . ~ | | +----+----+----+----+----+----+----+----+ | | + + | encrypted data | + + | | + + | | + + | | + + | | +----+----+----+----+----+----+----+----+ Y: 256 byte Y from Diffie Hellman encrypted data: 48 bytes AES encrypted using the DH session key and the last 16 bytes of Y as the IV
Notes:
* E(sz+Alice.identity+tsA+padding+S(X+Y+Bob.identHash+tsA+tsB), sk, hX_xor_Bob.identHash[16:31])---> Size: 448 bytes (typ. for 387 byte identity)Unencrypted Contents:
+----+----+----+----+----+----+----+----+ | sz | Alice's Router Identity | +----+----+ + | | ~ . . . ~ | | + +----+----+----+ | | tsA +----+----+----+----+----+----+----+----+ | padding | +----+ + | | +----+----+----+----+----+----+----+----+ | | + + | signature | + + | | + + | | + + | | +----+----+----+----+----+----+----+----+ sz: 2 byte size of Alice's router identity to follow (should always be 387) ident: Alice's 387 byte Router Identity tsA: 4 byte timestamp (seconds since the epoch) padding: 15 bytes random data signature: the 40 byte DSA signature of the following concatenated data: X, Y, Bob's Router Identity, tsA, tsB. Alice signs it with the private signing key associated with the public signing key in her Router IdentityEncrypted Contents:
+----+----+----+----+----+----+----+----+ | | + + | encrypted data | ~ . . . ~ | | +----+----+----+----+----+----+----+----+ encrypted data: 448 bytes AES encrypted using the DH session key and the last 16 bytes of HXxorHI (i.e., the last 16 bytes of message #1) as the IV
Notes:
* <----------------------E(S(X+Y+Alice.identHash+tsA+tsB)+padding, sk, prev) Size: 48 bytesUnencrypted Contents:
+----+----+----+----+----+----+----+----+ | | + + | signature | + + | | + + | | + + | | +----+----+----+----+----+----+----+----+ | padding | +----+----+----+----+----+----+----+----+ signature: the 40 byte DSA signature of the following concatenated data: X, Y, Alice's Router Identity, tsA, tsB. Bob signs it with the private signing key associated with the public signing key in his Router Identity padding: 8 bytes random dataEncrypted Contents:
+----+----+----+----+----+----+----+----+ | | + + | encrypted data | ~ . . . ~ | | +----+----+----+----+----+----+----+----+ encrypted data: 48 bytes AES encrypted using the DH session key and the last 16 bytes of the encrypted contents of message #2 as the IV
Notes:
The connection is established, and standard or time sync messages may be exchanged. All subsequent messages are AES encrypted using the negotiated DH session key. Alice will use the last 16 bytes of the encrypted contents of message #3 as the next IV. Bob will use the last 16 bytes of the encrypted contents of message #4 as the next IV.