- 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)
119 lines
3.8 KiB
MoonBit
119 lines
3.8 KiB
MoonBit
///|
|
|
/// I2P SU3 signed container parser & reseed bundle (`i2pseeds.su3`) extractor.
|
|
|
|
///|
|
|
#derive(Eq, Debug)
|
|
pub(all) struct Su3File {
|
|
format_version : Byte
|
|
sig_type : UInt32
|
|
version : String
|
|
signer_id : String
|
|
file_type : Byte // 0 = ZIP, 1 = XML, 2 = HTML, 3 = XML.GZ
|
|
content_type : Byte // 1 = router update, 2 = plugin, 3 = reseed, 4 = news, 5 = blocklist
|
|
content : Bytes
|
|
signature : Bytes
|
|
signed_bytes_len : Int32
|
|
}
|
|
|
|
///|
|
|
/// Decodes an I2P SU3 file header, payload content, and trailing signature.
|
|
pub fn Su3File::decode(data : Bytes) -> Su3File raise CommonError {
|
|
if data.length() < 40 {
|
|
raise InvalidLength("SU3 file shorter than 40 bytes: \{data.length()}")
|
|
}
|
|
if data[0] != b'\x49' ||
|
|
data[1] != b'\x32' ||
|
|
data[2] != b'\x50' ||
|
|
data[3] != b'\x73' ||
|
|
data[4] != b'\x75' ||
|
|
data[5] != b'\x33' {
|
|
raise InvalidFormat("invalid SU3 magic header (expected 'I2Psu3')")
|
|
}
|
|
let r = @encoding.Reader::new(data)
|
|
r.skip(6) catch {
|
|
e => raise Encoding(e)
|
|
}
|
|
let _unused6 = r.read_u8() catch { e => raise Encoding(e) }
|
|
let format_version = r.read_u8() catch { e => raise Encoding(e) }
|
|
if format_version != b'\x00' {
|
|
raise InvalidFormat(
|
|
"unsupported SU3 format version: \{format_version.to_int()}",
|
|
)
|
|
}
|
|
let sig_type = r.read_u16_be() catch { e => raise Encoding(e) }
|
|
let sig_len = (r.read_u16_be() catch { e => raise Encoding(e) }).reinterpret_as_int()
|
|
let _unused12 = r.read_u8() catch { e => raise Encoding(e) }
|
|
let version_len = (r.read_u8() catch { e => raise Encoding(e) }).to_int()
|
|
let _unused14 = r.read_u8() catch { e => raise Encoding(e) }
|
|
let signer_id_len = (r.read_u8() catch { e => raise Encoding(e) }).to_int()
|
|
let content_len_u64 = r.read_u64_be() catch { e => raise Encoding(e) }
|
|
if content_len_u64 > 64UL * 1024UL * 1024UL {
|
|
raise InvalidLength("SU3 content length too large")
|
|
}
|
|
let content_len = content_len_u64.to_int()
|
|
let _unused24 = r.read_u8() catch { e => raise Encoding(e) }
|
|
let file_type = r.read_u8() catch { e => raise Encoding(e) }
|
|
let _unused26 = r.read_u8() catch { e => raise Encoding(e) }
|
|
let content_type = r.read_u8() catch { e => raise Encoding(e) }
|
|
r.skip(12) catch {
|
|
e => raise Encoding(e)
|
|
}
|
|
let version_bytes = r.read_bytes(version_len) catch { e => raise Encoding(e) }
|
|
let version = @encoding.utf8_bytes_to_string(version_bytes) catch {
|
|
e => raise Encoding(e)
|
|
}
|
|
let signer_bytes = r.read_bytes(signer_id_len) catch {
|
|
e => raise Encoding(e)
|
|
}
|
|
let signer_id = @encoding.utf8_bytes_to_string(signer_bytes) catch {
|
|
e => raise Encoding(e)
|
|
}
|
|
let content = r.read_bytes(content_len) catch { e => raise Encoding(e) }
|
|
let signed_bytes_len = r.position()
|
|
let signature = r.read_bytes(sig_len) catch { e => raise Encoding(e) }
|
|
{
|
|
format_version,
|
|
sig_type,
|
|
version,
|
|
signer_id,
|
|
file_type,
|
|
content_type,
|
|
content,
|
|
signature,
|
|
signed_bytes_len,
|
|
}
|
|
}
|
|
|
|
///|
|
|
/// Extracts and Ed25519-verifies all `routerInfo-*.dat` entries from an I2P reseed `.su3` file.
|
|
pub fn parse_reseed_su3(data : Bytes) -> Array[RouterInfo] raise CommonError {
|
|
let su3 = Su3File::decode(data)
|
|
if su3.file_type != b'\x00' {
|
|
raise InvalidFormat(
|
|
"reseed SU3 must contain a ZIP file (type 0), got \{su3.file_type.to_int()}",
|
|
)
|
|
}
|
|
if su3.content_type != b'\x03' {
|
|
raise InvalidFormat(
|
|
"reseed SU3 must have content type 3, got \{su3.content_type.to_int()}",
|
|
)
|
|
}
|
|
let files = @encoding.zip_extract_entries(su3.content) catch {
|
|
e => raise Encoding(e)
|
|
}
|
|
let peers : Array[RouterInfo] = []
|
|
for item in files {
|
|
let (name, raw) = item
|
|
if !name.has_suffix(".dat") {
|
|
continue
|
|
}
|
|
let ri = RouterInfo::decode(@encoding.Reader::new(raw)) catch {
|
|
_ => continue
|
|
}
|
|
if ri.verify_signature() {
|
|
peers.push(ri)
|
|
}
|
|
}
|
|
peers
|
|
}
|