Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 46 additions & 22 deletions src/wh_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ int wh_Client_SendRequest(whClientContext* c,

int wh_Client_RecvResponse(whClientContext *c,
uint16_t *out_group, uint16_t *out_action,
uint16_t *out_size, void* data)
uint16_t *out_size, uint16_t data_size, void* data)
{
int rc = 0;
uint16_t resp_kind = 0;
Expand All @@ -268,7 +268,7 @@ int wh_Client_RecvResponse(whClientContext *c,

/* Comm layer performs magic and sequence validation */
rc = wh_CommClient_RecvResponse(c->comm, NULL, &resp_kind, &resp_id,
&resp_size, data);
&resp_size, data_size, data);
if (rc == 0) {
Comment thread
padelsbach marked this conversation as resolved.
if ((resp_kind != c->last_req_kind) || (resp_id != c->last_req_id)) {
/* Response kind/id doesn't match outstanding request. */
Expand All @@ -286,6 +286,16 @@ int wh_Client_RecvResponse(whClientContext *c,
}
}
}
else if (rc == WH_ERROR_BUFFER_SIZE) {
Comment thread
padelsbach marked this conversation as resolved.
if ((resp_kind != c->last_req_kind) || (resp_id != c->last_req_id)) {
/* Response kind/id doesn't match outstanding request. */
rc = WH_ERROR_ABORTED;
}
else if (out_size != NULL) {
/* Payload exceeded the caller's buffer; report the required size. */
*out_size = resp_size;
}
}
return rc;
}

Expand Down Expand Up @@ -329,7 +339,7 @@ int wh_Client_CommInitResponse(whClientContext* c,

rc = wh_Client_RecvResponse(c,
&resp_group, &resp_action,
&resp_size, &msg);
&resp_size, sizeof(msg), &msg);
if (rc == 0) {
/* Validate response */
if ( (resp_group != WH_MESSAGE_GROUP_COMM) ||
Expand Down Expand Up @@ -409,7 +419,7 @@ int wh_Client_CommInfoResponse(whClientContext* c,

rc = wh_Client_RecvResponse(c,
&resp_group, &resp_action,
&resp_size, &msg);
&resp_size, sizeof(msg), &msg);
if (rc == 0) {
/* Validate response */
if ( (resp_group != WH_MESSAGE_GROUP_COMM) ||
Expand Down Expand Up @@ -587,7 +597,7 @@ int wh_Client_CommCloseResponse(whClientContext* c)

rc = wh_Client_RecvResponse(c,
&resp_group, &resp_action,
&resp_size, NULL);
&resp_size, 0, NULL);
if (rc == 0) {
/* Validate response */
if ( (resp_group != WH_MESSAGE_GROUP_COMM) ||
Expand Down Expand Up @@ -660,7 +670,7 @@ int wh_Client_EchoResponse(whClientContext* c, uint16_t *out_size, void* data)

rc = wh_Client_RecvResponse(c,
&resp_group, &resp_action,
&resp_size, msg);
&resp_size, WOLFHSM_CFG_COMM_DATA_LEN, msg);
if (rc == 0) {
/* Validate response */
if ( (resp_group != WH_MESSAGE_GROUP_COMM) ||
Expand Down Expand Up @@ -722,7 +732,8 @@ int wh_Client_CustomCbResponse(whClientContext* c,
}

rc =
wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, &resp);
wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
sizeof(resp), &resp);
if (rc != WH_ERROR_OK) {
return rc;
}
Expand Down Expand Up @@ -872,7 +883,8 @@ int wh_Client_KeyCacheResponse(whClientContext* c, uint16_t* keyId)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size,
WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == WH_ERROR_OK) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -959,7 +971,8 @@ int wh_Client_KeyCacheRandomResponse(whClientContext* c, uint16_t* outKeyId)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size,
WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == WH_ERROR_OK) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -1027,7 +1040,8 @@ int wh_Client_KeyEvictResponse(whClientContext* c)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)&resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size, sizeof(resp),
(uint8_t*)&resp);

