Example #1
0
		/**
		 * Build and validate a CertPath using the given parameter.
		 * 
		 * @param params PKIXBuilderParameters object containing all information to
		 *            build the CertPath
		 */
		public virtual PkixCertPathBuilderResult Build(
			PkixBuilderParameters pkixParams)
		{
			// search target certificates

			IX509Selector certSelect = pkixParams.GetTargetCertConstraints();
			if (!(certSelect is X509CertStoreSelector))
			{
				throw new PkixCertPathBuilderException(
					"TargetConstraints must be an instance of "
					+ typeof(X509CertStoreSelector).FullName + " for "
					+ this.GetType() + " class.");
			}

			ISet targets = new HashSet();
			try
			{
				targets.AddAll(PkixCertPathValidatorUtilities.FindCertificates((X509CertStoreSelector)certSelect, pkixParams.GetStores()));
				// TODO Should this include an entry for pkixParams.GetAdditionalStores() too?
			}
			catch (Exception e)
			{
				throw new PkixCertPathBuilderException(
					"Error finding target certificate.", e);
			}

			if (targets.IsEmpty)
				throw new PkixCertPathBuilderException("No certificate found matching targetContraints.");

			PkixCertPathBuilderResult result = null;
			IList certPathList = new ArrayList();

			// check all potential target certificates
			foreach (X509Certificate cert in targets)
			{
				result = Build(cert, pkixParams, certPathList);

				if (result != null)
					break;
			}

			if (result == null && certPathException != null)
			{
				throw new PkixCertPathBuilderException(certPathException.Message, certPathException.InnerException);
			}

			if (result == null && certPathException == null)
			{
				throw new PkixCertPathBuilderException("Unable to find certificate chain.");
			}

			return result;
		}
        public virtual PkixCertPathBuilderResult Build(PkixBuilderParameters pkixParams)
        {
            IX509Selector targetConstraints = pkixParams.GetTargetConstraints();

            if (!(targetConstraints is X509AttrCertStoreSelector))
            {
                throw new PkixCertPathBuilderException(string.Concat(new string[]
                {
                    "TargetConstraints must be an instance of ",
                    typeof(X509AttrCertStoreSelector).FullName,
                    " for ",
                    typeof(PkixAttrCertPathBuilder).FullName,
                    " class."
                }));
            }
            ICollection collection;

            try
            {
                collection = PkixCertPathValidatorUtilities.FindCertificates((X509AttrCertStoreSelector)targetConstraints, pkixParams.GetStores());
            }
            catch (Exception exception)
            {
                throw new PkixCertPathBuilderException("Error finding target attribute certificate.", exception);
            }
            if (collection.Count == 0)
            {
                throw new PkixCertPathBuilderException("No attribute certificate found matching targetContraints.");
            }
            PkixCertPathBuilderResult pkixCertPathBuilderResult = null;

            foreach (IX509AttributeCertificate iX509AttributeCertificate in collection)
            {
                X509CertStoreSelector x509CertStoreSelector = new X509CertStoreSelector();
                X509Name[]            principals            = iX509AttributeCertificate.Issuer.GetPrincipals();
                ISet set = new HashSet();
                for (int i = 0; i < principals.Length; i++)
                {
                    try
                    {
                        x509CertStoreSelector.Subject = principals[i];
                        set.AddAll(PkixCertPathValidatorUtilities.FindCertificates(x509CertStoreSelector, pkixParams.GetStores()));
                    }
                    catch (Exception exception2)
                    {
                        throw new PkixCertPathBuilderException("Public key certificate for attribute certificate cannot be searched.", exception2);
                    }
                }
                if (set.IsEmpty)
                {
                    throw new PkixCertPathBuilderException("Public key certificate for attribute certificate cannot be found.");
                }
                IList tbvPath = Platform.CreateArrayList();
                foreach (X509Certificate tbvCert in set)
                {
                    pkixCertPathBuilderResult = this.Build(iX509AttributeCertificate, tbvCert, pkixParams, tbvPath);
                    if (pkixCertPathBuilderResult != null)
                    {
                        break;
                    }
                }
                if (pkixCertPathBuilderResult != null)
                {
                    break;
                }
            }
            if (pkixCertPathBuilderResult == null && this.certPathException != null)
            {
                throw new PkixCertPathBuilderException("Possible certificate chain could not be validated.", this.certPathException);
            }
            if (pkixCertPathBuilderResult == null && this.certPathException == null)
            {
                throw new PkixCertPathBuilderException("Unable to find certificate chain.");
            }
            return(pkixCertPathBuilderResult);
        }
		/**
		* Find the issuer certificates of a given certificate.
		*
		* @param cert
		*            The certificate for which an issuer should be found.
		* @param pkixParams
		* @return A <code>Collection</code> object containing the issuer
		*         <code>X509Certificate</code>s. Never <code>null</code>.
		*
		* @exception Exception
		*                if an error occurs.
		*/
		internal static ICollection FindIssuerCerts(
			X509Certificate			cert,
			PkixBuilderParameters	pkixParams)
		{
			X509CertStoreSelector certSelect = new X509CertStoreSelector();
			ISet certs = new HashSet();
			try
			{
				certSelect.Subject = cert.IssuerDN;
			}
			catch (IOException ex)
			{
				throw new Exception(
					"Subject criteria for certificate selector to find issuer certificate could not be set.", ex);
			}

			try
			{
                certs.AddAll(PkixCertPathValidatorUtilities.FindCertificates(certSelect, pkixParams.GetStores()));
                certs.AddAll(PkixCertPathValidatorUtilities.FindCertificates(certSelect, pkixParams.GetAdditionalStores()));
			}
			catch (Exception e)
			{
				throw new Exception("Issuer certificate cannot be searched.", e);
			}

			return certs;
		}
