|
|
@@ -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
|