Skip to content
Open
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
89 changes: 79 additions & 10 deletions src/wh_client_she.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ int wh_Client_SheSetUidResponse(whClientContext* c)

resp = (whMessageShe_SetUidResponse*)wh_CommClient_GetDataPtr(c->comm);
ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp);
if (ret == WH_ERROR_OK && dataSz < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
if (ret == WH_ERROR_OK) {
ret = resp->rc;
}
Expand Down Expand Up @@ -150,6 +153,9 @@ int wh_Client_SheSecureBoot(whClientContext* c, uint8_t* bootloader,
initResp = (whMessageShe_SecureBootInitResponse*)respBuf;
} while (ret == WH_ERROR_NOTREADY);
}
if (ret == 0 && dataSz < sizeof(*initResp)) {
ret = WH_ERROR_ABORTED;
}

/* send update sub command until we've sent the entire bootloader */
while (ret == 0 && bootloaderSent < bootloaderLen) {
Expand Down Expand Up @@ -186,6 +192,13 @@ int wh_Client_SheSecureBoot(whClientContext* c, uint8_t* bootloader,
respBuf);
} while (ret == WH_ERROR_NOTREADY);
}
if (ret == 0) {
whMessageShe_SecureBootUpdateResponse* updateResp =
(whMessageShe_SecureBootUpdateResponse*)respBuf;
if (dataSz < sizeof(*updateResp)) {
ret = WH_ERROR_ABORTED;
}
}

/* increment sent */
if (ret == 0) {
Expand All @@ -205,6 +218,9 @@ int wh_Client_SheSecureBoot(whClientContext* c, uint8_t* bootloader,
finishResp = (whMessageShe_SecureBootFinishResponse*)respBuf;
} while (ret == WH_ERROR_NOTREADY);
}
if (ret == 0 && dataSz < sizeof(*finishResp)) {
ret = WH_ERROR_ABORTED;
}

