CarrotChat v2.8.60.240131版本的 MD5 值为:2baf8b9f31830b86b5c5a85ae6b47e05
以下内容为反编译后的 HttpURLTools.java 源代码,内容仅作参考
package ak.im.utils;
import ak.im.BuildConfig;
import ak.im.module.AkeyChatX509PrivateCA;
import ak.im.sdk.manager.XMPPConnectionManager;
import ak.im.sdk.manager.ye;
import ak.im.uitls.AKCAppConfiguration;
import android.os.Build;
import android.os.SystemClock;
import android.text.TextUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.qiniu.android.dns.NetworkInfo;
import com.zerotier.libzt.ZeroTierSocketFactory;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import okhttp3.a0;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.y;
import org.apache.http.protocol.HTTP;
import org.conscrypt.OpenSSLContextImpl;
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.util.TLSUtils;
import org.jivesoftware.smackx.ping.PingManager;
public class HttpURLTools {
private static Map<String, AkeyChatX509PrivateCA> f3604b;
public static HostnameVerifier a = new HostnameVerifier() {
@Override
public final boolean verify(String str, SSLSession sSLSession) {
return HttpURLTools.d(str, sSLSession);
}
};
private static int f3605c = 0;
static X509TrustManager f3606d = new b();
private static okhttp3.k f3607e = new okhttp3.k(3, 10000, TimeUnit.MILLISECONDS);
public static HashSet<String> f = new HashSet<>();
public static HashSet<String> g = new HashSet<>();
public static HashSet<String> h = new HashSet<>();
public enum UrlType {
PublicNetworkInternalUrl,
PublicNetworkExternalUrl,
BoxNetNetworkInternalUrl
}
class a implements okhttp3.f {
final ak.worker.j0 a;
final String f3608b;
final String f3609c;
a(ak.worker.j0 j0Var, String str, String str2) {
this.a = j0Var;
this.f3608b = str;
this.f3609c = str2;
}
@Override
public void onFailure(okhttp3.e eVar, IOException iOException) {
ak.worker.j0 j0Var = this.a;
if (j0Var != null) {
j0Var.onRecvResult(false, this.f3608b, null);
}
AkeyChatUtils.logException(iOException);
}
@Override
public void onResponse(okhttp3.e eVar, okhttp3.c0 c0Var) throws IOException {
Log.i("HttpURLTools", "lwxdownload response code is " + c0Var.code());
int code = c0Var.code();
String str = null;
if (code != 200) {
if (code == 403) {
try {
JSONObject parseObject = JSON.parseObject(new String(c0Var.body().bytes()));
if (parseObject.containsKey("return_code") && parseObject.getInteger("return_code").intValue() == 50332419 && parseObject.containsKey("description")) {
str = parseObject.getString("description");
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
ak.worker.j0 j0Var = this.a;
if (j0Var != null) {
j0Var.onRecvResult(false, this.f3608b, str);
return;
}
return;
}
try {
if (this.a != null) {
Log.i("HttpURLTools", "lwxdownload start");
InputStream byteStream = c0Var.body().byteStream();
if (l4.isVaultPath(this.f3609c)) {
System.out.println("downloading and save to vault file system.");
l4.createVaultDirByFilePath(this.f3609c);
String path = l4.a.getPath(this.f3609c);
l4.deleteFile(path);
String str2 = l4.getGlobalCachePath() + "temp" + f4.getRightTime();
File file = new File(str2);
if (file.exists()) {
file.delete();
}
l4.copyFile(byteStream, str2);
l4.a.encryptFile(str2, path, (ak.im.utils.v5.b) null);
} else {
l4.createDir(new File(this.f3609c).getParentFile());
l4.write(new File(this.f3609c), byteStream);
}
Log.i("HttpURLTools", "lwxdownload success");
this.a.onRecvResult(true, this.f3608b, null);
}
} catch (Throwable th) {
th.printStackTrace();
Log.e("HttpURLTools", "lwxdownload onResponse failed,error is " + th.getMessage());
ak.worker.j0 j0Var2 = this.a;
if (j0Var2 != null) {
j0Var2.onRecvResult(false, this.f3608b, null);
}
}
}
}
class b implements X509TrustManager {
b() {
}
@Override
public void checkClientTrusted(X509Certificate[] x509CertificateArr, String str) {
}
@Override
public void checkServerTrusted(X509Certificate[] x509CertificateArr, String str) {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
}
public static class c implements X509TrustManager {
private X509TrustManager a;
private X509TrustManager f3610b;
public c(X509TrustManager x509TrustManager) throws NoSuchAlgorithmException, KeyStoreException {
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);
this.a = HttpURLTools.b(trustManagerFactory.getTrustManagers());
this.f3610b = x509TrustManager;
}
@Override
public void checkClientTrusted(X509Certificate[] x509CertificateArr, String str) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] x509CertificateArr, String str) throws CertificateException {
try {
this.a.checkServerTrusted(x509CertificateArr, str);
} catch (CertificateException unused) {
X509TrustManager x509TrustManager = this.f3610b;
if (x509TrustManager != null) {
x509TrustManager.checkServerTrusted(x509CertificateArr, str);
}
}
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
}
public static class d implements okhttp3.q {
com.qiniu.android.dns.a f3611b = new com.qiniu.android.dns.a(NetworkInfo.f13435b, new com.qiniu.android.dns.c[]{new com.qiniu.android.dns.g.e("223.5.5.5"), new com.qiniu.android.dns.g.e("8.8.8.8"), new com.qiniu.android.dns.g.f("https://dns.alidns.com/dns-query")});
@Override
public List<InetAddress> lookup(String str) throws UnknownHostException {
try {
Long valueOf = Long.valueOf(System.currentTimeMillis());
List<InetAddress> asList = Arrays.asList(this.f3611b.queryInetAdress(new com.qiniu.android.dns.b(str)));
Log.e("OkHttpDns", "inetAddresses:" + asList + ", for " + str + ", elapsed " + String.valueOf(System.currentTimeMillis() - valueOf.longValue()));
return asList;
} catch (IOException e2) {
e2.printStackTrace();
return okhttp3.q.a.lookup(str);
}
}
}
public static class e {
public SSLSocketFactory a;
public X509TrustManager f3612b;
}
public static class g implements X509TrustManager {
@Override
public void checkClientTrusted(X509Certificate[] x509CertificateArr, String str) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] x509CertificateArr, String str) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
}
public static X509TrustManager b(TrustManager[] trustManagerArr) {
for (TrustManager trustManager : trustManagerArr) {
if (trustManager instanceof X509TrustManager) {
return (X509TrustManager) trustManager;
}
}
return null;
}
private static AkeyChatX509PrivateCA c(URL url) {
if (f3604b == null) {
f3604b = new HashMap();
}
String host = url.getHost();
Log.i("HttpURLTools", "x509 key:" + host + " url:" + url);
AkeyChatX509PrivateCA akeyChatX509PrivateCA = f3604b.get(host);
if (akeyChatX509PrivateCA == null) {
try {
akeyChatX509PrivateCA = new AkeyChatX509PrivateCA(url);
} catch (CertificateException e2) {
e2.printStackTrace();
}
f3604b.put(host, akeyChatX509PrivateCA);
} else {
StringBuilder sb = new StringBuilder();
sb.append("we save one:");
int i = f3605c;
f3605c = i + 1;
sb.append(i);
Log.i("HttpURLTools", sb.toString());
}
return akeyChatX509PrivateCA;
}
public static boolean canOpenUrl() {
XMPPConnectionManager.a aVar = XMPPConnectionManager.a;
AbstractXMPPConnection connection = aVar.getInstance().getConnection();
if (connection != null && connection.isConnected() && connection.isAuthenticated()) {
try {
return PingManager.getInstanceFor(aVar.getInstance().getConnection()).pingMyServer(false, 5000L);
} catch (InterruptedException e2) {
e2.printStackTrace();
return false;
} catch (SmackException.NotConnectedException e3) {
e3.printStackTrace();
return false;
}
}
return false;
}
public static UrlType checkHttpUrlType(String str) {
boolean z;
if (n5.isEmptyString(str)) {
return UrlType.PublicNetworkExternalUrl;
}
if (g.size() == 0) {
initOssServerHosts(null);
}
boolean z2 = false;
try {
String host = new URL(str).getHost();
Log.i("HttpURLTools", "check host " + host + " with main servers: " + f + ", oss servers: " + g + ", id nodes: " + h);
z = f.contains(host);
try {
if (!g.contains(host)) {
}
z2 = true;
} catch (MalformedURLException e2) {
e = e2;
AkeyChatUtils.logException(e);
if (z2) {
}
}
} catch (MalformedURLException e3) {
e = e3;
z = false;
}
if (z2) {
if (z) {
return UrlType.PublicNetworkInternalUrl;
}
return UrlType.PublicNetworkExternalUrl;
}
return UrlType.PublicNetworkInternalUrl;
}
public static boolean d(String str, SSLSession sSLSession) {
return true;
}
public static byte[] getBytesFromHttpsUrl(String str, int i, String str2, String str3) {
return getBytesFromOkHttpsUrl(str, i, null, str2, str3);
}
public static byte[] getBytesFromOkHttpsUrl(String str, int i, ak.worker.j0 j0Var, String str2, String str3) {
SystemClock.uptimeMillis();
try {
y.b okHttpClientBuilder = getOkHttpClientBuilder(str, str2, false);
if (j0Var != null) {
Iterator<okhttp3.v> it = okHttpClientBuilder.interceptors().iterator();
while (it.hasNext()) {
if (it.next() instanceof ak.i.n) {
it.remove();
}
}
okHttpClientBuilder.addInterceptor(new ak.i.n(j0Var, str));
}
y.b readTimeout = okHttpClientBuilder.retryOnConnectionFailure(true).connectTimeout(10L, TimeUnit.SECONDS).readTimeout(i, TimeUnit.MILLISECONDS);
if (AKCAppConfiguration.a.CanDnsResolve()) {
readTimeout.dns(new d());
}
okhttp3.c0 execute = readTimeout.build().newCall(setHeadIfSeaweed(str, new a0.a().url(str), str3)).execute();
if (j0Var != null) {
j0Var.onRecvResult(true, str, null);
}
Log.i("HttpURLTools", "response code is " + execute.code());
execute.body().contentLength();
if (execute.code() == 200) {
return execute.body().bytes();
}
return null;
} catch (Exception e2) {
AkeyChatUtils.logException(e2);
return null;
}
}
public static void getBytesFromOkHttpsUrlAsync(String str, String str2, int i, ak.worker.j0 j0Var, String str3, String str4) {
SystemClock.uptimeMillis();
y.b okHttpClientBuilder = getOkHttpClientBuilder(str2, str4, false);
try {
List<okhttp3.v> interceptors = okHttpClientBuilder.interceptors();
Iterator<okhttp3.v> it = okHttpClientBuilder.networkInterceptors().iterator();
Iterator<okhttp3.v> it2 = interceptors.iterator();
while (it2.hasNext()) {
okhttp3.v next = it2.next();
if ((next instanceof ak.i.n) || (next instanceof HttpLoggingInterceptor)) {
it2.remove();
}
}
while (it.hasNext()) {
okhttp3.v next2 = it.next();
if ((next2 instanceof ak.i.n) || (next2 instanceof HttpLoggingInterceptor)) {
it.remove();
}
}
if (j0Var != null) {
okHttpClientBuilder.addNetworkInterceptor(new ak.i.n(j0Var, str2));
}
} catch (Exception e2) {
e2.printStackTrace();
}
y.b readTimeout = okHttpClientBuilder.retryOnConnectionFailure(true).connectTimeout(10L, TimeUnit.SECONDS).readTimeout(i, TimeUnit.MILLISECONDS);
if (AKCAppConfiguration.a.CanDnsResolve()) {
readTimeout.dns(new d());
}
readTimeout.build().newCall(setHeadIfSeaweed(str2, new a0.a().url(str2), str)).enqueue(new a(j0Var, str2, str3));
}
public static InputStream getInputStreamFromOkHttpsUrl(String str, int i, String str2, String str3) {
try {
y.b readTimeout = getOkHttpClientBuilder(str, str2, false).retryOnConnectionFailure(true).connectTimeout(10L, TimeUnit.SECONDS).readTimeout(i, TimeUnit.MILLISECONDS);
if (AKCAppConfiguration.a.CanDnsResolve()) {
readTimeout.dns(new d());
}
okhttp3.c0 execute = readTimeout.build().newCall(setHeadIfSeaweed(str, new a0.a().url(str), str3)).execute();
Log.i("HttpURLTools", "response code is " + execute.code());
if (execute.code() == 200) {
return execute.body().byteStream();
}
return null;
} catch (Exception e2) {
AkeyChatUtils.logException(e2);
return null;
}
}
public static SSLContext getNormalSSLContext(TrustManager trustManager) {
SSLContext sSLContext;
try {
TrustManager[] trustManagerArr = {trustManager};
if (Build.VERSION.SDK_INT >= 20) {
sSLContext = SSLContext.getInstance(TLSUtils.PROTO_TLSV1_2);
} else {
sSLContext = SSLContext.getInstance(TLSUtils.TLS);
}
sSLContext.init(null, trustManagerArr, new SecureRandom());
return sSLContext;
} catch (KeyManagementException | NoSuchAlgorithmException e2) {
e2.printStackTrace();
return null;
}
}
public static SSLSocketFactory getNormalSSLSocketFactory(TrustManager trustManager) {
try {
return getNormalSSLContext(trustManager).getSocketFactory();
} catch (Exception e2) {
e2.printStackTrace();
return null;
}
}
public static y.b getOkHttpClientBuilder(String str, String str2, boolean z, boolean z2) {
URL url;
boolean z3;
e eVar;
List<okhttp3.v> interceptors;
ak.i.d languageInterceptor;
y.b connectionPool = new y.b().connectionPool(f3607e);
if (z) {
url = null;
} else {
try {
url = new URL(str);
} catch (Exception e2) {
AkeyChatUtils.logException(e2);
}
}
UrlType checkHttpUrlType = checkHttpUrlType(str);
StringBuilder sb = new StringBuilder();
sb.append("build url ");
sb.append(str);
sb.append(", type ");
sb.append(checkHttpUrlType);
sb.append(z ? ", skip server cert verification" : "");
Log.i("HttpURLTools", sb.toString());
if (!z && AkeyChatUtils.oemNeedServerCertificateVerify()) {
z3 = false;
eVar = new e();
if (!z2 && checkHttpUrlType != UrlType.PublicNetworkInternalUrl && checkHttpUrlType != UrlType.BoxNetNetworkInternalUrl) {
eVar.f3612b = !z3 ? new g() : new c(null);
eVar.a = new f(getNormalSSLSocketFactory(eVar.f3612b));
connectionPool.sslSocketFactory(eVar.a, eVar.f3612b).hostnameVerifier(a);
interceptors = connectionPool.interceptors();
languageInterceptor = ak.i.d.getLanguageInterceptor();
if (interceptors != null || !interceptors.contains(languageInterceptor)) {
connectionPool.addInterceptor(languageInterceptor);
}
if (!TextUtils.isEmpty(str2)) {
ak.i.e accessTokenInterceptor = ak.i.e.getAccessTokenInterceptor(str2);
if (interceptors == null || !interceptors.contains(accessTokenInterceptor)) {
connectionPool.addInterceptor(accessTokenInterceptor);
}
}
if (ye.getInstance().getServer() != null) {
String enterpriseId = ye.getInstance().getServer().getEnterpriseId();
if (!TextUtils.isEmpty(enterpriseId)) {
Log.i("HttpURLTools", "ADD X-AK-Server-ID:" + enterpriseId);
ak.i.c xServerIDInterceptor = ak.i.c.getXServerIDInterceptor(enterpriseId);
if (interceptors == null || !interceptors.contains(xServerIDInterceptor)) {
connectionPool.addInterceptor(xServerIDInterceptor);
}
}
}
if (str != null && ((str.contains(ye.getInstance().getOssCenterHost()) || str.contains(ye.getCountServerURL())) && AKCAppConfiguration.a.CanDnsResolve())) {
connectionPool.dns(new d());
}
return connectionPool;
}
X509TrustManager c2 = c(url);
eVar.f3612b = c2;
OpenSSLContextImpl.TLSv13 tLSv13 = new OpenSSLContextImpl.TLSv13();
tLSv13.engineInit(null, new TrustManager[]{eVar.f3612b}, null);
eVar.a = tLSv13.engineGetSocketFactory();
if (checkHttpUrlType == UrlType.BoxNetNetworkInternalUrl) {
connectionPool.socketFactory(new ZeroTierSocketFactory(false));
}
connectionPool.sslSocketFactory(eVar.a, eVar.f3612b).hostnameVerifier(a);
interceptors = connectionPool.interceptors();
languageInterceptor = ak.i.d.getLanguageInterceptor();
if (interceptors != null) {
}
connectionPool.addInterceptor(languageInterceptor);
if (!TextUtils.isEmpty(str2)) {
}
if (ye.getInstance().getServer() != null) {
}
if (str != null) {
connectionPool.dns(new d());
}
return connectionPool;
}
z3 = true;
eVar = new e();
if (!z2) {
eVar.f3612b = !z3 ? new g() : new c(null);
eVar.a = new f(getNormalSSLSocketFactory(eVar.f3612b));
connectionPool.sslSocketFactory(eVar.a, eVar.f3612b).hostnameVerifier(a);
interceptors = connectionPool.interceptors();
languageInterceptor = ak.i.d.getLanguageInterceptor();
if (interceptors != null) {
}
connectionPool.addInterceptor(languageInterceptor);
if (!TextUtils.isEmpty(str2)) {
}
if (ye.getInstance().getServer() != null) {
}
if (str != null) {
}
return connectionPool;
}
X509TrustManager c22 = c(url);
eVar.f3612b = c22;
OpenSSLContextImpl.TLSv13 tLSv132 = new OpenSSLContextImpl.TLSv13();
tLSv132.engineInit(null, new TrustManager[]{eVar.f3612b}, null);
eVar.a = tLSv132.engineGetSocketFactory();
if (checkHttpUrlType == UrlType.BoxNetNetworkInternalUrl) {
}
connectionPool.sslSocketFactory(eVar.a, eVar.f3612b).hostnameVerifier(a);
interceptors = connectionPool.interceptors();
languageInterceptor = ak.i.d.getLanguageInterceptor();
if (interceptors != null) {
}
connectionPool.addInterceptor(languageInterceptor);
if (!TextUtils.isEmpty(str2)) {
}
if (ye.getInstance().getServer() != null) {
}
if (str != null) {
}
return connectionPool;
}
public static SSLContext getSSLContext(String str, boolean z) {
SSLContext sSLContext;
SSLContext sSLContext2;
TrustManager[] trustManagerArr;
try {
URL url = !TextUtils.isEmpty(str) ? new URL(str) : null;
if (!(!z || AkeyChatUtils.isNeedVerifyCertificate(url))) {
trustManagerArr = new TrustManager[]{f3606d};
sSLContext2 = SSLContext.getInstance(TLSUtils.TLS);
} else {
if (Build.VERSION.SDK_INT >= 20) {
sSLContext = SSLContext.getInstance(TLSUtils.PROTO_TLSV1_2);
} else {
sSLContext = SSLContext.getInstance(TLSUtils.TLS);
}
sSLContext2 = sSLContext;
trustManagerArr = new TrustManager[]{c(url)};
}
sSLContext2.init(null, trustManagerArr, new SecureRandom());
return sSLContext2;
} catch (MalformedURLException e2) {
e2.printStackTrace();
return null;
} catch (KeyManagementException e3) {
e3.printStackTrace();
return null;
} catch (NoSuchAlgorithmException e4) {
e4.printStackTrace();
return null;
}
}
public static SSLSocketFactory getSSLSocketFactory(String str) {
try {
return getSSLContext(str, false).getSocketFactory();
} catch (Exception e2) {
e2.printStackTrace();
return null;
}
}
public static void initIdNodeHosts(String str) {
if (n5.isEmptyString(str)) {
return;
}
h.add(str);
Log.i("HttpURLTools", "id nodes updated: " + h);
}
public static void initMainServerHosts(String str) {
if (n5.isEmptyString(str)) {
return;
}
f.add(str);
Log.i("HttpURLTools", "main servers updated: " + f);
}
public static void initOssServerHosts(String str) {
g.add("enterprise.akeychat.cn:20443".split(":")[0]);
g.add(BuildConfig.OSS_CENTER_HOST.split(":")[0]);
g.add("statistical.akeychat.cn");
g.add("teststatistical.akeychat.cn");
HashSet<String> hashSet = g;
AKCAppConfiguration aKCAppConfiguration = AKCAppConfiguration.a;
hashSet.add(aKCAppConfiguration.stats());
String stats2 = aKCAppConfiguration.stats2();
HashSet<String> hashSet2 = g;
if (stats2.contains(":")) {
stats2 = stats2.split(":")[0];
}
hashSet2.add(stats2);
g.add(aKCAppConfiguration.oss());
if (str != null) {
g.add(str);
}
Log.i("HttpURLTools", "oss servers updated: " + g);
}
public static KeyManager[] prepareKeyManager(InputStream inputStream, String str) {
if (inputStream != null && str != null) {
try {
KeyStore keyStore = KeyStore.getInstance("BKS");
keyStore.load(inputStream, str.toCharArray());
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, str.toCharArray());
return keyManagerFactory.getKeyManagers();
} catch (IOException e2) {
e2.printStackTrace();
} catch (KeyStoreException e3) {
e3.printStackTrace();
} catch (NoSuchAlgorithmException e4) {
e4.printStackTrace();
} catch (UnrecoverableKeyException e5) {
e5.printStackTrace();
} catch (CertificateException e6) {
e6.printStackTrace();
} catch (Exception e7) {
e7.printStackTrace();
}
}
return null;
}
public static String printResponse(HttpURLConnection httpURLConnection) {
StringBuilder sb = new StringBuilder();
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
sb.append("\n" + readLine);
}
} catch (IOException e2) {
e2.printStackTrace();
}
return sb.toString();
}
public static String sendHttpsPost(String str, String str2) {
?? url;
BufferedReader bufferedReader;
Log.i("HttpURLTools", "https post url:" + str);
Log.i("HttpURLTools", "https post data:" + ((String) str2));
String str3 = "";
PrintWriter printWriter = null;
r1 = null;
r1 = null;
r1 = null;
StringBuilder sb = null;
printWriter = null;
try {
try {
url = new URL(str);
} catch (IOException e2) {
e2.printStackTrace();
}
} catch (Exception e3) {
e = e3;
str2 = 0;
} catch (Throwable th) {
th = th;
str2 = 0;
}
try {
try {
if (str.startsWith("https")) {
c(url);
HttpsURLConnection.setDefaultSSLSocketFactory(getSSLContext(str, false).getSocketFactory());
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
httpsURLConnection.setRequestProperty("accept", "*/*");
httpsURLConnection.setRequestProperty("connection", HTTP.CONN_KEEP_ALIVE);
httpsURLConnection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
httpsURLConnection.setDoOutput(true);
httpsURLConnection.setDoInput(true);
url = new PrintWriter(httpsURLConnection.getOutputStream());
url.print(str2);
url.flush();
bufferedReader = new BufferedReader(new InputStreamReader(httpsURLConnection.getInputStream()));
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
sb = new StringBuilder();
sb.append(str3);
sb.append(readLine);
str3 = sb.toString();
}
} else {
URLConnection openConnection = url.openConnection();
openConnection.setRequestProperty("accept", "*/*");
openConnection.setRequestProperty("connection", HTTP.CONN_KEEP_ALIVE);
openConnection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
openConnection.setDoOutput(true);
openConnection.setDoInput(true);
url = new PrintWriter(openConnection.getOutputStream());
url.print(str2);
url.flush();
bufferedReader = new BufferedReader(new InputStreamReader(openConnection.getInputStream()));
while (true) {
String readLine2 = bufferedReader.readLine();
if (readLine2 == null) {
break;
}
sb = new StringBuilder();
sb.append(str3);
sb.append(readLine2);
str3 = sb.toString();
}
}
url.close();
bufferedReader.close();
} catch (Exception e4) {
e = e4;
printWriter = url;
str2 = str2;
try {
e.printStackTrace();
if (printWriter != null) {
printWriter.close();
}
if (str2 != 0) {
str2.close();
}
return str3;
} catch (Throwable th2) {
th = th2;
if (printWriter != null) {
try {
printWriter.close();
} catch (IOException e5) {
e5.printStackTrace();
throw th;
}
}
if (str2 != 0) {
str2.close();
}
throw th;
}
} catch (Throwable th3) {
th = th3;
printWriter = url;
if (printWriter != null) {
}
if (str2 != 0) {
}
throw th;
}
} catch (Exception e6) {
e = e6;
str2 = sb;
printWriter = url;
str2 = str2;
e.printStackTrace();
if (printWriter != null) {
}
if (str2 != 0) {
}
return str3;
} catch (Throwable th4) {
th = th4;
str2 = sb;
printWriter = url;
if (printWriter != null) {
}
if (str2 != 0) {
}
throw th;
}
return str3;
}
public static okhttp3.a0 setHeadIfSeaweed(String str, a0.a aVar, String str2) {
if (!TextUtils.isEmpty(str) && str.contains("/app/seaweedfsdownload") && !TextUtils.isEmpty(str2)) {
aVar.header("X-Server-Id", str2);
aVar.header("X-Authentication-Id", ye.getInstance().getServer().getEnterpriseId());
}
return aVar.build();
}
public static class f extends SSLSocketFactory {
private static String[] a;
final SSLSocketFactory f3613b;
static {
int i = Build.VERSION.SDK_INT;
if (i >= 26) {
a = new String[]{TLSUtils.PROTO_TLSV1, TLSUtils.PROTO_TLSV1_1, TLSUtils.PROTO_TLSV1_2};
} else if (i >= 16) {
a = new String[]{TLSUtils.PROTO_SSL3, TLSUtils.PROTO_TLSV1, TLSUtils.PROTO_TLSV1_1, TLSUtils.PROTO_TLSV1_2};
} else {
a = new String[]{TLSUtils.PROTO_SSL3, TLSUtils.PROTO_TLSV1};
}
}
public f(SSLSocketFactory sSLSocketFactory) {
this.f3613b = sSLSocketFactory;
}
private Socket a(Socket socket) {
if (socket instanceof SSLSocket) {
((SSLSocket) socket).setEnabledProtocols(a);
}
return socket;
}
@Override
public Socket createSocket(Socket socket, String str, int i, boolean z) throws IOException {
Log.w("Tls12SocketFactory", "create socket " + socket + " sock type " + socket.getClass() + ", connected " + socket.isConnected() + ", " + str + ", " + i + ", " + z);
return a(this.f3613b.createSocket(socket, str, i, z));
}
@Override
public String[] getDefaultCipherSuites() {
return this.f3613b.getDefaultCipherSuites();
}
@Override
public String[] getSupportedCipherSuites() {
return this.f3613b.getSupportedCipherSuites();
}
@Override
public Socket createSocket(String str, int i) throws IOException, UnknownHostException {
Log.w("Tls12SocketFactory", "1create socket " + str + ", " + i);
return a(this.f3613b.createSocket(str, i));
}
@Override
public Socket createSocket(String str, int i, InetAddress inetAddress, int i2) throws IOException, UnknownHostException {
Log.w("Tls12SocketFactory", "create socket " + str + ", " + i + ", " + inetAddress + ", " + i2);
return a(this.f3613b.createSocket(str, i, inetAddress, i2));
}
@Override
public Socket createSocket(InetAddress inetAddress, int i) throws IOException {
Log.w("Tls12SocketFactory", "create socket " + inetAddress + ", " + i);
return a(this.f3613b.createSocket(inetAddress, i));
}
@Override
public Socket createSocket(InetAddress inetAddress, int i, InetAddress inetAddress2, int i2) throws IOException {
Log.w("Tls12SocketFactory", "create socket " + inetAddress + ", " + i + ", " + inetAddress2 + ", " + i2);
return a(this.f3613b.createSocket(inetAddress, i, inetAddress2, i2));
}
}
public static y.b getOkHttpClientBuilder(String str, String str2, boolean z) {
return getOkHttpClientBuilder(str, str2, z, false);
}
}