common/encrypt: move constant test key to common code
authorEric Biggers <ebiggers@google.com>
Mon, 3 Feb 2020 18:18:54 +0000 (10:18 -0800)
committerEryu Guan <guaneryu@gmail.com>
Mon, 17 Feb 2020 13:04:52 +0000 (21:04 +0800)
For some encryption tests it's helpful to always use the same key so
that the test's output is always the same.

generic/580 already defines such a key, so move it into common/encrypt
so that other tests can use it too.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
common/encrypt
tests/generic/580

index 2e9908adf1cbbf0e900068b6551e926d2c2e2ee4..98a407ce31f42728b13999b1b2b17879bb74d8fa 100644 (file)
@@ -187,6 +187,17 @@ _scratch_mkfs_stable_inodes_encrypted()
        esac
 }
 
+# For some tests it's helpful to always use the same key so that the test's
+# output is always the same.  For this purpose the following key can be used:
+TEST_RAW_KEY=
+for i in {1..64}; do
+       TEST_RAW_KEY+="\\x$(printf "%02x" $i)"
+done
+# Key descriptor: arbitrary value
+TEST_KEY_DESCRIPTOR="0000111122223333"
+# Key identifier: HKDF-SHA512(key=$TEST_RAW_KEY, salt="", info="fscrypt\0\x01")
+TEST_KEY_IDENTIFIER="69b2f6edeee720cce0577937eb8a6751"
+
 # Give the invoking shell a new session keyring.  This makes any keys we add to
 # the session keyring scoped to the lifetime of the test script.
 _new_session_keyring()
index d0b0e9b3182f69c1bd5fd923149923678d0eb6ef..283d6efa4e673d2c85e6099935a14953bef85e1a 100755 (executable)
@@ -43,21 +43,12 @@ _scratch_mount
 test_with_policy_version()
 {
        local vers=$1
-       local raw_key=""
-       local i
-
-       for i in {1..64}; do
-               raw_key+="\\x$(printf "%02x" $i)"
-       done
 
        if (( vers == 1 )); then
-               # Key descriptor: arbitrary value
-               local keyspec="0000111122223333"
+               local keyspec=$TEST_KEY_DESCRIPTOR
                local add_enckey_args="-d $keyspec"
        else
-               # Key identifier:
-               # HKDF-SHA512(key=raw_key, salt="", info="fscrypt\0\x01")
-               local keyspec="69b2f6edeee720cce0577937eb8a6751"
+               local keyspec=$TEST_KEY_IDENTIFIER
                local add_enckey_args=""
        fi
 
@@ -75,7 +66,7 @@ test_with_policy_version()
        echo "# Getting encryption key status"
        _enckey_status $SCRATCH_MNT $keyspec
        echo "# Adding encryption key"
-       _add_enckey $SCRATCH_MNT "$raw_key" $add_enckey_args
+       _add_enckey $SCRATCH_MNT "$TEST_RAW_KEY" $add_enckey_args
        echo "# Creating encrypted file"
        echo contents > $dir/file
        echo "# Getting encryption key status"
@@ -90,7 +81,7 @@ test_with_policy_version()
 
        # Test removing key with a file open.
        echo "# Re-adding encryption key"
-       _add_enckey $SCRATCH_MNT "$raw_key" $add_enckey_args
+       _add_enckey $SCRATCH_MNT "$TEST_RAW_KEY" $add_enckey_args
        echo "# Creating another encrypted file"
        echo foo > $dir/file2
        echo "# Removing key while an encrypted file is open"