diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index 1c3ec0a9c..7c7f5a98c 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -1367,6 +1367,13 @@ bool Utility::PathExists(const String& path) return fs::exists(fs::path(path.Begin(), path.End()), ec) && !ec; } +time_t Utility::GetFileCreationTime(const String& path) +{ + namespace fs = boost::filesystem; + + return fs::last_write_time(boost::lexical_cast(path)); +} + Value Utility::LoadJsonFile(const String& path) { std::ifstream fp; diff --git a/lib/base/utility.hpp b/lib/base/utility.hpp index 0fb216d9e..c2d1a0857 100644 --- a/lib/base/utility.hpp +++ b/lib/base/utility.hpp @@ -112,6 +112,7 @@ public: static tm LocalTime(time_t ts); static bool PathExists(const String& path); + static time_t GetFileCreationTime(const String& path); static void Remove(const String& path); static void RemoveDirRecursive(const String& path); diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 02a5eef03..3a302544b 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -432,11 +432,31 @@ void ApiListener::ListenerCoroutineProc(boost::asio::yield_context yc, const Sha auto& io (IoEngine::Get().GetIoContext()); + time_t lastModified = -1; + const String crlPath = GetCrlPath(); + + if (!crlPath.IsEmpty()) { + lastModified = Utility::GetFileCreationTime(crlPath); + } + for (;;) { try { - auto sslConn (Shared::Make(io, *sslContext)); + asio::ip::tcp::socket socket (io); - server->async_accept(sslConn->lowest_layer(), yc); + server->async_accept(socket.lowest_layer(), yc); + + if (!crlPath.IsEmpty()) { + time_t currentCreationTime = Utility::GetFileCreationTime(crlPath); + + if (lastModified != currentCreationTime) { + UpdateSSLContext(); + + lastModified = currentCreationTime; + } + } + + auto sslConn (Shared::Make(io, *sslContext)); + sslConn->lowest_layer() = std::move(socket); auto strand (Shared::Make(io));