address deprecated warnings
Mimi Zohar
maintainercover address deprecated warnings
Between travis/ci and OpenSSL v3 a large number of deprecated warnings are being emitted when compiling ima-evm-utils. Start addressing these deprecated warnings by replacing the low level SHA1 and HMAC calls with the EVP_ functions. IMA signature version 1 also uses low level calls, but instead of fixing it, deprecate it as nobody should be using it anyway.
OpenSSL v3 "engine" support is deprecated and replaced with "providers". Engine support will continue to work for a while, but results in deprecated declaration and other messages. Define a "--disable-engine" and the equivalent "--enable-engine=no" configuration option.
Changelog:
- Based on Stefan's comments, removed deprecated functions when not used and added missing word. Updated the usage and options accordingly.
- Based on Vitaly's comments, explicitly require "--disable-engine" configuration to compile ima-evm-utils without OpenSSL v3 engine support and typo.
- Based on Petr's comments, addressed the "return 77" by removing it, updated the travis patch description, and added his Reviewed-by tags.
Mimi Zohar (11):
travis: use the distro OpenSSL version on jammy
travis: update dist=focal
Update configure.ac to address a couple of obsolete warnings Deprecate IMA signature version 1
Replace the low level SHA1 calls when calculating the TPM 1.2 PCRs Replace the low level HMAC calls when calculating the EVM HMAC Add missing EVP_MD_CTX_free() call in calc_evm_hash() Deprecate use of OpenSSL v3 "engine" support
Fix potential use after free in read_tpm_banks()
Limit the file hash algorithm name length
Missing template data size lower bounds checking
.travis.yml | 4 +- acinclude.m4 | 2 +- configure.ac | 23 +++- m4/manpage-docbook-xsl.m4 | 2 +- src/Makefile.am | 18 +++ src/evmctl.c | 223 +++++++++++++++++++++++++++++--------- src/imaevm.h | 2 + src/libimaevm.c | 27 ++++- tests/functions.sh | 14 ++- tests/ima_hash.test | 9 ++ tests/sign_verify.test | 28 ++++- 11 files changed, 280 insertions(+), 72 deletions(-)
Signature · 1 line
2.31.1
Mimi Zohar
maintainerPATCH 1/11 travis: use the distro OpenSSL version on jammy
Use the distro OpenSSL version on jammy, which is newer than OpenSSL 3-beta.
--- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
.travis.yml +1 -1
@@ -40,7 +40,7 @@ matrix: compiler: gcc - os: linux - env: DISTRO=ubuntu:jammy TSS=ibmtss COMPILE_SSL=openssl-3.0.0-beta1 + env: DISTRO=ubuntu:jammy TSS=ibmtss compiler: gcc - os: linux
Signature · 1 line
2.31.1
Mimi Zohar
maintainerPATCH 2/11 travis: update dist=focal
In reply to Mimi ZoharAlthough Github Actions is available on Github Enterprise Server 3.x single server edition, as well as the unpaid version, it is not available in Github Enterprise Server 3.x cluster edition[1]. Continue to support travis.
[1] https://docs.github.com/en/[email protected]/admin/release-notes#github-packages
--- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
.travis.yml +1 -1
@@ -1,6 +1,6 @@ # Copyright (c) 2017-2021 Petr Vorel <[email protected]> -dist: bionic +dist: focal language: C services: - docker
Signature · 1 line
2.31.1
Re: [PATCH ima-evm-utils 02/11] travis: update dist=focal
Quoted 4 lines · Mimi Zohar
Although Github Actions is available on Github Enterprise Server 3.x single server edition, as well as the unpaid version, it is not available in Github Enterprise Server 3.x cluster edition[1]. Continue to support travis.
This text really has nothing obvious to do with the upgrade to focal...
Quoted 21 lines
[1] https://docs.github.com/en/[email protected]/admin/release-notes#github-packages
Reviewed-by Petr Vorel <[email protected]>Signed-off-by Mimi Zohar <[email protected]>--- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-).travis.yml +1
-1@@ -1,6 +1,6 @@ # Copyright (c) 2017-2021 Petr Vorel <[email protected]> -dist: bionic +dist: focal language: C services: - docker
Mimi Zohar
maintainerRe: [PATCH ima-evm-utils 02/11] travis: update dist=focal
Quoted 8 lines · Stefan Berger
Quoted 4 lines · Mimi Zohar
Although Github Actions is available on Github Enterprise Server 3.x single server edition, as well as the unpaid version, it is not available in Github Enterprise Server 3.x cluster edition[1]. Continue to support travis.
This text really has nothing obvious to do with the upgrade to focal...
True, but I've been asked why we have both github actions and travis. This was a convienent place for providing that explanation.
Mimi
Mimi Zohar
maintainerPATCH 3/11 Update configure.ac to address a couple of obsolete warnings
In reply to Mimi ZoharRemove AC_PROG_LIBTOOL and AC_HEAD_STDC. Replace AC_HELP_STRING with AS_HELP_STRING.
--- acinclude.m4 | 2 +- configure.ac | 4 ---- m4/manpage-docbook-xsl.m4 | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-)
acinclude.m4 +1 -1
@@ -2,7 +2,7 @@ AC_DEFUN([PKG_ARG_ENABLE], [ AC_MSG_CHECKING(whether to enable $1) - AC_ARG_ENABLE([$1], AC_HELP_STRING([--enable-$1], [enable $1 (default is $2)]), + AC_ARG_ENABLE([$1], AS_HELP_STRING([--enable-$1], [enable $1 (default is $2)]), [pkg_cv_enable_$1=$enableval], [AC_CACHE_VAL([pkg_cv_enable_$1], [pkg_cv_enable_$1=$2])]) if test $pkg_cv_enable_$1 = yes; then
configure.ac +0 -4
@@ -15,16 +15,12 @@ AM_PROG_CC_C_O #AC_PROG_CXX #AC_PROG_CPP AC_PROG_INSTALL -AC_PROG_LIBTOOL #AC_PROG_LN_S LT_INIT # FIXME: Replace `main' with a function in `-lpthread': #AC_CHECK_LIB([pthread], [main]) -# Checks for header files. -AC_HEADER_STDC - PKG_CHECK_MODULES(LIBCRYPTO, [libcrypto >= 0.9.8 ]) AC_SUBST(KERNEL_HEADERS) AC_CHECK_HEADER(unistd.h)
m4/manpage-docbook-xsl.m4 +1 -1
@@ -7,7 +7,7 @@ AC_DEFUN([EVMCTL_MANPAGE_DOCBOOK_XSL], [ AC_PATH_PROGS(XMLCATALOG, xmlcatalog) AC_ARG_WITH([xml-catalog], - AC_HELP_STRING([--with-xml-catalog=CATALOG], + AS_HELP_STRING([--with-xml-catalog=CATALOG], [path to xml catalog to use]),, [with_xml_catalog=/etc/xml/catalog]) XML_CATALOG_FILE="$with_xml_catalog"
Signature · 1 line
2.31.1
Mimi Zohar
maintainerPATCH 4/11 Deprecate IMA signature version 1
In reply to Mimi ZoharThe original IMA file signatures were based on a SHA1 hash. Kernel support for other hash algorithms was subsequently upstreamed. Deprecate "--rsa" support.
Define "--enable-sigv1" option to configure signature v1 support.
--- configure.ac | 6 ++++++ src/Makefile.am | 10 ++++++++++ src/evmctl.c | 20 ++++++++++++++++---- src/libimaevm.c | 22 +++++++++++++++++++--- tests/sign_verify.test | 18 ++++++++++++------ 5 files changed, 63 insertions(+), 13 deletions(-)
configure.ac +6 -0
@@ -49,6 +49,11 @@ AC_ARG_ENABLE([openssl_conf], AC_DEFINE(DISABLE_OPENSSL_CONF, 1, [Define to disable loading of openssl config by evmctl.]) fi], [enable_openssl_conf=yes]) +AC_ARG_ENABLE(sigv1, + AS_HELP_STRING([--enable-sigv1], [Build ima-evm-utils with signature v1 support])) + AM_CONDITIONAL([CONFIG_SIGV1], [test "x$enable_sigv1" = "xyes"]) + AS_IF([test "$enable_sigv1" != "yes"], [enable_sigv1="no"]) + #debug support - yes for a while PKG_ARG_ENABLE(debug, "yes", DEBUG, [Enable Debug support]) if test $pkg_cv_enable_debug = yes; then
@@ -83,5 +88,6 @@ echo " openssl-conf: $enable_openssl_conf" echo " tss2-esys: $ac_cv_lib_tss2_esys_Esys_Free" echo " tss2-rc-decode: $ac_cv_lib_tss2_rc_Tss2_RC_Decode" echo " ibmtss: $ac_cv_header_ibmtss_tss_h" +echo " sigv1: $enable_sigv1" echo " doc: $have_doc" echo
src/Makefile.am +10 -0
@@ -7,6 +7,10 @@ libimaevm_la_CPPFLAGS = $(AM_CPPFLAGS) $(LIBCRYPTO_CFLAGS) libimaevm_la_LDFLAGS = -version-info 3:0:0 libimaevm_la_LIBADD = $(LIBCRYPTO_LIBS) +if CONFIG_SIGV1 +libimaevm_la_CFLAGS = -DCONFIG_SIGV1 +endif + include_HEADERS = imaevm.h nodist_libimaevm_la_SOURCES = hash_info.h
@@ -22,6 +26,12 @@ evmctl_CPPFLAGS = $(AM_CPPFLAGS) $(LIBCRYPTO_CFLAGS) evmctl_LDFLAGS = $(LDFLAGS_READLINE) evmctl_LDADD = $(LIBCRYPTO_LIBS) -lkeyutils libimaevm.la +# Enable IMA signature version 1 +if CONFIG_SIGV1 +evmctl_CFLAGS = -DCONFIG_SIGV1 +endif + + # USE_PCRTSS uses the Intel TSS if USE_PCRTSS evmctl_SOURCES += pcr_tss.c
src/evmctl.c +16 -4
@@ -987,7 +987,6 @@ static int cmd_verify_ima(struct command *cmd)init_public_keys ("/etc/keys/x509_evm.der" ); } - errno =0 ;if (!file) {log_err ("Parameters missing\n" );print_usage (cmd);
@@ -1004,6 +1003,7 @@ static int cmd_verify_ima(struct command *cmd)return fails >0 ; } +#if CONFIG_SIGV1 static int cmd_convert (struct command *cmd) {char *inkey;
@@ -1034,6 +1034,7 @@ static int cmd_convert(struct command *cmd)RSA_free (key); return err; } +#endif static int cmd_import (struct command *cmd) {
@@ -1088,6 +1089,7 @@ static int cmd_import(struct command *cmd)calc_keyid_v2 ((uint32_t *)keyid, name, pkey);EVP_PKEY_free (pkey); }else { +#if CONFIG_SIGV1 RSA *key =read_pub_key (inkey, imaevm_params.x509);if (!key)
@@ -1095,6 +1097,10 @@ static int cmd_import(struct command *cmd) len =key2bin (key, pub);calc_keyid_v1 (keyid, name, pub, len);RSA_free (key); +#else +log_info ("Importing public RSA key is not supported\n" ); +return 1 ; +#endif }log_info ("Importing public key %s from file %s into keyring %d\n" , name, inkey, id);
@@ -2598,7 +2604,9 @@ static void usage(void) " -d, --imahash make IMA hash\n" " -f, --sigfile store IMA signature in .sig file instead of xattr\n" " --xattr-user store xattrs in user namespace (for testing purposes)\n" -" --rsa use RSA key type and signing scheme v1\n" +#if CONFIG_SIGV1 + " --rsa use RSA key type and signing scheme v1 (deprecated)\n" +#endif" -k, --key path to signing key (default: /etc/keys/{privkey,pubkey}_evm.pem)\n" " or a pkcs11 URI\n" " --keyid n overwrite signature keyid with a 32-bit value in hex (for signing)\n"
@@ -2637,8 +2645,12 @@ static void usage(void)struct command cmds[] = { {"--version" ,NULL ,0 ,"" }, {"help" , cmd_help,0 ,"<command>" }, - {"import" , cmd_import,0 ,"[--rsa] pubkey keyring" ,"Import public key into the keyring.\n" }, - {"convert" , cmd_convert,0 ,"key" ,"convert public key into the keyring.\n" }, +#if CONFIG_SIGV1 + {"import" , cmd_import,0 ,"[--rsa] pubkey keyring" ,"Import public key into the keyring. ([--rsa] deprecated)\n" }, + {"convert" , cmd_convert,0 ,"key" ,"convert public key into the keyring. (deprecated)\n" }, +#else + {"import" , cmd_import,0 ,"pubkey keyring" ,"Import public key into the keyring.\n" }, +#endif {"sign" , cmd_sign_evm,0 ,"[-r] [--imahash | --imasig ] [--key key] [--pass [password] file" ,"Sign file metadata.\n" }, {"verify" , cmd_verify_evm,0 ,"file" ,"Verify EVM signature (for debugging).\n" }, {"ima_sign" , cmd_sign_ima,0 ,"[--sigfile] [--key key] [--pass [password] file" ,"Make file content signature.\n" },
src/libimaevm.c +19 -3
@@ -292,6 +292,7 @@ out:return pkey; } +#if CONFIG_SIGV1 RSA *read_pub_key (const char *keyfile,int x509) {EVP_PKEY *pkey;
@@ -351,6 +352,7 @@ static int verify_hash_v1(const char *file, const unsigned char *hash, int size,return 0 ; } +#endif /* CONFIG_SIGV1 */ struct public_key_entry {struct public_key_entry *next;
@@ -686,6 +688,7 @@ int verify_hash(const char *file, const unsigned char *hash, int size, {/* Get signature type from sig header */ if (sig[1 ] ==DIGSIG_VERSION_1 ) { +#if CONFIG_SIGV1 const char *key =NULL ;/* Read pubkey from RSA key */
@@ -695,6 +698,10 @@ int verify_hash(const char *file, const unsigned char *hash, int size, key = imaevm_params.keyfile;return verify_hash_v1 (file, hash, size, sig +1 , siglen -1 , key); +#else +log_info ("Signature version 1 deprecated." ); +return -1 ; +#endif }else if (sig[1 ] ==DIGSIG_VERSION_2 ) {return verify_hash_v2 (file, hash, size, sig, siglen); }else if (sig[1 ] ==DIGSIG_VERSION_3 ) {
@@ -742,6 +749,7 @@ int ima_verify_signature(const char *file, unsigned char *sig, int siglen,return verify_hash (file, hash, hashlen, sig, siglen); } +#if CONFIG_SIGV1 /* * Create binary key representation suitable for kernel */
@@ -800,6 +808,7 @@ void calc_keyid_v1(uint8_t *keyid, char *str, const unsigned char *pkey, int lenif (imaevm_params.verbose >LOG_INFO ) log_info("keyid-v1: %s\n", str); } +#endif /* CONFIG_SIGV1 */ /* * Calculate keyid of the public_key part of EVP_PKEY
@@ -990,6 +999,7 @@ err_engine:return NULL ; } +#if CONFIG_SIGV1 static RSA *read_priv_key (const char *keyfile,const char *keypass) {EVP_PKEY *pkey;
@@ -1100,6 +1110,7 @@ out:RSA_free (key); return len; } +#endif /* CONFIG_SIGV1 */ /* * @sig is assumed to be of (MAX_SIGNATURE_SIZE - 1) size
@@ -1214,9 +1225,14 @@ int sign_hash(const char *hashalgo, const unsigned char *hash, int size, const cif (keypass) imaevm_params.keypass = keypass; -return imaevm_params.x509 ? -sign_hash_v2 (hashalgo, hash, size, keyfile, sig) : -sign_hash_v1 (hashalgo, hash, size, keyfile, sig); +if (imaevm_params.x509) +return sign_hash_v2 (hashalgo, hash, size, keyfile, sig); +#if CONFIG_SIGV1 + else + return sign_hash_v1(hashalgo, hash, size, keyfile, sig); +#endif +log_info ("Signature version 1 deprecated." ); +return -1 ; }static void libinit ()
tests/sign_verify.test +12 -6
@@ -17,6 +17,7 @@ cd "$(dirname "$0")" || exit 1 PATH=../src:$PATH +SIGV1=0 source ./functions.sh _require cmp evmctl getfattr openssl xxd
@@ -368,13 +369,18 @@ try_different_sigs() { ## Test v1 signatures # Signature v1 only supports sha1 and sha256 so any other should fail -expect_fail \ - check_sign TYPE=ima KEY=rsa1024 ALG=md5 PREFIX=0x0301 OPTS=--rsa +if [ $SIGV1 -eq 0 ]; then + __skip() { echo "IMA signature v1 tests are skipped: not supported"; return $SKIP; } + expect_pass __skip +else + expect_fail \ + check_sign TYPE=ima KEY=rsa1024 ALG=md5 PREFIX=0x0301 OPTS=--rsa -sign_verify rsa1024 sha1 0x0301 --rsa -sign_verify rsa1024 sha256 0x0301 --rsa - try_different_keys - try_different_sigs + sign_verify rsa1024 sha1 0x0301 --rsa + sign_verify rsa1024 sha256 0x0301 --rsa + try_different_keys + try_different_sigs +fi ## Test v2 signatures with RSA PKCS#1 # List of allowed hashes much greater but not all are supported.
Signature · 1 line
2.31.1
Re: [PATCH ima-evm-utils 04/11] Deprecate IMA signature version 1
Quoted 8 lines · Mimi Zohar
The original IMA file signatures were based on a SHA1 hash. Kernel support for other hash algorithms was subsequently upstreamed. Deprecate "--rsa" support.
Define "--enable-sigv1" option to configure signature v1 support.
Reviewed-by Petr Vorel <[email protected]>Signed-off-by Mimi Zohar <[email protected]>
Quoted 258 lines
--- configure.ac | 6 ++++++ src/Makefile.am | 10 ++++++++++ src/evmctl.c | 20 ++++++++++++++++---- src/libimaevm.c | 22 +++++++++++++++++++--- tests/sign_verify.test | 18 ++++++++++++------ 5 files changed, 63 insertions(+), 13 deletions(-)configure.ac +6
-0@@ -49,6 +49,11 @@ AC_ARG_ENABLE([openssl_conf], AC_DEFINE(DISABLE_OPENSSL_CONF, 1, [Define to disable loading of openssl config by evmctl.]) fi], [enable_openssl_conf=yes]) +AC_ARG_ENABLE(sigv1, + AS_HELP_STRING([--enable-sigv1], [Build ima-evm-utils with signature v1 support])) + AM_CONDITIONAL([CONFIG_SIGV1], [test "x$enable_sigv1" = "xyes"]) + AS_IF([test "$enable_sigv1" != "yes"], [enable_sigv1="no"]) + #debug support - yes for a while PKG_ARG_ENABLE(debug, "yes", DEBUG, [Enable Debug support]) if test $pkg_cv_enable_debug = yes; then@@ -83,5 +88,6 @@ echo " openssl-conf: $enable_openssl_conf" echo " tss2-esys: $ac_cv_lib_tss2_esys_Esys_Free" echo " tss2-rc-decode: $ac_cv_lib_tss2_rc_Tss2_RC_Decode" echo " ibmtss: $ac_cv_header_ibmtss_tss_h" +echo " sigv1: $enable_sigv1" echo " doc: $have_doc" echosrc/Makefile.am +10
-0@@ -7,6 +7,10 @@ libimaevm_la_CPPFLAGS = $(AM_CPPFLAGS) $(LIBCRYPTO_CFLAGS) libimaevm_la_LDFLAGS = -version-info 3:0:0 libimaevm_la_LIBADD = $(LIBCRYPTO_LIBS) +if CONFIG_SIGV1 +libimaevm_la_CFLAGS = -DCONFIG_SIGV1 +endif + include_HEADERS = imaevm.h nodist_libimaevm_la_SOURCES = hash_info.h@@ -22,6 +26,12 @@ evmctl_CPPFLAGS = $(AM_CPPFLAGS) $(LIBCRYPTO_CFLAGS) evmctl_LDFLAGS = $(LDFLAGS_READLINE) evmctl_LDADD = $(LIBCRYPTO_LIBS) -lkeyutils libimaevm.la +# Enable IMA signature version 1 +if CONFIG_SIGV1 +evmctl_CFLAGS = -DCONFIG_SIGV1 +endif + + # USE_PCRTSS uses the Intel TSS if USE_PCRTSS evmctl_SOURCES += pcr_tss.csrc/evmctl.c +16
-4@@ -987,7 +987,6 @@ static int cmd_verify_ima(struct command *cmd)init_public_keys ("/etc/keys/x509_evm.der" ); } - errno =0 ;if (!file) {log_err ("Parameters missing\n" );print_usage (cmd);@@ -1004,6 +1003,7 @@ static int cmd_verify_ima(struct command *cmd)return fails >0 ; } +#if CONFIG_SIGV1 static int cmd_convert (struct command *cmd) {char *inkey;@@ -1034,6 +1034,7 @@ static int cmd_convert(struct command *cmd)RSA_free (key); return err; } +#endif static int cmd_import (struct command *cmd) {@@ -1088,6 +1089,7 @@ static int cmd_import(struct command *cmd)calc_keyid_v2 ((uint32_t *)keyid, name, pkey);EVP_PKEY_free (pkey); }else { +#if CONFIG_SIGV1 RSA *key =read_pub_key (inkey, imaevm_params.x509);if (!key)@@ -1095,6 +1097,10 @@ static int cmd_import(struct command *cmd) len =key2bin (key, pub);calc_keyid_v1 (keyid, name, pub, len);RSA_free (key); +#else +log_info ("Importing public RSA key is not supported\n" ); +return 1 ; +#endif }log_info ("Importing public key %s from file %s into keyring %d\n" , name, inkey, id);@@ -2598,7 +2604,9 @@ static void usage(void) " -d, --imahash make IMA hash\n" " -f, --sigfile store IMA signature in .sig file instead of xattr\n" " --xattr-user store xattrs in user namespace (for testing purposes)\n" -" --rsa use RSA key type and signing scheme v1\n" +#if CONFIG_SIGV1 + " --rsa use RSA key type and signing scheme v1 (deprecated)\n" +#endif" -k, --key path to signing key (default: /etc/keys/{privkey,pubkey}_evm.pem)\n" " or a pkcs11 URI\n" " --keyid n overwrite signature keyid with a 32-bit value in hex (for signing)\n" @@ -2637,8 +2645,12 @@ static void usage(void)struct command cmds[] = { {"--version" ,NULL ,0 ,"" }, {"help" , cmd_help,0 ,"<command>" }, - {"import" , cmd_import,0 ,"[--rsa] pubkey keyring" ,"Import public key into the keyring.\n" }, - {"convert" , cmd_convert,0 ,"key" ,"convert public key into the keyring.\n" }, +#if CONFIG_SIGV1 + {"import" , cmd_import,0 ,"[--rsa] pubkey keyring" ,"Import public key into the keyring. ([--rsa] deprecated)\n" }, + {"convert" , cmd_convert,0 ,"key" ,"convert public key into the keyring. (deprecated)\n" }, +#else + {"import" , cmd_import,0 ,"pubkey keyring" ,"Import public key into the keyring.\n" }, +#endif {"sign" , cmd_sign_evm,0 ,"[-r] [--imahash | --imasig ] [--key key] [--pass [password] file" ,"Sign file metadata.\n" }, {"verify" , cmd_verify_evm,0 ,"file" ,"Verify EVM signature (for debugging).\n" }, {"ima_sign" , cmd_sign_ima,0 ,"[--sigfile] [--key key] [--pass [password] file" ,"Make file content signature.\n" },src/libimaevm.c +19
-3@@ -292,6 +292,7 @@ out:return pkey; } +#if CONFIG_SIGV1 RSA *read_pub_key (const char *keyfile,int x509) {EVP_PKEY *pkey;@@ -351,6 +352,7 @@ static int verify_hash_v1(const char *file, const unsigned char *hash, int size,return 0 ; } +#endif /* CONFIG_SIGV1 */ struct public_key_entry {struct public_key_entry *next;@@ -686,6 +688,7 @@ int verify_hash(const char *file, const unsigned char *hash, int size, {/* Get signature type from sig header */ if (sig[1 ] ==DIGSIG_VERSION_1 ) { +#if CONFIG_SIGV1 const char *key =NULL ;/* Read pubkey from RSA key */ @@ -695,6 +698,10 @@ int verify_hash(const char *file, const unsigned char *hash, int size, key = imaevm_params.keyfile;return verify_hash_v1 (file, hash, size, sig +1 , siglen -1 , key); +#else +log_info ("Signature version 1 deprecated." ); +return -1 ; +#endif }else if (sig[1 ] ==DIGSIG_VERSION_2 ) {return verify_hash_v2 (file, hash, size, sig, siglen); }else if (sig[1 ] ==DIGSIG_VERSION_3 ) {@@ -742,6 +749,7 @@ int ima_verify_signature(const char *file, unsigned char *sig, int siglen,return verify_hash (file, hash, hashlen, sig, siglen); } +#if CONFIG_SIGV1 /* * Create binary key representation suitable for kernel */ @@ -800,6 +808,7 @@ void calc_keyid_v1(uint8_t *keyid, char *str, const unsigned char *pkey, int lenif (imaevm_params.verbose >LOG_INFO ) log_info("keyid-v1: %s\n", str); } +#endif /* CONFIG_SIGV1 */ /* * Calculate keyid of the public_key part of EVP_PKEY @@ -990,6 +999,7 @@ err_engine:return NULL ; } +#if CONFIG_SIGV1 static RSA *read_priv_key (const char *keyfile,const char *keypass) {EVP_PKEY *pkey;@@ -1100,6 +1110,7 @@ out:RSA_free (key); return len; } +#endif /* CONFIG_SIGV1 */ /* * @sig is assumed to be of (MAX_SIGNATURE_SIZE - 1) size @@ -1214,9 +1225,14 @@ int sign_hash(const char *hashalgo, const unsigned char *hash, int size, const cif (keypass) imaevm_params.keypass = keypass; -return imaevm_params.x509 ? -sign_hash_v2 (hashalgo, hash, size, keyfile, sig) : -sign_hash_v1 (hashalgo, hash, size, keyfile, sig); +if (imaevm_params.x509) +return sign_hash_v2 (hashalgo, hash, size, keyfile, sig); +#if CONFIG_SIGV1 + else + return sign_hash_v1(hashalgo, hash, size, keyfile, sig); +#endif +log_info ("Signature version 1 deprecated." ); +return -1 ; }static void libinit ()tests/sign_verify.test +12
-6@@ -17,6 +17,7 @@ cd "$(dirname "$0")" || exit 1 PATH=../src:$PATH +SIGV1=0 source ./functions.sh _require cmp evmctl getfattr openssl xxd@@ -368,13 +369,18 @@ try_different_sigs() { ## Test v1 signatures # Signature v1 only supports sha1 and sha256 so any other should fail -expect_fail \ - check_sign TYPE=ima KEY=rsa1024 ALG=md5 PREFIX=0x0301 OPTS=--rsa +if [ $SIGV1 -eq 0 ]; then + __skip() { echo "IMA signature v1 tests are skipped: not supported"; return $SKIP; } + expect_pass __skip +else + expect_fail \ + check_sign TYPE=ima KEY=rsa1024 ALG=md5 PREFIX=0x0301 OPTS=--rsa -sign_verify rsa1024 sha1 0x0301 --rsa -sign_verify rsa1024 sha256 0x0301 --rsa - try_different_keys - try_different_sigs + sign_verify rsa1024 sha1 0x0301 --rsa + sign_verify rsa1024 sha256 0x0301 --rsa + try_different_keys + try_different_sigs +fi ## Test v2 signatures with RSA PKCS#1 # List of allowed hashes much greater but not all are supported.
Mimi Zohar
maintainerPATCH 5/11 Replace the low level SHA1 calls when calculating the TPM 1.2 PCRs
In reply to Mimi ZoharOpenSSL v3 emits deprecated warnings for SHA1 functions. Use the EVP_ functions when walking the TPM 1.2 binary bios measurements to calculate the TPM 1.2 PCRs.
--- src/evmctl.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 6 deletions(-)
src/evmctl.c +59 -6
@@ -2295,6 +2295,11 @@ static int cmd_ima_measurement(struct command *cmd)return ima_measurement (file); } +/* +* read_binary_bios_measurements - read the TPM 1.2 event log +* +* Returns 0 on success, 1 on failure. +*/ #define MAX_EVENT_DATA_SIZE 200000static int read_binary_bios_measurements (char *file,struct tpm_bank_info *bank) {
@@ -2307,12 +2312,19 @@ static int read_binary_bios_measurements(char *file, struct tpm_bank_info *bank) } header;unsigned char data[MAX_EVENT_DATA_SIZE ]; } event; +EVP_MD_CTX *mdctx; +const EVP_MD *md; +unsigned int mdlen; +int evp_err =1 ;/* success */ struct stat s;FILE *fp; -SHA_CTX c;int err =0 ;int len;int i; +#if OPENSSL_VERSION_NUMBER <0x10100000 +EVP_MD_CTX ctx; + mdctx = &ctx; +#endif if (stat (file, &s) ==-1 ) { errno =0 ;
@@ -2334,6 +2346,23 @@ static int read_binary_bios_measurements(char *file, struct tpm_bank_info *bank)if (imaevm_params.verbose >LOG_INFO )log_info ("Reading the TPM 1.2 event log %s.\n" , file); + md =EVP_get_digestbyname (bank->algo_name); +if (!md) { +log_errno ("Unknown message digest %s\n" , bank->algo_name); + errno =0 ; +fclose (fp); +return 1 ; + } + +#if OPENSSL_VERSION_NUMBER >=0x10100000 + mdctx =EVP_MD_CTX_new (); +if (!mdctx) { +log_err ("EVP_MD_CTX_new failed\n" ); +fclose (fp); +return 1 ; + } +#endif +/* Extend the pseudo TPM PCRs with the event digest */ while (fread (&event,sizeof (event.header),1 , fp) ==1 ) {if (imaevm_params.verbose >LOG_INFO ) {
@@ -2342,13 +2371,30 @@ static int read_binary_bios_measurements(char *file, struct tpm_bank_info *bank) }if (event.header.pcr >=NUM_PCRS ) {log_err ("Invalid PCR %d.\n" , event.header.pcr); - err =1 ;break ; } -SHA1_Init (&c); -SHA1_Update (&c, bank->pcr[event.header.pcr],20 ); -SHA1_Update (&c, event.header.digest,20 ); -SHA1_Final (bank->pcr[event.header.pcr], &c); + + evp_err =EVP_DigestInit (mdctx, md); +if (evp_err ==0 ) { +log_err ("EVP_DigestInit() failed\n" ); +break ; + } + + evp_err =EVP_DigestUpdate (mdctx, bank->pcr[event.header.pcr],20 ); +if (evp_err ==0 ) { +log_err ("EVP_DigestUpdate() failed\n" ); +break ; + } + evp_err =EVP_DigestUpdate (mdctx, event.header.digest,20 ); +if (evp_err ==0 ) { +log_err ("EVP_DigestUpdate() failed\n" ); +break ; + } + evp_err =EVP_DigestFinal (mdctx, bank->pcr[event.header.pcr], &mdlen); +if (evp_err ==0 ) { +log_err ("EVP_DigestFinal() failed\n" ); +break ; + }if (event.header.len >MAX_EVENT_DATA_SIZE ) {log_err ("Event data event too long.\n" ); err =1 ;
@@ -2357,10 +2403,17 @@ static int read_binary_bios_measurements(char *file, struct tpm_bank_info *bank) len =fread (event.data, event.header.len,1 , fp);if (len !=1 ) {log_errno ("Failed reading event data (short read)\n" ); + err =1 ;break ; } } + +if (evp_err ==0 )/* EVP_ functions return 1 on success, 0 on failure */ + err =1 ;fclose (fp); +#if OPENSSL_VERSION_NUMBER >=0x10100000 +EVP_MD_CTX_free (mdctx); +#endif if (imaevm_params.verbose <=LOG_INFO )return err;
Signature · 1 line
2.31.1
Re: [PATCH ima-evm-utils 05/11] Replace the low level SHA1 calls when calculating the TPM 1.2 PCRs
Quoted 115 lines · Mimi Zohar
OpenSSL v3 emits deprecated warnings for SHA1 functions. Use the
EVP_functions when walking the TPM 1.2 binary bios measurements to calculate the TPM 1.2 PCRs.Reviewed-by Petr Vorel <[email protected]>Signed-off-by Mimi Zohar <[email protected]>--- src/evmctl.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 6 deletions(-)src/evmctl.c +53
-6@@ -2295,6 +2295,11 @@ static int cmd_ima_measurement(struct command *cmd)return ima_measurement (file); } +/* +* read_binary_bios_measurements - read the TPM 1.2 event log +* +* Returns 0 on success, 1 on failure. +*/ #define MAX_EVENT_DATA_SIZE 200000static int read_binary_bios_measurements (char *file,struct tpm_bank_info *bank) {@@ -2307,12 +2312,19 @@ static int read_binary_bios_measurements(char *file, struct tpm_bank_info *bank) } header;unsigned char data[MAX_EVENT_DATA_SIZE ]; } event; +EVP_MD_CTX *mdctx; +const EVP_MD *md; +unsigned int mdlen; +int evp_err =1 ;/* success */ struct stat s;FILE *fp; -SHA_CTX c;int err =0 ;int len;int i; +#if OPENSSL_VERSION_NUMBER <0x10100000 +EVP_MD_CTX ctx; + mdctx = &ctx; +#endif if (stat (file, &s) ==-1 ) { errno =0 ;@@ -2334,6 +2346,23 @@ static int read_binary_bios_measurements(char *file, struct tpm_bank_info *bank)if (imaevm_params.verbose >LOG_INFO )log_info ("Reading the TPM 1.2 event log %s.\n" , file); + md =EVP_get_digestbyname (bank->algo_name); +if (!md) { +log_errno ("Unknown message digest %s\n" , bank->algo_name); + errno =0 ; +fclose (fp); +return 1 ; + } + +#if OPENSSL_VERSION_NUMBER >=0x10100000 + mdctx =EVP_MD_CTX_new (); +if (!mdctx) { +log_err ("EVP_MD_CTX_new failed\n" ); +fclose (fp); +return 1 ; + } +#endif +/* Extend the pseudo TPM PCRs with the event digest */ while (fread (&event,sizeof (event.header),1 , fp) ==1 ) {if (imaevm_params.verbose >LOG_INFO ) {@@ -2342,13 +2371,30 @@ static int read_binary_bios_measurements(char *file, struct tpm_bank_info *bank) }if (event.header.pcr >=NUM_PCRS ) {log_err ("Invalid PCR %d.\n" , event.header.pcr); - err =1 ;break ; } -SHA1_Init (&c); -SHA1_Update (&c, bank->pcr[event.header.pcr],20 ); -SHA1_Update (&c, event.header.digest,20 ); -SHA1_Final (bank->pcr[event.header.pcr], &c); + + evp_err =EVP_DigestInit (mdctx, md); +if (evp_err ==0 ) { +log_err ("EVP_DigestInit() failed\n" ); +break ; + } + + evp_err =EVP_DigestUpdate (mdctx, bank->pcr[event.header.pcr],20 ); +if (evp_err ==0 ) { +log_err ("EVP_DigestUpdate() failed\n" ); +break ; + } + evp_err =EVP_DigestUpdate (mdctx, event.header.digest,20 ); +if (evp_err ==0 ) { +log_err ("EVP_DigestUpdate() failed\n" ); +break ; + } + evp_err =EVP_DigestFinal (mdctx, bank->pcr[event.header.pcr], &mdlen); +if (evp_err ==0 ) { +log_err ("EVP_DigestFinal() failed\n" ); +break ; + }if (event.header.len >MAX_EVENT_DATA_SIZE ) {log_err ("Event data event too long.\n" ); err =1 ;@@ -2357,10 +2403,17 @@ static int read_binary_bios_measurements(char *file, struct tpm_bank_info *bank) len =fread (event.data, event.header.len,1 , fp);if (len !=1 ) {log_errno ("Failed reading event data (short read)\n" ); + err =1 ;break ; } }
src/evmctl.c static int read_binary_bios_measurements(char *file, struct tpm_bank_info *bank) · line 2419
Quoted 10 lines
src/evmctl.c +6
-0+ +if (evp_err ==0 )/* EVP_ functions return 1 on success, 0 on failure */ + err =1 ;fclose (fp); +#if OPENSSL_VERSION_NUMBER >=0x10100000 +EVP_MD_CTX_free (mdctx); +#endif if (imaevm_params.verbose <=LOG_INFO )return err;
Mimi Zohar
maintainerPATCH 6/11 Replace the low level HMAC calls when calculating the EVM HMAC
In reply to Mimi ZoharCalculating the EVM HMAC and labeling the filesystem was originally included in ima-evm-utils for debugging purposes only. For now, instead of removing EVM HMAC support just replace the low level HMAC_ calls with EVP_ calls.
The '-a, --hashalgo' specifies the IMA hash or signature algorithm. The kernel EVM HMAC is limited to SHA1. Fix ima-evm-utils by hard coding the EVM HMAC algorithm to SHA1.
--- src/evmctl.c | 57 +++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 25 deletions(-)
src/evmctl.c +32 -25
@@ -1159,12 +1159,12 @@ static int cmd_setxattr_ima(struct command *cmd)static int calc_evm_hmac (const char *file,const char *keyfile,unsigned char *hash) { -const EVP_MD *md; +size_t mdlen; +EVP_MD_CTX *pctx; +EVP_PKEY *pkey =NULL ;struct stat st;int err =-1 ;uint32_t generation =0 ; -HMAC_CTX *pctx; -unsigned int mdlen;char **xattrname;unsigned char xattr_value[1024 ];unsigned char *key;
@@ -1175,10 +1175,8 @@ static int calc_evm_hmac(const char *file, const char *keyfile, unsigned char *hstruct h_misc_64 hmac_misc;int hmac_size;#if OPENSSL_VERSION_NUMBER <0x10100000 -HMAC_CTX ctx; +EVP_MD_CTX ctx; pctx = &ctx; -#else - pctx =HMAC_CTX_new ();#endif key =file2bin (keyfile,NULL , &keylen);
@@ -1226,19 +1224,26 @@ static int calc_evm_hmac(const char *file, const char *keyfile, unsigned char *h goto out; } - md =EVP_get_digestbyname (imaevm_params.hash_algo); -if (!md) { -log_err ("EVP_get_digestbyname(%s) failed\n" , - imaevm_params.hash_algo); +#if OPENSSL_VERSION_NUMBER >=0x10100000 + pctx =EVP_MD_CTX_new (); +if (!pctx) { +log_err ("EVP_MD_CTX_new failed\n" ); goto out; } +#endif - err = !HMAC_Init_ex (pctx, evmkey,sizeof (evmkey), md,NULL ); -if (err) { + pkey =EVP_PKEY_new_mac_key (EVP_PKEY_HMAC ,NULL , evmkey,sizeof (evmkey)); +if (!pkey) {log_err ("HMAC_Init() failed\n" ); goto out; } + err =EVP_DigestSignInit (pctx,NULL ,EVP_sha1 (),NULL , pkey); +if (err !=1 ) { +log_err ("EVP_DigestSignInit() failed\n" ); + goto out; + } +for (xattrname = evm_config_xattrnames; *xattrname !=NULL ; xattrname++) { err =lgetxattr (file, *xattrname, xattr_value,sizeof (xattr_value));if (err <0 ) {
@@ -1249,12 +1254,12 @@ static int calc_evm_hmac(const char *file, const char *keyfile, unsigned char *hlog_info ("skipping xattr: %s\n" , *xattrname);continue ; } -/*log_debug("name: %s, value: %s, size: %d\n", *xattrname, xattr_value, err);*/ log_info ("name: %s, size: %d\n" , *xattrname, err);log_debug_dump (xattr_value, err); - err = !HMAC_Update (pctx, xattr_value, err); -if (err) { -log_err ("HMAC_Update() failed\n" ); + + err =EVP_DigestSignUpdate (pctx, xattr_value, err); +if (err !=1 ) { +log_err ("EVP_DigestSignUpdate() failed\n" ); goto out_ctx_cleanup; } }
@@ -1293,23 +1298,24 @@ static int calc_evm_hmac(const char *file, const char *keyfile, unsigned char *hlog_debug ("hmac_misc (%d): " , hmac_size);log_debug_dump (&hmac_misc, hmac_size); - err = !HMAC_Update (pctx, (const unsigned char *)&hmac_misc, hmac_size); -if (err) { + err =EVP_DigestSignUpdate (pctx, &hmac_misc, hmac_size); +if (err !=1 ) {log_err ("HMAC_Update() failed\n" ); goto out_ctx_cleanup; } - err = !HMAC_Final (pctx, hash, &mdlen); -if (err) + err =EVP_DigestSignFinal (pctx, hash, &mdlen); +if (err !=1 )log_err ("HMAC_Final() failed\n" ); out_ctx_cleanup: -#if OPENSSL_VERSION_NUMBER <0x10100000 -HMAC_CTX_cleanup (pctx); -#else -HMAC_CTX_free (pctx); +EVP_PKEY_free (pkey); +#if OPENSSL_VERSION_NUMBER >=0x10100000 +EVP_MD_CTX_free (pctx);#endif out:free (key); -return err ?: mdlen; +if (err ==1 ) +return mdlen; +return err; }static int hmac_evm (const char *file,const char *key)
@@ -1333,6 +1339,7 @@ static int hmac_evm(const char *file, const char *key) err =lsetxattr (file, xattr_evm, sig, len +1 ,0 );if (err <0 ) {log_err ("setxattr failed: %s\n" , file); + errno =0 ;return err; } }
Signature · 1 line
2.31.1
Mimi Zohar
maintainerPATCH 7/11 Add missing EVP_MD_CTX_free() call in calc_evm_hash()
In reply to Mimi ZoharWhen EVP_MD_CTX_new() call was added, the corresponding EVP_MD_CTX_free() was never called. Properly free it.
--- src/evmctl.c | 57 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 17 deletions(-)
src/evmctl.c +40 -17
@@ -331,11 +331,17 @@ err:return -1 ; } +/* +* calc_evm_hash - calculate the file metadata hash +* +* Returns 0 for EVP_ function failures. Return -1 for other failures. +* Return hash algorithm size on success. +*/ static int calc_evm_hash (const char *file,unsigned char *hash) {const EVP_MD *md;struct stat st; -int err; +int err =-1 ;uint32_t generation =0 ;EVP_MD_CTX *pctx;unsigned int mdlen;
@@ -349,12 +355,11 @@ static int calc_evm_hash(const char *file, unsigned char *hash)#if OPENSSL_VERSION_NUMBER <0x10100000 EVP_MD_CTX ctx; pctx = &ctx; -#else - pctx =EVP_MD_CTX_new ();#endif if (lstat (file, &st)) {log_err ("Failed to stat: %s\n" , file); + errno =0 ;return -1 ; }
@@ -391,20 +396,30 @@ static int calc_evm_hash(const char *file, unsigned char *hash) list_size =llistxattr (file, list,sizeof (list));if (list_size <0 ) {log_err ("llistxattr() failed\n" ); + errno =0 ;return -1 ; } +#if OPENSSL_VERSION_NUMBER >=0x10100000 + pctx =EVP_MD_CTX_new (); +if (!pctx) { +log_err ("EVP_MD_CTX_new() failed\n" ); +return 0 ; + } +#endif + md =EVP_get_digestbyname (imaevm_params.hash_algo);if (!md) {log_err ("EVP_get_digestbyname(%s) failed\n" , imaevm_params.hash_algo); -return 1 ; + err =0 ; + goto out; } err =EVP_DigestInit (pctx, md);if (!err) {log_err ("EVP_DigestInit() failed\n" ); -return 1 ; + goto out; }for (xattrname = evm_config_xattrnames; *xattrname !=NULL ; xattrname++) {
@@ -415,7 +430,8 @@ static int calc_evm_hash(const char *file, unsigned char *hash)if (err >sizeof (xattr_value)) {log_err ("selinux[%u] value is too long to fit into xattr[%zu]\n" , err,sizeof (xattr_value)); -return -1 ; + err =-1 ; + goto out; }strcpy (xattr_value, selinux_str); }else if (!strcmp (*xattrname,XATTR_NAME_IMA ) && ima_str) {
@@ -423,7 +439,8 @@ static int calc_evm_hash(const char *file, unsigned char *hash)if (err >sizeof (xattr_value)) {log_err ("ima[%u] value is too long to fit into xattr[%zu]\n" , err,sizeof (xattr_value)); -return -1 ; + err =-1 ; + goto out; }hex2bin (xattr_value, ima_str, err); }else if (!strcmp (*xattrname,XATTR_NAME_IMA ) && evm_portable){
@@ -432,7 +449,7 @@ static int calc_evm_hash(const char *file, unsigned char *hash)if (err <0 ) {log_err ("EVM portable sig: %s required\n" , xattr_ima); -return -1 ; + goto out; } use_xattr_ima =1 ; }else if (!strcmp (*xattrname,XATTR_NAME_CAPS ) && (hmac_flags &HMAC_FLAG_CAPS_SET )) {
@@ -442,7 +459,8 @@ static int calc_evm_hash(const char *file, unsigned char *hash)if (err >=sizeof (xattr_value)) {log_err ("caps[%u] value is too long to fit into xattr[%zu]\n" , err +1 ,sizeof (xattr_value)); -return -1 ; + err =-1 ; + goto out; }strcpy (xattr_value, caps_str); }else {
@@ -463,7 +481,7 @@ static int calc_evm_hash(const char *file, unsigned char *hash) err =EVP_DigestUpdate (pctx, xattr_value, err);if (!err) {log_err ("EVP_DigestUpdate() failed\n" ); -return 1 ; + goto out; } }
@@ -517,29 +535,33 @@ static int calc_evm_hash(const char *file, unsigned char *hash) err =EVP_DigestUpdate (pctx, &hmac_misc, hmac_size);if (!err) {log_err ("EVP_DigestUpdate() failed\n" ); -return 1 ; + goto out; }if (!evm_immutable && !evm_portable && !(hmac_flags &HMAC_FLAG_NO_UUID )) { err =get_uuid (&st, uuid);if (err) -return -1 ; + goto out; err =EVP_DigestUpdate (pctx, (const unsigned char *)uuid,sizeof (uuid));if (!err) {log_err ("EVP_DigestUpdate() failed\n" ); -return 1 ; + goto out; } } err =EVP_DigestFinal (pctx, hash, &mdlen); -if (!err) { +if (!err)log_err ("EVP_DigestFinal() failed\n" ); -return 1 ; - } -return mdlen; +out: +#if OPENSSL_VERSION_NUMBER >=0x10100000 +EVP_MD_CTX_free (pctx); +#endif +if (err ==1 ) +return mdlen; +return err; }static int sign_evm (const char *file,const char *key)
@@ -575,6 +597,7 @@ static int sign_evm(const char *file, const char *key) err =lsetxattr (file, xattr_evm, sig, len,0 );if (err <0 ) {log_err ("setxattr failed: %s\n" , file); + errno =0 ;return err; } }
Signature · 1 line
2.31.1
Mimi Zohar
maintainerPATCH 8/11 Deprecate use of OpenSSL v3 "engine" support
In reply to Mimi ZoharOpenSSL v3 "engine" support is deprecated and replaced with "providers". Engine support will continue to work for a while, but results in deprecated declaration and other messages. One option is simply to hide them ("-Wno-deprecated-declarations"). The other alternative is to conditionally build ima-evm-utils without OpenSSL v3 engine support and without disabling deprecated declarations.
Based on "--disable-engine" or "--enable-engine=no" configuration option, disable OpenSSL v3 "engine" support.
When ima-evm-utils engine support is disabled, don't execute the tests requiring it.
--- configure.ac | 13 +++++++++++++ src/Makefile.am | 8 ++++++++ src/evmctl.c | 17 ++++++++++++++++- src/imaevm.h | 2 ++ src/libimaevm.c | 5 +++++ tests/functions.sh | 14 +++++++++++++- tests/ima_hash.test | 9 +++++++++ tests/sign_verify.test | 10 ++++++++++ 8 files changed, 76 insertions(+), 2 deletions(-)
configure.ac +13 -0
@@ -54,6 +54,17 @@ AC_ARG_ENABLE(sigv1, AM_CONDITIONAL([CONFIG_SIGV1], [test "x$enable_sigv1" = "xyes"]) AS_IF([test "$enable_sigv1" != "yes"], [enable_sigv1="no"]) +AC_ARG_ENABLE(engine, + [AS_HELP_STRING([--disable-engine], [build ima-evm-utils without OpenSSL v3 engine support])]) + +ssl_version=$(openssl version | sed -e 's/^OpenSSL //' | sed -e 's/ .*//') +if test "${ssl_version::1}" != "3"; then + enable_engine="yes" +elif test -z "$enable_engine"; then + enable_engine="yes" +fi +AM_CONDITIONAL([CONFIG_ENGINE], [test "x$enable_engine" = "xyes"]) + #debug support - yes for a while PKG_ARG_ENABLE(debug, "yes", DEBUG, [Enable Debug support]) if test $pkg_cv_enable_debug = yes; then
@@ -89,5 +100,7 @@ echo " tss2-esys: $ac_cv_lib_tss2_esys_Esys_Free" echo " tss2-rc-decode: $ac_cv_lib_tss2_rc_Tss2_RC_Decode" echo " ibmtss: $ac_cv_header_ibmtss_tss_h" echo " sigv1: $enable_sigv1" +echo " engine: $enable_engine" +echo " ssl: $ssl_version" echo " doc: $have_doc" echo
src/Makefile.am +8 -0
@@ -11,6 +11,10 @@ if CONFIG_SIGV1 libimaevm_la_CFLAGS = -DCONFIG_SIGV1 endif +if CONFIG_ENGINE +libimaevm_la_CFLAGS = -DCONFIG_ENGINE +endif + include_HEADERS = imaevm.h nodist_libimaevm_la_SOURCES = hash_info.h
@@ -31,6 +35,10 @@ if CONFIG_SIGV1 evmctl_CFLAGS = -DCONFIG_SIGV1 endif +# Enable "--engine" support +if CONFIG_ENGINE +evmctl_CFLAGS = -DCONFIG_ENGINE +endif # USE_PCRTSS uses the Intel TSS if USE_PCRTSS
src/evmctl.c +16 -1
@@ -64,7 +64,9 @@#include <openssl/hmac.h> #include <openssl/err.h> #include <openssl/rsa.h> +#if CONFIG_ENGINE #include <openssl/engine.h> +#endif #include <openssl/x509v3.h> #include "hash_info.h" #include "pcr.h"
@@ -2715,7 +2717,9 @@ static void usage(void) " --selinux use custom Selinux label for EVM\n" " --caps use custom Capabilities for EVM(unspecified: from FS, empty: do not use)\n" " --verify-sig verify measurement list signatures\n" -" --engine e preload OpenSSL engine e (such as: gost)\n" +#if CONFIG_ENGINE + " --engine e preload OpenSSL engine e (such as: gost) is deprecated\n" +#endif" --ignore-violations ignore ToMToU measurement violations\n" " -v increase verbosity level\n" " -h, --help display this help and exit\n"
@@ -2777,7 +2781,9 @@ static struct option opts[] = { {"selinux", 1, 0, 136}, {"caps", 2, 0, 137}, {"verify-sig", 0, 0, 138}, +#if CONFIG_ENGINE {"engine", 1, 0, 139}, +#endif {"xattr-user", 0, 0, 140}, {"ignore-violations", 0, 0, 141}, {"pcrs", 1, 0, 142},
@@ -2830,9 +2836,11 @@ static char *get_password(void)return password; } +#if CONFIG_ENGINE static ENGINE *setup_engine (const char *engine_id) {ENGINE *eng =ENGINE_by_id (engine_id); +if (!eng) {log_err ("engine %s isn't available\n" , optarg);ERR_print_errors_fp (stderr);
@@ -2846,6 +2854,7 @@ static ENGINE *setup_engine(const char *engine_id)ENGINE_set_default (eng,ENGINE_METHOD_ALL ); return eng; } +#endif int main (int argc,char *argv[]) {
@@ -2971,11 +2980,13 @@ int main(int argc, char *argv[])case 138 : verify_list_sig =1 ;break ; +#if CONFIG_ENGINE case 139 :/* --engine e */ imaevm_params.eng =setup_engine (optarg);if (!imaevm_params.eng) goto error;break ; +#endif case 140 :/* --xattr-user */ xattr_ima ="user.ima" ; xattr_evm ="user.evm" ;
@@ -3034,7 +3045,9 @@ int main(int argc, char *argv[])if (imaevm_params.keyfile !=NULL && imaevm_params.eng ==NULL && !strncmp (imaevm_params.keyfile,"pkcs11:" ,7 )) { +#if CONFIG_ENGINE imaevm_params.eng =setup_engine ("pkcs11" ); +#endif if (!imaevm_params.eng) goto error; }
@@ -3060,6 +3073,7 @@ int main(int argc, char *argv[]) } error: +#if CONFIG_ENGINE if (imaevm_params.eng) {ENGINE_finish (imaevm_params.eng);ENGINE_free (imaevm_params.eng);
@@ -3067,6 +3081,7 @@ error:ENGINE_cleanup (); #endif } +#endif ERR_free_strings ();EVP_cleanup ();BIO_free (NULL );
src/imaevm.h +2 -0
@@ -48,7 +48,9 @@#include <errno.h> #include <sys/types.h> #include <openssl/rsa.h> +#ifdef CONFIG_ENGINE #include <openssl/engine.h> +#endif #ifdef USE_FPRINTF #define do_log(level, fmt, args...) \
src/libimaevm.c +5 -0
@@ -959,6 +959,7 @@ static EVP_PKEY *read_priv_pkey(const char *keyfile, const char *keypass)EVP_PKEY *pkey;if (!strncmp (keyfile,"pkcs11:" ,7 )) { +#ifdef CONFIG_ENGINE if (!imaevm_params.keyid) {log_err ("When using a pkcs11 URI you must provide the keyid with an option\n" );return NULL ;
@@ -975,6 +976,10 @@ static EVP_PKEY *read_priv_pkey(const char *keyfile, const char *keypass)log_err ("Failed to load private key %s\n" , keyfile); goto err_engine; } +#else +log_err ("OpenSSL 3 \"engine\" support is deprecated\n" ); + goto err_engine; +#endif }else { fp =fopen (keyfile,"r" );if (!fp) {
tests/functions.sh +13 -1
@@ -312,4 +312,16 @@ _softhsm_teardown() { rm -rf "${SOFTHSM_SETUP_CONFIGDIR}" unset SOFTHSM_SETUP_CONFIGDIR SOFTHSM2_CONF PKCS11_KEYURI \ EVMCTL_ENGINE OPENSSL_ENGINE OPENSSL_KEYFORM -} +} + +# OpenSSL 3 engine support still works, but is deprecated. In preparation +# for it being removed, a new ima-evm-utils configuration option +# "--disable-engine" and the equivalent "--enable-engine=no" is defined.` +_is_engine_supported() { + cmd="evmctl --engine pkcs11" + $cmd &>/dev/null + if [ $? -eq 1 ]; then + return 0 + fi + return 1 +}
tests/ima_hash.test +9 -0
@@ -71,6 +71,15 @@ expect_pass check sha384 0x0405 38b060a751ac96384cd9327eb1b1e36a21fdb71114b expect_pass check sha512 0x0406 cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e expect_pass check rmd160 0x0403 9c1185a5c5e9fc54612808977ee8f548b2258d31 expect_pass check sm3 0x0411 1ab21d8355cfa17f8e61194831e81a8f22bec8c728fefb747ed035eb5082aa2b + +# Remaining tests require engine support +_is_engine_supported +if [ $? -eq 0 ]; then + __skip() { echo "Tests requiring engine support are skipped (not supported)"; return $SKIP; } + expect_pass __skip + exit 0 +fi + _enable_gost_engine expect_pass check md_gost12_256 0x0412 3f539a213e97c802cc229d474c6aa32a825a360b2a933a949fd925208d9ce1bb expect_pass check streebog256 0x0412 3f539a213e97c802cc229d474c6aa32a825a360b2a933a949fd925208d9ce1bb
tests/sign_verify.test +10 -0
@@ -18,6 +18,8 @@ cd "$(dirname "$0")" || exit 1 PATH=../src:$PATH SIGV1=0 +ENGINE_SUPPORTED=0 + source ./functions.sh _require cmp evmctl getfattr openssl xxd
@@ -418,6 +420,14 @@ if [ -x /opt/openssl3/bin/openssl ]; then sign_verify sm2 sm3 0x030211:K:004[345678] fi +# Remaining tests require engine support +_is_engine_supported +if [ $? -eq 0 ]; then + __skip() { echo "Tests requiring engine support are skipped (not supported)"; return $SKIP; } + expect_pass __skip + exit 0 +fi + # Test v2 signatures with EC-RDSA _enable_gost_engine sign_verify gost2012_256-A md_gost12_256 0x030212:K:0040
Signature · 1 line
2.31.1
Re: [PATCH ima-evm-utils 08/11] Deprecate use of OpenSSL v3 "engine" support
Mimi,
Quoted 30 lines · Mimi Zohar
OpenSSL v3 "engine" support is deprecated and replaced with "providers". Engine support will continue to work for a while, but results in deprecated declaration and other messages. One option is simply to hide them ("-Wno-deprecated-declarations"). The other alternative is to conditionally build ima-evm-utils without OpenSSL v3 engine support and without disabling deprecated declarations.
Based on "--disable-engine" or "--enable-engine=no" configuration option, disable OpenSSL v3 "engine" support.
When ima-evm-utils engine support is disabled, don't execute the tests requiring it.
Signed-off-by Mimi Zohar <[email protected]>--- configure.ac | 13 +++++++++++++ src/Makefile.am | 8 ++++++++ src/evmctl.c | 17 ++++++++++++++++- src/imaevm.h | 2 ++ src/libimaevm.c | 5 +++++ tests/functions.sh | 14 +++++++++++++- tests/ima_hash.test | 9 +++++++++ tests/sign_verify.test | 10 ++++++++++ 8 files changed, 76 insertions(+), 2 deletions(-)configure.ac +0
-0
configure.ac AC_ARG_ENABLE(sigv1, · line 57
Quoted 4 lines
configure.ac +1
-0@@ -54,6 +54,17 @@ AC_ARG_ENABLE(sigv1, AM_CONDITIONAL([CONFIG_SIGV1], [test "x$enable_sigv1" = "xyes"]) AS_IF([test "$enable_sigv1" != "yes"], [enable_sigv1="no"]) +AC_ARG_ENABLE(engine,
Thanks.
BTW, if we now have handling of disabled engine -- OpenSSL have defines OPENSSL_NO_ENGINE and OPENSSL_NO_DYNAMIC_ENGINE -- I think if any of them is defined we could disable engine support automatically.
(Just a thought: In general, I would prefer if we rely on what is configured in OpenSSL (whatever is enabled or disabled), and not complicate things for user with post-decision of what is allowed for us from OpenSSL. But of course opinions are different.)
configure.ac AC_ARG_ENABLE(sigv1, · line 58
Quoted 1 line
configure.ac +1
-0+ [AS_HELP_STRING([--disable-engine], [build ima-evm-utils without OpenSSL v3 engine support])])
I think "v3" could be removed since it exists in v1 too.
Quoted 13 lines
src/libimaevm.c +1
-0@@ -959,6 +959,7 @@ static EVP_PKEY *read_priv_pkey(const char *keyfile, const char *keypass)EVP_PKEY *pkey;if (!strncmp (keyfile,"pkcs11:" ,7 )) { +#ifdef CONFIG_ENGINE if (!imaevm_params.keyid) {log_err ("When using a pkcs11 URI you must provide the keyid with an option\n" );return NULL ;
src/libimaevm.c static EVP_PKEY *read_priv_pkey(const char *keyfile, const char *keypass) · line 980
Quoted 5 lines
src/libimaevm.c +2
-0@@ -975,6 +976,10 @@ static EVP_PKEY *read_priv_pkey(const char *keyfile, const char *keypass)log_err ("Failed to load private key %s\n" , keyfile); goto err_engine; } +#else +log_err ("OpenSSL 3 \"engine\" support is deprecated\n" );
And here too "3" could be removed. And perhaps "is disabled" since this is not just a deprecation warning, but an error.
Thanks,
Mimi Zohar
maintainerRe: [PATCH ima-evm-utils 08/11] Deprecate use of OpenSSL v3 "engine" support
Hi Vitaly,
Quoted 34 lines · Vitaly Chikunov
Quoted 33 lines · Mimi Zohar
OpenSSL v3 "engine" support is deprecated and replaced with "providers". Engine support will continue to work for a while, but results in deprecated declaration and other messages. One option is simply to hide them ("-Wno-deprecated-declarations"). The other alternative is to conditionally build ima-evm-utils without OpenSSL v3 engine support and without disabling deprecated declarations.
Based on "--disable-engine" or "--enable-engine=no" configuration option, disable OpenSSL v3 "engine" support.
When ima-evm-utils engine support is disabled, don't execute the tests requiring it.
Signed-off-by Mimi Zohar <[email protected]>--- configure.ac | 13 +++++++++++++ src/Makefile.am | 8 ++++++++ src/evmctl.c | 17 ++++++++++++++++- src/imaevm.h | 2 ++ src/libimaevm.c | 5 +++++ tests/functions.sh | 14 +++++++++++++- tests/ima_hash.test | 9 +++++++++ tests/sign_verify.test | 10 ++++++++++ 8 files changed, 76 insertions(+), 2 deletions(-)configure.ac +0
-0@@ -54,6 +54,17 @@ AC_ARG_ENABLE(sigv1, AM_CONDITIONAL([CONFIG_SIGV1], [test "x$enable_sigv1" = "xyes"]) AS_IF([test "$enable_sigv1" != "yes"], [enable_sigv1="no"])
Quoted 7 lines
configure.ac AC_ARG_ENABLE(sigv1, · line 57
Quoted 1 line
configure.ac +1
-0+AC_ARG_ENABLE(engine,Thanks.
BTW, if we now have handling of disabled engine -- OpenSSL have defines
OPENSSL_NO_ENGINEandOPENSSL_NO_DYNAMIC_ENGINE-- I think if any of them is defined we could disable engine support automatically.
Ok
Quoted 5 lines
(Just a thought: In general, I would prefer if we rely on what is configured in OpenSSL (whatever is enabled or disabled), and not complicate things for user with post-decision of what is allowed for us from OpenSSL. But of course opinions are different.)
Sorry, but at leat for my testing purposes, being able to disable ima- evm-utils OpenSSL engine support without recompiling other packages is a requirement.
Quoted 3 lines
configure.ac AC_ARG_ENABLE(sigv1, · line 58
Quoted 1 line
configure.ac +1
-0+ [AS_HELP_STRING([--disable-engine], [build ima-evm-utils without OpenSSL v3 engine support])])I think "v3" could be removed since it exists in v1 too.
configure.ac currently still limits disabling OpenSSL engine support to v3, but that could be removed.
Quoted 8 lines
Quoted 8 lines
src/libimaevm.c +0
-0@@ -959,6 +959,7 @@ static EVP_PKEY *read_priv_pkey(const char *keyfile, const char *keypass)EVP_PKEY *pkey;
Quoted 14 lines
src/libimaevm.c static EVP_PKEY *read_priv_pkey(const char *keyfile, const char *keypass) · line 980
Quoted 11 lines
src/libimaevm.c +3
-0if (!strncmp (keyfile,"pkcs11:" ,7 )) { +#ifdef CONFIG_ENGINE if (!imaevm_params.keyid) {log_err ("When using a pkcs11 URI you must provide the keyid with an option\n" );return NULL ;@@ -975,6 +976,10 @@ static EVP_PKEY *read_priv_pkey(const char *keyfile, const char *keypass)log_err ("Failed to load private key %s\n" , keyfile); goto err_engine; } +#else +log_err ("OpenSSL 3 \"engine\" support is deprecated\n" );And here too "3" could be removed. And perhaps "is disabled" since this is not just a deprecation warning, but an error.
Sure.
Mimi Zohar
maintainerPATCH 9/11 Fix potential use after free in read_tpm_banks()
In reply to Mimi ZoharOn failure to read TPM 2.0 bank PCRs 'errmsg' is not properly set to NULL after being freed. Fix potential use after free.
--- src/evmctl.c | 1 + 1 file changed, 1 insertion(+)
src/evmctl.c +1 -0
@@ -2075,6 +2075,7 @@ static int read_tpm_banks(int num_banks, struct tpm_bank_info *bank)log_debug ("Failed to read %s PCRs: (%s)\n" , bank[i].algo_name, errmsg);free (errmsg); + errmsg =NULL ; bank[i].supported =0 ; } }
Signature · 1 line
2.31.1
Mimi Zohar
maintainerPATCH 10/11 Limit the file hash algorithm name length
In reply to Mimi ZoharInstead of assuming the file hash algorithm is a properly NULL terminated string, properly limit the "algo:<hash>" field size.
--- src/evmctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/evmctl.c +1 -1
@@ -1602,7 +1602,7 @@ void ima_ng_show(struct template_entry *entry) total_len -=sizeof (field_len); algo = (char *)fieldp; - len =strlen (algo) +1 ; + len =strnlen (algo, field_len -1 ) +1 ; digest_len = field_len - len; digest = fieldp + len;
Signature · 1 line
2.31.1
Mimi Zohar
maintainerPATCH 11/11 Missing template data size lower bounds checking
In reply to Mimi ZoharEach record in the IMA measurement list must contain some template data. Ensure the template data is not zero length.
--- src/evmctl.c | 4 ++++ 1 file changed, 4 insertions(+)
src/evmctl.c +4 -0
@@ -2188,6 +2188,10 @@ static int ima_measurement(const char *file)log_err ("Unable to read template length\n" ); goto out; } +if (entry.template_len ==0 ) { +log_err ("Invalid template data len\n" ); + goto out; + } }else { entry.template_len =SHA_DIGEST_LENGTH +TCG_EVENT_NAME_LEN_MAX +1 ;
Signature · 1 line
2.31.1