package com.mobile.auth.y; import android.net.Network; import android.os.Build; import android.text.TextUtils; import com.alibaba.fastjson.support.spring.FastJsonJsonView; import com.baidu.mobads.sdk.internal.ae; import com.baidu.speech.utils.AsrError; import com.bytedance.sdk.openadsdk.api.plugin.PluginConstants; import com.czhj.sdk.common.Constants; import com.kwai.video.player.PlayerProps; import com.mobile.auth.gatewayauth.ExceptionProcessor; import com.mobile.auth.z.e; import com.mobile.auth.z.f; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.security.SecureRandom; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.HashMap; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import org.json.JSONObject; public class b { /* access modifiers changed from: package-private */ public class a implements X509TrustManager { public a() { } @Override // javax.net.ssl.X509TrustManager public void checkClientTrusted(X509Certificate[] x509CertificateArr, String str) throws CertificateException { } /* JADX WARNING: Code restructure failed: missing block: B:11:?, code lost: com.mobile.auth.gatewayauth.ExceptionProcessor.processException(r3); */ /* JADX WARNING: Code restructure failed: missing block: B:12:0x001a, code lost: return; */ /* JADX WARNING: Code restructure failed: missing block: B:13:0x001b, code lost: r3 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:14:0x001c, code lost: com.mobile.auth.gatewayauth.ExceptionProcessor.processException(r3); */ /* JADX WARNING: Code restructure failed: missing block: B:15:0x001f, code lost: return; */ /* JADX WARNING: Code restructure failed: missing block: B:6:0x000d, code lost: r3 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:9:0x0016, code lost: throw new java.security.cert.CertificateException("bad certificate"); */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:7:0x000f */ @Override // javax.net.ssl.X509TrustManager public void checkServerTrusted(X509Certificate[] x509CertificateArr, String str) throws CertificateException { for (X509Certificate x509Certificate : x509CertificateArr) { x509Certificate.checkValidity(); } } public X509Certificate[] getAcceptedIssuers() { try { return new X509Certificate[0]; } catch (Throwable th) { ExceptionProcessor.processException(th); return null; } } } /* JADX WARNING: Code restructure failed: missing block: B:32:0x0040, code lost: r7 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:37:?, code lost: com.mobile.auth.gatewayauth.ExceptionProcessor.processException(r7); */ /* JADX WARNING: Code restructure failed: missing block: B:38:0x004b, code lost: return null; */ /* JADX WARNING: Code restructure failed: missing block: B:39:0x004c, code lost: r7 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:40:0x004d, code lost: com.mobile.auth.gatewayauth.ExceptionProcessor.processException(r7); */ /* JADX WARNING: Exception block dominator not found, dom blocks: [B:10:0x001f, B:30:0x003c, B:36:0x0048] */ /* JADX WARNING: Removed duplicated region for block: B:20:0x0030 A[SYNTHETIC, Splitter:B:20:0x0030] */ /* JADX WARNING: Removed duplicated region for block: B:23:0x0035 A[Catch:{ Exception -> 0x0038 }] */ /* JADX WARNING: Removed duplicated region for block: B:30:0x003c A[SYNTHETIC, Splitter:B:30:0x003c] */ /* JADX WARNING: Removed duplicated region for block: B:32:0x0040 A[Catch:{ Exception -> 0x0050, all -> 0x0040, all -> 0x004c }, ExcHandler: all (r7v1 'th' java.lang.Throwable A[CUSTOM_DECLARE, Catch:{ Exception -> 0x0050, all -> 0x0040, all -> 0x004c }]), Splitter:B:10:0x001f] */ /* JADX WARNING: Removed duplicated region for block: B:35:0x0044 A[Catch:{ Exception -> 0x0050, all -> 0x0040, all -> 0x004c }] */ private String a(InputStream inputStream) { ByteArrayOutputStream byteArrayOutputStream; Throwable th; try { byteArrayOutputStream = new ByteArrayOutputStream(); try { byte[] bArr = new byte[1024]; while (true) { int read = inputStream.read(bArr); if (read == -1) { break; } byteArrayOutputStream.write(bArr, 0, read); } String str = new String(byteArrayOutputStream.toByteArray()); try { byteArrayOutputStream.close(); if (inputStream != null) { inputStream.close(); } } catch (Exception unused) { } catch (Throwable th2) { } return str; } catch (Exception unused2) { if (byteArrayOutputStream != null) { byteArrayOutputStream.close(); } if (inputStream != null) { inputStream.close(); } return null; } catch (Throwable th3) { th = th3; if (byteArrayOutputStream != null) { try { byteArrayOutputStream.close(); } catch (Exception unused3) { throw th; } } if (inputStream != null) { inputStream.close(); } throw th; } } catch (Exception unused4) { byteArrayOutputStream = null; if (byteArrayOutputStream != null) { } if (inputStream != null) { } return null; } catch (Throwable th4) { byteArrayOutputStream = null; th = th4; if (byteArrayOutputStream != null) { } if (inputStream != null) { } throw th; } } /* JADX WARNING: Removed duplicated region for block: B:21:0x009b */ /* JADX WARNING: Removed duplicated region for block: B:33:0x00ae */ public String a(String str, String str2) { Throwable th; Exception e; HttpsURLConnection httpsURLConnection; String str3 = ""; HttpsURLConnection httpsURLConnection2 = null; try { SSLContext instance = SSLContext.getInstance("TLS"); instance.init(null, new TrustManager[]{new a()}, new SecureRandom()); httpsURLConnection = (HttpsURLConnection) new URL(str).openConnection(); try { httpsURLConnection.setDoInput(true); httpsURLConnection.setDoOutput(true); httpsURLConnection.setUseCaches(false); httpsURLConnection.setInstanceFollowRedirects(true); httpsURLConnection.setReadTimeout(PlayerProps.FFP_PROP_FLOAT_MAX_AVDIFF_REALTIME); httpsURLConnection.setConnectTimeout(PlayerProps.FFP_PROP_FLOAT_MAX_AVDIFF_REALTIME); httpsURLConnection.setRequestMethod(ae.b); httpsURLConnection.setSSLSocketFactory(instance.getSocketFactory()); httpsURLConnection.setHostnameVerifier(new HostnameVerifier() { /* class com.mobile.auth.y.b.AnonymousClass2 */ public boolean verify(String str, SSLSession sSLSession) { try { HostnameVerifier defaultHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier(); return defaultHostnameVerifier.verify("wostore.cn", sSLSession) || defaultHostnameVerifier.verify("10010.com", sSLSession); } catch (Throwable th) { ExceptionProcessor.processException(th); return false; } } }); httpsURLConnection.addRequestProperty("Connection", "close"); httpsURLConnection.addRequestProperty("Content-Type", FastJsonJsonView.DEFAULT_CONTENT_TYPE); httpsURLConnection.connect(); DataOutputStream dataOutputStream = new DataOutputStream(httpsURLConnection.getOutputStream()); if (str2 != null) { dataOutputStream.write(str2.getBytes("UTF-8")); } dataOutputStream.flush(); dataOutputStream.close(); if (httpsURLConnection.getResponseCode() == 200) { str3 = a(httpsURLConnection.getInputStream()); } if (httpsURLConnection != null) { try { httpsURLConnection.disconnect(); } catch (Throwable th2) { ExceptionProcessor.processException(th2); return null; } } return str3; } catch (Exception e2) { e = e2; try { e.printStackTrace(); if (httpsURLConnection != null) { httpsURLConnection.disconnect(); } return str3; } catch (Throwable th3) { th = th3; httpsURLConnection2 = httpsURLConnection; if (httpsURLConnection2 != null) { httpsURLConnection2.disconnect(); } throw th; } } } catch (Exception e3) { e = e3; httpsURLConnection = null; e.printStackTrace(); if (httpsURLConnection != null) { } return str3; } catch (Throwable th4) { th = th4; if (httpsURLConnection2 != null) { } throw th; } } public String a(String str, HashMap<String, String> hashMap, Network network) { String str2 = ""; try { e.a("url:".concat(String.valueOf(str))); try { URL url = new URL(str); str2 = "https://" + url.getHost(); } catch (MalformedURLException e) { e.printStackTrace(); } f.c(str); try { SSLContext instance = SSLContext.getInstance("TLS"); instance.init(null, new TrustManager[]{new a()}, new SecureRandom()); URL url2 = new URL(str); HttpsURLConnection httpsURLConnection = (HttpsURLConnection) ((network == null || Build.VERSION.SDK_INT < 21) ? url2.openConnection() : network.openConnection(url2)); httpsURLConnection.setDoInput(true); httpsURLConnection.setDoOutput(false); httpsURLConnection.setUseCaches(false); httpsURLConnection.setInstanceFollowRedirects(false); httpsURLConnection.setReadTimeout(PlayerProps.FFP_PROP_FLOAT_MAX_AVDIFF_REALTIME); httpsURLConnection.setConnectTimeout(PlayerProps.FFP_PROP_FLOAT_MAX_AVDIFF_REALTIME); httpsURLConnection.setRequestMethod("GET"); httpsURLConnection.setSSLSocketFactory(instance.getSocketFactory()); httpsURLConnection.setHostnameVerifier(new HostnameVerifier() { /* class com.mobile.auth.y.b.AnonymousClass1 */ public boolean verify(String str, SSLSession sSLSession) { try { HostnameVerifier defaultHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier(); return defaultHostnameVerifier.verify("wostore.cn", sSLSession) || defaultHostnameVerifier.verify("10010.com", sSLSession); } catch (Throwable th) { ExceptionProcessor.processException(th); return false; } } }); if (hashMap != null) { for (String str3 : hashMap.keySet()) { httpsURLConnection.setRequestProperty(str3, hashMap.get(str3)); } } if (str.startsWith("https://opencloud.wostore.cn/openapi/netauth/precheck/wp?")) { e.a("Keep-Alive"); httpsURLConnection.addRequestProperty("Connection", "Keep-Alive"); } else { httpsURLConnection.addRequestProperty("Connection", "close"); } httpsURLConnection.connect(); if (httpsURLConnection.getResponseCode() == 200) { String a2 = a(httpsURLConnection.getInputStream()); if (!TextUtils.isEmpty(a2)) { return a2; } JSONObject jSONObject = new JSONObject(); jSONObject.put(PluginConstants.KEY_ERROR_CODE, AsrError.ERROR_OFFLINE_RECOGNIZE_FAIL); jSONObject.put("msg", "10012"); jSONObject.put("data", str2); return jSONObject.toString(); } else if (httpsURLConnection.getResponseCode() == 302) { String headerField = httpsURLConnection.getHeaderField("Location"); if (!TextUtils.isEmpty(headerField)) { return headerField.startsWith(Constants.HTTPS) ? a(headerField, null, network) : b(headerField, null, network); } JSONObject jSONObject2 = new JSONObject(); jSONObject2.put(PluginConstants.KEY_ERROR_CODE, 10013); jSONObject2.put("msg", "无跳转地址"); jSONObject2.put("data", str2); return jSONObject2.toString(); } else { JSONObject jSONObject3 = new JSONObject(); jSONObject3.put(PluginConstants.KEY_ERROR_CODE, AsrError.ERROR_OFFLINE_ENGINE_FREE_FAIL); jSONObject3.put("msg", "https状态码" + httpsURLConnection.getResponseCode()); jSONObject3.put("data", str2); return jSONObject3.toString(); } } catch (Exception e2) { e2.printStackTrace(); try { JSONObject jSONObject4 = new JSONObject(); jSONObject4.put(PluginConstants.KEY_ERROR_CODE, AsrError.ERROR_OFFLINE_ENGINE_NOT_SUPPORT); jSONObject4.put("msg", "https异常" + e2.getMessage()); jSONObject4.put("data", str2); return jSONObject4.toString(); } catch (Exception unused) { return null; } } } catch (Throwable th) { ExceptionProcessor.processException(th); return null; } } /* JADX WARNING: Removed duplicated region for block: B:69:0x0173 */ /* JADX WARNING: Removed duplicated region for block: B:78:0x0182 */ public String b(String str, HashMap<String, String> hashMap, Network network) { String str2; Throwable th; HttpURLConnection httpURLConnection; Exception e; HttpURLConnection httpURLConnection2 = null; try { URL url = new URL(str); str2 = "http://" + url.getHost(); } catch (MalformedURLException e2) { try { e2.printStackTrace(); str2 = str; } catch (Throwable th2) { ExceptionProcessor.processException(th2); return null; } } f.c(str); e.a(str); try { URL url2 = new URL(str); HttpURLConnection httpURLConnection3 = (HttpURLConnection) ((network == null || Build.VERSION.SDK_INT < 21) ? url2.openConnection() : network.openConnection(url2)); try { httpURLConnection3.setDoInput(true); httpURLConnection3.setDoOutput(false); httpURLConnection3.setUseCaches(false); httpURLConnection3.setInstanceFollowRedirects(false); httpURLConnection3.setReadTimeout(PlayerProps.FFP_PROP_FLOAT_MAX_AVDIFF_REALTIME); httpURLConnection3.setConnectTimeout(PlayerProps.FFP_PROP_FLOAT_MAX_AVDIFF_REALTIME); httpURLConnection3.setRequestMethod("GET"); if (hashMap != null) { for (String str3 : hashMap.keySet()) { httpURLConnection3.setRequestProperty(str3, hashMap.get(str3)); } } httpURLConnection3.addRequestProperty("Connection", "close"); httpURLConnection3.connect(); if (httpURLConnection3.getResponseCode() == 200) { String a2 = a(httpURLConnection3.getInputStream()); if (TextUtils.isEmpty(a2)) { JSONObject jSONObject = new JSONObject(); jSONObject.put(PluginConstants.KEY_ERROR_CODE, AsrError.ERROR_OFFLINE_RECOGNIZE_FAIL); jSONObject.put("msg", "10012"); jSONObject.put("data", str2); String jSONObject2 = jSONObject.toString(); if (httpURLConnection3 != null) { httpURLConnection3.disconnect(); } return jSONObject2; } if (httpURLConnection3 != null) { httpURLConnection3.disconnect(); } return a2; } else if (httpURLConnection3.getResponseCode() == 302) { String headerField = httpURLConnection3.getHeaderField("Location"); if (TextUtils.isEmpty(headerField)) { JSONObject jSONObject3 = new JSONObject(); jSONObject3.put(PluginConstants.KEY_ERROR_CODE, 10013); jSONObject3.put("msg", "无跳转地址"); jSONObject3.put("data", str2); String jSONObject4 = jSONObject3.toString(); if (httpURLConnection3 != null) { httpURLConnection3.disconnect(); } return jSONObject4; } else if (headerField.startsWith(Constants.HTTPS)) { String a3 = a(headerField, null, network); if (httpURLConnection3 != null) { httpURLConnection3.disconnect(); } return a3; } else { String b = b(headerField, null, network); if (httpURLConnection3 != null) { httpURLConnection3.disconnect(); } return b; } } else { JSONObject jSONObject5 = new JSONObject(); jSONObject5.put(PluginConstants.KEY_ERROR_CODE, AsrError.ERROR_OFFLINE_ENGINE_FREE_FAIL); jSONObject5.put("msg", "https状态码" + httpURLConnection3.getResponseCode()); jSONObject5.put("data", str2); String jSONObject6 = jSONObject5.toString(); if (httpURLConnection3 != null) { httpURLConnection3.disconnect(); } return jSONObject6; } } catch (Exception e3) { httpURLConnection = httpURLConnection3; e = e3; try { e.printStackTrace(); try { JSONObject jSONObject7 = new JSONObject(); jSONObject7.put(PluginConstants.KEY_ERROR_CODE, 10024); jSONObject7.put("msg", "http异常" + e.getMessage()); jSONObject7.put("data", str2); String jSONObject8 = jSONObject7.toString(); if (httpURLConnection != null) { httpURLConnection.disconnect(); } return jSONObject8; } catch (Exception unused) { if (httpURLConnection != null) { httpURLConnection.disconnect(); } return null; } } catch (Throwable th3) { th = th3; httpURLConnection2 = httpURLConnection; if (httpURLConnection2 != null) { } throw th; } } catch (Throwable th4) { httpURLConnection2 = httpURLConnection3; th = th4; if (httpURLConnection2 != null) { httpURLConnection2.disconnect(); } throw th; } } catch (Exception e4) { e = e4; httpURLConnection = null; e.printStackTrace(); JSONObject jSONObject72 = new JSONObject(); jSONObject72.put(PluginConstants.KEY_ERROR_CODE, 10024); jSONObject72.put("msg", "http异常" + e.getMessage()); jSONObject72.put("data", str2); String jSONObject82 = jSONObject72.toString(); if (httpURLConnection != null) { } return jSONObject82; } catch (Throwable th5) { th = th5; if (httpURLConnection2 != null) { } throw th; } } }