From 898e9df21a2feb8dc144733526c577ce1d43b7e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Fri, 4 Dec 2026 14:35:16 +0100 Subject: [PATCH] gh-163154: Run SSL tests on FIPS mode on the CI Assisted-By: Claude Sonnet 5.5 --- .github/workflows/build.yml | 14 ++++++++ Tools/ssl/multissltests.py | 69 +++++++++++++++++++++++++++++++++++-- 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0cbc05a448cf67..d5fd4ac4878cd2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -268,6 +268,8 @@ jobs: - { name: openssl, version: 1.1.1w } - { name: openssl, version: 3.5.10 } - { name: openssl, version: 4.0.4 } + - { name: openssl, version: 3.5.10, fips: true } + - { name: openssl, version: 4.0.4, fips: true } ## AWS-LC - { name: aws-lc, version: 5.15.0 } env: @@ -316,6 +318,18 @@ jobs: run: | ./python -c 'import ssl; print(ssl.OPENSSL_VERSION)' \ | grep -iE '${{ matrix.ssllib.name }}.*${{ matrix.ssllib.version }}' + - name: Enable FIPS mode for the tests + if: ${{ matrix.ssllib.fips }} + run: | + python3 Tools/ssl/multissltests.py \ + --steps=fips \ + --base-directory "$MULTISSL_DIR" \ + '--${{ matrix.ssllib.name }}' '${{ matrix.ssllib.version }}' \ + --system Linux \ + >> "$GITHUB_ENV" + - name: Verify FIPS mode is enabled + if: ${{ matrix.ssllib.fips }} + run: ./python -c 'import _hashlib; assert _hashlib.get_fips_mode()' - name: SSL tests run: ./python Lib/test/ssltests.py diff --git a/Tools/ssl/multissltests.py b/Tools/ssl/multissltests.py index 732e13156ffb8e..e52a578bfab02e 100755 --- a/Tools/ssl/multissltests.py +++ b/Tools/ssl/multissltests.py @@ -29,6 +29,7 @@ import subprocess import sys import tarfile +from textwrap import dedent from urllib.error import HTTPError from urllib.request import urlopen @@ -133,12 +134,14 @@ ) parser.add_argument( '--steps', - choices=['library', 'modules', 'tests'], + choices=['library', 'modules', 'tests', 'fips'], default='tests', help=( "Which steps to perform. 'library' downloads and compiles a crypto" "library. 'module' also compiles Python modules. 'tests' builds " - "all and runs the test suite." + "all and runs the test suite. 'fips' only prints the environment " + "variables (KEY=value lines) that enable the OpenSSL 3.x+ FIPS " + "provider for the given library." ) ) parser.add_argument( @@ -397,6 +400,9 @@ def check_pyssl(self): if self.version not in version: raise ValueError(version) + def fips_env(self): + raise ValueError(f"FIPS is not supported for {self}") + def run_python_tests(self, tests, network=True): if not tests: cmd = [ @@ -452,6 +458,57 @@ def _post_install_3xx(self): def _post_install_4xx(self): self._post_install_3xx() + def fips_env(self): + """Create an OpenSSL config that activates the FIPS provider + and return environment variables to be appended to $GITHUB_ENV""" + if not self.version.startswith(("3.", "4.")): + return super().fips_env() + modules_dir = os.path.join(self.lib_dir, "ossl-modules") + fips_module = os.path.join(modules_dir, "fips.so") + ssl_dir = os.path.join(self.install_dir, "ssl") + fipsmodule_cnf = os.path.join(ssl_dir, "fipsmodule.cnf") + fips_cnf = os.path.join(ssl_dir, "openssl-fips.cnf") + env = os.environ.copy() + env["LD_LIBRARY_PATH"] = self.lib_dir + self._subprocess_call( + [ + self.openssl_cli, "fipsinstall", + "-out", fipsmodule_cnf, + "-module", fips_module, + ], + env=env, + stdout=sys.stderr, # stdout is reserved for KEY=value output + ) + with open(fips_cnf, "w", encoding="utf-8") as f: + f.write(dedent(f"""\ + config_diagnostics = 1 + openssl_conf = openssl_init + + .include {fipsmodule_cnf} + + [openssl_init] + providers = provider_sect + alg_section = algorithm_sect + + [provider_sect] + fips = fips_sect + base = base_sect + default = default_sect + + [base_sect] + activate = 1 + + [default_sect] + activate = 1 + + [algorithm_sect] + default_properties = fips=yes + """)) + return { + "OPENSSL_CONF": fips_cnf, + "OPENSSL_MODULES": modules_dir, + } + @property def short_version(self): """Short version for OpenSSL download URL""" @@ -556,6 +613,14 @@ def main(): build.install() builds.append(build) + if args.steps == 'fips': + # stdout is meant to be appended to $GITHUB_ENV + if len(builds) != 1: + parser.error("--steps=fips needs exactly one library version") + for key, value in builds[0].fips_env().items(): + print(f"{key}={value}") + return + if args.steps in {'modules', 'tests'}: for build in builds: try: