Skip to content
Merged
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
93 changes: 80 additions & 13 deletions src/wh_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ int wh_Client_CommCloseResponse(whClientContext* c)
if (rc == 0) {
/* Validate response */
if ( (resp_group != WH_MESSAGE_GROUP_COMM) ||
(resp_action != WH_MESSAGE_COMM_ACTION_CLOSE) ){
(resp_action != WH_MESSAGE_COMM_ACTION_CLOSE) ||
(resp_size != 0) ){
/* Invalid message */
rc = WH_ERROR_ABORTED;
} else {
Expand Down Expand Up @@ -867,7 +868,12 @@ int wh_Client_KeyCacheResponse(whClientContext* c, uint16_t* keyId)
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) {
/* Defensive bound: the response fields must fit within the actual
* received frame */
if (size < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != 0) {
ret = resp->rc;
}
else {
Expand Down Expand Up @@ -955,7 +961,12 @@ int wh_Client_KeyCacheRandomResponse(whClientContext* c, uint16_t* outKeyId)
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) {
/* Defensive bound: the response fields must fit within the actual
* received frame */
if (size < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != 0) {
ret = resp->rc;
}
else {
Expand Down Expand Up @@ -1025,7 +1036,12 @@ int wh_Client_KeyEvictResponse(whClientContext* c)
(uint8_t*)&resp);

if (ret == 0) {
if (resp.rc != 0) {
/* Defensive bound: the response fields must fit within the actual
* received frame */
if (size < sizeof(resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp.rc != 0) {
ret = resp.rc;
}
}
Expand Down Expand Up @@ -1088,9 +1104,17 @@ int wh_Client_KeyExportResponse(whClientContext* c, uint8_t* label,
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) {
/* Defensive bounds: the fixed fields, then the key material, must fit
* within the actual received frame */
if (size < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != 0) {
ret = resp->rc;
}
else if (resp->len > (size - sizeof(*resp))) {
ret = WH_ERROR_ABORTED;
}
else {
if (out == NULL) {
*outSz = resp->len;
Expand Down Expand Up @@ -1174,9 +1198,17 @@ int wh_Client_KeyExportPublicResponse(whClientContext* c, uint8_t* label,
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) {
/* Defensive bounds: the fixed fields, then the key material, must fit
* within the actual received frame */
if (size < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != 0) {
ret = resp->rc;
}
else if (resp->len > (size - sizeof(*resp))) {
ret = WH_ERROR_ABORTED;
}
else {
if (out == NULL) {
*outSz = resp->len;
Expand Down Expand Up @@ -1252,7 +1284,12 @@ int wh_Client_KeyCommitResponse(whClientContext* c)
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) {
/* Defensive bound: the response fields must fit within the actual
* received frame */
if (size < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != 0) {
ret = resp->rc;
}
}
Expand Down Expand Up @@ -1309,7 +1346,12 @@ int wh_Client_KeyEraseResponse(whClientContext* c)
ret = wh_Client_RecvResponse(c, &group, &action, &size,
WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == 0) {
if (resp->rc != 0) {
/* Defensive bound: the response fields must fit within the actual
* received frame */
if (size < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != 0) {
ret = resp->rc;
}
}
Expand Down Expand Up @@ -1366,7 +1408,12 @@ int wh_Client_KeyRevokeResponse(whClientContext* c)
ret = wh_Client_RecvResponse(c, &group, &action, &size,
WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == 0) {
if (resp->rc != 0) {
/* Defensive bound: the response fields must fit within the actual
* received frame */
if (size < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != 0) {
ret = resp->rc;
}
}
Expand Down Expand Up @@ -1425,7 +1472,12 @@ int wh_Client_CounterInitResponse(whClientContext* c, uint32_t* counter)
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) {
/* Defensive bound: the response fields must fit within the actual
* received frame */
if (size < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != 0) {
ret = resp->rc;
}
else if (counter != NULL) {
Expand Down Expand Up @@ -1504,7 +1556,12 @@ int wh_Client_CounterIncrementResponse(whClientContext* c, uint32_t* counter)
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) {
/* Defensive bound: the response fields must fit within the actual
* received frame */
if (size < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != 0) {
ret = resp->rc;
}
else if (counter != NULL) {
Expand Down Expand Up @@ -1565,7 +1622,12 @@ int wh_Client_CounterReadResponse(whClientContext* c, uint32_t* counter)
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) {
/* Defensive bound: the response fields must fit within the actual
* received frame */
if (size < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != 0) {
ret = resp->rc;
}
else {
Expand Down Expand Up @@ -1626,7 +1688,12 @@ int wh_Client_CounterDestroyResponse(whClientContext* c)
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) {
/* Defensive bound: the response fields must fit within the actual
* received frame */
if (size < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != 0) {
ret = resp->rc;
}
}
Expand Down
Loading