package o; import java.io.IOException; import java.io.InputStream; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509TrustManager; /* loaded from: classes2.dex */ public final class CyF implements X509TrustManager { private List c = new ArrayList(); @Override // javax.net.ssl.X509TrustManager public final void checkClientTrusted(X509Certificate[] x509CertificateArr, String str) throws CertificateException { Iterator it = this.c.iterator(); while (it.hasNext()) { try { it.next().checkServerTrusted(x509CertificateArr, str); return; } catch (CertificateException e) { e.getMessage(); } } throw new CertificateException("checkServerTrusted CertificateException"); } @Override // javax.net.ssl.X509TrustManager public final X509Certificate[] getAcceptedIssuers() { try { ArrayList arrayList = new ArrayList(); Iterator it = this.c.iterator(); while (it.hasNext()) { arrayList.addAll(Arrays.asList(it.next().getAcceptedIssuers())); } return (X509Certificate[]) arrayList.toArray(new X509Certificate[arrayList.size()]); } catch (Exception e) { e.getMessage(); return new X509Certificate[0]; } } @Override // javax.net.ssl.X509TrustManager public final void checkServerTrusted(X509Certificate[] x509CertificateArr, String str) throws CertificateException { int length = x509CertificateArr.length; for (X509Certificate x509Certificate : x509CertificateArr) { x509Certificate.getSubjectDN(); x509Certificate.getIssuerDN(); x509Certificate.getSerialNumber(); } int size = this.c.size(); for (int i = 0; i < size; i++) { try { X509TrustManager x509TrustManager = this.c.get(i); X509Certificate[] acceptedIssuers = x509TrustManager.getAcceptedIssuers(); if (acceptedIssuers != null) { int length2 = acceptedIssuers.length; for (X509Certificate x509Certificate2 : acceptedIssuers) { x509Certificate2.getIssuerDN(); } } x509TrustManager.checkServerTrusted(x509CertificateArr, str); x509CertificateArr[x509CertificateArr.length - 1].getIssuerDN(); return; } catch (CertificateException e) { e.getMessage(); if (i == size - 1) { if (x509CertificateArr != null && x509CertificateArr.length > 0) { x509CertificateArr[x509CertificateArr.length - 1].getIssuerDN(); } throw e; } } } } public CyF(InputStream inputStream, String str) throws IllegalArgumentException { try { if (inputStream != null) { try { TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("X509"); KeyStore keyStore = KeyStore.getInstance("bks"); keyStore.load(inputStream, str.toCharArray()); trustManagerFactory.init(keyStore); TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); for (TrustManager trustManager : trustManagers) { if (trustManager instanceof X509TrustManager) { this.c.add((X509TrustManager) trustManager); } } if (inputStream != null) { try { inputStream.close(); return; } catch (IOException unused) { return; } } return; } catch (IOException | NegativeArraySizeException | OutOfMemoryError | KeyStoreException | NoSuchAlgorithmException | CertificateException e) { e.getMessage(); if (inputStream != null) { try { inputStream.close(); return; } catch (IOException unused2) { return; } } return; } } throw new IllegalArgumentException("inputstream or trustPwd is null"); } catch (Throwable th) { if (inputStream != null) { try { inputStream.close(); } catch (IOException unused3) { } } throw th; } } }