证书安装安全警告解决方法?

发布于 2024-10-02 18:00:38 字数 273 浏览 4 评论 0原文

我有一些 C# 4.0 代码,尝试将 CA(.der 编码)证书安装到当前(我的)用户的“受信任的根证书颁发机构”存储中。我的小控制台应用程序在其他商店中静默运行,但对于此商店,会出现一个 GUI 弹出窗口“您即将安装来自证书颁发机构的证书...Windows 无法验证该证书实际上来自...吗?想要安装这个证书吗?”

这个消息框是一个问题,因为其想法是使用 MSI 自动部署应用程序,并在正确的位置默默地获取正确的证书。拥有模式框将杀死自动化部署。

如何在不出现破坏部署的消息框的情况下完成此安装?

I have some C# 4.0 code that attempts to install a CA (.der encoded) certificate into the "Trusted Root Certification Authorities" store for the current (My) user. My little console app runs silently against other stores, but for this store a GUI popup comes up "You are about to install a certificate from a certification authority... Windows cannot validate that the certificate is actually from..... Do you want to install this certificate?"

This messagebox is a problem because the idea is to automatically deploy the app with an MSI and silently get the right certs in the right place. Having a modal box will kill automated deployment.

How can this installation be done without a deployment-breaking messagebox?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

椒妓 2024-10-09 18:00:39

这听起来不合逻辑,但为了没有警告,您不应该将证书添加到当前用户的根证书存储中,而是添加到本地计算机的根证书中。您可以轻松验证是否

certmgr.exe -add -c t.cer -s -r currentUser root

会产生安全警告,但事实

certmgr.exe -add -c t.cer -s -r localMachine root

并非如此。

因此,如果您想在.NET中导入证书,那么相应的代码可能如下

using System;
using System.Security.Cryptography.X509Certificates;

namespace AddCertToRootStore {
    class Program {
        static void Main (string[] args) {
            X509Store store = new X509Store (StoreName.Root,
                                             StoreLocation.LocalMachine);
            store.Open (OpenFlags.ReadWrite);
            X509Certificate2Collection collection = new X509Certificate2Collection();
            X509Certificate2 cert = new X509Certificate2 (@"C:\Oleg\t.cer");
            byte[] encodedCert = cert.GetRawCertData();
            Console.WriteLine ("The certificate will be added to the Root...");
            store.Add (cert);
            Console.WriteLine("Verify, that the certificate are added successfully");
            Console.ReadKey ();
            Console.WriteLine ("The certificate will be removed from the Root");
            store.Remove (cert);
            store.Close ();
        }
    }
}

It can sound not logical, but to have no warning you should add the certificate not to the Root certificate store of the current user, but to the Root of the local machine instead. You can easy verify that

certmgr.exe -add -c t.cer -s -r currentUser root

produce the security warning, but

certmgr.exe -add -c t.cer -s -r localMachine root

not.

So if you want import a certificate in .NET then the corresponding code could be about following

using System;
using System.Security.Cryptography.X509Certificates;

namespace AddCertToRootStore {
    class Program {
        static void Main (string[] args) {
            X509Store store = new X509Store (StoreName.Root,
                                             StoreLocation.LocalMachine);
            store.Open (OpenFlags.ReadWrite);
            X509Certificate2Collection collection = new X509Certificate2Collection();
            X509Certificate2 cert = new X509Certificate2 (@"C:\Oleg\t.cer");
            byte[] encodedCert = cert.GetRawCertData();
            Console.WriteLine ("The certificate will be added to the Root...");
            store.Add (cert);
            Console.WriteLine("Verify, that the certificate are added successfully");
            Console.ReadKey ();
            Console.WriteLine ("The certificate will be removed from the Root");
            store.Remove (cert);
            store.Close ();
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文