in src/dcap_provider.cpp [992:1067]
static quote3_error_t get_collateral(
CollateralTypes collateral_type,
std::string url,
const char *issuer_chain_header,
std::vector<uint8_t>& response_body,
std::string& issuer_chain,
const std::string* const request_body = nullptr)
{
quote3_error_t retval = SGX_QL_ERROR_UNEXPECTED;
std::string friendly_name = get_collateral_friendly_name(collateral_type);
try
{
std::string issuer_chain_cache_name = get_issuer_chain_cache_name(url);
if (auto cache_hit_collateral = try_cache_get(url))
{
if (auto cache_hit_issuer_chain = try_cache_get(issuer_chain_cache_name))
{
log(SGX_QL_LOG_INFO,
"Fetching %s from cache: '%s'.",
friendly_name.c_str(),
url.c_str());
response_body = *cache_hit_collateral;
issuer_chain = std::string(cache_hit_issuer_chain->begin(), cache_hit_issuer_chain->end());
return SGX_QL_SUCCESS;
}
}
log(SGX_QL_LOG_INFO,
"Fetching %s from remote server: '%s'.",
friendly_name.c_str(),
url.c_str());
const auto curl_operation = curl_easy::create(url, request_body);
curl_operation->perform();
response_body = curl_operation->get_body();
auto get_issuer_chain_operation =
get_unescape_header(*curl_operation, issuer_chain_header, &issuer_chain);
retval = convert_to_intel_error(get_issuer_chain_operation);
if (retval == SGX_QL_SUCCESS)
{
std::string cache_control;
auto get_cache_header_operation = get_unescape_header(*curl_operation, headers::CACHE_CONTROL, &cache_control);
retval = convert_to_intel_error(get_cache_header_operation);
if (retval == SGX_QL_SUCCESS)
{
// Update the cache
time_t expiry = 0;
if (get_cache_expiration_time(cache_control, url, expiry))
{
local_cache_add(url, expiry, response_body.size(), response_body.data());
local_cache_add(issuer_chain_cache_name, expiry, issuer_chain.size(), issuer_chain.c_str());
}
}
}
return retval;
}
catch (const std::runtime_error& error)
{
log(SGX_QL_LOG_WARNING,
"Runtime exception thrown, error: %s",
error.what());
// Swallow adding file to cache. Library can
// operate without caching
return retval;
}
catch (const curl_easy::error& error)
{
log(SGX_QL_LOG_ERROR,
"curl error thrown, error code: %x: %s",
error.code,
error.what());
return error.code == CURLE_HTTP_RETURNED_ERROR
? SGX_QL_NO_QUOTE_COLLATERAL_DATA
: SGX_QL_NETWORK_ERROR;
}
}