X509CrlStoreSelector.cs :  » PDF » iTextSharp » Org » BouncyCastle » X509 » Store » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » PDF » iTextSharp 
iTextSharp » Org » BouncyCastle » X509 » Store » X509CrlStoreSelector.cs
using System;
using System.Collections;

using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Utilities;
using Org.BouncyCastle.Utilities.Date;
using Org.BouncyCastle.X509;
using Org.BouncyCastle.X509.Extension;

namespace Org.BouncyCastle.X509.Store{
  public class X509CrlStoreSelector
    : IX509Selector
  {
    // TODO Missing criteria?

    private X509Certificate certificateChecking;
    private DateTimeObject dateAndTime;
    private ICollection issuers;
    private BigInteger maxCrlNumber;
    private BigInteger minCrlNumber;

    private IX509AttributeCertificate attrCertChecking;
    private bool completeCrlEnabled;
    private bool deltaCrlIndicatorEnabled;
    private byte[] issuingDistributionPoint;
    private bool issuingDistributionPointEnabled;
    private BigInteger maxBaseCrlNumber;

    public X509CrlStoreSelector()
    {
    }

    public X509CrlStoreSelector(
      X509CrlStoreSelector o)
    {
      this.certificateChecking = o.CertificateChecking;
      this.dateAndTime = o.DateAndTime;
      this.issuers = o.Issuers;
      this.maxCrlNumber = o.MaxCrlNumber;
      this.minCrlNumber = o.MinCrlNumber;

      this.deltaCrlIndicatorEnabled = o.DeltaCrlIndicatorEnabled;
      this.completeCrlEnabled = o.CompleteCrlEnabled;
      this.maxBaseCrlNumber = o.MaxBaseCrlNumber;
      this.attrCertChecking = o.AttrCertChecking;
      this.issuingDistributionPointEnabled = o.IssuingDistributionPointEnabled;
      this.issuingDistributionPoint = o.IssuingDistributionPoint;
    }

    public virtual object Clone()
    {
      return new X509CrlStoreSelector(this);
    }

    public X509Certificate CertificateChecking
    {
      get { return certificateChecking; }
      set { certificateChecking = value; }
    }

    public DateTimeObject DateAndTime
    {
      get { return dateAndTime; }
      set { dateAndTime = value; }
    }

    /// <summary>
    /// An <code>ICollection</code> of <code>X509Name</code> objects
    /// </summary>
    public ICollection Issuers
    {
      get { return new ArrayList(issuers); }
      set { issuers = new ArrayList(value); }
    }

    public BigInteger MaxCrlNumber
    {
      get { return maxCrlNumber; }
      set { maxCrlNumber = value; }
    }

    public BigInteger MinCrlNumber
    {
      get { return minCrlNumber; }
      set { minCrlNumber = value; }
    }

    /**
     * The attribute certificate being checked. This is not a criterion.
     * Rather, it is optional information that may help a {@link X509Store} find
     * CRLs that would be relevant when checking revocation for the specified
     * attribute certificate. If <code>null</code> is specified, then no such
     * optional information is provided.
     *
     * @param attrCert the <code>IX509AttributeCertificate</code> being checked (or
     *             <code>null</code>)
     * @see #getAttrCertificateChecking()
     */
    public IX509AttributeCertificate AttrCertChecking
    {
      get { return attrCertChecking; }
      set { this.attrCertChecking = value; }
    }

    /**
     * If <code>true</code> only complete CRLs are returned. Defaults to
     * <code>false</code>.
     *
     * @return <code>true</code> if only complete CRLs are returned.
     */
    public bool CompleteCrlEnabled
    {
      get { return completeCrlEnabled; }
      set { this.completeCrlEnabled = value; }
    }

    /**
     * Returns if this selector must match CRLs with the delta CRL indicator
     * extension set. Defaults to <code>false</code>.
     *
     * @return Returns <code>true</code> if only CRLs with the delta CRL
     *         indicator extension are selected.
     */
    public bool DeltaCrlIndicatorEnabled
    {
      get { return deltaCrlIndicatorEnabled; }
      set { this.deltaCrlIndicatorEnabled = value; }
    }

    /**
     * The issuing distribution point.
     * <p>
     * The issuing distribution point extension is a CRL extension which
     * identifies the scope and the distribution point of a CRL. The scope
     * contains among others information about revocation reasons contained in
     * the CRL. Delta CRLs and complete CRLs must have matching issuing
     * distribution points.</p>
     * <p>
     * The byte array is cloned to protect against subsequent modifications.</p>
     * <p>
     * You must also enable or disable this criteria with
     * {@link #setIssuingDistributionPointEnabled(bool)}.</p>
     *
     * @param issuingDistributionPoint The issuing distribution point to set.
     *                                 This is the DER encoded OCTET STRING extension value.
     * @see #getIssuingDistributionPoint()
     */
    public byte[] IssuingDistributionPoint
    {
      get { return Arrays.Clone(issuingDistributionPoint); }
      set { this.issuingDistributionPoint = Arrays.Clone(value); }
    }

    /**
     * Whether the issuing distribution point criteria should be applied.
     * Defaults to <code>false</code>.
     * <p>
     * You may also set the issuing distribution point criteria if not a missing
     * issuing distribution point should be assumed.</p>
     *
     * @return Returns if the issuing distribution point check is enabled.
     */
    public bool IssuingDistributionPointEnabled
    {
      get { return issuingDistributionPointEnabled; }
      set { this.issuingDistributionPointEnabled = value; }
    }

    /**
     * The maximum base CRL number. Defaults to <code>null</code>.
     *
     * @return Returns the maximum base CRL number.
     * @see #setMaxBaseCRLNumber(BigInteger)
     */
    public BigInteger MaxBaseCrlNumber
    {
      get { return maxBaseCrlNumber; }
      set { this.maxBaseCrlNumber = value; }
    }

    public virtual bool Match(
      object obj)
    {
      X509Crl c = obj as X509Crl;

      if (c == null)
        return false;

      if (dateAndTime != null)
      {
        DateTime dt = dateAndTime.Value;
        DateTime tu = c.ThisUpdate;
        DateTimeObject nu = c.NextUpdate;

        if (dt.CompareTo(tu) < 0 || nu == null || dt.CompareTo(nu.Value) >= 0)
          return false;
      }

      if (issuers != null)
      {
        X509Name i = c.IssuerDN;

        bool found = false;

        foreach (X509Name issuer in issuers)
        {
          if (issuer.Equivalent(i, true))
          {
            found = true;
            break;
          }
        }

        if (!found)
          return false;
      }

      if (maxCrlNumber != null || minCrlNumber != null)
      {
        Asn1OctetString extVal = c.GetExtensionValue(X509Extensions.CrlNumber);
        if (extVal == null)
          return false;

        BigInteger cn = CrlNumber.GetInstance(
          X509ExtensionUtilities.FromExtensionValue(extVal)).PositiveValue;

        if (maxCrlNumber != null && cn.CompareTo(maxCrlNumber) > 0)
          return false;

        if (minCrlNumber != null && cn.CompareTo(minCrlNumber) < 0)
          return false;
      }

      DerInteger dci = null;
      try
      {
        Asn1OctetString bytes = c.GetExtensionValue(X509Extensions.DeltaCrlIndicator);
        if (bytes != null)
        {
          dci = DerInteger.GetInstance(X509ExtensionUtilities.FromExtensionValue(bytes));
        }
      }
      catch (Exception)
      {
        return false;
      }

      if (dci == null)
      {
        if (DeltaCrlIndicatorEnabled)
          return false;
      }
      else
      {
        if (CompleteCrlEnabled)
          return false;

        if (maxBaseCrlNumber != null && dci.PositiveValue.CompareTo(maxBaseCrlNumber) > 0)
          return false;
      }

      if (issuingDistributionPointEnabled)
      {
        Asn1OctetString idp = c.GetExtensionValue(X509Extensions.IssuingDistributionPoint);
        if (issuingDistributionPoint == null)
        {
          if (idp != null)
            return false;
        }
        else
        {
          if (!Arrays.AreEqual(idp.GetOctets(), issuingDistributionPoint))
            return false;
        }
      }

      return true;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.