Skip to content

Refactor ALTS handshake + record layer, add AES-GCM(-ReKey) support, tighten framing & timeouts#34

Closed
mateeullahmalik wants to merge 1 commit intomasterfrom
fixP2PSecureConnectionHandler
Closed

Refactor ALTS handshake + record layer, add AES-GCM(-ReKey) support, tighten framing & timeouts#34
mateeullahmalik wants to merge 1 commit intomasterfrom
fixP2PSecureConnectionHandler

Conversation

@mateeullahmalik
Copy link
Collaborator

Why
Performance: XChaCha20-Poly1305 is ~3× slower than AES-GCM on our hosts.

Stability: The goroutine-per-read approach sometimes leaked when peers hung the socket.

Security hardening: No guard against oversized frames → easy DoS.

Extensibility: Adding a new record cipher required touching switch statements all over.

Impact
API – No public signature changes; callers are unaffected.

Interop – New code still advertises XChaCha for older peers, but prefers AES-GCM-ReKey when both sides support it.

Perf – Local bench (go test -run=NONE -bench .) shows ≈ +40 % throughput on encryption/decryption; handshake allocs down ~1.5 KB.

Security – Oversized-frame and slow-loris attempts now fail fast.

@mateeullahmalik mateeullahmalik force-pushed the fixP2PSecureConnectionHandler branch from 6ec121a to 98d55bb Compare April 30, 2025 15:29
@mateeullahmalik mateeullahmalik requested a review from a-ok123 April 30, 2025 15:31
@a-ok123 a-ok123 requested review from akobrin1 and Copilot May 1, 2025 00:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the ALTS handshake and record layer to improve performance, stability, and security by adding support for AES-GCM(-ReKey) and tightening framing and timeouts.

  • Change the default record protocol from XChaCha20-Poly1305ReKey to AESGCMReKey.
  • Replace goroutine-based handshake message reads with synchronous calls leveraging connection deadlines.
  • Introduce a thread-safe protocol registration mechanism and add new AES-GCM cipher implementations.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
pkg/net/credentials/alts/handshake/handshake.go Updated default protocol and streamlined handshake read functions.
pkg/net/credentials/alts/conn/register.go Added thread-safe protocol registration via mutex-protected maps.
pkg/net/credentials/alts/conn/record.go Integrated new AES-GCM and AES-GCM-ReKey implementations with init().
pkg/net/credentials/alts/common/utils.go Improved handshake message normalization and enforced a max frame size.
Comments suppressed due to low confidence (3)

pkg/net/credentials/alts/handshake/handshake.go:95

  • The default protocol has been changed to RecordProtocolAESGCMReKey. Confirm that all components relying on the previous protocol are updated and tested for compatibility.
protocol:     RecordProtocolAESGCMReKey,

pkg/net/credentials/alts/conn/record.go:106

  • The Encrypt method always initializes the nonce as a zeroed slice. Ensure that nonce uniqueness is guaranteed by the external frame layer or update the nonce generation strategy to prevent reuse.
nonce := make([]byte, r.aead.NonceSize())

pkg/net/credentials/alts/common/utils.go:77

  • The maxFrameSize constant (64 KiB) is imposed on handshake messages; verify that this limit accommodates all expected handshake message sizes to avoid unintended rejections.
if handshakeLen == 0 || handshakeLen > maxFrameSize {

@mateeullahmalik mateeullahmalik deleted the fixP2PSecureConnectionHandler branch May 14, 2025 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants