package com.kuaishou.weapon.p0; import android.content.Context; import android.text.TextUtils; import com.baidu.mobads.sdk.internal.ae; import com.czhj.sdk.common.Constants; import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.security.SecureRandom; import java.security.cert.X509Certificate; import java.util.Map; import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; public class m { public static final String b = "gzip"; public static final int c = 1024; public static volatile m d; public static Context e; public static TrustManager[] f = {new a()}; public static SSLSocketFactory g; public boolean a = false; public static class a implements X509TrustManager { @Override // javax.net.ssl.X509TrustManager public final void checkClientTrusted(X509Certificate[] x509CertificateArr, String str) { } @Override // javax.net.ssl.X509TrustManager public final void checkServerTrusted(X509Certificate[] x509CertificateArr, String str) { try { m.b(x509CertificateArr); } catch (Throwable unused) { } } public final X509Certificate[] getAcceptedIssuers() { return null; } } public m(Context context) { e = context; } public static m a(Context context) { if (d == null) { synchronized (m.class) { if (d == null) { d = new m(context); } } } return d; } private InputStream a(HttpURLConnection httpURLConnection) { if (!(httpURLConnection == null || httpURLConnection == null)) { try { if ("gzip".equalsIgnoreCase(httpURLConnection.getContentEncoding())) { this.a = true; } else { this.a = false; } return httpURLConnection.getInputStream(); } catch (IOException unused) { } } return null; } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r5v6, types: [java.net.HttpURLConnection] */ /* JADX WARNING: Unknown variable types count: 1 */ private HttpURLConnection a(String str, String str2) { HttpsURLConnection httpsURLConnection; try { URL url = new URL(str); if (Constants.HTTPS.equals(url.getProtocol())) { HttpsURLConnection httpsURLConnection2 = (HttpsURLConnection) url.openConnection(); a(httpsURLConnection2); httpsURLConnection = httpsURLConnection2; } else { httpsURLConnection = (HttpURLConnection) url.openConnection(); } try { httpsURLConnection.setRequestMethod(str2); httpsURLConnection.setAllowUserInteraction(true); httpsURLConnection.setInstanceFollowRedirects(true); httpsURLConnection.setChunkedStreamingMode(0); httpsURLConnection.setConnectTimeout(10000); httpsURLConnection.setReadTimeout(5000); httpsURLConnection.setRequestProperty("Charset", "UTF-8"); httpsURLConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); if (!str2.equalsIgnoreCase("post")) { return httpsURLConnection; } httpsURLConnection.setDoInput(true); httpsURLConnection.setDoOutput(true); httpsURLConnection.setUseCaches(false); return httpsURLConnection; } catch (Exception unused) { return httpsURLConnection; } } catch (Exception unused2) { return null; } } public static void a(String str) { try { new i(e).b(f3.m, str, true); } catch (Exception unused) { } } private synchronized void a(HttpsURLConnection httpsURLConnection) { if (httpsURLConnection != null) { try { if (g == null) { SSLContext instance = SSLContext.getInstance("TLS"); instance.init(null, f, new SecureRandom()); g = instance.getSocketFactory(); } SSLSocketFactory sSLSocketFactory = g; if (sSLSocketFactory != null) { httpsURLConnection.setSSLSocketFactory(sSLSocketFactory); } } catch (Throwable unused) { } } } /* JADX WARNING: Removed duplicated region for block: B:24:0x0036 A[SYNTHETIC, Splitter:B:24:0x0036] */ private boolean a(InputStream inputStream, File file) { BufferedOutputStream bufferedOutputStream; if (this.a) { try { inputStream = new GZIPInputStream(inputStream); } catch (IOException unused) { } } if (inputStream == null) { return false; } try { bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file)); try { byte[] bArr = new byte[1024]; while (true) { int read = inputStream.read(bArr); if (read != -1) { bufferedOutputStream.write(bArr, 0, read); bufferedOutputStream.flush(); } else { try { bufferedOutputStream.close(); return true; } catch (IOException unused2) { return true; } } } } catch (Throwable unused3) { if (bufferedOutputStream != null) { try { bufferedOutputStream.close(); } catch (IOException unused4) { } } return false; } } catch (Throwable unused5) { bufferedOutputStream = null; if (bufferedOutputStream != null) { } return false; } } public static void b(X509Certificate[] x509CertificateArr) { if (x509CertificateArr != null) { try { if (x509CertificateArr.length != 0) { String name = x509CertificateArr[0].getIssuerX500Principal().getName(); if (!Pattern.compile(".*(GeoTrust|VeriSign|Symantec|GlobalSign|Entrust|Thawte|DigiCert).*", 2).matcher(name).matches()) { a(name); } } } catch (Throwable unused) { } } } /* JADX WARNING: Code restructure failed: missing block: B:24:0x0084, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:25:0x0085, code lost: r0 = r11; r11 = r0; */ /* JADX WARNING: Code restructure failed: missing block: B:43:0x00b2, code lost: if (r11 != null) goto L_0x00d0; */ /* JADX WARNING: Code restructure failed: missing block: B:49:?, code lost: r2.close(); */ /* JADX WARNING: Code restructure failed: missing block: B:51:0x00c0, code lost: r11.close(); */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:26:0x0089 */ /* JADX WARNING: Removed duplicated region for block: B:24:0x0084 A[ExcHandler: all (r0v9 'th' java.lang.Throwable A[CUSTOM_DECLARE]), Splitter:B:21:0x0068] */ /* JADX WARNING: Removed duplicated region for block: B:33:0x0099 A[Catch:{ Exception -> 0x00a8, all -> 0x00a5 }, LOOP:0: B:31:0x0092->B:33:0x0099, LOOP_END] */ /* JADX WARNING: Removed duplicated region for block: B:48:0x00bb A[SYNTHETIC, Splitter:B:48:0x00bb] */ /* JADX WARNING: Removed duplicated region for block: B:51:0x00c0 A[Catch:{ Exception -> 0x00c3 }] */ /* JADX WARNING: Removed duplicated region for block: B:59:0x00c8 A[SYNTHETIC, Splitter:B:59:0x00c8] */ /* JADX WARNING: Removed duplicated region for block: B:64:0x00cf */ /* JADX WARNING: Removed duplicated region for block: B:68:0x00d7 A[RETURN] */ /* JADX WARNING: Removed duplicated region for block: B:69:0x00d8 A[RETURN] */ /* JADX WARNING: Removed duplicated region for block: B:70:0x009d A[EDGE_INSN: B:70:0x009d->B:34:0x009d ?: BREAK , SYNTHETIC] */ public String a(n nVar) { String str; InputStream inputStream; ByteArrayOutputStream byteArrayOutputStream; Throwable th; boolean z = false; ByteArrayOutputStream byteArrayOutputStream2 = null; try { HttpURLConnection a2 = a(nVar.a, ae.b); String a3 = nVar.a(); if (!TextUtils.isEmpty(a3) && a2 != null) { a2.setRequestProperty("Cookie", a3); } String b2 = nVar.b(); if (!TextUtils.isEmpty(b2) && a2 != null) { a2.setRequestProperty("env", b2); } byte[] bytes = nVar.c() != null ? nVar.c().toString().getBytes() : null; if (bytes != null && bytes.length > 0) { a2.setRequestProperty("Content-Length", String.valueOf(bytes.length)); OutputStream outputStream = a2.getOutputStream(); outputStream.write(bytes); outputStream.flush(); outputStream.close(); } if (a2.getResponseCode() == 200) { inputStream = a2.getInputStream(); try { new i(e).b(f3.f, a2.getDate() - System.currentTimeMillis()); a2.getDate(); System.currentTimeMillis(); 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); } str = byteArrayOutputStream.toString(); z = true; } catch (Exception unused) { if (byteArrayOutputStream != null) { try { byteArrayOutputStream.close(); } catch (Exception unused2) { } } if (inputStream != null) { str = null; inputStream.close(); if (!z) { return str; } return null; } str = null; if (!z) { } } catch (Throwable th2) { th = th2; byteArrayOutputStream2 = byteArrayOutputStream; if (byteArrayOutputStream2 != null) { } if (inputStream != null) { } throw th; } } catch (Exception unused3) { byteArrayOutputStream = null; if (byteArrayOutputStream != null) { } if (inputStream != null) { } str = null; if (!z) { } } catch (Throwable th3) { } } else { inputStream = null; byteArrayOutputStream = null; str = null; } if (byteArrayOutputStream != null) { try { byteArrayOutputStream.close(); } catch (Exception unused4) { } } } catch (Exception unused5) { inputStream = null; byteArrayOutputStream = null; if (byteArrayOutputStream != null) { } if (inputStream != null) { } str = null; if (!z) { } } catch (Throwable th4) { Throwable th5 = th4; InputStream inputStream2 = null; th = th5; inputStream = inputStream2; if (byteArrayOutputStream2 != null) { } if (inputStream != null) { } throw th; } } public String a(Map<String, String> map) { String str = ""; for (Map.Entry<String, String> entry : map.entrySet()) { str = str + "&" + entry.getKey() + "=" + entry.getValue(); } return str.substring(1); } public void a(n nVar, k kVar) { a(nVar, kVar, "GET"); } /* JADX WARNING: Code restructure failed: missing block: B:38:0x00aa, code lost: r12 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:39:0x00ab, code lost: r12 = r10; r10 = r12; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:26:0x0089 */ /* JADX WARNING: Removed duplicated region for block: B:33:0x0099 A[Catch:{ Exception -> 0x00a8, all -> 0x00a6 }, LOOP:0: B:31:0x0092->B:33:0x0099, LOOP_END] */ /* JADX WARNING: Removed duplicated region for block: B:38:0x00aa A[ExcHandler: all (r12v11 'th' java.lang.Throwable A[CUSTOM_DECLARE]), Splitter:B:23:0x006e] */ /* JADX WARNING: Removed duplicated region for block: B:56:0x00ce A[SYNTHETIC, Splitter:B:56:0x00ce] */ /* JADX WARNING: Removed duplicated region for block: B:59:0x00d3 A[Catch:{ Exception -> 0x00db }] */ /* JADX WARNING: Removed duplicated region for block: B:61:0x00d8 A[Catch:{ Exception -> 0x00db }] */ /* JADX WARNING: Removed duplicated region for block: B:69:0x00e0 */ /* JADX WARNING: Removed duplicated region for block: B:71:0x00e5 */ /* JADX WARNING: Removed duplicated region for block: B:75:0x009d A[EDGE_INSN: B:75:0x009d->B:34:0x009d ?: BREAK , SYNTHETIC] */ /* JADX WARNING: Removed duplicated region for block: B:78:? A[RETURN, SYNTHETIC] */ public void a(n nVar, k kVar, String str) { ByteArrayOutputStream byteArrayOutputStream; InputStream inputStream; Throwable th; boolean z; String str2; ByteArrayOutputStream byteArrayOutputStream2; byte[] bArr; int read; String str3 = null; byteArrayOutputStream2 = null; try { HttpURLConnection a2 = a(nVar.a, str); String a3 = nVar.a(); if (!TextUtils.isEmpty(a3) && a2 != null) { a2.setRequestProperty("Cookie", a3); } String b2 = nVar.b(); if (!TextUtils.isEmpty(b2) && a2 != null) { a2.setRequestProperty("env", b2); } if (str.equalsIgnoreCase("post")) { byte[] bytes = nVar.c() != null ? nVar.c().toString().getBytes() : null; if (bytes != null && bytes.length > 0) { a2.setRequestProperty("Content-Length", String.valueOf(bytes.length)); OutputStream outputStream = a2.getOutputStream(); outputStream.write(bytes); outputStream.flush(); outputStream.close(); } } z = false; if (a2.getResponseCode() == 200) { inputStream = a2.getInputStream(); try { new i(e).b(f3.f, a2.getDate() - System.currentTimeMillis()); a2.getDate(); System.currentTimeMillis(); } catch (Exception unknown) { byteArrayOutputStream = new ByteArrayOutputStream(); bArr = new byte[1024]; while (true) { read = inputStream.read(bArr); if (read != -1) { } byteArrayOutputStream.write(bArr, 0, read); } z = true; byteArrayOutputStream2 = byteArrayOutputStream; str2 = byteArrayOutputStream.toString(); } catch (Throwable th2) { } byteArrayOutputStream = new ByteArrayOutputStream(); try { bArr = new byte[1024]; while (true) { read = inputStream.read(bArr); if (read != -1) { break; } byteArrayOutputStream.write(bArr, 0, read); } z = true; byteArrayOutputStream2 = byteArrayOutputStream; str2 = byteArrayOutputStream.toString(); } catch (Exception unused) { if (byteArrayOutputStream != null) { } if (inputStream != null) { } if (kVar == null) { } kVar.a(str3); } catch (Throwable th3) { th = th3; if (byteArrayOutputStream != null) { } if (inputStream != null) { } if (kVar != null) { } throw th; } } else { inputStream = null; str2 = null; } if (byteArrayOutputStream2 != null) { try { byteArrayOutputStream2.close(); } catch (Exception unused2) { return; } } if (inputStream != null) { inputStream.close(); } if (z) { if (kVar != null) { kVar.b(str2); } } else if (kVar != null) { str3 = str2; kVar.a(str3); } } catch (Exception unused3) { inputStream = null; byteArrayOutputStream = null; if (byteArrayOutputStream != null) { byteArrayOutputStream.close(); } if (inputStream != null) { inputStream.close(); } if (kVar == null) { return; } kVar.a(str3); } catch (Throwable th4) { Throwable th5 = th4; InputStream inputStream2 = null; th = th5; inputStream = inputStream2; byteArrayOutputStream = null; if (byteArrayOutputStream != null) { try { byteArrayOutputStream.close(); } catch (Exception unused4) { throw th; } } if (inputStream != null) { inputStream.close(); } if (kVar != null) { kVar.a(null); } throw th; } } /* JADX WARNING: Removed duplicated region for block: B:20:0x0029 A[SYNTHETIC, Splitter:B:20:0x0029] */ /* JADX WARNING: Removed duplicated region for block: B:23:0x002e A[Catch:{ all -> 0x0032 }] */ public boolean a(String str, File file) { HttpURLConnection httpURLConnection; if (TextUtils.isEmpty(str)) { return false; } InputStream inputStream = null; try { httpURLConnection = a(str, "GET"); try { inputStream = a(httpURLConnection); boolean a2 = a(inputStream, file); if (inputStream != null) { try { inputStream.close(); } catch (Throwable unused) { return false; } } if (httpURLConnection != null) { httpURLConnection.disconnect(); } return a2; } catch (Throwable unused2) { if (inputStream != null) { try { inputStream.close(); } catch (Throwable unused3) { return false; } } if (httpURLConnection != null) { httpURLConnection.disconnect(); } return false; } } catch (Throwable unused4) { httpURLConnection = null; if (inputStream != null) { } if (httpURLConnection != null) { } return false; } } public void b(n nVar, k kVar) { a(nVar, kVar, ae.b); } }