Skip to content
Snippets Groups Projects
Commit 4d5d783a authored by Guillaume Roguez's avatar Guillaume Roguez
Browse files

ringaccount: modify DhParams loading method

- changed logging strings
- factoring clock computation

Change-Id: Idae00b3e0bb5f929c8ad23cedb0ca3095f10d05b
Tuleap: #452
parent a7b0e236
Branches
Tags
No related merge requests found
......@@ -72,6 +72,7 @@
namespace ring {
using sip_utils::CONST_PJ_STR;
using std::chrono::system_clock;
static constexpr int ICE_COMPONENTS {1};
static constexpr int ICE_COMP_SIP_TRANSPORT {0};
......@@ -1224,20 +1225,21 @@ tls::DhParams
RingAccount::loadDhParams(const std::string path)
{
try {
auto modified = fileutils::writeTime(path);
RING_WARN("modification date: %ld", std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now() - modified).count());
if (modified > std::chrono::system_clock::now() - std::chrono::hours(24 * 3))
// writeTime throw exception if file doesn't exist
auto duration = system_clock::now() - fileutils::writeTime(path);
if (duration >= std::chrono::hours(24 * 3)) // file is valid only 3 days
throw std::runtime_error("too old file");
RING_DBG("Loading DhParams from file '%s'", path.c_str());
return {fileutils::loadFile(path)};
else {
RING_WARN("file is too old");
throw std::runtime_error("file is too old");
}
} catch (...) {
} catch (const std::exception& e) {
RING_WARN("Failed to load DhParams file '%s': %s", path.c_str(), e.what());
auto params = tls::DhParams::generate();
try {
fileutils::saveFile(path, params.serialize(), 0600);
} catch (...) {
RING_WARN("error saving dh params");
RING_DBG("Saved DhParams to file '%s'", path.c_str());
} catch (const std::exception& ex) {
RING_WARN("Failed to save DhParams in file '%s': %s", path.c_str(), ex.what());
}
return params;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment