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
@@ -0,0 +1,163 @@
|
||||
///|
|
||||
fn make_test_identity(seed_byte : Byte) -> (@common.Destination, Bytes) {
|
||||
let ed_seed = Bytes::make(32, seed_byte)
|
||||
let ed_pub = try! @crypto.ed25519_public_key(ed_seed)
|
||||
let x_pub = try! @crypto.x25519_public_key(
|
||||
Bytes::make(32, (seed_byte.to_int() ^ 0x33).to_byte()),
|
||||
)
|
||||
let dest = try! @common.Destination::new_x25519_ed25519(x_pub, ed_pub)
|
||||
(dest, ed_seed)
|
||||
}
|
||||
|
||||
///|
|
||||
test "StreamingPacket Ed25519 sign/verify, option order, and I2CP gzip wrap" {
|
||||
let (dest, ed_seed) = make_test_identity(b'\x11')
|
||||
let pkt : @streaming.StreamingPacket = {
|
||||
send_stream_id: 100U,
|
||||
recv_stream_id: 200U,
|
||||
sequence_num: 0U,
|
||||
ack_through: 0U,
|
||||
nacks: [1U, 3U],
|
||||
resend_delay: b'\x02',
|
||||
flags: @streaming.flag_synchronize |
|
||||
@streaming.flag_from_included |
|
||||
@streaming.flag_delay_requested |
|
||||
@streaming.flag_max_packet_size_included |
|
||||
@streaming.flag_no_ack,
|
||||
delay_requested: Some(50U),
|
||||
from_dest: Some(dest),
|
||||
max_packet_size: Some(1730U),
|
||||
offline_sig: None,
|
||||
signature: None,
|
||||
payload: b"syn-payload",
|
||||
}
|
||||
let signed = pkt.sign_ed25519(ed_seed)
|
||||
assert_eq(signed.verify_signature(dest), true)
|
||||
|
||||
let i2cp = @streaming.encode_i2cp_streaming(
|
||||
signed,
|
||||
from_port=4000U,
|
||||
to_port=8080U,
|
||||
)
|
||||
let (hdr, dec) = @streaming.decode_i2cp_streaming(i2cp)
|
||||
assert_eq(hdr.from_port, 4000U)
|
||||
assert_eq(hdr.to_port, 8080U)
|
||||
assert_eq(hdr.protocol, b'\x06')
|
||||
assert_eq(dec, signed)
|
||||
assert_eq(dec.verify_signature(dest), true)
|
||||
|
||||
// Tampering payload invalidates signature
|
||||
let tampered : @streaming.StreamingPacket = {
|
||||
send_stream_id: dec.send_stream_id,
|
||||
recv_stream_id: dec.recv_stream_id,
|
||||
sequence_num: dec.sequence_num,
|
||||
ack_through: dec.ack_through,
|
||||
nacks: dec.nacks,
|
||||
resend_delay: dec.resend_delay,
|
||||
flags: dec.flags,
|
||||
delay_requested: dec.delay_requested,
|
||||
from_dest: dec.from_dest,
|
||||
max_packet_size: dec.max_packet_size,
|
||||
offline_sig: dec.offline_sig,
|
||||
signature: dec.signature,
|
||||
payload: b"tampered!",
|
||||
}
|
||||
assert_eq(tampered.verify_signature(dest), false)
|
||||
}
|
||||
|
||||
///|
|
||||
test "Streaming full SYN -> SYN-ACK -> Data with drop/NACK/retransmit -> CLOSE" {
|
||||
let (alice_dest, alice_seed) = make_test_identity(b'\x21')
|
||||
let (bob_dest, bob_seed) = make_test_identity(b'\x22')
|
||||
let alice_mgr = @streaming.StreamManager::new(
|
||||
alice_dest,
|
||||
alice_seed,
|
||||
initial_stream_id=100U,
|
||||
)
|
||||
let bob_mgr = @streaming.StreamManager::new(
|
||||
bob_dest,
|
||||
bob_seed,
|
||||
initial_stream_id=200U,
|
||||
)
|
||||
|
||||
let a_stream = alice_mgr.connect(
|
||||
bob_dest.hash(),
|
||||
1000UL,
|
||||
from_port=1111U,
|
||||
to_port=80U,
|
||||
)
|
||||
// Deliver SYN to Bob
|
||||
for msg in a_stream.drain_outbound() {
|
||||
let _ = bob_mgr.handle_incoming_i2cp(msg, 1010UL)
|
||||
}
|
||||
let b_stream = match bob_mgr.accept_next() {
|
||||
Some(s) => s
|
||||
None => fail("expected Bob to accept incoming SYN stream")
|
||||
}
|
||||
assert_eq(b_stream.remote_hash, alice_dest.hash())
|
||||
|
||||
// Deliver SYN-ACK to Alice, then Alice's ACK back to Bob
|
||||
for msg in b_stream.drain_outbound() {
|
||||
let _ = alice_mgr.handle_incoming_i2cp(msg, 1020UL)
|
||||
}
|
||||
assert_eq(a_stream.state, Established)
|
||||
for msg in a_stream.drain_outbound() {
|
||||
let _ = bob_mgr.handle_incoming_i2cp(msg, 1025UL)
|
||||
}
|
||||
|
||||
// Alice writes 4000 bytes (3 packets at 1730B MTU); drop packet #1 to force NACK & retransmit!
|
||||
let buf = FixedArray::make(4000, b'\x00')
|
||||
for i = 0; i < 4000; i = i + 1 {
|
||||
buf[i] = ((i * 17 + 3) & 0xFF).to_byte()
|
||||
}
|
||||
let msg_data = Bytes::from_array(buf)
|
||||
let written = a_stream.write(msg_data, 1030UL)
|
||||
assert_eq(written, 4000)
|
||||
let pkts = a_stream.drain_outbound()
|
||||
assert_eq(pkts.length(), 3)
|
||||
// Deliver packet 0 and packet 2 (drop packet 1)
|
||||
let _ = bob_mgr.handle_incoming_i2cp(pkts[0], 1040UL)
|
||||
let _ = bob_mgr.handle_incoming_i2cp(pkts[2], 1041UL)
|
||||
// Bob emits ACK+NACK for seq 2; deliver to Alice so Alice retransmits seq 2
|
||||
for ack in b_stream.drain_outbound() {
|
||||
let _ = alice_mgr.handle_incoming_i2cp(ack, 1050UL)
|
||||
}
|
||||
for retx in a_stream.drain_outbound() {
|
||||
let _ = bob_mgr.handle_incoming_i2cp(retx, 1060UL)
|
||||
}
|
||||
assert_eq(b_stream.read_available(), msg_data)
|
||||
|
||||
// Bob replies and closes
|
||||
assert_eq(b_stream.write(b"HTTP/1.1 200 OK\r\n\r\n", 1070UL), 19)
|
||||
b_stream.close(1071UL)
|
||||
for msg in b_stream.drain_outbound() {
|
||||
let _ = alice_mgr.handle_incoming_i2cp(msg, 1080UL)
|
||||
}
|
||||
assert_eq(a_stream.read_available(), b"HTTP/1.1 200 OK\r\n\r\n")
|
||||
assert_eq(a_stream.is_eof(), true)
|
||||
}
|
||||
|
||||
///|
|
||||
test "RepliableDatagram (Ed25519 raw payload) and RawDatagram I2CP round-trip" {
|
||||
let (dest, seed) = make_test_identity(b'\x33')
|
||||
let dg = @streaming.RepliableDatagram::sign_ed25519(
|
||||
dest, seed, b"ping-datagram",
|
||||
)
|
||||
assert_eq(dg.verify(), true)
|
||||
let i2cp = dg.to_i2cp_bytes(from_port=5000U, to_port=5001U)
|
||||
let (hdr, dec) = @streaming.RepliableDatagram::from_i2cp_bytes(i2cp)
|
||||
assert_eq(hdr.from_port, 5000U)
|
||||
assert_eq(hdr.to_port, 5001U)
|
||||
assert_eq(hdr.protocol, b'\x11')
|
||||
assert_eq(dec, dg)
|
||||
assert_eq(dec.verify(), true)
|
||||
|
||||
let raw_i2cp = @streaming.encode_raw_datagram(
|
||||
b"unauth-raw",
|
||||
from_port=9U,
|
||||
to_port=10U,
|
||||
)
|
||||
let (rh, rbody) = @streaming.decode_raw_datagram(raw_i2cp)
|
||||
assert_eq(rh.protocol, b'\x12')
|
||||
assert_eq(rbody, b"unauth-raw")
|
||||
}
|
||||
Reference in new issue
Block a user