module

Raft::Transport::Handshake

Mutual HMAC-SHA256 cookie authentication for TCP connections.

Uses standard TLV framing (type 0x00 for handshake, 0xFF for error). Both sides exchange a challenge frame and verify the peer holds the same cookie. The responder's HMAC is bound to the initiator's nonce, preventing replay attacks.

Protocol flow:

  1. Initiator sends Handshake(HMAC(cookie, nonce_i), nonce_i)
  2. Responder verifies initiator's HMAC
  3. Responder sends Handshake(HMAC(cookie, nonce_i || nonce_r), nonce_r)
  4. Initiator verifies responder's HMAC using both nonces
  5. Both sides are now authenticated — normal TLV messages follow

Constants

HMAC_SIZE = 32

Size of the HMAC-SHA256 digest in bytes.

NONCE_SIZE = 32

Size of the random nonce in bytes.

Class methods