Represent CRL stored in the cache.
Represent CRL stored in the cache.
예제 #1
0
		/// <exception cref="System.IO.IOException"></exception>
		public virtual X509Crl FindCrl(X509Certificate certificate, X509Certificate issuerCertificate)
		{
			OnlineCrlSource source = this.CachedSource ?? new OnlineCrlSource();
			string crlUrl = source.GetCrlUri(certificate);            

            if (crlUrl != null)
			{
                try
                {
                    CachedCRL cachedCrl = null;

                    string key = Hex.ToHexString(
                        DigestUtilities.CalculateDigest(DigestAlgorithm.SHA1.GetOid()
                        , Sharpen.Runtime.GetBytesForString(crlUrl)));

                    string pathCrl = Path.Combine("CRL", key);

                    DirectoryInfo dirCrl = new DirectoryInfo("CRL");

                    if (dirCrl.Exists)
                    {
                        FileInfo[] archivosCrl = dirCrl.GetFiles();

                        foreach (FileInfo a in archivosCrl)
                        {
                            if (a.Extension.Equals(".txt"))
                                continue;

                            if (a.Name.Equals(key))
                            {
                                cachedCrl = new CachedCRL()
                                {
                                    Crl = File.ReadAllBytes(a.FullName),
                                    Key = key
                                };

                                break;
                            }
                        }
                    }
                    else
                    {
                        dirCrl.Create();
                    }

                    if (cachedCrl == null)
                    {
                        LOG.Info("CRL not in cache");
                        return FindAndCacheCrlOnline(certificate, issuerCertificate, pathCrl);
                    }

                    X509CrlParser parser = new X509CrlParser();
                    X509Crl x509crl = parser.ReadCrl(cachedCrl.Crl);

                    if (x509crl.NextUpdate.Value.CompareTo(DateTime.Now) > 0)
                    {
                        LOG.Info("CRL in cache");
                        return x509crl;
                    }
                    else
                    {
                        LOG.Info("CRL expired");
                        return FindAndCacheCrlOnline(certificate, issuerCertificate, pathCrl);
                    }
                }
                catch (NoSuchAlgorithmException)
                {
                    LOG.Info("Cannot instantiate digest for algorithm SHA1 !?");
                }
                catch (CrlException)
                {
                    LOG.Info("Cannot serialize CRL");
                }
                catch (CertificateException)
                {
                    LOG.Info("Cannot instanciate X509 Factory");
                }
                catch (WebException)
                {
                    LOG.Info("Cannot connect to CRL URL");
                }
			}
			return null;
		}
예제 #2
0
        /// <exception cref="System.IO.IOException"></exception>
        public virtual X509Crl FindCrl(X509Certificate certificate, X509Certificate issuerCertificate)
        {
            OnlineCrlSource source = this.CachedSource ?? new OnlineCrlSource();
            string          crlUrl = source.GetCrlUri(certificate);

            if (crlUrl != null)
            {
                try
                {
                    CachedCRL cachedCrl = null;

                    string key = Hex.ToHexString(
                        DigestUtilities.CalculateDigest(DigestAlgorithm.SHA1.GetOid()
                                                        , Sharpen.Runtime.GetBytesForString(crlUrl)));

                    string pathCrl = Path.Combine("CRL", key);

                    DirectoryInfo dirCrl = new DirectoryInfo("CRL");

                    if (dirCrl.Exists)
                    {
                        FileInfo[] archivosCrl = dirCrl.GetFiles();

                        foreach (FileInfo a in archivosCrl)
                        {
                            if (a.Extension.Equals(".txt"))
                            {
                                continue;
                            }

                            if (a.Name.Equals(key))
                            {
                                cachedCrl = new CachedCRL()
                                {
                                    Crl = File.ReadAllBytes(a.FullName),
                                    Key = key
                                };

                                break;
                            }
                        }
                    }
                    else
                    {
                        dirCrl.Create();
                    }

                    if (cachedCrl == null)
                    {
                        LOG.Info("CRL not in cache");
                        return(FindAndCacheCrlOnline(certificate, issuerCertificate, pathCrl));
                    }

                    X509CrlParser parser  = new X509CrlParser();
                    X509Crl       x509crl = parser.ReadCrl(cachedCrl.Crl);

                    if (x509crl.NextUpdate.Value.CompareTo(DateTime.Now) > 0)
                    {
                        LOG.Info("CRL in cache");
                        return(x509crl);
                    }
                    else
                    {
                        LOG.Info("CRL expired");
                        return(FindAndCacheCrlOnline(certificate, issuerCertificate, pathCrl));
                    }
                }
                catch (NoSuchAlgorithmException)
                {
                    LOG.Info("Cannot instantiate digest for algorithm SHA1 !?");
                }
                catch (CrlException)
                {
                    LOG.Info("Cannot serialize CRL");
                }
                catch (CertificateException)
                {
                    LOG.Info("Cannot instanciate X509 Factory");
                }
                catch (WebException)
                {
                    LOG.Info("Cannot connect to CRL URL");
                }
            }
            return(null);
        }