controlbase: add hybrid ML-KEM ts2021 handshake

Teach controlbase to switch to a hybrid X25519 plus ML-KEM-768
handshake for ts2021 protocol versions 142 and newer. The legacy
Noise IK wire format remains available for older protocol versions, while
newer clients must send the expanded PQ initiation and response frames.

The ML-KEM public key and ciphertext are transcript-bound, and both
sides mix the resulting ML-KEM shared secret into the Noise chaining key
before deriving transport keys. Add tests for legacy and PQ handshakes,
wire-format selection, mismatch rejection, and tampering of PQ fields.

Updates #14370

Change-Id: I6877d9fa71d01782a2034777ae720020fe52b168
This commit is contained in:
Brad Fitzpatrick committed 2026-06-10 00:27:45 +00:00
1 parent 632293de7d
commit 223a8d5291
4 files changed
+506 -20

No files matched your search

+272 -16
View File
@@ -6,6 +6,7 @@ package controlbase
import (
"context"
"crypto/cipher"
"crypto/mlkem"
"encoding/binary"
"errors"
"fmt"
@@ -41,6 +42,10 @@ const (
// matches the advertised version in the cleartext packet header.
protocolVersionPrefix = "Tailscale Control Protocol v"
invalidNonce = ^uint64(0)
// pqMinProtocolVersion is the first ts2021/control protocol version that
// uses the hybrid X25519 + ML-KEM-768 handshake.
pqMinProtocolVersion uint16 = 142
)
func protocolVersionPrologue(version uint16) []byte {
@@ -49,6 +54,10 @@ func protocolVersionPrologue(version uint16) []byte {
return strconv.AppendUint(ret, uint64(version), 10)
}
func usesPQHandshake(version uint16) bool {
return version >= pqMinProtocolVersion
}
// HandshakeContinuation upgrades a net.Conn to a Conn. The net.Conn
// is assumed to have already sent the client>server handshake
// initiation message.
@@ -66,6 +75,10 @@ type HandshakeContinuation func(context.Context, net.Conn) (*Conn, error)
// message and a continuation, we can embed the handshake initiation
// into the HTTP protocol switching request and avoid a bit of delay.
func ClientDeferred(machineKey key.MachinePrivate, controlKey key.MachinePublic, protocolVersion uint16) (initialHandshake []byte, continueHandshake HandshakeContinuation, err error) {
if usesPQHandshake(protocolVersion) {
return clientDeferredPQ(machineKey, controlKey, protocolVersion)
}
var s symmetricState
s.Initialize()
@@ -100,6 +113,50 @@ func ClientDeferred(machineKey key.MachinePrivate, controlKey key.MachinePublic,
return init[:], cont, nil
}
func clientDeferredPQ(machineKey key.MachinePrivate, controlKey key.MachinePublic, protocolVersion uint16) (initialHandshake []byte, continueHandshake HandshakeContinuation, err error) {
var s symmetricState
s.Initialize()
// prologue
s.MixHash(protocolVersionPrologue(protocolVersion))
// <- s
// ...
s.MixHash(controlKey.UntypedBytes())
// -> e, pq, es, s, ss
init := mkPQInitiationMessage(protocolVersion)
machineEphemeral := key.NewMachine()
machineEphemeralPub := machineEphemeral.Public()
copy(init.EphemeralPub(), machineEphemeralPub.UntypedBytes())
s.MixHash(machineEphemeralPub.UntypedBytes())
mlkemDecap, err := mlkem.GenerateKey768()
if err != nil {
return nil, nil, fmt.Errorf("generating ML-KEM key: %w", err)
}
mlkemEncap := mlkemDecap.EncapsulationKey().Bytes()
copy(init.MLKEMEncapsulationKey(), mlkemEncap)
s.MixHash(init.MLKEMEncapsulationKey())
cipher, err := s.MixDH(machineEphemeral, controlKey)
if err != nil {
return nil, nil, fmt.Errorf("computing es: %w", err)
}
machineKeyPub := machineKey.Public()
s.EncryptAndHash(cipher, init.MachinePub(), machineKeyPub.UntypedBytes())
cipher, err = s.MixDH(machineKey, controlKey)
if err != nil {
return nil, nil, fmt.Errorf("computing ss: %w", err)
}
s.EncryptAndHash(cipher, init.Tag(), nil) // empty message payload
cont := func(ctx context.Context, conn net.Conn) (*Conn, error) {
return continueClientHandshakePQ(ctx, conn, &s, machineKey, machineEphemeral, mlkemDecap, controlKey, protocolVersion)
}
return init[:], cont, nil
}
// Client wraps ClientDeferred and immediately invokes the returned
// continuation with conn.
//
@@ -189,6 +246,86 @@ func continueClientHandshake(ctx context.Context, conn net.Conn, s *symmetricSta
return c, nil
}
func continueClientHandshakePQ(ctx context.Context, conn net.Conn, s *symmetricState, machineKey, machineEphemeral key.MachinePrivate, mlkemDecap *mlkem.DecapsulationKey768, controlKey key.MachinePublic, protocolVersion uint16) (*Conn, error) {
// No matter what, this function can only run once per s. Ensure
// attempted reuse causes a panic.
defer func() {
s.finished = true
}()
if deadline, ok := ctx.Deadline(); ok {
if err := conn.SetDeadline(deadline); err != nil {
return nil, fmt.Errorf("setting conn deadline: %w", err)
}
defer func() {
conn.SetDeadline(time.Time{})
}()
}
// Read in the payload and look for errors/protocol violations from the server.
var resp pqResponseMessage
if _, err := io.ReadFull(conn, resp.Header()); err != nil {
return nil, fmt.Errorf("reading response header: %w", err)
}
if resp.Type() != msgTypeResponse {
if resp.Type() != msgTypeError {
return nil, fmt.Errorf("unexpected response message type %d", resp.Type())
}
msg := make([]byte, resp.Length())
if _, err := io.ReadFull(conn, msg); err != nil {
return nil, err
}
return nil, fmt.Errorf("server error: %q", msg)
}
if resp.Length() != len(resp.Payload()) {
return nil, fmt.Errorf("wrong length %d received for handshake response", resp.Length())
}
if _, err := io.ReadFull(conn, resp.Payload()); err != nil {
return nil, err
}
// <- e, pq, ee, se
controlEphemeralPub := key.MachinePublicFromRaw32(mem.B(resp.EphemeralPub()))
s.MixHash(controlEphemeralPub.UntypedBytes())
s.MixHash(resp.MLKEMCiphertext())
if _, err := s.MixDH(machineEphemeral, controlEphemeralPub); err != nil {
return nil, fmt.Errorf("computing ee: %w", err)
}
cipher, err := s.MixDH(machineKey, controlEphemeralPub)
if err != nil {
return nil, fmt.Errorf("computing se: %w", err)
}
sharedKey, err := mlkemDecap.Decapsulate(resp.MLKEMCiphertext())
if err != nil {
return nil, fmt.Errorf("decapsulating ML-KEM shared key: %w", err)
}
if err := s.MixSecret(sharedKey); err != nil {
return nil, fmt.Errorf("mixing ML-KEM shared key: %w", err)
}
if err := s.DecryptAndHash(cipher, nil, resp.Tag()); err != nil {
return nil, fmt.Errorf("decrypting payload: %w", err)
}
c1, c2, err := s.Split()
if err != nil {
return nil, fmt.Errorf("finalizing handshake: %w", err)
}
c := &Conn{
conn: conn,
version: protocolVersion,
peer: controlKey,
handshakeHash: s.h,
tx: txState{
cipher: c1,
},
rx: rxState{
cipher: c2,
},
}
return c, nil
}
// Server initiates a control server handshake, returning the resulting
// control connection.
//
@@ -226,16 +363,13 @@ func Server(ctx context.Context, conn net.Conn, controlKey key.MachinePrivate, o
return fmt.Errorf("refused client handshake: %q", msg)
}
var s symmetricState
s.Initialize()
var init initiationMessage
var initHeader [initiationHeaderLen]byte
if optionalInit != nil {
if len(optionalInit) != len(init) {
return nil, sendErr("wrong handshake initiation size")
if len(optionalInit) < len(initHeader) {
return nil, sendErr("short handshake initiation")
}
copy(init[:], optionalInit)
} else if _, err := io.ReadFull(conn, init.Header()); err != nil {
copy(initHeader[:], optionalInit)
} else if _, err := io.ReadFull(conn, initHeader[:]); err != nil {
return nil, err
}
// Just a rename to make it more obvious what the value is. In the
@@ -243,20 +377,41 @@ func Server(ctx context.Context, conn net.Conn, controlKey key.MachinePrivate, o
// versions at this layer, it's safe to let the handshake proceed
// and then let the caller make decisions based on the agreed-upon
// protocol version.
clientVersion := init.Version()
if init.Type() != msgTypeInitiation {
clientVersion := binary.BigEndian.Uint16(initHeader[:2])
msgType := initHeader[2]
msgLen := int(binary.BigEndian.Uint16(initHeader[3:5]))
if msgType != msgTypeInitiation {
return nil, sendErr("unexpected handshake message type")
}
if init.Length() != len(init.Payload()) {
wantPayloadLen := initiationPayloadLen
if usesPQHandshake(clientVersion) {
wantPayloadLen = pqInitiationPayloadLen
}
if msgLen != wantPayloadLen {
return nil, sendErr("wrong handshake initiation length")
}
// if optionalInit was provided, we have the payload already.
if optionalInit == nil {
if _, err := io.ReadFull(conn, init.Payload()); err != nil {
init := make([]byte, len(initHeader)+wantPayloadLen)
copy(init, initHeader[:])
if optionalInit != nil {
if len(optionalInit) != len(init) {
return nil, sendErr("wrong handshake initiation size")
}
copy(init, optionalInit)
} else {
if _, err := io.ReadFull(conn, init[len(initHeader):]); err != nil {
return nil, err
}
}
if usesPQHandshake(clientVersion) {
return serverPQ(conn, controlKey, init, clientVersion)
}
var s symmetricState
s.Initialize()
var legacyInit initiationMessage
copy(legacyInit[:], init)
// prologue. Can only do this once we at least think the client is
// handshaking using a supported version.
s.MixHash(protocolVersionPrologue(clientVersion))
@@ -267,8 +422,83 @@ func Server(ctx context.Context, conn net.Conn, controlKey key.MachinePrivate, o
s.MixHash(controlKeyPub.UntypedBytes())
// -> e, es, s, ss
machineEphemeralPub := key.MachinePublicFromRaw32(mem.B(legacyInit.EphemeralPub()))
s.MixHash(machineEphemeralPub.UntypedBytes())
cipher, err := s.MixDH(controlKey, machineEphemeralPub)
if err != nil {
return nil, fmt.Errorf("computing es: %w", err)
}
var machineKeyBytes [32]byte
if err := s.DecryptAndHash(cipher, machineKeyBytes[:], legacyInit.MachinePub()); err != nil {
return nil, fmt.Errorf("decrypting machine key: %w", err)
}
machineKey := key.MachinePublicFromRaw32(mem.B(machineKeyBytes[:]))
cipher, err = s.MixDH(controlKey, machineKey)
if err != nil {
return nil, fmt.Errorf("computing ss: %w", err)
}
if err := s.DecryptAndHash(cipher, nil, legacyInit.Tag()); err != nil {
return nil, fmt.Errorf("decrypting initiation tag: %w", err)
}
// <- e, ee, se
resp := mkResponseMessage()
controlEphemeral := key.NewMachine()
controlEphemeralPub := controlEphemeral.Public()
copy(resp.EphemeralPub(), controlEphemeralPub.UntypedBytes())
s.MixHash(controlEphemeralPub.UntypedBytes())
if _, err := s.MixDH(controlEphemeral, machineEphemeralPub); err != nil {
return nil, fmt.Errorf("computing ee: %w", err)
}
cipher, err = s.MixDH(controlEphemeral, machineKey)
if err != nil {
return nil, fmt.Errorf("computing se: %w", err)
}
s.EncryptAndHash(cipher, resp.Tag(), nil) // empty message payload
c1, c2, err := s.Split()
if err != nil {
return nil, fmt.Errorf("finalizing handshake: %w", err)
}
if _, err := conn.Write(resp[:]); err != nil {
return nil, err
}
c := &Conn{
conn: conn,
version: clientVersion,
peer: machineKey,
handshakeHash: s.h,
tx: txState{
cipher: c2,
},
rx: rxState{
cipher: c1,
},
}
return c, nil
}
func serverPQ(conn net.Conn, controlKey key.MachinePrivate, initBytes []byte, clientVersion uint16) (*Conn, error) {
var s symmetricState
s.Initialize()
var init pqInitiationMessage
copy(init[:], initBytes)
// prologue. Can only do this once we at least think the client is
// handshaking using a supported version.
s.MixHash(protocolVersionPrologue(clientVersion))
// <- s
// ...
controlKeyPub := controlKey.Public()
s.MixHash(controlKeyPub.UntypedBytes())
// -> e, pq, es, s, ss
machineEphemeralPub := key.MachinePublicFromRaw32(mem.B(init.EphemeralPub()))
s.MixHash(machineEphemeralPub.UntypedBytes())
s.MixHash(init.MLKEMEncapsulationKey())
cipher, err := s.MixDH(controlKey, machineEphemeralPub)
if err != nil {
return nil, fmt.Errorf("computing es: %w", err)
@@ -286,12 +516,20 @@ func Server(ctx context.Context, conn net.Conn, controlKey key.MachinePrivate, o
return nil, fmt.Errorf("decrypting initiation tag: %w", err)
}
// <- e, ee, se
resp := mkResponseMessage()
mlkemEncap, err := mlkem.NewEncapsulationKey768(init.MLKEMEncapsulationKey())
if err != nil {
return nil, fmt.Errorf("parsing ML-KEM encapsulation key: %w", err)
}
// <- e, pq, ee, se
resp := mkPQResponseMessage()
controlEphemeral := key.NewMachine()
controlEphemeralPub := controlEphemeral.Public()
copy(resp.EphemeralPub(), controlEphemeralPub.UntypedBytes())
s.MixHash(controlEphemeralPub.UntypedBytes())
sharedKey, mlkemCiphertext := mlkemEncap.Encapsulate()
copy(resp.MLKEMCiphertext(), mlkemCiphertext)
s.MixHash(resp.MLKEMCiphertext())
if _, err := s.MixDH(controlEphemeral, machineEphemeralPub); err != nil {
return nil, fmt.Errorf("computing ee: %w", err)
}
@@ -299,6 +537,9 @@ func Server(ctx context.Context, conn net.Conn, controlKey key.MachinePrivate, o
if err != nil {
return nil, fmt.Errorf("computing se: %w", err)
}
if err := s.MixSecret(sharedKey); err != nil {
return nil, fmt.Errorf("mixing ML-KEM shared key: %w", err)
}
s.EncryptAndHash(cipher, resp.Tag(), nil) // empty message payload
c1, c2, err := s.Split()
@@ -373,6 +614,10 @@ func (s *symmetricState) MixDH(priv key.MachinePrivate, pub key.MachinePublic) (
return nil, fmt.Errorf("computing X25519: %w", err)
}
return s.mixKey(keyData)
}
func (s *symmetricState) mixKey(keyData []byte) (*singleUseCHP, error) {
r := hkdf.New(newBLAKE2s, keyData, s.ck[:], nil)
if _, err := io.ReadFull(r, s.ck[:]); err != nil {
return nil, fmt.Errorf("extracting ck: %w", err)
@@ -384,6 +629,17 @@ func (s *symmetricState) MixDH(priv key.MachinePrivate, pub key.MachinePublic) (
return newSingleUseCHP(k), nil
}
// MixSecret updates s.ck with additional shared secret material. It is used for
// hybridizing the Noise handshake with an ML-KEM shared key.
func (s *symmetricState) MixSecret(keyData []byte) error {
s.checkFinished()
r := hkdf.New(newBLAKE2s, keyData, s.ck[:], nil)
if _, err := io.ReadFull(r, s.ck[:]); err != nil {
return fmt.Errorf("extracting ck: %w", err)
}
return nil
}
// EncryptAndHash encrypts plaintext into ciphertext (which must be
// the correct size to hold the encrypted plaintext) using cipher,
// mixes the ciphertext into s.h, and returns the ciphertext.
+152
View File
@@ -55,6 +55,158 @@ func TestHandshake(t *testing.T) {
}
}
func TestHandshakePQ(t *testing.T) {
var (
clientConn, serverConn = memnet.NewConn("noise", 128000)
serverKey = key.NewMachine()
clientKey = key.NewMachine()
server *Conn
serverErr = make(chan error, 1)
)
go func() {
var err error
server, err = Server(context.Background(), serverConn, serverKey, nil)
serverErr <- err
}()
client, err := Client(context.Background(), clientConn, clientKey, serverKey.Public(), pqMinProtocolVersion)
if err != nil {
t.Fatalf("client connection failed: %v", err)
}
if err := <-serverErr; err != nil {
t.Fatalf("server connection failed: %v", err)
}
if client.HandshakeHash() != server.HandshakeHash() {
t.Fatal("client and server disagree on handshake hash")
}
if client.ProtocolVersion() != int(pqMinProtocolVersion) {
t.Fatalf("client reporting wrong protocol version %d, want %d", client.ProtocolVersion(), pqMinProtocolVersion)
}
if client.ProtocolVersion() != server.ProtocolVersion() {
t.Fatalf("peers disagree on protocol version, client=%d server=%d", client.ProtocolVersion(), server.ProtocolVersion())
}
if client.Peer() != serverKey.Public() {
t.Fatal("client peer key isn't serverKey")
}
if server.Peer() != clientKey.Public() {
t.Fatal("server peer key isn't clientKey")
}
cb := sinkReads(client)
sb := sinkReads(server)
if _, err := io.WriteString(client, strings.Repeat("a", 14)); err != nil {
t.Fatalf("client>server write failed: %v", err)
}
if _, err := io.WriteString(server, strings.Repeat("b", 14)); err != nil {
t.Fatalf("server>client write failed: %v", err)
}
cb.String(14)
sb.String(14)
}
func TestHandshakeWireFormatByVersion(t *testing.T) {
serverKey := key.NewMachine()
clientKey := key.NewMachine()
init, _, err := ClientDeferred(clientKey, serverKey.Public(), testProtocolVersion)
if err != nil {
t.Fatal(err)
}
if got, want := len(init), len(initiationMessage{}); got != want {
t.Fatalf("legacy initiation length = %d, want %d", got, want)
}
init, _, err = ClientDeferred(clientKey, serverKey.Public(), pqMinProtocolVersion)
if err != nil {
t.Fatal(err)
}
if got, want := len(init), len(pqInitiationMessage{}); got != want {
t.Fatalf("PQ initiation length = %d, want %d", got, want)
}
}
func TestHandshakeVersionRequiresMatchingFormat(t *testing.T) {
for _, tt := range []struct {
name string
init []byte
}{
{
name: "pq-version-with-legacy-initiation",
init: func() []byte {
init := mkInitiationMessage(pqMinProtocolVersion)
return init[:]
}(),
},
{
name: "legacy-version-with-pq-initiation",
init: func() []byte {
init := mkPQInitiationMessage(testProtocolVersion)
return init[:]
}(),
},
} {
t.Run(tt.name, func(t *testing.T) {
_, serverConn := memnet.NewConn("noise", 128000)
serverKey := key.NewMachine()
_, err := Server(context.Background(), serverConn, serverKey, tt.init)
if err == nil {
t.Fatal("server accepted mismatched handshake format")
}
if !strings.Contains(err.Error(), "wrong handshake initiation length") {
t.Fatalf("server error = %v, want wrong handshake initiation length", err)
}
})
}
}
func TestPQHandshakeTampering(t *testing.T) {
t.Run("client ML-KEM encapsulation key", func(t *testing.T) {
var (
clientConn, serverRaw = memnet.NewConn("noise", 128000)
serverConn = &readerConn{serverRaw, &tamperReader{serverRaw, initiationHeaderLen + 32, 0}}
serverKey = key.NewMachine()
clientKey = key.NewMachine()
serverErr = make(chan error, 1)
)
go func() {
_, err := Server(context.Background(), serverConn, serverKey, nil)
if err != nil {
serverConn.Close()
}
serverErr <- err
}()
if _, err := Client(context.Background(), clientConn, clientKey, serverKey.Public(), pqMinProtocolVersion); err == nil {
t.Fatal("client connection succeeded despite tampering")
}
if err := <-serverErr; err == nil {
t.Fatal("server connection succeeded despite tampering")
}
})
t.Run("server ML-KEM ciphertext", func(t *testing.T) {
var (
clientRaw, serverConn = memnet.NewConn("noise", 128000)
clientConn = &readerConn{clientRaw, &tamperReader{clientRaw, headerLen + 32, 0}}
serverKey = key.NewMachine()
clientKey = key.NewMachine()
serverErr = make(chan error, 1)
)
go func() {
_, err := Server(context.Background(), serverConn, serverKey, nil)
serverErr <- err
}()
if _, err := Client(context.Background(), clientConn, clientKey, serverKey.Public(), pqMinProtocolVersion); err == nil {
t.Fatal("client connection succeeded despite tampering")
}
if err := <-serverErr; err != nil {
t.Fatalf("server connection failed despite response-only tampering: %v", err)
}
})
}
// Check that handshaking repeatedly with the same long-term keys
// result in different handshake hashes and wire traffic.
func TestNoReuse(t *testing.T) {
+80 -3
View File
@@ -3,7 +3,10 @@
package controlbase
import "encoding/binary"
import (
"crypto/mlkem"
"encoding/binary"
)
const (
// msgTypeInitiation frames carry a Noise IK handshake initiation message.
@@ -24,6 +27,11 @@ const (
headerLen = 3
// initiationHeaderLen is the size of the header on all msgTypeInitiation messages.
initiationHeaderLen = 5
initiationPayloadLen = 32 + 48 + 16
responsePayloadLen = 32 + 16
pqInitiationPayloadLen = 32 + mlkem.EncapsulationKeySize768 + 48 + 16
pqResponsePayloadLen = 32 + mlkem.CiphertextSize768 + 16
)
// initiationMessage is the protocol message sent from a client
@@ -36,7 +44,7 @@ const (
// 32b: client ephemeral public key (cleartext)
// 48b: client machine public key (encrypted)
// 16b: message tag (authenticates the whole message)
type initiationMessage [101]byte
type initiationMessage [initiationHeaderLen + initiationPayloadLen]byte
func mkInitiationMessage(protocolVersion uint16) initiationMessage {
var ret initiationMessage
@@ -61,6 +69,46 @@ func (m *initiationMessage) MachinePub() []byte {
}
func (m *initiationMessage) Tag() []byte { return m[initiationHeaderLen+32+48:] }
// pqInitiationMessage is the ML-KEM-augmented protocol message sent from a
// client machine to a control server.
//
// 2b: protocol version
// 1b: message type (0x01)
// 2b: payload length (1280)
// 32b: client ephemeral public key (cleartext)
// 1184b: client ML-KEM-768 encapsulation key (cleartext)
// 48b: client machine public key (encrypted)
// 16b: message tag (authenticates the whole message)
type pqInitiationMessage [initiationHeaderLen + pqInitiationPayloadLen]byte
func mkPQInitiationMessage(protocolVersion uint16) pqInitiationMessage {
var ret pqInitiationMessage
binary.BigEndian.PutUint16(ret[:2], protocolVersion)
ret[2] = msgTypeInitiation
binary.BigEndian.PutUint16(ret[3:5], uint16(len(ret.Payload())))
return ret
}
func (m *pqInitiationMessage) Header() []byte { return m[:initiationHeaderLen] }
func (m *pqInitiationMessage) Payload() []byte { return m[initiationHeaderLen:] }
func (m *pqInitiationMessage) Version() uint16 { return binary.BigEndian.Uint16(m[:2]) }
func (m *pqInitiationMessage) Type() byte { return m[2] }
func (m *pqInitiationMessage) Length() int { return int(binary.BigEndian.Uint16(m[3:5])) }
func (m *pqInitiationMessage) EphemeralPub() []byte {
return m[initiationHeaderLen : initiationHeaderLen+32]
}
func (m *pqInitiationMessage) MLKEMEncapsulationKey() []byte {
return m[initiationHeaderLen+32 : initiationHeaderLen+32+mlkem.EncapsulationKeySize768]
}
func (m *pqInitiationMessage) MachinePub() []byte {
return m[initiationHeaderLen+32+mlkem.EncapsulationKeySize768 : initiationHeaderLen+32+mlkem.EncapsulationKeySize768+48]
}
func (m *pqInitiationMessage) Tag() []byte {
return m[initiationHeaderLen+32+mlkem.EncapsulationKeySize768+48:]
}
// responseMessage is the protocol message sent from a control server
// to a client machine.
//
@@ -68,7 +116,7 @@ func (m *initiationMessage) Tag() []byte { return m[initiationHeaderLen+32+48:]
// 2b: payload length (48)
// 32b: control ephemeral public key (cleartext)
// 16b: message tag (authenticates the whole message)
type responseMessage [51]byte
type responseMessage [headerLen + responsePayloadLen]byte
func mkResponseMessage() responseMessage {
var ret responseMessage
@@ -85,3 +133,32 @@ func (m *responseMessage) Length() int { return int(binary.BigEndian.Uint16(m[1:
func (m *responseMessage) EphemeralPub() []byte { return m[headerLen : headerLen+32] }
func (m *responseMessage) Tag() []byte { return m[headerLen+32:] }
// pqResponseMessage is the ML-KEM-augmented protocol message sent from a
// control server to a client machine.
//
// 1b: message type (0x02)
// 2b: payload length (1136)
// 32b: control ephemeral public key (cleartext)
// 1088b: ML-KEM-768 ciphertext (cleartext)
// 16b: message tag (authenticates the whole message)
type pqResponseMessage [headerLen + pqResponsePayloadLen]byte
func mkPQResponseMessage() pqResponseMessage {
var ret pqResponseMessage
ret[0] = msgTypeResponse
binary.BigEndian.PutUint16(ret[1:], uint16(len(ret.Payload())))
return ret
}
func (m *pqResponseMessage) Header() []byte { return m[:headerLen] }
func (m *pqResponseMessage) Payload() []byte { return m[headerLen:] }
func (m *pqResponseMessage) Type() byte { return m[0] }
func (m *pqResponseMessage) Length() int { return int(binary.BigEndian.Uint16(m[1:3])) }
func (m *pqResponseMessage) EphemeralPub() []byte { return m[headerLen : headerLen+32] }
func (m *pqResponseMessage) MLKEMCiphertext() []byte {
return m[headerLen+32 : headerLen+32+mlkem.CiphertextSize768]
}
func (m *pqResponseMessage) Tag() []byte { return m[headerLen+32+mlkem.CiphertextSize768:] }
+2 -1
View File
@@ -188,7 +188,8 @@ type CapabilityVersion int
// - 139: 2026-05-22: Client understands [NodeAttrEmitRuntimeMetrics]
// - 140: 2026-05-27: Client understands [NodeAttrDisableUDPGRO], [NodeAttrDisableUDPGSO], [NodeAttrDisableTUNUDPGRO], [NodeAttrDisableTUNTCPGRO]
// - 141: 2026-05-28: Client understands [NodeAttrNeverGSOEqualTail]
const CurrentCapabilityVersion CapabilityVersion = 141
// - 142: 2026-06-10: ts2021 control transport uses a hybrid X25519 + ML-KEM-768 handshake.
const CurrentCapabilityVersion CapabilityVersion = 142
// ID is an integer ID for a user, node, or login allocated by the
// control plane.