Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# verify certificate in CRL list

Tags:

c#

certificate

How can I programmatically check if a certain certificate is revoked from its CA CRL list?

I'm doing this:

X509Chain ch = new X509Chain();
ch.ChainPolicy.RevocationMode = X509RevocationMode.Online;
ch.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain;
ch.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(1000);
ch.ChainPolicy.VerificationFlags = X509VerificationFlags.NoFlag;
ch.ChainPolicy.VerificationTime = DateTime.Now;
ch.Build(certificate);
foreach (X509ChainStatus s in ch.ChainStatus)
{
    string str = s.Status.ToString();
    Console.WriteLine("str: " + str);
}
X509Store store = new X509Store(StoreName.Disallowed, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadWrite);
bool isRevoked = store.Certificates.Contains(certificate);
store.Close();
return !isRevoked && certificate.Verify();

And I get "str: RevokedStatusUnknown". Only if I wait many hours after I revoke the certificate -> the status is returned as Revoked, despite the fact that I publish the CRL immediately after revoking the certificate. Why it does not access the CRL instantaneously?

like image 298
user252816 Avatar asked Jan 27 '10 15:01

user252816


1 Answers

Try running the following MS command.

   certutil -urlcache * delete

Windows caches certificate revocation statuses for a certain period, using the above command will flush the cache.

like image 154
g01d Avatar answered Oct 12 '22 07:10

g01d