feat: add ratchet, streaming, SU3 reseed, and router floodfill
- Add ratchet/ with ECIES-X25519-AEAD-Ratchet (Proposal 144), Garlic cloves, and ECIES DatabaseLookup replies - Add streaming/ with Ed25519-signed I2P Streaming (SYN/ACK/NACK/CLOSE/RESET, retransmit, window) and Repliable/Raw Datagrams - Add common/su3.mbt to parse and verify reseed .su3 bundles - Add Elligator2 encoding in crypto/ and OfflineSignature support in LeaseSet2 (flags bit 0) - Router: NTCP2 peer pool, floodfill NetDB crawl, transit tunnel relay, and Garlic/Streaming bridge - cmd/router: add --peer-dir, --su3, --reseed, --floodfill, --no-clock-skew - cmd/client: add --dest for persistent destination keys - Mark Phase 6 complete in README and document the transport scope (NTCP2 only, no SSU2)
This commit is contained in:
1 parent
8eafa11b22
commit
ae72b00323
54 files changed
+9607
-704
No files matched your search
@@ -94,3 +94,36 @@ test "I2NP TunnelData and DatabaseSearchReply round-trip" {
|
||||
)
|
||||
assert_eq(dsr_dec, dsr)
|
||||
}
|
||||
|
||||
///|
|
||||
test "I2NP DatabaseLookup ECIES (0x10) and AES (0x02) reply key/tags round-trip" {
|
||||
let key = @common.Hash::from_bytes(Bytes::make(32, b'\x11'))
|
||||
let from = @common.Hash::from_bytes(Bytes::make(32, b'\x22'))
|
||||
let ecies_dbl = @i2np.I2npPayload::DatabaseLookup(
|
||||
key~,
|
||||
from~,
|
||||
flags=b'\x11', // tunnel delivery (0x01) + ECIES reply (0x10)
|
||||
reply_tunnel_id=Some(445566U),
|
||||
excluded_peers=[@common.Hash::from_bytes(Bytes::make(32, b'\x33'))],
|
||||
reply_key=Some(Bytes::make(32, b'\x44')),
|
||||
reply_tags=[Bytes::make(8, b'\x55')],
|
||||
)
|
||||
let ecies_wire = @i2np.encode_short_message(11U, 1700000900U, ecies_dbl)
|
||||
let (_, ecies_dec) = @i2np.decode_short_message(
|
||||
@encoding.Reader::new(ecies_wire),
|
||||
)
|
||||
assert_eq(ecies_dec, ecies_dbl)
|
||||
|
||||
let aes_dbl = @i2np.I2npPayload::DatabaseLookup(
|
||||
key~,
|
||||
from~,
|
||||
flags=b'\x0a', // RouterInfo lookup (0x08) + AES encryption (0x02)
|
||||
reply_tunnel_id=None,
|
||||
excluded_peers=[],
|
||||
reply_key=Some(Bytes::make(32, b'\x66')),
|
||||
reply_tags=[Bytes::make(32, b'\x77')],
|
||||
)
|
||||
let aes_wire = @i2np.encode_short_message(12U, 1700000900U, aes_dbl)
|
||||
let (_, aes_dec) = @i2np.decode_short_message(@encoding.Reader::new(aes_wire))
|
||||
assert_eq(aes_dec, aes_dbl)
|
||||
}
|
||||
+68
-3
@@ -166,7 +166,9 @@ pub(all) enum I2npPayload {
|
||||
from~ : @common.Hash,
|
||||
flags~ : Byte,
|
||||
reply_tunnel_id~ : UInt32?,
|
||||
excluded_peers~ : Array[@common.Hash]
|
||||
excluded_peers~ : Array[@common.Hash],
|
||||
reply_key~ : Bytes?,
|
||||
reply_tags~ : Array[Bytes]
|
||||
)
|
||||
/// Type 3: DatabaseSearchReply (floodfill returns closest router hashes).
|
||||
DatabaseSearchReply(
|
||||
@@ -236,7 +238,15 @@ pub fn I2npPayload::encode_body(self : I2npPayload) -> Bytes raise I2npError {
|
||||
}
|
||||
w.write_bytes(data)
|
||||
}
|
||||
DatabaseLookup(key~, from~, flags~, reply_tunnel_id~, excluded_peers~) => {
|
||||
DatabaseLookup(
|
||||
key~,
|
||||
from~,
|
||||
flags~,
|
||||
reply_tunnel_id~,
|
||||
excluded_peers~,
|
||||
reply_key~,
|
||||
reply_tags~
|
||||
) => {
|
||||
key.encode(w)
|
||||
from.encode(w)
|
||||
w.write_u8(flags)
|
||||
@@ -253,6 +263,39 @@ pub fn I2npPayload::encode_body(self : I2npPayload) -> Bytes raise I2npError {
|
||||
for peer in excluded_peers {
|
||||
peer.encode(w)
|
||||
}
|
||||
let enc_aes = (flags.to_int() & 0x02) != 0
|
||||
let enc_ecies = (flags.to_int() & 0x10) != 0
|
||||
if enc_aes || enc_ecies {
|
||||
match reply_key {
|
||||
Some(rk) => {
|
||||
if rk.length() != 32 {
|
||||
raise InvalidLength(
|
||||
"DatabaseLookup reply_key must be 32 bytes, got \{rk.length()}",
|
||||
)
|
||||
}
|
||||
w.write_bytes(rk)
|
||||
}
|
||||
None =>
|
||||
raise InvalidLength(
|
||||
"DatabaseLookup encryption flag requires reply_key",
|
||||
)
|
||||
}
|
||||
let expected_tag_len = if enc_ecies { 8 } else { 32 }
|
||||
if reply_tags.length() == 0 || reply_tags.length() > 255 {
|
||||
raise InvalidLength(
|
||||
"DatabaseLookup encrypted reply requires 1..255 reply_tags",
|
||||
)
|
||||
}
|
||||
w.write_u8(reply_tags.length().to_byte())
|
||||
for tag in reply_tags {
|
||||
if tag.length() != expected_tag_len {
|
||||
raise InvalidLength(
|
||||
"DatabaseLookup reply_tag must be \{expected_tag_len} bytes, got \{tag.length()}",
|
||||
)
|
||||
}
|
||||
w.write_bytes(tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
DatabaseSearchReply(key~, peer_hashes~, from~) => {
|
||||
key.encode(w)
|
||||
@@ -353,7 +396,29 @@ pub fn I2npPayload::decode_body(
|
||||
},
|
||||
)
|
||||
}
|
||||
DatabaseLookup(key~, from~, flags~, reply_tunnel_id~, excluded_peers~)
|
||||
let enc_aes = (flags.to_int() & 0x02) != 0
|
||||
let enc_ecies = (flags.to_int() & 0x10) != 0
|
||||
let (reply_key, reply_tags) = if enc_aes || enc_ecies {
|
||||
let rk = r.read_bytes(32) catch { e => raise Encoding(e) }
|
||||
let tag_count = (r.read_u8() catch { e => raise Encoding(e) }).to_int()
|
||||
let tag_len = if enc_ecies { 8 } else { 32 }
|
||||
let tags : Array[Bytes] = Array(capacity=tag_count)
|
||||
for _i = 0; _i < tag_count; _i = _i + 1 {
|
||||
tags.push(r.read_bytes(tag_len) catch { e => raise Encoding(e) })
|
||||
}
|
||||
(Some(rk), tags)
|
||||
} else {
|
||||
(None, [])
|
||||
}
|
||||
DatabaseLookup(
|
||||
key~,
|
||||
from~,
|
||||
flags~,
|
||||
reply_tunnel_id~,
|
||||
excluded_peers~,
|
||||
reply_key~,
|
||||
reply_tags~,
|
||||
)
|
||||
}
|
||||
DatabaseSearchReply => {
|
||||
let key = @common.Hash::decode(r) catch { e => raise Common(e) }
|
||||
|
||||
@@ -52,7 +52,7 @@ pub fn I2npMessageType::to_byte(Self) -> Byte
|
||||
#derive(Eq, @debug.Debug)
|
||||
pub(all) enum I2npPayload {
|
||||
DatabaseStore(key~ : @common.Hash, store_type~ : Byte, reply_token~ : UInt32, reply_tunnel_id~ : UInt32, reply_gateway~ : @common.Hash?, data~ : Bytes)
|
||||
DatabaseLookup(key~ : @common.Hash, from~ : @common.Hash, flags~ : Byte, reply_tunnel_id~ : UInt32?, excluded_peers~ : Array[@common.Hash])
|
||||
DatabaseLookup(key~ : @common.Hash, from~ : @common.Hash, flags~ : Byte, reply_tunnel_id~ : UInt32?, excluded_peers~ : Array[@common.Hash], reply_key~ : Bytes?, reply_tags~ : Array[Bytes])
|
||||
DatabaseSearchReply(key~ : @common.Hash, peer_hashes~ : Array[@common.Hash], from~ : @common.Hash)
|
||||
DeliveryStatus(msg_id~ : UInt32, timestamp_ms~ : UInt64)
|
||||
Garlic(data~ : Bytes)
|
||||
|
||||
Reference in new issue
Block a user