Example #4
0
        /**
         * Build and validate a CertPath using the given parameter.
         *
         * @param params PKIXBuilderParameters object containing all information to
         *            build the CertPath
         */
        public virtual PkixCertPathBuilderResult Build(
            PkixBuilderParameters pkixParams)
        {
            // search target certificates

            IX509Selector certSelect = pkixParams.GetTargetCertConstraints();

            if (!(certSelect is X509CertStoreSelector))
            {
                throw new PkixCertPathBuilderException(
                          "TargetConstraints must be an instance of "
                          + typeof(X509CertStoreSelector).FullName + " for "
                          + this.GetType() + " class.");
            }

            ISet targets = new HashSet();

            try
            {
                targets.AddAll(PkixCertPathValidatorUtilities.FindCertificates((X509CertStoreSelector)certSelect, pkixParams.GetStores()));
                // TODO Should this include an entry for pkixParams.GetAdditionalStores() too?
            }
            catch (Exception e)
            {
                throw new PkixCertPathBuilderException(
                          "Error finding target certificate.", e);
            }

            if (targets.IsEmpty)
            {
                throw new PkixCertPathBuilderException("No certificate found matching targetContraints.");
            }

            PkixCertPathBuilderResult result = null;
            IList certPathList = new ArrayList();

            // check all potential target certificates
            foreach (X509Certificate cert in targets)
            {
                result = Build(cert, pkixParams, certPathList);

                if (result != null)
                {
                    break;
                }
            }

            if (result == null && certPathException != null)
            {
                throw new PkixCertPathBuilderException(certPathException.Message, certPathException.InnerException);
            }

            if (result == null && certPathException == null)
            {
                throw new PkixCertPathBuilderException("Unable to find certificate chain.");
            }

            return(result);
        }
		/**
		* Build and validate a CertPath using the given parameter.
		*
		* @param params PKIXBuilderParameters object containing all information to
		*            build the CertPath
		*/
		public virtual PkixCertPathBuilderResult Build(
			PkixBuilderParameters pkixParams)
		{
			// search target certificates

			IX509Selector certSelect = pkixParams.GetTargetConstraints();
			if (!(certSelect is X509AttrCertStoreSelector))
			{
				throw new PkixCertPathBuilderException(
					"TargetConstraints must be an instance of "
					+ typeof(X509AttrCertStoreSelector).FullName
					+ " for "
					+ typeof(PkixAttrCertPathBuilder).FullName + " class.");
			}

			ICollection targets;
			try
			{
				targets = PkixCertPathValidatorUtilities.FindCertificates(
					(X509AttrCertStoreSelector)certSelect, pkixParams.GetStores());
			}
			catch (Exception e)
			{
				throw new PkixCertPathBuilderException("Error finding target attribute certificate.", e);
			}

			if (targets.Count == 0)
			{
				throw new PkixCertPathBuilderException(
					"No attribute certificate found matching targetContraints.");
			}

			PkixCertPathBuilderResult result = null;

			// check all potential target certificates
			foreach (IX509AttributeCertificate cert in targets)
			{
				X509CertStoreSelector selector = new X509CertStoreSelector();
				X509Name[] principals = cert.Issuer.GetPrincipals();
				ISet issuers = new HashSet();
				for (int i = 0; i < principals.Length; i++)
				{
					try
					{
						selector.Subject = principals[i];

						issuers.AddAll(PkixCertPathValidatorUtilities.FindCertificates(selector, pkixParams.GetStores()));
					}
					catch (Exception e)
					{
						throw new PkixCertPathBuilderException(
							"Public key certificate for attribute certificate cannot be searched.",
							e);
					}
				}

				if (issuers.IsEmpty)
					throw new PkixCertPathBuilderException("Public key certificate for attribute certificate cannot be found.");

                IList certPathList = Platform.CreateArrayList();

				foreach (X509Certificate issuer in issuers)
				{
					result = Build(cert, issuer, pkixParams, certPathList);

					if (result != null)
						break;
				}

				if (result != null)
					break;
			}

			if (result == null && certPathException != null)
			{
				throw new PkixCertPathBuilderException(
					"Possible certificate chain could not be validated.",
					certPathException);
			}

			if (result == null && certPathException == null)
			{
				throw new PkixCertPathBuilderException(
					"Unable to find certificate chain.");
			}

			return result;
		}
