feat(gateway): bind Apollo launch to encrypted session work
Verify Data Plane / gateway (push) Successful in 1m52s

This commit is contained in:
sechmachine
2026-07-29 11:44:17 +07:00
parent 1357ea0c8f
commit 67eeb9e898
3 changed files with 224 additions and 32 deletions
+20 -7
View File
@@ -18,10 +18,12 @@ var errEncryptedRTSPFrame = errors.New("invalid encrypted RTSP frame")
// only strictly increasing host sequence numbers, so a replay cannot be fed
// into the RTSP parser after it has already authenticated once.
type encryptedRTSPCodec struct {
aead cipher.AEAD
nextClient uint32
lastHost uint32
hostReceived bool
aead cipher.AEAD
nextClient uint32
lastClient uint32
clientReceived bool
lastHost uint32
hostReceived bool
}
func newEncryptedRTSPCodec(key []byte) (*encryptedRTSPCodec, error) {
@@ -54,6 +56,17 @@ func (codec *encryptedRTSPCodec) SealClient(plaintext []byte) ([]byte, error) {
}
func (codec *encryptedRTSPCodec) OpenHost(frame []byte) ([]byte, error) {
return codec.open(frame, 'H', 'R', &codec.lastHost, &codec.hostReceived)
}
// OpenClient validates the client-originated direction. The native gateway
// only sends this direction, but retaining the inverse lets a bounded fake
// provider verify the negotiated session key and frame shape.
func (codec *encryptedRTSPCodec) OpenClient(frame []byte) ([]byte, error) {
return codec.open(frame, 'C', 'R', &codec.lastClient, &codec.clientReceived)
}
func (codec *encryptedRTSPCodec) open(frame []byte, origin, protocol byte, last *uint32, received *bool) ([]byte, error) {
if codec == nil || codec.aead == nil || len(frame) < encryptedRTSPHeaderSize {
return nil, errEncryptedRTSPFrame
}
@@ -62,10 +75,10 @@ func (codec *encryptedRTSPCodec) OpenHost(frame []byte) ([]byte, error) {
return nil, errEncryptedRTSPFrame
}
sequence := binary.BigEndian.Uint32(frame[4:8])
if sequence == 0 || (codec.hostReceived && sequence <= codec.lastHost) {
if sequence == 0 || (*received && sequence <= *last) {
return nil, errEncryptedRTSPFrame
}
nonce := encryptedRTSPNonce(sequence, 'H', 'R')
nonce := encryptedRTSPNonce(sequence, origin, protocol)
sealed := make([]byte, int(length&0x7fffffff)+codec.aead.Overhead())
copy(sealed, frame[24:])
copy(sealed[length&0x7fffffff:], frame[8:24])
@@ -73,7 +86,7 @@ func (codec *encryptedRTSPCodec) OpenHost(frame []byte) ([]byte, error) {
if err != nil {
return nil, errEncryptedRTSPFrame
}
codec.lastHost, codec.hostReceived = sequence, true
*last, *received = sequence, true
return plaintext, nil
}