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
+267
-17
@@ -1,3 +1,52 @@
|
||||
///|
|
||||
fn step_routers(rs : Array[@router.Router], count : Int32) -> Unit {
|
||||
for _i = 0; _i < count; _i = _i + 1 {
|
||||
for r in rs {
|
||||
r.step(poll_ms=1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
fn pump_read_line(
|
||||
sock : @ntcp2_net.TcpSocket,
|
||||
rs : Array[@router.Router],
|
||||
max_ticks~ : Int32 = 1000,
|
||||
) -> String raise {
|
||||
for _i = 0; _i < max_ticks; _i = _i + 1 {
|
||||
step_routers(rs, 1)
|
||||
if sock.poll_readable(0) {
|
||||
match sock.read_line() {
|
||||
Some(l) => return l
|
||||
None => fail("unexpected EOF while waiting for SAM line")
|
||||
}
|
||||
}
|
||||
}
|
||||
fail("timed out waiting for SAM line")
|
||||
}
|
||||
|
||||
///|
|
||||
fn pump_read_until_eof(
|
||||
sock : @ntcp2_net.TcpSocket,
|
||||
rs : Array[@router.Router],
|
||||
max_ticks~ : Int32 = 1500,
|
||||
) -> Bytes raise {
|
||||
let out : Array[Byte] = []
|
||||
for _i = 0; _i < max_ticks; _i = _i + 1 {
|
||||
step_routers(rs, 1)
|
||||
while sock.poll_readable(0) {
|
||||
let chunk = sock.read_some(4096)
|
||||
if chunk.length() == 0 {
|
||||
return Bytes::from_array(out)
|
||||
}
|
||||
for j = 0; j < chunk.length(); j = j + 1 {
|
||||
out.push(chunk[j])
|
||||
}
|
||||
}
|
||||
}
|
||||
fail("timed out waiting for EOF on stream socket")
|
||||
}
|
||||
|
||||
///|
|
||||
test "Router transient startup, self-signed RouterInfo, and embedded SAMv3 bridge" {
|
||||
let r = @router.Router::start({
|
||||
@@ -16,36 +65,237 @@ test "Router transient startup, self-signed RouterInfo, and embedded SAMv3 bridg
|
||||
r.step(poll_ms=50)
|
||||
|
||||
sock.write_all(b"HELLO VERSION MIN=3.1 MAX=3.3\n")
|
||||
r.step(poll_ms=50)
|
||||
assert_eq(sock.read_line(), Some("HELLO REPLY RESULT=OK VERSION=3.3"))
|
||||
assert_eq(pump_read_line(sock, [r]), "HELLO REPLY RESULT=OK VERSION=3.3")
|
||||
|
||||
sock.write_all(b"DEST GENERATE SIGNATURE_TYPE=7\n")
|
||||
r.step(poll_ms=50)
|
||||
let dest_line = match sock.read_line() {
|
||||
Some(l) => l
|
||||
None => fail("expected DEST REPLY")
|
||||
}
|
||||
let dest_line = pump_read_line(sock, [r])
|
||||
assert_true(dest_line.has_prefix("DEST REPLY PUB="))
|
||||
|
||||
sock.write_all(
|
||||
b"SESSION CREATE STYLE=STREAM ID=test1 DESTINATION=TRANSIENT\n",
|
||||
)
|
||||
r.step(poll_ms=50)
|
||||
let sess_line = match sock.read_line() {
|
||||
Some(l) => l
|
||||
None => fail("expected SESSION STATUS")
|
||||
}
|
||||
let sess_line = pump_read_line(sock, [r])
|
||||
assert_true(sess_line.has_prefix("SESSION STATUS RESULT=OK DESTINATION="))
|
||||
assert_eq(r.netdb.leaseset_count(), 1)
|
||||
|
||||
sock.write_all(b"NAMING LOOKUP NAME=ME\n")
|
||||
r.step(poll_ms=50)
|
||||
let lookup_line = match sock.read_line() {
|
||||
Some(l) => l
|
||||
None => fail("expected NAMING REPLY")
|
||||
}
|
||||
let lookup_line = pump_read_line(sock, [r])
|
||||
assert_true(lookup_line.has_prefix("NAMING REPLY RESULT=OK NAME=ME VALUE="))
|
||||
|
||||
sock.close()
|
||||
r.close()
|
||||
}
|
||||
|
||||
///|
|
||||
fn sam_connect_and_hello(
|
||||
port : Int32,
|
||||
rs : Array[@router.Router],
|
||||
) -> @ntcp2_net.TcpSocket raise {
|
||||
let sock = @ntcp2_net.TcpSocket::connect("127.0.0.1", port)
|
||||
sock.write_all(b"HELLO VERSION MIN=3.1 MAX=3.3\n")
|
||||
let reply = pump_read_line(sock, rs)
|
||||
assert_eq(reply, "HELLO REPLY RESULT=OK VERSION=3.3")
|
||||
sock
|
||||
}
|
||||
|
||||
///|
|
||||
fn extract_kv(line : String, key : String) -> String {
|
||||
let prefix = key + "="
|
||||
let tokens = line.split(" ").collect()
|
||||
for t in tokens {
|
||||
let ts = t.to_owned()
|
||||
if ts.has_prefix(prefix) {
|
||||
return ts[prefix.length():].to_owned()
|
||||
}
|
||||
}
|
||||
""
|
||||
}
|
||||
|
||||
///|
|
||||
test "Two live routers end-to-end: NTCP2 + ECIES NetDB + Garlic Ratchet + Ed25519 Streaming" {
|
||||
let router_b = @router.Router::start(
|
||||
{
|
||||
sam_host: "127.0.0.1",
|
||||
sam_port: 0,
|
||||
ntcp2_host: "127.0.0.1",
|
||||
ntcp2_port: 0,
|
||||
},
|
||||
floodfill=true,
|
||||
)
|
||||
defer router_b.close()
|
||||
let router_a = @router.Router::start({
|
||||
sam_host: "127.0.0.1",
|
||||
sam_port: 0,
|
||||
ntcp2_host: "127.0.0.1",
|
||||
ntcp2_port: 0,
|
||||
})
|
||||
defer router_a.close()
|
||||
let _ = router_a.netdb.store_router_info(router_b.router_info)
|
||||
let _ = router_b.netdb.store_router_info(router_a.router_info)
|
||||
let rs = [router_a, router_b]
|
||||
|
||||
// Bob opens SAM control session + STREAM ACCEPT on router B
|
||||
let bob_ctrl = sam_connect_and_hello(router_b.sam_port(), rs)
|
||||
defer bob_ctrl.close()
|
||||
bob_ctrl.write_all(
|
||||
b"SESSION CREATE STYLE=STREAM ID=bob DESTINATION=TRANSIENT\n",
|
||||
)
|
||||
let bob_sess = pump_read_line(bob_ctrl, rs)
|
||||
assert_true(bob_sess.has_prefix("SESSION STATUS RESULT=OK"))
|
||||
bob_ctrl.write_all(b"NAMING LOOKUP NAME=ME\n")
|
||||
let bob_me = pump_read_line(bob_ctrl, rs)
|
||||
let bob_pub_b64 = extract_kv(bob_me, "VALUE")
|
||||
let bob_dest = @common.Destination::from_base64(bob_pub_b64)
|
||||
let bob_b32 = bob_dest.b32_address()
|
||||
|
||||
let bob_acc = sam_connect_and_hello(router_b.sam_port(), rs)
|
||||
defer bob_acc.close()
|
||||
bob_acc.write_all(b"STREAM ACCEPT ID=bob SILENT=false\n")
|
||||
assert_eq(pump_read_line(bob_acc, rs), "STREAM STATUS RESULT=OK")
|
||||
|
||||
// Alice creates SAM control session on router A and looks up Bob's .b32.i2p via live NTCP2 ECIES NetDB
|
||||
let alice_ctrl = sam_connect_and_hello(router_a.sam_port(), rs)
|
||||
defer alice_ctrl.close()
|
||||
alice_ctrl.write_all(
|
||||
b"SESSION CREATE STYLE=STREAM ID=alice DESTINATION=TRANSIENT\n",
|
||||
)
|
||||
let alice_sess = pump_read_line(alice_ctrl, rs)
|
||||
assert_true(alice_sess.has_prefix("SESSION STATUS RESULT=OK"))
|
||||
|
||||
alice_ctrl.write_all(
|
||||
@encoding.string_to_utf8_bytes("NAMING LOOKUP NAME=\{bob_b32}\n"),
|
||||
)
|
||||
let alice_lookup = pump_read_line(alice_ctrl, rs)
|
||||
assert_true(alice_lookup.has_prefix("NAMING REPLY RESULT=OK"))
|
||||
assert_eq(extract_kv(alice_lookup, "VALUE"), bob_pub_b64)
|
||||
|
||||
// Alice connects over ECIES-X25519-AEAD-Ratchet Garlic + Ed25519 Streaming
|
||||
let alice_data = sam_connect_and_hello(router_a.sam_port(), rs)
|
||||
defer alice_data.close()
|
||||
alice_data.write_all(
|
||||
@encoding.string_to_utf8_bytes(
|
||||
"STREAM CONNECT ID=alice DESTINATION=\{bob_pub_b64} SILENT=false\n",
|
||||
),
|
||||
)
|
||||
assert_eq(pump_read_line(alice_data, rs), "STREAM STATUS RESULT=OK")
|
||||
let seen_peer_b64 = pump_read_line(bob_acc, rs)
|
||||
assert_true(seen_peer_b64.length() > 100)
|
||||
|
||||
// Bidirectional Streaming payload + close exchange
|
||||
alice_data.write_all(b"hello-over-ecies-streaming")
|
||||
alice_data.shutdown_write()
|
||||
let got_on_bob = pump_read_until_eof(bob_acc, rs)
|
||||
assert_eq(got_on_bob, b"hello-over-ecies-streaming")
|
||||
|
||||
bob_acc.write_all(b"ack-from-bob")
|
||||
bob_acc.shutdown_write()
|
||||
let got_on_alice = pump_read_until_eof(alice_data, rs)
|
||||
assert_eq(got_on_alice, b"ack-from-bob")
|
||||
}
|
||||
|
||||
///|
|
||||
test "Three-router live Proposal 157 multi-hop tunnel build and fragmented 2500B TunnelData stream" {
|
||||
let router_b = @router.Router::start(
|
||||
{
|
||||
sam_host: "127.0.0.1",
|
||||
sam_port: 0,
|
||||
ntcp2_host: "127.0.0.1",
|
||||
ntcp2_port: 0,
|
||||
},
|
||||
floodfill=true,
|
||||
)
|
||||
defer router_b.close()
|
||||
let router_c = @router.Router::start({
|
||||
sam_host: "127.0.0.1",
|
||||
sam_port: 0,
|
||||
ntcp2_host: "127.0.0.1",
|
||||
ntcp2_port: 0,
|
||||
})
|
||||
defer router_c.close()
|
||||
let router_a = @router.Router::start({
|
||||
sam_host: "127.0.0.1",
|
||||
sam_port: 0,
|
||||
ntcp2_host: "127.0.0.1",
|
||||
ntcp2_port: 0,
|
||||
})
|
||||
defer router_a.close()
|
||||
|
||||
for r in [router_a, router_b, router_c] {
|
||||
let _ = r.netdb.store_router_info(router_a.router_info)
|
||||
let _ = r.netdb.store_router_info(router_b.router_info)
|
||||
let _ = r.netdb.store_router_info(router_c.router_info)
|
||||
}
|
||||
let rs = [router_a, router_b, router_c]
|
||||
|
||||
// Router A builds 2-hop Outbound [B -> C] and 2-hop Inbound [B -> C -> A] tunnels via Proposal 157
|
||||
let out_tid = router_a.build_tunnel(
|
||||
[router_b.router_hash(), router_c.router_hash()],
|
||||
Outbound,
|
||||
)
|
||||
let in_tid = router_a.build_tunnel(
|
||||
[router_b.router_hash(), router_c.router_hash()],
|
||||
Inbound,
|
||||
)
|
||||
let mut built = false
|
||||
for _i = 0; _i < 1000; _i = _i + 1 {
|
||||
step_routers(rs, 1)
|
||||
if router_a.has_tunnel(out_tid) && router_a.has_tunnel(in_tid) {
|
||||
built = true
|
||||
break
|
||||
}
|
||||
}
|
||||
assert_true(built)
|
||||
assert_true(router_b.tunnels.transit_count() >= 2)
|
||||
assert_true(router_c.tunnels.transit_count() >= 2)
|
||||
|
||||
// Router C hosts Bob; Router A hosts Alice (whose LS2 uses her Inbound [B -> C -> A] tunnel lease)
|
||||
let bob_ctrl = sam_connect_and_hello(router_c.sam_port(), rs)
|
||||
defer bob_ctrl.close()
|
||||
bob_ctrl.write_all(
|
||||
b"SESSION CREATE STYLE=STREAM ID=bob3 DESTINATION=TRANSIENT\n",
|
||||
)
|
||||
assert_true(
|
||||
pump_read_line(bob_ctrl, rs).has_prefix("SESSION STATUS RESULT=OK"),
|
||||
)
|
||||
bob_ctrl.write_all(b"NAMING LOOKUP NAME=ME\n")
|
||||
let bob_pub_b64 = extract_kv(pump_read_line(bob_ctrl, rs), "VALUE")
|
||||
let bob_b32 = @common.Destination::from_base64(bob_pub_b64).b32_address()
|
||||
|
||||
let bob_acc = sam_connect_and_hello(router_c.sam_port(), rs)
|
||||
defer bob_acc.close()
|
||||
bob_acc.write_all(b"STREAM ACCEPT ID=bob3 SILENT=false\n")
|
||||
assert_eq(pump_read_line(bob_acc, rs), "STREAM STATUS RESULT=OK")
|
||||
|
||||
let alice_ctrl = sam_connect_and_hello(router_a.sam_port(), rs)
|
||||
defer alice_ctrl.close()
|
||||
alice_ctrl.write_all(
|
||||
b"SESSION CREATE STYLE=STREAM ID=alice3 DESTINATION=TRANSIENT\n",
|
||||
)
|
||||
assert_true(
|
||||
pump_read_line(alice_ctrl, rs).has_prefix("SESSION STATUS RESULT=OK"),
|
||||
)
|
||||
alice_ctrl.write_all(
|
||||
@encoding.string_to_utf8_bytes("NAMING LOOKUP NAME=\{bob_b32}\n"),
|
||||
)
|
||||
assert_eq(extract_kv(pump_read_line(alice_ctrl, rs), "VALUE"), bob_pub_b64)
|
||||
|
||||
let alice_data = sam_connect_and_hello(router_a.sam_port(), rs)
|
||||
defer alice_data.close()
|
||||
alice_data.write_all(
|
||||
@encoding.string_to_utf8_bytes(
|
||||
"STREAM CONNECT ID=alice3 DESTINATION=\{bob_pub_b64} SILENT=false\n",
|
||||
),
|
||||
)
|
||||
assert_eq(pump_read_line(alice_data, rs), "STREAM STATUS RESULT=OK")
|
||||
let _ = pump_read_line(bob_acc, rs)
|
||||
|
||||
// Send 2500 bytes (spanning multiple Streaming packets & fragmented 1024B TunnelData cells)
|
||||
let big_payload = Bytes::make(2500, b'\x41')
|
||||
alice_data.write_all(big_payload)
|
||||
alice_data.shutdown_write()
|
||||
assert_eq(pump_read_until_eof(bob_acc, rs), big_payload)
|
||||
|
||||
bob_acc.write_all(b"tunneled-ok")
|
||||
bob_acc.shutdown_write()
|
||||
assert_eq(pump_read_until_eof(alice_data, rs), b"tunneled-ok")
|
||||
}
|
||||
Reference in new issue
Block a user