Skip to content

API: Update the ssl context after each accepting incoming connection #8515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/base/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,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<fs::path>(path));
}

Value Utility::LoadJsonFile(const String& path)
{
std::ifstream fp;
Expand Down
1 change: 1 addition & 0 deletions lib/base/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class Utility
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);
Expand Down
24 changes: 22 additions & 2 deletions lib/remote/apilistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<AsioTlsStream>::Make(io, *sslContext));
asio::ip::tcp::socket socket (io);

server->async_accept(socket.lowest_layer(), yc);

if (!crlPath.IsEmpty()) {
time_t currentCreationTime = Utility::GetFileCreationTime(crlPath);

server->async_accept(sslConn->lowest_layer(), yc);
if (lastModified != currentCreationTime) {
UpdateSSLContext();

lastModified = currentCreationTime;
}
}

auto sslConn (Shared<AsioTlsStream>::Make(io, *sslContext));
sslConn->lowest_layer() = std::move(socket);

auto strand (Shared<asio::io_context::strand>::Make(io));

Expand Down