2
我有證書驗證問題。我有.perm文件女巫是鏈證書文件(裏面有多個BEGIN和END證書)。來自文件的ChainCertificate
我嘗試導入收藏證書,但進口收集後的長度爲1
X509Certificate2Collection collection = new X509Certificate2Collection();
collection.Import(certpath);
我沒有看到任何有趣的選項
X509Chain chain2 = new X509Chain();
我得到驗證的回報虛假的,我相信原因是並非所有的證書都已被加載。
下面是我的全部驗證方法
private static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
try
{
string certpath = "actual path";
X509Certificate2Collection collection = new X509Certificate2Collection();
collection.Import(certpath);
X509Chain chain2 = new X509Chain();
foreach(X509Certificate2 c in collection)
{
chain2.ChainPolicy.ExtraStore.Add(c);
}
// Check all properties
chain2.ChainPolicy.VerificationFlags = X509VerificationFlags.NoFlag;
// This setup does not have revocation information
chain2.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
// Build the chain
chain2.Build(new X509Certificate2(certificate));
// Are there any failures from building the chain?
if (chain2.ChainStatus.Length == 0)
return true;
// If there is a status, verify the status is NoError
bool result = chain2.ChainStatus[0].Status == X509ChainStatusFlags.NoError;
return result;
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
return false;
}
我編輯了你的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 –