Skip to content

Commit 96d3811

Browse files
committed
fix(qgs): release context on init failure to enable auto-recovery
When QPL fails to retrieve PCK certificates (e.g., HTTP 404 from PCCS), the QGS context was not being released, causing all subsequent quote requests to fail until the service was restarted. This fix ensures context is released on failure at all critical points: qgs_ql_logic.cpp: - Release context when tee_att_init_quote fails (first request) - Release context when tee_att_get_quote_size/get_quote fails (subsequent requests with existing context) network_wrapper.cpp (Linux & Windows): - Add error logging for HTTP 404 (no cache data) with full URL - Add error logging for unexpected HTTP status codes The root cause was that HTTP 404 errors from PCCS (indicating no certificate data available) left the context in a corrupted state. With this fix, the next request will automatically re-initialize the context and retry.
1 parent 717f2a9 commit 96d3811

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

QuoteGeneration/qcnl/linux/network_wrapper.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ static sgx_qcnl_error_t pccs_status_to_qcnl_error(long pccs_status_code) {
244244
case 403:
245245
return SGX_QCNL_NETWORK_ERROR;
246246
case 404: // PCCS_STATUS_NO_CACHE_DATA
247+
qcnl_log(SGX_QL_LOG_ERROR, "[QCNL] PCCS returned HTTP 404: No cache data available for this platform.\n");
247248
return SGX_QCNL_ERROR_STATUS_NO_CACHE_DATA;
248249
case 461: // PCCS_STATUS_PLATFORM_UNKNOWN
249250
return SGX_QCNL_ERROR_STATUS_PLATFORM_UNKNOWN;
@@ -252,6 +253,7 @@ static sgx_qcnl_error_t pccs_status_to_qcnl_error(long pccs_status_code) {
252253
case 503: // PCCS_STATUS_SERVICE_UNAVAILABLE
253254
return SGX_QCNL_ERROR_STATUS_SERVICE_UNAVAILABLE;
254255
default:
256+
qcnl_log(SGX_QL_LOG_ERROR, "[QCNL] PCCS returned unexpected HTTP status: %ld\n", pccs_status_code);
255257
return SGX_QCNL_ERROR_STATUS_UNEXPECTED;
256258
}
257259
}
@@ -396,8 +398,10 @@ sgx_qcnl_error_t qcnl_https_request(const char *url,
396398
qcnl_log(SGX_QL_LOG_ERROR, "[QCNL] Encountered CURL error: (%d) %s \n",
397399
curl_ret, f_easy_strerror(curl_ret));
398400
ret = curl_error_to_qcnl_error(curl_ret);
399-
} else
401+
} else {
402+
qcnl_log(SGX_QL_LOG_ERROR, "[QCNL] Request failed for URL: %s (HTTP %ld)\n", url, http_code);
400403
ret = pccs_status_to_qcnl_error(http_code);
404+
}
401405
goto cleanup;
402406
}
403407
} while (true);

