aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Bottomley <James.Bottomley@HansenPartnership.com>2021-04-11 14:44:30 -0700
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2021-04-11 14:49:05 -0700
commite41ef43db37e730e129f4d53238ad77a6248e629 (patch)
treeb262da839fae7f7467e00324f76d05ffe5e28ed1
parenta0b0a5cf6ea9fb0ac356f8564f8417f491f62b8c (diff)
downloadopenssl_tpm2_engine-e41ef43db37e730e129f4d53238ad77a6248e629.tar.gz
seal_unseal: add --pcr-lock for easy policy
Just as with create_tpm2_key add the --pcr-lock policy to specify the PCRs to seal to at their current values. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
-rw-r--r--seal_tpm2_data.1.in14
-rw-r--r--seal_tpm2_data.c47
-rwxr-xr-xtests/seal_unseal.sh18
3 files changed, 72 insertions, 7 deletions
diff --git a/seal_tpm2_data.1.in b/seal_tpm2_data.1.in
index b88510a..48c008e 100644
--- a/seal_tpm2_data.1.in
+++ b/seal_tpm2_data.1.in
@@ -7,6 +7,20 @@ Used to create a sealed blob of data which can be unsealed via the
TPM. Possible uses for this blob of data include as a symmetric key,
which is the use in the linux kernel trusted key infrastructure.
+[PCR Values]
+
+The PCR values are specified as
+
+ <bank>:<list>
+
+Where <bank> is any supported PCR hash bank and list specifies the
+PCRs to lock the key to as both comma separated individual values as
+well as comma separated ranges. So
+
+ sha256:1,3 means PCRs 1 and 3 in the sha256 bank
+
+ sha512:1,3-5 means PCRs 1,3,4 and 5 in the sha512 bank
+
[examples]
Create a sealed data blob to the storage parent (owner hierarchy)
diff --git a/seal_tpm2_data.c b/seal_tpm2_data.c
index 9017c12..877eac0 100644
--- a/seal_tpm2_data.c
+++ b/seal_tpm2_data.c
@@ -27,6 +27,7 @@ static struct option long_options[] = {
{"auth-parent", 1, 0, 'b'},
{"help", 0, 0, 'h'},
{"parent-handle", 1, 0, 'p'},
+ {"pcr-lock", 1, 0, 'x'},
{"version", 0, 0, 'v'},
{"password", 1, 0, 'k'},
{"da", 0, 0, 'd'},
@@ -71,6 +72,10 @@ usage(char *argv0)
"\t-m,--nomigrate Create a sealed data bundle that can be\n"
" migrated to other systems.\n"
"\t-n, --name-scheme <scheme> name algorithm to use sha1 [sha256] sha384 sha512\n"
+ "\t-x, --pcr-lock <pcrs> Lock the created key to the specified PCRs\n"
+ " By current value. See PCR VALUES for\n"
+ " details about formatting\n"
+ "\n"
"\n"
"Report bugs to " PACKAGE_BUGREPORT "\n",
argv0);
@@ -106,6 +111,10 @@ int main(int argc, char **argv)
int32_t size;
uint16_t pubkey_len, privkey_len;
char *parent_str = NULL;
+ TPML_PCR_SELECTION pcr_lock;
+ int has_policy = 0;
+
+ pcr_lock.count = 0;
while (1) {
option_index = 0;
@@ -165,6 +174,9 @@ int main(int argc, char **argv)
case 'm':
nomigrate = 1;
break;
+ case 'x':
+ tpm2_get_pcr_lock(&pcr_lock, optarg);
+ break;
default:
printf("Unknown option '%c'\n", c);
usage(argv[0]);
@@ -183,22 +195,32 @@ int main(int argc, char **argv)
usage(argv[0]);
}
+ if (pcr_lock.count !=0 && policyFilename) {
+ fprintf(stderr, "cannot specify both policy file and pcr lock\n");
+ exit(1);
+ }
+
+ if (pcr_lock.count != 0 || policyFilename)
+ has_policy = 1;
+
digest.hashAlg = name_alg;
sizeInBytes = TSS_GetDigestSize(digest.hashAlg);
memset((uint8_t *)&digest.digest, 0, sizeInBytes);
- if (policyFilename) {
+ if (has_policy) {
sk = sk_TSSOPTPOLICY_new_null();
if (!sk) {
fprintf(stderr, "Failed to allocate policy stack\n");
exit(1);
}
- rc = tpm2_parse_policy_file(policyFilename, sk,
- data_auth, &digest);
- if (rc) {
- reason = "parse_policy_file";
- goto out_free_policy;
+ if (policyFilename) {
+ rc = tpm2_parse_policy_file(policyFilename, sk,
+ data_auth, &digest);
+ if (rc) {
+ reason = "parse_policy_file";
+ goto out_free_policy;
+ }
}
}
@@ -215,6 +237,8 @@ int main(int argc, char **argv)
goto out_free_auth;
}
}
+ if (has_policy && !policyFilename)
+ tpm2_add_auth_policy(sk, &digest);
}
dir = tpm2_set_unique_tssdir();
@@ -224,6 +248,15 @@ int main(int argc, char **argv)
goto out_rmdir;
}
+ if (pcr_lock.count != 0) {
+ rc = tpm2_pcr_lock_policy(tssContext, &pcr_lock,
+ sk, &digest);
+ if (rc) {
+ reason = "create pcr policy";
+ goto out_free_auth;
+ }
+ }
+
if (parent_str) {
parent = tpm2_get_parent(tssContext, parent_str);
if (parent == 0) {
@@ -245,7 +278,7 @@ int main(int argc, char **argv)
tpm2_public_template_seal(p);
- if (policyFilename) {
+ if (has_policy) {
VAL(p->objectAttributes) &=
~TPMA_OBJECT_USERWITHAUTH;
rc = TSS_TPM2B_Create(
diff --git a/tests/seal_unseal.sh b/tests/seal_unseal.sh
index b1df920..37b077e 100755
--- a/tests/seal_unseal.sh
+++ b/tests/seal_unseal.sh
@@ -16,4 +16,22 @@ ${bindir}/unseal_tpm2_data key.tpm 2> /dev/null && exit 1;
echo $DATA | ${bindir}/seal_tpm2_data -a -k ${AUTH} seal.tpm || exit 1;
${bindir}/unseal_tpm2_data -k ${AUTH} seal.tpm | grep -q "${DATA}" || exit 1;
+##
+# Check with policy
+# test is
+# 1. seal with a pcr lock and no auth
+# 2. verify unseal
+# 3. move PCR on and verify no unseal
+# 4. 1-3 with auth and pcr lock
+##
+echo $DATA | ${bindir}/seal_tpm2_data --pcr-lock 2,16 seal.tpm || exit 1;
+${bindir}/unseal_tpm2_data seal.tpm | grep -q "${DATA}" || exit 1;
+tsspcrextend -ha 16 -ic $RANDOM
+${bindir}/unseal_tpm2_data seal.tpm && exit 1
+echo $DATA | ${bindir}/seal_tpm2_data -a -k ${AUTH} --pcr-lock 2,16 seal.tpm || exit 1;
+${bindir}/unseal_tpm2_data -k ${AUTH} seal.tpm | grep -q "${DATA}" || exit 1;
+tsspcrextend -ha 16 -ic $RANDOM
+${bindir}/unseal_tpm2_data -k ${AUTH} seal.tpm && exit 1
+
+
exit 0