@@ -21,33 +21,6 @@ setup()
[ -f "$IMA_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
@@ -83,7 +56,7 @@ test1()
{
tst_res TINFO "verify adding record to the IMA measurement list"
ROD echo "$(date) this is a test file" \> $TEST_FILE
- ima_check
+ ima_check $TEST_FILE
}
test2()
@@ -92,7 +65,7 @@ test2()
tst_res TINFO "verify updating record in the IMA measurement list"
check_iversion_support || return
ROD echo "$(date) modified file" \> $TEST_FILE
- ima_check
+ ima_check $TEST_FILE
}
test3()
@@ -279,6 +279,34 @@ get_algorithm_digest()
echo "$algorithm|$digest"
}
+ima_check()
+{
+ local test_file="$1"
+ 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()