【问题标题】:x509 certificate not recognized in Windows server 2008 R2x509 证书在 Windows server 2008 R2 中无法识别
【发布时间】:2019-03-28 09:53:57
【问题描述】:

我从 NeutralUS CA 获得了一份数字证书。我已经安装在我的本地系统中。我在 MMC 的个人证书下找到了已安装的证书,并且我的应用程序使用此证书进行了验证。我刚刚将我的应用程序转移到我们的生产服务器并安装了相同的证书。在这里,我还可以在 Windows Server 2008 R2 上的 MMC 中的个人证书下看到我的证书。但是当我尝试加载带有序列号的证书时,它显示存储证书计数为零。你能告诉我会是什么原因吗?为什么无法从个人文件夹中识别。我的个人文件夹中只有一张证书。

var clientCertStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);

clientCertStore.Open(OpenFlags.OpenExistingOnly & OpenFlags.ReadOnly);
base.Data.ErrorLog.Append("Certificates Count : " + clientCertStore.Certificates.Count);

我只是将数据记录到一个文本文件中...它将clientCertStore.Certificates.Count 设为 0。

【问题讨论】:

  • 您的证书会不会安装在 StoreLocation.LocalMachine 上?
  • 您粘贴的代码必须在正确的用户帐户下运行,以便查询该用户的个人商店。否则,它会读取完全不同的位置,并且可能什么也不返回。

标签: c# x509certificate


【解决方案1】:

我从 NeutralUS CA 获得了一份数字证书。我已经安装在我的本地系统中。

安装了什么?最终实体证书是否已安装并受信任?还是 NeutralUS CA?

我在网上找不到可供下载的 NeutralUS CA。这很不寻常。


你能告诉我是什么原因吗?为什么无法从个人文件夹中识别。

我怀疑这是帐户的问题(但这只是猜测)。证书安装在什么帐号下,程序在什么帐号下运行?


我真的很鄙视 Java 和 .Net 让使用该死的证书变得多么困难。这是我用来避免在那些该死的商店上浪费时间的代码。它允许您直接从文件系统或应用程序包加载。它还使用 Windows 携带的数百个 CA 和下属。

static bool VerifyServerCertificate(object sender, X509Certificate certificate,
    X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
    try
    {
        String CA_FILE = "ca-cert.der";
        X509Certificate2 ca = new X509Certificate2();
        ca.Import(CA_FILE);

        X509Chain chain2 = new X509Chain();
        chain2.ChainPolicy.ExtraStore.Add(ca);

        // Check all properties
        chain2.ChainPolicy.VerificationFlags = X509VerificationFlags.NoFlag;

        // This setup does not have revocation information
        chain2.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;

        // Are there any failures from building the chain?
        chain2.Build(new X509Certificate2(certificate));
        if (chain2.ChainStatus.Length == 0)
            return true;

        // Verify the status is NoError
        bool result = chain2.ChainStatus[0].Status == X509ChainStatusFlags.NoError;
        Debug.Assert(result == true);

        return result;
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex);
    }

    return false;
}

而且我还没有弄清楚如何将作为参数传入的原始X509Chain chain 设置为我想在调用回调VerifyServerCertificate 之前使用的X509Chain chain2之前

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-18
    • 2013-03-15
    • 2011-06-15
    • 1970-01-01
    • 2015-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多