Skip to content

Commit 7ccca1a

Browse files
committed
Added -K argument for the user supplied password ThisIsMyKeyAuth
1 parent 540fe01 commit 7ccca1a

5 files changed

Lines changed: 35 additions & 44 deletions

File tree

README.md

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -574,22 +574,8 @@ server:
574574

575575
$ ./examples/echoserver/echoserver
576576

577-
From another terminal run the client with the keyblob. You must specify which
578-
key type to use:
579-
580-
Using primary endorsement key (recommened)
581-
$ ./examples/client/client -i ../wolfTPM/keyblob.bin -u hansel -s pk
582-
583-
Using storage root key
584-
$ ./examples/client/client -i ../wolfTPM/keyblob.bin -u hansel -s srk
585-
586-
For debuging run server like above then:
587-
588-
$ <lldb, gdb, etc.> ./examples/client/client
589-
590-
Set break point or just run:
591-
592-
$ r -i ../wolfTPM/keyblob.bin -u hansel
577+
From another terminal run the client with the keyblob. Using primary endorsement key
578+
$ ./examples/client/client -i ../wolfTPM/keyblob.bin -u hansel -K <keyAuth>
593579

594580
WOLFSSH APPLICATIONS
595581
====================

configure.ac

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,6 @@ AS_IF([test "x$ENABLED_SSHCLIENT" = "xyes"],
237237
[AM_CPPFLAGS="$AM_CPPFLAGS -DWOLFSSH_SSHCLIENT"])
238238
AS_IF([test "x$ENABLED_TPM" = "xyes"],
239239
[AM_CPPFLAGS="$AM_CPPFLAGS -DWOLFSSH_TPM"])
240-
AS_IF([test "x$ENABLED_SMALLSTACK" = "xyes"],
241-
[AM_CPPFLAGS="$AM_CPPFLAGS -DWOLFSSH_SMALL_STACK"])
242240

243241
if test "$ENABLED_SSHD" = "yes"; then
244242
if test -n "$PAM_LIB"

