mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 21:44:03 +03:00
More correct calculation of dc for obfuscated2 frame
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
package obfuscated2
|
package obfuscated2
|
||||||
|
|
||||||
import "encoding/binary"
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DefaultDC = 2
|
DefaultDC = 2
|
||||||
|
|
||||||
@@ -10,14 +8,12 @@ const (
|
|||||||
handshakeFrameLenKey = 32
|
handshakeFrameLenKey = 32
|
||||||
handshakeFrameLenIV = 16
|
handshakeFrameLenIV = 16
|
||||||
handshakeFrameLenConnectionType = 4
|
handshakeFrameLenConnectionType = 4
|
||||||
handshakeFrameLenDC = 2
|
|
||||||
|
|
||||||
handshakeFrameOffsetStart = 8
|
handshakeFrameOffsetStart = 8
|
||||||
handshakeFrameOffsetKey = handshakeFrameOffsetStart
|
handshakeFrameOffsetKey = handshakeFrameOffsetStart
|
||||||
handshakeFrameOffsetIV = handshakeFrameOffsetKey + handshakeFrameLenKey
|
handshakeFrameOffsetIV = handshakeFrameOffsetKey + handshakeFrameLenKey
|
||||||
handshakeFrameOffsetConnectionType = handshakeFrameOffsetIV + handshakeFrameLenIV
|
handshakeFrameOffsetConnectionType = handshakeFrameOffsetIV + handshakeFrameLenIV
|
||||||
handshakeFrameOffsetDC = handshakeFrameOffsetConnectionType + handshakeFrameLenConnectionType
|
handshakeFrameOffsetDC = handshakeFrameOffsetConnectionType + handshakeFrameLenConnectionType
|
||||||
handshakeFrameOffsetEnd = handshakeFrameOffsetDC + handshakeFrameLenDC
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Connection-Type: Secure. We support only fake tls.
|
// Connection-Type: Secure. We support only fake tls.
|
||||||
@@ -38,8 +34,7 @@ type handshakeFrame struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *handshakeFrame) dc() int {
|
func (h *handshakeFrame) dc() int {
|
||||||
data := h.data[handshakeFrameOffsetDC:handshakeFrameOffsetEnd]
|
idx := int16(h.data[handshakeFrameOffsetDC]) | int16(h.data[handshakeFrameOffsetDC+1])<<8 // nolint: gomnd, lll // little endian for int16 is here
|
||||||
idx := int16(binary.LittleEndian.Uint16(data))
|
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case idx > 0:
|
case idx > 0:
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package obfuscated2
|
package obfuscated2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -40,6 +43,30 @@ func (suite *HandshakeFrameTestSuite) TestOk() {
|
|||||||
suite.EqualValues(2094, inverted.dc())
|
suite.EqualValues(2094, inverted.dc())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *HandshakeFrameTestSuite) TestDC() {
|
||||||
|
testData := map[int16]int{
|
||||||
|
1: 1,
|
||||||
|
-1: 1,
|
||||||
|
0: DefaultDC,
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range testData {
|
||||||
|
incoming := k
|
||||||
|
expected := v
|
||||||
|
|
||||||
|
suite.T().Run(strconv.Itoa(int(incoming)), func(t *testing.T) {
|
||||||
|
frame := handshakeFrame{}
|
||||||
|
|
||||||
|
rand.Read(frame.data[:]) // nolint: errcheck
|
||||||
|
|
||||||
|
frame.data[handshakeFrameOffsetDC] = byte(incoming)
|
||||||
|
frame.data[handshakeFrameOffsetDC+1] = byte(incoming >> 8)
|
||||||
|
|
||||||
|
assert.Equal(t, expected, frame.dc())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestHandshakeFrame(t *testing.T) {
|
func TestHandshakeFrame(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
suite.Run(t, &HandshakeFrameTestSuite{})
|
suite.Run(t, &HandshakeFrameTestSuite{})
|
||||||
|
|||||||
Reference in New Issue
Block a user