Просмотр исходного кода

Add new secure-only mode

tags/0.14^2^2
9seconds 7 лет назад
Родитель
Сommit
7182c7bf65
3 измененных файлов: 15 добавлений и 2 удалений
  1. 4
    1
      config/config.go
  2. 6
    1
      main.go
  3. 5
    0
      proxy/proxy.go

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

16
 	Debug      bool
16
 	Debug      bool
17
 	Verbose    bool
17
 	Verbose    bool
18
 	SecureMode bool
18
 	SecureMode bool
19
+	SecureOnly bool
19
 
20
 
20
 	ReadBufferSize  int
21
 	ReadBufferSize  int
21
 	WriteBufferSize int
22
 	WriteBufferSize int
116
 	bindPort, publicIPv4Port, publicIPv6Port, statsPort, statsdPort uint16,
117
 	bindPort, publicIPv4Port, publicIPv6Port, statsPort, statsdPort uint16,
117
 	statsdIP, statsdNetwork, statsdPrefix, statsdTagsFormat string,
118
 	statsdIP, statsdNetwork, statsdPrefix, statsdTagsFormat string,
118
 	statsdTags map[string]string,
119
 	statsdTags map[string]string,
120
+	secureOnly bool,
119
 	secret, adtag []byte) (*Config, error) {
121
 	secret, adtag []byte) (*Config, error) {
120
-	secureMode := false
122
+	secureMode := secureOnly
121
 	if bytes.HasPrefix(secret, []byte{0xdd}) && len(secret) == 17 {
123
 	if bytes.HasPrefix(secret, []byte{0xdd}) && len(secret) == 17 {
122
 		secureMode = true
124
 		secureMode = true
123
 		secret = bytes.TrimPrefix(secret, []byte{0xdd})
125
 		secret = bytes.TrimPrefix(secret, []byte{0xdd})
157
 	conf := &Config{
159
 	conf := &Config{
158
 		Debug:           debug,
160
 		Debug:           debug,
159
 		Verbose:         verbose,
161
 		Verbose:         verbose,
162
+		SecureOnly:      secureOnly,
160
 		BindIP:          bindIP,
163
 		BindIP:          bindIP,
161
 		BindPort:        bindPort,
164
 		BindPort:        bindPort,
162
 		PublicIPv4:      publicIPv4,
165
 		PublicIPv4:      publicIPv4,

+ 6
- 1
main.go Просмотреть файл

122
 		Envar("MTG_BUFFER_READ").
122
 		Envar("MTG_BUFFER_READ").
123
 		Default("131072").
123
 		Default("131072").
124
 		Uint32()
124
 		Uint32()
125
+	secureOnly = app.Flag("secure-only",
126
+		"Support clients with dd-secrets only.").
127
+		Short('s').
128
+		Envar("MTG_SECURE_ONLY").
129
+		Bool()
125
 
130
 
126
 	secret = app.Arg("secret", "Secret of this proxy.").Required().HexBytes()
131
 	secret = app.Arg("secret", "Secret of this proxy.").Required().HexBytes()
127
 	adtag  = app.Arg("adtag", "ADTag of the proxy.").HexBytes()
132
 	adtag  = app.Arg("adtag", "ADTag of the proxy.").HexBytes()
146
 		*bindIP, *publicIPv4, *publicIPv6, *statsIP,
151
 		*bindIP, *publicIPv4, *publicIPv6, *statsIP,
147
 		*bindPort, *publicIPv4Port, *publicIPv6Port, *statsPort, *statsdPort,
152
 		*bindPort, *publicIPv4Port, *publicIPv6Port, *statsPort, *statsdPort,
148
 		*statsdIP, *statsdNetwork, *statsdPrefix, *statsdTagsFormat,
153
 		*statsdIP, *statsdNetwork, *statsdPrefix, *statsdTagsFormat,
149
-		*statsdTags,
154
+		*statsdTags, *secureOnly,
150
 		*secret, *adtag,
155
 		*secret, *adtag,
151
 	)
156
 	)
152
 	if err != nil {
157
 	if err != nil {

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

65
 	}
65
 	}
66
 	defer clientConn.(io.Closer).Close() // nolint: errcheck
66
 	defer clientConn.(io.Closer).Close() // nolint: errcheck
67
 
67
 
68
+	if p.conf.SecureOnly && opts.ConnectionType != mtproto.ConnectionTypeSecure {
69
+		log.Errorw("Proxy supports only secure connections", "connection_type", opts.ConnectionType)
70
+		return
71
+	}
72
+
68
 	stats.ClientConnected(opts.ConnectionType, clientConn.RemoteAddr())
73
 	stats.ClientConnected(opts.ConnectionType, clientConn.RemoteAddr())
69
 	defer stats.ClientDisconnected(opts.ConnectionType, clientConn.RemoteAddr())
74
 	defer stats.ClientDisconnected(opts.ConnectionType, clientConn.RemoteAddr())
70
 
75
 

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