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

Determine whether OpenSSL needs to be configured (FIPs, SHA1 s… …ignature) #878

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

stefanberger
Copy link
Owner

@stefanberger stefanberger commented Jul 22, 2024

Get the list of enabled 'RuntimeAlgorithms' from libtpms and determine
whether any of these enabled algorithms is disabled in OpenSSL due to FIPS
mode. If FIPS mode on the host is enabled then disabled FIPS mode in
OpenSSL so that the TPM 2 can function properly.

The following algorithms are disabled when OpenSSL is in FIPS mode:

  • camellia
  • rsaes
  • tdes
  • ECC keys <224 bits
  • RSA signing with SHA1 and key of any size

Per openssl-ciphers man page it should be possible to disable the following
algorithms use by cipher-suites:

  • AES128, AES256, AES
  • CAMELLIA128, CAMELLIA256, CAMELLIA
  • 3DES
  • SHA1, SHA, SHA256, SHA384
  • CBC

WIP: It's not clear at what API level these are disabled. I have not been able
to use !SHA256 to disabled SHA256.

@stefanberger
Copy link
Owner Author

@elmarco @berrange These are for now the unchanged remainders of the original profiles PR. I believe swtpm still needs to check whether FIPs mode is enabled in OpenSSL but maybe display an error message if it is and algorithms are not functioning and exit, OR allow to disable FIPS mode in the OpenSSL instance if the user passed a command line option.

@stefanberger stefanberger marked this pull request as draft July 22, 2024 16:00
@stefanberger
Copy link
Owner Author

stefanberger commented Jul 25, 2024

It seems there are different ways we could disable the enforcement of disabled algorithms on a host:

  • OPENSSL_no_config() : do not read any configuration file; very last resort
  • EVP_default_properties_enable_fips(NULL, 0): this seems to enable a few algorithms disabled by FIPS mode; /etc/crypto-policies/back-ends/opensslcnf.config not changed between fips and non-fips mode

My current thinking is to

  1. check for FIPS mode enabled and
  2. if it is enabled test candidate algorithms to be disabled by FIPS mode
  3. then disable FIPS mode if necessary and
  4. then test the same candidate algorithms again and possibly more
  5. and exit with error if any algorithm fails

This is a test program:

#include <openssl/evp.h>
#include <openssl/conf.h>

int main(void)
{
//    OPENSSL_no_config();
//    EVP_default_properties_enable_fips(NULL, 1);

    printf("AES-128-CFB: %d\n", EVP_CIPHER_fetch(NULL, "AES-128-CFB", NULL));
    printf("AES-256-CFB: %d\n", EVP_CIPHER_fetch(NULL, "AES-256-CFB", NULL));
    printf("CAMELLIA-128-CFB: %d\n", EVP_CIPHER_fetch(NULL, "CAMELLIA-128-CFB", NULL));
    printf("CAMELLIA-256-CFB: %d\n", EVP_CIPHER_fetch(NULL, "CAMELLIA-256-CFB", NULL));
    printf("DES-EDE3-CFB: %d\n", EVP_CIPHER_fetch(NULL, "DES-EDE3-CFB", NULL));

    EVP_default_properties_enable_fips(NULL, 0);

    printf("AES-128-CFB: %d\n", EVP_CIPHER_fetch(NULL, "AES-128-CFB", NULL));
    printf("CAMELLIA-128-CFB: %d\n", EVP_CIPHER_fetch(NULL, "CAMELLIA-128-CFB", NULL));
    printf("CAMELLIA-256-CFB: %d\n", EVP_CIPHER_fetch(NULL, "CAMELLIA-256-CFB", NULL));
    printf("DES-EDE3-CFB: %d\n", EVP_CIPHER_fetch(NULL, "DES-EDE3-CFB", NULL));
}

On a FIPS-enabled FC-40 host this prints:

AES-128-CFB: 1005757168
AES-256-CFB: 1005756496
CAMELLIA-128-CFB: 0
CAMELLIA-256-CFB: 0
DES-EDE3-CFB: 0
AES-128-CFB: 1005653632
CAMELLIA-128-CFB: 1005727792
CAMELLIA-256-CFB: 1005725840
DES-EDE3-CFB: 1005741520

Per this man page here https://docs.openssl.org/3.0/man1/openssl-ciphers/#cipher-strings it seems to be necessary to test availability of the following algorithms:

  • sha1, sha256, sha384
  • aes-128, aes-256, aes-192
  • camellia-128, camellia-192, camellia-256
  • 3des
  • cbc
    (subject to verification)

Thought "fips=yes" does have some other meanings not covered via the cipherstrings.

@stefanberger stefanberger force-pushed the stefanberger/disable_openssl_fips_mode branch 4 times, most recently from 5024e8f to 48ad68d Compare July 29, 2024 17:51
@stefanberger stefanberger marked this pull request as ready for review July 29, 2024 18:06
@stefanberger stefanberger force-pushed the stefanberger/disable_openssl_fips_mode branch 12 times, most recently from 5c32a1c to 5b13aa4 Compare August 19, 2024 21:12
@stefanberger stefanberger changed the title DO-NOT-MERGE: Disable OpenSSL's FIPS mode if enabled algorithms require it Determine whether OpenSSL needs to be configured (FIPs, SHA1 s… …ignature) Aug 20, 2024
@stefanberger stefanberger force-pushed the stefanberger/disable_openssl_fips_mode branch 3 times, most recently from a24385a to 9e671fd Compare August 20, 2024 20:02
…ignature)

Get the list of enabled 'RuntimeAlgorithms' from libtpms and determine
whether any of these enabled algorithms is disabled in OpenSSL due to FIPS
mode. If FIPS mode on the host is enabled then disabled FIPS mode in
OpenSSL so that the TPM 2 can function properly.

The following algorithms are disabled when OpenSSL is in FIPS mode:
- camellia
- rsaes
- tdes
- ECC keys <224 bits
- RSA keys <2048 bits

Per openssl-ciphers man page it should be possible to disable the following
algorithms use by cipher-suites:

- AES128, AES256, AES
- CAMELLIA128, CAMELLIA256, CAMELLIA
- 3DES
- SHA1, SHA, SHA256, SHA384
- CBC

Note: It's not clear at what API level these are disabled. I have not been able
to use !SHA256 to disabled SHA256.

Also test whether signatures with SHA1 are working and enable them by setting
OPENSSL_ENABLE_SHA1_SIGNATURES=1.

The following output is expected for RHEL 9.x and CentOS 9 but does not
appear on Fedora 40 since there sha1 signatures are not (yet) disabled.

> swtpm socket \
    --tpmstate dir=/tmp/myvtpm \
    --ctrl type=tcp,port=2322 \
    --server type=tcp,port=2321,disconnect \
    --flags not-need-init,startup-clear \
    --log level=0 \
    --tpm2 \
    --profile name=null
Warning: Profile-enabled algorithms contain disabled 'RSA-1024-sign(SHA1, pkcs1-pss)'
Warning: Setting OPENSSL_ENABLE_SHA1_SIGNATURES=1

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
@stefanberger stefanberger force-pushed the stefanberger/disable_openssl_fips_mode branch from 9e671fd to e035994 Compare August 20, 2024 21:12
@stefanberger stefanberger mentioned this pull request Aug 20, 2024
5 tasks
@stefanberger stefanberger merged commit 8d31d88 into master Aug 21, 2024
4 of 5 checks passed
@stefanberger stefanberger deleted the stefanberger/disable_openssl_fips_mode branch August 21, 2024 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant