GetInstance() public static method

public static GetInstance ( PkixParameters pkixParams ) : PkixBuilderParameters
pkixParams PkixParameters
return PkixBuilderParameters
        internal static PkixCertPath ProcessAttrCert1(IX509AttributeCertificate attrCert, PkixParameters pkixParams)
        {
            PkixCertPathBuilderResult pkixCertPathBuilderResult = null;
            ISet set = new HashSet();

            if (attrCert.Holder.GetIssuer() != null)
            {
                X509CertStoreSelector x509CertStoreSelector = new X509CertStoreSelector();
                x509CertStoreSelector.SerialNumber = attrCert.Holder.SerialNumber;
                X509Name[] issuer = attrCert.Holder.GetIssuer();
                for (int i = 0; i < issuer.Length; i++)
                {
                    try
                    {
                        x509CertStoreSelector.Issuer = issuer[i];
                        set.AddAll(PkixCertPathValidatorUtilities.FindCertificates(x509CertStoreSelector, pkixParams.GetStores()));
                    }
                    catch (Exception cause)
                    {
                        throw new PkixCertPathValidatorException("Public key certificate for attribute certificate cannot be searched.", cause);
                    }
                }
                if (set.IsEmpty)
                {
                    throw new PkixCertPathValidatorException("Public key certificate specified in base certificate ID for attribute certificate cannot be found.");
                }
            }
            if (attrCert.Holder.GetEntityNames() != null)
            {
                X509CertStoreSelector x509CertStoreSelector2 = new X509CertStoreSelector();
                X509Name[]            entityNames            = attrCert.Holder.GetEntityNames();
                for (int j = 0; j < entityNames.Length; j++)
                {
                    try
                    {
                        x509CertStoreSelector2.Issuer = entityNames[j];
                        set.AddAll(PkixCertPathValidatorUtilities.FindCertificates(x509CertStoreSelector2, pkixParams.GetStores()));
                    }
                    catch (Exception cause2)
                    {
                        throw new PkixCertPathValidatorException("Public key certificate for attribute certificate cannot be searched.", cause2);
                    }
                }
                if (set.IsEmpty)
                {
                    throw new PkixCertPathValidatorException("Public key certificate specified in entity name for attribute certificate cannot be found.");
                }
            }
            PkixBuilderParameters          instance = PkixBuilderParameters.GetInstance(pkixParams);
            PkixCertPathValidatorException ex       = null;

            foreach (X509Certificate certificate in set)
            {
                instance.SetTargetConstraints(new X509CertStoreSelector
                {
                    Certificate = certificate
                });
                PkixCertPathBuilder pkixCertPathBuilder = new PkixCertPathBuilder();
                try
                {
                    pkixCertPathBuilderResult = pkixCertPathBuilder.Build(PkixBuilderParameters.GetInstance(instance));
                }
                catch (PkixCertPathBuilderException cause3)
                {
                    ex = new PkixCertPathValidatorException("Certification path for public key certificate of attribute certificate could not be build.", cause3);
                }
            }
            if (ex != null)
            {
                throw ex;
            }
            return(pkixCertPathBuilderResult.CertPath);
        }
