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
+167
-8
@@ -206,6 +206,94 @@ pub(all) struct LeaseSet2EncryptionKey {
|
||||
key_data : Bytes
|
||||
}
|
||||
|
||||
///|
|
||||
/// Offline signature block inside a `LeaseSet2` (Proposal 123, `flags & 1 != 0`):
|
||||
/// allows a transient signing key to sign the LeaseSet2 while the Destination's
|
||||
/// long-term signing key stays offline.
|
||||
#derive(Eq, Debug)
|
||||
pub(all) struct OfflineSignature {
|
||||
expires_sec : UInt32
|
||||
transient_sig_type : SigningPublicKeyType
|
||||
transient_pub_key : Bytes
|
||||
signature : Bytes
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn OfflineSignature::unsigned_bytes(self : OfflineSignature) -> Bytes {
|
||||
let w = @encoding.Writer::new(capacity=6 + self.transient_pub_key.length())
|
||||
w.write_u32_be(self.expires_sec)
|
||||
w.write_u16_be(self.transient_sig_type.to_u16())
|
||||
w.write_bytes(self.transient_pub_key)
|
||||
w.to_bytes()
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn OfflineSignature::encode(
|
||||
self : OfflineSignature,
|
||||
w : @encoding.Writer,
|
||||
) -> Unit {
|
||||
w.write_bytes(self.unsigned_bytes())
|
||||
w.write_bytes(self.signature)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn OfflineSignature::decode(
|
||||
r : @encoding.Reader,
|
||||
dest_sig_type : SigningPublicKeyType,
|
||||
) -> OfflineSignature raise CommonError {
|
||||
let expires_sec = r.read_u32_be() catch { e => raise Encoding(e) }
|
||||
let transient_sig_type = SigningPublicKeyType::from_u16(
|
||||
r.read_u16_be() catch {
|
||||
e => raise Encoding(e)
|
||||
},
|
||||
)
|
||||
let tkey_len = transient_sig_type.public_key_length()
|
||||
if tkey_len <= 0 {
|
||||
raise InvalidFormat(
|
||||
"unsupported transient signing type in OfflineSignature",
|
||||
)
|
||||
}
|
||||
let transient_pub_key = r.read_bytes(tkey_len) catch {
|
||||
e => raise Encoding(e)
|
||||
}
|
||||
let dsig_len = dest_sig_type.signature_length()
|
||||
if dsig_len <= 0 {
|
||||
raise InvalidFormat(
|
||||
"unsupported destination signing type in OfflineSignature",
|
||||
)
|
||||
}
|
||||
let signature = r.read_bytes(dsig_len) catch { e => raise Encoding(e) }
|
||||
{ expires_sec, transient_sig_type, transient_pub_key, signature, }
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn OfflineSignature::sign_ed25519(
|
||||
self : OfflineSignature,
|
||||
dest_seed : Bytes,
|
||||
) -> OfflineSignature raise CommonError {
|
||||
let sig = @crypto.ed25519_sign(dest_seed, self.unsigned_bytes()) catch {
|
||||
e => raise Crypto(e)
|
||||
}
|
||||
{
|
||||
expires_sec: self.expires_sec,
|
||||
transient_sig_type: self.transient_sig_type,
|
||||
transient_pub_key: self.transient_pub_key,
|
||||
signature: sig,
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn OfflineSignature::verify_ed25519(
|
||||
self : OfflineSignature,
|
||||
dest_signing_pub : Bytes,
|
||||
) -> Bool {
|
||||
@crypto.ed25519_verify(
|
||||
dest_signing_pub,
|
||||
self.unsigned_bytes(),
|
||||
self.signature,
|
||||
)
|
||||
}
|
||||
|
||||
///|
|
||||
/// Modern LeaseSet2 (I2P Proposal 123, NetDB type 3).
|
||||
#derive(Eq, Debug)
|
||||
@@ -213,7 +301,8 @@ pub(all) struct LeaseSet2 {
|
||||
destination : Destination
|
||||
published_sec : UInt32
|
||||
expires_offset : UInt32 // uint16 offset in seconds from published_sec
|
||||
flags : UInt32 // uint16
|
||||
flags : UInt32 // uint16 (bit 0 = offline keys present)
|
||||
offline_sig : OfflineSignature?
|
||||
options : Mapping
|
||||
encryption_keys : Array[LeaseSet2EncryptionKey]
|
||||
leases : Array[Lease2]
|
||||
@@ -228,6 +317,15 @@ pub fn LeaseSet2::unsigned_bytes(self : LeaseSet2) -> Bytes raise CommonError {
|
||||
w.write_u32_be(self.published_sec)
|
||||
w.write_u16_be(self.expires_offset)
|
||||
w.write_u16_be(self.flags)
|
||||
if (self.flags & 0x0001U) != 0U {
|
||||
match self.offline_sig {
|
||||
Some(os) => os.encode(w)
|
||||
None =>
|
||||
raise InvalidFormat(
|
||||
"LeaseSet2 offline signature flag set without offline_sig",
|
||||
)
|
||||
}
|
||||
}
|
||||
self.options.encode(w)
|
||||
w.write_u8(self.encryption_keys.length().to_byte())
|
||||
for ek in self.encryption_keys {
|
||||
@@ -289,6 +387,7 @@ pub fn LeaseSet2::sign_ed25519(
|
||||
published_sec: self.published_sec,
|
||||
expires_offset: self.expires_offset,
|
||||
flags: self.flags,
|
||||
offline_sig: self.offline_sig,
|
||||
options: self.options,
|
||||
encryption_keys: self.encryption_keys,
|
||||
leases: self.leases,
|
||||
@@ -297,17 +396,68 @@ pub fn LeaseSet2::sign_ed25519(
|
||||
}
|
||||
|
||||
///|
|
||||
/// Verifies the `LeaseSet2` Ed25519 signature against `self.destination.inner.signing_public_key()`.
|
||||
/// Signs a `LeaseSet2` that carries an `OfflineSignature` (`flags & 1 != 0`)
|
||||
/// using the transient Ed25519 signing seed.
|
||||
pub fn LeaseSet2::sign_with_transient_ed25519(
|
||||
self : LeaseSet2,
|
||||
transient_seed : Bytes,
|
||||
) -> LeaseSet2 raise CommonError {
|
||||
if (self.flags & 0x0001U) == 0U {
|
||||
raise InvalidFormat("LeaseSet2 offline signature flag (bit 0) must be set")
|
||||
}
|
||||
match self.offline_sig {
|
||||
Some(os) =>
|
||||
if os.transient_sig_type != EdDsaSha512Ed25519 {
|
||||
raise InvalidFormat(
|
||||
"LeaseSet2 transient signing type must be EdDsaSha512Ed25519",
|
||||
)
|
||||
}
|
||||
None => raise InvalidFormat("LeaseSet2 offline_sig is missing")
|
||||
}
|
||||
let to_sign = self.signing_bytes()
|
||||
let signature = @crypto.ed25519_sign(transient_seed, to_sign) catch {
|
||||
e => raise Crypto(e)
|
||||
}
|
||||
{
|
||||
destination: self.destination,
|
||||
published_sec: self.published_sec,
|
||||
expires_offset: self.expires_offset,
|
||||
flags: self.flags,
|
||||
offline_sig: self.offline_sig,
|
||||
options: self.options,
|
||||
encryption_keys: self.encryption_keys,
|
||||
leases: self.leases,
|
||||
signature,
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
/// Verifies the `LeaseSet2` Ed25519 signature (including any `OfflineSignature` chain).
|
||||
pub fn LeaseSet2::verify_signature(self : LeaseSet2) -> Bool {
|
||||
if self.destination.inner.signing_type() != EdDsaSha512Ed25519 {
|
||||
return false
|
||||
}
|
||||
let to_sign = self.signing_bytes() catch { _ => return false }
|
||||
@crypto.ed25519_verify(
|
||||
self.destination.inner.signing_public_key(),
|
||||
to_sign,
|
||||
self.signature,
|
||||
)
|
||||
if (self.flags & 0x0001U) != 0U {
|
||||
match self.offline_sig {
|
||||
Some(os) => {
|
||||
if os.transient_sig_type != EdDsaSha512Ed25519 {
|
||||
return false
|
||||
}
|
||||
if !os.verify_ed25519(self.destination.inner.signing_public_key()) {
|
||||
return false
|
||||
}
|
||||
@crypto.ed25519_verify(os.transient_pub_key, to_sign, self.signature)
|
||||
}
|
||||
None => false
|
||||
}
|
||||
} else {
|
||||
@crypto.ed25519_verify(
|
||||
self.destination.inner.signing_public_key(),
|
||||
to_sign,
|
||||
self.signature,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -316,6 +466,11 @@ pub fn LeaseSet2::decode(r : @encoding.Reader) -> LeaseSet2 raise CommonError {
|
||||
let published_sec = r.read_u32_be() catch { e => raise Encoding(e) }
|
||||
let expires_offset = r.read_u16_be() catch { e => raise Encoding(e) }
|
||||
let flags = r.read_u16_be() catch { e => raise Encoding(e) }
|
||||
let offline_sig = if (flags & 0x0001U) != 0U {
|
||||
Some(OfflineSignature::decode(r, destination.inner.signing_type()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
let options = Mapping::decode(r)
|
||||
let key_count = (r.read_u8() catch { e => raise Encoding(e) }).to_int()
|
||||
let encryption_keys : Array[LeaseSet2EncryptionKey] = Array(
|
||||
@@ -336,7 +491,10 @@ pub fn LeaseSet2::decode(r : @encoding.Reader) -> LeaseSet2 raise CommonError {
|
||||
for _i = 0; _i < lease_count; _i = _i + 1 {
|
||||
leases.push(Lease2::decode(r))
|
||||
}
|
||||
let sig_len = destination.inner.signing_type().signature_length()
|
||||
let sig_len = match offline_sig {
|
||||
Some(os) => os.transient_sig_type.signature_length()
|
||||
None => destination.inner.signing_type().signature_length()
|
||||
}
|
||||
let signature = if sig_len > 0 {
|
||||
r.read_bytes(sig_len) catch {
|
||||
e => raise Encoding(e)
|
||||
@@ -349,6 +507,7 @@ pub fn LeaseSet2::decode(r : @encoding.Reader) -> LeaseSet2 raise CommonError {
|
||||
published_sec,
|
||||
expires_offset,
|
||||
flags,
|
||||
offline_sig,
|
||||
options,
|
||||
encryption_keys,
|
||||
leases,
|
||||
|
||||
Reference in new issue
Block a user