Example #6
0
        /**
         * Build and validate a CertPath using the given parameter.
         *
         * @param params PKIXBuilderParameters object containing all information to
         *            build the CertPath
         */
        public virtual PkixCertPathBuilderResult Build(
            PkixBuilderParameters pkixParams)
        {
            // search target certificates

            IX509Selector certSelect = pkixParams.GetTargetConstraints();

            if (!(certSelect is X509AttrCertStoreSelector))
            {
                throw new PkixCertPathBuilderException(
                          "TargetConstraints must be an instance of "
                          + typeof(X509AttrCertStoreSelector).FullName
                          + " for "
                          + typeof(PkixAttrCertPathBuilder).FullName + " class.");
            }

            ICollection targets;

            try
            {
                targets = PkixCertPathValidatorUtilities.FindCertificates(
                    (X509AttrCertStoreSelector)certSelect, pkixParams.GetStores());
            }
            catch (Exception e)
            {
                throw new PkixCertPathBuilderException("Error finding target attribute certificate.", e);
            }

            if (targets.Count == 0)
            {
                throw new PkixCertPathBuilderException(
                          "No attribute certificate found matching targetContraints.");
            }

            PkixCertPathBuilderResult result = null;

            // check all potential target certificates
            foreach (IX509AttributeCertificate cert in targets)
            {
                X509CertStoreSelector selector   = new X509CertStoreSelector();
                X509Name[]            principals = cert.Issuer.GetPrincipals();
                ISet issuers = new HashSet();
                for (int i = 0; i < principals.Length; i++)
                {
                    try
                    {
                        selector.Subject = principals[i];

                        issuers.AddAll(PkixCertPathValidatorUtilities.FindCertificates(selector, pkixParams.GetStores()));
                    }
                    catch (Exception e)
                    {
                        throw new PkixCertPathBuilderException(
                                  "Public key certificate for attribute certificate cannot be searched.",
                                  e);
                    }
                }

                if (issuers.IsEmpty)
                {
                    throw new PkixCertPathBuilderException("Public key certificate for attribute certificate cannot be found.");
                }

                IList certPathList = Platform.CreateArrayList();

                foreach (X509Certificate issuer in issuers)
                {
                    result = Build(cert, issuer, pkixParams, certPathList);

                    if (result != null)
                    {
                        break;
                    }
                }

                if (result != null)
                {
                    break;
                }
            }

            if (result == null && certPathException != null)
            {
                throw new PkixCertPathBuilderException(
                          "Possible certificate chain could not be validated.",
                          certPathException);
            }

            if (result == null && certPathException == null)
            {
                throw new PkixCertPathBuilderException(
                          "Unable to find certificate chain.");
            }

            return(result);
        }
