package org.bouncycastle.pkix.jcajce;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.URL;
import java.security.GeneralSecurityException;
import java.security.PublicKey;
import java.security.SignatureException;
import java.security.cert.CertPath;
import java.security.cert.CertPathValidatorException;
import java.security.cert.Certificate;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateFactory;
import java.security.cert.CertificateNotYetValidException;
import java.security.cert.PKIXCertPathChecker;
import java.security.cert.PKIXParameters;
import java.security.cert.PolicyNode;
import java.security.cert.TrustAnchor;
import java.security.cert.X509CRL;
import java.security.cert.X509CRLEntry;
import java.security.cert.X509CertSelector;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.Vector;
import javax.security.auth.x500.X500Principal;
import org.bouncycastle.asn1.ASN1Encoding;
import org.bouncycastle.asn1.ASN1Enumerated;
import org.bouncycastle.asn1.ASN1IA5String;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.x509.AccessDescription;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.AuthorityInformationAccess;
import org.bouncycastle.asn1.x509.AuthorityKeyIdentifier;
import org.bouncycastle.asn1.x509.BasicConstraints;
import org.bouncycastle.asn1.x509.CRLDistPoint;
import org.bouncycastle.asn1.x509.DistributionPoint;
import org.bouncycastle.asn1.x509.DistributionPointName;
import org.bouncycastle.asn1.x509.Extension;
import org.bouncycastle.asn1.x509.GeneralName;
import org.bouncycastle.asn1.x509.GeneralNames;
import org.bouncycastle.asn1.x509.GeneralSubtree;
import org.bouncycastle.asn1.x509.IssuingDistributionPoint;
import org.bouncycastle.asn1.x509.NameConstraints;
import org.bouncycastle.asn1.x509.PolicyInformation;
import org.bouncycastle.asn1.x509.qualified.MonetaryValue;
import org.bouncycastle.asn1.x509.qualified.QCStatement;
import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.pkix.PKIXNameConstraintValidator;
import org.bouncycastle.pkix.PKIXNameConstraintValidatorException;
import org.bouncycastle.pkix.util.ErrorBundle;
import org.bouncycastle.pkix.util.LocaleString;
import org.bouncycastle.pkix.util.filter.TrustedInput;
import org.bouncycastle.pkix.util.filter.UntrustedInput;
import org.bouncycastle.pkix.util.filter.UntrustedUrlInput;
import org.bouncycastle.util.Integers;
import org.bouncycastle.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public class PKIXCertPathReviewer extends CertPathValidatorUtilities {
    private static final int NAME_CHECK_MAX = 1024;
    private static final String RESOURCE_NAME = "org.bouncycastle.pkix.CertPathReviewerMessages";
    protected CertPath certPath;
    protected List certs;
    protected Date currentDate;
    protected List[] errors;
    private boolean initialized;
    protected int n;
    protected List[] notifications;
    protected PKIXParameters pkixParams;
    protected PolicyNode policyTree;
    protected PublicKey subjectPublicKey;
    protected TrustAnchor trustAnchor;
    protected Date validDate;
    private static final String QC_STATEMENT = Extension.qCStatements.getId();
    private static final String CRL_DIST_POINTS = Extension.cRLDistributionPoints.getId();
    private static final String AUTH_INFO_ACCESS = Extension.authorityInfoAccess.getId();

    public PKIXCertPathReviewer() {
    }

    public PKIXCertPathReviewer(CertPath certPath, PKIXParameters pKIXParameters) throws CertPathReviewerException {
        init(certPath, pKIXParameters);
    }

    private String IPtoString(byte[] bArr) {
        try {
            return InetAddress.getByAddress(bArr).getHostAddress();
        } catch (Exception e) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i != bArr.length; i++) {
                sb.append(Integer.toHexString(bArr[i] & 255));
                sb.append(' ');
            }
            return sb.toString();
        }
    }

    private void checkCriticalExtensions() {
        List<PKIXCertPathChecker> certPathCheckers = this.pkixParams.getCertPathCheckers();
        Iterator<PKIXCertPathChecker> it = certPathCheckers.iterator();
        while (it.hasNext()) {
            try {
                try {
                    it.next().init(false);
                } catch (CertPathValidatorException e) {
                    throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.certPathCheckerError", new Object[]{e.getMessage(), e, e.getClass().getName()}), e);
                }
            } catch (CertPathReviewerException e2) {
                addError(e2.getErrorMessage(), e2.getIndex());
                return;
            }
        }
        for (int size = this.certs.size() - 1; size >= 0; size--) {
            X509Certificate x509Certificate = (X509Certificate) this.certs.get(size);
            Set<String> criticalExtensionOIDs = x509Certificate.getCriticalExtensionOIDs();
            if (criticalExtensionOIDs != null && !criticalExtensionOIDs.isEmpty()) {
                criticalExtensionOIDs.remove(KEY_USAGE);
                criticalExtensionOIDs.remove(CERTIFICATE_POLICIES);
                criticalExtensionOIDs.remove(POLICY_MAPPINGS);
                criticalExtensionOIDs.remove(INHIBIT_ANY_POLICY);
                criticalExtensionOIDs.remove(ISSUING_DISTRIBUTION_POINT);
                criticalExtensionOIDs.remove(DELTA_CRL_INDICATOR);
                criticalExtensionOIDs.remove(POLICY_CONSTRAINTS);
                criticalExtensionOIDs.remove(BASIC_CONSTRAINTS);
                criticalExtensionOIDs.remove(SUBJECT_ALTERNATIVE_NAME);
                criticalExtensionOIDs.remove(NAME_CONSTRAINTS);
                if (size == 0) {
                    criticalExtensionOIDs.remove(Extension.extendedKeyUsage.getId());
                }
                if (criticalExtensionOIDs.contains(QC_STATEMENT) && processQcStatements(x509Certificate, size)) {
                    criticalExtensionOIDs.remove(QC_STATEMENT);
                }
                Iterator<PKIXCertPathChecker> it2 = certPathCheckers.iterator();
                while (it2.hasNext()) {
                    try {
                        it2.next().check(x509Certificate, criticalExtensionOIDs);
                    } catch (CertPathValidatorException e3) {
                        throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.criticalExtensionError", new Object[]{e3.getMessage(), e3, e3.getClass().getName()}), e3.getCause(), this.certPath, size);
                    }
                }
                if (!criticalExtensionOIDs.isEmpty()) {
                    Iterator<String> it3 = criticalExtensionOIDs.iterator();
                    while (it3.hasNext()) {
                        addError(createErrorBundle("CertPathReviewer.unknownCriticalExt", new Object[]{new ASN1ObjectIdentifier(it3.next())}), size);
                    }
                }
            }
        }
    }

    private void checkNameConstraints() {
        PKIXNameConstraintValidator pKIXNameConstraintValidator = new PKIXNameConstraintValidator();
        try {
            for (int size = this.certs.size() - 1; size > 0; size--) {
                X509Certificate x509Certificate = (X509Certificate) this.certs.get(size);
                if (!isSelfIssued(x509Certificate)) {
                    X500Principal subjectPrincipal = getSubjectPrincipal(x509Certificate);
                    try {
                        ASN1Sequence aSN1Sequence = (ASN1Sequence) new ASN1InputStream(new ByteArrayInputStream(subjectPrincipal.getEncoded())).readObject();
                        try {
                            pKIXNameConstraintValidator.checkPermittedDN(aSN1Sequence);
                            try {
                                pKIXNameConstraintValidator.checkExcludedDN(aSN1Sequence);
                                try {
                                    ASN1Sequence aSN1Sequence2 = (ASN1Sequence) getExtensionValue(x509Certificate, SUBJECT_ALTERNATIVE_NAME);
                                    if (aSN1Sequence2 != null) {
                                        if (aSN1Sequence2.size() > 1024) {
                                            throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.subjAltNameExtError"), this.certPath, size);
                                        }
                                        for (int i = 0; i < aSN1Sequence2.size(); i++) {
                                            GeneralName generalName = GeneralName.getInstance(aSN1Sequence2.getObjectAt(i));
                                            try {
                                                pKIXNameConstraintValidator.checkPermitted(generalName);
                                                pKIXNameConstraintValidator.checkExcluded(generalName);
                                            } catch (PKIXNameConstraintValidatorException e) {
                                                throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.notPermittedEmail", new Object[]{new UntrustedInput(generalName)}), e, this.certPath, size);
                                            }
                                        }
                                    }
                                } catch (AnnotatedException e2) {
                                    throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.subjAltNameExtError"), e2, this.certPath, size);
                                }
                            } catch (PKIXNameConstraintValidatorException e3) {
                                throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.excludedDN", new Object[]{new UntrustedInput(subjectPrincipal.getName())}), e3, this.certPath, size);
                            }
                        } catch (PKIXNameConstraintValidatorException e4) {
                            throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.notPermittedDN", new Object[]{new UntrustedInput(subjectPrincipal.getName())}), e4, this.certPath, size);
                        }
                    } catch (IOException e5) {
                        throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.ncSubjectNameError", new Object[]{new UntrustedInput(subjectPrincipal)}), e5, this.certPath, size);
                    }
                }
                try {
                    ASN1Sequence aSN1Sequence3 = (ASN1Sequence) getExtensionValue(x509Certificate, NAME_CONSTRAINTS);
                    if (aSN1Sequence3 != null) {
                        NameConstraints nameConstraints = NameConstraints.getInstance(aSN1Sequence3);
                        GeneralSubtree[] permittedSubtrees = nameConstraints.getPermittedSubtrees();
                        if (permittedSubtrees != null) {
                            pKIXNameConstraintValidator.intersectPermittedSubtree(permittedSubtrees);
                        }
                        GeneralSubtree[] excludedSubtrees = nameConstraints.getExcludedSubtrees();
                        if (excludedSubtrees != null) {
                            for (int i2 = 0; i2 != excludedSubtrees.length; i2++) {
                                pKIXNameConstraintValidator.addExcludedSubtree(excludedSubtrees[i2]);
                            }
                        }
                    }
                } catch (AnnotatedException e6) {
                    throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.ncExtError"), e6, this.certPath, size);
                }
            }
        } catch (CertPathReviewerException e7) {
            addError(e7.getErrorMessage(), e7.getIndex());
        }
    }

    private void checkPathLength() {
        BasicConstraints basicConstraints;
        ASN1Integer pathLenConstraintInteger;
        int iMin = this.n;
        int i = 0;
        for (int size = this.certs.size() - 1; size > 0; size--) {
            X509Certificate x509Certificate = (X509Certificate) this.certs.get(size);
            if (!isSelfIssued(x509Certificate)) {
                if (iMin <= 0) {
                    addError(createErrorBundle("CertPathReviewer.pathLengthExtended"));
                }
                iMin--;
                i++;
            }
            try {
                basicConstraints = BasicConstraints.getInstance(getExtensionValue(x509Certificate, BASIC_CONSTRAINTS));
            } catch (AnnotatedException e) {
                addError(createErrorBundle("CertPathReviewer.processLengthConstError"), size);
                basicConstraints = null;
            }
            if (basicConstraints != null && basicConstraints.isCA() && (pathLenConstraintInteger = basicConstraints.getPathLenConstraintInteger()) != null) {
                iMin = Math.min(iMin, pathLenConstraintInteger.intPositiveValueExact());
            }
        }
        addNotification(createErrorBundle("CertPathReviewer.totalPathLength", new Object[]{Integers.valueOf(i)}));
    }

    private void checkPolicy() {
        PKIXPolicyNode pKIXPolicyNode;
        String str;
        ASN1Sequence aSN1Sequence;
        int iIntValueExact;
        String id;
        String str2 = "CertPathReviewer.policyExtError";
        Set<String> initialPolicies = this.pkixParams.getInitialPolicies();
        int i = this.n + 1;
        ArrayList[] arrayListArr = new ArrayList[i];
        for (int i2 = 0; i2 < i; i2++) {
            arrayListArr[i2] = new ArrayList();
        }
        HashSet hashSet = new HashSet();
        hashSet.add(org.bouncycastle.jce.provider.RFC3280CertPathUtilities.ANY_POLICY);
        PKIXPolicyNode pKIXPolicyNode2 = new PKIXPolicyNode(new ArrayList(), 0, hashSet, null, new HashSet(), org.bouncycastle.jce.provider.RFC3280CertPathUtilities.ANY_POLICY, false);
        arrayListArr[0].add(pKIXPolicyNode2);
        int i3 = this.pkixParams.isExplicitPolicyRequired() ? 0 : this.n + 1;
        int i4 = this.pkixParams.isAnyPolicyInhibited() ? 0 : this.n + 1;
        int i5 = this.pkixParams.isPolicyMappingInhibited() ? 0 : this.n + 1;
        try {
            int size = this.certs.size() - 1;
            X509Certificate x509Certificate = null;
            HashSet hashSet2 = null;
            while (size >= 0) {
                int i6 = this.n - size;
                X509Certificate x509Certificate2 = (X509Certificate) this.certs.get(size);
                try {
                    ASN1Sequence aSN1Sequence2 = (ASN1Sequence) getExtensionValue(x509Certificate2, CERTIFICATE_POLICIES);
                    if (aSN1Sequence2 == null || pKIXPolicyNode2 == null) {
                        str = str2;
                        aSN1Sequence = aSN1Sequence2;
                    } else {
                        Enumeration objects = aSN1Sequence2.getObjects();
                        HashSet hashSet3 = new HashSet();
                        while (objects.hasMoreElements()) {
                            PolicyInformation policyInformation = PolicyInformation.getInstance(objects.nextElement());
                            String str3 = str2;
                            ASN1ObjectIdentifier policyIdentifier = policyInformation.getPolicyIdentifier();
                            ASN1Sequence aSN1Sequence3 = aSN1Sequence2;
                            hashSet3.add(policyIdentifier.getId());
                            if (!org.bouncycastle.jce.provider.RFC3280CertPathUtilities.ANY_POLICY.equals(policyIdentifier.getId())) {
                                try {
                                    Set qualifierSet = getQualifierSet(policyInformation.getPolicyQualifiers());
                                    if (!processCertD1i(i6, arrayListArr, policyIdentifier, qualifierSet)) {
                                        processCertD1ii(i6, arrayListArr, policyIdentifier, qualifierSet);
                                    }
                                } catch (CertPathValidatorException e) {
                                    throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.policyQualifierError"), e, this.certPath, size);
                                }
                            }
                            str2 = str3;
                            aSN1Sequence2 = aSN1Sequence3;
                        }
                        str = str2;
                        aSN1Sequence = aSN1Sequence2;
                        if (hashSet2 == null || hashSet2.contains(org.bouncycastle.jce.provider.RFC3280CertPathUtilities.ANY_POLICY)) {
                            hashSet2 = hashSet3;
                        } else {
                            HashSet hashSet4 = new HashSet();
                            for (Object obj : hashSet2) {
                                if (hashSet3.contains(obj)) {
                                    hashSet4.add(obj);
                                }
                            }
                            hashSet2 = hashSet4;
                        }
                        if (i4 > 0 || (i6 < this.n && isSelfIssued(x509Certificate2))) {
                            Enumeration objects2 = aSN1Sequence.getObjects();
                            while (objects2.hasMoreElements()) {
                                PolicyInformation policyInformation2 = PolicyInformation.getInstance(objects2.nextElement());
                                if (org.bouncycastle.jce.provider.RFC3280CertPathUtilities.ANY_POLICY.equals(policyInformation2.getPolicyIdentifier().getId())) {
                                    try {
                                        Set qualifierSet2 = getQualifierSet(policyInformation2.getPolicyQualifiers());
                                        ArrayList arrayList = arrayListArr[i6 - 1];
                                        int i7 = 0;
                                        while (i7 < arrayList.size()) {
                                            PKIXPolicyNode pKIXPolicyNode3 = (PKIXPolicyNode) arrayList.get(i7);
                                            for (Object obj2 : pKIXPolicyNode3.getExpectedPolicies()) {
                                                ArrayList arrayList2 = arrayList;
                                                int i8 = i7;
                                                if (obj2 instanceof String) {
                                                    id = (String) obj2;
                                                } else {
                                                    if (obj2 instanceof ASN1ObjectIdentifier) {
                                                        id = ((ASN1ObjectIdentifier) obj2).getId();
                                                    }
                                                    arrayList = arrayList2;
                                                    i7 = i8;
                                                }
                                                Iterator children = pKIXPolicyNode3.getChildren();
                                                boolean z = false;
                                                while (children.hasNext()) {
                                                    Iterator it = children;
                                                    if (id.equals(((PKIXPolicyNode) children.next()).getValidPolicy())) {
                                                        z = true;
                                                    }
                                                    children = it;
                                                }
                                                if (!z) {
                                                    HashSet hashSet5 = new HashSet();
                                                    hashSet5.add(id);
                                                    PKIXPolicyNode pKIXPolicyNode4 = new PKIXPolicyNode(new ArrayList(), i6, hashSet5, pKIXPolicyNode3, qualifierSet2, id, false);
                                                    PKIXPolicyNode pKIXPolicyNode5 = pKIXPolicyNode3;
                                                    pKIXPolicyNode5.addChild(pKIXPolicyNode4);
                                                    pKIXPolicyNode3 = pKIXPolicyNode5;
                                                    arrayListArr[i6].add(pKIXPolicyNode4);
                                                }
                                                arrayList = arrayList2;
                                                i7 = i8;
                                            }
                                            i7++;
                                        }
                                    } catch (CertPathValidatorException e2) {
                                        throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.policyQualifierError"), e2, this.certPath, size);
                                    }
                                }
                            }
                        }
                        int i9 = i6 - 1;
                        while (i9 >= 0) {
                            ArrayList arrayList3 = arrayListArr[i9];
                            int i10 = i9;
                            for (int i11 = 0; i11 < arrayList3.size(); i11++) {
                                PKIXPolicyNode pKIXPolicyNode6 = (PKIXPolicyNode) arrayList3.get(i11);
                                if (!pKIXPolicyNode6.hasChildren()) {
                                    PKIXPolicyNode pKIXPolicyNodeRemovePolicyNode = removePolicyNode(pKIXPolicyNode2, arrayListArr, pKIXPolicyNode6);
                                    pKIXPolicyNode2 = pKIXPolicyNodeRemovePolicyNode;
                                    if (pKIXPolicyNodeRemovePolicyNode == null) {
                                        break;
                                    }
                                }
                            }
                            i9 = i10 - 1;
                        }
                        Set<String> criticalExtensionOIDs = x509Certificate2.getCriticalExtensionOIDs();
                        if (criticalExtensionOIDs != null) {
                            boolean zContains = criticalExtensionOIDs.contains(CERTIFICATE_POLICIES);
                            ArrayList arrayList4 = arrayListArr[i6];
                            for (int i12 = 0; i12 < arrayList4.size(); i12++) {
                                ((PKIXPolicyNode) arrayList4.get(i12)).setCritical(zContains);
                            }
                        }
                        pKIXPolicyNode2 = pKIXPolicyNode2;
                    }
                    if (aSN1Sequence == null) {
                        pKIXPolicyNode2 = null;
                    }
                    if (i3 <= 0 && pKIXPolicyNode2 == null) {
                        throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.noValidPolicyTree"));
                    }
                    if (i6 != this.n) {
                        try {
                            ASN1Primitive extensionValue = getExtensionValue(x509Certificate2, POLICY_MAPPINGS);
                            if (extensionValue != null) {
                                ASN1Sequence aSN1Sequence4 = (ASN1Sequence) extensionValue;
                                int i13 = 0;
                                while (i13 < aSN1Sequence4.size()) {
                                    ASN1Sequence aSN1Sequence5 = (ASN1Sequence) aSN1Sequence4.getObjectAt(i13);
                                    ASN1Sequence aSN1Sequence6 = aSN1Sequence4;
                                    ASN1ObjectIdentifier aSN1ObjectIdentifier = (ASN1ObjectIdentifier) aSN1Sequence5.getObjectAt(0);
                                    ASN1ObjectIdentifier aSN1ObjectIdentifier2 = (ASN1ObjectIdentifier) aSN1Sequence5.getObjectAt(1);
                                    if (org.bouncycastle.jce.provider.RFC3280CertPathUtilities.ANY_POLICY.equals(aSN1ObjectIdentifier.getId())) {
                                        throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.invalidPolicyMapping"), this.certPath, size);
                                    }
                                    if (org.bouncycastle.jce.provider.RFC3280CertPathUtilities.ANY_POLICY.equals(aSN1ObjectIdentifier2.getId())) {
                                        throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.invalidPolicyMapping"), this.certPath, size);
                                    }
                                    i13++;
                                    aSN1Sequence4 = aSN1Sequence6;
                                }
                            }
                            if (extensionValue != 0) {
                                ASN1Sequence aSN1Sequence7 = (ASN1Sequence) extensionValue;
                                HashMap map = new HashMap();
                                HashSet<String> hashSet6 = new HashSet();
                                PKIXPolicyNode pKIXPolicyNode7 = pKIXPolicyNode2;
                                int i14 = 0;
                                while (i14 < aSN1Sequence7.size()) {
                                    ASN1Sequence aSN1Sequence8 = (ASN1Sequence) aSN1Sequence7.getObjectAt(i14);
                                    ASN1Sequence aSN1Sequence9 = aSN1Sequence7;
                                    String id2 = ((ASN1ObjectIdentifier) aSN1Sequence8.getObjectAt(0)).getId();
                                    int i15 = i14;
                                    String id3 = ((ASN1ObjectIdentifier) aSN1Sequence8.getObjectAt(1)).getId();
                                    if (map.containsKey(id2)) {
                                        ((Set) map.get(id2)).add(id3);
                                    } else {
                                        HashSet hashSet7 = new HashSet();
                                        hashSet7.add(id3);
                                        map.put(id2, hashSet7);
                                        hashSet6.add(id2);
                                    }
                                    i14 = i15 + 1;
                                    aSN1Sequence7 = aSN1Sequence9;
                                }
                                pKIXPolicyNode2 = pKIXPolicyNode7;
                                for (String str4 : hashSet6) {
                                    if (i5 > 0) {
                                        try {
                                            prepareNextCertB1(i6, arrayListArr, str4, map, x509Certificate2);
                                        } catch (CertPathValidatorException e3) {
                                            throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.policyQualifierError"), e3, this.certPath, size);
                                        } catch (AnnotatedException e4) {
                                            throw new CertPathReviewerException(createErrorBundle(str), e4, this.certPath, size);
                                        }
                                    } else if (i5 <= 0) {
                                        pKIXPolicyNode2 = prepareNextCertB2(i6, arrayListArr, str4, pKIXPolicyNode2);
                                    }
                                }
                            }
                            if (isSelfIssued(x509Certificate2)) {
                                i3 = i3;
                            } else {
                                i3 = i3 != 0 ? i3 - 1 : i3;
                                if (i5 != 0) {
                                    i5--;
                                }
                                if (i4 != 0) {
                                    i4--;
                                }
                            }
                            try {
                                ASN1Sequence aSN1Sequence10 = (ASN1Sequence) getExtensionValue(x509Certificate2, POLICY_CONSTRAINTS);
                                if (aSN1Sequence10 != null) {
                                    Enumeration objects3 = aSN1Sequence10.getObjects();
                                    while (objects3.hasMoreElements()) {
                                        ASN1TaggedObject aSN1TaggedObject = (ASN1TaggedObject) objects3.nextElement();
                                        switch (aSN1TaggedObject.getTagNo()) {
                                            case 0:
                                                int iIntValueExact2 = ASN1Integer.getInstance(aSN1TaggedObject, false).intValueExact();
                                                if (iIntValueExact2 < i3) {
                                                    i3 = iIntValueExact2;
                                                }
                                                break;
                                            case 1:
                                                int iIntValueExact3 = ASN1Integer.getInstance(aSN1TaggedObject, false).intValueExact();
                                                if (iIntValueExact3 < i5) {
                                                    i5 = iIntValueExact3;
                                                }
                                                break;
                                        }
                                    }
                                }
                                try {
                                    ASN1Integer aSN1Integer = (ASN1Integer) getExtensionValue(x509Certificate2, INHIBIT_ANY_POLICY);
                                    if (aSN1Integer != null && (iIntValueExact = aSN1Integer.intValueExact()) < i4) {
                                        i4 = iIntValueExact;
                                    }
                                } catch (AnnotatedException e5) {
                                    throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.policyInhibitExtError"), this.certPath, size);
                                }
                            } catch (AnnotatedException e6) {
                                throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.policyConstExtError"), this.certPath, size);
                            }
                        } catch (AnnotatedException e7) {
                            throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.policyMapExtError"), e7, this.certPath, size);
                        }
                    }
                    size--;
                    x509Certificate = x509Certificate2;
                    str2 = str;
                } catch (AnnotatedException e8) {
                    throw new CertPathReviewerException(createErrorBundle(str2), e8, this.certPath, size);
                }
            }
            int i16 = i3;
            int i17 = (isSelfIssued(x509Certificate) || i16 <= 0) ? i16 : i16 - 1;
            try {
                ASN1Sequence aSN1Sequence11 = (ASN1Sequence) getExtensionValue(x509Certificate, POLICY_CONSTRAINTS);
                if (aSN1Sequence11 != null) {
                    Enumeration objects4 = aSN1Sequence11.getObjects();
                    int i18 = i17;
                    while (objects4.hasMoreElements()) {
                        ASN1TaggedObject aSN1TaggedObject2 = (ASN1TaggedObject) objects4.nextElement();
                        switch (aSN1TaggedObject2.getTagNo()) {
                            case 0:
                                if (ASN1Integer.getInstance(aSN1TaggedObject2, false).intValueExact() == 0) {
                                    i18 = 0;
                                }
                                break;
                            default:
                                break;
                        }
                    }
                    i17 = i18;
                }
                if (pKIXPolicyNode2 != null) {
                    if (!isAnyPolicy(initialPolicies)) {
                        HashSet<PKIXPolicyNode> hashSet8 = new HashSet();
                        for (int i19 = 0; i19 < i; i19++) {
                            ArrayList arrayList5 = arrayListArr[i19];
                            for (int i20 = 0; i20 < arrayList5.size(); i20++) {
                                PKIXPolicyNode pKIXPolicyNode8 = (PKIXPolicyNode) arrayList5.get(i20);
                                if (org.bouncycastle.jce.provider.RFC3280CertPathUtilities.ANY_POLICY.equals(pKIXPolicyNode8.getValidPolicy())) {
                                    Iterator children2 = pKIXPolicyNode8.getChildren();
                                    while (children2.hasNext()) {
                                        PKIXPolicyNode pKIXPolicyNode9 = (PKIXPolicyNode) children2.next();
                                        if (!org.bouncycastle.jce.provider.RFC3280CertPathUtilities.ANY_POLICY.equals(pKIXPolicyNode9.getValidPolicy())) {
                                            hashSet8.add(pKIXPolicyNode9);
                                        }
                                    }
                                }
                            }
                        }
                        for (PKIXPolicyNode pKIXPolicyNode10 : hashSet8) {
                            if (!initialPolicies.contains(pKIXPolicyNode10.getValidPolicy())) {
                                pKIXPolicyNode2 = removePolicyNode(pKIXPolicyNode2, arrayListArr, pKIXPolicyNode10);
                            }
                        }
                        if (pKIXPolicyNode2 != null) {
                            for (int i21 = this.n - 1; i21 >= 0; i21--) {
                                ArrayList arrayList6 = arrayListArr[i21];
                                for (int i22 = 0; i22 < arrayList6.size(); i22++) {
                                    PKIXPolicyNode pKIXPolicyNode11 = (PKIXPolicyNode) arrayList6.get(i22);
                                    if (!pKIXPolicyNode11.hasChildren()) {
                                        pKIXPolicyNode2 = removePolicyNode(pKIXPolicyNode2, arrayListArr, pKIXPolicyNode11);
                                    }
                                }
                            }
                        }
                    } else if (this.pkixParams.isExplicitPolicyRequired()) {
                        if (hashSet2.isEmpty()) {
                            throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.explicitPolicy"), this.certPath, size);
                        }
                        HashSet hashSet9 = new HashSet();
                        for (int i23 = 0; i23 < i; i23++) {
                            ArrayList arrayList7 = arrayListArr[i23];
                            for (int i24 = 0; i24 < arrayList7.size(); i24++) {
                                PKIXPolicyNode pKIXPolicyNode12 = (PKIXPolicyNode) arrayList7.get(i24);
                                if (org.bouncycastle.jce.provider.RFC3280CertPathUtilities.ANY_POLICY.equals(pKIXPolicyNode12.getValidPolicy())) {
                                    Iterator children3 = pKIXPolicyNode12.getChildren();
                                    while (children3.hasNext()) {
                                        hashSet9.add(children3.next());
                                    }
                                }
                            }
                        }
                        Iterator it2 = hashSet9.iterator();
                        while (it2.hasNext()) {
                            hashSet2.contains(((PKIXPolicyNode) it2.next()).getValidPolicy());
                        }
                        if (pKIXPolicyNode2 != null) {
                            for (int i25 = this.n - 1; i25 >= 0; i25--) {
                                ArrayList arrayList8 = arrayListArr[i25];
                                for (int i26 = 0; i26 < arrayList8.size(); i26++) {
                                    PKIXPolicyNode pKIXPolicyNode13 = (PKIXPolicyNode) arrayList8.get(i26);
                                    if (!pKIXPolicyNode13.hasChildren()) {
                                        pKIXPolicyNode2 = removePolicyNode(pKIXPolicyNode2, arrayListArr, pKIXPolicyNode13);
                                    }
                                }
                            }
                        }
                    }
                    pKIXPolicyNode = pKIXPolicyNode2;
                } else {
                    if (this.pkixParams.isExplicitPolicyRequired()) {
                        throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.explicitPolicy"), this.certPath, size);
                    }
                    pKIXPolicyNode = null;
                }
                if (i17 <= 0 && pKIXPolicyNode == null) {
                    throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.invalidPolicy"));
                }
            } catch (AnnotatedException e9) {
                throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.policyConstExtError"), this.certPath, size);
            }
        } catch (CertPathReviewerException e10) {
            addError(e10.getErrorMessage(), e10.getIndex());
        }
    }

    /* JADX WARN: Code duplicated, block: B:100:0x0268  */
    /* JADX WARN: Code duplicated, block: B:106:0x027e A[Catch: AnnotatedException -> 0x0283, TRY_LEAVE, TryCatch #3 {AnnotatedException -> 0x0283, blocks: (B:104:0x0276, B:106:0x027e), top: B:160:0x0276 }] */
    /* JADX WARN: Code duplicated, block: B:110:0x028d  */
    /* JADX WARN: Code duplicated, block: B:114:0x02a0 A[LOOP:1: B:112:0x029a->B:114:0x02a0, LOOP_END] */
    /* JADX WARN: Code duplicated, block: B:118:0x02c1 A[LOOP:2: B:116:0x02bb->B:118:0x02c1, LOOP_END] */
    /* JADX WARN: Code duplicated, block: B:129:0x0311  */
    /* JADX WARN: Code duplicated, block: B:136:0x032e A[Catch: AnnotatedException -> 0x033f, TryCatch #6 {AnnotatedException -> 0x033f, blocks: (B:134:0x0322, B:136:0x032e, B:138:0x0334), top: B:165:0x0322 }] */
    /* JADX WARN: Code duplicated, block: B:139:0x033c  */
    /* JADX WARN: Code duplicated, block: B:145:0x034f  */
    /* JADX WARN: Code duplicated, block: B:158:0x0177 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Code duplicated, block: B:167:0x019f A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Code duplicated, block: B:175:0x025b A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Code duplicated, block: B:184:0x0382 A[SYNTHETIC] */
    /* JADX WARN: Code duplicated, block: B:36:0x00e7  */
    /* JADX WARN: Code duplicated, block: B:38:0x00ed A[Catch: IllegalArgumentException -> 0x00fc, TRY_ENTER, TryCatch #5 {IllegalArgumentException -> 0x00fc, blocks: (B:38:0x00ed, B:39:0x00f2), top: B:163:0x00eb }] */
    /* JADX WARN: Code duplicated, block: B:39:0x00f2 A[Catch: IllegalArgumentException -> 0x00fc, TRY_LEAVE, TryCatch #5 {IllegalArgumentException -> 0x00fc, blocks: (B:38:0x00ed, B:39:0x00f2), top: B:163:0x00eb }] */
    /* JADX WARN: Code duplicated, block: B:52:0x012e  */
    /* JADX WARN: Code duplicated, block: B:54:0x0131  */
    /* JADX WARN: Code duplicated, block: B:56:0x0137  */
    /* JADX WARN: Code duplicated, block: B:57:0x013c  */
    /* JADX WARN: Code duplicated, block: B:63:0x0157  */
    /* JADX WARN: Code duplicated, block: B:67:0x0166  */
    /* JADX WARN: Code duplicated, block: B:73:0x0199  */
    /* JADX WARN: Code duplicated, block: B:79:0x01cc  */
    /* JADX WARN: Code duplicated, block: B:85:0x01fd  */
    /* JADX WARN: Code duplicated, block: B:98:0x0263 A[Catch: AnnotatedException -> 0x026b, TRY_LEAVE, TryCatch #15 {AnnotatedException -> 0x026b, blocks: (B:96:0x025b, B:98:0x0263), top: B:175:0x025b }] */
    private void checkSignatures() {
        TrustAnchor trustAnchor;
        ErrorBundle errorBundleCreateErrorBundle;
        TrustAnchor trustAnchor2;
        X500Principal x500Principal;
        X509Certificate trustedCert;
        PublicKey publicKey;
        int size;
        X500Principal subjectX500Principal;
        PublicKey nextWorkingKey;
        X509Certificate x509Certificate;
        int i;
        ErrorBundle errorBundleCreateErrorBundle2;
        ErrorBundle errorBundleCreateErrorBundle3;
        CRLDistPoint cRLDistPoint;
        AuthorityInformationAccess authorityInformationAccess;
        Iterator it;
        Iterator it2;
        ASN1Primitive extensionValue;
        ASN1Primitive extensionValue2;
        CRLDistPoint cRLDistPoint2;
        String str;
        boolean[] keyUsage;
        BasicConstraints basicConstraints;
        byte[] extensionValue3;
        AuthorityKeyIdentifier authorityKeyIdentifier;
        GeneralNames authorityCertIssuer;
        GeneralName generalName;
        BigInteger authorityCertSerialNumber;
        PublicKey cAPublicKey;
        X509Certificate trustedCert2;
        X500Principal x500Principal2;
        boolean[] keyUsage2;
        ErrorBundle errorBundleCreateErrorBundle4;
        addNotification(createErrorBundle("CertPathReviewer.certPathValidDate", new Object[]{new TrustedInput(this.validDate), new TrustedInput(this.currentDate)}));
        try {
            X509Certificate x509Certificate2 = (X509Certificate) this.certs.get(this.certs.size() - 1);
            Collection trustAnchors = getTrustAnchors(x509Certificate2, this.pkixParams.getTrustAnchors());
            if (trustAnchors.size() > 1) {
                errorBundleCreateErrorBundle4 = createErrorBundle("CertPathReviewer.conflictingTrustAnchors", new Object[]{Integers.valueOf(trustAnchors.size()), new UntrustedInput(x509Certificate2.getIssuerX500Principal())});
            } else {
                if (trustAnchors.isEmpty()) {
                    errorBundleCreateErrorBundle4 = createErrorBundle("CertPathReviewer.noTrustAnchorFound", new Object[]{new UntrustedInput(x509Certificate2.getIssuerX500Principal()), Integers.valueOf(this.pkixParams.getTrustAnchors().size())});
                } else {
                    trustAnchor = (TrustAnchor) trustAnchors.iterator().next();
                    try {
                        try {
                            CertPathValidatorUtilities.verifyX509Certificate(x509Certificate2, trustAnchor.getTrustedCert() != null ? trustAnchor.getTrustedCert().getPublicKey() : trustAnchor.getCAPublicKey(), this.pkixParams.getSigProvider());
                        } catch (SignatureException e) {
                            addError(createErrorBundle("CertPathReviewer.trustButInvalidCert"));
                        } catch (Exception e2) {
                        }
                    } catch (CertPathReviewerException e3) {
                        e = e3;
                        errorBundleCreateErrorBundle = e.getErrorMessage();
                        addError(errorBundleCreateErrorBundle);
                    } catch (Throwable th) {
                        th = th;
                        errorBundleCreateErrorBundle = createErrorBundle("CertPathReviewer.unknown", new Object[]{new UntrustedInput(th.getMessage()), new UntrustedInput(th)});
                        addError(errorBundleCreateErrorBundle);
                    }
                }
                trustAnchor2 = trustAnchor;
                if (trustAnchor2 != null) {
                    trustedCert2 = trustAnchor2.getTrustedCert();
                    try {
                        if (trustedCert2 != null) {
                            x500Principal2 = getSubjectPrincipal(trustedCert2);
                        } else {
                            x500Principal2 = new X500Principal(trustAnchor2.getCAName());
                        }
                    } catch (IllegalArgumentException e4) {
                        addError(createErrorBundle("CertPathReviewer.trustDNInvalid", new Object[]{new UntrustedInput(trustAnchor2.getCAName())}));
                        x500Principal2 = null;
                    }
                    if (trustedCert2 != null && (keyUsage2 = trustedCert2.getKeyUsage()) != null && (keyUsage2.length <= 5 || !keyUsage2[5])) {
                        addNotification(createErrorBundle("CertPathReviewer.trustKeyUsage"));
                    }
                    x500Principal = x500Principal2;
                } else {
                    x500Principal = null;
                }
                if (trustAnchor2 != null) {
                    trustedCert = trustAnchor2.getTrustedCert();
                    if (trustedCert != null) {
                        cAPublicKey = trustedCert.getPublicKey();
                    } else {
                        cAPublicKey = trustAnchor2.getCAPublicKey();
                    }
                    publicKey = cAPublicKey;
                    try {
                        AlgorithmIdentifier algorithmIdentifier = getAlgorithmIdentifier(publicKey);
                        algorithmIdentifier.getAlgorithm();
                        algorithmIdentifier.getParameters();
                    } catch (CertPathValidatorException e5) {
                        addError(createErrorBundle("CertPathReviewer.trustPubKeyError"));
                    }
                } else {
                    trustedCert = null;
                    publicKey = null;
                }
                size = this.certs.size() - 1;
                subjectX500Principal = x500Principal;
                nextWorkingKey = publicKey;
                while (true) {
                    x509Certificate = trustedCert;
                    if (size >= 0) {
                        this.trustAnchor = trustAnchor2;
                        this.subjectPublicKey = nextWorkingKey;
                        return;
                    }
                    i = this.n - size;
                    trustedCert = (X509Certificate) this.certs.get(size);
                    if (nextWorkingKey != null) {
                        try {
                            CertPathValidatorUtilities.verifyX509Certificate(trustedCert, nextWorkingKey, this.pkixParams.getSigProvider());
                        } catch (GeneralSecurityException e6) {
                            errorBundleCreateErrorBundle2 = createErrorBundle("CertPathReviewer.signatureNotVerified", new Object[]{e6.getMessage(), e6, e6.getClass().getName()});
                            addError(errorBundleCreateErrorBundle2, size);
                        }
                    } else {
                        if (isSelfIssued(trustedCert)) {
                            try {
                                CertPathValidatorUtilities.verifyX509Certificate(trustedCert, trustedCert.getPublicKey(), this.pkixParams.getSigProvider());
                                addError(createErrorBundle("CertPathReviewer.rootKeyIsValidButNotATrustAnchor"), size);
                            } catch (GeneralSecurityException e7) {
                                errorBundleCreateErrorBundle2 = createErrorBundle("CertPathReviewer.signatureNotVerified", new Object[]{e7.getMessage(), e7, e7.getClass().getName()});
                                addError(errorBundleCreateErrorBundle2, size);
                            }
                        } else {
                            errorBundleCreateErrorBundle2 = createErrorBundle("CertPathReviewer.NoIssuerPublicKey");
                            extensionValue3 = trustedCert.getExtensionValue(Extension.authorityKeyIdentifier.getId());
                            if (extensionValue3 != null && (authorityCertIssuer = (authorityKeyIdentifier = AuthorityKeyIdentifier.getInstance(ASN1OctetString.getInstance(extensionValue3).getOctets())).getAuthorityCertIssuer()) != null) {
                                generalName = authorityCertIssuer.getNames()[0];
                                authorityCertSerialNumber = authorityKeyIdentifier.getAuthorityCertSerialNumber();
                                if (authorityCertSerialNumber != null) {
                                    errorBundleCreateErrorBundle2.setExtraArguments(new Object[]{new LocaleString(RESOURCE_NAME, "missingIssuer"), " \"", generalName, "\" ", new LocaleString(RESOURCE_NAME, "missingSerial"), " ", authorityCertSerialNumber});
                                }
                            }
                        }
                        addError(errorBundleCreateErrorBundle2, size);
                    }
                    try {
                        trustedCert.checkValidity(this.validDate);
                    } catch (CertificateExpiredException e8) {
                        errorBundleCreateErrorBundle3 = createErrorBundle("CertPathReviewer.certificateExpired", new Object[]{new TrustedInput(trustedCert.getNotAfter())});
                        addError(errorBundleCreateErrorBundle3, size);
                    } catch (CertificateNotYetValidException e9) {
                        errorBundleCreateErrorBundle3 = createErrorBundle("CertPathReviewer.certificateNotYetValid", new Object[]{new TrustedInput(trustedCert.getNotBefore())});
                        addError(errorBundleCreateErrorBundle3, size);
                    }
                    if (this.pkixParams.isRevocationEnabled()) {
                        try {
                            extensionValue2 = getExtensionValue(trustedCert, CRL_DIST_POINTS);
                            if (extensionValue2 != null) {
                                cRLDistPoint2 = CRLDistPoint.getInstance(extensionValue2);
                            } else {
                                cRLDistPoint2 = null;
                            }
                            cRLDistPoint = cRLDistPoint2;
                        } catch (AnnotatedException e10) {
                            addError(createErrorBundle("CertPathReviewer.crlDistPtExtError"), size);
                            cRLDistPoint = null;
                        }
                        try {
                            extensionValue = getExtensionValue(trustedCert, AUTH_INFO_ACCESS);
                            if (extensionValue != null) {
                                authorityInformationAccess = AuthorityInformationAccess.getInstance(extensionValue);
                            } else {
                                authorityInformationAccess = null;
                            }
                        } catch (AnnotatedException e11) {
                            addError(createErrorBundle("CertPathReviewer.crlAuthInfoAccError"), size);
                        }
                        Vector cRLDistUrls = getCRLDistUrls(cRLDistPoint);
                        Vector oCSPUrls = getOCSPUrls(authorityInformationAccess);
                        it = cRLDistUrls.iterator();
                        while (it.hasNext()) {
                            addNotification(createErrorBundle("CertPathReviewer.crlDistPoint", new Object[]{new UntrustedUrlInput(it.next())}), size);
                        }
                        it2 = oCSPUrls.iterator();
                        while (it2.hasNext()) {
                            addNotification(createErrorBundle("CertPathReviewer.ocspLocation", new Object[]{new UntrustedUrlInput(it2.next())}), size);
                        }
                        try {
                            checkRevocation(this.pkixParams, trustedCert, this.validDate, x509Certificate, nextWorkingKey, cRLDistUrls, oCSPUrls, size);
                        } catch (CertPathReviewerException e12) {
                            addError(e12.getErrorMessage(), size);
                        }
                    }
                    if (subjectX500Principal != null && !trustedCert.getIssuerX500Principal().equals(subjectX500Principal)) {
                        addError(createErrorBundle("CertPathReviewer.certWrongIssuer", new Object[]{subjectX500Principal.getName(), trustedCert.getIssuerX500Principal().getName()}), size);
                    }
                    if (i != this.n) {
                        str = "CertPathReviewer.noCACert";
                        if (trustedCert != null && trustedCert.getVersion() == 1) {
                            addError(createErrorBundle("CertPathReviewer.noCACert"), size);
                        }
                        try {
                            basicConstraints = BasicConstraints.getInstance(getExtensionValue(trustedCert, BASIC_CONSTRAINTS));
                            if (basicConstraints != null) {
                                if (!basicConstraints.isCA()) {
                                }
                                keyUsage = trustedCert.getKeyUsage();
                                if (keyUsage != null && (keyUsage.length <= 5 || !keyUsage[5])) {
                                    addError(createErrorBundle("CertPathReviewer.noCertSign"), size);
                                }
                            } else {
                                str = "CertPathReviewer.noBasicConstraints";
                            }
                            addError(createErrorBundle(str), size);
                        } catch (AnnotatedException e13) {
                            addError(createErrorBundle("CertPathReviewer.errorProcesingBC"), size);
                        }
                        keyUsage = trustedCert.getKeyUsage();
                        if (keyUsage != null) {
                            addError(createErrorBundle("CertPathReviewer.noCertSign"), size);
                        }
                    }
                    subjectX500Principal = trustedCert.getSubjectX500Principal();
                    try {
                        nextWorkingKey = getNextWorkingKey(this.certs, size);
                        AlgorithmIdentifier algorithmIdentifier2 = getAlgorithmIdentifier(nextWorkingKey);
                        algorithmIdentifier2.getAlgorithm();
                        algorithmIdentifier2.getParameters();
                    } catch (CertPathValidatorException e14) {
                        addError(createErrorBundle("CertPathReviewer.pubKeyError"), size);
                    }
                    size--;
                }
            }
            addError(errorBundleCreateErrorBundle4);
            trustAnchor = null;
            while (true) {
                x509Certificate = trustedCert;
                if (size >= 0) {
                    this.trustAnchor = trustAnchor2;
                    this.subjectPublicKey = nextWorkingKey;
                    return;
                }
                i = this.n - size;
                trustedCert = (X509Certificate) this.certs.get(size);
                if (nextWorkingKey != null) {
                    CertPathValidatorUtilities.verifyX509Certificate(trustedCert, nextWorkingKey, this.pkixParams.getSigProvider());
                } else {
                    if (isSelfIssued(trustedCert)) {
                        CertPathValidatorUtilities.verifyX509Certificate(trustedCert, trustedCert.getPublicKey(), this.pkixParams.getSigProvider());
                        addError(createErrorBundle("CertPathReviewer.rootKeyIsValidButNotATrustAnchor"), size);
                    } else {
                        errorBundleCreateErrorBundle2 = createErrorBundle("CertPathReviewer.NoIssuerPublicKey");
                        extensionValue3 = trustedCert.getExtensionValue(Extension.authorityKeyIdentifier.getId());
                        if (extensionValue3 != null) {
                            generalName = authorityCertIssuer.getNames()[0];
                            authorityCertSerialNumber = authorityKeyIdentifier.getAuthorityCertSerialNumber();
                            if (authorityCertSerialNumber != null) {
                                errorBundleCreateErrorBundle2.setExtraArguments(new Object[]{new LocaleString(RESOURCE_NAME, "missingIssuer"), " \"", generalName, "\" ", new LocaleString(RESOURCE_NAME, "missingSerial"), " ", authorityCertSerialNumber});
                            }
                        }
                    }
                    addError(errorBundleCreateErrorBundle2, size);
                }
                trustedCert.checkValidity(this.validDate);
                if (this.pkixParams.isRevocationEnabled()) {
                    extensionValue2 = getExtensionValue(trustedCert, CRL_DIST_POINTS);
                    if (extensionValue2 != null) {
                        cRLDistPoint2 = CRLDistPoint.getInstance(extensionValue2);
                    } else {
                        cRLDistPoint2 = null;
                    }
                    cRLDistPoint = cRLDistPoint2;
                    extensionValue = getExtensionValue(trustedCert, AUTH_INFO_ACCESS);
                    if (extensionValue != null) {
                        authorityInformationAccess = AuthorityInformationAccess.getInstance(extensionValue);
                    } else {
                        authorityInformationAccess = null;
                    }
                    Vector cRLDistUrls2 = getCRLDistUrls(cRLDistPoint);
                    Vector oCSPUrls2 = getOCSPUrls(authorityInformationAccess);
                    it = cRLDistUrls2.iterator();
                    while (it.hasNext()) {
                        addNotification(createErrorBundle("CertPathReviewer.crlDistPoint", new Object[]{new UntrustedUrlInput(it.next())}), size);
                    }
                    it2 = oCSPUrls2.iterator();
                    while (it2.hasNext()) {
                        addNotification(createErrorBundle("CertPathReviewer.ocspLocation", new Object[]{new UntrustedUrlInput(it2.next())}), size);
                    }
                    checkRevocation(this.pkixParams, trustedCert, this.validDate, x509Certificate, nextWorkingKey, cRLDistUrls2, oCSPUrls2, size);
                }
                if (subjectX500Principal != null) {
                    addError(createErrorBundle("CertPathReviewer.certWrongIssuer", new Object[]{subjectX500Principal.getName(), trustedCert.getIssuerX500Principal().getName()}), size);
                }
                if (i != this.n) {
                    str = "CertPathReviewer.noCACert";
                    if (trustedCert != null) {
                        addError(createErrorBundle("CertPathReviewer.noCACert"), size);
                    }
                    basicConstraints = BasicConstraints.getInstance(getExtensionValue(trustedCert, BASIC_CONSTRAINTS));
                    if (basicConstraints != null) {
                        if (!basicConstraints.isCA()) {
                        }
                        keyUsage = trustedCert.getKeyUsage();
                        if (keyUsage != null) {
                            addError(createErrorBundle("CertPathReviewer.noCertSign"), size);
                        }
                    } else {
                        str = "CertPathReviewer.noBasicConstraints";
                    }
                    addError(createErrorBundle(str), size);
                    keyUsage = trustedCert.getKeyUsage();
                    if (keyUsage != null) {
                        addError(createErrorBundle("CertPathReviewer.noCertSign"), size);
                    }
                }
                subjectX500Principal = trustedCert.getSubjectX500Principal();
                nextWorkingKey = getNextWorkingKey(this.certs, size);
                AlgorithmIdentifier algorithmIdentifier3 = getAlgorithmIdentifier(nextWorkingKey);
                algorithmIdentifier3.getAlgorithm();
                algorithmIdentifier3.getParameters();
                size--;
            }
        } catch (CertPathReviewerException e15) {
            e = e15;
            trustAnchor = null;
        } catch (Throwable th2) {
            th = th2;
            trustAnchor = null;
        }
        trustAnchor2 = trustAnchor;
        if (trustAnchor2 != null) {
            trustedCert2 = trustAnchor2.getTrustedCert();
            if (trustedCert2 != null) {
                x500Principal2 = getSubjectPrincipal(trustedCert2);
            } else {
                x500Principal2 = new X500Principal(trustAnchor2.getCAName());
            }
            if (trustedCert2 != null) {
                addNotification(createErrorBundle("CertPathReviewer.trustKeyUsage"));
            }
            x500Principal = x500Principal2;
        } else {
            x500Principal = null;
        }
        if (trustAnchor2 != null) {
            trustedCert = trustAnchor2.getTrustedCert();
            if (trustedCert != null) {
                cAPublicKey = trustedCert.getPublicKey();
            } else {
                cAPublicKey = trustAnchor2.getCAPublicKey();
            }
            publicKey = cAPublicKey;
            AlgorithmIdentifier algorithmIdentifier4 = getAlgorithmIdentifier(publicKey);
            algorithmIdentifier4.getAlgorithm();
            algorithmIdentifier4.getParameters();
        } else {
            trustedCert = null;
            publicKey = null;
        }
        size = this.certs.size() - 1;
        subjectX500Principal = x500Principal;
        nextWorkingKey = publicKey;
    }

    private static ErrorBundle createErrorBundle(String str) {
        ErrorBundle errorBundle = new ErrorBundle(RESOURCE_NAME, str);
        errorBundle.setClassLoader(PKIXCertPathReviewer.class.getClassLoader());
        return errorBundle;
    }

    private static ErrorBundle createErrorBundle(String str, Object[] objArr) {
        ErrorBundle errorBundle = new ErrorBundle(RESOURCE_NAME, str, objArr);
        errorBundle.setClassLoader(PKIXCertPathReviewer.class.getClassLoader());
        return errorBundle;
    }

    private X509CRL getCRL(String str) throws CertPathReviewerException {
        try {
            URL url = new URL(str);
            if (!url.getProtocol().equals("http") && !url.getProtocol().equals("https")) {
                return null;
            }
            HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
            httpURLConnection.setUseCaches(false);
            httpURLConnection.setDoInput(true);
            httpURLConnection.connect();
            if (httpURLConnection.getResponseCode() == 200) {
                return (X509CRL) CertificateFactory.getInstance("X.509", BouncyCastleProvider.PROVIDER_NAME).generateCRL(httpURLConnection.getInputStream());
            }
            throw new Exception(httpURLConnection.getResponseMessage());
        } catch (Exception e) {
            throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.loadCrlDistPointError", new Object[]{new UntrustedInput(str), e.getMessage(), e, e.getClass().getName()}));
        }
    }

    private boolean processQcStatements(X509Certificate x509Certificate, int i) {
        ErrorBundle errorBundleCreateErrorBundle;
        String str;
        try {
            ASN1Sequence aSN1Sequence = (ASN1Sequence) getExtensionValue(x509Certificate, QC_STATEMENT);
            boolean z = false;
            for (int i2 = 0; i2 < aSN1Sequence.size(); i2++) {
                QCStatement qCStatement = QCStatement.getInstance(aSN1Sequence.getObjectAt(i2));
                if (QCStatement.id_etsi_qcs_QcCompliance.equals((ASN1Primitive) qCStatement.getStatementId())) {
                    str = "CertPathReviewer.QcEuCompliance";
                } else {
                    if (!QCStatement.id_qcs_pkixQCSyntax_v1.equals((ASN1Primitive) qCStatement.getStatementId())) {
                        if (QCStatement.id_etsi_qcs_QcSSCD.equals((ASN1Primitive) qCStatement.getStatementId())) {
                            str = "CertPathReviewer.QcSSCD";
                        } else if (QCStatement.id_etsi_qcs_LimiteValue.equals((ASN1Primitive) qCStatement.getStatementId())) {
                            MonetaryValue monetaryValue = MonetaryValue.getInstance(qCStatement.getStatementInfo());
                            monetaryValue.getCurrency();
                            double dDoubleValue = monetaryValue.getAmount().doubleValue() * Math.pow(10.0d, monetaryValue.getExponent().doubleValue());
                            errorBundleCreateErrorBundle = monetaryValue.getCurrency().isAlphabetic() ? createErrorBundle("CertPathReviewer.QcLimitValueAlpha", new Object[]{monetaryValue.getCurrency().getAlphabetic(), new TrustedInput(new Double(dDoubleValue)), monetaryValue}) : createErrorBundle("CertPathReviewer.QcLimitValueNum", new Object[]{Integers.valueOf(monetaryValue.getCurrency().getNumeric()), new TrustedInput(new Double(dDoubleValue)), monetaryValue});
                            addNotification(errorBundleCreateErrorBundle, i);
                        } else {
                            addNotification(createErrorBundle("CertPathReviewer.QcUnknownStatement", new Object[]{qCStatement.getStatementId(), new UntrustedInput(qCStatement)}), i);
                            z = true;
                        }
                    }
                }
                errorBundleCreateErrorBundle = createErrorBundle(str);
                addNotification(errorBundleCreateErrorBundle, i);
            }
            return !z;
        } catch (AnnotatedException e) {
            addError(createErrorBundle("CertPathReviewer.QcStatementExtError"), i);
            return false;
        }
    }

    protected void addError(ErrorBundle errorBundle) {
        this.errors[0].add(errorBundle);
    }

    protected void addError(ErrorBundle errorBundle, int i) {
        if (i < -1 || i >= this.n) {
            throw new IndexOutOfBoundsException();
        }
        this.errors[i + 1].add(errorBundle);
    }

    protected void addNotification(ErrorBundle errorBundle) {
        this.notifications[0].add(errorBundle);
    }

    protected void addNotification(ErrorBundle errorBundle, int i) {
        if (i < -1 || i >= this.n) {
            throw new IndexOutOfBoundsException();
        }
        this.notifications[i + 1].add(errorBundle);
    }

    /* JADX WARN: Code duplicated, block: B:86:0x0203  */
    protected void checkCRLs(PKIXParameters pKIXParameters, X509Certificate x509Certificate, Date date, X509Certificate x509Certificate2, PublicKey publicKey, Vector vector, int i) throws CertPathReviewerException {
        Iterator it;
        X509CRL x509crl;
        X509CRL x509crl2;
        boolean z;
        String str;
        String str2;
        boolean z2;
        ErrorBundle errorBundleCreateErrorBundle;
        String str3;
        boolean[] keyUsage;
        ErrorBundle errorBundleCreateErrorBundle2;
        String str4 = "CertPathReviewer.distrPtExtError";
        String str5 = "CertPathReviewer.crlExtractionError";
        X509CRLStoreSelector x509CRLStoreSelector = new X509CRLStoreSelector();
        try {
            x509CRLStoreSelector.addIssuerName(getEncodedIssuerPrincipal(x509Certificate).getEncoded());
            x509CRLStoreSelector.setCertificateChecking(x509Certificate);
            try {
                Set setFindCRLs = PKIXCRLUtil.findCRLs(x509CRLStoreSelector, pKIXParameters);
                it = setFindCRLs.iterator();
                if (setFindCRLs.isEmpty()) {
                    Iterator it2 = PKIXCRLUtil.findCRLs(new X509CRLStoreSelector(), pKIXParameters).iterator();
                    ArrayList arrayList = new ArrayList();
                    while (it2.hasNext()) {
                        arrayList.add(((X509CRL) it2.next()).getIssuerX500Principal());
                    }
                    addNotification(createErrorBundle("CertPathReviewer.noCrlInCertstore", new Object[]{new UntrustedInput(x509CRLStoreSelector.getIssuerNames()), new UntrustedInput(arrayList), Integers.valueOf(arrayList.size())}), i);
                }
                while (true) {
                    if (!it.hasNext()) {
                        x509crl2 = x509crl;
                        z = false;
                        break;
                    }
                    x509crl = (X509CRL) it.next();
                    Date thisUpdate = x509crl.getThisUpdate();
                    Date nextUpdate = x509crl.getNextUpdate();
                    Object[] objArr = {new TrustedInput(thisUpdate), new TrustedInput(nextUpdate)};
                    if (nextUpdate == null || date.before(nextUpdate)) {
                        addNotification(createErrorBundle("CertPathReviewer.localValidCRL", objArr), i);
                        x509crl2 = x509crl;
                        z = true;
                        break;
                    }
                    addNotification(createErrorBundle("CertPathReviewer.localInvalidCRL", objArr), i);
                }
            } catch (AnnotatedException e) {
                addError(createErrorBundle("CertPathReviewer.crlExtractionError", new Object[]{e.getCause().getMessage(), e.getCause(), e.getCause().getClass().getName()}), i);
                it = new ArrayList().iterator();
            }
            x509crl = null;
            if (!z) {
                X500Principal issuerX500Principal = x509Certificate.getIssuerX500Principal();
                Iterator it3 = vector.iterator();
                boolean z3 = z;
                while (true) {
                    if (!it3.hasNext()) {
                        str = str4;
                        str2 = str5;
                        z2 = z3;
                        break;
                    }
                    try {
                        String str6 = (String) it3.next();
                        X509CRL crl = getCRL(str6);
                        if (crl != null) {
                            X500Principal issuerX500Principal2 = crl.getIssuerX500Principal();
                            if (issuerX500Principal.equals(issuerX500Principal2)) {
                                str = str4;
                                str2 = str5;
                                Date thisUpdate2 = crl.getThisUpdate();
                                Date nextUpdate2 = crl.getNextUpdate();
                                Object[] objArr2 = {new TrustedInput(thisUpdate2), new TrustedInput(nextUpdate2), new UntrustedUrlInput(str6)};
                                if (nextUpdate2 != null && !date.before(nextUpdate2)) {
                                    errorBundleCreateErrorBundle2 = createErrorBundle("CertPathReviewer.onlineInvalidCRL", objArr2);
                                    addNotification(errorBundleCreateErrorBundle2, i);
                                }
                                try {
                                    addNotification(createErrorBundle("CertPathReviewer.onlineValidCRL", objArr2), i);
                                    x509crl2 = crl;
                                    z2 = true;
                                    break;
                                } catch (CertPathReviewerException e2) {
                                    e = e2;
                                    z3 = true;
                                    addNotification(e.getErrorMessage(), i);
                                    str4 = str;
                                    str5 = str2;
                                }
                            } else {
                                str = str4;
                                try {
                                    str2 = str5;
                                    try {
                                        errorBundleCreateErrorBundle2 = createErrorBundle("CertPathReviewer.onlineCRLWrongCA", new Object[]{new UntrustedInput(issuerX500Principal2.getName()), new UntrustedInput(issuerX500Principal.getName()), new UntrustedUrlInput(str6)});
                                        addNotification(errorBundleCreateErrorBundle2, i);
                                    } catch (CertPathReviewerException e3) {
                                        e = e3;
                                        addNotification(e.getErrorMessage(), i);
                                    }
                                } catch (CertPathReviewerException e4) {
                                    e = e4;
                                    str2 = str5;
                                    addNotification(e.getErrorMessage(), i);
                                    str4 = str;
                                    str5 = str2;
                                }
                            }
                        } else {
                            str = str4;
                            str2 = str5;
                        }
                    } catch (CertPathReviewerException e5) {
                        e = e5;
                        str = str4;
                    }
                    str4 = str;
                    str5 = str2;
                }
            } else {
                str = "CertPathReviewer.distrPtExtError";
                str2 = "CertPathReviewer.crlExtractionError";
                z2 = z;
            }
            if (x509crl2 != null) {
                if (x509Certificate2 != null && (keyUsage = x509Certificate2.getKeyUsage()) != null && (keyUsage.length <= 6 || !keyUsage[6])) {
                    throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.noCrlSigningPermited"));
                }
                if (publicKey == null) {
                    throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.crlNoIssuerPublicKey"));
                }
                try {
                    x509crl2.verify(publicKey, BouncyCastleProvider.PROVIDER_NAME);
                    X509CRLEntry revokedCertificate = x509crl2.getRevokedCertificate(x509Certificate.getSerialNumber());
                    if (revokedCertificate != null) {
                        if (revokedCertificate.hasExtensions()) {
                            try {
                                ASN1Enumerated aSN1Enumerated = ASN1Enumerated.getInstance(getExtensionValue(revokedCertificate, Extension.reasonCode.getId()));
                                if (aSN1Enumerated != null) {
                                    str3 = crlReasons[aSN1Enumerated.intValueExact()];
                                } else {
                                    str3 = null;
                                }
                            } catch (AnnotatedException e6) {
                                throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.crlReasonExtError"), e6);
                            }
                        } else {
                            str3 = null;
                        }
                        if (str3 == null) {
                            str3 = crlReasons[7];
                        }
                        LocaleString localeString = new LocaleString(RESOURCE_NAME, str3);
                        if (!date.before(revokedCertificate.getRevocationDate())) {
                            throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.certRevoked", new Object[]{new TrustedInput(revokedCertificate.getRevocationDate()), localeString}));
                        }
                        errorBundleCreateErrorBundle = createErrorBundle("CertPathReviewer.revokedAfterValidation", new Object[]{new TrustedInput(revokedCertificate.getRevocationDate()), localeString});
                    } else {
                        errorBundleCreateErrorBundle = createErrorBundle("CertPathReviewer.notRevoked");
                    }
                    addNotification(errorBundleCreateErrorBundle, i);
                    Date nextUpdate3 = x509crl2.getNextUpdate();
                    if (nextUpdate3 != null && !date.before(nextUpdate3)) {
                        addNotification(createErrorBundle("CertPathReviewer.crlUpdateAvailable", new Object[]{new TrustedInput(nextUpdate3)}), i);
                    }
                    try {
                        ASN1Primitive extensionValue = getExtensionValue(x509crl2, ISSUING_DISTRIBUTION_POINT);
                        try {
                            ASN1Primitive extensionValue2 = getExtensionValue(x509crl2, DELTA_CRL_INDICATOR);
                            if (extensionValue2 != null) {
                                X509CRLStoreSelector x509CRLStoreSelector2 = new X509CRLStoreSelector();
                                try {
                                    x509CRLStoreSelector2.addIssuerName(getIssuerPrincipal(x509crl2).getEncoded());
                                    x509CRLStoreSelector2.setMinCRLNumber(((ASN1Integer) extensionValue2).getPositiveValue());
                                    try {
                                        x509CRLStoreSelector2.setMaxCRLNumber(((ASN1Integer) getExtensionValue(x509crl2, CRL_NUMBER)).getPositiveValue().subtract(BigInteger.valueOf(1L)));
                                        try {
                                            Iterator it4 = PKIXCRLUtil.findCRLs(x509CRLStoreSelector2, pKIXParameters).iterator();
                                            do {
                                                if (!it4.hasNext()) {
                                                    throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.noBaseCRL"));
                                                }
                                                try {
                                                } catch (AnnotatedException e7) {
                                                    throw new CertPathReviewerException(createErrorBundle(str), e7);
                                                }
                                            } while (!Objects.areEqual(extensionValue, getExtensionValue((X509CRL) it4.next(), ISSUING_DISTRIBUTION_POINT)));
                                        } catch (AnnotatedException e8) {
                                            throw new CertPathReviewerException(createErrorBundle(str2), e8);
                                        }
                                    } catch (AnnotatedException e9) {
                                        throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.crlNbrExtError"), e9);
                                    }
                                } catch (IOException e10) {
                                    throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.crlIssuerException"), e10);
                                }
                            }
                            if (extensionValue != null) {
                                IssuingDistributionPoint issuingDistributionPoint = IssuingDistributionPoint.getInstance(extensionValue);
                                try {
                                    BasicConstraints basicConstraints = BasicConstraints.getInstance(getExtensionValue(x509Certificate, BASIC_CONSTRAINTS));
                                    if (issuingDistributionPoint.onlyContainsUserCerts() && basicConstraints != null && basicConstraints.isCA()) {
                                        throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.crlOnlyUserCert"));
                                    }
                                    if (issuingDistributionPoint.onlyContainsCACerts() && (basicConstraints == null || !basicConstraints.isCA())) {
                                        throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.crlOnlyCaCert"));
                                    }
                                    if (issuingDistributionPoint.onlyContainsAttributeCerts()) {
                                        throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.crlOnlyAttrCert"));
                                    }
                                } catch (AnnotatedException e11) {
                                    throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.crlBCExtError"), e11);
                                }
                            }
                        } catch (AnnotatedException e12) {
                            throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.deltaCrlExtError"));
                        }
                    } catch (AnnotatedException e13) {
                        throw new CertPathReviewerException(createErrorBundle(str));
                    }
                } catch (Exception e14) {
                    throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.crlVerifyFailed"), e14);
                }
            }
            if (!z2) {
                throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.noValidCrlFound"));
            }
        } catch (IOException e15) {
            throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.crlIssuerException"), e15);
        }
    }

    protected void checkRevocation(PKIXParameters pKIXParameters, X509Certificate x509Certificate, Date date, X509Certificate x509Certificate2, PublicKey publicKey, Vector vector, Vector vector2, int i) throws CertPathReviewerException {
        checkCRLs(pKIXParameters, x509Certificate, date, x509Certificate2, publicKey, vector, i);
    }

    protected void doChecks() {
        if (!this.initialized) {
            throw new IllegalStateException("Object not initialized. Call init() first.");
        }
        if (this.notifications == null) {
            this.notifications = new List[this.n + 1];
            this.errors = new List[this.n + 1];
            for (int i = 0; i < this.notifications.length; i++) {
                this.notifications[i] = new ArrayList();
                this.errors[i] = new ArrayList();
            }
            checkSignatures();
            checkNameConstraints();
            checkPathLength();
            checkPolicy();
            checkCriticalExtensions();
        }
    }

    protected Vector getCRLDistUrls(CRLDistPoint cRLDistPoint) {
        Vector vector = new Vector();
        if (cRLDistPoint != null) {
            for (DistributionPoint distributionPoint : cRLDistPoint.getDistributionPoints()) {
                DistributionPointName distributionPoint2 = distributionPoint.getDistributionPoint();
                if (distributionPoint2.getType() == 0) {
                    GeneralName[] names = GeneralNames.getInstance(distributionPoint2.getName()).getNames();
                    for (int i = 0; i < names.length; i++) {
                        if (names[i].getTagNo() == 6) {
                            vector.add(((ASN1IA5String) names[i].getName()).getString());
                        }
                    }
                }
            }
        }
        return vector;
    }

    public CertPath getCertPath() {
        return this.certPath;
    }

    public int getCertPathSize() {
        return this.n;
    }

    public List getErrors(int i) {
        doChecks();
        return this.errors[i + 1];
    }

    public List[] getErrors() {
        doChecks();
        return this.errors;
    }

    public List getNotifications(int i) {
        doChecks();
        return this.notifications[i + 1];
    }

    public List[] getNotifications() {
        doChecks();
        return this.notifications;
    }

    protected Vector getOCSPUrls(AuthorityInformationAccess authorityInformationAccess) {
        Vector vector = new Vector();
        if (authorityInformationAccess != null) {
            AccessDescription[] accessDescriptions = authorityInformationAccess.getAccessDescriptions();
            for (int i = 0; i < accessDescriptions.length; i++) {
                if (accessDescriptions[i].getAccessMethod().equals((ASN1Primitive) AccessDescription.id_ad_ocsp)) {
                    GeneralName accessLocation = accessDescriptions[i].getAccessLocation();
                    if (accessLocation.getTagNo() == 6) {
                        vector.add(((ASN1IA5String) accessLocation.getName()).getString());
                    }
                }
            }
        }
        return vector;
    }

    public PolicyNode getPolicyTree() {
        doChecks();
        return this.policyTree;
    }

    public PublicKey getSubjectPublicKey() {
        doChecks();
        return this.subjectPublicKey;
    }

    public TrustAnchor getTrustAnchor() {
        doChecks();
        return this.trustAnchor;
    }

    protected Collection getTrustAnchors(X509Certificate x509Certificate, Set set) throws CertPathReviewerException {
        ArrayList arrayList = new ArrayList();
        Iterator it = set.iterator();
        X509CertSelector x509CertSelector = new X509CertSelector();
        try {
            x509CertSelector.setSubject(getEncodedIssuerPrincipal(x509Certificate).getEncoded());
            byte[] extensionValue = x509Certificate.getExtensionValue(Extension.authorityKeyIdentifier.getId());
            if (extensionValue != null) {
                AuthorityKeyIdentifier authorityKeyIdentifier = AuthorityKeyIdentifier.getInstance(JcaX509ExtensionUtils.parseExtensionValue(extensionValue));
                if (authorityKeyIdentifier.getAuthorityCertSerialNumber() != null) {
                    x509CertSelector.setSerialNumber(authorityKeyIdentifier.getAuthorityCertSerialNumber());
                } else {
                    ASN1OctetString keyIdentifierObject = authorityKeyIdentifier.getKeyIdentifierObject();
                    if (keyIdentifierObject != null) {
                        x509CertSelector.setSubjectKeyIdentifier(keyIdentifierObject.getEncoded(ASN1Encoding.DER));
                    }
                }
            }
            while (it.hasNext()) {
                TrustAnchor trustAnchor = (TrustAnchor) it.next();
                if (trustAnchor.getTrustedCert() != null) {
                    if (x509CertSelector.match(trustAnchor.getTrustedCert())) {
                        arrayList.add(trustAnchor);
                    }
                } else if (trustAnchor.getCAName() != null && trustAnchor.getCAPublicKey() != null && getEncodedIssuerPrincipal(x509Certificate).equals(new X500Principal(trustAnchor.getCAName()))) {
                    arrayList.add(trustAnchor);
                }
            }
            return arrayList;
        } catch (IOException e) {
            throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.trustAnchorIssuerError"));
        }
    }

    public void init(CertPath certPath, PKIXParameters pKIXParameters) throws CertPathReviewerException {
        if (this.initialized) {
            throw new IllegalStateException("object is already initialized!");
        }
        this.initialized = true;
        if (certPath == null) {
            throw new NullPointerException("certPath was null");
        }
        List<? extends Certificate> certificates = certPath.getCertificates();
        if (certificates.size() != 1) {
            HashSet hashSet = new HashSet();
            Iterator<TrustAnchor> it = pKIXParameters.getTrustAnchors().iterator();
            while (it.hasNext()) {
                hashSet.add(it.next().getTrustedCert());
            }
            ArrayList arrayList = new ArrayList();
            for (int i = 0; i != certificates.size(); i++) {
                if (!hashSet.contains(certificates.get(i))) {
                    arrayList.add(certificates.get(i));
                }
            }
            try {
                this.certPath = CertificateFactory.getInstance("X.509", BouncyCastleProvider.PROVIDER_NAME).generateCertPath(arrayList);
                this.certs = arrayList;
            } catch (GeneralSecurityException e) {
                throw new IllegalStateException("unable to rebuild certpath");
            }
        } else {
            this.certPath = certPath;
            this.certs = certPath.getCertificates();
        }
        this.n = this.certs.size();
        if (this.certs.isEmpty()) {
            throw new CertPathReviewerException(createErrorBundle("CertPathReviewer.emptyCertPath"));
        }
        this.pkixParams = (PKIXParameters) pKIXParameters.clone();
        this.currentDate = new Date();
        this.validDate = getValidityDate(this.pkixParams, this.currentDate);
        this.notifications = null;
        this.errors = null;
        this.trustAnchor = null;
        this.subjectPublicKey = null;
        this.policyTree = null;
    }

    public boolean isValidCertPath() {
        doChecks();
        for (int i = 0; i < this.errors.length; i++) {
            if (!this.errors[i].isEmpty()) {
                return false;
            }
        }
        return true;
    }
}
