Feat: ConnAuth HMAC verification gated by YAMA_CONN_AUTH_KEY

Verify the HMAC-SHA256 signature and timestamp of device sub-connections
(screen/terminal/file) when the YAMA_CONN_AUTH_KEY environment variable is
set. With the key set, a sub-connection whose signature or clock skew fails
is answered with a non-OK ConnAuth status and dropped; without the key the
legacy always-OK behavior is preserved.

The key is never compiled in: it is read from the environment at startup, so
no secret enters the repository. Source-IP binding in hub.BindScreenConn
remains in place as defense-in-depth.

Co-Authored-By: deepseek-v4-pro
This commit is contained in:
yuanyuanxianganddeepseek-v4-pro committed 2026-10-15 19:43:58 +02:00
1 parent 4ff965a2b4
commit 7651ee8602
3 files changed
+222 -19

No files matched your search

+17 -2
View File
@@ -140,11 +140,26 @@ const (
ConnAuthOffClientID = 1 // uint64 LE — pin to the sub-conn so later
// // 1-byte tokens (TOKEN_TERMINAL_START etc.) can
// // resolve the parent device.
ConnAuthOffTimestamp = 9 // uint64 LE - Unix seconds, anti-replay window
ConnAuthOffNonce = 17 // [16]byte - part of the signed message
ConnAuthOffSignature = 33 // [64]byte - hex of HMAC-SHA256(key, clientID||timestamp||nonce)
ConnAuthSignatureSize = 64
// ConnAuthAck field offsets within the outbound 256-byte buffer.
ConnAuthAckOffStatus = 1 // uint8
ConnAuthAckOffServerTime = 2 // uint64 LE
// Status codes.
ConnAuthStatusOK byte = 0
// ConnAuthTimestampToleranceSec bounds |server - client| clock skew in
// seconds (matches CONN_AUTH_TIMESTAMP_TOLERANCE_SEC in common/commands.h).
// A timestamp outside this window is treated as replayed or forged.
ConnAuthTimestampToleranceSec = 300
// Status codes (match common/commands.h::ConnAuthStatus). The client treats
// any non-zero status as failure and drops the sub-connection.
ConnAuthStatusOK byte = 0
ConnAuthStatusBadSize byte = 1 // packet shorter than the signature field
ConnAuthStatusClockSkew byte = 2 // timestamp outside tolerance
ConnAuthStatusBadSignature byte = 3 // HMAC mismatch
ConnAuthStatusInternalError byte = 4
)
// CMD_MASTERSETTING is the server's reply to a fresh client login. The