in src/dcap_provider.cpp [293:336]
bool get_cert_cache_expiration_time(const string& cache_max_age, const string& url, time_t& expiration_time)
{
time_t max_age = 0;
tm* max_age_s = localtime(&max_age);
int cache_time_seconds = 0;
constexpr int MAX_CACHE_TIME_SECONDS = 86400;
try
{
cache_time_seconds = stoi(cache_max_age);
if (cache_time_seconds > MAX_CACHE_TIME_SECONDS)
{
log(SGX_QL_LOG_ERROR,
"Caching control '%d' larger than maximum '%d' seconds. Collateral will not be cached",
cache_time_seconds,
MAX_CACHE_TIME_SECONDS);
return false;
}
}
catch (const std::invalid_argument& e)
{
log(SGX_QL_LOG_ERROR,
"Invalid argument thrown when parsing cache-control. Header text: '%s' Error: '%s'. Collateral will not be cached",
cache_max_age.c_str(),
e.what());
return false;
}
catch (const std::out_of_range& e)
{
log(SGX_QL_LOG_ERROR,
"Invalid argument thrown when parsing cache-control. Header "
"text: '%s' Error: '%s'. Collateral will not be cached",
cache_max_age.c_str(),
e.what());
return false;
}
max_age_s->tm_sec += cache_time_seconds;
expiration_time = time(nullptr) + mktime(max_age_s);
log(SGX_QL_LOG_INFO,
"Caching collateral '%s' for '%d' seconds",
url.c_str(),
cache_time_seconds);
return true;
}