fix protocol+tests: replay protection rework, wire envelope nonce auth,
flaky e2e test deadlines, build imports
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user