소스 검색

Add new secure-only mode

tags/0.14^2^2
9seconds 7 년 전
부모
커밋
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,6 +16,7 @@ type Config struct {
16 16
 	Debug      bool
17 17
 	Verbose    bool
18 18
 	SecureMode bool
19
+	SecureOnly bool
19 20
 
20 21
 	ReadBufferSize  int
21 22
 	WriteBufferSize int
@@ -116,8 +117,9 @@ func NewConfig(debug, verbose bool, // nolint: gocyclo
116 117
 	bindPort, publicIPv4Port, publicIPv6Port, statsPort, statsdPort uint16,
117 118
 	statsdIP, statsdNetwork, statsdPrefix, statsdTagsFormat string,
118 119
 	statsdTags map[string]string,
120
+	secureOnly bool,
119 121
 	secret, adtag []byte) (*Config, error) {
120
-	secureMode := false
122
+	secureMode := secureOnly
121 123
 	if bytes.HasPrefix(secret, []byte{0xdd}) && len(secret) == 17 {
122 124
 		secureMode = true
123 125
 		secret = bytes.TrimPrefix(secret, []byte{0xdd})
@@ -157,6 +159,7 @@ func NewConfig(debug, verbose bool, // nolint: gocyclo
157 159
 	conf := &Config{
158 160
 		Debug:           debug,
159 161
 		Verbose:         verbose,
162
+		SecureOnly:      secureOnly,
160 163
 		BindIP:          bindIP,
161 164
 		BindPort:        bindPort,
162 165
 		PublicIPv4:      publicIPv4,

+ 6
- 1
main.go 파일 보기

@@ -122,6 +122,11 @@ var (
122 122
 		Envar("MTG_BUFFER_READ").
123 123
 		Default("131072").
124 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 131
 	secret = app.Arg("secret", "Secret of this proxy.").Required().HexBytes()
127 132
 	adtag  = app.Arg("adtag", "ADTag of the proxy.").HexBytes()
@@ -146,7 +151,7 @@ func main() { // nolint: gocyclo
146 151
 		*bindIP, *publicIPv4, *publicIPv6, *statsIP,
147 152
 		*bindPort, *publicIPv4Port, *publicIPv6Port, *statsPort, *statsdPort,
148 153
 		*statsdIP, *statsdNetwork, *statsdPrefix, *statsdTagsFormat,
149
-		*statsdTags,
154
+		*statsdTags, *secureOnly,
150 155
 		*secret, *adtag,
151 156
 	)
152 157
 	if err != nil {

+ 5
- 0
proxy/proxy.go 파일 보기

@@ -65,6 +65,11 @@ func (p *Proxy) accept(conn net.Conn) {
65 65
 	}
66 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 73
 	stats.ClientConnected(opts.ConnectionType, clientConn.RemoteAddr())
69 74
 	defer stats.ClientDisconnected(opts.ConnectionType, clientConn.RemoteAddr())
70 75
 

Loading…
취소
저장