Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

building: collect .hmac files for linux shared libraries #8288

Merged
merged 6 commits into from Feb 7, 2024

Conversation

rokm
Copy link
Member

@rokm rokm commented Feb 6, 2024

Implement collection of .hmac files that may accompany shared library .so files on some linux systems (Red Hat Enterprise Linux, Fedora Linux). As per #8287, these HMACs are used in crypto library validation/self-check that is enforced when RHEL system is running in FIPS-enabled mode:

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/security_hardening/assembly_installing-a-rhel-8-system-with-fips-mode-enabled_security-hardening

Closes #8273.

When running in FIPS-mode, hashlib.md5() cannot be used - therefore, switch the binary cache hashes from md5 to sha1. This allows to run PyInstaller with --strip option on FIPS-enabled RHEL system.

A shared library with HMAC should not be modified in any way (as this invalidates the HMAC), so exempt such shared libraries from processing in process_collected_binaries (strip and/or upx, although upx is currently disabled on linux).

At the same time, refactor process_collected_binaries to remove call to itself when both strip and upx are used; instead, both utilities are called one after another (i.e., without separately caching the intermediate result). The main goal here is to simplify the processing flow to make it easier to eventually introduce support for code-signing on Windows.

In the late analysis stage, go over all collected binaries, and
collect their accompanying .hmac files, if they are available.
These files are required in FIPS-enabled mode on RHEL, where the
HMAC accompanying OpenSSL shared library is used in the library's
self-check.
On FIPS-enabled RHEL systems, `hashlib.md5()` raises exception:
```
ValueError: [digital envelope routines: EVP_DigestInit_ex] disabled
for FIPS
```

So switch to SHA1 instead.
Remove the check for WinSxS `.manifest` files in
`process_collected_binaries` helper, as automatic data vs binary
(re)classification should hopefully ensure that `.manifest` files
never end up in this processing codepath.
Refactor `process_collected_binary` helper, with goal of removing
the recursive call to itself when both strip and upx are enabled.

This makes the processing flow easier to follow, and makes it
easier to add additional steps (for example, code-signing on
Windows), without having to worry about those steps being
performed in intermediate recursive calls.
Automatically disable upx and/or strip if a linux binary has an
accompanying .hmac file, as modification to the binary will
invalidate the HMAC.
If calling `strip` or `upx` in `process_collected_binary` fails
for whatever reason, display a warning and captured stdout/stderr.
The failure is still considered non-fatal (warning instead of an
error), but it should be visible to the user.
@rokm rokm marked this pull request as ready for review February 7, 2024 10:14
@rokm rokm requested a review from bwoodsend February 7, 2024 10:15
@rokm rokm merged commit 08e2ee5 into pyinstaller:develop Feb 7, 2024
18 checks passed
@rokm rokm deleted the fips-hmac branch February 7, 2024 17:07
rokm added a commit to rokm/pyinstaller that referenced this pull request Feb 22, 2024
Extend the mechanism for collection of `.hmac` files from pyinstaller#8288
to `.chk` files that are used by NSS libraries.
rokm added a commit that referenced this pull request Feb 23, 2024
Extend the mechanism for collection of `.hmac` files from #8288
to `.chk` files that are used by NSS libraries.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RHEL8 FIPS Fatal Selftest Failure
2 participants