Example #7
0
        /**
         * Find the issuer certificates of a given certificate.
         *
         * @param cert
         *            The certificate for which an issuer should be found.
         * @param pkixParams
         * @return A <code>Collection</code> object containing the issuer
         *         <code>X509Certificate</code>s. Never <code>null</code>.
         *
         * @exception Exception
         *                if an error occurs.
         */
        internal static ICollection FindIssuerCerts(
            X509Certificate cert,
            PkixBuilderParameters pkixParams)
        {
            X509CertStoreSelector certSelect = new X509CertStoreSelector();
            ISet certs = new HashSet();

            try
            {
                certSelect.Subject = cert.IssuerDN;
            }
            catch (IOException ex)
            {
                throw new Exception(
                          "Subject criteria for certificate selector to find issuer certificate could not be set.", ex);
            }

            try
            {
                certs.AddAll(PkixCertPathValidatorUtilities.FindCertificates(certSelect, pkixParams.GetStores()));
                certs.AddAll(PkixCertPathValidatorUtilities.FindCertificates(certSelect, pkixParams.GetAdditionalStores()));
            }
            catch (Exception e)
            {
                throw new Exception("Issuer certificate cannot be searched.", e);
            }

            return(certs);
        }
Example #8
0
        public virtual PkixCertPathBuilderResult Build(PkixBuilderParameters pkixParams)
        {
            IX509Selector targetConstraints = pkixParams.GetTargetConstraints();

            if (!(targetConstraints is X509AttrCertStoreSelector))
            {
                throw new PkixCertPathBuilderException(string.Concat(new string[5]
                {
                    "TargetConstraints must be an instance of ",
                    typeof(X509AttrCertStoreSelector).get_FullName(),
                    " for ",
                    typeof(PkixAttrCertPathBuilder).get_FullName(),
                    " class."
                }));
            }
            global::System.Collections.ICollection collection;
            try
            {
                collection = PkixCertPathValidatorUtilities.FindCertificates((X509AttrCertStoreSelector)targetConstraints, pkixParams.GetStores());
            }
            catch (global::System.Exception exception)
            {
                throw new PkixCertPathBuilderException("Error finding target attribute certificate.", exception);
            }
            if (collection.get_Count() == 0)
            {
                throw new PkixCertPathBuilderException("No attribute certificate found matching targetContraints.");
            }
            PkixCertPathBuilderResult pkixCertPathBuilderResult = null;

            global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)collection).GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    IX509AttributeCertificate iX509AttributeCertificate = (IX509AttributeCertificate)enumerator.get_Current();
                    X509CertStoreSelector     x509CertStoreSelector     = new X509CertStoreSelector();
                    X509Name[] principals = iX509AttributeCertificate.Issuer.GetPrincipals();
                    ISet       set        = new HashSet();
                    for (int i = 0; i < principals.Length; i++)
                    {
                        try
                        {
                            x509CertStoreSelector.Subject = principals[i];
                            set.AddAll((global::System.Collections.IEnumerable)PkixCertPathValidatorUtilities.FindCertificates(x509CertStoreSelector, pkixParams.GetStores()));
                        }
                        catch (global::System.Exception exception2)
                        {
                            throw new PkixCertPathBuilderException("Public key certificate for attribute certificate cannot be searched.", exception2);
                        }
                    }
                    if (set.IsEmpty)
                    {
                        throw new PkixCertPathBuilderException("Public key certificate for attribute certificate cannot be found.");
                    }
                    global::System.Collections.IList tbvPath = Platform.CreateArrayList();
                    {
                        global::System.Collections.IEnumerator enumerator2 = ((global::System.Collections.IEnumerable)set).GetEnumerator();
                        try
                        {
                            while (enumerator2.MoveNext())
                            {
                                X509Certificate tbvCert = (X509Certificate)enumerator2.get_Current();
                                pkixCertPathBuilderResult = Build(iX509AttributeCertificate, tbvCert, pkixParams, tbvPath);
                                if (pkixCertPathBuilderResult != null)
                                {
                                    break;
                                }
                            }
                        }
                        finally
                        {
                            global::System.IDisposable disposable2 = enumerator2 as global::System.IDisposable;
                            if (disposable2 != null)
                            {
                                disposable2.Dispose();
                            }
                        }
                    }
                    if (pkixCertPathBuilderResult != null)
                    {
                        break;
                    }
                }
            }
            finally
            {
                global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            if (pkixCertPathBuilderResult == null && certPathException != null)
            {
                throw new PkixCertPathBuilderException("Possible certificate chain could not be validated.", certPathException);
            }
            if (pkixCertPathBuilderResult == null && certPathException == null)
            {
                throw new PkixCertPathBuilderException("Unable to find certificate chain.");
            }
            return(pkixCertPathBuilderResult);
        }
