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
@@ -9,6 +9,9 @@
|
||||
///|
|
||||
pub let ecies_protocol_name : Bytes = b"Noise_IKelg2+hs2_25519_ChaChaPoly_SHA256"
|
||||
|
||||
///|
|
||||
pub let router_garlic_protocol_name : Bytes = b"Noise_N_25519_ChaChaPoly_SHA256"
|
||||
|
||||
///|
|
||||
fn r_slice(data : Bytes, start : Int32, len : Int32) -> Bytes {
|
||||
let out = FixedArray::make(len, b'\x00')
|
||||
@@ -559,6 +562,56 @@ pub fn decrypt_ecies_lookup_reply(
|
||||
decode_blocks(pt)
|
||||
}
|
||||
|
||||
///|
|
||||
/// Encrypts Garlic blocks to a router's static X25519 key using Proposal 144 `Noise_N_25519_ChaChaPoly_SHA256`
|
||||
/// (canonical `WrapECIESX25519MessageForRouter`: `raw_ephem_pub (32B) || AEAD ciphertext`).
|
||||
pub fn encrypt_router_garlic(
|
||||
remote_static_pub : Bytes,
|
||||
ephemeral : @noise.KeyPair,
|
||||
blocks : Array[RatchetBlock],
|
||||
) -> Bytes raise RatchetError {
|
||||
if remote_static_pub.length() != 32 {
|
||||
raise InvalidLength("remote_static_pub must be 32 bytes")
|
||||
}
|
||||
let sym = @noise.SymmetricState::initialize(router_garlic_protocol_name)
|
||||
sym.mix_hash(b"") // null prologue
|
||||
sym.mix_hash(remote_static_pub)
|
||||
sym.mix_hash(ephemeral.public_key)
|
||||
let dh = @crypto.x25519(ephemeral.private_key, remote_static_pub) catch {
|
||||
e => raise Crypto(e)
|
||||
}
|
||||
sym.mix_key(dh)
|
||||
let pt = encode_blocks(blocks)
|
||||
let ct = sym.encrypt_and_hash(pt) catch { e => raise Noise(e) }
|
||||
let w = @encoding.Writer::new(capacity=32 + ct.length())
|
||||
w.write_bytes(ephemeral.public_key)
|
||||
w.write_bytes(ct)
|
||||
w.to_bytes()
|
||||
}
|
||||
|
||||
///|
|
||||
/// Decrypts a router-targeted `Noise_N_25519_ChaChaPoly_SHA256` Garlic message addressed to `local_static`.
|
||||
pub fn decrypt_router_garlic(
|
||||
local_static : @noise.KeyPair,
|
||||
data : Bytes,
|
||||
) -> Array[RatchetBlock] raise RatchetError {
|
||||
if data.length() < 48 {
|
||||
raise InvalidLength("Router Garlic shorter than 48 bytes")
|
||||
}
|
||||
let ephem_pub = r_slice(data, 0, 32)
|
||||
let ct = r_slice(data, 32, data.length() - 32)
|
||||
let sym = @noise.SymmetricState::initialize(router_garlic_protocol_name)
|
||||
sym.mix_hash(b"")
|
||||
sym.mix_hash(local_static.public_key)
|
||||
sym.mix_hash(ephem_pub)
|
||||
let dh = @crypto.x25519(local_static.private_key, ephem_pub) catch {
|
||||
e => raise Crypto(e)
|
||||
}
|
||||
sym.mix_key(dh)
|
||||
let pt = sym.decrypt_and_hash(ct) catch { _ => raise AuthenticationFailed }
|
||||
decode_blocks(pt)
|
||||
}
|
||||
|
||||
///|
|
||||
/// High-level session manager handling New Session, New Session Reply, and Existing Session
|
||||
/// state transitions for a local I2P Destination.
|
||||
|
||||
@@ -21,6 +21,8 @@ pub fn decrypt_new_session(@noise.KeyPair, Bytes) -> (Array[RatchetBlock], Pendi
|
||||
|
||||
pub fn decrypt_new_session_reply(@noise.KeyPair, PendingNewSession, Bytes) -> (Array[RatchetBlock], RatchetPeerSession) raise RatchetError
|
||||
|
||||
pub fn decrypt_router_garlic(@noise.KeyPair, Bytes) -> Array[RatchetBlock] raise RatchetError
|
||||
|
||||
pub fn dh_initialize(Bytes, Bytes) -> (Bytes, TagSet) raise RatchetError
|
||||
|
||||
pub let ecies_protocol_name : Bytes
|
||||
@@ -33,10 +35,14 @@ pub fn encrypt_new_session(@noise.KeyPair?, Bytes, ElligatorKeyPair, Array[Ratch
|
||||
|
||||
pub fn encrypt_new_session_reply(PendingNewSession, ElligatorKeyPair, Array[RatchetBlock]) -> (Bytes, RatchetPeerSession) raise RatchetError
|
||||
|
||||
pub fn encrypt_router_garlic(Bytes, @noise.KeyPair, Array[RatchetBlock]) -> Bytes raise RatchetError
|
||||
|
||||
pub fn garlic_clove_block(GarlicDelivery, UInt32, UInt32, @i2np.I2npPayload) -> RatchetBlock raise RatchetError
|
||||
|
||||
pub fn generate_elligator_keypair(() -> Bytes) -> ElligatorKeyPair raise RatchetError
|
||||
|
||||
pub let router_garlic_protocol_name : Bytes
|
||||
|
||||
// Errors
|
||||
#derive(Eq, @debug.Debug)
|
||||
pub suberror RatchetError {
|
||||
|
||||
@@ -162,4 +162,31 @@ test "Proposal 144 ECIES-X25519-AEAD-Ratchet NS -> NSR -> bidirectional ES + DH
|
||||
let enc_dsm = @ratchet.encrypt_ecies_lookup_reply(rkey, rtag, [dsm_blk])
|
||||
let dec_dsm = @ratchet.decrypt_ecies_lookup_reply(rkey, rtag, enc_dsm)
|
||||
assert_eq(dec_dsm, [dsm_blk])
|
||||
|
||||
// 6. Router-targeted Noise_N Garlic round-trip & auth check
|
||||
let router_s = @noise.KeyPair::from_private(
|
||||
@crypto.sha256(b"router-n-static"),
|
||||
)
|
||||
let ephem_n = @noise.KeyPair::from_private(@crypto.sha256(b"router-n-ephem"))
|
||||
let wrong_s = @noise.KeyPair::from_private(@crypto.sha256(b"wrong-n-static"))
|
||||
let router_clove = @ratchet.garlic_clove_block(
|
||||
Local,
|
||||
123U,
|
||||
1700000600U,
|
||||
Data(data=b"lookup-payload"),
|
||||
)
|
||||
let rg_wire = @ratchet.encrypt_router_garlic(router_s.public_key, ephem_n, [
|
||||
DateTime(1700000200U),
|
||||
router_clove,
|
||||
])
|
||||
let rg_dec = @ratchet.decrypt_router_garlic(router_s, rg_wire)
|
||||
assert_eq(rg_dec, [DateTime(1700000200U), router_clove])
|
||||
let mut wrong_failed = false
|
||||
try {
|
||||
let _ = @ratchet.decrypt_router_garlic(wrong_s, rg_wire)
|
||||
} catch {
|
||||
AuthenticationFailed => wrong_failed = true
|
||||
_ => ()
|
||||
}
|
||||
assert_eq(wrong_failed, true)
|
||||
}
|
||||
Reference in new issue
Block a user