if (ret == 0) {
ret = finishResp->rc;
Expand Down Expand Up @@ -245,7 +261,9 @@ int wh_Client_SheGetStatusResponse(whClientContext* c, uint8_t* sreg)

/* return error or set sreg */
if (ret == 0) {
if (resp->rc != WH_SHE_ERC_NO_ERROR)
if (dataSz < sizeof(*resp))
ret = WH_ERROR_ABORTED;
else if (resp->rc != WH_SHE_ERC_NO_ERROR)
ret = resp->rc;
else
*sreg = resp->sreg;
Expand Down Expand Up @@ -307,7 +325,10 @@ int wh_Client_SheLoadKeyResponse(whClientContext* c, uint8_t* messageFour,

ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp);
if (ret == 0) {
if (resp->rc != WH_SHE_ERC_NO_ERROR) {
if (dataSz < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != WH_SHE_ERC_NO_ERROR) {
ret = resp->rc;
}
else {
Expand Down Expand Up @@ -366,6 +387,9 @@ int wh_Client_SheLoadPlainKeyResponse(whClientContext* c)
(whMessageShe_LoadPlainKeyResponse*)wh_CommClient_GetDataPtr(c->comm);

ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp);
if (ret == 0 && dataSz < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
if (ret == 0) {
ret = resp->rc;
}
Expand Down Expand Up @@ -417,7 +441,10 @@ int wh_Client_SheExportRamKeyResponse(whClientContext* c, uint8_t* messageOne,

ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp);
if (ret == 0) {
if (resp->rc != WH_SHE_ERC_NO_ERROR) {
if (dataSz < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != WH_SHE_ERC_NO_ERROR) {
ret = resp->rc;
}
else {
Expand Down Expand Up @@ -473,6 +500,9 @@ int wh_Client_SheInitRndResponse(whClientContext* c)

resp = (whMessageShe_InitRngResponse*)wh_CommClient_GetDataPtr(c->comm);
ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp);
if (ret == 0 && dataSz < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
if (ret == 0) {
ret = resp->rc;
}
Expand Down Expand Up @@ -518,7 +548,9 @@ int wh_Client_SheRndResponse(whClientContext* c, uint8_t* out, uint32_t* outSz)
ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp);

if (ret == 0) {
if (resp->rc != WH_SHE_ERC_NO_ERROR)
if (dataSz < sizeof(*resp))
ret = WH_ERROR_ABORTED;
else if (resp->rc != WH_SHE_ERC_NO_ERROR)
ret = resp->rc;
else {
memcpy(out, resp->rnd, sizeof(resp->rnd));
Expand Down Expand Up @@ -577,6 +609,9 @@ int wh_Client_SheExtendSeedResponse(whClientContext* c)
resp = (whMessageShe_ExtendSeedResponse*)wh_CommClient_GetDataPtr(c->comm);
ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp);

if (ret == 0 && dataSz < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
if (ret == 0) {
ret = resp->rc;
}
Expand Down Expand Up @@ -640,9 +675,16 @@ int wh_Client_SheEncEcbResponse(whClientContext* c, uint8_t* out, uint32_t sz)

ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp);
if (ret == 0) {
if (resp->rc != WH_SHE_ERC_NO_ERROR) {
if (dataSz < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != WH_SHE_ERC_NO_ERROR) {
ret = resp->rc;
}
/* payload is only present on success, so validate its size before copy */
else if (dataSz < sizeof(*resp) + resp->sz) {
ret = WH_ERROR_ABORTED;
}
else if (sz < resp->sz) {
ret = WH_ERROR_BADARGS;
}
Expand Down Expand Up @@ -712,9 +754,16 @@ int wh_Client_SheEncCbcResponse(whClientContext* c, uint8_t* out, uint32_t sz)

ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp);
if (ret == 0) {
if (resp->rc != WH_SHE_ERC_NO_ERROR) {
if (dataSz < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != WH_SHE_ERC_NO_ERROR) {
ret = resp->rc;
}
/* payload is only present on success, so validate its size before copy */
else if (dataSz < sizeof(*resp) + resp->sz) {
ret = WH_ERROR_ABORTED;
}
else if (sz < resp->sz) {
ret = WH_ERROR_BADARGS;
}
Expand Down Expand Up @@ -780,9 +829,16 @@ int wh_Client_SheDecEcbResponse(whClientContext* c, uint8_t* out, uint32_t sz)

ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp);
if (ret == 0) {
if (resp->rc != WH_SHE_ERC_NO_ERROR) {
if (dataSz < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != WH_SHE_ERC_NO_ERROR) {
ret = resp->rc;
}
/* payload is only present on success, so validate its size before copy */
else if (dataSz < sizeof(*resp) + resp->sz) {
ret = WH_ERROR_ABORTED;
}
else if (sz < resp->sz) {
ret = WH_ERROR_BADARGS;
}
Expand Down Expand Up @@ -852,9 +908,16 @@ int wh_Client_SheDecCbcResponse(whClientContext* c, uint8_t* out, uint32_t sz)

ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp);
if (ret == 0) {
if (resp->rc != WH_SHE_ERC_NO_ERROR) {
if (dataSz < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != WH_SHE_ERC_NO_ERROR) {
ret = resp->rc;
}
/* payload is only present on success, so validate its size before copy */
else if (dataSz < sizeof(*resp) + resp->sz) {
ret = WH_ERROR_ABORTED;
}
else if (sz < resp->sz) {
ret = WH_ERROR_BADARGS;
}
Expand Down Expand Up @@ -919,7 +982,10 @@ int wh_Client_SheGenerateMacResponse(whClientContext* c, uint8_t* out,

ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp);
if (ret == 0) {
if (resp->rc != WH_SHE_ERC_NO_ERROR) {
if (dataSz < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != WH_SHE_ERC_NO_ERROR) {
ret = resp->rc;
}
else {
Expand Down Expand Up @@ -991,7 +1057,10 @@ int wh_Client_SheVerifyMacResponse(whClientContext* c, uint8_t* outStatus)
resp = (whMessageShe_VerifyMacResponse*)wh_CommClient_GetDataPtr(c->comm);
ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp);
if (ret == 0) {
if (resp->rc != WH_SHE_ERC_NO_ERROR) {
if (dataSz < sizeof(*resp)) {
ret = WH_ERROR_ABORTED;
}
else if (resp->rc != WH_SHE_ERC_NO_ERROR) {
ret = resp->rc;
}
else {
Expand Down
Loading