V2TBSCertListGenerator.cs :  » PDF » iTextSharp » Org » BouncyCastle » Asn1 » X509 » 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 » Asn1 » X509 » V2TBSCertListGenerator.cs
using System;
using System.Collections;
using System.IO;

namespace Org.BouncyCastle.Asn1.X509{
    /**
     * Generator for Version 2 TbsCertList structures.
     * <pre>
     *  TbsCertList  ::=  Sequence  {
     *       version                 Version OPTIONAL,
     *                                    -- if present, shall be v2
     *       signature               AlgorithmIdentifier,
     *       issuer                  Name,
     *       thisUpdate              Time,
     *       nextUpdate              Time OPTIONAL,
     *       revokedCertificates     Sequence OF Sequence  {
     *            userCertificate         CertificateSerialNumber,
     *            revocationDate          Time,
     *            crlEntryExtensions      Extensions OPTIONAL
     *                                          -- if present, shall be v2
     *                                 }  OPTIONAL,
     *       crlExtensions           [0]  EXPLICIT Extensions OPTIONAL
     *                                          -- if present, shall be v2
     *                                 }
     * </pre>
     *
     * <b>Note: This class may be subject to change</b>
     */
    public class V2TbsCertListGenerator
    {
        private DerInteger      version = new DerInteger(1);
        private AlgorithmIdentifier  signature;
        private X509Name      issuer;
        private Time        thisUpdate, nextUpdate;
        private X509Extensions    extensions;
        private ArrayList      crlEntries;

    public V2TbsCertListGenerator()
        {
        }

    public void SetSignature(
            AlgorithmIdentifier signature)
        {
            this.signature = signature;
        }

    public void SetIssuer(
            X509Name issuer)
        {
            this.issuer = issuer;
        }

    public void SetThisUpdate(
            DerUtcTime thisUpdate)
        {
            this.thisUpdate = new Time(thisUpdate);
        }

    public void SetNextUpdate(
            DerUtcTime nextUpdate)
        {
            this.nextUpdate = (nextUpdate != null)
        ?  new Time(nextUpdate)
        :  null;
        }

    public void SetThisUpdate(
            Time thisUpdate)
        {
            this.thisUpdate = thisUpdate;
        }

    public void SetNextUpdate(
            Time nextUpdate)
        {
            this.nextUpdate = nextUpdate;
        }

    public void AddCrlEntry(
      Asn1Sequence crlEntry)
    {
      if (crlEntries == null)
      {
        crlEntries = new ArrayList();
      }

      crlEntries.Add(crlEntry);
    }

    public void AddCrlEntry(DerInteger userCertificate, DerUtcTime revocationDate, int reason)
    {
      AddCrlEntry(userCertificate, new Time(revocationDate), reason);
    }

    public void AddCrlEntry(DerInteger userCertificate, Time revocationDate, int reason)
    {
      AddCrlEntry(userCertificate, revocationDate, reason, null);
    }

    public void AddCrlEntry(DerInteger userCertificate, Time revocationDate, int reason,
      DerGeneralizedTime invalidityDate)
    {
      ArrayList extOids = new ArrayList();
      ArrayList extValues = new ArrayList();

      if (reason != 0)
      {
        CrlReason crlReason = new CrlReason(reason);

        try
        {
          extOids.Add(X509Extensions.ReasonCode);
          extValues.Add(new X509Extension(false, new DerOctetString(crlReason.GetEncoded())));
        }
        catch (IOException e)
        {
          throw new ArgumentException("error encoding reason: " + e);
        }
      }

      if (invalidityDate != null)
      {
        try
        {
          extOids.Add(X509Extensions.InvalidityDate);
          extValues.Add(new X509Extension(false, new DerOctetString(invalidityDate.GetEncoded())));
        }
        catch (IOException e)
        {
          throw new ArgumentException("error encoding invalidityDate: " + e);
        }
      }

      if (extOids.Count != 0)
      {
        AddCrlEntry(userCertificate, revocationDate, new X509Extensions(extOids, extValues));
      }
      else
      {
        AddCrlEntry(userCertificate, revocationDate, null);
      }
    }

    public void AddCrlEntry(DerInteger userCertificate, Time revocationDate, X509Extensions extensions)
    {
      Asn1EncodableVector v = new Asn1EncodableVector(
        userCertificate, revocationDate);

      if (extensions != null)
      {
        v.Add(extensions);
      }

      AddCrlEntry(new DerSequence(v));
    }

    public void SetExtensions(
            X509Extensions extensions)
        {
            this.extensions = extensions;
        }

    public TbsCertificateList GenerateTbsCertList()
        {
            if ((signature == null) || (issuer == null) || (thisUpdate == null))
            {
                throw new InvalidOperationException("Not all mandatory fields set in V2 TbsCertList generator.");
            }

      Asn1EncodableVector v = new Asn1EncodableVector(
        version, signature, issuer, thisUpdate);

      if (nextUpdate != null)
            {
                v.Add(nextUpdate);
            }

      // Add CRLEntries if they exist
            if (crlEntries != null)
            {
        Asn1Sequence[] certs = (Asn1Sequence[]) crlEntries.ToArray(typeof(Asn1Sequence));

        v.Add(new DerSequence(certs));
            }

      if (extensions != null)
            {
                v.Add(new DerTaggedObject(0, extensions));
            }

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