public virtual PkixCertPathValidatorResult Validate(PkixCertPath certPath, PkixParameters pkixParams)
    {
        IX509Selector targetConstraints = pkixParams.GetTargetConstraints();

        if (!(targetConstraints is X509AttrCertStoreSelector))
        {
            throw new ArgumentException("TargetConstraints must be an instance of " + typeof(X509AttrCertStoreSelector).FullName, "pkixParams");
        }
        IX509AttributeCertificate attributeCert     = ((X509AttrCertStoreSelector)targetConstraints).AttributeCert;
        PkixCertPath holderCertPath                 = Rfc3281CertPathUtilities.ProcessAttrCert1(attributeCert, pkixParams);
        PkixCertPathValidatorResult result          = Rfc3281CertPathUtilities.ProcessAttrCert2(certPath, pkixParams);
        X509Certificate             x509Certificate = (X509Certificate)certPath.Certificates[0];

        Rfc3281CertPathUtilities.ProcessAttrCert3(x509Certificate, pkixParams);
        Rfc3281CertPathUtilities.ProcessAttrCert4(x509Certificate, pkixParams);
        Rfc3281CertPathUtilities.ProcessAttrCert5(attributeCert, pkixParams);
        Rfc3281CertPathUtilities.ProcessAttrCert7(attributeCert, certPath, holderCertPath, pkixParams);
        Rfc3281CertPathUtilities.AdditionalChecks(attributeCert, pkixParams);
        DateTime validCertDateFromValidityModel;

        try
        {
            validCertDateFromValidityModel = PkixCertPathValidatorUtilities.GetValidCertDateFromValidityModel(pkixParams, null, -1);
        }
        catch (Exception cause)
        {
            throw new PkixCertPathValidatorException("Could not get validity date from attribute certificate.", cause);
        }
        Rfc3281CertPathUtilities.CheckCrls(attributeCert, pkixParams, x509Certificate, validCertDateFromValidityModel, certPath.Certificates);
        return(result);
    }
    internal static void ProcessAttrCert7(IX509AttributeCertificate attrCert, PkixCertPath certPath, PkixCertPath holderCertPath, PkixParameters pkixParams)
    {
        ISet criticalExtensionOids = attrCert.GetCriticalExtensionOids();

        if (criticalExtensionOids.Contains(X509Extensions.TargetInformation.Id))
        {
            try
            {
                TargetInformation.GetInstance(PkixCertPathValidatorUtilities.GetExtensionValue(attrCert, X509Extensions.TargetInformation));
            }
            catch (Exception cause)
            {
                throw new PkixCertPathValidatorException("Target information extension could not be read.", cause);
            }
        }
        criticalExtensionOids.Remove(X509Extensions.TargetInformation.Id);
        foreach (PkixAttrCertChecker attrCertChecker in pkixParams.GetAttrCertCheckers())
        {
            attrCertChecker.Check(attrCert, certPath, holderCertPath, criticalExtensionOids);
        }
        if (!criticalExtensionOids.IsEmpty)
        {
            throw new PkixCertPathValidatorException("Attribute certificate contains unsupported critical extensions: " + criticalExtensionOids);
        }
    }
 private static void CheckCrl(DistributionPoint dp, IX509AttributeCertificate attrCert, PkixParameters paramsPKIX, DateTime validDate, X509Certificate issuerCert, CertStatus certStatus, ReasonsMask reasonMask, IList certPathCerts)
 {
     if (attrCert.GetExtensionValue(X509Extensions.NoRevAvail) == null)
     {
         DateTime utcNow = DateTime.UtcNow;
         if (validDate.CompareTo((object)utcNow) > 0)
         {
             throw new Exception("Validation time is in future.");
         }
         ISet        completeCrls = PkixCertPathValidatorUtilities.GetCompleteCrls(dp, attrCert, utcNow, paramsPKIX);
         bool        flag         = false;
         Exception   ex           = null;
         IEnumerator enumerator   = completeCrls.GetEnumerator();
         while (enumerator.MoveNext() && certStatus.Status == 11 && !reasonMask.IsAllReasons)
         {
             try
             {
                 X509Crl     x509Crl     = (X509Crl)enumerator.Current;
                 ReasonsMask reasonsMask = Rfc3280CertPathUtilities.ProcessCrlD(x509Crl, dp);
                 if (reasonsMask.HasNewReasons(reasonMask))
                 {
                     ISet keys = Rfc3280CertPathUtilities.ProcessCrlF(x509Crl, attrCert, null, null, paramsPKIX, certPathCerts);
                     AsymmetricKeyParameter key = Rfc3280CertPathUtilities.ProcessCrlG(x509Crl, keys);
                     X509Crl x509Crl2           = null;
                     if (paramsPKIX.IsUseDeltasEnabled)
                     {
                         ISet deltaCrls = PkixCertPathValidatorUtilities.GetDeltaCrls(utcNow, paramsPKIX, x509Crl);
                         x509Crl2 = Rfc3280CertPathUtilities.ProcessCrlH(deltaCrls, key);
                     }
                     if (paramsPKIX.ValidityModel != 1 && attrCert.NotAfter.CompareTo((object)x509Crl.ThisUpdate) < 0)
                     {
                         throw new Exception("No valid CRL for current time found.");
                     }
                     Rfc3280CertPathUtilities.ProcessCrlB1(dp, attrCert, x509Crl);
                     Rfc3280CertPathUtilities.ProcessCrlB2(dp, attrCert, x509Crl);
                     Rfc3280CertPathUtilities.ProcessCrlC(x509Crl2, x509Crl, paramsPKIX);
                     Rfc3280CertPathUtilities.ProcessCrlI(validDate, x509Crl2, attrCert, certStatus, paramsPKIX);
                     Rfc3280CertPathUtilities.ProcessCrlJ(validDate, x509Crl, attrCert, certStatus);
                     if (certStatus.Status == 8)
                     {
                         certStatus.Status = 11;
                     }
                     reasonMask.AddReasons(reasonsMask);
                     flag = true;
                 }
             }
             catch (Exception ex2)
             {
                 ex = ex2;
             }
         }
         if (!flag)
         {
             throw ex;
         }
     }
 }
 internal static void ProcessAttrCert5(IX509AttributeCertificate attrCert, PkixParameters pkixParams)
 {
     try
     {
         attrCert.CheckValidity(PkixCertPathValidatorUtilities.GetValidDate(pkixParams));
     }
     catch (CertificateExpiredException cause)
     {
         throw new PkixCertPathValidatorException("Attribute certificate is not valid.", cause);
     }
     catch (CertificateNotYetValidException cause2)
     {
         throw new PkixCertPathValidatorException("Attribute certificate is not valid.", cause2);
     }
 }
