[LTP] [PATCH ltp v4 2/3] IMA: Move ima_check to ima_setup.sh
Alex Henrie
alexh@vpitech.com
Tue Sep 21 02:41:39 CEST 2021
Signed-off-by: Alex Henrie <alexh@vpitech.com>
---
.../integrity/ima/tests/ima_measurements.sh | 28 -------------------
.../security/integrity/ima/tests/ima_setup.sh | 28 +++++++++++++++++++
2 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_measurements.sh b/testcases/kernel/security/integrity/ima/tests/ima_measurements.sh
index 1927e937c..807c5f57b 100755
--- a/testcases/kernel/security/integrity/ima/tests/ima_measurements.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_measurements.sh
@@ -17,38 +17,10 @@ setup()
{
require_ima_policy_cmdline "tcb"
- TEST_FILE="$PWD/test.txt"
POLICY="$IMA_DIR/policy"
[ -f "$POLICY" ] || tst_res TINFO "not using default policy"
}
-ima_check()
-{
- local algorithm digest expected_digest line tmp
-
- # need to read file to get updated $ASCII_MEASUREMENTS
- cat $TEST_FILE > /dev/null
-
- line="$(grep $TEST_FILE $ASCII_MEASUREMENTS | tail -1)"
-
- if tmp=$(get_algorithm_digest "$line"); then
- algorithm=$(echo "$tmp" | cut -d'|' -f1)
- digest=$(echo "$tmp" | cut -d'|' -f2)
- else
- tst_res TBROK "failed to get algorithm/digest for '$TEST_FILE': $tmp"
- fi
-
- tst_res TINFO "computing digest for $algorithm algorithm"
- expected_digest="$(compute_digest $algorithm $TEST_FILE)" || \
- tst_brk TCONF "cannot compute digest for $algorithm algorithm"
-
- if [ "$digest" = "$expected_digest" ]; then
- tst_res TPASS "correct digest found"
- else
- tst_res TFAIL "digest not found"
- fi
-}
-
check_iversion_support()
{
local device mount fs
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
index 9c25d634d..976c6a86c 100644
--- a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
@@ -188,6 +188,7 @@ ima_setup()
if [ "$TST_NEEDS_DEVICE" = 1 ]; then
tst_res TINFO "\$TMPDIR is on tmpfs => run on loop device"
mount_loop_device
+ TEST_FILE="$PWD/test.txt"
fi
[ -n "$TST_SETUP_CALLER" ] && $TST_SETUP_CALLER
@@ -279,6 +280,33 @@ get_algorithm_digest()
echo "$algorithm|$digest"
}
+ima_check()
+{
+ local algorithm digest expected_digest line tmp
+
+ # need to read file to get updated $ASCII_MEASUREMENTS
+ cat $TEST_FILE > /dev/null
+
+ line="$(grep $TEST_FILE $ASCII_MEASUREMENTS | tail -1)"
+
+ if tmp=$(get_algorithm_digest "$line"); then
+ algorithm=$(echo "$tmp" | cut -d'|' -f1)
+ digest=$(echo "$tmp" | cut -d'|' -f2)
+ else
+ tst_res TBROK "failed to get algorithm/digest for '$TEST_FILE': $tmp"
+ fi
+
+ tst_res TINFO "computing digest for $algorithm algorithm"
+ expected_digest="$(compute_digest $algorithm $TEST_FILE)" || \
+ tst_brk TCONF "cannot compute digest for $algorithm algorithm"
+
+ if [ "$digest" = "$expected_digest" ]; then
+ tst_res TPASS "correct digest found"
+ else
+ tst_res TFAIL "digest not found"
+ fi
+}
+
# check_evmctl REQUIRED_TPM_VERSION
# return: 0: evmctl is new enough, 1: version older than required (or version < v0.9)
check_evmctl()
--
2.33.0
More information about the ltp
mailing list