Преглед изворни кода

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
 		return
236
 		return
237
 	}
237
 	}
238
 
238
 
239
+	v4Match := ourIP4 == nil
240
+	v6Match := ourIP6 == nil
241
+
239
 	for _, addr := range addresses {
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
 	resolved := make([]string, 0, len(addresses))
256
 	resolved := make([]string, 0, len(addresses))
247
 	for _, addr := range addresses {
257
 	for _, addr := range addresses {
248
 		resolved = append(resolved, addr.IP.String())
258
 		resolved = append(resolved, addr.IP.String())
261
 		our += ourIP6.String()
271
 		our += ourIP6.String()
262
 	}
272
 	}
263
 
273
 
264
-	log.BindStr("hostname", host).
274
+	entry := log.BindStr("hostname", host).
265
 		BindStr("resolved", strings.Join(resolved, ", ")).
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
 func runProxy(conf *config.Config, version string) error { //nolint: funlen, cyclop
290
 func runProxy(conf *config.Config, version string) error { //nolint: funlen, cyclop

Loading…
Откажи
Сачувај