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);
        }
Example #2
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 = Platform.CreateArrayList();

			// 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 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);
        }
Example #4
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);
        }