QuoteGeneration/qcnl/win/network_wrapper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ static sgx_qcnl_error_t pccs_status_to_qcnl_error(DWORD pccs_status_code) {
8686
case 200: // PCCS_STATUS_SUCCESS
8787
return SGX_QCNL_SUCCESS;
8888
case 404: // PCCS_STATUS_NO_CACHE_DATA
89+
qcnl_log(SGX_QL_LOG_ERROR, "[QCNL] PCCS returned HTTP 404: No cache data available for this platform.\n");
8990
return SGX_QCNL_ERROR_STATUS_NO_CACHE_DATA;
9091
case 461: // PCCS_STATUS_PLATFORM_UNKNOWN
9192
return SGX_QCNL_ERROR_STATUS_PLATFORM_UNKNOWN;
@@ -94,6 +95,7 @@ static sgx_qcnl_error_t pccs_status_to_qcnl_error(DWORD pccs_status_code) {
9495
case 503: // PCCS_STATUS_SERVICE_UNAVAILABLE;
9596
return SGX_QCNL_ERROR_STATUS_SERVICE_UNAVAILABLE;
9697
default:
98+
qcnl_log(SGX_QL_LOG_ERROR, "[QCNL] PCCS returned unexpected HTTP status: %ld\n", pccs_status_code);
9799
return SGX_QCNL_ERROR_STATUS_UNEXPECTED;
98100
}
99101
}
@@ -329,9 +331,12 @@ sgx_qcnl_error_t qcnl_https_request_once(const char *url,
329331
delete[] lpOutBuffer;
330332
} else if (dwStatus == HTTP_STATUS_NOT_FOUND) // 404
331333
{
334+
qcnl_log(SGX_QL_LOG_ERROR, "[QCNL] PCCS returned HTTP 404: No cache data available for this platform.\n");
335+
qcnl_log(SGX_QL_LOG_ERROR, "[QCNL] Request failed for URL: %s (HTTP 404)\n", url);
332336
ret = SGX_QCNL_ERROR_STATUS_NO_CACHE_DATA;
333337
break;
334338
} else {
339+
qcnl_log(SGX_QL_LOG_ERROR, "[QCNL] Request failed for URL: %s (HTTP %lu)\n", url, dwStatus);
335340
ret = pccs_status_to_qcnl_error(dwStatus);
336341
break;
337342
}

QuoteGeneration/quote_wrapper/qgs/qgs_ql_logic.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ namespace intel { namespace sgx { namespace dcap { namespace qgs {
127127
tee_att_ret = tee_att_init_quote(ptr.get(), &qe_target_info, false, &hash_size, hash);
128128
if (TEE_ATT_SUCCESS != tee_att_ret) {
129129
QGS_LOG_ERROR("tee_att_init_quote return 0x%x\n", tee_att_ret);
130+
ptr.reset(); // Release context on failure to allow re-initialization on next request
130131
return {};
131132
} else {
132133
QGS_LOG_INFO("tee_att_init_quote return success\n");
@@ -194,6 +195,11 @@ namespace intel { namespace sgx { namespace dcap { namespace qgs {
194195
}
195196
// Only retry once when the return code is TEE_ATT_ATT_KEY_NOT_INITIALIZED
196197
} while (TEE_ATT_ATT_KEY_NOT_INITIALIZED == tee_att_ret && retry--);
198+
199+
// Release context on failure to allow re-initialization on next request
200+
if (resp_error_code != QGS_MSG_SUCCESS) {
201+
ptr.reset();
202+
}
197203
}
198204
if (resp_error_code == QGS_MSG_SUCCESS) {
199205
qgs_msg_error_ret = qgs_msg_gen_get_quote_resp(NULL, 0, quote_buf.data(), size, &p_resp, &resp_size);
@@ -370,7 +376,8 @@ namespace intel { namespace sgx { namespace dcap { namespace qgs {
370376
hash);
371377
if (TEE_ATT_SUCCESS != tee_att_ret) {
372378
QGS_LOG_ERROR("tee_att_init_quote return 0x%x\n", tee_att_ret);
373-
//ingnore failure
379+
ptr.reset(); // Release context on failure to allow re-initialization on next request
380+
return {};
374381
} else {
375382
QGS_LOG_INFO("tee_att_init_quote return success\n");
376383
}
@@ -429,6 +436,11 @@ namespace intel { namespace sgx { namespace dcap { namespace qgs {
429436
// Only retry once when the return code is TEE_ATT_ATT_KEY_NOT_INITIALIZED
430437
} while (TEE_ATT_ATT_KEY_NOT_INITIALIZED == tee_att_ret && retry--);
431438

439+
// Release context on failure to allow re-initialization on next request
440+
if (TEE_ATT_SUCCESS != tee_att_ret) {
441+
ptr.reset();
442+
}
443+
432444
return resp;
433445
} else {
434446
QGS_LOG_INFO("Not a legimit raw request, stop\n");

0 commit comments

Comments
 (0)