@@ -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-
766759static 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
850843static 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 ;
0 commit comments