Repository navigation
Closed
Description
I would like to use this ticket to manage all the issues related to OpenSSL 3 FIPS. The goal of this ticket is to pass all the unit tests with the OpenSSL 3.2, 3.1 and 3.0 FIPS cases on the CI.
FIPS related issues/pull-requests
I update the list regularly. The issues are sorted by newest first.
- 19: Fix test_ts.rb in FIPS. #1056
- 18: Fix test_kdf.rb in FIPS. #1054
- 17: hmac: enable tests in the FIPS mode #1042
- 16: Fix test_pkcs12.rb in FIPS. #997
- 15: Fix test_digest.rb in FIPS. #995
- 14: Fix test_cipher.rb in FIPS. #994
- 13: Update keys used in tests #953
- 12: Fix test_ssl.rb in FIPS. #937
- 11: Rakefile: Manage test files by excluding test files in the test_fips task. #820
- 10: Add passing test files in FIPS. #819
- 9: Fix test_provider.rb in FIPS. #794
- 8: Fix test_pkey_rsa.rb in FIPS. #790
- 7: Fix test_pkey_dsa.rb in FIPS. #729
- 6: Fix test_pkey_dh.rb in FIPS. #694
- 5: Fixed
test/openssl/test_pkey_ec.rb. test_pkey_ec.rb test failures in OpenSSL FIPS #671 fixed by test/openssl/test_pkey_ec.rb: refactor tests for EC.builtin_curves #675, and Fix test_pkey_ec.rb on FIPS. #681. - 4: Fixed the second issue in
OpenSSL::PKey.readandtest/openssl/test_pkey.rb. The issue was fixed by the the workaround ossl_pkey.c: Workaround: Decode with non-zero selections. #669.- ed25519: OpenSSL 3.0.8: ed25519 a decode from and then encode to a pem file corrupts the key if fips+base provider is used openssl/openssl#20758
- x25519: OpenSSL 3: x25519 a decode from and then encode to a pem file corrupts the key if fips+base provider is used openssl/openssl#21493
- Fixed PR in OpenSSL Decoder key export fixes openssl/openssl#21519
- 3: OpenSSL 3 FIPS mode - creating encrypted RSA key pair fails with PEM_write_bio_PrivateKey_traditional: initialization error (OpenSSL::PKey::PKeyError) #643
- 2: Fixed an issue in
OpenSSL::PKey.read. Applied the workaround PR Fix OpenSSL::PKey.read that cannot parse PKey in the FIPS mode. #615 to avoid the OpenSSL issue OSSL_DECODER_CTX_set_selection doesn't apply the selection value properly openssl/openssl#20657. - 1: Fixed the
OpenSSL.fips_modein OpenSSL 3.0+. The issue: OpenSSL 3: OpenSSL.fips_mode returns false in FIPS enabled environment #605, the PR: Implement FIPS functions, adding OpenSSL FIPS mode case on CI. #608
Remaining tasks to the goal
Fix other test files test/**/test_*.rb to pass in CI. The fixed test files 18/33.
$ date
Wed Oct 4 04:54:22 PM CEST 2023
$ find test/ -name "test_*.rb" | wc -l
33
Documents
- How to debug Ruby OpenSSL binding with OpenSSL 3 FIPS: Contribution is welcome!
- Check openssl-head fips, openssl-3.1.z fips or openssl-3.0 fips cases in this repository's GitHub Actions YAML file to know how to compile Ruby OpenSSL binding with OpenSSL FIPS.
Original comment
I deleted to simplify this issue ticket. I think we don't need the original comment's information any more.
Reacted by brad
Metadata
Metadata
Assignees
Labels
No labels
Activity
jackorp commentedon Feb 27, 2023
I'll add what we learned on our side in more detail.
Downstream bug report: https://bugzilla.redhat.com/show_bug.cgi?id=2170105
Some words and what they refer to throughout this report:
rubygem-openssl = this repo, the OpenSSL bindings gem shipped with Ruby
OpenSSL / C OpenSSL / libopenssl = the system OpenSSL
Problem description:
rubygem-openssl cannot load keys when the system is in FIPS mode. This was found on RHEL 9 and applies to RHEL 9.0 up to the package set available in C9S at the time of this report, which translates to RHEL 9.2.
Reproducer on RHEL 9:
0. have FIPS enabled system
1.a
$ sudo dnf install ruby-- this will install Ruby 3.0 with backported patches to work with OpenSSL 3.01.b Optionally, you can use Ruby 3.1 which ships with rubygem-openssl 3.0 on RHEL 9.1 and later:
$ openssl genrsa -out key.pem 4096-- create a key for reproducer purposesruby -ropenssl -e "OpenSSL::PKey.read(File.read('key.pem'))"Actual results:
Expected results:
No errors
This was observed with OpenSSL versions 3.0.1 through 3.0.7 and with rubygem-openssl 2.2.1, 3.0.0, 3.1.0 up to the more recent commits on the master branch of this repo: 9ea934a .
The problem is that
ossl_pkey_read_genericfails to correctly parse the key.I have distilled Ruby's code flow into a simple C example to illustrate better what is happening. See the comment on the downstream ticket: https://bugzilla.redhat.com/show_bug.cgi?id=2170105#c7
I found that initializing
OSSL_DECODER_CTX_new_for_pkey(...)withEVP_PKEY_KEYPAIRas the value for theselectionargument of the function allows for the decoding to succeed. However, if I reuse theOSSL_DECODER_CTXstructure, whereselectionis 0 and useOSSL_DECODER_CTX_set_selectionbefore decoding withEVP_PKEY_KEYPAIR, decoding fails unless there is a proper call toOpenSSL_init_ssl()at the beginning of the main function of the C example. Currently these OpenSSL flags work for the example:I'll emphasize that it is important that
OSSL_DECODER_CTX_new_for_pkeywith different selection arguments works when decoding a key in BIO struct multiple times.I have also used system's python (python 3.9), where loading pem key simply works:
They seem to initialize OpenSSL similarly to Ruby
From inspecting ltraces of both languages I noticed that python uses EVP_MD* function family from openssl unlike rubygem-openssl, where OSSL_DECODER* function family is used.
Traces for python and Ruby:
python was ran as follows:
python script.pypython_crypto_ltrace.txt
python_crypto_strace.txt
Ruby was ran as follows:
ruby -ropenssl -e "OpenSSL::PKey.read(File.read('key.pem'))"rubygem_openssl_ltrace.txt
rubygem_openssl_ltrace.txt
To me it seems something isn't being loaded properly in Ruby when system is in FIPS mode as calling
OSSL_PROVIDER_load(NULL, "fips")fixes the situation when inserted into rubygem-openssl code before decoding the key. However, from what I understand from Dmitry Belyavskiy on the downstream ticket, that call should not be needed, as correct providers should be loaded automatically, assuming OpenSSL was initialized: https://bugzilla.redhat.com/show_bug.cgi?id=2170105#c29junaruga commentedon Mar 3, 2023
Note that now the maintainers can try the FIPS mode enabled environment on the RHEL 9.1 server in the Ruby project. For the steps, see #601 (comment) . I was able to reproduce this issue ticket' error on the environment.
junaruga commentedon Mar 15, 2023
I noted the the mentioned RPM package "python3-cryptography" is not available on Fedora: https://src.fedoraproject.org/rpms/python3-cryptography .
So, just installing the PyPI package "cryptography" directly is convenient. The GitHub is here.
junaruga commentedon Mar 17, 2023
We can reproduce this issue on GitHub Actions after this PR #608 is merged!
jackorp commentedon Mar 17, 2023
I am not sure you are right in this. I was able to find this via both the
dnf infoanddnf installon containers of Fedora 36 up to Rawhide.it is actually coming from this repo: https://src.fedoraproject.org/rpms/python-cryptography
junaruga commentedon Mar 17, 2023
@jackorp You are right. Thanks for the info. I also can see the installed package on my environment. What was I seeing at that time... Sorry.
It seems that the
python-cryptographyrepository's python-cryptography.spec (recipe file) manages the entry of thepython3-cryptographypackage.junaruga commentedon Mar 28, 2023
I am debugging this issue on Fedora 37. Let me share my current status. I think my small program: fips_mode command is helpful for you to check if you are running the correct FIPS mode on your environment. You can run like this.
I am debugging this issue with GDB on the commits in the #608 on Fedora. There is an issue gdb with
LD_LIBRARY_PATH=/path/to/openssl_lib(this issue). So, I am setting theLD_LIBRARY_PATHin the GDB prompt.Some of the content might repeat what jarkorp said.
The error is happening on the code below, because the
pkeyis NULL.openssl/ext/openssl/ossl_pkey.c
Lines 215 to 218 in a14055a
Here is the backtrace.
In the process, the
ossl_pkey_read_genericis called from the ext/openssl/ossl_pkey_dh.cossl_dh_initialize, and also called from ext/openssl/ossl_pkey.cossl_pkey_new_from_data.When the
ossl_pkey_read_genericcalled from theossl_dh_initialize, theOSSL_DECODER_from_bio(dctx, bio)returns 1, and set the value to the poinerpkeyin this timing. But theossl_pkey_read_genericcalled from theossl_pkey_new_from_data,OSSL_DECODER_from_bio(dctx, bio)doesn't return 1, and the variablepkeyis still NULL.openssl/ext/openssl/ossl_pkey.c
Lines 144 to 145 in a14055a
junaruga commentedon Mar 30, 2023
I opened the issue ticket openssl/openssl#20657 on the OpenSSL project to ask a queston.
junaruga commentedon Apr 13, 2023
In the issue ticket on the openssl/openssl above, the root cause was found. In short summary, the
OSSL_DECODER_CTX_set_selectionhas a bug in the FIPS mode case. And I confirmed this issue was fixed with my patch on openssl/openssl#20657 (comment). As a note, I am working for that on my forked repository's branch https://github.com/junaruga/openssl/tree/wip/fips-read.By applying this patch, the unit test result in the FIPS mode changes in a better way from
https://github.com/junaruga/openssl/actions/runs/4681990779/jobs/8295272065
to
https://github.com/junaruga/openssl/actions/runs/4690199157/jobs/8312977212
.
I am still working to fix other issues on the FIPS mode. Seeing the code below in the test, it seems that the FIPS mode case was not tested before. And I would like to remove this logic to run the unit tests in the FIPS mode.
openssl/test/openssl/utils.rb
Lines 5 to 8 in 6182ac0
[-]OpenSSL::PKey.read: can't parse PKey on Linux with FIPS mode enabled[/-][+]Test failiures on Linux with OpenSSL 3.0 FIPS mode enabled[/+][-]Test failiures on Linux with OpenSSL 3.0 FIPS mode enabled[/-][+]Support the OpenSSL 3 FIPS mode[/+][-]Support the OpenSSL 3 FIPS mode[/-][+]Support OpenSSL 3 FIPS mode[/+]junaruga commentedon Apr 17, 2023
I changed this issue ticket's title to the "Support OpenSSL 3 FIPS mode" to manage all the issues on this one ticket. I think it's easy for people to track. This ticket's goal is to pass all the unit tests on the OpenSSL 3.0 FIPS mode on GitHub Actions CI.
My current focus is to fix the 2 test failures
test_ed25519andtest_x25519in thetest/openssl/test_pkey.rbon the OpenSSL 3 FIPS mode. And I opened an issue ticket to ask people with my reproducing program written by C at the OpenSSL project on openssl/openssl#20758.cwjenkins commentedon May 31, 2023
@junaruga you still working on this? Need help?
junaruga commentedon May 31, 2023
@cwjenkins Yes, I am still working on this. And yes! Thank you for your help.
For the original issue on this ticket, I plan to rebase the PR #615 as a workaround of this issue and merge it to the master branch. If you want to see it soon, I can work on it as a higher priority. The root cause was found on the OpenSSL side. Here is the issue ticket openssl/openssl#20657 Folks are working on it.
In the other issues, I want to fix the issue that I wrote on the comment above, #603 (comment). The ticket is openssl/openssl#20758. They are working on it. I don't have a time to debug it by myself (yet).
Right now my focus is to add checks for the compiler warnings on GitHub Actions. Here is the ticket, #626. Because I made a bug #620 related to compiler warning. I think checking compiler warnings by
-Werrorat least on the currently passing cases on the CI is useful and effective. But the #628 is a blocker.So, I need your help for any things related to this issue. Please let me know if you take a task. Thanks!
29 remaining items
junaruga commentedon Jul 3, 2025
During the term from April 2025 to June 2025, there is no progress for this ticket. I really sad to inform you such a situation. I will work on it.
junaruga commentedon Sep 1, 2025
I opened the PR #937.
junaruga commentedon Oct 14, 2025
I would share the status update about this ticket.
During the term from July 2025 to September 2025, we finished the task 12 below.
rhenium commentedon Oct 27, 2025
Removed skips for those in #953, which mostly only required updating keys used in the tests.
junaruga commentedon Oct 28, 2025
Thank you! I would appreciate that. This is a big step forward! I see the following 4 commits on the PR #953 removed the 7 skipped tests.
junaruga commentedon Oct 29, 2025
The number of the remaining skipping files is just 6 now!
openssl/Rakefile
Lines 29 to 34 in fe5f2aa
junaruga commentedon Jan 9, 2026
I sent the PR #994.
junaruga commentedon Jan 13, 2026
I sent the PR #995.
junaruga commentedon Jan 13, 2026
I forgot to share the status update about this ticket.
During the term from October 2025 to December 2025, we didn't finish any tasks. However, in January 2026, we fixed or are fixing 2 test files so far.
junaruga commentedon Jan 19, 2026
I sent the PR #997 (working in progress).
junaruga commentedon Apr 13, 2026
I would share the status update about this ticket.
During the term from January 2026 to March 2026, we finished the task 14, 15 and 16 below.
junaruga commentedon Apr 14, 2026
The number of the remaining skipping files is just 3 now!
openssl/Rakefile
Lines 29 to 31 in 3bd8833
junaruga commentedon May 21, 2026
I sent the following PRs to fix the last 2 test files.
junaruga commentedon Jun 1, 2026
I am glad that finally we can close this ticket created on February 27, 2023 after supporting all the test files to run in FIPS. As today is on June 1st, 2026. We took around 3 years 3 months for this task as a record.