Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
69 changes: 67 additions & 2 deletions Tools/ssl/multissltests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import subprocess
import sys
import tarfile
from textwrap import dedent
from urllib.error import HTTPError
from urllib.request import urlopen

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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:
Expand Down
Loading