Kode-Animator commited on
Commit
144552c
·
1 Parent(s): a2eb29c

discriminate Cloudflare TLS versions

Browse files
Files changed (2) hide show
  1. app.py +22 -16
  2. test_transport_diag.py +8 -0
app.py CHANGED
@@ -538,25 +538,31 @@ async def transport_diagnostic():
538
  finally:
539
  sock.close()
540
 
541
- t0 = time.monotonic()
542
- raw = socket.socket(family, socktype, proto)
543
- raw.settimeout(3.0)
544
- try:
545
- raw.connect(sockaddr)
546
- context = ssl.create_default_context()
547
- with context.wrap_socket(raw, server_hostname=host) as tls_sock:
 
 
 
 
 
 
 
 
 
 
 
 
548
  result["tls"].append({
549
- "family": label, "ok": True,
550
- "version": tls_sock.version(),
551
  "elapsed_ms": round((time.monotonic() - t0) * 1000, 1),
552
  })
553
- except Exception as exc:
554
- result["tls"].append({
555
- "family": label, "ok": False,
556
- "error": type(exc).__name__,
557
- "elapsed_ms": round((time.monotonic() - t0) * 1000, 1),
558
- })
559
- raw.close()
560
 
561
  result["dns_elapsed_ms"] = round((time.monotonic() - started) * 1000, 1)
562
 
 
538
  finally:
539
  sock.close()
540
 
541
+ for tls_name, tls_version in (
542
+ ("TLSv1_2", ssl.TLSVersion.TLSv1_2),
543
+ ("TLSv1_3", ssl.TLSVersion.TLSv1_3),
544
+ ):
545
+ t0 = time.monotonic()
546
+ raw = socket.socket(family, socktype, proto)
547
+ raw.settimeout(3.0)
548
+ try:
549
+ raw.connect(sockaddr)
550
+ context = ssl.create_default_context()
551
+ context.minimum_version = tls_version
552
+ context.maximum_version = tls_version
553
+ with context.wrap_socket(raw, server_hostname=host) as tls_sock:
554
+ result["tls"].append({
555
+ "family": label, "requested": tls_name, "ok": True,
556
+ "version": tls_sock.version(),
557
+ "elapsed_ms": round((time.monotonic() - t0) * 1000, 1),
558
+ })
559
+ except Exception as exc:
560
  result["tls"].append({
561
+ "family": label, "requested": tls_name, "ok": False,
562
+ "error": type(exc).__name__,
563
  "elapsed_ms": round((time.monotonic() - t0) * 1000, 1),
564
  })
565
+ raw.close()
 
 
 
 
 
 
566
 
567
  result["dns_elapsed_ms"] = round((time.monotonic() - started) * 1000, 1)
568
 
test_transport_diag.py CHANGED
@@ -18,3 +18,11 @@ class TransportDiagnosticRouteTest(unittest.TestCase):
18
 
19
  if __name__ == "__main__":
20
  unittest.main()
 
 
 
 
 
 
 
 
 
18
 
19
  if __name__ == "__main__":
20
  unittest.main()
21
+
22
+
23
+ class TransportDiagnosticTLSVersionTest(unittest.TestCase):
24
+ def test_probe_discriminates_tls12_and_tls13(self):
25
+ import inspect
26
+ source = inspect.getsource(app.transport_diagnostic)
27
+ self.assertIn("TLSv1_2", source)
28
+ self.assertIn("TLSv1_3", source)