Skip to content

Commit d5882c5

Browse files
authored
Bump automatic certificate update on Windows during builds (GH-143741)
Without this, OpenSSL that we use to download external dependencies might use a stale certificate store and be unable to connect to servers. We need to use a Windows-specific HTTP client that uses CryptoAPI directly to trigger certificate updates. We only do it on failure to avoid hitting servers twice. And we only do it once per each URL.
1 parent 0bee481 commit d5882c5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

PCbuild/get_external.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/usr/bin/env python3
22

33
import argparse
4+
import functools
45
import os
56
import pathlib
67
import platform
8+
import subprocess
79
import sys
810
import tarfile
911
import time
@@ -12,6 +14,27 @@
1214
import zipfile
1315

1416

17+
@functools.cache
18+
def trigger_automatic_root_certificate_update(url: str, timeout: int = 30) -> None:
19+
escaped_url = url.replace("'", "''")
20+
try:
21+
subprocess.run(
22+
[
23+
"powershell",
24+
"-NoProfile",
25+
"-Command",
26+
f"Invoke-WebRequest -Uri '{escaped_url}'"
27+
f" -UseBasicParsing -Method HEAD -MaximumRedirection 0"
28+
f" -TimeoutSec {timeout}",
29+
],
30+
check=True,
31+
capture_output=True,
32+
timeout=timeout + 5,
33+
)
34+
except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as e:
35+
print(e)
36+
37+
1538
def retrieve_with_retries(download_location, output_path, reporthook,
1639
max_retries=7):
1740
"""Download a file with exponential backoff retry and save to disk."""
@@ -25,6 +48,7 @@ def retrieve_with_retries(download_location, output_path, reporthook,
2548
except (urllib.error.URLError, ConnectionError) as ex:
2649
if attempt == max_retries:
2750
raise OSError(f'Download from {download_location} failed.') from ex
51+
trigger_automatic_root_certificate_update(download_location)
2852
time.sleep(2.25**attempt)
2953
else:
3054
return resp

0 commit comments

Comments
 (0)