Blame SOURCES/0001-tpm2_create-Use-better-object-attributes-defaults-fo.patch

a41b42
From 1a541fbef647cd495e1c9fb9667d0f0525ff5fd7 Mon Sep 17 00:00:00 2001
a41b42
From: Javier Martinez Canillas <javierm@redhat.com>
a41b42
Date: Mon, 30 Jul 2018 11:40:19 +0200
a41b42
Subject: [PATCH] tpm2_create: Use better object attributes defaults for
a41b42
 authentication
a41b42
a41b42
The tpm2_create tool allows to define a policy session or a password for
a41b42
authentication. By default no policy session is used and the password is
a41b42
empty, which means that this empty password is used for authentication.
a41b42
a41b42
So the default object attribute flag userWithAuth is set in order to use
a41b42
the empty password. This isn't a good default though if a policy is set,
a41b42
since in this case the policy session has to be used for authentication
a41b42
instead of an empty password.
a41b42
a41b42
If a policy is defined, the userWithAuth bit has to be clear unless the
a41b42
user defines a password so in that case authentication would happen only
a41b42
using the policy session or the defined password.
a41b42
a41b42
Also add these cases in the integration test to detect regressions.
a41b42
a41b42
Fixes: #1123
a41b42
a41b42
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
a41b42
---
a41b42
 test/system/test_tpm2_unseal.sh | 51 +++++++++++++++++++++++++++++++++
a41b42
 tools/tpm2_create.c             |  4 +++
a41b42
 2 files changed, 55 insertions(+)
a41b42
a41b42
diff --git a/test/system/test_tpm2_unseal.sh b/test/system/test_tpm2_unseal.sh
a41b42
index 1015a43..abfffce 100755
a41b42
--- a/test/system/test_tpm2_unseal.sh
a41b42
+++ b/test/system/test_tpm2_unseal.sh
a41b42
@@ -109,4 +109,55 @@ unsealed=`tpm2_unseal -c $file_unseal_key_ctx -L ${alg_pcr_policy}:${pcr_ids} -F
a41b42
 
a41b42
 test "$unsealed" == "$secret"
a41b42
 
a41b42
+# Test that unseal fails if a PCR policy isn't provided
a41b42
+
a41b42
+trap - ERR
a41b42
+
a41b42
+tpm2_unseal -c $file_unseal_key_ctx 2> /dev/null
a41b42
+if [ $? != 1 ]; then
a41b42
+  echo "tpm2_unseal didn't fail without a PCR policy!"
a41b42
+  exit 1
a41b42
+fi
a41b42
+
a41b42
+# Test that unseal fails if PCR state isn't the same as the defined PCR policy
a41b42
+
a41b42
+pcr_extend=$(echo $pcr_ids | cut -d ',' -f1)
a41b42
+
a41b42
+tpm2_pcrextend $pcr_extend:sha1=6c10289a8da7f774cf67bd2fc8502cd4b585346a
a41b42
+
a41b42
+tpm2_unseal -c $file_unseal_key_ctx -L ${alg_pcr_policy}:${pcr_ids} -F $file_pcr_value 2> /dev/null
a41b42
+if [ $? != 1 ]; then
a41b42
+  echo "tpm2_unseal didn't fail with a PCR state different than the policy!"
a41b42
+  exit 1
a41b42
+fi
a41b42
+
a41b42
+# Test that the object can be unsealed without a policy but a password
a41b42
+
a41b42
+trap onerror ERR
a41b42
+
a41b42
+rm $file_unseal_key_pub $file_unseal_key_priv $file_unseal_key_name
a41b42
+
a41b42
+tpm2_pcrlist -Q -L ${alg_pcr_policy}:${pcr_ids} -o $file_pcr_value
a41b42
+
a41b42
+tpm2_createpolicy -Q -P -L ${alg_pcr_policy}:${pcr_ids} -F $file_pcr_value -f $file_policy
a41b42
+
a41b42
+tpm2_create -Q -g $alg_create_obj -G $alg_create_key -u $file_unseal_key_pub -r $file_unseal_key_priv -I- -c $file_primary_key_ctx -L $file_policy -K secretpass\
a41b42
+  -A 'sign|fixedtpm|fixedparent|sensitivedataorigin' <<< $secret
a41b42
+
a41b42
+tpm2_load -Q -c $file_primary_key_ctx  -u $file_unseal_key_pub  -r $file_unseal_key_priv -n $file_unseal_key_name -C $file_unseal_key_ctx
a41b42
+
a41b42
+unsealed=`tpm2_unseal -c $file_unseal_key_ctx -P secretpass`
a41b42
+
a41b42
+test "$unsealed" == "$secret"
a41b42
+
a41b42
+# Test that unseal fails when using a wrong password
a41b42
+
a41b42
+trap - ERR
a41b42
+
a41b42
+tpm2_unseal -c $file_unseal_key_ctx -P wrongpass 2> /dev/null
a41b42
+if [ $? != 1 ]; then
a41b42
+  echo "tpm2_unseal didn't fail when using a wrong object password!"
a41b42
+  exit 1
a41b42
+fi
a41b42
+
a41b42
 exit 0
a41b42
diff --git a/tools/tpm2_create.c b/tools/tpm2_create.c
a41b42
index 41d7b42..15166fc 100644
a41b42
--- a/tools/tpm2_create.c
a41b42
+++ b/tools/tpm2_create.c
a41b42
@@ -256,6 +256,7 @@ static bool on_option(char key, char *value) {
a41b42
             return false;
a41b42
         }
a41b42
         ctx.flags.K = 1;
a41b42
+        ctx.in_public.t.publicArea.objectAttributes.userWithAuth = 1;
a41b42
         break;
a41b42
     case 'g':
a41b42
         ctx.nameAlg = tpm2_alg_util_from_optarg(value);
a41b42
@@ -294,6 +295,9 @@ static bool on_option(char key, char *value) {
a41b42
             return false;
a41b42
         }
a41b42
         ctx.flags.L = 1;
a41b42
+        if (!ctx.flags.K) {
a41b42
+             ctx.in_public.t.publicArea.objectAttributes.userWithAuth = 0;
a41b42
+        }
a41b42
         break;
a41b42
     case 'S':
a41b42
         if (!tpm2_util_string_to_uint32(value, &ctx.session_data.sessionHandle)) {
a41b42
-- 
a41b42
2.17.0
a41b42