Fixes for obfuscated2

This commit is contained in:
9seconds
2021-03-18 17:15:55 +03:00
parent 0ad2d61742
commit 0330a0e5cd
14 changed files with 335 additions and 19 deletions
@@ -9,7 +9,7 @@ import (
)
// Connection Type secure. We support only fake tls.
var clientHandshakeMagic = []byte{0xdd, 0xdd, 0xdd, 0xdd}
var clientHandshakeConnectionType = []byte{0xdd, 0xdd, 0xdd, 0xdd}
func ClientHandshake(secret []byte, reader io.Reader) (int16, cipher.Stream, cipher.Stream, error) {
handshakeFrame := acquireHandshakeFrame()
@@ -42,8 +42,8 @@ func ClientHandshake(secret []byte, reader io.Reader) (int16, cipher.Stream, cip
decryptor.XORKeyStream(handshakeFrame.data[:], handshakeFrame.data[:])
if magic := handshakeFrame.magic(); subtle.ConstantTimeCompare(clientHandshakeMagic, magic) != 1 {
return 0, nil, nil, fmt.Errorf("unsupported connection type: %s", hex.EncodeToString(magic))
if val := handshakeFrame.connectionType(); subtle.ConstantTimeCompare(clientHandshakeConnectionType, val) != 1 {
return 0, nil, nil, fmt.Errorf("unsupported connection type: %s", hex.EncodeToString(val))
}
return handshakeFrame.dc(), encryptor, decryptor, nil
+15 -15
View File
@@ -5,17 +5,17 @@ import "encoding/binary"
const (
handshakeFrameLen = 64
handshakeFrameLenKey = 32
handshakeFrameLenIV = 16
handshakeFrameLenMagic = 4
handshakeFrameLenDC = 2
handshakeFrameLenKey = 32
handshakeFrameLenIV = 16
handshakeFrameLenConnectionType = 4
handshakeFrameLenDC = 2
handshakeFrameOffsetStart = 8
handshakeFrameOffsetKey = handshakeFrameOffsetStart
handshakeFrameOffsetIV = handshakeFrameOffsetKey + handshakeFrameLenKey
handshakeFrameOffsetMagic = handshakeFrameOffsetIV + handshakeFrameLenIV
handshakeFrameOffsetDC = handshakeFrameOffsetMagic + handshakeFrameLenMagic
handshakeFrameOffsetEnd = handshakeFrameOffsetDC + handshakeFrameLenDC
handshakeFrameOffsetStart = 8
handshakeFrameOffsetKey = handshakeFrameOffsetStart
handshakeFrameOffsetIV = handshakeFrameOffsetKey + handshakeFrameLenKey
handshakeFrameOffsetConnectionType = handshakeFrameOffsetIV + handshakeFrameLenIV
handshakeFrameOffsetDC = handshakeFrameOffsetConnectionType + handshakeFrameLenConnectionType
handshakeFrameOffsetEnd = handshakeFrameOffsetDC + handshakeFrameLenDC
)
// A structure of obfuscated2 handshake frame is following:
@@ -25,7 +25,7 @@ const (
// - 8 bytes of noise
// - 32 bytes of AES Key
// - 16 bytes of AES IV
// - 4 bytes of 'magic' - this has some settings like a connection type
// - 4 bytes of 'connection type' - this has some setting like a connection type
// - 2 bytes of 'DC'. DC is little endian int16
// - 2 bytes of noise
type handshakeFrame struct {
@@ -39,13 +39,13 @@ func (h *handshakeFrame) dc() int16 {
}
func (h *handshakeFrame) key() []byte {
return h.data[handshakeFrameLenKey:handshakeFrameOffsetIV]
return h.data[handshakeFrameOffsetKey:handshakeFrameOffsetIV]
}
func (h *handshakeFrame) iv() []byte {
return h.data[handshakeFrameOffsetIV:handshakeFrameOffsetMagic]
return h.data[handshakeFrameOffsetIV:handshakeFrameOffsetConnectionType]
}
func (h *handshakeFrame) magic() []byte {
return h.data[handshakeFrameOffsetMagic:handshakeFrameOffsetDC]
func (h *handshakeFrame) connectionType() []byte {
return h.data[handshakeFrameOffsetConnectionType:handshakeFrameOffsetDC]
}