Skip to content

Commit a9abf16

Browse files
committed
按证书过期时间来定时检查证书过期
1 parent 55a0ce6 commit a9abf16

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

proxy/include/proxy/proxy_server.hpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4984,6 +4984,12 @@ R"x*x*x(<html>
49844984
{
49854985
walk_certificate(m_option.ssl_cert_path_, certificates);
49864986

4987+
// 按过期时间排序.
4988+
std::sort(certificates.begin(), certificates.end(),
4989+
[](const certificate_file& a, const certificate_file& b) {
4990+
return a.expire_date_ < b.expire_date_;
4991+
});
4992+
49874993
for (const auto& ctx : certificates)
49884994
{
49894995
XLOG_DBG << "domain: '" << ctx.domain_
@@ -5063,11 +5069,33 @@ R"x*x*x(<html>
50635069
auto self = shared_from_this();
50645070
boost::system::error_code ec;
50655071

5072+
// 定时检查证书是否过期, 按照过期时间排序, 从最小时间开始检查.
50665073
while (!m_abort)
50675074
{
5068-
// 每隔 7 天检查一次证书是否过期.
5069-
m_timer.expires_from_now(std::chrono::days(7));
5075+
auto now = boost::posix_time::second_clock::universal_time();
5076+
std::chrono::seconds duration(std::chrono::days(1));
5077+
5078+
auto& certificates = *m_certificates;
5079+
5080+
for (const auto& ctx : certificates)
5081+
{
5082+
if (now > ctx.expire_date_)
5083+
{
5084+
XLOG_WARN << "domain: '" << ctx.domain_
5085+
<< "', cert: '" << ctx.cert_.filepath_.string()
5086+
<< "', key: '" << ctx.key_.filepath_.string()
5087+
<< "', dhparam: '" << ctx.dhparam_.filepath_.string()
5088+
<< "', pwd: '" << ctx.pwd_.filepath_.string()
5089+
<< "', expired: '" << ctx.expire_date_ << "'";
5090+
continue;
5091+
}
5092+
5093+
duration = std::chrono::seconds((ctx.expire_date_ - now).total_seconds());
5094+
break;
5095+
}
50705096

5097+
// 每隔 duration 检查一次证书是否过期.
5098+
m_timer.expires_from_now(duration);
50715099
co_await m_timer.async_wait(net_awaitable[ec]);
50725100
if (ec)
50735101
break;

0 commit comments

Comments
 (0)