package com.tencent.open.utils; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Proxy; import android.os.Build; import android.os.Bundle; import android.text.TextUtils; import com.ijm.dataencryption.de.DataDecryptTool; import com.tencent.bugly.BuglyStrategy; import com.tencent.connect.auth.QQToken; import com.tencent.open.utils.i; import com.tencent.tauth.IRequestListener; import java.io.ByteArrayOutputStream; import java.io.CharConversionException; import java.io.EOFException; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InvalidClassException; import java.io.InvalidObjectException; import java.io.NotActiveException; import java.io.NotSerializableException; import java.io.OptionalDataException; import java.io.StreamCorruptedException; import java.io.SyncFailedException; import java.io.UTFDataFormatException; import java.io.UnsupportedEncodingException; import java.io.WriteAbortedException; import java.net.BindException; import java.net.ConnectException; import java.net.HttpRetryException; import java.net.MalformedURLException; import java.net.NoRouteToHostException; import java.net.PortUnreachableException; import java.net.ProtocolException; import java.net.Socket; import java.net.SocketTimeoutException; import java.net.URLEncoder; import java.net.UnknownHostException; import java.net.UnknownServiceException; import java.nio.channels.ClosedChannelException; import java.nio.channels.FileLockInterruptionException; import java.nio.charset.MalformedInputException; import java.nio.charset.UnmappableCharacterException; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.InvalidPropertiesFormatException; import java.util.zip.GZIPInputStream; import java.util.zip.ZipException; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLKeyException; import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLProtocolException; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509TrustManager; import org.apache.http.ConnectionClosedException; import org.apache.http.Header; import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.HttpVersion; import org.apache.http.MalformedChunkCodingException; import org.apache.http.NoHttpResponseException; import org.apache.http.client.HttpClient; import org.apache.http.client.HttpResponseException; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.conn.ConnectTimeoutException; import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; import org.apache.http.params.BasicHttpParams; import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpProtocolParams; import org.json.JSONException; import org.json.JSONObject; /* compiled from: ProGuard */ /* loaded from: classes.dex */ public class HttpUtils { /* compiled from: ProGuard */ public static class HttpStatusException extends Exception { public static final String ERROR_INFO = "http status code error:"; public HttpStatusException(String str) { super(str); } } /* compiled from: ProGuard */ public static class NetworkUnavailableException extends Exception { public static final String ERROR_INFO = "network unavailable"; public NetworkUnavailableException(String str) { super(str); } } /* compiled from: ProGuard */ public static class a extends SSLSocketFactory { private final SSLContext a; public a(KeyStore keyStore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { super(keyStore); b bVar; this.a = SSLContext.getInstance("TLS"); try { bVar = new b(); } catch (Exception unused) { bVar = null; } this.a.init(null, new TrustManager[]{bVar}, null); } @Override // org.apache.http.conn.ssl.SSLSocketFactory, org.apache.http.conn.scheme.LayeredSocketFactory public Socket createSocket(Socket socket, String str, int i, boolean z) throws IOException, UnknownHostException { return this.a.getSocketFactory().createSocket(socket, str, i, z); } @Override // org.apache.http.conn.ssl.SSLSocketFactory, org.apache.http.conn.scheme.SocketFactory public Socket createSocket() throws IOException { return this.a.getSocketFactory().createSocket(); } } /* compiled from: ProGuard */ public static class b implements X509TrustManager { X509TrustManager a; b() throws Exception { KeyStore keyStore; FileInputStream fileInputStream; Throwable th; TrustManager[] trustManagers; try { keyStore = KeyStore.getInstance("JKS"); } catch (Exception unused) { keyStore = null; } if (keyStore != null) { try { fileInputStream = new FileInputStream("trustedCerts"); } catch (Throwable th2) { fileInputStream = null; th = th2; } try { keyStore.load(fileInputStream, "passphrase".toCharArray()); TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509", "SunJSSE"); trustManagerFactory.init(keyStore); trustManagers = trustManagerFactory.getTrustManagers(); fileInputStream.close(); } catch (Throwable th3) { th = th3; if (fileInputStream != null) { fileInputStream.close(); } throw th; } } else { TrustManagerFactory trustManagerFactory2 = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); trustManagerFactory2.init((KeyStore) null); trustManagers = trustManagerFactory2.getTrustManagers(); } for (int i = 0; i < trustManagers.length; i++) { if (trustManagers[i] instanceof X509TrustManager) { this.a = (X509TrustManager) trustManagers[i]; return; } } throw new Exception("Couldn't initialize"); } @Override // javax.net.ssl.X509TrustManager public void checkClientTrusted(X509Certificate[] x509CertificateArr, String str) throws CertificateException { this.a.checkClientTrusted(x509CertificateArr, str); } @Override // javax.net.ssl.X509TrustManager public void checkServerTrusted(X509Certificate[] x509CertificateArr, String str) throws CertificateException { this.a.checkServerTrusted(x509CertificateArr, str); } @Override // javax.net.ssl.X509TrustManager public X509Certificate[] getAcceptedIssuers() { return this.a.getAcceptedIssuers(); } } /* compiled from: ProGuard */ public static class c { public final String a; public final int b; private c(String str, int i) { this.a = str; this.b = i; } } private HttpUtils() { } private static void a(Context context, QQToken qQToken, String str) { if (str.indexOf("add_share") > -1 || str.indexOf("upload_pic") > -1 || str.indexOf("add_topic") > -1 || str.indexOf("set_user_face") > -1 || str.indexOf("add_t") > -1 || str.indexOf("add_pic_t") > -1 || str.indexOf("add_pic_url") > -1 || str.indexOf("add_video") > -1) { com.tencent.connect.a.a.a(context, qQToken, "requireApi", str); } } private static String b(Context context) { if (Build.VERSION.SDK_INT >= 11) { return System.getProperty("http.proxyHost"); } if (context == null) { return Proxy.getDefaultHost(); } String host = Proxy.getHost(context); return TextUtils.isEmpty(host) ? Proxy.getDefaultHost() : host; } public static String encodePostBody(Bundle bundle, String str) { if (bundle == null) { return ""; } StringBuilder sb = new StringBuilder(); int i = -1; int size = bundle.size(); for (String str2 : bundle.keySet()) { i++; Object obj = bundle.get(str2); if (obj instanceof String) { sb.append("Content-Disposition: form-data; name=\"" + str2 + "\"\r\n\r\n" + ((String) obj)); if (i < size - 1) { sb.append("\r\n--" + str + "\r\n"); } } } return sb.toString(); } public static String encodeUrl(Bundle bundle) { if (bundle == null) { return ""; } StringBuilder sb = new StringBuilder(); boolean z = true; for (String str : bundle.keySet()) { Object obj = bundle.get(str); if ((obj instanceof String) || (obj instanceof String[])) { if (obj instanceof String[]) { if (z) { z = false; } else { sb.append("&"); } sb.append(URLEncoder.encode(str) + "="); String[] stringArray = bundle.getStringArray(str); if (stringArray != null) { for (int i = 0; i < stringArray.length; i++) { if (i == 0) { sb.append(URLEncoder.encode(stringArray[i])); } else { sb.append(URLEncoder.encode("," + stringArray[i])); } } } } else { if (z) { z = false; } else { sb.append("&"); } sb.append(URLEncoder.encode(str) + "=" + URLEncoder.encode(bundle.getString(str))); } } } return sb.toString(); } public static int getErrorCodeFromException(IOException iOException) { if (iOException instanceof CharConversionException) { return -20; } if (iOException instanceof MalformedInputException) { return -21; } if (iOException instanceof UnmappableCharacterException) { return -22; } if (iOException instanceof HttpResponseException) { return -23; } if (iOException instanceof ClosedChannelException) { return -24; } if (iOException instanceof ConnectionClosedException) { return -25; } if (iOException instanceof EOFException) { return -26; } if (iOException instanceof FileLockInterruptionException) { return -27; } if (iOException instanceof FileNotFoundException) { return -28; } if (iOException instanceof HttpRetryException) { return -29; } if (iOException instanceof ConnectTimeoutException) { return -7; } if (iOException instanceof SocketTimeoutException) { return -8; } if (iOException instanceof InvalidPropertiesFormatException) { return -30; } if (iOException instanceof MalformedChunkCodingException) { return -31; } if (iOException instanceof MalformedURLException) { return -3; } if (iOException instanceof NoHttpResponseException) { return -32; } if (iOException instanceof InvalidClassException) { return -33; } if (iOException instanceof InvalidObjectException) { return -34; } if (iOException instanceof NotActiveException) { return -35; } if (iOException instanceof NotSerializableException) { return -36; } if (iOException instanceof OptionalDataException) { return -37; } if (iOException instanceof StreamCorruptedException) { return -38; } if (iOException instanceof WriteAbortedException) { return -39; } if (iOException instanceof ProtocolException) { return -40; } if (iOException instanceof SSLHandshakeException) { return -41; } if (iOException instanceof SSLKeyException) { return -42; } if (iOException instanceof SSLPeerUnverifiedException) { return -43; } if (iOException instanceof SSLProtocolException) { return -44; } if (iOException instanceof BindException) { return -45; } if (iOException instanceof ConnectException) { return -46; } if (iOException instanceof NoRouteToHostException) { return -47; } if (iOException instanceof PortUnreachableException) { return -48; } if (iOException instanceof SyncFailedException) { return -49; } if (iOException instanceof UTFDataFormatException) { return -50; } if (iOException instanceof UnknownHostException) { return -51; } if (iOException instanceof UnknownServiceException) { return -52; } if (iOException instanceof UnsupportedEncodingException) { return -53; } return iOException instanceof ZipException ? -54 : -2; } public static HttpClient getHttpClient(Context context, String str, String str2) { int i; SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); if (Build.VERSION.SDK_INT < 16) { try { KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(null, null); a aVar = new a(keyStore); aVar.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); schemeRegistry.register(new Scheme("https", aVar, 443)); } catch (Exception unused) { schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); } } else { schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); } BasicHttpParams basicHttpParams = new BasicHttpParams(); e a2 = context != null ? e.a(context, str) : null; int i2 = 0; if (a2 != null) { i2 = a2.a("Common_HttpConnectionTimeout"); i = a2.a("Common_SocketConnectionTimeout"); } else { i = 0; } if (i2 == 0) { i2 = 15000; } if (i == 0) { i = BuglyStrategy.a.MAX_USERDATA_VALUE_LENGTH; } HttpConnectionParams.setConnectionTimeout(basicHttpParams, i2); HttpConnectionParams.setSoTimeout(basicHttpParams, i); HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(basicHttpParams, "UTF-8"); HttpProtocolParams.setUserAgent(basicHttpParams, "AndroidSDK_" + Build.VERSION.SDK + "_" + Build.DEVICE + "_" + Build.VERSION.RELEASE); DefaultHttpClient defaultHttpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry), basicHttpParams); c proxy = getProxy(context); if (proxy != null) { defaultHttpClient.getParams().setParameter("http.route.default-proxy", new HttpHost(proxy.a, proxy.b)); } return defaultHttpClient; } public static c getProxy(Context context) { ConnectivityManager connectivityManager; NetworkInfo activeNetworkInfo; if (context != null && (connectivityManager = (ConnectivityManager) context.getSystemService("connectivity")) != null && (activeNetworkInfo = connectivityManager.getActiveNetworkInfo()) != null && activeNetworkInfo.getType() == 0) { String b2 = b(context); int a2 = a(context); if (!TextUtils.isEmpty(b2) && a2 >= 0) { return new c(b2, a2); } } return null; } public static i.a openUrl2(Context context, String str, String str2, Bundle bundle) throws MalformedURLException, IOException, NetworkUnavailableException, HttpStatusException { ConnectivityManager connectivityManager; NetworkInfo activeNetworkInfo; if (context != null && (connectivityManager = (ConnectivityManager) context.getSystemService("connectivity")) != null && ((activeNetworkInfo = connectivityManager.getActiveNetworkInfo()) == null || !activeNetworkInfo.isAvailable())) { throw new NetworkUnavailableException(NetworkUnavailableException.ERROR_INFO); } Bundle bundle2 = bundle != null ? new Bundle(bundle) : new Bundle(); String string = bundle2.getString("appid_for_getting_config"); bundle2.remove("appid_for_getting_config"); HttpClient httpClient = getHttpClient(context, string, str); HttpUriRequest httpUriRequest = null; int i = 0; int i2 = -1; if (str2.equals("GET")) { String encodeUrl = encodeUrl(bundle2); i = 0 + encodeUrl.length(); com.tencent.open.a.f.a("openSDK_LOG.HttpUtils", "-->openUrl2 before url =" + str); String str3 = str.indexOf("?") == -1 ? str + "?" : str + "&"; com.tencent.open.a.f.a("openSDK_LOG.HttpUtils", "-->openUrl2 encodedParam =" + encodeUrl + " -- url = " + str3); StringBuilder sb = new StringBuilder(); sb.append(str3); sb.append(encodeUrl); HttpGet httpGet = new HttpGet(sb.toString()); httpGet.addHeader("Accept-Encoding", "gzip"); httpUriRequest = httpGet; } else if (str2.equals("POST")) { HttpPost httpPost = new HttpPost(str); httpPost.addHeader("Accept-Encoding", "gzip"); Bundle bundle3 = new Bundle(); for (String str4 : bundle2.keySet()) { Object obj = bundle2.get(str4); if (obj instanceof byte[]) { bundle3.putByteArray(str4, (byte[]) obj); } } if (!bundle2.containsKey("method")) { bundle2.putString("method", str2); } httpPost.setHeader("Content-Type", "multipart/form-data; boundary=3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f"); httpPost.setHeader("Connection", "Keep-Alive"); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byteArrayOutputStream.write(i.i("--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f\r\n")); byteArrayOutputStream.write(i.i(encodePostBody(bundle2, "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f"))); if (!bundle3.isEmpty()) { int size = bundle3.size(); byteArrayOutputStream.write(i.i("\r\n--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f\r\n")); for (String str5 : bundle3.keySet()) { i2++; byteArrayOutputStream.write(i.i("Content-Disposition: form-data; name=\"" + str5 + "\"; filename=\"" + str5 + "\"\r\n")); byteArrayOutputStream.write(i.i("Content-Type: content/unknown\r\n\r\n")); byte[] byteArray = bundle3.getByteArray(str5); if (byteArray != null) { byteArrayOutputStream.write(byteArray); } if (i2 < size - 1) { byteArrayOutputStream.write(i.i("\r\n--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f\r\n")); } } } byteArrayOutputStream.write(i.i("\r\n--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f--\r\n")); byte[] byteArray2 = byteArrayOutputStream.toByteArray(); i = 0 + byteArray2.length; byteArrayOutputStream.close(); httpPost.setEntity(new ByteArrayEntity(byteArray2)); httpUriRequest = httpPost; } HttpResponse execute = httpClient.execute(httpUriRequest); int statusCode = execute.getStatusLine().getStatusCode(); if (statusCode == 200) { return new i.a(a(execute), i); } throw new HttpStatusException(HttpStatusException.ERROR_INFO + statusCode); } /* JADX WARN: Removed duplicated region for block: B:47:0x0185 A[SYNTHETIC] */ /* JADX WARN: Removed duplicated region for block: B:49:? A[LOOP:0: B:8:0x00b8->B:49:?, LOOP_END, SYNTHETIC] */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public static org.json.JSONObject request(com.tencent.connect.auth.QQToken r19, android.content.Context r20, java.lang.String r21, android.os.Bundle r22, java.lang.String r23) throws java.io.IOException, org.json.JSONException, com.tencent.open.utils.HttpUtils.NetworkUnavailableException, com.tencent.open.utils.HttpUtils.HttpStatusException { /* Method dump skipped, instructions count: 418 To view this dump change 'Code comments level' option to 'DEBUG' */ throw new UnsupportedOperationException("Method not decompiled: com.tencent.open.utils.HttpUtils.request(com.tencent.connect.auth.QQToken, android.content.Context, java.lang.String, android.os.Bundle, java.lang.String):org.json.JSONObject"); } public static void requestAsync(final QQToken qQToken, final Context context, final String str, final Bundle bundle, final String str2, final IRequestListener iRequestListener) { com.tencent.open.a.f.a("openSDK_LOG.HttpUtils", "OpenApi requestAsync"); new Thread() { // from class: com.tencent.open.utils.HttpUtils.1 @Override // java.lang.Thread, java.lang.Runnable public void run() { try { JSONObject request = HttpUtils.request(QQToken.this, context, str, bundle, str2); if (iRequestListener != null) { iRequestListener.a(request); com.tencent.open.a.f.b("openSDK_LOG.HttpUtils", "OpenApi onComplete"); } } catch (HttpStatusException e) { IRequestListener iRequestListener2 = iRequestListener; if (iRequestListener2 != null) { iRequestListener2.a(e); com.tencent.open.a.f.b("openSDK_LOG.HttpUtils", "OpenApi requestAsync onHttpStatusException", e); } } catch (NetworkUnavailableException e2) { IRequestListener iRequestListener3 = iRequestListener; if (iRequestListener3 != null) { iRequestListener3.a(e2); com.tencent.open.a.f.b("openSDK_LOG.HttpUtils", "OpenApi requestAsync onNetworkUnavailableException", e2); } } catch (MalformedURLException e3) { IRequestListener iRequestListener4 = iRequestListener; if (iRequestListener4 != null) { iRequestListener4.a(e3); com.tencent.open.a.f.b("openSDK_LOG.HttpUtils", "OpenApi requestAsync MalformedURLException", e3); } } catch (SocketTimeoutException e4) { IRequestListener iRequestListener5 = iRequestListener; if (iRequestListener5 != null) { iRequestListener5.a(e4); com.tencent.open.a.f.b("openSDK_LOG.HttpUtils", "OpenApi requestAsync onSocketTimeoutException", e4); } } catch (ConnectTimeoutException e5) { IRequestListener iRequestListener6 = iRequestListener; if (iRequestListener6 != null) { iRequestListener6.a(e5); com.tencent.open.a.f.b("openSDK_LOG.HttpUtils", "OpenApi requestAsync onConnectTimeoutException", e5); } } catch (IOException e6) { IRequestListener iRequestListener7 = iRequestListener; if (iRequestListener7 != null) { iRequestListener7.a(e6); com.tencent.open.a.f.b("openSDK_LOG.HttpUtils", "OpenApi requestAsync IOException", e6); } } catch (JSONException e7) { IRequestListener iRequestListener8 = iRequestListener; if (iRequestListener8 != null) { iRequestListener8.a(e7); com.tencent.open.a.f.b("openSDK_LOG.HttpUtils", "OpenApi requestAsync JSONException", e7); } } catch (Exception e8) { IRequestListener iRequestListener9 = iRequestListener; if (iRequestListener9 != null) { iRequestListener9.a(e8); com.tencent.open.a.f.b("openSDK_LOG.HttpUtils", "OpenApi requestAsync onUnknowException", e8); } } } }.start(); } private static String a(HttpResponse httpResponse) throws IllegalStateException, IOException { InputStream content = httpResponse.getEntity().getContent(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); Header firstHeader = httpResponse.getFirstHeader("Content-Encoding"); InputStream gZIPInputStream = (firstHeader == null || firstHeader.getValue().toLowerCase().indexOf("gzip") <= -1) ? content : new GZIPInputStream(content); byte[] bArr = new byte[DataDecryptTool.DECRYPT_DB_FILE]; while (true) { int read = gZIPInputStream.read(bArr); if (read != -1) { byteArrayOutputStream.write(bArr, 0, read); } else { String str = new String(byteArrayOutputStream.toByteArray(), "UTF-8"); gZIPInputStream.close(); return str; } } } private static int a(Context context) { if (Build.VERSION.SDK_INT < 11) { if (context != null) { int port = Proxy.getPort(context); return port < 0 ? Proxy.getDefaultPort() : port; } return Proxy.getDefaultPort(); } String property = System.getProperty("http.proxyPort"); if (!TextUtils.isEmpty(property)) { try { return Integer.parseInt(property); } catch (NumberFormatException unused) { } } return -1; } }