mirror of
				https://git.code.sf.net/p/linux-ima/ima-evm-utils
				synced 2025-11-04 06:40:49 +01:00 
			
		
		
		
	Merge branch 'default-hash-algo' into next
Due to SHA1 weaknesses, define a configuration option to set the default hash algorithm. The set of permitted hash algorithms is defined in the hash_info.h header file. At the same time, change the default hash algorithm from SHA1 to SHA256.
This commit is contained in:
		
							
								
								
									
										2
									
								
								README
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								README
									
									
									
									
									
								
							@@ -41,7 +41,7 @@ COMMANDS
 | 
			
		||||
OPTIONS
 | 
			
		||||
-------
 | 
			
		||||
 | 
			
		||||
  -a, --hashalgo     sha1 (default), sha224, sha256, sha384, sha512
 | 
			
		||||
  -a, --hashalgo     sha1, sha224, sha256, sha384, sha512
 | 
			
		||||
  -s, --imasig       make IMA signature
 | 
			
		||||
  -d, --imahash      make IMA hash
 | 
			
		||||
  -f, --sigfile      store IMA signature in .sig file instead of xattr
 | 
			
		||||
 
 | 
			
		||||
@@ -62,6 +62,7 @@ else
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
EVMCTL_MANPAGE_DOCBOOK_XSL
 | 
			
		||||
AX_DEFAULT_HASH_ALGO([$KERNEL_HEADERS])
 | 
			
		||||
 | 
			
		||||
# for gcov
 | 
			
		||||
#CFLAGS="$CFLAGS -Wall -fprofile-arcs -ftest-coverage"
 | 
			
		||||
@@ -81,6 +82,7 @@ echo
 | 
			
		||||
echo
 | 
			
		||||
echo	"Configuration:"
 | 
			
		||||
echo	"          debug: $pkg_cv_enable_debug"
 | 
			
		||||
echo	"   default-hash: $HASH_ALGO"
 | 
			
		||||
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"
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										36
									
								
								m4/default-hash-algo.m4
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								m4/default-hash-algo.m4
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
dnl Copyright (c) 2021 Bruno Meneguele <bmeneg@redhat.com>
 | 
			
		||||
dnl Check hash algorithm availability in the kernel
 | 
			
		||||
dnl
 | 
			
		||||
dnl $1 - $KERNEL_HEADERS
 | 
			
		||||
 | 
			
		||||
AC_DEFUN([AX_DEFAULT_HASH_ALGO], [
 | 
			
		||||
	HASH_INFO_HEADER="$1/include/uapi/linux/hash_info.h"
 | 
			
		||||
 | 
			
		||||
	AC_ARG_WITH([default_hash],
 | 
			
		||||
		AS_HELP_STRING([--with-default-hash=ALGORITHM], [specifies the default hash algorithm to be used]),
 | 
			
		||||
		[HASH_ALGO=$withval],
 | 
			
		||||
		[HASH_ALGO=sha256])
 | 
			
		||||
 | 
			
		||||
	AC_PROG_SED()
 | 
			
		||||
	HASH_ALGO="$(echo $HASH_ALGO | $SED 's/\(.*\)/\L\1\E/')"
 | 
			
		||||
 | 
			
		||||
	AC_CHECK_HEADER([$HASH_INFO_HEADER],
 | 
			
		||||
		[HAVE_HASH_INFO_HEADER=yes],
 | 
			
		||||
		[AC_MSG_WARN([$HASH_INFO_HEADER not found.])])
 | 
			
		||||
 | 
			
		||||
	if test "x$HAVE_HASH_INFO_HEADER" = "x"; then
 | 
			
		||||
		AC_MSG_RESULT([using $HASH_ALGO algorithm as default hash algorith])
 | 
			
		||||
		AC_DEFINE_UNQUOTED(DEFAULT_HASH_ALGO, "$HASH_ALGO", [Define default hash algorithm])
 | 
			
		||||
	else
 | 
			
		||||
		AC_PROG_GREP()
 | 
			
		||||
		$SED -n 's/HASH_ALGO_\(.*\),/\L\1\E/p' $HASH_INFO_HEADER | $GREP -w $HASH_ALGO > /dev/null
 | 
			
		||||
		have_hash=$?
 | 
			
		||||
 | 
			
		||||
		if test $have_hash -ne 0; then
 | 
			
		||||
			AC_MSG_ERROR([$HASH_ALGO algorithm specified, but not provided by the kernel], 1)
 | 
			
		||||
		else
 | 
			
		||||
			AC_MSG_NOTICE([using $HASH_ALGO as default hash algorithm])
 | 
			
		||||
			AC_DEFINE_UNQUOTED(DEFAULT_HASH_ALGO, "$HASH_ALGO", [Define default hash algorithm])
 | 
			
		||||
		fi
 | 
			
		||||
	fi
 | 
			
		||||
])
 | 
			
		||||
@@ -2500,7 +2500,7 @@ static void usage(void)
 | 
			
		||||
 | 
			
		||||
	printf(
 | 
			
		||||
		"\n"
 | 
			
		||||
		"  -a, --hashalgo     sha1 (default), sha224, sha256, sha384, sha512, streebog256, streebog512\n"
 | 
			
		||||
		"  -a, --hashalgo     sha1, sha224, sha256, sha384, sha512, streebog256, streebog512 (default: %s)\n"
 | 
			
		||||
		"  -s, --imasig       make IMA signature\n"
 | 
			
		||||
		"  -d, --imahash      make IMA hash\n"
 | 
			
		||||
		"  -f, --sigfile      store IMA signature in .sig file instead of xattr\n"
 | 
			
		||||
@@ -2538,7 +2538,7 @@ static void usage(void)
 | 
			
		||||
		"\n"
 | 
			
		||||
		"Environment variables:\n\n"
 | 
			
		||||
		"EVMCTL_KEY_PASSWORD  : Private key password to use; do not use --pass option\n"
 | 
			
		||||
		"\n");
 | 
			
		||||
		"\n", DEFAULT_HASH_ALGO);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct command cmds[] = {
 | 
			
		||||
 
 | 
			
		||||
@@ -75,6 +75,10 @@
 | 
			
		||||
#define log_err(fmt, args...)		do_log(LOG_ERR, fmt, ##args)
 | 
			
		||||
#define log_errno(fmt, args...)		do_log(LOG_ERR, fmt ": errno: %s (%d)\n", ##args, strerror(errno), errno)
 | 
			
		||||
 | 
			
		||||
#ifndef DEFAULT_HASH_ALGO
 | 
			
		||||
#define DEFAULT_HASH_ALGO "sha256"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define	DATA_SIZE	4096
 | 
			
		||||
#define SHA1_HASH_LEN   20
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -89,7 +89,7 @@ static const char *const pkey_hash_algo_kern[PKEY_HASH__LAST] = {
 | 
			
		||||
struct libimaevm_params imaevm_params = {
 | 
			
		||||
	.verbose = LOG_INFO,
 | 
			
		||||
	.x509 = 1,
 | 
			
		||||
	.hash_algo = "sha1",
 | 
			
		||||
	.hash_algo = DEFAULT_HASH_ALGO,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void __attribute__ ((constructor)) libinit(void);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user