Skip to content

Commit 7d758f8

Browse files
committed
address review comments
1 parent 11eb696 commit 7d758f8

File tree

8 files changed

+16
-25
lines changed

8 files changed

+16
-25
lines changed

examples/posix/wh_posix_server/wh_posix_server.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,6 @@ static int loadAndStoreKeys(whServerContext* server, whKeyId* outKeyId,
118118
return ret;
119119
}
120120

121-
static int _InitDemoServer(whServerContext* server, whServerConfig* config)
122-
{
123-
int ret;
124-
125-
ret = wh_Server_Init(server, config);
126-
127-
return ret;
128-
}
129-
130-
131121
static int wh_ServerTask(void* cf, const char* keyFilePath, int keyId,
132122
int clientId)
133123
{
@@ -141,7 +131,7 @@ static int wh_ServerTask(void* cf, const char* keyFilePath, int keyId,
141131
return -1;
142132
}
143133

144-
ret = _InitDemoServer(server, config);
134+
ret = wh_Server_Init(server, config);
145135

146136
/* Load keys into cache if file path is provided */
147137
if (keyFilePath != NULL) {
@@ -191,7 +181,7 @@ static int wh_ServerTask(void* cf, const char* keyFilePath, int keyId,
191181
(void)wh_Server_Cleanup(server);
192182

193183
/* Reinitialize the server */
194-
ret = _InitDemoServer(server, config);
184+
ret = wh_Server_Init(server, config);
195185
if (ret != 0) {
196186
printf("Failed to reinitialize server: %d\n", ret);
197187
break;

src/wh_server_keystore.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,9 @@ static int _HandleWrapKeyRequest(whServerContext* server,
873873
memcpy(&metadata, reqData, sizeof(metadata));
874874
memcpy(key, reqData + sizeof(metadata), req->keySz);
875875

876+
/* Ensure the keyId in the wrapped metadata has the wrapped flag set */
876877
if (!WH_KEYID_ISWRAPPED(metadata.id)) {
877-
return WH_ERROR_CONFIG;
878+
return WH_ERROR_BADARGS;
878879
}
879880

880881
/* Store the wrapped key in the response data */
@@ -969,8 +970,9 @@ static int _HandleUnwrapAndExportKeyRequest(
969970
return ret;
970971
}
971972

973+
/* Ensure unwrapped metadata has the wrapped flag set */
972974
if (!WH_KEYID_ISWRAPPED(metadata->id)) {
973-
return WH_ERROR_CONFIG;
975+
return WH_ERROR_ABORTED;
974976
}
975977

976978
/* Check if the key is exportable */
@@ -1079,7 +1081,7 @@ _HandleUnwrapAndCacheKeyRequest(whServerContext* server,
10791081

10801082
/* Require explicit wrapped-key encoding */
10811083
if (wrappedKeyType != WH_KEYTYPE_WRAPPED) {
1082-
return WH_ERROR_CONFIG;
1084+
return WH_ERROR_ABORTED;
10831085
}
10841086

10851087
/* Validate ownership: USER field must match requesting client.

test/wh_test_crypto.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3599,10 +3599,12 @@ int whTest_CryptoClientConfig(whClientConfig* config)
35993599
ret = whTest_NonExportableKeystore(client, WH_DEV_ID, rng);
36003600
}
36013601

3602+
#ifdef WOLFHSM_CFG_KEYWRAP
36023603
if (ret == 0) {
36033604
/* Test keywrap functionality */
36043605
ret = whTest_Client_KeyWrap(client);
36053606
}
3607+
#endif
36063608

36073609
#ifndef NO_AES
36083610
i = 0;

test/wh_test_multiclient.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@
6161
#define FLASH_PAGE_SIZE (8) /* 8B */
6262
#define BUFFER_SIZE 4096
6363

64+
#ifdef WOLFHSM_CFG_GLOBAL_KEYS
6465
/* Test key data */
6566
static const uint8_t TEST_KEY_DATA_1[] = "TestGlobalKey1Data";
6667
static const uint8_t TEST_KEY_DATA_2[] = "TestLocalKey2Data";
6768
static const uint8_t TEST_KEY_DATA_3[] = "TestGlobalKey3DataLonger";
69+
#endif
6870

6971
/* ============================================================================
7072
* DUMMY KEY ID DEFINITIONS

wolfhsm/wh_common.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,14 @@ WH_INLINE whKeyId WH_TRANSLATE_CLIENT_KEYID(uint16_t type, uint16_t clientId,
113113
}
114114
#endif
115115

116+
#ifdef WOLFHSM_CFG_KEYWRAP
116117
/* Check for wrapped flag (bit 9: 0x0200) */
117118
if ((reqId & 0x0200) != 0) {
118119
type = WH_KEYTYPE_WRAPPED;
119120
}
120-
else {
121+
else
122+
#endif
123+
{
121124
type = WH_KEYTYPE_CRYPTO;
122125
}
123126

wolfhsm/wh_error.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ enum WH_ERROR_ENUM {
4343
WH_ERROR_NOHANDLER = -2007, /* No customcb handler registered */
4444
WH_ERROR_NOTIMPL = -2008, /* Functionality not implemented given the
4545
compile-time configuration */
46-
WH_ERROR_CONFIG = -2009, /* Server configuration assumption error, something
47-
occured at runtime that is prohibited by the
48-
server configuration */
4946

5047
/* NVM and keystore specific status returns */
5148
WH_ERROR_LOCKED = -2100, /* Unlock and retry if necessary */

wolfhsm/wh_nvm.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,8 @@
4242

4343
#include <stdint.h>
4444

45-
#include "wolfhsm/wh_common.h" /* For whNvm types */
46-
47-
#if !defined(WOLFHSM_CFG_NO_CRYPTO) && defined(WOLFHSM_CFG_GLOBAL_KEYS)
45+
#include "wolfhsm/wh_common.h" /* For whNvm types */
4846
#include "wolfhsm/wh_server_cache.h" /* For whKeyCacheContext */
49-
#endif
5047

5148
typedef struct {
5249
int (*Init)(void* context, const void *config);

wolfhsm/wh_server_keystore.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ int wh_Server_KeystoreExportKeyDma(whServerContext* server, whKeyId keyId,
190190
uint64_t keyAddr, uint64_t keySz,
191191
whNvmMetadata* outMeta);
192192

193-
#ifdef WOLFHSM_CFG_KEYWRAP
194193
/**
195194
* @brief Query whether a key identifier refers to wrapped material
196195
*
@@ -201,6 +200,5 @@ int wh_Server_KeystoreExportKeyDma(whServerContext* server, whKeyId keyId,
201200
*/
202201
int wh_Server_KeystoreIsWrappedKey(whServerContext* server, whKeyId keyId,
203202
int* outIsWrapped);
204-
#endif /* WOLFHSM_CFG_KEYWRAP */
205203

206204
#endif /* !WOLFHSM_WH_SERVER_KEYSTORE_H_ */

0 commit comments

Comments
 (0)