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