Skip to content

Commit

Permalink
fix(faketls): fix encoding SNI in faketls ClientHello
Browse files Browse the repository at this point in the history
The offset calculation used in the stack code in the ClientHello
creation function was incorrect, resulting in the SNI field not
being correctly encoded and therefore not being able to connect
to faketls mtproto proxies.

Added parenthesis to fix the math.

Signed-off-by: Mark Pashmfouroush <[email protected]>
  • Loading branch information
markpash committed Jul 3, 2024
1 parent 7183696 commit 736dd57
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mtproxy/faketls/client_hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func createClientHello(b *bin.Buffer, sessionID [32]byte, domain string, key [32
s := stack[lastIdx]
stack = stack[:lastIdx]

length := b.Len() - s + 2
length := b.Len() - (s + 2)
binary.BigEndian.PutUint16(b.Buf[s:], uint16(length))
}

Expand Down
10 changes: 5 additions & 5 deletions mtproxy/faketls/faketls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ func TestTLS(t *testing.T) {
_, err := writeClientHello(b, c, sessionID, "google.com", secret[:])
a.NoError(err)

testVector := []uint8{
0x16, 0x03, 0x01, 0x02, 0x00, 0x01, 0x00, 0x01, 0xfc, 0x03, 0x03, 0xd5, 0x20, 0xce, 0xde, 0x64,
0x71, 0x9b, 0xa7, 0x3f, 0x51, 0x9d, 0x51, 0x35, 0xd5, 0x64, 0x31, 0x68, 0x2a, 0xe8, 0x07, 0x98,
0xf3, 0xca, 0xb3, 0x32, 0xc4, 0xb2, 0xbc, 0x2e, 0xb5, 0x04, 0x4d, 0x20, 0x00, 0x00, 0x00, 0x00,
testVector := []byte{
0x16, 0x03, 0x01, 0x02, 0x00, 0x01, 0x00, 0x01, 0xfc, 0x03, 0x03, 0xf9, 0x75, 0x5f, 0xdd, 0xb9,
0xe3, 0x46, 0x57, 0x5a, 0x26, 0x71, 0xfa, 0x29, 0x7f, 0xab, 0xf0, 0xa1, 0xf3, 0x69, 0x4f, 0x72,
0xe0, 0xc3, 0x8f, 0x62, 0x77, 0x5c, 0x8f, 0x5a, 0xf8, 0xa2, 0xa9, 0x20, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x13, 0x01,
0x13, 0x02, 0x13, 0x03, 0xc0, 0x2b, 0xc0, 0x2f, 0xc0, 0x2c, 0xc0, 0x30, 0xcc, 0xa9, 0xcc, 0xa8,
0xc0, 0x13, 0xc0, 0x14, 0x00, 0x9c, 0x00, 0x9d, 0x00, 0x2f, 0x00, 0x35, 0x01, 0x00, 0x01, 0x93,
0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x11, 0x00, 0x00, 0x0e, 0x67, 0x6f, 0x6f, 0x67, 0x6c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0d, 0x00, 0x00, 0x0a, 0x67, 0x6f, 0x6f, 0x67, 0x6c,
0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x17, 0x00, 0x00, 0xff, 0x01, 0x00, 0x01, 0x00, 0x00, 0x0a,
0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x18, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00,
0x00, 0x23, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0e, 0x00, 0x0c, 0x02, 0x68, 0x32, 0x08, 0x68, 0x74,
Expand Down

0 comments on commit 736dd57

Please sign in to comment.