Allow Node download through intercepted TLS

This commit is contained in:
王鹏
2026-10-10 11:22:22 +08:00
parent ab501eacdb
commit 0363e6295a
2 changed files with 78 additions and 2 deletions

View File

@@ -922,7 +922,14 @@ def _read_url_bytes(
on_output("Python 未信任当前网络证书,正在改用 Windows 系统证书存储重试下载...")
with tempfile.TemporaryDirectory(prefix="autodeploy-windows-download-") as temporary:
destination = Path(temporary) / "download.bin"
_download_with_windows_certificates(url, destination, timeout)
try:
_download_with_windows_certificates(url, destination, timeout)
except Exception:
on_output(
"Windows 系统证书存储仍无法下载,正在按用户设置跳过 HTTPS 证书校验重试..."
)
with _open_url_without_certificate_validation(url, timeout=timeout) as response:
return response.read()
return destination.read_bytes()
@@ -941,7 +948,26 @@ def _download_to_file_with_windows_fallback(
raise
destination.unlink(missing_ok=True)
on_output("Python 未信任当前网络证书,正在改用 Windows 系统证书存储重试下载...")
_download_with_windows_certificates(url, destination, 60)
try:
_download_with_windows_certificates(url, destination, 60)
except Exception:
destination.unlink(missing_ok=True)
on_output(
"Windows 系统证书存储仍无法下载,正在按用户设置跳过 HTTPS 证书校验重试..."
)
_download_to_file(
url,
destination,
_open_url_without_certificate_validation,
on_output,
)
def _open_url_without_certificate_validation(url: str, timeout: int):
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
return urllib.request.urlopen(url, timeout=timeout, context=context)
def _is_certificate_verification_failure(exc: BaseException) -> bool: