package o; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.math.BigInteger; import java.net.InetAddress; import java.net.UnknownHostException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.Principal; import java.security.Provider; import java.security.PublicKey; import java.security.Signature; import java.security.SignatureException; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.CertificateExpiredException; import java.security.cert.CertificateNotYetValidException; import java.security.cert.CertificateParsingException; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.Enumeration; import java.util.HashSet; import java.util.List; import java.util.Set; import javax.security.auth.x500.X500Principal; import org.bouncycastle.asn1.ASN1Encoding; import org.spongycastle.asn1.ASN1Integer; /* loaded from: classes6.dex */ final class gqK extends X509Certificate implements gqT { private C15389gpD a; private gqT b = new gqB(); private gqQ c; private int d; private C15422gpy e; private boolean[] h; private boolean j; public gqK(gqQ gqq, C15389gpD c15389gpD) throws CertificateParsingException { this.c = gqq; this.a = c15389gpD; try { byte[] b = b("2.5.29.19"); if (b != null) { AbstractC15315gnE b2 = AbstractC15315gnE.b(b); this.e = b2 != null ? new C15422gpy(AbstractC15317gnH.a(b2)) : null; } try { byte[] b3 = b("2.5.29.15"); if (b3 == null) { this.h = null; return; } C15367gog c = C15367gog.c(AbstractC15315gnE.b(b3)); byte[] b4 = c.b(); int length = (b4.length << 3) - c.a(); this.h = new boolean[length >= 9 ? length : 9]; for (int i = 0; i != length; i++) { this.h[i] = (b4[i / 8] & (128 >>> (i % 8))) != 0; } } catch (Exception e) { throw new CertificateParsingException("cannot construct KeyUsage: ".concat(String.valueOf(e))); } } catch (Exception e2) { throw new CertificateParsingException("cannot construct BasicConstraints: ".concat(String.valueOf(e2))); } } @Override // java.security.cert.X509Certificate public final void checkValidity() throws CertificateExpiredException, CertificateNotYetValidException { checkValidity(new Date()); } @Override // java.security.cert.X509Certificate public final void checkValidity(Date date) throws CertificateExpiredException, CertificateNotYetValidException { String a; String a2; if (date.getTime() > getNotAfter().getTime()) { StringBuilder sb = new StringBuilder("certificate expired on "); AbstractC15315gnE abstractC15315gnE = this.a.e.b.e; if (abstractC15315gnE instanceof C15320gnN) { a = ((C15320gnN) abstractC15315gnE).a(); } else { a = ((C15349gny) abstractC15315gnE).a(); } sb.append(a); throw new CertificateExpiredException(sb.toString()); } if (date.getTime() >= getNotBefore().getTime()) { return; } StringBuilder sb2 = new StringBuilder("certificate not valid till "); AbstractC15315gnE abstractC15315gnE2 = this.a.e.h.e; if (abstractC15315gnE2 instanceof C15320gnN) { a2 = ((C15320gnN) abstractC15315gnE2).a(); } else { a2 = ((C15349gny) abstractC15315gnE2).a(); } sb2.append(a2); throw new CertificateNotYetValidException(sb2.toString()); } @Override // java.security.cert.X509Certificate public final int getVersion() { return new BigInteger(this.a.e.m.b).intValue() + 1; } @Override // java.security.cert.X509Certificate public final BigInteger getSerialNumber() { return new BigInteger(this.a.e.a.b); } @Override // java.security.cert.X509Certificate public final Principal getIssuerDN() { try { return new gqV(C15417gpt.c(this.a.e.c.l())); } catch (IOException unused) { return null; } } @Override // java.security.cert.X509Certificate public final X500Principal getIssuerX500Principal() { try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); new gnG(byteArrayOutputStream).d(this.a.e.c); return new X500Principal(byteArrayOutputStream.toByteArray()); } catch (IOException unused) { throw new IllegalStateException("can't encode issuer DN"); } } @Override // java.security.cert.X509Certificate public final Principal getSubjectDN() { return new gqV(C15417gpt.c(this.a.e.g.i())); } @Override // java.security.cert.X509Certificate public final X500Principal getSubjectX500Principal() { try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); new gnG(byteArrayOutputStream).d(this.a.e.g); return new X500Principal(byteArrayOutputStream.toByteArray()); } catch (IOException unused) { throw new IllegalStateException("can't encode issuer DN"); } } @Override // java.security.cert.X509Certificate public final Date getNotBefore() { return this.a.e.h.c(); } @Override // java.security.cert.X509Certificate public final Date getNotAfter() { return this.a.e.b.c(); } @Override // java.security.cert.X509Certificate public final List getExtendedKeyUsage() throws CertificateParsingException { byte[] b = b("2.5.29.37"); if (b == null) { return null; } try { AbstractC15317gnH abstractC15317gnH = (AbstractC15317gnH) new C15348gnx(b).b(); ArrayList arrayList = new ArrayList(); for (int i = 0; i != abstractC15317gnH.e(); i++) { arrayList.add(((C15314gnC) abstractC15317gnH.d(i)).d); } return Collections.unmodifiableList(arrayList); } catch (Exception unused) { throw new CertificateParsingException("error processing extended key usage extension"); } } @Override // java.security.cert.X509Certificate public final int getBasicConstraints() { C15422gpy c15422gpy = this.e; if (c15422gpy == null || !c15422gpy.a()) { return -1; } ASN1Integer aSN1Integer = this.e.e; if ((aSN1Integer != null ? new BigInteger(aSN1Integer.b) : null) == null) { return Integer.MAX_VALUE; } ASN1Integer aSN1Integer2 = this.e.e; return (aSN1Integer2 != null ? new BigInteger(aSN1Integer2.b) : null).intValue(); } @Override // java.security.cert.X509Certificate public final Collection getSubjectAlternativeNames() throws CertificateParsingException { return a(b(C15394gpK.s.d)); } @Override // java.security.cert.X509Certificate public final Collection getIssuerAlternativeNames() throws CertificateParsingException { return a(b(C15394gpK.k.d)); } @Override // java.security.cert.X509Extension public final Set getCriticalExtensionOIDs() { if (getVersion() != 3) { return null; } HashSet hashSet = new HashSet(); C15391gpH c15391gpH = this.a.e.e; if (c15391gpH == null) { return null; } Enumeration elements = c15391gpH.a.elements(); while (elements.hasMoreElements()) { C15314gnC c15314gnC = (C15314gnC) elements.nextElement(); if (((C15394gpK) c15391gpH.d.get(c15314gnC)).p) { hashSet.add(c15314gnC.d); } } return hashSet; } @Override // java.security.cert.X509Extension public final Set getNonCriticalExtensionOIDs() { if (getVersion() != 3) { return null; } HashSet hashSet = new HashSet(); C15391gpH c15391gpH = this.a.e.e; if (c15391gpH == null) { return null; } Enumeration elements = c15391gpH.a.elements(); while (elements.hasMoreElements()) { C15314gnC c15314gnC = (C15314gnC) elements.nextElement(); if (!((C15394gpK) c15391gpH.d.get(c15314gnC)).p) { hashSet.add(c15314gnC.d); } } return hashSet; } @Override // java.security.cert.X509Extension public final boolean hasUnsupportedCriticalExtension() { C15391gpH c15391gpH; if (getVersion() != 3 || (c15391gpH = this.a.e.e) == null) { return false; } Enumeration elements = c15391gpH.a.elements(); while (elements.hasMoreElements()) { C15314gnC c15314gnC = (C15314gnC) elements.nextElement(); if (!c15314gnC.equals(C15394gpK.n) && !c15314gnC.equals(C15394gpK.i) && !c15314gnC.equals(C15394gpK.q) && !c15314gnC.equals(C15394gpK.f) && !c15314gnC.equals(C15394gpK.c) && !c15314gnC.equals(C15394gpK.f9146o) && !c15314gnC.equals(C15394gpK.h) && !c15314gnC.equals(C15394gpK.m) && !c15314gnC.equals(C15394gpK.b) && !c15314gnC.equals(C15394gpK.s) && !c15314gnC.equals(C15394gpK.l) && ((C15394gpK) c15391gpH.d.get(c15314gnC)).p) { return true; } } return false; } @Override // java.security.cert.Certificate public final PublicKey getPublicKey() { try { return gqX.b(this.a.e.i); } catch (IOException unused) { return null; } } @Override // java.security.cert.Certificate public final byte[] getEncoded() throws CertificateEncodingException { try { return this.a.c(ASN1Encoding.DER); } catch (IOException e) { throw new CertificateEncodingException(e.toString()); } } @Override // java.security.cert.Certificate public final boolean equals(Object obj) { if (obj == this) { return true; } if (obj instanceof gqK) { gqK gqk = (gqK) obj; if (this.j && gqk.j && this.d != gqk.d) { return false; } return this.a.equals(gqk.a); } return super.equals(obj); } @Override // java.security.cert.Certificate public final int hashCode() { int i; synchronized (this) { if (!this.j) { this.d = super.hashCode(); this.j = true; } i = this.d; } return i; } @Override // java.security.cert.Certificate public final String toString() { StringBuffer stringBuffer = new StringBuffer(" [0] Version: "); String b = grR.b(); stringBuffer.append(getVersion()).append(b); stringBuffer.append(" SerialNumber: ").append(getSerialNumber()).append(b); stringBuffer.append(" IssuerDN: ").append(getIssuerDN()).append(b); stringBuffer.append(" Start Date: ").append(getNotBefore()).append(b); stringBuffer.append(" Final Date: ").append(getNotAfter()).append(b); stringBuffer.append(" SubjectDN: ").append(getSubjectDN()).append(b); stringBuffer.append(" Public Key: ").append(getPublicKey()).append(b); stringBuffer.append(" Signature Algorithm: ").append(getSigAlgName()).append(b); byte[] signature = getSignature(); stringBuffer.append(" Signature: ").append(new String(grS.e(signature, 0, 20))).append(b); for (int i = 20; i < signature.length; i += 20) { if (i < signature.length - 20) { stringBuffer.append(" ").append(new String(grS.e(signature, i, 20))).append(b); } else { stringBuffer.append(" ").append(new String(grS.e(signature, i, signature.length - i))).append(b); } } C15391gpH c15391gpH = this.a.e.e; if (c15391gpH != null) { Enumeration elements = c15391gpH.a.elements(); if (elements.hasMoreElements()) { stringBuffer.append(" Extensions: \n"); } while (elements.hasMoreElements()) { C15314gnC c15314gnC = (C15314gnC) elements.nextElement(); C15394gpK c15394gpK = (C15394gpK) c15391gpH.d.get(c15314gnC); if (c15394gpK.v != null) { C15348gnx c15348gnx = new C15348gnx(c15394gpK.v.b()); stringBuffer.append(" critical(").append(c15394gpK.p).append(") "); try { if (c15314gnC.equals(C15394gpK.b)) { AbstractC15315gnE b2 = c15348gnx.b(); stringBuffer.append(b2 != null ? new C15422gpy(AbstractC15317gnH.a(b2)) : null).append(b); } else if (c15314gnC.equals(C15394gpK.n)) { AbstractC15315gnE b3 = c15348gnx.b(); stringBuffer.append(b3 != null ? new gpW(C15367gog.c(b3)) : null).append(b); } else if (c15314gnC.equals(InterfaceC15399gpb.b)) { stringBuffer.append(new C15401gpd((C15367gog) c15348gnx.b())).append(b); } else if (c15314gnC.equals(InterfaceC15399gpb.e)) { stringBuffer.append(new goZ((C15376gop) c15348gnx.b())).append(b); } else if (c15314gnC.equals(InterfaceC15399gpb.d)) { stringBuffer.append(new C15400gpc((C15376gop) c15348gnx.b())).append(b); } else { stringBuffer.append(c15314gnC.d); stringBuffer.append(" value = ").append(C15408gpk.d(c15348gnx.b())).append(b); } } catch (Exception unused) { stringBuffer.append(c15314gnC.d); stringBuffer.append(" value = *****").append(b); } } else { stringBuffer.append(b); } } } return stringBuffer.toString(); } /* JADX WARN: Failed to find 'out' block for switch in B:10:0x002f. Please report as an issue. */ private static Collection a(byte[] bArr) throws CertificateParsingException { if (bArr == null) { return null; } try { ArrayList arrayList = new ArrayList(); Enumeration b = AbstractC15317gnH.a(bArr).b(); while (b.hasMoreElements()) { gpO a = gpO.a(b.nextElement()); ArrayList arrayList2 = new ArrayList(); arrayList2.add(Integer.valueOf(a.e)); switch (a.e) { case 0: case 3: case 5: arrayList2.add(a.l()); arrayList.add(Collections.unmodifiableList(arrayList2)); case 1: case 2: case 6: arrayList2.add(((InterfaceC15322gnQ) a.d).j()); arrayList.add(Collections.unmodifiableList(arrayList2)); case 4: arrayList2.add(C15417gpt.c(C15420gpw.d, a.d).toString()); arrayList.add(Collections.unmodifiableList(arrayList2)); case 7: try { arrayList2.add(InetAddress.getByAddress(C15382gov.b(a.d).b()).getHostAddress()); arrayList.add(Collections.unmodifiableList(arrayList2)); } catch (UnknownHostException unused) { } case 8: arrayList2.add(C15314gnC.d(a.d).d); arrayList.add(Collections.unmodifiableList(arrayList2)); default: StringBuilder sb = new StringBuilder(); sb.append("Bad tag number: "); sb.append(a.e); throw new IOException(sb.toString()); } } if (arrayList.size() == 0) { return null; } return Collections.unmodifiableCollection(arrayList); } catch (Exception e) { throw new CertificateParsingException(e.getMessage()); } } private void e(PublicKey publicKey, Signature signature) throws CertificateException, NoSuchAlgorithmException, SignatureException, InvalidKeyException { C15423gpz c15423gpz = this.a.a; C15423gpz c15423gpz2 = this.a.e.f; if (!c15423gpz.e.equals(c15423gpz2.e) || (c15423gpz.a != null ? c15423gpz2.a != null ? !c15423gpz.a.equals(c15423gpz2.a) : c15423gpz.a != null && !c15423gpz.a.equals(C15380got.a) : c15423gpz2.a != null && !c15423gpz2.a.equals(C15380got.a))) { throw new CertificateException("signature algorithm in TBS cert not same as outer cert"); } C15430gqM.d(signature, this.a.a.a); signature.initVerify(publicKey); signature.update(getTBSCertificate()); if (!signature.verify(getSignature())) { throw new SignatureException("certificate does not verify with supplied key"); } } private byte[] b(String str) { C15391gpH c15391gpH = this.a.e.e; if (c15391gpH == null) { return null; } C15394gpK c15394gpK = (C15394gpK) c15391gpH.d.get(new C15314gnC(str)); if (c15394gpK != null) { return c15394gpK.v.b(); } return null; } @Override // java.security.cert.X509Extension public final byte[] getExtensionValue(String str) { C15391gpH c15391gpH = this.a.e.e; if (c15391gpH == null) { return null; } C15394gpK c15394gpK = (C15394gpK) c15391gpH.d.get(new C15314gnC(str)); if (c15394gpK == null) { return null; } try { return c15394gpK.v.l(); } catch (Exception e) { StringBuilder sb = new StringBuilder("error parsing "); sb.append(e.toString()); throw new IllegalStateException(sb.toString()); } } @Override // java.security.cert.X509Certificate public final boolean[] getIssuerUniqueID() { C15367gog c15367gog = this.a.e.d; if (c15367gog == null) { return null; } byte[] b = c15367gog.b(); int length = (b.length << 3) - c15367gog.a(); boolean[] zArr = new boolean[length]; for (int i = 0; i != length; i++) { zArr[i] = (b[i / 8] & (128 >>> (i % 8))) != 0; } return zArr; } @Override // java.security.cert.X509Certificate public final String getSigAlgName() { return C15430gqM.d(this.a.a); } @Override // java.security.cert.X509Certificate public final String getSigAlgOID() { return this.a.a.e.d; } @Override // java.security.cert.X509Certificate public final byte[] getSigAlgParams() { if (this.a.a.a == null) { return null; } try { return this.a.a.a.i().c(ASN1Encoding.DER); } catch (IOException unused) { return null; } } @Override // java.security.cert.X509Certificate public final byte[] getSignature() { return this.a.d.e(); } @Override // java.security.cert.X509Certificate public final boolean[] getSubjectUniqueID() { C15367gog c15367gog = this.a.e.j; if (c15367gog == null) { return null; } byte[] b = c15367gog.b(); int length = (b.length << 3) - c15367gog.a(); boolean[] zArr = new boolean[length]; for (int i = 0; i != length; i++) { zArr[i] = (b[i / 8] & (128 >>> (i % 8))) != 0; } return zArr; } @Override // java.security.cert.X509Certificate public final byte[] getTBSCertificate() throws CertificateEncodingException { try { return this.a.e.c(ASN1Encoding.DER); } catch (IOException e) { throw new CertificateEncodingException(e.toString()); } } @Override // java.security.cert.Certificate public final void verify(PublicKey publicKey) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException { Signature signature; String d = C15430gqM.d(this.a.a); try { signature = this.c.e(d); } catch (Exception unused) { signature = Signature.getInstance(d); } e(publicKey, signature); } @Override // java.security.cert.Certificate public final void verify(PublicKey publicKey, String str) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException { Signature signature; String d = C15430gqM.d(this.a.a); if (str != null) { signature = Signature.getInstance(d, str); } else { signature = Signature.getInstance(d); } e(publicKey, signature); } @Override // java.security.cert.X509Certificate, java.security.cert.Certificate public final void verify(PublicKey publicKey, Provider provider) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, SignatureException { Signature signature; String d = C15430gqM.d(this.a.a); if (provider != null) { signature = Signature.getInstance(d, provider); } else { signature = Signature.getInstance(d); } e(publicKey, signature); } @Override // java.security.cert.X509Certificate public final boolean[] getKeyUsage() { return this.h; } }