Skip to content

Commit

Permalink
Add error return for QueryResponse (#184)
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
  • Loading branch information
dthaler authored Jul 23, 2023
1 parent 8cbcc19 commit 1ea0f50
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 43 deletions.
4 changes: 3 additions & 1 deletion TeepUnitTest/ProtocolTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,9 @@ TEST_CASE("TAM receives QueryResponse with supported version and ES256", "[proto

TEST_CASE("TAM receives QueryResponse with unsupported version", "[protocol]")
{
const uint64_t expected_message_count = 0;
// Issue #347: unclear whether it's ok (2) or not ok (0) to send an Update with error info
// in response to a bad QueryResponse.
const uint64_t expected_message_count = 2;
TestQueryResponseVersion(1, TEEP_SIGNATURE_ES256, TEEP_ERR_UNSUPPORTED_MSG_VERSION, expected_message_count);
}

Expand Down
22 changes: 22 additions & 0 deletions protocol/TeepAgentLib/TeepAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,28 @@ static teep_error_code_t TeepAgentHandleUpdate(void* sessionHandle, QCBORDecodeC
// TODO: use Attestation Result.
break;
}
case TEEP_LABEL_ERR_CODE:
{
if (item.uDataType != QCBOR_TYPE_INT64) {
REPORT_TYPE_ERROR(errorMessage, "err-code", QCBOR_TYPE_INT64, item);
teep_error = TeepAgentComposeError(token, TEEP_ERR_PERMANENT_ERROR, errorMessage.str(), &errorResponse);
TeepAgentSendError(errorResponse, sessionHandle);
return teep_error;
}
errorMessage << "err-code: " << item.val.int64 << std::endl;
TeepLogMessage(errorMessage.str().c_str());
break;
}
case TEEP_LABEL_ERR_MSG:
{
if (item.uDataType != QCBOR_TYPE_TEXT_STRING) {
REPORT_TYPE_ERROR(errorMessage, "err-msg", QCBOR_TYPE_TEXT_STRING, item);
return TEEP_ERR_PERMANENT_ERROR;
}
errorMessage << "err-msg: " << std::string((const char*)item.val.string.ptr, item.val.string.len) << std::endl;
TeepLogMessage(errorMessage.str().c_str());
break;
}
default:
errorMessage << "Unrecognized option label " << label;
teep_error = TeepAgentComposeError(token, TEEP_ERR_PERMANENT_ERROR, errorMessage.str(), &errorResponse);
Expand Down
1 change: 1 addition & 0 deletions protocol/TeepCommonLib/teep_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ typedef enum {
TEEP_LABEL_SUIT_REPORTS = 19,
TEEP_LABEL_TOKEN = 20,
TEEP_LABEL_SUPPORTED_FRESHNESS_MECHANISMS = 21,
TEEP_LABEL_ERR_CODE = 23,
} teep_label_t;

typedef enum {
Expand Down
Loading

0 comments on commit 1ea0f50

Please sign in to comment.