浏览代码

Require all detected IP families to match in SNI-DNS check

Previously the check returned OK if any resolved address matched
either the public IPv4 or IPv6. A matching AAAA could mask a
mismatched A record (and vice versa), which is a problem because
most client connectivity is still IPv4: a partial match would
silently pass the warning while DPI still blocks the proxy.

Now each detected IP family must appear in the DNS response; the
warning also reports per-family match status so operators can tell
which record is wrong.
pull/461/head
dolonet 3 周前
父节点
当前提交
491a355a61
共有 1 个文件被更改,包括 26 次插入7 次删除
  1. 26
    7
      internal/cli/run_proxy.go

+ 26
- 7
internal/cli/run_proxy.go 查看文件

@@ -236,13 +236,23 @@ func warnSNIMismatch(conf *config.Config, ntw mtglib.Network, log mtglib.Logger)
236 236
 		return
237 237
 	}
238 238
 
239
+	v4Match := ourIP4 == nil
240
+	v6Match := ourIP6 == nil
241
+
239 242
 	for _, addr := range addresses {
240
-		if (ourIP4 != nil && addr.IP.String() == ourIP4.String()) ||
241
-			(ourIP6 != nil && addr.IP.String() == ourIP6.String()) {
242
-			return
243
+		if ourIP4 != nil && addr.IP.String() == ourIP4.String() {
244
+			v4Match = true
245
+		}
246
+
247
+		if ourIP6 != nil && addr.IP.String() == ourIP6.String() {
248
+			v6Match = true
243 249
 		}
244 250
 	}
245 251
 
252
+	if v4Match && v6Match {
253
+		return
254
+	}
255
+
246 256
 	resolved := make([]string, 0, len(addresses))
247 257
 	for _, addr := range addresses {
248 258
 		resolved = append(resolved, addr.IP.String())
@@ -261,11 +271,20 @@ func warnSNIMismatch(conf *config.Config, ntw mtglib.Network, log mtglib.Logger)
261 271
 		our += ourIP6.String()
262 272
 	}
263 273
 
264
-	log.BindStr("hostname", host).
274
+	entry := log.BindStr("hostname", host).
265 275
 		BindStr("resolved", strings.Join(resolved, ", ")).
266
-		BindStr("public_ip", our).
267
-		Warning("SNI-DNS mismatch: secret hostname does not resolve to this server's public IP. " +
268
-			"DPI may detect and block the proxy. See 'mtg doctor' for details")
276
+		BindStr("public_ip", our)
277
+
278
+	if ourIP4 != nil {
279
+		entry = entry.BindStr("ipv4_match", fmt.Sprintf("%t", v4Match))
280
+	}
281
+
282
+	if ourIP6 != nil {
283
+		entry = entry.BindStr("ipv6_match", fmt.Sprintf("%t", v6Match))
284
+	}
285
+
286
+	entry.Warning("SNI-DNS mismatch: secret hostname does not resolve to this server's public IP. " +
287
+		"DPI may detect and block the proxy. See 'mtg doctor' for details")
269 288
 }
270 289
 
271 290
 func runProxy(conf *config.Config, version string) error { //nolint: funlen, cyclop

正在加载...
取消
保存