我試圖使用HttpClientHandler.ServerCertificateCustomValidationCallback
驗證客戶端證書。我用我的ChainPolicy
參數構建了我的x509chain
。如何使用本地CRL文件(C#)在驗證過程中檢查客戶端證書吊銷
我本地有我的CRL(.pem)文件,我想將其添加到撤銷過程。
我正在考慮做一些類似CRL validation,用distributionPoint oid導入我的X509Certificate
和X509Extension
,但我很難理解它。
下面是一段我的回調代碼
private static Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool>
ServerCertificateCustomValidationCallback()
{
return (sender, cert, chain, sslPolicyErrors) =>
{
X509Certificate2 ca = new X509Certificate2(@"pathToCa\\ca.crt");
X509Chain chai = new X509Chain();
chai.ChainPolicy.ExtraStore.Add(ca);
chai.ChainPolicy.RevocationFlag = X509RevocationFlag.ExcludeRoot;
chai.ChainPolicy.RevocationMode = X509RevocationMode.Online;
chai.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags;
chai.ChainPolicy.VerificationTime = DateTime.Now;
try
{
if (!chai.Build(cert))
{
return false;
}
foreach (X509ChainStatus status in chai.ChainStatus)
{
if (status.Status == X509ChainStatusFlags.UntrustedRoot) continue;
if (status.Status == X509ChainStatusFlags.OfflineRevocation) continue;
if (status.Status == X509ChainStatusFlags.RevocationStatusUnknown) continue;
return false;
}
}
catch (Exception e)
{
throw e;
}
return true;
};
}
感謝您的幫助&澄清
最新問題? –
@Mike_G對不起,這是我的第一篇文章。我如何在撤銷過程中添加我的本地CRL文件? –