我创建一个这样的证书请求:
certreq -new req.inf req-Revoked.req
certreq -submit -attrib "SAN:email=ttesting@Test.Domain&upn=1234567890@Test.Domain" -config Win2K8-64\Test-Win2K8-64-CA req-Revoked.req testerCert-Revoked.cer
certreq -accept testerCert-Revoked.cer
CertUtil -f -p testerCert -exportPFX -user My Testing.Tester.T.1234567890 testerCert-Revoked.pfx
CertUtil -delstore -user My Testing.Tester.T.1234567890
然后我通过以下方式撤销它:
CertUtil -revoke <SerialNumber_from_above_Cert>
然后我执行这段代码:
X509Certificate2 certificate = GetCertificate("testerCert-Revoked.pfx", "password"); // helper method loads the pfx from a file
X509Chain chain = new X509Chain();
chain.ChainPolicy.RevocationFlag = X509RevocationFlag.ExcludeRoot;
chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;
chain.ChainPolicy.VerificationTime = DateTime.Now;
chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 0, 0);
chain.ChainPolicy.VerificationFlags = X509VerificationFlags.NoFlag;
if (!chain.Build(certificate))
{
errorBuffer.Append("Could not build X.509 certificate chain:\r\n");
foreach (X509ChainStatus status in chain.ChainStatus)
{
errorBuffer.AppendFormat(" - {0}\r\n", status.StatusInformation);
}
throw new CryptographicException(errorBuffer.ToString());
}
chain.Build() 总是返回 true。但是既然证书被吊销了,那应该是False!我仔细检查了证书是否已被吊销,并且序列号是否列在服务器管理器中的吊销证书下。我已经仔细检查了服务器上的 CURL 分发点 url 和证书请求是否匹配。(它们是 LDAP 网址)。CertUtil 将中间 .cer 文件视为已撤销。但上面的 C# 代码没有。
这一切都在原始 CA 过期之前有效,IT 使用新证书重建了我的测试机器。我已经使用新的 CA 重新生成了证书,并且每个单元测试都再次工作,除了那些处理撤销的单元测试。过期的证书按预期工作,但未撤销的证书。
我不知道下一步该怎么做才能让这段代码再次工作,并希望得到一些帮助。谢谢!