Skip to content

Commit 1ee1076

Browse files
committed
windows: build with OpenSSL 3.0 on CPython 3.11+
The official CPython build system doesn't yet have support for OpenSSL 3.x on <3.11. I suspect this will change in the future. But for right now I don't feel like doing the work of upstream to add support. Closes astral-sh#175.
1 parent 6fdcab4 commit 1ee1076

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

‎cpython-windows/build.py

+37-7
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"_hashlib": ["openssl"],
110110
"_lzma": ["xz"],
111111
"_sqlite3": ["sqlite"],
112-
"_ssl": ["openssl-1.1"],
112+
"_ssl": ["openssl"],
113113
"_tkinter": ["tcl", "tk", "tix"],
114114
"_uuid": ["uuid"],
115115
"zlib": ["zlib"],
@@ -870,7 +870,7 @@ def hack_props(
870870
static_replace_in_file(
871871
openssl_props,
872872
b"<_DLLSuffix>-3</_DLLSuffix>",
873-
b"<_DLLSuffix>-1_1%s</_DLLSuffix>" % suffix,
873+
b"<_DLLSuffix>-3%s</_DLLSuffix>" % suffix,
874874
)
875875
except NoSearchStringError:
876876
static_replace_in_file(
@@ -1565,13 +1565,13 @@ def build_openssl_for_arch(
15651565
perl_path,
15661566
arch: str,
15671567
openssl_archive,
1568+
openssl_version: str,
15681569
nasm_archive,
15691570
build_root: pathlib.Path,
15701571
profile: str,
15711572
*,
15721573
jom_archive,
15731574
):
1574-
openssl_version = DOWNLOADS["openssl-1.1"]["version"]
15751575
nasm_version = DOWNLOADS["nasm-windows-bin"]["version"]
15761576

15771577
log("extracting %s to %s" % (openssl_archive, build_root))
@@ -1661,12 +1661,18 @@ def build_openssl_for_arch(
16611661

16621662

16631663
def build_openssl(
1664-
perl_path: pathlib.Path, arch: str, profile: str, dest_archive: pathlib.Path
1664+
entry: str,
1665+
perl_path: pathlib.Path,
1666+
arch: str,
1667+
profile: str,
1668+
dest_archive: pathlib.Path,
16651669
):
16661670
"""Build OpenSSL from sources using the Perl executable specified."""
16671671

1672+
openssl_version = DOWNLOADS[entry]["version"]
1673+
16681674
# First ensure the dependencies are in place.
1669-
openssl_archive = download_entry("openssl-1.1", BUILD)
1675+
openssl_archive = download_entry(entry, BUILD)
16701676
nasm_archive = download_entry("nasm-windows-bin", BUILD)
16711677
jom_archive = download_entry("jom-windows-bin", BUILD)
16721678

@@ -1682,6 +1688,7 @@ def build_openssl(
16821688
perl_path,
16831689
"x86",
16841690
openssl_archive,
1691+
openssl_version,
16851692
nasm_archive,
16861693
root_32,
16871694
profile,
@@ -1693,6 +1700,7 @@ def build_openssl(
16931700
perl_path,
16941701
"amd64",
16951702
openssl_archive,
1703+
openssl_version,
16961704
nasm_archive,
16971705
root_64,
16981706
profile,
@@ -1843,6 +1851,7 @@ def collect_python_build_artifacts(
18431851
arch: str,
18441852
config: str,
18451853
static: bool,
1854+
openssl_entry: str,
18461855
):
18471856
"""Collect build artifacts from Python.
18481857
@@ -2087,6 +2096,9 @@ def find_additional_dependencies(project: pathlib.Path):
20872096
license_public_domain = False
20882097

20892098
for name in EXTENSION_TO_LIBRARY_DOWNLOADS_ENTRY[ext]:
2099+
if name == "openssl":
2100+
name = openssl_entry
2101+
20902102
download_entry = DOWNLOADS[name]
20912103

20922104
# This will raise if no license metadata defined. This is
@@ -2145,6 +2157,7 @@ def build_cpython(
21452157
windows_sdk_version: str,
21462158
openssl_archive,
21472159
libffi_archive,
2160+
openssl_entry: str,
21482161
):
21492162
static = "static" in profile
21502163
pgo = "-pgo" in profile
@@ -2439,6 +2452,7 @@ def build_cpython(
24392452
build_directory,
24402453
artifact_config,
24412454
static=static,
2455+
openssl_entry=openssl_entry,
24422456
)
24432457

24442458
for ext, init_fn in sorted(builtin_extensions.items()):
@@ -2648,12 +2662,27 @@ def main():
26482662
arch = "amd64"
26492663

26502664
# TODO need better dependency checking.
2651-
openssl_archive = BUILD / ("openssl-%s-%s.tar" % (target_triple, args.profile))
2665+
2666+
# CPython 3.11+ have native support for OpenSSL 3.x. We anticipate this
2667+
# will change in a future minor release once OpenSSL 1.1 goes out of support.
2668+
# But who knows.
2669+
if args.python in ("cpython-3.8", "cpython-3.9", "cpython-3.10"):
2670+
openssl_entry = "openssl-1.1"
2671+
else:
2672+
openssl_entry = "openssl-3.0"
2673+
2674+
openssl_archive = BUILD / (
2675+
"%s-%s-%s.tar" % (openssl_entry, target_triple, args.profile)
2676+
)
26522677
if not openssl_archive.exists():
26532678
perl_path = fetch_strawberry_perl() / "perl" / "bin" / "perl.exe"
26542679
LOG_PREFIX[0] = "openssl"
26552680
build_openssl(
2656-
perl_path, arch, profile=args.profile, dest_archive=openssl_archive
2681+
openssl_entry,
2682+
perl_path,
2683+
arch,
2684+
profile=args.profile,
2685+
dest_archive=openssl_archive,
26572686
)
26582687

26592688
libffi_archive = BUILD / ("libffi-%s-%s.tar" % (target_triple, args.profile))
@@ -2677,6 +2706,7 @@ def main():
26772706
windows_sdk_version=args.windows_sdk_version,
26782707
openssl_archive=openssl_archive,
26792708
libffi_archive=libffi_archive,
2709+
openssl_entry=openssl_entry,
26802710
)
26812711

26822712
if "PYBUILD_RELEASE_TAG" in os.environ:

‎src/validation.rs

+4
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,13 @@ const PE_ALLOWED_LIBRARIES: &[&str] = &[
111111
// Our libraries.
112112
"libcrypto-1_1.dll",
113113
"libcrypto-1_1-x64.dll",
114+
"libcrypto-3.dll",
115+
"libcrypto-3-x64.dll",
114116
"libffi-8.dll",
115117
"libssl-1_1.dll",
116118
"libssl-1_1-x64.dll",
119+
"libssl-3.dll",
120+
"libssl-3-x64.dll",
117121
"python3.dll",
118122
"python38.dll",
119123
"python39.dll",

‎src/verify_distribution.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ def test_hashlib(self):
102102
"sm3",
103103
}
104104

105-
if os.name == "nt":
105+
# Legacy algorithms only present on OpenSSL 1.1.
106+
if os.name == "nt" and sys.version_info[0:2] < (3, 11):
106107
wanted_hashes.add("md4")
107108
wanted_hashes.add("whirlpool")
108109

@@ -129,7 +130,9 @@ def test_ssl(self):
129130
self.assertTrue(ssl.HAS_TLSv1_2)
130131
self.assertTrue(ssl.HAS_TLSv1_3)
131132

132-
if os.name == "nt":
133+
# OpenSSL 1.1 on older CPython versions on Windows. 3.0 everywhere
134+
# else.
135+
if os.name == "nt" and sys.version_info[0:2] < (3, 11):
133136
wanted_version = (1, 1, 1, 23, 15)
134137
else:
135138
wanted_version = (3, 0, 0, 10, 0)

0 commit comments

Comments
 (0)