Skip to content

Commit

Permalink
🐛 紧急修复证书有效期检查 Timer 报错
Browse files Browse the repository at this point in the history
  • Loading branch information
luojunyuan committed Dec 2, 2024
1 parent 50a3c76 commit afa4ad9
Showing 1 changed file with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,41 @@ protected override void CheckRootCertificate()
platformService,
CertificateManager);

X509Certificate2? cer = CertificateManager.RootCertificatePackable;
if (cer is not null && DateTime.Now <= cer.NotAfter && cer.NotAfter <= DateTime.Now.AddMonths(1))
try
{
var interval = cer.NotAfter - DateTime.Now;

_certificateTimer = new System.Timers.Timer(interval)
X509Certificate2? cer = CertificateManager.RootCertificatePackable;
if (cer is not null &&
DateTime.Now <= cer.NotAfter && cer.NotAfter <= DateTime.Now.AddMilliseconds(int.MaxValue))
{
AutoReset = false,
};
var interval = cer.NotAfter - DateTime.Now;

_certificateTimer.Elapsed += async (_, _) =>
{
ICertificateManager.Constants.CheckRootCertificate(
platformService,
CertificateManager);
_certificateTimer = new System.Timers.Timer(interval)
{
AutoReset = false,
};

await StopProxyAsync();
await StartProxyImpl();
};
_certificateTimer.Start();
_certificateTimer.Elapsed += async (_, _) =>
{
try
{
ICertificateManager.Constants.CheckRootCertificate(
platformService,
CertificateManager);

await StopProxyAsync();
await StartProxyImpl();
}
catch (Exception e)
{
e.LogAndShowT(TAG, msg: "CheckRootCertificate in Timer.Elapsed Error");
}
};
_certificateTimer.Start();
}
}
catch (Exception e)
{
e.LogAndShowT(TAG, msg: "CheckRootCertificate Error");
}
}
}
Expand Down

0 comments on commit afa4ad9

Please sign in to comment.