Ejemplo n.º 5
0
    public virtual PkixCertPathBuilderResult Build(PkixBuilderParameters pkixParams)
    {
        IX509Selector targetCertConstraints = pkixParams.GetTargetCertConstraints();

        if (!(targetCertConstraints is X509CertStoreSelector))
        {
            throw new PkixCertPathBuilderException("TargetConstraints must be an instance of " + typeof(X509CertStoreSelector).FullName + " for " + Platform.GetTypeName(this) + " 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 item in set)
        {
            pkixCertPathBuilderResult = Build(item, pkixParams, tbvPath);
            if (pkixCertPathBuilderResult != null)
            {
                break;
            }
        }
        if (pkixCertPathBuilderResult == null && certPathException != null)
        {
            throw new PkixCertPathBuilderException(certPathException.Message, certPathException.InnerException);
        }
        if (pkixCertPathBuilderResult == null && certPathException == null)
        {
            throw new PkixCertPathBuilderException("Unable to find certificate chain.");
        }
        return(pkixCertPathBuilderResult);
    }
    private PkixCertPathBuilderResult Build(IX509AttributeCertificate attrCert, X509Certificate tbvCert, PkixBuilderParameters pkixParams, IList tbvPath)
    {
        if (tbvPath.Contains(tbvCert))
        {
            return(null);
        }
        if (pkixParams.GetExcludedCerts().Contains(tbvCert))
        {
            return(null);
        }
        if (pkixParams.MaxPathLength != -1 && tbvPath.Count - 1 > pkixParams.MaxPathLength)
        {
            return(null);
        }
        tbvPath.Add(tbvCert);
        PkixCertPathBuilderResult pkixCertPathBuilderResult = null;
        PkixAttrCertPathValidator pkixAttrCertPathValidator = new PkixAttrCertPathValidator();

        try
        {
            if (PkixCertPathValidatorUtilities.FindTrustAnchor(tbvCert, pkixParams.GetTrustAnchors()) != null)
            {
                PkixCertPath certPath = new PkixCertPath(tbvPath);
                PkixCertPathValidatorResult pkixCertPathValidatorResult;
                try
                {
                    pkixCertPathValidatorResult = pkixAttrCertPathValidator.Validate(certPath, pkixParams);
                }
                catch (Exception innerException)
                {
                    throw new Exception("Certification path could not be validated.", innerException);
                }
                return(new PkixCertPathBuilderResult(certPath, pkixCertPathValidatorResult.TrustAnchor, pkixCertPathValidatorResult.PolicyTree, pkixCertPathValidatorResult.SubjectPublicKey));
            }
            try
            {
                PkixCertPathValidatorUtilities.AddAdditionalStoresFromAltNames(tbvCert, pkixParams);
            }
            catch (CertificateParsingException innerException2)
            {
                throw new Exception("No additional X.509 stores can be added from certificate locations.", innerException2);
            }
            ISet set = new HashSet();
            try
            {
                set.AddAll(PkixCertPathValidatorUtilities.FindIssuerCerts(tbvCert, pkixParams));
            }
            catch (Exception innerException3)
            {
                throw new Exception("Cannot find issuer certificate for certificate in certification path.", innerException3);
            }
            if (set.IsEmpty)
            {
                throw new Exception("No issuer certificate for certificate in certification path found.");
            }
            foreach (X509Certificate item in set)
            {
                if (!PkixCertPathValidatorUtilities.IsSelfIssued(item))
                {
                    pkixCertPathBuilderResult = Build(attrCert, item, pkixParams, tbvPath);
                    if (pkixCertPathBuilderResult != null)
                    {
                        break;
                    }
                }
            }
        }
        catch (Exception innerException4)
        {
            certPathException = new Exception("No valid certification path could be build.", innerException4);
        }
        if (pkixCertPathBuilderResult == null)
        {
            tbvPath.Remove(tbvCert);
        }
        return(pkixCertPathBuilderResult);
    }
    public virtual PkixCertPathBuilderResult Build(PkixBuilderParameters pkixParams)
    {
        IX509Selector targetConstraints = pkixParams.GetTargetConstraints();

        if (!(targetConstraints is X509AttrCertStoreSelector))
        {
            throw new PkixCertPathBuilderException("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 item in collection)
        {
            X509CertStoreSelector x509CertStoreSelector = new X509CertStoreSelector();
            X509Name[]            principals            = item.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 item2 in set)
            {
                pkixCertPathBuilderResult = Build(item, item2, pkixParams, tbvPath);
                if (pkixCertPathBuilderResult != null)
                {
                    break;
                }
            }
            if (pkixCertPathBuilderResult != null)
            {
                break;
            }
        }
        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);
    }
    public virtual PkixCertPathValidatorResult Validate(PkixCertPath certPath, PkixParameters paramsPkix)
    {
        if (paramsPkix.GetTrustAnchors() == null)
        {
            throw new ArgumentException("trustAnchors is null, this is not allowed for certification path validation.", "parameters");
        }
        IList certificates = certPath.Certificates;
        int   count        = certificates.Count;

        if (certificates.Count == 0)
        {
            throw new PkixCertPathValidatorException("Certification path is empty.", null, certPath, 0);
        }
        ISet        initialPolicies = paramsPkix.GetInitialPolicies();
        TrustAnchor trustAnchor;

        try
        {
            trustAnchor = PkixCertPathValidatorUtilities.FindTrustAnchor((X509Certificate)certificates[certificates.Count - 1], paramsPkix.GetTrustAnchors());
        }
        catch (Exception ex)
        {
            throw new PkixCertPathValidatorException(ex.Message, ex, certPath, certificates.Count - 1);
        }
        if (trustAnchor == null)
        {
            throw new PkixCertPathValidatorException("Trust anchor for certification path not found.", null, certPath, -1);
        }
        int num = 0;

        IList[] array = new IList[count + 1];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = Platform.CreateArrayList();
        }
        ISet set = new HashSet();

        set.Add(Rfc3280CertPathUtilities.ANY_POLICY);
        PkixPolicyNode pkixPolicyNode = new PkixPolicyNode(Platform.CreateArrayList(), 0, set, null, new HashSet(), Rfc3280CertPathUtilities.ANY_POLICY, critical: false);

        array[0].Add(pkixPolicyNode);
        PkixNameConstraintValidator nameConstraintValidator = new PkixNameConstraintValidator();
        ISet                   acceptablePolicies           = new HashSet();
        int                    explicitPolicy   = (!paramsPkix.IsExplicitPolicyRequired) ? (count + 1) : 0;
        int                    inhibitAnyPolicy = (!paramsPkix.IsAnyPolicyInhibited) ? (count + 1) : 0;
        int                    policyMapping    = (!paramsPkix.IsPolicyMappingInhibited) ? (count + 1) : 0;
        X509Certificate        x509Certificate  = trustAnchor.TrustedCert;
        X509Name               workingIssuerName;
        AsymmetricKeyParameter asymmetricKeyParameter;

        try
        {
            if (x509Certificate != null)
            {
                workingIssuerName      = x509Certificate.SubjectDN;
                asymmetricKeyParameter = x509Certificate.GetPublicKey();
            }
            else
            {
                workingIssuerName      = new X509Name(trustAnchor.CAName);
                asymmetricKeyParameter = trustAnchor.CAPublicKey;
            }
        }
        catch (ArgumentException cause)
        {
            throw new PkixCertPathValidatorException("Subject of trust anchor could not be (re)encoded.", cause, certPath, -1);
        }
        try
        {
            PkixCertPathValidatorUtilities.GetAlgorithmIdentifier(asymmetricKeyParameter);
        }
        catch (PkixCertPathValidatorException cause2)
        {
            throw new PkixCertPathValidatorException("Algorithm identifier of public key of trust anchor could not be read.", cause2, certPath, -1);
        }
        int maxPathLength = count;
        X509CertStoreSelector targetCertConstraints = paramsPkix.GetTargetCertConstraints();

        if (targetCertConstraints != null && !targetCertConstraints.Match((X509Certificate)certificates[0]))
        {
            throw new PkixCertPathValidatorException("Target certificate in certification path does not match targetConstraints.", null, certPath, 0);
        }
        IList       certPathCheckers = paramsPkix.GetCertPathCheckers();
        IEnumerator enumerator       = certPathCheckers.GetEnumerator();

        while (enumerator.MoveNext())
        {
            ((PkixCertPathChecker)enumerator.Current).Init(forward: false);
        }
        X509Certificate x509Certificate2 = null;

        for (num = certificates.Count - 1; num >= 0; num--)
        {
            int num2 = count - num;
            x509Certificate2 = (X509Certificate)certificates[num];
            Rfc3280CertPathUtilities.ProcessCertA(certPath, paramsPkix, num, asymmetricKeyParameter, workingIssuerName, x509Certificate);
            Rfc3280CertPathUtilities.ProcessCertBC(certPath, num, nameConstraintValidator);
            pkixPolicyNode = Rfc3280CertPathUtilities.ProcessCertD(certPath, num, acceptablePolicies, pkixPolicyNode, array, inhibitAnyPolicy);
            pkixPolicyNode = Rfc3280CertPathUtilities.ProcessCertE(certPath, num, pkixPolicyNode);
            Rfc3280CertPathUtilities.ProcessCertF(certPath, num, pkixPolicyNode, explicitPolicy);
            if (num2 != count)
            {
                if (x509Certificate2 != null && x509Certificate2.Version == 1)
                {
                    throw new PkixCertPathValidatorException("Version 1 certificates can't be used as CA ones.", null, certPath, num);
                }
                Rfc3280CertPathUtilities.PrepareNextCertA(certPath, num);
                pkixPolicyNode = Rfc3280CertPathUtilities.PrepareCertB(certPath, num, array, pkixPolicyNode, policyMapping);
                Rfc3280CertPathUtilities.PrepareNextCertG(certPath, num, nameConstraintValidator);
                explicitPolicy   = Rfc3280CertPathUtilities.PrepareNextCertH1(certPath, num, explicitPolicy);
                policyMapping    = Rfc3280CertPathUtilities.PrepareNextCertH2(certPath, num, policyMapping);
                inhibitAnyPolicy = Rfc3280CertPathUtilities.PrepareNextCertH3(certPath, num, inhibitAnyPolicy);
                explicitPolicy   = Rfc3280CertPathUtilities.PrepareNextCertI1(certPath, num, explicitPolicy);
                policyMapping    = Rfc3280CertPathUtilities.PrepareNextCertI2(certPath, num, policyMapping);
                inhibitAnyPolicy = Rfc3280CertPathUtilities.PrepareNextCertJ(certPath, num, inhibitAnyPolicy);
                Rfc3280CertPathUtilities.PrepareNextCertK(certPath, num);
                maxPathLength = Rfc3280CertPathUtilities.PrepareNextCertL(certPath, num, maxPathLength);
                maxPathLength = Rfc3280CertPathUtilities.PrepareNextCertM(certPath, num, maxPathLength);
                Rfc3280CertPathUtilities.PrepareNextCertN(certPath, num);
                ISet criticalExtensionOids = x509Certificate2.GetCriticalExtensionOids();
                if (criticalExtensionOids != null)
                {
                    criticalExtensionOids = new HashSet(criticalExtensionOids);
                    criticalExtensionOids.Remove(X509Extensions.KeyUsage.Id);
                    criticalExtensionOids.Remove(X509Extensions.CertificatePolicies.Id);
                    criticalExtensionOids.Remove(X509Extensions.PolicyMappings.Id);
                    criticalExtensionOids.Remove(X509Extensions.InhibitAnyPolicy.Id);
                    criticalExtensionOids.Remove(X509Extensions.IssuingDistributionPoint.Id);
                    criticalExtensionOids.Remove(X509Extensions.DeltaCrlIndicator.Id);
                    criticalExtensionOids.Remove(X509Extensions.PolicyConstraints.Id);
                    criticalExtensionOids.Remove(X509Extensions.BasicConstraints.Id);
                    criticalExtensionOids.Remove(X509Extensions.SubjectAlternativeName.Id);
                    criticalExtensionOids.Remove(X509Extensions.NameConstraints.Id);
                }
                else
                {
                    criticalExtensionOids = new HashSet();
                }
                Rfc3280CertPathUtilities.PrepareNextCertO(certPath, num, criticalExtensionOids, certPathCheckers);
                x509Certificate   = x509Certificate2;
                workingIssuerName = x509Certificate.SubjectDN;
                try
                {
                    asymmetricKeyParameter = PkixCertPathValidatorUtilities.GetNextWorkingKey(certPath.Certificates, num);
                }
                catch (PkixCertPathValidatorException cause3)
                {
                    throw new PkixCertPathValidatorException("Next working key could not be retrieved.", cause3, certPath, num);
                }
                PkixCertPathValidatorUtilities.GetAlgorithmIdentifier(asymmetricKeyParameter);
            }
        }
        explicitPolicy = Rfc3280CertPathUtilities.WrapupCertA(explicitPolicy, x509Certificate2);
        explicitPolicy = Rfc3280CertPathUtilities.WrapupCertB(certPath, num + 1, explicitPolicy);
        ISet criticalExtensionOids2 = x509Certificate2.GetCriticalExtensionOids();

        if (criticalExtensionOids2 != null)
        {
            criticalExtensionOids2 = new HashSet(criticalExtensionOids2);
            criticalExtensionOids2.Remove(X509Extensions.KeyUsage.Id);
            criticalExtensionOids2.Remove(X509Extensions.CertificatePolicies.Id);
            criticalExtensionOids2.Remove(X509Extensions.PolicyMappings.Id);
            criticalExtensionOids2.Remove(X509Extensions.InhibitAnyPolicy.Id);
            criticalExtensionOids2.Remove(X509Extensions.IssuingDistributionPoint.Id);
            criticalExtensionOids2.Remove(X509Extensions.DeltaCrlIndicator.Id);
            criticalExtensionOids2.Remove(X509Extensions.PolicyConstraints.Id);
            criticalExtensionOids2.Remove(X509Extensions.BasicConstraints.Id);
            criticalExtensionOids2.Remove(X509Extensions.SubjectAlternativeName.Id);
            criticalExtensionOids2.Remove(X509Extensions.NameConstraints.Id);
            criticalExtensionOids2.Remove(X509Extensions.CrlDistributionPoints.Id);
        }
        else
        {
            criticalExtensionOids2 = new HashSet();
        }
        Rfc3280CertPathUtilities.WrapupCertF(certPath, num + 1, certPathCheckers, criticalExtensionOids2);
        PkixPolicyNode pkixPolicyNode2 = Rfc3280CertPathUtilities.WrapupCertG(certPath, paramsPkix, initialPolicies, num + 1, array, pkixPolicyNode, acceptablePolicies);

        if (explicitPolicy > 0 || pkixPolicyNode2 != null)
        {
            return(new PkixCertPathValidatorResult(trustAnchor, pkixPolicyNode2, x509Certificate2.GetPublicKey()));
        }
        throw new PkixCertPathValidatorException("Path processing failed on policy.", null, certPath, num);
    }
 internal static void CheckCrls(IX509AttributeCertificate attrCert, PkixParameters paramsPKIX, X509Certificate issuerCert, DateTime validDate, IList certPathCerts)
 {
     if (!paramsPKIX.IsRevocationEnabled)
     {
         return;
     }
     if (attrCert.GetExtensionValue(X509Extensions.NoRevAvail) == null)
     {
         CrlDistPoint crlDistPoint = null;
         try
         {
             crlDistPoint = CrlDistPoint.GetInstance(PkixCertPathValidatorUtilities.GetExtensionValue(attrCert, X509Extensions.CrlDistributionPoints));
         }
         catch (Exception cause)
         {
             throw new PkixCertPathValidatorException("CRL distribution point extension could not be read.", cause);
         }
         try
         {
             PkixCertPathValidatorUtilities.AddAdditionalStoresFromCrlDistributionPoint(crlDistPoint, paramsPKIX);
         }
         catch (Exception cause2)
         {
             throw new PkixCertPathValidatorException("No additional CRL locations could be decoded from CRL distribution point extension.", cause2);
         }
         CertStatus  certStatus  = new CertStatus();
         ReasonsMask reasonsMask = new ReasonsMask();
         Exception   cause3      = null;
         bool        flag        = false;
         if (crlDistPoint != null)
         {
             DistributionPoint[] array = null;
             try
             {
                 array = crlDistPoint.GetDistributionPoints();
             }
             catch (Exception cause4)
             {
                 throw new PkixCertPathValidatorException("Distribution points could not be read.", cause4);
             }
             try
             {
                 for (int i = 0; i < array.Length; i++)
                 {
                     if (certStatus.Status != 11)
                     {
                         break;
                     }
                     if (reasonsMask.IsAllReasons)
                     {
                         break;
                     }
                     PkixParameters paramsPKIX2 = (PkixParameters)paramsPKIX.Clone();
                     CheckCrl(array[i], attrCert, paramsPKIX2, validDate, issuerCert, certStatus, reasonsMask, certPathCerts);
                     flag = true;
                 }
             }
             catch (Exception innerException)
             {
                 cause3 = new Exception("No valid CRL for distribution point found.", innerException);
             }
         }
         if (certStatus.Status == 11 && !reasonsMask.IsAllReasons)
         {
             try
             {
                 Asn1Object asn1Object = null;
                 try
                 {
                     asn1Object = new Asn1InputStream(attrCert.Issuer.GetPrincipals()[0].GetEncoded()).ReadObject();
                 }
                 catch (Exception innerException2)
                 {
                     throw new Exception("Issuer from certificate for CRL could not be reencoded.", innerException2);
                 }
                 DistributionPoint dp          = new DistributionPoint(new DistributionPointName(0, new GeneralNames(new GeneralName(4, asn1Object))), null, null);
                 PkixParameters    paramsPKIX3 = (PkixParameters)paramsPKIX.Clone();
                 CheckCrl(dp, attrCert, paramsPKIX3, validDate, issuerCert, certStatus, reasonsMask, certPathCerts);
                 flag = true;
             }
             catch (Exception innerException3)
             {
                 cause3 = new Exception("No valid CRL for distribution point found.", innerException3);
             }
         }
         if (!flag)
         {
             throw new PkixCertPathValidatorException("No valid CRL found.", cause3);
         }
         if (certStatus.Status != 11)
         {
             string str  = certStatus.RevocationDate.Value.ToString("ddd MMM dd HH:mm:ss K yyyy");
             string str2 = "Attribute certificate revocation after " + str;
             str2 = str2 + ", reason: " + Rfc3280CertPathUtilities.CrlReasons[certStatus.Status];
             throw new PkixCertPathValidatorException(str2);
         }
         if (!reasonsMask.IsAllReasons && certStatus.Status == 11)
         {
             certStatus.Status = 12;
         }
         if (certStatus.Status == 12)
         {
             throw new PkixCertPathValidatorException("Attribute certificate status could not be determined.");
         }
     }
     else if (attrCert.GetExtensionValue(X509Extensions.CrlDistributionPoints) != null || attrCert.GetExtensionValue(X509Extensions.AuthorityInfoAccess) != null)
     {
         throw new PkixCertPathValidatorException("No rev avail extension is set, but also an AC revocation pointer.");
     }
 }
    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 item in set)
        {
            X509CertStoreSelector x509CertStoreSelector3 = new X509CertStoreSelector();
            x509CertStoreSelector3.Certificate = item;
            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);
            }
        }
        if (ex != null)
        {
            throw ex;
        }
        return(pkixCertPathBuilderResult.CertPath);
    }