From fae59c7dc5186e0fb429ecccbd06f5a08dc8cda0 Mon Sep 17 00:00:00 2001 From: aidan garske Date: Mon, 16 Dec 2024 16:37:32 -0800 Subject: [PATCH] No need for tpm specific return code will refactor passes test/unit.test --- examples/client/common.c | 14 +++++++------- src/ssh.c | 4 ++++ wolfssh/error.h | 10 +--------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/examples/client/common.c b/examples/client/common.c index ae5cfd5f..489be8b7 100644 --- a/examples/client/common.c +++ b/examples/client/common.c @@ -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) { @@ -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 */ @@ -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 */ @@ -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 */ @@ -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); @@ -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 */ @@ -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; diff --git a/src/ssh.c b/src/ssh.c index 72e4ee1f..044513bc 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -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; diff --git a/wolfssh/error.h b/wolfssh/error.h index f5073762..b0000419 100644 --- a/wolfssh/error.h +++ b/wolfssh/error.h @@ -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 */ };