9seconds 8 лет назад
Родитель
Сommit
dd7a095947
5 измененных файлов: 32 добавлений и 16 удалений
  1. 1
    1
      Makefile
  2. 23
    10
      config/config.go
  3. 1
    1
      config/global_ips.go
  4. 1
    1
      config/urls.go
  5. 6
    3
      obfuscated2/obfuscated2_test.go

+ 1
- 1
Makefile Просмотреть файл

1
 ROOT_DIR     := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
1
 ROOT_DIR     := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
2
 IMAGE_NAME   := mtg
2
 IMAGE_NAME   := mtg
3
 APP_NAME     := $(IMAGE_NAME)
3
 APP_NAME     := $(IMAGE_NAME)
4
-GOMETALINTER := gometalinter.v2
4
+GOMETALINTER := gometalinter
5
 
5
 
6
 VENDOR_FILES := $(shell find "$(ROOT_DIR)/vendor" 2>/dev/null || echo -n "vendor")
6
 VENDOR_FILES := $(shell find "$(ROOT_DIR)/vendor" 2>/dev/null || echo -n "vendor")
7
 CC_BINARIES  := $(shell bash -c "echo -n $(APP_NAME)-{linux,windows,darwin,freebsd,openbsd}-{386,amd64} $(APP_NAME)-linux-{arm,arm64}")
7
 CC_BINARIES  := $(shell bash -c "echo -n $(APP_NAME)-{linux,windows,darwin,freebsd,openbsd}-{386,amd64} $(APP_NAME)-linux-{arm,arm64}")

+ 23
- 10
config/config.go Просмотреть файл

10
 	"github.com/juju/errors"
10
 	"github.com/juju/errors"
11
 )
11
 )
12
 
12
 
13
+// Config represents common configuration of mtg.
13
 type Config struct {
14
 type Config struct {
14
-	Debug    bool
15
-	Verbose  bool
16
-	BindIP   net.IP
17
-	BindPort uint16
15
+	Debug   bool
16
+	Verbose bool
18
 
17
 
19
-	PublicIPv4     net.IP
18
+	BindPort       uint16
20
 	PublicIPv4Port uint16
19
 	PublicIPv4Port uint16
21
-	PublicIPv6     net.IP
22
 	PublicIPv6Port uint16
20
 	PublicIPv6Port uint16
23
-
24
-	StatsIP   net.IP
25
-	StatsPort uint16
21
+	StatsPort      uint16
26
 
22
 
27
 	TimeoutRead  time.Duration
23
 	TimeoutRead  time.Duration
28
 	TimeoutWrite time.Duration
24
 	TimeoutWrite time.Duration
29
 
25
 
26
+	BindIP     net.IP
27
+	PublicIPv4 net.IP
28
+	PublicIPv6 net.IP
29
+	StatsIP    net.IP
30
+
30
 	Secret []byte
31
 	Secret []byte
31
 }
32
 }
32
 
33
 
34
+// URLs contains links to the proxy (tg://, t.me) and their QR codes.
33
 type URLs struct {
35
 type URLs struct {
34
 	TG        string `json:"tg_url"`
36
 	TG        string `json:"tg_url"`
35
 	TMe       string `json:"tme_url"`
37
 	TMe       string `json:"tme_url"`
37
 	TMeQRCode string `json:"tme_qrcode"`
39
 	TMeQRCode string `json:"tme_qrcode"`
38
 }
40
 }
39
 
41
 
42
+// IPURLs contains links to both ipv4 and ipv6 of the proxy.
40
 type IPURLs struct {
43
 type IPURLs struct {
41
 	IPv4 URLs `json:"ipv4"`
44
 	IPv4 URLs `json:"ipv4"`
42
 	IPv6 URLs `json:"ipv6"`
45
 	IPv6 URLs `json:"ipv6"`
43
 }
46
 }
44
 
47
 
48
+// BindAddr returns connection for this server to bind to.
45
 func (c *Config) BindAddr() string {
49
 func (c *Config) BindAddr() string {
46
 	return getAddr(c.BindIP, c.BindPort)
50
 	return getAddr(c.BindIP, c.BindPort)
47
 }
51
 }
48
 
52
 
53
+// IPv4Addr returns connection string to ipv6 for mtproto proxy.
49
 func (c *Config) IPv4Addr() string {
54
 func (c *Config) IPv4Addr() string {
50
 	return getAddr(c.PublicIPv4, c.PublicIPv4Port)
55
 	return getAddr(c.PublicIPv4, c.PublicIPv4Port)
51
 }
56
 }
52
 
57
 
58
+// IPv6Addr returns connection string to ipv6 for mtproto proxy.
53
 func (c *Config) IPv6Addr() string {
59
 func (c *Config) IPv6Addr() string {
54
 	return getAddr(c.PublicIPv6, c.PublicIPv6Port)
60
 	return getAddr(c.PublicIPv6, c.PublicIPv6Port)
55
 }
61
 }
56
 
62
 
63
+// StatAddr returns connection string to the stats API.
57
 func (c *Config) StatAddr() string {
64
 func (c *Config) StatAddr() string {
58
 	return getAddr(c.StatsIP, c.StatsPort)
65
 	return getAddr(c.StatsIP, c.StatsPort)
59
 }
66
 }
60
 
67
 