示例#2
0
        /**
         * Searches for a holder public key certificate and verifies its
         * certification path.
         *
         * @param attrCert the attribute certificate.
         * @param pkixParams The PKIX parameters.
         * @return The certificate path of the holder certificate.
         * @throws Exception if
         *             <ul>
         *             <li>no public key certificate can be found although holder
         *             information is given by an entity name or a base certificate
         *             ID</li>
         *             <li>support classes cannot be created</li>
         *             <li>no certification path for the public key certificate can
         *             be built</li>
         *             </ul>
         */
        internal static PkixCertPath ProcessAttrCert1(
            IX509AttributeCertificate attrCert,
            PkixParameters pkixParams)
        {
            PkixCertPathBuilderResult result = null;
            // find holder PKCs
            ISet holderPKCs = new HashSet();

            if (attrCert.Holder.GetIssuer() != null)
            {
                X509CertStoreSelector selector = new X509CertStoreSelector();
                selector.SerialNumber = attrCert.Holder.SerialNumber;
                X509Name[] principals = attrCert.Holder.GetIssuer();
                for (int i = 0; i < principals.Length; i++)
                {
                    try
                    {
//						if (principals[i] is X500Principal)
                        {
                            selector.Issuer = principals[i];
                        }
                        holderPKCs.AddAll(PkixCertPathValidatorUtilities
                                          .FindCertificates(selector, pkixParams.GetStores()));
                    }
                    catch (Exception e)
                    {
                        throw new PkixCertPathValidatorException(
                                  "Public key certificate for attribute certificate cannot be searched.",
                                  e);
                    }
                }
                if (holderPKCs.IsEmpty)
                {
                    throw new PkixCertPathValidatorException(
                              "Public key certificate specified in base certificate ID for attribute certificate cannot be found.");
                }
            }
            if (attrCert.Holder.GetEntityNames() != null)
            {
                X509CertStoreSelector selector   = new X509CertStoreSelector();
                X509Name[]            principals = attrCert.Holder.GetEntityNames();
                for (int i = 0; i < principals.Length; i++)
                {
                    try
                    {
//						if (principals[i] is X500Principal)
                        {
                            selector.Issuer = principals[i];
                        }
                        holderPKCs.AddAll(PkixCertPathValidatorUtilities
                                          .FindCertificates(selector, pkixParams.GetStores()));
                    }
                    catch (Exception e)
                    {
                        throw new PkixCertPathValidatorException(
                                  "Public key certificate for attribute certificate cannot be searched.",
                                  e);
                    }
                }
                if (holderPKCs.IsEmpty)
                {
                    throw new PkixCertPathValidatorException(
                              "Public key certificate specified in entity name for attribute certificate cannot be found.");
                }
            }

            // verify cert paths for PKCs
            PkixBuilderParameters parameters = (PkixBuilderParameters)
                                               PkixBuilderParameters.GetInstance(pkixParams);

            PkixCertPathValidatorException lastException = null;

            foreach (X509Certificate cert in holderPKCs)
            {
                X509CertStoreSelector selector = new X509CertStoreSelector();
                selector.Certificate = cert;
                parameters.SetTargetConstraints(selector);

                PkixCertPathBuilder builder = new PkixCertPathBuilder();

                try
                {
                    result = builder.Build(PkixBuilderParameters.GetInstance(parameters));
                }
                catch (PkixCertPathBuilderException e)
                {
                    lastException = new PkixCertPathValidatorException(
                        "Certification path for public key certificate of attribute certificate could not be build.",
                        e);
                }
            }
            if (lastException != null)
            {
                throw lastException;
            }
            return(result.CertPath);
        }
        internal static PkixCertPath ProcessAttrCert1(IX509AttributeCertificate attrCert, PkixParameters pkixParams)
        {
            PkixCertPathBuilderResult pkixCertPathBuilderResult = null;
            ISet set = new HashSet();

            if (attrCert.Holder.GetIssuer() != null)
            {
                X509CertStoreSelector x509CertStoreSelector = new X509CertStoreSelector();
                x509CertStoreSelector.SerialNumber = attrCert.Holder.SerialNumber;
                X509Name[] issuer = attrCert.Holder.GetIssuer();
                for (int i = 0; i < issuer.Length; i++)
                {
                    try
                    {
                        x509CertStoreSelector.Issuer = issuer[i];
                        set.AddAll((global::System.Collections.IEnumerable)PkixCertPathValidatorUtilities.FindCertificates(x509CertStoreSelector, pkixParams.GetStores()));
                    }
                    catch (global::System.Exception cause)
                    {
                        throw new PkixCertPathValidatorException("Public key certificate for attribute certificate cannot be searched.", cause);
                    }
                }
                if (set.IsEmpty)
                {
                    throw new PkixCertPathValidatorException("Public key certificate specified in base certificate ID for attribute certificate cannot be found.");
                }
            }
            if (attrCert.Holder.GetEntityNames() != null)
            {
                X509CertStoreSelector x509CertStoreSelector2 = new X509CertStoreSelector();
                X509Name[]            entityNames            = attrCert.Holder.GetEntityNames();
                for (int j = 0; j < entityNames.Length; j++)
                {
                    try
                    {
                        x509CertStoreSelector2.Issuer = entityNames[j];
                        set.AddAll((global::System.Collections.IEnumerable)PkixCertPathValidatorUtilities.FindCertificates(x509CertStoreSelector2, pkixParams.GetStores()));
                    }
                    catch (global::System.Exception cause2)
                    {
                        throw new PkixCertPathValidatorException("Public key certificate for attribute certificate cannot be searched.", cause2);
                    }
                }
                if (set.IsEmpty)
                {
                    throw new PkixCertPathValidatorException("Public key certificate specified in entity name for attribute certificate cannot be found.");
                }
            }
            PkixBuilderParameters          instance = PkixBuilderParameters.GetInstance(pkixParams);
            PkixCertPathValidatorException ex       = null;

            global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)set).GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    X509Certificate       certificate            = (X509Certificate)enumerator.get_Current();
                    X509CertStoreSelector x509CertStoreSelector3 = new X509CertStoreSelector();
                    x509CertStoreSelector3.Certificate = certificate;
                    instance.SetTargetConstraints(x509CertStoreSelector3);
                    PkixCertPathBuilder pkixCertPathBuilder = new PkixCertPathBuilder();
                    try
                    {
                        pkixCertPathBuilderResult = pkixCertPathBuilder.Build(PkixBuilderParameters.GetInstance(instance));
                    }
                    catch (PkixCertPathBuilderException cause3)
                    {
                        ex = new PkixCertPathValidatorException("Certification path for public key certificate of attribute certificate could not be build.", cause3);
                    }
                }
            }
            finally
            {
                global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            if (ex != null)
            {
                throw ex;
            }
            return(pkixCertPathBuilderResult.CertPath);
        }