Skip to content

Commit

Permalink
No need for tpm specific return code will refactor passes test/unit.test
Browse files Browse the repository at this point in the history
  • Loading branch information
aidangarske committed Dec 17, 2024
1 parent 436cd91 commit fae59c7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
14 changes: 7 additions & 7 deletions examples/client/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ static int readKeyBlob(const char* filename, WOLFTPM2_KEYBLOB* key)
WLOG(WS_LOG_DEBUG, "Leaving readKeyBlob(), rc = %d", rc);
return rc;
}

// make rc check cleanup at end and get rid of uneeded returns
static int wolfSSH_TPM_InitKey(WOLFTPM2_DEV* dev, const char* name,
WOLFTPM2_KEY* pTpmKey)
{
Expand All @@ -832,7 +832,7 @@ static int wolfSSH_TPM_InitKey(WOLFTPM2_DEV* dev, const char* name,
#ifdef DEBUG_WOLFSSH
printf("TPM 2.0 Device initialization failed\n");
#endif
return WOLFSSH_TPM_FAILED_INIT;
return WS_ERROR;
}

/* TPM 2.0 keys live under a Primary Key, acquire such key */
Expand All @@ -841,7 +841,7 @@ static int wolfSSH_TPM_InitKey(WOLFTPM2_DEV* dev, const char* name,
#ifdef DEBUG_WOLFSSH
printf("Acquiring a Primary TPM 2.0 Key failed\n");
#endif
return WOLFSSH_TPM_FAILED_LOAD_PRIMARY;
return WS_BAD_ARGUMENT;
}

/* Load the TPM 2.0 key blob from disk */
Expand All @@ -850,7 +850,7 @@ static int wolfSSH_TPM_InitKey(WOLFTPM2_DEV* dev, const char* name,
#ifdef DEBUG_WOLFSSH
printf("Reading key blob from disk failed\n");
#endif
return WOLFSSH_TPM_FAILED_READ_KEYBLOB;
return WS_DECRYPT_E;
}

/* TODO: workaround until password can be supplied */
Expand All @@ -866,7 +866,7 @@ static int wolfSSH_TPM_InitKey(WOLFTPM2_DEV* dev, const char* name,
#ifdef DEBUG_WOLFSSH
printf("wolfTPM2_LoadKey failed\n");
#endif
return WOLFSSH_TPM_FAILED_LOAD_KEY;
return WS_BAD_ARGUMENT;
}
#ifdef DEBUG_WOLFSSH
printf("Loaded key to 0x%x\n", (word32)tpmKeyBlob.handle.hndl);
Expand All @@ -880,7 +880,7 @@ static int wolfSSH_TPM_InitKey(WOLFTPM2_DEV* dev, const char* name,
#ifdef DEBUG_WOLFSSH
printf("Exporting TPM key failed\n");
#endif
return WOLFSSH_TPM_FAILED_EXPORT_KEY;
return WS_MEMORY_E;
}

/* Read public key from the buffer and convert the key to OpenSSH format */
Expand All @@ -891,7 +891,7 @@ static int wolfSSH_TPM_InitKey(WOLFTPM2_DEV* dev, const char* name,
#ifdef DEBUG_WOLFSSH
printf("Reading public key failed returned: %d\n", rc);
#endif
return WOLFSSH_TPM_FAILED_READ_PUBLIC_KEY;
return WS_PUBKEY_REJECTED_E;
}
userPublicKey = p;

Expand Down
4 changes: 4 additions & 0 deletions src/ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,11 @@ static int DoPemKey(const byte* in, word32 inSz, byte** out,
ret = wc_KeyPemToDer(in, inSz, newKey, newKeySz, NULL);
}
else {
#ifdef WOLFSSH_TPM
ret = wc_PubKeyPemToDer(in, inSz, newKey, newKeySz);
#else
ret = NOT_COMPILED_IN;
#endif
}
if (ret > 0) {
newKeySz = (word32)ret;
Expand Down
10 changes: 1 addition & 9 deletions wolfssh/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,7 @@ enum WS_ErrorCodes {
WS_AUTH_PENDING = -1096, /* User authentication still pending */
WS_KDF_E = -1097, /* KDF error*/

/* TODO: Fix names and add hard coded value */
WOLFSSH_TPM_FAILED_INIT,
WOLFSSH_TPM_FAILED_LOAD_PRIMARY,
WOLFSSH_TPM_FAILED_READ_KEYBLOB,
WOLFSSH_TPM_FAILED_EXPORT_KEY,
WOLFSSH_TPM_FAILED_LOAD_KEY,
WOLFSSH_TPM_FAILED_READ_PUBLIC_KEY,

WS_LAST_E = WOLFSSH_TPM_FAILED_READ_PUBLIC_KEY /* Update this to indicate last error */
WS_LAST_E = WS_KDF_E /* Update this to indicate last error */
};


Expand Down

0 comments on commit fae59c7

Please sign in to comment.