package com.baidu.liantian.utility; import android.content.Context; import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkInfo; import android.net.Proxy; import android.os.Build; import android.text.TextUtils; import android.util.Base64; import com.baidu.liantian.a; import com.czhj.sdk.common.Constants; import com.kuaishou.weapon.p0.h; import com.mbridge.msdk.foundation.entity.CampaignEx; import java.net.HttpURLConnection; import java.net.InetSocketAddress; import java.net.Proxy; import java.net.URL; import java.security.cert.Certificate; import java.security.cert.X509Certificate; import javax.net.ssl.HttpsURLConnection; import org.json.JSONArray; import org.json.JSONObject; /* compiled from: HttpCetificateUtil */ public final class g { public static JSONArray a(Context context) { try { String string = k.a(context).a.getString("lt_sha", ""); if (TextUtils.isEmpty(string)) { a.a(); return new JSONArray(); } JSONArray jSONArray = new JSONArray(); JSONArray jSONArray2 = new JSONArray(string); for (int i = 0; i < jSONArray2.length(); i++) { String optString = jSONArray2.optString(i); String a = a(context, optString); JSONObject jSONObject = new JSONObject(); jSONObject.put("url", optString); jSONObject.put(CampaignEx.JSON_KEY_AD_MP, a); jSONArray.put(jSONObject); } return jSONArray; } catch (Throwable unused) { a.a(); return new JSONArray(); } } public static int b(Context context) { Network[] allNetworks; try { if (i.a(context, new String[]{h.b})) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity"); if (Build.VERSION.SDK_INT > 20) { for (Network network : connectivityManager.getAllNetworks()) { if (connectivityManager.getNetworkCapabilities(network).hasTransport(4)) { return 17; } } } else { NetworkInfo networkInfo = connectivityManager.getNetworkInfo(17); if (networkInfo != null && networkInfo.isConnectedOrConnecting()) { return 17; } } if (!TextUtils.isEmpty(System.getProperties().getProperty("http.proxyHost"))) { return 16; } NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetworkInfo == null) { return -1; } return activeNetworkInfo.getType(); } } catch (Throwable unused) { a.a(); } return -1; } private static String a(HttpsURLConnection httpsURLConnection) { try { Certificate[] serverCertificates = httpsURLConnection.getServerCertificates(); int length = serverCertificates.length; a.a(); String str = ""; for (Certificate certificate : serverCertificates) { try { X509Certificate x509Certificate = (X509Certificate) certificate; x509Certificate.toString(); byte[] encoded = x509Certificate.getPublicKey().getEncoded(); if (encoded != null) { String encodeToString = Base64.encodeToString(encoded, 0); str = str + h.a(encodeToString.replace("\n", "").replace("\r", "")); } str = str + ";"; } catch (Throwable unused) { a.a(); } } if (TextUtils.isEmpty(str)) { a.a(); return ""; } String substring = str.substring(0, str.length() - 1); httpsURLConnection.getURL().toString(); a.a(); return substring; } catch (Throwable unused2) { a.a(); return ""; } } /* JADX DEBUG: Multi-variable search result rejected for r5v4, resolved type: java.lang.String */ /* JADX DEBUG: Multi-variable search result rejected for r5v18, resolved type: java.lang.String */ /* JADX WARN: Multi-variable type inference failed */ /* JADX WARNING: Can't wrap try/catch for region: R(3:26|27|(1:36)) */ /* JADX WARNING: Code restructure failed: missing block: B:27:?, code lost: com.baidu.liantian.utility.a.a(); */ /* JADX WARNING: Code restructure failed: missing block: B:30:0x0092, code lost: r5 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:31:0x0093, code lost: if (r0 != null) goto L_0x0095; */ /* JADX WARNING: Code restructure failed: missing block: B:32:0x0095, code lost: r0.disconnect(); */ /* JADX WARNING: Code restructure failed: missing block: B:33:0x0098, code lost: throw r5; */ /* JADX WARNING: Code restructure failed: missing block: B:36:?, code lost: return ""; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:26:0x0087 */ private static String a(Context context, String str) { String str2; HttpURLConnection httpURLConnection; HttpURLConnection httpURLConnection2 = null; URL url = new URL(str); int i = 0; if (a.c(context)) { str2 = httpURLConnection2; } else if (Build.VERSION.SDK_INT >= 13) { String property = System.getProperties().getProperty("http.proxyHost"); String property2 = System.getProperties().getProperty("http.proxyPort"); if (!TextUtils.isEmpty(property2)) { try { i = Integer.parseInt(property2); str2 = property; } catch (Throwable unused) { a.a(); } } i = -1; str2 = property; } else { String host = Proxy.getHost(context); i = Proxy.getPort(context); str2 = host; } if (str2 == 0 || i <= 0) { httpURLConnection = (HttpURLConnection) url.openConnection(); } else { httpURLConnection = (HttpURLConnection) url.openConnection(new java.net.Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(str2, i))); } httpURLConnection2 = httpURLConnection; httpURLConnection2.setConnectTimeout(10000); httpURLConnection2.connect(); if (Constants.HTTPS.equalsIgnoreCase(url.getProtocol())) { String a = a((HttpsURLConnection) httpURLConnection2); if (httpURLConnection2 != null) { httpURLConnection2.disconnect(); } return a; } if (httpURLConnection2 == null) { return ""; } return ""; } }