- 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)
123 lines
3.2 KiB
MoonBit
123 lines
3.2 KiB
MoonBit
///|
|
|
/// Canonical I2P Repliable Datagrams (I2CP protocol 17) and Raw Datagrams (I2CP protocol 18).
|
|
|
|
///|
|
|
#derive(Eq, Debug)
|
|
pub(all) struct RepliableDatagram {
|
|
sender : @common.Destination
|
|
signature : Bytes
|
|
payload : Bytes
|
|
}
|
|
|
|
///|
|
|
/// Signs `payload` directly with Ed25519 `seed` (per I2P Repliable Datagram spec for non-DSA_SHA1).
|
|
pub fn RepliableDatagram::sign_ed25519(
|
|
sender : @common.Destination,
|
|
seed : Bytes,
|
|
payload : Bytes,
|
|
) -> RepliableDatagram raise StreamingError {
|
|
if sender.inner.signing_type() != EdDsaSha512Ed25519 {
|
|
raise InvalidFormat(
|
|
"RepliableDatagram sender signing type must be EdDsaSha512Ed25519",
|
|
)
|
|
}
|
|
let signature = @crypto.ed25519_sign(seed, payload) catch {
|
|
e => raise Crypto(e)
|
|
}
|
|
{ sender, signature, payload, }
|
|
}
|
|
|
|
///|
|
|
pub fn RepliableDatagram::verify(self : RepliableDatagram) -> Bool {
|
|
match self.sender.inner.signing_type() {
|
|
EdDsaSha512Ed25519 =>
|
|
@crypto.ed25519_verify(
|
|
self.sender.inner.signing_public_key(),
|
|
self.payload,
|
|
self.signature,
|
|
)
|
|
_ => false
|
|
}
|
|
}
|
|
|
|
///|
|
|
pub fn RepliableDatagram::encode(self : RepliableDatagram) -> Bytes {
|
|
let w = @encoding.Writer::new(
|
|
capacity=391 + self.signature.length() + self.payload.length(),
|
|
)
|
|
self.sender.encode(w)
|
|
w.write_bytes(self.signature)
|
|
w.write_bytes(self.payload)
|
|
w.to_bytes()
|
|
}
|
|
|
|
///|
|
|
pub fn RepliableDatagram::decode(
|
|
data : Bytes,
|
|
) -> RepliableDatagram raise StreamingError {
|
|
let r = @encoding.Reader::new(data)
|
|
let sender = @common.Destination::decode(r) catch { e => raise Common(e) }
|
|
let sig_len = sender.inner.signing_type().signature_length()
|
|
if sig_len <= 0 {
|
|
raise InvalidFormat("unsupported RepliableDatagram signing type")
|
|
}
|
|
let signature = r.read_bytes(sig_len) catch { e => raise Encoding(e) }
|
|
let payload = r.read_remaining()
|
|
{ sender, signature, payload, }
|
|
}
|
|
|
|
///|
|
|
pub fn RepliableDatagram::to_i2cp_bytes(
|
|
self : RepliableDatagram,
|
|
from_port~ : UInt32 = 0U,
|
|
to_port~ : UInt32 = 0U,
|
|
) -> Bytes {
|
|
@encoding.i2cp_gzip_wrap(
|
|
self.encode(),
|
|
from_port~,
|
|
to_port~,
|
|
protocol=b'\x11',
|
|
)
|
|
}
|
|
|
|
///|
|
|
pub fn RepliableDatagram::from_i2cp_bytes(
|
|
i2cp_bytes : Bytes,
|
|
) -> (@encoding.I2cpGzipHeader, RepliableDatagram) raise StreamingError {
|
|
let (hdr, raw) = @encoding.i2cp_gzip_unwrap(i2cp_bytes) catch {
|
|
e => raise Encoding(e)
|
|
}
|
|
if hdr.protocol != b'\x11' {
|
|
raise InvalidFormat(
|
|
"expected I2CP protocol 17 (Repliable Datagram), got \{hdr.protocol.to_int()}",
|
|
)
|
|
}
|
|
(hdr, RepliableDatagram::decode(raw))
|
|
}
|
|
|
|
///|
|
|
/// Wraps a raw (non-repliable) datagram in an I2CP Gzip envelope (`protocol = 18`).
|
|
pub fn encode_raw_datagram(
|
|
payload : Bytes,
|
|
from_port~ : UInt32 = 0U,
|
|
to_port~ : UInt32 = 0U,
|
|
) -> Bytes {
|
|
@encoding.i2cp_gzip_wrap(payload, from_port~, to_port~, protocol=b'\x12')
|
|
}
|
|
|
|
///|
|
|
/// Unwraps an I2CP Gzip raw datagram (`protocol = 18`).
|
|
pub fn decode_raw_datagram(
|
|
i2cp_bytes : Bytes,
|
|
) -> (@encoding.I2cpGzipHeader, Bytes) raise StreamingError {
|
|
let (hdr, raw) = @encoding.i2cp_gzip_unwrap(i2cp_bytes) catch {
|
|
e => raise Encoding(e)
|
|
}
|
|
if hdr.protocol != b'\x12' {
|
|
raise InvalidFormat(
|
|
"expected I2CP protocol 18 (Raw Datagram), got \{hdr.protocol.to_int()}",
|
|
)
|
|
}
|
|
(hdr, raw)
|
|
}
|