package o; import java.security.InvalidAlgorithmParameterException; import java.security.PublicKey; import java.security.cert.CertPath; import java.security.cert.CertPathParameters; import java.security.cert.CertPathValidatorException; import java.security.cert.CertPathValidatorResult; import java.security.cert.CertPathValidatorSpi; import java.security.cert.Certificate; import java.security.cert.PKIXCertPathChecker; import java.security.cert.PKIXCertPathValidatorResult; import java.security.cert.PKIXParameters; import java.security.cert.TrustAnchor; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import o.C15457gqz; import org.bouncycastle.jce.provider.RFC3280CertPathUtilities; import org.spongycastle.jce.exception.ExtCertPathValidatorException; import org.spongycastle.jce.provider.AnnotatedException; /* renamed from: o.grk, reason: case insensitive filesystem */ /* loaded from: classes6.dex */ public class C15483grk extends CertPathValidatorSpi { private final gqQ e = new gqR(); @Override // java.security.cert.CertPathValidatorSpi public CertPathValidatorResult engineValidate(CertPath certPath, CertPathParameters certPathParameters) throws CertPathValidatorException, InvalidAlgorithmParameterException { C15457gqz c15457gqz; C15417gpt c; PublicKey cAPublicKey; HashSet hashSet; int i; List list; ArrayList[] arrayListArr; HashSet hashSet2; int i2; C15483grk c15483grk = this; if (certPathParameters instanceof PKIXParameters) { C15457gqz.LWm lWm = new C15457gqz.LWm((PKIXParameters) certPathParameters); if (certPathParameters instanceof C15472grZ) { C15472grZ c15472grZ = (C15472grZ) certPathParameters; lWm.i = c15472grZ.i; lWm.f9150o = c15472grZ.g; } c15457gqz = new C15457gqz(lWm, (byte) 0); } else if (!(certPathParameters instanceof gqA)) { if (certPathParameters instanceof C15457gqz) { c15457gqz = (C15457gqz) certPathParameters; } else { StringBuilder sb = new StringBuilder("Parameters must be a "); sb.append(PKIXParameters.class.getName()); sb.append(" instance."); throw new InvalidAlgorithmParameterException(sb.toString()); } } else { c15457gqz = ((gqA) certPathParameters).e; } if (c15457gqz.i == null) { throw new InvalidAlgorithmParameterException("trustAnchors is null, this is not allowed for certification path validation."); } List certificates = certPath.getCertificates(); int size = certificates.size(); if (certificates.isEmpty()) { throw new CertPathValidatorException("Certification path is empty.", null, certPath, -1); } Set initialPolicies = c15457gqz.b.getInitialPolicies(); try { TrustAnchor e = C15473gra.e((X509Certificate) certificates.get(certificates.size() - 1), c15457gqz.i, c15457gqz.b.getSigProvider()); if (e == null) { throw new CertPathValidatorException("Trust anchor for certification path not found.", null, certPath, -1); } C15457gqz.LWm lWm2 = new C15457gqz.LWm(c15457gqz); lWm2.g = Collections.singleton(e); C15457gqz c15457gqz2 = new C15457gqz(lWm2, (byte) 0); int i3 = size + 1; ArrayList[] arrayListArr2 = new ArrayList[i3]; for (int i4 = 0; i4 < i3; i4++) { arrayListArr2[i4] = new ArrayList(); } HashSet hashSet3 = new HashSet(); hashSet3.add(RFC3280CertPathUtilities.ANY_POLICY); C15485grm c15485grm = new C15485grm(new ArrayList(), 0, hashSet3, null, new HashSet(), RFC3280CertPathUtilities.ANY_POLICY, false); arrayListArr2[0].add(c15485grm); C15486grn c15486grn = new C15486grn(); HashSet hashSet4 = new HashSet(); int i5 = c15457gqz2.b.isExplicitPolicyRequired() ? 0 : i3; int i6 = c15457gqz2.b.isAnyPolicyInhibited() ? 0 : i3; if (c15457gqz2.b.isPolicyMappingInhibited()) { i3 = 0; } X509Certificate trustedCert = e.getTrustedCert(); try { if (trustedCert != null) { c = C15417gpt.c(trustedCert.getSubjectX500Principal().getEncoded()); cAPublicKey = trustedCert.getPublicKey(); } else { c = C15417gpt.c(e.getCA().getEncoded()); cAPublicKey = e.getCAPublicKey(); } try { C15423gpz b = C15473gra.b(cAPublicKey); C15314gnC c15314gnC = b.e; InterfaceC15342gnr interfaceC15342gnr = b.a; if (c15457gqz2.g != null) { if (!c15457gqz2.g.b.match((X509Certificate) certificates.get(0))) { throw new ExtCertPathValidatorException("Target certificate in certification path does not match targetConstraints.", null, certPath, 0); } } List certPathCheckers = c15457gqz2.b.getCertPathCheckers(); Iterator it = certPathCheckers.iterator(); while (it.hasNext()) { it.next().init(false); i3 = i3; } int i7 = i3; X509Certificate x509Certificate = trustedCert; int i8 = i6; int i9 = size; PublicKey publicKey = cAPublicKey; int size2 = certificates.size() - 1; C15417gpt c15417gpt = c; X509Certificate x509Certificate2 = null; C15485grm c15485grm2 = c15485grm; int i10 = i7; while (size2 >= 0) { X509Certificate x509Certificate3 = (X509Certificate) certificates.get(size2); boolean z = size2 == certificates.size() + (-1); gqQ gqq = c15483grk.e; int i11 = i8; List list2 = certificates; int i12 = i5; Set set = initialPolicies; int i13 = i10; C15457gqz c15457gqz3 = c15457gqz2; C15486grn c15486grn2 = c15486grn; boolean z2 = z; ArrayList[] arrayListArr3 = arrayListArr2; TrustAnchor trustAnchor = e; int i14 = size2; List list3 = certPathCheckers; C15492grt.c(certPath, c15457gqz2, size2, publicKey, z2, c15417gpt, x509Certificate, gqq); C15492grt.a(certPath, i14, c15486grn2); C15485grm e2 = C15492grt.e(certPath, i14, C15492grt.d(certPath, i14, hashSet4, c15485grm2, arrayListArr3, i11)); C15492grt.a(certPath, i14, e2, i12); if (size - i14 == size) { i = i14; list = list3; arrayListArr = arrayListArr3; c15483grk = this; c15485grm2 = e2; i8 = i11; i5 = i12; i10 = i13; } else { if (x509Certificate3 != null && x509Certificate3.getVersion() == 1) { throw new CertPathValidatorException("Version 1 certificates can't be used as CA ones.", null, certPath, i14); } C15492grt.e(certPath, i14); arrayListArr = arrayListArr3; C15485grm b2 = C15492grt.b(certPath, i14, arrayListArr, e2, i13); C15492grt.c(certPath, i14, c15486grn2); int e3 = C15492grt.e(certPath, i14, i12); int d = C15492grt.d(certPath, i14, i13); int b3 = C15492grt.b(certPath, i14, i11); int a = C15492grt.a(certPath, i14, e3); int c2 = C15492grt.c(certPath, i14, d); int g = C15492grt.g(certPath, i14, b3); C15492grt.b(certPath, i14); i9 = C15492grt.i(certPath, i14, C15492grt.h(certPath, i14, i9)); C15492grt.d(certPath, i14); Set criticalExtensionOIDs = x509Certificate3.getCriticalExtensionOIDs(); if (criticalExtensionOIDs != null) { hashSet2 = new HashSet(criticalExtensionOIDs); hashSet2.remove(C15492grt.h); hashSet2.remove(C15492grt.d); hashSet2.remove(C15492grt.i); hashSet2.remove(C15492grt.a); hashSet2.remove(C15492grt.j); hashSet2.remove(C15492grt.e); hashSet2.remove(C15492grt.g); hashSet2.remove(C15492grt.c); hashSet2.remove(C15492grt.l); hashSet2.remove(C15492grt.f); } else { hashSet2 = new HashSet(); } list = list3; C15492grt.d(certPath, i14, hashSet2, list); C15417gpt c3 = C15417gpt.c(x509Certificate3.getSubjectX500Principal().getEncoded()); try { i2 = i14; c15483grk = this; try { PublicKey c4 = C15473gra.c(certPath.getCertificates(), i2, c15483grk.e); C15423gpz b4 = C15473gra.b(c4); C15314gnC c15314gnC2 = b4.e; InterfaceC15342gnr interfaceC15342gnr2 = b4.a; c15485grm2 = b2; c15417gpt = c3; publicKey = c4; i = i2; x509Certificate = x509Certificate3; i5 = a; i8 = g; i10 = c2; } catch (CertPathValidatorException e4) { e = e4; throw new CertPathValidatorException("Next working key could not be retrieved.", e, certPath, i2); } } catch (CertPathValidatorException e5) { e = e5; i2 = i14; } } size2 = i - 1; certPathCheckers = list; x509Certificate2 = x509Certificate3; certificates = list2; initialPolicies = set; e = trustAnchor; arrayListArr2 = arrayListArr; c15486grn = c15486grn2; c15457gqz2 = c15457gqz3; } C15457gqz c15457gqz4 = c15457gqz2; ArrayList[] arrayListArr4 = arrayListArr2; TrustAnchor trustAnchor2 = e; List list4 = certPathCheckers; Set set2 = initialPolicies; int i15 = size2; int i16 = i15 + 1; int j = C15492grt.j(certPath, i16, C15492grt.a(i5, x509Certificate2)); Set criticalExtensionOIDs2 = x509Certificate2.getCriticalExtensionOIDs(); if (criticalExtensionOIDs2 != null) { hashSet = new HashSet(criticalExtensionOIDs2); hashSet.remove(C15492grt.h); hashSet.remove(C15492grt.d); hashSet.remove(C15492grt.i); hashSet.remove(C15492grt.a); hashSet.remove(C15492grt.j); hashSet.remove(C15492grt.e); hashSet.remove(C15492grt.g); hashSet.remove(C15492grt.c); hashSet.remove(C15492grt.l); hashSet.remove(C15492grt.f); hashSet.remove(C15492grt.b); hashSet.remove(C15394gpK.g.d); } else { hashSet = new HashSet(); } C15492grt.e(certPath, i16, list4, hashSet); X509Certificate x509Certificate4 = x509Certificate2; C15485grm b5 = C15492grt.b(certPath, c15457gqz4, set2, i16, arrayListArr4, c15485grm2, hashSet4); if (j > 0 || b5 != null) { return new PKIXCertPathValidatorResult(trustAnchor2, b5, x509Certificate4.getPublicKey()); } throw new CertPathValidatorException("Path processing failed on policy.", null, certPath, i15); } catch (CertPathValidatorException e6) { throw new ExtCertPathValidatorException("Algorithm identifier of public key of trust anchor could not be read.", e6, certPath, -1); } } catch (IllegalArgumentException e7) { throw new ExtCertPathValidatorException("Subject of trust anchor could not be (re)encoded.", e7, certPath, -1); } } catch (AnnotatedException e8) { throw new CertPathValidatorException(e8.getMessage(), e8, certPath, certificates.size() - 1); } } }