Example #9
0
        public virtual PkixCertPathBuilderResult Build(PkixBuilderParameters pkixParams)
        {
            IX509Selector targetCertConstraints = pkixParams.GetTargetCertConstraints();

            if (!(targetCertConstraints is X509CertStoreSelector))
            {
                throw new PkixCertPathBuilderException(string.Concat(new string[5]
                {
                    "TargetConstraints must be an instance of ",
                    typeof(X509CertStoreSelector).get_FullName(),
                    " for ",
                    Platform.GetTypeName(this),
                    " class."
                }));
            }
            ISet set = new HashSet();

            try
            {
                set.AddAll((global::System.Collections.IEnumerable)PkixCertPathValidatorUtilities.FindCertificates((X509CertStoreSelector)targetCertConstraints, pkixParams.GetStores()));
            }
            catch (global::System.Exception exception)
            {
                throw new PkixCertPathBuilderException("Error finding target certificate.", exception);
            }
            if (set.IsEmpty)
            {
                throw new PkixCertPathBuilderException("No certificate found matching targetContraints.");
            }
            PkixCertPathBuilderResult pkixCertPathBuilderResult = null;

            global::System.Collections.IList       tbvPath    = Platform.CreateArrayList();
            global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)set).GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    X509Certificate tbvCert = (X509Certificate)enumerator.get_Current();
                    pkixCertPathBuilderResult = Build(tbvCert, pkixParams, tbvPath);
                    if (pkixCertPathBuilderResult != null)
                    {
                        break;
                    }
                }
            }
            finally
            {
                global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            if (pkixCertPathBuilderResult == null && certPathException != null)
            {
                throw new PkixCertPathBuilderException(certPathException.get_Message(), certPathException.get_InnerException());
            }
            if (pkixCertPathBuilderResult == null && certPathException == null)
            {
                throw new PkixCertPathBuilderException("Unable to find certificate chain.");
            }
            return(pkixCertPathBuilderResult);
        }
