Skip to content

Commit aace02e

Browse files
JuergenReppSITAndreasFuchsTPM
authored andcommitted
tpm2_createak: add attribute option.
The default attributes for the ak are: "restricted|userwithauth|sign|fixedtpm|fixedparent|sensitivedataorigin" This default setting differs from the settings in the specification TPM 2.0 Keys for Device Identity and Attestation. "adminwithpolicy" is not set. Thus the option -a, --attributes is added. Addresses: #3225 Signed-off-by: Juergen Repp <juergen_repp@web.de>
1 parent bc4cf8b commit aace02e

3 files changed

Lines changed: 37 additions & 4 deletions

File tree

man/tpm2_createak.1.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ loaded-key:
4848
* **rsa** - An RSA2048 key.
4949
* **keyedhash** - hmac key.
5050

51+
* **-a**, **\--attributes**=_ATTRIBUTES_:
52+
53+
The object attributes, optional. The default for created objects is:
54+
"restricted|userwithauth|sign|fixedtpm|fixedparent|sensitivedataorigin"
55+
This default setting differs from the settings in the specification
56+
TPM 2.0 Keys for Device Identity and Attestation. "adminwithpolicy" is
57+
not set and can be added to the default:
58+
"restricted|userwithauth|...|adminwithpolicy"
59+
5160
* **-g**, **\--hash-algorithm**=_ALGORITHM_:
5261

5362
Specifies the digest algorithm used for signing.

test/integration/tests/createak.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
source helpers.sh
44

55
cleanup() {
6-
rm -f ek.pub ak.pub ak.name ak.name ak.log
6+
rm -f ek.pub ak.pub ak.name ak.name ak.log ek.ctx
77

88
# Evict persistent handles, we want them to always succeed and never trip
99
# the onerror trap.
@@ -26,7 +26,7 @@ cleanup "no-shut-down"
2626
tpm2 createek -Q -c 0x8101000b -G rsa -u ek.pub
2727

2828
tpm2 createak -Q -C 0x8101000b -c ak.ctx -G rsa -g sha256 -s rsassa -u ak.pub \
29-
-n ak.name -q ak.qname
29+
-n ak.name -q ak.qname
3030

3131
# Validate the qname
3232
tpm2 readpublic -c ak.ctx -q ak.qname2
@@ -45,4 +45,13 @@ tpm2 changeauth -c e endauth
4545
tpm2 createek -Q -P endauth -c 0x8101000b -G rsa -u ek.pub
4646
tpm2 createak -Q -P endauth -C 0x8101000b -c ak.ctx -G rsa -u ak.pub -n ak.name
4747

48+
# Check attributes different from default
49+
tpm2 createak -Q -Q -P endauth -C 0x8101000b -c ak.ctx -u ak.pub -n ak.name \
50+
-a "restricted|userwithauth|sign|fixedtpm|fixedparent|sensitivedataorigin|adminwithpolicy"
51+
52+
# Check whether non default attribute was set
53+
tpm2 readpublic -c ak.ctx | grep adminwithpolicy
54+
55+
56+
4857
exit 0

tools/tpm2_createak.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "tpm2_auth_util.h"
1313
#include "tpm2_convert.h"
1414
#include "tpm2_tool.h"
15+
#include "tpm2_attr_util.h"
1516

1617
#define ATTRS \
1718
TPMA_OBJECT_RESTRICTED|TPMA_OBJECT_USERWITHAUTH| \
@@ -108,6 +109,7 @@ struct createak_context {
108109
const char *qname_file;
109110
} out;
110111
char *auth_str;
112+
char *attrs;
111113
} ak;
112114
struct {
113115
UINT8 f :1;
@@ -136,6 +138,7 @@ static tool_rc init_ak_public(TPMI_ALG_HASH name_alg, TPM2B_PUBLIC *public) {
136138

137139
const char *name_halg;
138140
char alg[256];
141+
TPMA_OBJECT attrs;
139142

140143
name_halg = tpm2_alg_util_algtostr(name_alg, tpm2_alg_util_flags_hash);
141144

@@ -159,7 +162,15 @@ static tool_rc init_ak_public(TPMI_ALG_HASH name_alg, TPM2B_PUBLIC *public) {
159162
snprintf(alg, sizeof(alg), "%s:%s-%s:null", ctx.ak.in.alg.type,
160163
ctx.ak.in.alg.sign, ctx.ak.in.alg.digest);
161164
}
162-
return tpm2_alg_util_public_init(alg, name_halg, NULL, NULL, ATTRS, public);
165+
if (ctx.ak.attrs) {
166+
if (!tpm2_attr_util_obj_from_optarg(ctx.ak.attrs, &attrs)) {
167+
LOG_ERR("Invalid attributes.");
168+
return tool_rc_general_error;
169+
}
170+
} else {
171+
attrs = ATTRS;
172+
}
173+
return tpm2_alg_util_public_init(alg, name_halg, NULL, NULL, attrs, public);
163174
}
164175

165176
static tool_rc create_ak(ESYS_CONTEXT *ectx) {
@@ -464,6 +475,9 @@ static bool on_option(char key, char *value) {
464475
case 'R':
465476
ctx.autoflush = true;
466477
break;
478+
case 'a':
479+
ctx.ak.attrs = value;
480+
break;
467481
}
468482

469483
return true;
@@ -479,6 +493,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
479493
{ "ak-name", required_argument, NULL, 'n' },
480494
{ "key-algorithm", required_argument, NULL, 'G' },
481495
{ "hash-algorithm", required_argument, NULL, 'g' },
496+
{ "attributes", required_argument, NULL, 'a' },
482497
{ "signing-algorithm", required_argument, NULL, 's' },
483498
{ "format", required_argument, NULL, 'f' },
484499
{ "public", required_argument, NULL, 'u' },
@@ -487,7 +502,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
487502
{ "autoflush", no_argument, NULL, 'R' },
488503
};
489504

490-
*opts = tpm2_options_new("P:p:C:c:n:G:g:s:f:u:r:q:R", ARRAY_LEN(topts), topts,
505+
*opts = tpm2_options_new("P:p:C:c:n:G:a:g:s:f:u:r:q:R", ARRAY_LEN(topts), topts,
491506
on_option, NULL, 0);
492507

493508
return *opts != NULL;

0 commit comments

Comments
 (0)