68
+// GetURLs returns configured IPURLs instance with links to this server.
61
 func (c *Config) GetURLs() IPURLs {
69
 func (c *Config) GetURLs() IPURLs {
62
 	return IPURLs{
70
 	return IPURLs{
63
 		IPv4: getURLs(c.PublicIPv4, c.PublicIPv4Port, c.Secret),
71
 		IPv4: getURLs(c.PublicIPv4, c.PublicIPv4Port, c.Secret),
69
 	return net.JoinHostPort(host.String(), strconv.Itoa(int(port)))
77
 	return net.JoinHostPort(host.String(), strconv.Itoa(int(port)))
70
 }
78
 }
71
 
79
 
72
-func NewConfig(debug, verbose bool,
80
+// NewConfig returns new configuration. If required, it manages and
81
+// fetches data from external sources. Parameters passed to this
82
+// function, should come from command line arguments.
83
+func NewConfig(debug, verbose bool, // nolint: gocyclo
73
 	bindIP net.IP, bindPort uint16,
84
 	bindIP net.IP, bindPort uint16,
74
 	publicIPv4 net.IP, PublicIPv4Port uint16,
85
 	publicIPv4 net.IP, PublicIPv4Port uint16,
75
 	publicIPv6 net.IP, publicIPv6Port uint16,
86
 	publicIPv6 net.IP, publicIPv6Port uint16,
120
 		PublicIPv4Port: PublicIPv4Port,
131
 		PublicIPv4Port: PublicIPv4Port,
121
 		PublicIPv6:     publicIPv6,
132
 		PublicIPv6:     publicIPv6,
122
 		PublicIPv6Port: publicIPv6Port,
133
 		PublicIPv6Port: publicIPv6Port,
134
+		StatsIP:        statsIP,
135
+		StatsPort:      statsPort,
123
 		TimeoutRead:    timeoutRead,
136
 		TimeoutRead:    timeoutRead,
124
 		TimeoutWrite:   timeoutWrite,
137
 		TimeoutWrite:   timeoutWrite,
125
 		Secret:         secretBytes,
138
 		Secret:         secretBytes,

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

22
 	if err != nil {
22
 	if err != nil {
23
 		return nil, err
23
 		return nil, err
24
 	}
24
 	}
25
-	defer resp.Body.Close()
25
+	defer resp.Body.Close() // nolint: errcheck
26
 
26
 
27
 	respData, err := ioutil.ReadAll(resp.Body)
27
 	respData, err := ioutil.ReadAll(resp.Body)
28
 	if err != nil {
28
 	if err != nil {

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

14
 	values.Set("secret", hex.EncodeToString(secret))
14
 	values.Set("secret", hex.EncodeToString(secret))
15
 
15
 
16
 	urls.TG = makeTGURL(values)
16
 	urls.TG = makeTGURL(values)
17
-	urls.TMe = makeTGURL(values)
17
+	urls.TMe = makeTMeURL(values)
18
 	urls.TGQRCode = makeQRCodeURL(urls.TG)
18
 	urls.TGQRCode = makeQRCodeURL(urls.TG)
19
 	urls.TMeQRCode = makeQRCodeURL(urls.TG)
19
 	urls.TMeQRCode = makeQRCodeURL(urls.TG)
20
 
20
 

+ 6
- 3
obfuscated2/obfuscated2_test.go Просмотреть файл

25
 	data := []byte{1, 2, 3}
25
 	data := []byte{1, 2, 3}
26
 	encrypted := make([]byte, 3)
26
 	encrypted := make([]byte, 3)
27
 	encryptor.XORKeyStream(encrypted, data)
27
 	encryptor.XORKeyStream(encrypted, data)
28
-	decrypted := obfs2.Decrypt(encrypted)
28
+	decrypted := make([]byte, 3)
29
+	obfs2.Decryptor.XORKeyStream(decrypted, encrypted)
29
 
30
 
30
 	assert.Equal(t, data, decrypted)
31
 	assert.Equal(t, data, decrypted)
31
 }
32
 }
67
 	tgEncryptedMessage := make([]byte, len(message))
68
 	tgEncryptedMessage := make([]byte, len(message))
68
 	tgEncryptor.XORKeyStream(tgEncryptedMessage, message)
69
 	tgEncryptor.XORKeyStream(tgEncryptedMessage, message)
69
 
70
 
70
-	tgEncDecryptedMessage := tgObfs.Decrypt(tgEncryptedMessage)
71
+	tgEncDecryptedMessage := make([]byte, len(tgEncryptedMessage))
72
+	tgObfs.Decryptor.XORKeyStream(tgEncDecryptedMessage, tgEncryptedMessage)
71
 	assert.Equal(t, message, tgEncDecryptedMessage)
73
 	assert.Equal(t, message, tgEncDecryptedMessage)
72
 
74
 
73
-	clientEncryptedMessage := clientObfs.Encrypt(tgEncDecryptedMessage)
75
+	clientEncryptedMessage := make([]byte, len(tgEncDecryptedMessage))
76
+	clientObfs.Encryptor.XORKeyStream(clientEncryptedMessage, tgEncDecryptedMessage)
74
 	finalMessage := make([]byte, len(clientEncryptedMessage))
77
 	finalMessage := make([]byte, len(clientEncryptedMessage))
75
 	clientDecryptor.XORKeyStream(finalMessage, clientEncryptedMessage)
78
 	clientDecryptor.XORKeyStream(finalMessage, clientEncryptedMessage)
76
 
79
 

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