diff --git a/QuickLook.Plugin/QuickLook.Plugin.CertViewer/CertLoadResult.cs b/QuickLook.Plugin/QuickLook.Plugin.CertViewer/CertLoadResult.cs index a23a49d..1ce728d 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.CertViewer/CertLoadResult.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.CertViewer/CertLoadResult.cs @@ -8,15 +8,17 @@ internal sealed class CertLoadResult public X509Certificate2 Certificate { get; } public string Message { get; } public string RawContent { get; } + public bool NeedsPassword { get; } - public CertLoadResult(bool success, X509Certificate2 certificate, string message, string rawContent) + public CertLoadResult(bool success, X509Certificate2 certificate, string message, string rawContent, bool needsPassword = false) { Success = success; Certificate = certificate; Message = message; RawContent = rawContent; + NeedsPassword = needsPassword; } - public static CertLoadResult From(bool success, X509Certificate2 certificate, string message, string rawContent) - => new CertLoadResult(success, certificate, message, rawContent); + public static CertLoadResult From(bool success, X509Certificate2 certificate, string message, string rawContent, bool needsPassword = false) + => new CertLoadResult(success, certificate, message, rawContent, needsPassword); } diff --git a/QuickLook.Plugin/QuickLook.Plugin.CertViewer/CertUtils.cs b/QuickLook.Plugin/QuickLook.Plugin.CertViewer/CertUtils.cs index 8445a69..f2ca99a 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.CertViewer/CertUtils.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.CertViewer/CertUtils.cs @@ -14,7 +14,7 @@ internal static class CertUtils /// - Message: an informational or error message /// - RawContent: original file text or hex when parsing failed /// - public static CertLoadResult TryLoadCertificate(string path) + public static CertLoadResult TryLoadCertificate(string path, string password = null) { try { @@ -24,12 +24,16 @@ internal static class CertUtils { try { - var cert = new X509Certificate2(path); + var cert = !string.IsNullOrEmpty(password) + ? new X509Certificate2(path, password) + : new X509Certificate2(path); return new CertLoadResult(true, cert, string.Empty, null); } catch (Exception ex) { - return new CertLoadResult(false, null, "Failed to load PFX/P12: " + ex.Message, null); + var isPasswordError = ex is System.Security.Cryptography.CryptographicException || + (ex.Message?.IndexOf("password", StringComparison.OrdinalIgnoreCase) >= 0); + return new CertLoadResult(false, null, "Failed to load PFX/P12: " + ex.Message, null, isPasswordError); } } diff --git a/QuickLook.Plugin/QuickLook.Plugin.CertViewer/CertViewerControl.xaml b/QuickLook.Plugin/QuickLook.Plugin.CertViewer/CertViewerControl.xaml index 57a0e0b..83aa460 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.CertViewer/CertViewerControl.xaml +++ b/QuickLook.Plugin/QuickLook.Plugin.CertViewer/CertViewerControl.xaml @@ -12,29 +12,41 @@ + - - - - - - + + + + +