feat: add public I2P network mode to router daemon
- Add `--public`, `--hops`, `--hosts`, and `--debug` router flags; `--public` auto-reseeds from the live network and keeps a status loop running. - Route NetDB lookups through tunnels with Noise_N garlic wrapping, fan out to two floodfills, and fetch unknown RouterInfos in the background. - Back off failed NTCP2 peers and fall back to IPv6 addresses when no IPv4 NTCP2 address is available. - Size session LeaseSet2 expiry from lease end dates and use the destination's X25519 key when present. - Add canonical Ed25519 Destination KeyCertificate constructors with round-trip tests. - Fix DatabaseStore gzip handling to honor the length prefix, and send `Wget/1.11.4` as the reseed User-Agent.
This commit is contained in:
1 parent
ae72b00323
commit
54cfb2faa9
25 files changed
+2033
-191
No files matched your search
+23
-14
@@ -146,7 +146,7 @@ pub fn ShortBuildRequestRecord::decode_154(
|
||||
|
||||
///|
|
||||
/// Canonical Proposal 157 chained HKDF key derivation:
|
||||
/// `SMTunnelReplyKey` -> `SMTunnelLayerKey` -> `TunnelLayerIVKey` (-> `RGarlicKeyAndTag` for OBEP).
|
||||
/// `SMTunnelReplyKey` -> `SMTunnelLayerKey` (-> `TunnelLayerIVKey` -> `RGarlicKeyAndTag` for OBEP).
|
||||
fn derive_hop_keys(
|
||||
ck : Bytes,
|
||||
h : Bytes,
|
||||
@@ -164,21 +164,30 @@ fn derive_hop_keys(
|
||||
let ck2 = t_slice(kd2, 0, 32)
|
||||
let layer_key = t_slice(kd2, 32, 32)
|
||||
|
||||
let kd3 = @crypto.hkdf(ck2, b"", b"TunnelLayerIVKey", 64) catch {
|
||||
e => raise Crypto(e)
|
||||
}
|
||||
let ck3 = t_slice(kd3, 0, 32)
|
||||
let iv_key = t_slice(kd3, 32, 32)
|
||||
|
||||
let (garlic_key, garlic_tag) = if is_obep {
|
||||
if is_obep {
|
||||
let kd3 = @crypto.hkdf(ck2, b"", b"TunnelLayerIVKey", 64) catch {
|
||||
e => raise Crypto(e)
|
||||
}
|
||||
let ck3 = t_slice(kd3, 0, 32)
|
||||
let iv_key = t_slice(kd3, 32, 32)
|
||||
let kd4 = @crypto.hkdf(ck3, b"", b"RGarlicKeyAndTag", 64) catch {
|
||||
e => raise Crypto(e)
|
||||
}
|
||||
(Some(t_slice(kd4, 0, 32)), Some(t_slice(kd4, 32, 8)))
|
||||
// Canonical i2pd: garlic_tag = kd4[0..8], garlic_key = kd4[32..64]
|
||||
let garlic_tag = Some(t_slice(kd4, 0, 8))
|
||||
let garlic_key = Some(t_slice(kd4, 32, 32))
|
||||
{ reply_key, layer_key, iv_key, handshake_hash: h, garlic_key, garlic_tag, }
|
||||
} else {
|
||||
(None, None)
|
||||
// Non-OBEP hops use ck2 directly as iv_key (no TunnelLayerIVKey HKDF step)
|
||||
{
|
||||
reply_key,
|
||||
layer_key,
|
||||
iv_key: ck2,
|
||||
handshake_hash: h,
|
||||
garlic_key: None,
|
||||
garlic_tag: None,
|
||||
}
|
||||
}
|
||||
{ reply_key, layer_key, iv_key, handshake_hash: h, garlic_key, garlic_tag, }
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -366,7 +375,7 @@ pub fn build_short_tunnel_request(
|
||||
let keys_k = hop_keys[k].1
|
||||
rec = @crypto.chacha20_xor(
|
||||
keys_k.reply_key,
|
||||
0U,
|
||||
1U,
|
||||
make_slot_nonce(slot_m),
|
||||
rec,
|
||||
) catch {
|
||||
@@ -430,7 +439,7 @@ pub fn process_short_tunnel_build_hop(
|
||||
)
|
||||
} else {
|
||||
out.push(
|
||||
@crypto.chacha20_xor(keys.reply_key, 0U, make_slot_nonce(j), records[j]) catch {
|
||||
@crypto.chacha20_xor(keys.reply_key, 1U, make_slot_nonce(j), records[j]) catch {
|
||||
e => raise Crypto(e)
|
||||
},
|
||||
)
|
||||
@@ -457,7 +466,7 @@ pub fn decrypt_short_tunnel_replies(
|
||||
let keys_k = hop_slots_and_keys[k].1
|
||||
rec = @crypto.chacha20_xor(
|
||||
keys_k.reply_key,
|
||||
0U,
|
||||
1U,
|
||||
make_slot_nonce(slot_m),
|
||||
rec,
|
||||
) catch {
|
||||
|
||||
@@ -25,6 +25,59 @@ test "Proposal 157 ShortTunnelBuild 218-byte record & reply round-trip" {
|
||||
)
|
||||
assert_eq(enc_rec.length(), 218)
|
||||
|
||||
// Verify canonical non-OBEP key derivation: iv_key == ck2 (no TunnelLayerIVKey step)
|
||||
let sym = @noise.SymmetricState::initialize(
|
||||
b"Noise_N_25519_ChaChaPoly_SHA256",
|
||||
)
|
||||
sym.mix_hash(b"")
|
||||
sym.mix_hash(hop_static.public_key)
|
||||
sym.mix_hash(ephem.public_key)
|
||||
let dh = @crypto.x25519(ephem.private_key, hop_static.public_key)
|
||||
sym.mix_key(dh)
|
||||
let pt = req.encode_154()
|
||||
let _ = sym.encrypt_and_hash(pt)
|
||||
let kd1 = @crypto.hkdf(sym.chaining_key(), b"", b"SMTunnelReplyKey", 64)
|
||||
let ck1 = kd1[:32].to_owned()
|
||||
let kd2 = @crypto.hkdf(ck1, b"", b"SMTunnelLayerKey", 64)
|
||||
let ck2 = kd2[:32].to_owned()
|
||||
assert_eq(creator_keys.iv_key, ck2)
|
||||
assert_eq(creator_keys.garlic_key, None)
|
||||
assert_eq(creator_keys.garlic_tag, None)
|
||||
|
||||
// Verify canonical OBEP key derivation: TunnelLayerIVKey + RGarlicKeyAndTag (tag=0..8, key=32..64)
|
||||
let obep_req : @tunnel.ShortBuildRequestRecord = {
|
||||
receive_tunnel_id: 1001U,
|
||||
next_tunnel_id: 2002U,
|
||||
next_ident: next_hash,
|
||||
flag: b'\x40', // OBEP
|
||||
layer_enc_type: b'\x00',
|
||||
request_time_min: 28333333U,
|
||||
request_expiration_sec: 600U,
|
||||
send_message_id: 5555U,
|
||||
options: @common.Mapping::new(),
|
||||
}
|
||||
let (_, obep_keys) = @tunnel.encrypt_short_build_record(
|
||||
obep_req,
|
||||
hop_hash,
|
||||
hop_static.public_key,
|
||||
ephem,
|
||||
)
|
||||
let sym2 = @noise.SymmetricState::initialize(
|
||||
b"Noise_N_25519_ChaChaPoly_SHA256",
|
||||
)
|
||||
sym2.mix_hash(b"")
|
||||
sym2.mix_hash(hop_static.public_key)
|
||||
sym2.mix_hash(ephem.public_key)
|
||||
sym2.mix_key(dh)
|
||||
let _ = sym2.encrypt_and_hash(obep_req.encode_154())
|
||||
let ok1 = @crypto.hkdf(sym2.chaining_key(), b"", b"SMTunnelReplyKey", 64)
|
||||
let ok2 = @crypto.hkdf(ok1[:32].to_owned(), b"", b"SMTunnelLayerKey", 64)
|
||||
let ok3 = @crypto.hkdf(ok2[:32].to_owned(), b"", b"TunnelLayerIVKey", 64)
|
||||
let ok4 = @crypto.hkdf(ok3[:32].to_owned(), b"", b"RGarlicKeyAndTag", 64)
|
||||
assert_eq(obep_keys.iv_key, ok3[32:64].to_owned())
|
||||
assert_eq(obep_keys.garlic_tag, Some(ok4[:8].to_owned()))
|
||||
assert_eq(obep_keys.garlic_key, Some(ok4[32:64].to_owned()))
|
||||
|
||||
// Wrong hop rejects with RecordNotForUs
|
||||
let mut rejected = false
|
||||
try {
|
||||
@@ -99,6 +152,22 @@ test "Proposal 157 multi-hop ShortTunnelBuild onion build, hop relay, OBEP garli
|
||||
assert_true(creator_hop_keys[2].1.garlic_key is Some(_))
|
||||
assert_true(creator_hop_keys[2].1.garlic_tag is Some(_))
|
||||
|
||||
// Verify Proposal 157 canonical ChaCha20 initial block counter 1U on downstream slot 1
|
||||
let (raw_hop1, _) = @tunnel.encrypt_short_build_record(
|
||||
hops[1].record,
|
||||
hops[1].hop_ident,
|
||||
hops[1].hop_static_pub,
|
||||
hops[1].ephemeral,
|
||||
padding=hops[1].padding,
|
||||
)
|
||||
let expected_slot1 = @crypto.chacha20_xor(
|
||||
creator_hop_keys[0].1.reply_key,
|
||||
1U,
|
||||
@tunnel.make_slot_nonce(hops[1].slot_idx),
|
||||
raw_hop1,
|
||||
)
|
||||
assert_eq(req_records[hops[1].slot_idx], expected_slot1)
|
||||
|
||||
let mut wire_records = req_records
|
||||
for i = 0; i < 3; i = i + 1 {
|
||||
let (rec, keys, slot, next_records) = @tunnel.process_short_tunnel_build_hop(
|
||||
|
||||
Reference in new issue
Block a user