if (ret == 0) {
if (resp.rc != 0) {
Expand Down Expand Up @@ -1090,7 +1104,8 @@ int wh_Client_KeyExportResponse(whClientContext* c, uint8_t* label,
}
packOut = (uint8_t*)(resp + 1);

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size,
WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == WH_ERROR_OK) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -1175,7 +1190,8 @@ int wh_Client_KeyExportPublicResponse(whClientContext* c, uint8_t* label,
}
packOut = (uint8_t*)(resp + 1);

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size,
WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == WH_ERROR_OK) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -1252,7 +1268,8 @@ int wh_Client_KeyCommitResponse(whClientContext* c)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size,
WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == WH_ERROR_OK) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -1308,7 +1325,8 @@ int wh_Client_KeyEraseResponse(whClientContext* c)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size,
WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == 0) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -1364,7 +1382,8 @@ int wh_Client_KeyRevokeResponse(whClientContext* c)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size,
WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == 0) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -1422,7 +1441,8 @@ int wh_Client_CounterInitResponse(whClientContext* c, uint32_t* counter)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size,
WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == WH_ERROR_OK) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -1500,7 +1520,8 @@ int wh_Client_CounterIncrementResponse(whClientContext* c, uint32_t* counter)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size,
WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == WH_ERROR_OK) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -1560,7 +1581,8 @@ int wh_Client_CounterReadResponse(whClientContext* c, uint32_t* counter)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size,
WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == WH_ERROR_OK) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -1620,7 +1642,8 @@ int wh_Client_CounterDestroyResponse(whClientContext* c)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size,
WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == WH_ERROR_OK) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -1715,7 +1738,8 @@ int wh_Client_KeyCacheDmaResponse(whClientContext* c, uint16_t* keyId)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size,
WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
/* NOTREADY: response not in yet - return without POST so the pending
* request keeps its mapping; POST runs once the response arrives. */
if (ret == WH_ERROR_NOTREADY) {
Expand Down Expand Up @@ -1826,7 +1850,7 @@ int wh_Client_KeyExportDmaResponse(whClientContext* c, uint8_t* label,
}

rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
(uint8_t*)resp);
WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
/* NOTREADY: response not in yet - return without POST so the pending
* request keeps its mapping; POST runs once the response arrives. */
if (rc == WH_ERROR_NOTREADY) {
Expand Down Expand Up @@ -1951,7 +1975,7 @@ int wh_Client_KeyExportPublicDmaResponse(whClientContext* c, uint8_t* label,
}

rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
(uint8_t*)resp);
WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
/* NOTREADY: response not in yet - return without POST so the pending
* request keeps its mapping; POST runs once the response arrives. */
if (rc == WH_ERROR_NOTREADY) {
Expand Down
14 changes: 7 additions & 7 deletions src/wh_client_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ int wh_Client_AuthLoginResponse(whClientContext* c, int32_t* out_rc,
}

rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
buffer);
sizeof(buffer), buffer);
if (rc == WH_ERROR_OK) {
/* Validate response */
if ((resp_group != WH_MESSAGE_GROUP_AUTH) ||
Expand Down Expand Up @@ -219,7 +219,7 @@ int wh_Client_AuthLogoutResponse(whClientContext* c, int32_t* out_rc)
}

rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
buffer);
sizeof(buffer), buffer);
if (rc == WH_ERROR_OK) {
/* Validate response */
if ((resp_group != WH_MESSAGE_GROUP_AUTH) ||
Expand Down Expand Up @@ -338,7 +338,7 @@ int wh_Client_AuthUserAddResponse(whClientContext* c, int32_t* out_rc,
}

rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
buffer);
sizeof(buffer), buffer);
if (rc == WH_ERROR_OK) {
/* Validate response */
if ((resp_group != WH_MESSAGE_GROUP_AUTH) ||
Expand Down Expand Up @@ -413,7 +413,7 @@ int wh_Client_AuthUserDeleteResponse(whClientContext* c, int32_t* out_rc)
}

rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
buffer);
sizeof(buffer), buffer);
if (rc == WH_ERROR_OK) {
/* Validate response */
if ((resp_group != WH_MESSAGE_GROUP_AUTH) ||
Expand Down Expand Up @@ -489,7 +489,7 @@ int wh_Client_AuthUserGetResponse(whClientContext* c, int32_t* out_rc,
}

rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
buffer);
sizeof(buffer), buffer);
if (rc == WH_ERROR_OK) {
/* Validate response */
if ((resp_group != WH_MESSAGE_GROUP_AUTH) ||
Expand Down Expand Up @@ -576,7 +576,7 @@ int wh_Client_AuthUserSetPermissionsResponse(whClientContext* c,
}

rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
buffer);
sizeof(buffer), buffer);
if (rc == WH_ERROR_OK) {
/* Validate response */
if ((resp_group != WH_MESSAGE_GROUP_AUTH) ||
Expand Down Expand Up @@ -702,7 +702,7 @@ int wh_Client_AuthUserSetCredentialsResponse(whClientContext* c,
}

rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
buffer);
sizeof(buffer), buffer);
if (rc == WH_ERROR_OK) {
/* Validate response */
if ((resp_group != WH_MESSAGE_GROUP_AUTH) ||
Expand Down
Loading
Loading