|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+package wrappers
|
|
|
2
|
+
|
|
|
3
|
+import (
|
|
|
4
|
+ "encoding/binary"
|
|
|
5
|
+ "net"
|
|
|
6
|
+ "testing"
|
|
|
7
|
+
|
|
|
8
|
+ "github.com/stretchr/testify/assert"
|
|
|
9
|
+
|
|
|
10
|
+ "github.com/9seconds/mtg/mtproto/rpc"
|
|
|
11
|
+)
|
|
|
12
|
+
|
|
|
13
|
+var proxySecret = []byte{196, 249, 250, 202, 150, 120, 230, 187, 72, 173,
|
|
|
14
|
+ 108, 126, 44, 229, 192, 210, 68, 48, 100, 93, 85, 74, 221, 235, 85, 65,
|
|
|
15
|
+ 158, 3, 77, 166, 39, 33, 208, 70, 234, 171, 110, 82, 171, 20, 169, 90, 68,
|
|
|
16
|
+ 62, 207, 179, 70, 62, 121, 160, 90, 102, 97, 42, 223, 156, 174, 218, 139,
|
|
|
17
|
+ 233, 168, 13, 166, 152, 111, 176, 166, 255, 56, 122, 248, 77, 136, 239,
|
|
|
18
|
+ 58, 100, 19, 113, 62, 92, 51, 119, 246, 225, 163, 212, 125, 153, 245, 224,
|
|
|
19
|
+ 197, 110, 236, 232, 240, 92, 84, 196, 144, 176, 121, 227, 27, 239, 130,
|
|
|
20
|
+ 255, 14, 232, 242, 176, 163, 39, 86, 210, 73, 197, 242, 18, 105, 129, 108,
|
|
|
21
|
+ 183, 6, 27, 38, 93, 178, 18}
|
|
|
22
|
+
|
|
|
23
|
+func TestMakeKeys(t *testing.T) {
|
|
|
24
|
+ req, err := rpc.NewRPCNonceRequest(proxySecret)
|
|
|
25
|
+ assert.Nil(t, err)
|
|
|
26
|
+
|
|
|
27
|
+ copy(req.Nonce[:], []byte{24, 49, 53, 111, 198, 10, 235, 180, 230, 112, 92, 78, 1, 201, 106, 105})
|
|
|
28
|
+ binary.LittleEndian.PutUint32(req.CryptoTS[:], 1528396015)
|
|
|
29
|
+
|
|
|
30
|
+ resp := &rpc.RPCNonceResponse{}
|
|
|
31
|
+ copy(resp.Nonce[:], []byte{247, 40, 210, 56, 65, 12, 101, 170, 216, 155, 14, 253, 250, 238, 219, 226})
|
|
|
32
|
+
|
|
|
33
|
+ cltAddr := &net.TCPAddr{
|
|
|
34
|
+ IP: net.ParseIP("80.211.29.34"),
|
|
|
35
|
+ Port: 54208,
|
|
|
36
|
+ }
|
|
|
37
|
+ srvAddr := &net.TCPAddr{
|
|
|
38
|
+ IP: net.ParseIP("149.154.162.38"),
|
|
|
39
|
+ Port: 80,
|
|
|
40
|
+ }
|
|
|
41
|
+
|
|
|
42
|
+ key, iv := makeKeys(CipherPurposeClient, req, resp, cltAddr, srvAddr, proxySecret)
|
|
|
43
|
+ assert.Equal(t, key, []byte{165, 158, 127, 49, 41, 232, 187, 69, 38, 29, 163, 226, 183, 146, 28, 67, 225, 224, 134, 191, 207, 152, 255, 166, 152, 66, 169, 196, 54, 135, 50, 188})
|
|
|
44
|
+ assert.Equal(t, iv, []byte{33, 110, 125, 221, 183, 121, 160, 116, 130, 180, 156, 249, 52, 111, 37, 178})
|
|
|
45
|
+}
|