Alexey Dolotov 1 день назад
Родитель
Сommit
327af9c463
Аккаунт пользователя с таким Email не найден

+ 2
- 2
.mise.toml Просмотреть файл

@@ -58,11 +58,11 @@ run = "go test -v {{ vars.fuzzflags }} -fuzz=FuzzReadClientHello ./mtglib/intern
58 58
 
59 59
 [tasks."test:fuzz:client-handshake"]
60 60
 description = "Run fuzzy test for ClientHandshake"
61
-run = "go test -v {{ vars.fuzzflags }} -fuzz=FuzzClientServerHandshake ./mtglib/internal/obfuscation"
61
+run = "go test -v {{ vars.fuzzflags }} -fuzz=FuzzClientServerHandshake ./mtglib/obfuscation"
62 62
 
63 63
 [tasks."test:fuzz:server-handshake-frame"]
64 64
 description = "Run fuzzy test for GenerateHandshakeFrame"
65
-run = "go test -v {{ vars.fuzzflags }} -fuzz=FuzzGenerateHandshakeFrame ./mtglib/internal/obfuscation"
65
+run = "go test -v {{ vars.fuzzflags }} -fuzz=FuzzGenerateHandshakeFrame ./mtglib/obfuscation"
66 66
 
67 67
 [tasks.static]
68 68
 description = "Build static binary"

+ 1
- 1
mtglib/internal/dc/addr.go Просмотреть файл

@@ -3,7 +3,7 @@ package dc
3 3
 import (
4 4
 	"fmt"
5 5
 
6
-	"github.com/9seconds/mtg/v2/mtglib/internal/obfuscation"
6
+	"github.com/9seconds/mtg/v2/mtglib/obfuscation"
7 7
 )
8 8
 
9 9
 type Addr struct {

mtglib/internal/obfuscation/conn.go → mtglib/obfuscation/conn.go Просмотреть файл


mtglib/internal/obfuscation/conn_test.go → mtglib/obfuscation/conn_test.go Просмотреть файл


mtglib/internal/obfuscation/handshake_frame.go → mtglib/obfuscation/handshake_frame.go Просмотреть файл


mtglib/internal/obfuscation/handshake_frame_fuzz_test.go → mtglib/obfuscation/handshake_frame_fuzz_test.go Просмотреть файл


mtglib/internal/obfuscation/handshake_frame_test.go → mtglib/obfuscation/handshake_frame_test.go Просмотреть файл


mtglib/internal/obfuscation/init_test.go → mtglib/obfuscation/init_test.go Просмотреть файл


mtglib/internal/obfuscation/obfuscator.go → mtglib/obfuscation/obfuscator.go Просмотреть файл

@@ -13,10 +13,17 @@ import (
13 13
 	"github.com/9seconds/mtg/v2/essentials"
14 14
 )
15 15
 
16
+// Obfuscator implements the obfuscated2 handshake
17
+// (https://core.telegram.org/mtproto/mtproto-transports#transport-obfuscation).
18
+// Set Secret to the MTProxy secret for key-mixed handshakes; leave nil for
19
+// direct DC connections.
16 20
 type Obfuscator struct {
17 21
 	Secret []byte
18 22
 }
19 23
 
24
+// ReadHandshake reads the 64-byte obfuscated2 client handshake from r,
25
+// validates it, and returns the DC the client requested along with a
26
+// transparent en/decrypting wrapper over r.
20 27
 func (o Obfuscator) ReadHandshake(r essentials.Conn) (int, essentials.Conn, error) {
21 28
 	frame := handshakeFrame{}
22 29
 
@@ -46,6 +53,8 @@ func (o Obfuscator) ReadHandshake(r essentials.Conn) (int, essentials.Conn, erro
46 53
 	return frame.dc(), cn, nil
47 54
 }
48 55
 
56
+// SendHandshake writes a fresh 64-byte obfuscated2 handshake for the given
57
+// DC to w and returns a transparent en/decrypting wrapper over w.
49 58
 func (o Obfuscator) SendHandshake(w essentials.Conn, dc int) (essentials.Conn, error) {
50 59
 	frame := generateHandshake(dc)
51 60
 	copyFrame := frame

mtglib/internal/obfuscation/obfuscator_fuzz_test.go → mtglib/obfuscation/obfuscator_fuzz_test.go Просмотреть файл

@@ -6,7 +6,7 @@ import (
6 6
 
7 7
 	"github.com/9seconds/mtg/v2/internal/testlib"
8 8
 	"github.com/9seconds/mtg/v2/mtglib"
9
-	"github.com/9seconds/mtg/v2/mtglib/internal/obfuscation"
9
+	"github.com/9seconds/mtg/v2/mtglib/obfuscation"
10 10
 	"github.com/stretchr/testify/assert"
11 11
 	"github.com/stretchr/testify/mock"
12 12
 )

mtglib/internal/obfuscation/obfuscator_test.go → mtglib/obfuscation/obfuscator_test.go Просмотреть файл

@@ -6,7 +6,7 @@ import (
6 6
 
7 7
 	"github.com/9seconds/mtg/v2/internal/testlib"
8 8
 	"github.com/9seconds/mtg/v2/mtglib"
9
-	"github.com/9seconds/mtg/v2/mtglib/internal/obfuscation"
9
+	"github.com/9seconds/mtg/v2/mtglib/obfuscation"
10 10
 	"github.com/stretchr/testify/assert"
11 11
 	"github.com/stretchr/testify/mock"
12 12
 	"github.com/stretchr/testify/require"

mtglib/internal/obfuscation/testdata/client-handshake-snapshot-4529d55776e2d427.json → mtglib/obfuscation/testdata/client-handshake-snapshot-4529d55776e2d427.json Просмотреть файл


mtglib/internal/obfuscation/testdata/client-handshake-snapshot-585c944d672f60a2.json → mtglib/obfuscation/testdata/client-handshake-snapshot-585c944d672f60a2.json Просмотреть файл


+ 1
- 1
mtglib/proxy.go Просмотреть файл

@@ -12,7 +12,7 @@ import (
12 12
 	"github.com/9seconds/mtg/v2/essentials"
13 13
 	"github.com/9seconds/mtg/v2/mtglib/internal/dc"
14 14
 	"github.com/9seconds/mtg/v2/mtglib/internal/doppel"
15
-	"github.com/9seconds/mtg/v2/mtglib/internal/obfuscation"
15
+	"github.com/9seconds/mtg/v2/mtglib/obfuscation"
16 16
 	"github.com/9seconds/mtg/v2/mtglib/internal/relay"
17 17
 	"github.com/9seconds/mtg/v2/mtglib/internal/tls"
18 18
 	"github.com/9seconds/mtg/v2/mtglib/internal/tls/fake"

Загрузка…
Отмена
Сохранить