Example #10
0
        internal static global::System.Collections.ICollection FindIssuerCerts(X509Certificate cert, PkixBuilderParameters pkixParams)
        {
            //IL_001b: Expected O, but got Unknown
            X509CertStoreSelector x509CertStoreSelector = new X509CertStoreSelector();
            ISet set = new HashSet();

            try
            {
                x509CertStoreSelector.Subject = cert.IssuerDN;
            }
            catch (IOException val)
            {
                IOException val2 = val;
                throw new global::System.Exception("Subject criteria for certificate selector to find issuer certificate could not be set.", (global::System.Exception)(object) val2);
            }
            try
            {
                set.AddAll((global::System.Collections.IEnumerable)FindCertificates(x509CertStoreSelector, pkixParams.GetStores()));
                set.AddAll((global::System.Collections.IEnumerable)FindCertificates(x509CertStoreSelector, pkixParams.GetAdditionalStores()));
                return(set);
            }
            catch (global::System.Exception ex)
            {
                throw new global::System.Exception("Issuer certificate cannot be searched.", ex);
            }
        }
Example #11
0
        internal static ICollection FindIssuerCerts(X509Certificate cert, PkixBuilderParameters pkixParams)
        {
            X509CertStoreSelector x509CertStoreSelector = new X509CertStoreSelector();
            ISet set = new HashSet();

            try
            {
                x509CertStoreSelector.Subject = cert.IssuerDN;
            }
            catch (IOException innerException)
            {
                throw new Exception("Subject criteria for certificate selector to find issuer certificate could not be set.", innerException);
            }
            try
            {
                set.AddAll(PkixCertPathValidatorUtilities.FindCertificates(x509CertStoreSelector, pkixParams.GetStores()));
                set.AddAll(PkixCertPathValidatorUtilities.FindCertificates(x509CertStoreSelector, pkixParams.GetAdditionalStores()));
            }
            catch (Exception innerException2)
            {
                throw new Exception("Issuer certificate cannot be searched.", innerException2);
            }
            return(set);
        }
        public virtual PkixCertPathBuilderResult Build(PkixBuilderParameters pkixParams)
        {
            IX509Selector targetCertConstraints = pkixParams.GetTargetCertConstraints();

            if (!(targetCertConstraints is X509CertStoreSelector))
            {
                throw new PkixCertPathBuilderException(string.Concat(new object[]
                {
                    "TargetConstraints must be an instance of ",
                    typeof(X509CertStoreSelector).FullName,
                    " for ",
                    base.GetType(),
                    " class."
                }));
            }
            ISet set = new HashSet();

            try
            {
                set.AddAll(PkixCertPathValidatorUtilities.FindCertificates((X509CertStoreSelector)targetCertConstraints, pkixParams.GetStores()));
            }
            catch (Exception exception)
            {
                throw new PkixCertPathBuilderException("Error finding target certificate.", exception);
            }
            if (set.IsEmpty)
            {
                throw new PkixCertPathBuilderException("No certificate found matching targetContraints.");
            }
            PkixCertPathBuilderResult pkixCertPathBuilderResult = null;
            IList tbvPath = Platform.CreateArrayList();

            foreach (X509Certificate tbvCert in set)
            {
                pkixCertPathBuilderResult = this.Build(tbvCert, pkixParams, tbvPath);
                if (pkixCertPathBuilderResult != null)
                {
                    break;
                }
            }
            if (pkixCertPathBuilderResult == null && this.certPathException != null)
            {
                throw new PkixCertPathBuilderException(this.certPathException.Message, this.certPathException.InnerException);
            }
            if (pkixCertPathBuilderResult == null && this.certPathException == null)
            {
                throw new PkixCertPathBuilderException("Unable to find certificate chain.");
            }
            return(pkixCertPathBuilderResult);
        }