fix protocol+tests: replay protection rework, wire envelope nonce auth,

flaky e2e test deadlines, build imports
This commit is contained in:
2026-02-13 16:37:30 -03:00
parent c94d189d42
commit 6ec1346cfd
22 changed files with 2275 additions and 786 deletions

View File

@@ -207,6 +207,14 @@ pub const PeerConnection = struct {
return null;
}
/// Get per-session envelope key from Noise handshake (null when unencrypted)
pub fn getEnvelopeKey(self: *const PeerConnection) ?[16]u8 {
if (self.secure) |sec| {
return sec.getEnvelopeKey();
}
return null;
}
/// Get remaining data to send (if any)
pub fn getPendingRemaining(self: *const PeerConnection) ?[]const u8 {
if (self.pending_send) |*ps| {
@@ -643,8 +651,18 @@ pub const NetworkManager = struct {
if (peer_conn.secure) |secure| {
defer self.releaseSocketLock();
// SecureConnection.send handles encryption and length prefixing
_ = secure.send(data) catch |err| {
// Prepend 4-byte big-endian inner length header to plaintext.
// The receive side strips this after decryption (line ~1184).
// This matches the unencrypted framing format inside the ciphertext.
var inner_msg = self.allocator.alloc(u8, 4 + data.len) catch {
return Error.OutOfMemory;
};
defer self.allocator.free(inner_msg);
std.mem.writeInt(u32, inner_msg[0..4], @intCast(data.len), .big);
@memcpy(inner_msg[4..], data);
// SecureConnection.send handles encryption and outer length prefixing
_ = secure.send(inner_msg) catch |err| {
self.stats.recordSendError();
return switch (err) {
secure_connection.Error.HandshakeTimeout,