mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-22 23:59:41 +08:00
Make the TLS and port-range cases hold on every platform
The MITM case reached its origin by address, so it depended on the certificate 3proxy spoofs carrying an IP alternative name. It does when the upstream certificate is copied, which is what happens on Linux and macOS but not on Windows, where the client then refused the connection. Point a name at 127.0.0.1 with nsrecord instead, and check the chain rather than the name: an intercepted certificate names the upstream host, not the one that was asked for. The log assertions gain from it too, since the name is better evidence than a port that the request was seen. nsrecord needs nserver as well as nscache, and has to follow nscache, so say that in the manual: the record goes into the table nscache allocates, and the table is only consulted when nserver is set. The port-range fallback was exercised with a range the same case had already used, so on a busy machine it could fail to bind for the ordinary reason rather than the one under test. Use privileged ports, which nothing can take. When a case fails, print what its servers wrote: the reason usually goes to the server's stderr, which was captured and then thrown away.
This commit is contained in:
1 parent
7011e78ece
commit
facc35e287
5 files changed
+52
-17
No files matched your search
+17
-7
@@ -122,6 +122,7 @@ class Tester:
|
||||
self.timeout = 10
|
||||
self._skipped = 0
|
||||
self._certs = None
|
||||
self.logs = []
|
||||
|
||||
# ---- servers -----------------------------------------------------
|
||||
|
||||
@@ -201,8 +202,10 @@ class Tester:
|
||||
time.sleep(0.05)
|
||||
|
||||
def stop_all(self):
|
||||
"""Stop the servers, keeping what they printed for the report."""
|
||||
for server in self.servers:
|
||||
server.stop()
|
||||
self.logs.append((server.name, server.output()))
|
||||
self.servers = []
|
||||
|
||||
# ---- requests ----------------------------------------------------
|
||||
@@ -464,14 +467,21 @@ class Tester:
|
||||
self._certs = c
|
||||
return c
|
||||
|
||||
def _context(self, ca=None, strict=True):
|
||||
"""A client context. strict=False drops the RFC 5280 checks Python
|
||||
turns on by default from 3.13, which reject a certificate with no
|
||||
Authority Key Identifier."""
|
||||
def _context(self, ca=None, strict=True, verify_name=True):
|
||||
"""A client context.
|
||||
|
||||
strict=False drops the RFC 5280 checks Python turns on by default
|
||||
from 3.13, which reject a certificate with no Authority Key
|
||||
Identifier. verify_name=False keeps the chain check but ignores
|
||||
which host the certificate names, for the intercepted connections
|
||||
where that is the upstream identity rather than the one asked for.
|
||||
"""
|
||||
if ca:
|
||||
context = ssl.create_default_context(cafile=ca)
|
||||
if not strict:
|
||||
context.verify_flags &= ~getattr(ssl, "VERIFY_X509_STRICT", 0)
|
||||
if not verify_name:
|
||||
context.check_hostname = False
|
||||
return context
|
||||
context = ssl.create_default_context()
|
||||
context.check_hostname = False
|
||||
@@ -503,11 +513,11 @@ class Tester:
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
def https(self, url, proxy=None, ca=None, strict=True, method="GET",
|
||||
headers=None):
|
||||
def https(self, url, proxy=None, ca=None, strict=True, verify_name=True,
|
||||
method="GET", headers=None):
|
||||
"""An https:// request, optionally tunnelled through a proxy."""
|
||||
host, port, path = self._split(url, default_port=443)
|
||||
context = self._context(ca, strict)
|
||||
context = self._context(ca, strict, verify_name)
|
||||
try:
|
||||
if proxy:
|
||||
phost, pport = self._hostport(proxy)
|
||||
|
||||
Reference in new issue
Block a user