From 78feece7bfcaf5210fee736d94bddc11deec0a4c Mon Sep 17 00:00:00 2001 From: Aigio Liu Date: Wed, 22 Jun 2022 21:49:53 +0800 Subject: [PATCH] fix TrustRootCertificate --- .../Services/ICertificateManager.cs | 4 ++-- .../Implementation/CertificateManagerImpl.cs | 22 ++++++++++++++++--- .../Pages/CommunityProxyPageViewModel.cs | 3 ++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/ST.Client.ReverseProxy/Services/ICertificateManager.cs b/src/ST.Client.ReverseProxy/Services/ICertificateManager.cs index 4971b468d..74fd05d3b 100644 --- a/src/ST.Client.ReverseProxy/Services/ICertificateManager.cs +++ b/src/ST.Client.ReverseProxy/Services/ICertificateManager.cs @@ -76,9 +76,9 @@ public interface ICertificateManager string? GetCerFilePathGeneratedWhenNoFileExists(); /// - /// 信任根证书 + /// 由平台实现的信任根证书引导,有 Root 权限将尝试执行信任,否则则 UI 引导,跳转网页或弹窗 /// - void TrustRootCertificate(); + void PlatformTrustRootCertificateGuide(); /// /// 安装根证书,如果没有证书将生成一个新的 diff --git a/src/ST.Client.ReverseProxy/Services/Implementation/CertificateManagerImpl.cs b/src/ST.Client.ReverseProxy/Services/Implementation/CertificateManagerImpl.cs index 6bc0822f8..275385336 100644 --- a/src/ST.Client.ReverseProxy/Services/Implementation/CertificateManagerImpl.cs +++ b/src/ST.Client.ReverseProxy/Services/Implementation/CertificateManagerImpl.cs @@ -86,13 +86,29 @@ abstract partial class CertificateManagerImpl } } - /// - public void TrustRootCertificate() + void TrustRootCertificate() { try { SharedTrustRootCertificate(); + } +#if DEBUG + catch (Exception e) + { + e.LogAndShowT(TAG, msg: "TrustRootCertificate Error"); + } +#else + catch { } +#endif + PlatformTrustRootCertificateGuide(); + } + + /// + public void PlatformTrustRootCertificateGuide() + { + try + { if (OperatingSystem2.IsMacOS()) { TrustRootCertificateMacOS(); @@ -105,7 +121,7 @@ abstract partial class CertificateManagerImpl #if DEBUG catch (Exception e) { - e.LogAndShowT(TAG, msg: "TrustRootCertificate Error"); + e.LogAndShowT(TAG, msg: "PlatformTrustRootCertificateGuide Error"); } #else catch { } diff --git a/src/ST.Client/UI/ViewModels/Pages/CommunityProxyPageViewModel.cs b/src/ST.Client/UI/ViewModels/Pages/CommunityProxyPageViewModel.cs index cd35d120d..81963f6b4 100644 --- a/src/ST.Client/UI/ViewModels/Pages/CommunityProxyPageViewModel.cs +++ b/src/ST.Client/UI/ViewModels/Pages/CommunityProxyPageViewModel.cs @@ -127,7 +127,8 @@ namespace System.Application.UI.ViewModels public void TrustCer_OnClick() { - reverseProxyService.CertificateManager.TrustRootCertificate(); + reverseProxyService.CertificateManager.GetCerFilePathGeneratedWhenNoFileExists(); + reverseProxyService.CertificateManager.PlatformTrustRootCertificateGuide(); } public override void Activation()