examples/client/client.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ static void ShowUsage(void)
9393
printf(" -p <num> port to connect on, default %d\n", wolfSshPort);
9494
printf(" -u <username> username to authenticate as (REQUIRED)\n");
9595
printf(" -P <password> password for username, prompted if omitted\n");
96+
#ifdef WOLFSSH_TPM
97+
printf(" -K <password> TPM key authentication password\n");
98+
#endif
9699
printf(" -i <filename> filename for the user's private key\n");
97100
printf(" -j <filename> filename for the user's public key\n");
98101
printf(" -x exit after successful connection without doing\n"
@@ -644,6 +647,7 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
644647
char* host = (char*)wolfSshIp;
645648
const char* username = NULL;
646649
const char* password = NULL;
650+
const char* tpmKeyAuth = NULL;
647651
const char* cmd = NULL;
648652
const char* privKeyName = NULL;
649653
const char* keyList = NULL;
@@ -665,7 +669,7 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
665669

666670
(void)keepOpen;
667671

668-
while ((ch = mygetopt(argc, argv, "?ac:h:i:j:p:tu:xzNP:RJ:A:XeEk:q")) != -1) {
672+
while ((ch = mygetopt(argc, argv, "?ac:h:i:j:p:tu:xzNP:RJ:A:XeEk:qK:")) != -1) {
669673
switch (ch) {
670674
case 'h':
671675
host = myoptarg;
@@ -769,6 +773,12 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
769773
break;
770774
#endif
771775

776+
#ifdef WOLFSSH_TPM
777+
case 'K':
778+
tpmKeyAuth = myoptarg;
779+
break;
780+
#endif
781+
772782
case '?':
773783
ShowUsage();
774784
exit(EXIT_SUCCESS);
@@ -798,7 +808,7 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
798808
}
799809
#endif
800810
#endif
801-
ret = ClientSetPrivateKey(privKeyName, userEcc, NULL);
811+
ret = ClientSetPrivateKey(privKeyName, userEcc, NULL, tpmKeyAuth);
802812
if (ret != 0) {
803813
err_sys("Error setting private key");
804814
}
@@ -853,7 +863,8 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
853863
err_sys("Couldn't create wolfSSH session.");
854864

855865
#ifdef WOLFSSH_TPM
856-
CLientSetTpm(ssh);
866+
if (tpmKeyAuth != NULL)
867+
ClientSetTpm(ssh);
857868
#endif
858869
#if defined(WOLFSSL_PTHREADS) && defined(WOLFSSL_TEST_GLOBAL_REQ)
859870
wolfSSH_SetGlobalReq(ctx, callbackGlobalReq);

examples/client/common.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -756,13 +756,6 @@ int ClientUseCert(const char* certName, void* heap)
756756

757757
#ifdef WOLFSSH_TPM
758758

759-
/* Key Authentication Password */
760-
#ifndef WOLFSSH_TPM_KEY_AUTH
761-
#define WOLFSSH_TPM_KEY_AUTH "ThisIsMyKeyAuth"
762-
#endif
763-
764-
static const char gKeyAuth[] = WOLFSSH_TPM_KEY_AUTH;
765-
766759
static int readKeyBlob(const char* filename, WOLFTPM2_KEYBLOB* key)
767760
{
768761
int rc = 0;
@@ -848,7 +841,7 @@ static int readKeyBlob(const char* filename, WOLFTPM2_KEYBLOB* key)
848841
}
849842

850843
static int wolfSSH_TPM_InitKey(WOLFTPM2_DEV* dev, const char* name,
851-
WOLFTPM2_KEY* pTpmKey)
844+
WOLFTPM2_KEY* pTpmKey, const char* tpmKeyAuth)
852845
{
853846
int rc = 0;
854847
WOLFTPM2_KEY endorse;
@@ -862,7 +855,8 @@ static int wolfSSH_TPM_InitKey(WOLFTPM2_DEV* dev, const char* name,
862855
if (rc == 0) {
863856
rc = wolfTPM2_Init(dev, TPM2_IoCb, NULL);
864857
if (rc != 0) {
865-
WLOG(WS_LOG_DEBUG, "TPM 2.0 Device initialization failed, rc: %d", rc);
858+
WLOG(WS_LOG_DEBUG,
859+
"TPM 2.0 Device initialization failed, rc: %d", rc);
866860
}
867861
}
868862

@@ -879,7 +873,8 @@ static int wolfSSH_TPM_InitKey(WOLFTPM2_DEV* dev, const char* name,
879873
endorse.handle.policyAuth = 1;
880874
rc = wolfTPM2_CreateAuthSession_EkPolicy(dev, &tpmSession);
881875
if (rc != 0) {
882-
WLOG(WS_LOG_DEBUG, "Creating EK policy session failed, rc: %d", rc);
876+
WLOG(WS_LOG_DEBUG,
877+
"Creating EK policy session failed, rc: %d", rc);
883878
}
884879
}
885880

@@ -899,10 +894,10 @@ static int wolfSSH_TPM_InitKey(WOLFTPM2_DEV* dev, const char* name,
899894
}
900895
}
901896

902-
/* Set auth for key */
903-
if (rc == 0) {
904-
tpmKeyBlob.handle.auth.size = (int)sizeof(gKeyAuth)-1;
905-
XMEMCPY(tpmKeyBlob.handle.auth.buffer, gKeyAuth,
897+
/* Use global auth if provided */
898+
if (rc == 0 && tpmKeyAuth != NULL) {
899+
tpmKeyBlob.handle.auth.size = (word32)XSTRLEN(tpmKeyAuth);
900+
XMEMCPY(tpmKeyBlob.handle.auth.buffer, tpmKeyAuth,
906901
tpmKeyBlob.handle.auth.size);
907902
}
908903

@@ -963,9 +958,8 @@ static void wolfSSH_TPM_Cleanup(WOLFTPM2_DEV* dev, WOLFTPM2_KEY* key)
963958
WLOG(WS_LOG_DEBUG, "Leaving wolfSSH_TPM_Cleanup()");
964959
}
965960

966-
/* Set the tpm device and
967-
* key for the client side */
968-
int CLientSetTpm(WOLFSSH* ssh)
961+
/* Set the tpm device and key for the client side */
962+
int ClientSetTpm(WOLFSSH* ssh)
969963
{
970964
if (ssh != NULL) {
971965
wolfSSH_SetTpmDev(ssh, &tpmDev);
@@ -979,9 +973,11 @@ int CLientSetTpm(WOLFSSH* ssh)
979973

980974
/* Reads the private key to use from file name privKeyName.
981975
* returns 0 on success */
982-
int ClientSetPrivateKey(const char* privKeyName, int userEcc, void* heap)
976+
int ClientSetPrivateKey(const char* privKeyName, int userEcc,
977+
void* heap, const char* tpmKeyAuth)
983978
{
984979
int ret = 0;
980+
(void)tpmKeyAuth; /* Not used*/
985981

986982
if (privKeyName == NULL) {
987983
if (userEcc) {
@@ -1015,7 +1011,7 @@ int ClientSetPrivateKey(const char* privKeyName, int userEcc, void* heap)
10151011
*/
10161012
WMEMSET(&tpmDev, 0, sizeof(tpmDev));
10171013
WMEMSET(&tpmKey, 0, sizeof(tpmKey));
1018-
ret = wolfSSH_TPM_InitKey(&tpmDev, privKeyName, &tpmKey);
1014+
ret = wolfSSH_TPM_InitKey(&tpmDev, privKeyName, &tpmKey, tpmKeyAuth);
10191015
#elif !defined(NO_FILESYSTEM)
10201016
userPrivateKey = NULL; /* create new buffer based on parsed input */
10211017
userPrivateKeyAlloc = 1;

examples/client/common.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222
#define WOLFSSH_COMMON_H
2323
int ClientLoadCA(WOLFSSH_CTX* ctx, const char* caCert);
2424
int ClientUsePubKey(const char* pubKeyName, int userEcc, void* heap);
25-
int ClientSetPrivateKey(const char* privKeyName, int userEcc, void* heap);
25+
int ClientSetPrivateKey(const char* privKeyName, int userEcc,
26+
void* heap, const char* tpmKeyAuth);
2627
int ClientUseCert(const char* certName, void* heap);
2728
int ClientSetEcho(int type);
2829
int ClientUserAuth(byte authType,
29-
WS_UserAuthData* authData,
30-
void* ctx);
30+
WS_UserAuthData* authData, void* ctx);
3131
int ClientPublicKeyCheck(const byte* pubKey, word32 pubKeySz, void* ctx);
3232
void ClientIPOverride(int flag);
3333
void ClientFreeBuffers(const char* pubKeyName, const char* privKeyName,
3434
void* heap);
3535
#ifdef WOLFSSH_TPM
36-
int CLientSetTpm(WOLFSSH* ssh);
36+
int ClientSetTpm(WOLFSSH* ssh);
3737
#endif
3838

3939
#endif /* WOLFSSH_COMMON_H */

0 commit comments

Comments
 (0)