Skip to content

Commit 0cd21b5

Browse files
authored
Merge pull request #409 from aidangarske/keygen_opKeyAuth
Keygen Optional Authentication Password -auth=<yourpassword>
2 parents 122885a + 8e03c40 commit 0cd21b5

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

examples/keygen/keygen.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
static void usage(void)
4444
{
4545
printf("Expected usage:\n");
46-
printf("./examples/keygen/keygen [keyblob.bin] [-ecc/-rsa/-sym] [-t] [-aes/xor] [-eh] [-pem]\n");
46+
printf("./examples/keygen/keygen [keyblob.bin] [-ecc/-rsa/-sym] [-t] [-aes/xor] [-eh] [-pem] [-auth=pass]\n");
4747
printf("* -pem: Store the primary and child public keys as PEM formatted files\n");
4848
printf("\t child public key filename: ak.pem or key.pem\n");
4949
printf("\t primary public key filename: ek.pem or srk.pem\n");
@@ -57,6 +57,8 @@ static void usage(void)
5757
printf("* -aes/xor: Use Parameter Encryption\n");
5858
printf("* -unique=[value]\n");
5959
printf("\t* Used for the KDF of the create\n");
60+
printf("* -auth=pass: Use custom password for key authentication\n");
61+
printf("\t* If not specified, default key auth is used\n");
6062

6163
printf("Example usage:\n");
6264
printf("\t* RSA, default template\n");
@@ -118,6 +120,7 @@ int TPM2_Keygen_Example(void* userCtx, int argc, char *argv[])
118120
int bAIK = 1;
119121
int keyBits = 256;
120122
const char* uniqueStr = NULL;
123+
const char* authStr = NULL;
121124
const char *outputFile = "keyblob.bin";
122125
const char *ekPubFile = "ek.pub";
123126
const char *srkPubFile = "srk.pub";
@@ -176,6 +179,9 @@ int TPM2_Keygen_Example(void* userCtx, int argc, char *argv[])
176179
else if (XSTRNCMP(argv[argc-1], "-unique=", XSTRLEN("-unique=")) == 0) {
177180
uniqueStr = argv[argc-1] + XSTRLEN("-unique=");
178181
}
182+
else if (XSTRNCMP(argv[argc-1], "-auth=", XSTRLEN("-auth=")) == 0) {
183+
authStr = argv[argc-1] + XSTRLEN("-auth=");
184+
}
179185
else if (argv[argc-1][0] != '-') {
180186
outputFile = argv[argc-1];
181187
}
@@ -292,9 +298,15 @@ int TPM2_Keygen_Example(void* userCtx, int argc, char *argv[])
292298
if (rc != 0) goto exit;
293299

294300
/* set session for authorization key */
295-
auth.size = (int)sizeof(gAiKeyAuth)-1;
296-
XMEMCPY(auth.buffer, gAiKeyAuth, auth.size);
297-
301+
if (authStr != NULL) {
302+
/* Use provided custom auth */
303+
auth.size = (int)XSTRLEN(authStr);
304+
XMEMCPY(auth.buffer, authStr, auth.size);
305+
}
306+
else {
307+
auth.size = (int)sizeof(gAiKeyAuth)-1;
308+
XMEMCPY(auth.buffer, gAiKeyAuth, auth.size);
309+
}
298310
}
299311
else {
300312
if (alg == TPM_ALG_RSA) {
@@ -326,8 +338,15 @@ int TPM2_Keygen_Example(void* userCtx, int argc, char *argv[])
326338
}
327339

328340
/* set session for authorization key */
329-
auth.size = (int)sizeof(gKeyAuth)-1;
330-
XMEMCPY(auth.buffer, gKeyAuth, auth.size);
341+
if (authStr != NULL) {
342+
/* Use provided custom auth key */
343+
auth.size = (int)XSTRLEN(authStr);
344+
XMEMCPY(auth.buffer, authStr, auth.size);
345+
}
346+
else {
347+
auth.size = (int)sizeof(gKeyAuth)-1;
348+
XMEMCPY(auth.buffer, gKeyAuth, auth.size);
349+
}
331350
}
332351
if (rc != 0) goto exit;
333352

examples/run_examples.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ if [ $WOLFCRYPT_ENABLE -eq 1 ]; then
251251
./examples/keygen/keyload ecckeyblobeh.bin -ecc -eh >> $TPMPWD/run.out 2>&1
252252
RESULT=$?
253253
[ $RESULT -ne 0 ] && echo -e "keyload endorsement ecc failed! $RESULT" && exit 1
254+
255+
# TODO: Add tests for -auth= keygen when used in example
254256
fi
255257

256258

0 commit comments

Comments
 (0)