Initial commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package io.fabric.sdk.android.services.network;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.LinkedList;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
final class CertificateChainCleaner {
|
||||
public static X509Certificate[] a(X509Certificate[] x509CertificateArr, SystemKeyStore systemKeyStore) throws CertificateException {
|
||||
LinkedList linkedList = new LinkedList();
|
||||
boolean b = systemKeyStore.b(x509CertificateArr[0]);
|
||||
linkedList.add(x509CertificateArr[0]);
|
||||
boolean z = true;
|
||||
boolean z2 = b;
|
||||
int i = 1;
|
||||
while (i < x509CertificateArr.length) {
|
||||
if (systemKeyStore.b(x509CertificateArr[i])) {
|
||||
z2 = true;
|
||||
}
|
||||
if (!a(x509CertificateArr[i], x509CertificateArr[i - 1])) {
|
||||
break;
|
||||
}
|
||||
linkedList.add(x509CertificateArr[i]);
|
||||
i++;
|
||||
}
|
||||
X509Certificate a = systemKeyStore.a(x509CertificateArr[i - 1]);
|
||||
if (a != null) {
|
||||
linkedList.add(a);
|
||||
} else {
|
||||
z = z2;
|
||||
}
|
||||
if (z) {
|
||||
return (X509Certificate[]) linkedList.toArray(new X509Certificate[linkedList.size()]);
|
||||
}
|
||||
throw new CertificateException("Didn't find a trust anchor in chain cleanup!");
|
||||
}
|
||||
|
||||
private static boolean a(X509Certificate x509Certificate, X509Certificate x509Certificate2) {
|
||||
if (!x509Certificate.getSubjectX500Principal().equals(x509Certificate2.getIssuerX500Principal())) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
x509Certificate2.verify(x509Certificate.getPublicKey());
|
||||
return true;
|
||||
} catch (GeneralSecurityException unused) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
package io.fabric.sdk.android.services.network;
|
||||
|
||||
import io.fabric.sdk.android.DefaultLogger;
|
||||
import io.fabric.sdk.android.Logger;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class DefaultHttpRequestFactory implements HttpRequestFactory {
|
||||
private final Logger a;
|
||||
private PinningInfoProvider b;
|
||||
private SSLSocketFactory c;
|
||||
private boolean d;
|
||||
|
||||
/* renamed from: io.fabric.sdk.android.services.network.DefaultHttpRequestFactory$1, reason: invalid class name */
|
||||
static /* synthetic */ class AnonymousClass1 {
|
||||
static final /* synthetic */ int[] a = new int[HttpMethod.values().length];
|
||||
|
||||
static {
|
||||
try {
|
||||
a[HttpMethod.GET.ordinal()] = 1;
|
||||
} catch (NoSuchFieldError unused) {
|
||||
}
|
||||
try {
|
||||
a[HttpMethod.POST.ordinal()] = 2;
|
||||
} catch (NoSuchFieldError unused2) {
|
||||
}
|
||||
try {
|
||||
a[HttpMethod.PUT.ordinal()] = 3;
|
||||
} catch (NoSuchFieldError unused3) {
|
||||
}
|
||||
try {
|
||||
a[HttpMethod.DELETE.ordinal()] = 4;
|
||||
} catch (NoSuchFieldError unused4) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DefaultHttpRequestFactory() {
|
||||
this(new DefaultLogger());
|
||||
}
|
||||
|
||||
private synchronized SSLSocketFactory b() {
|
||||
SSLSocketFactory a;
|
||||
this.d = true;
|
||||
try {
|
||||
a = NetworkUtils.a(this.b);
|
||||
this.a.d("Fabric", "Custom SSL pinning enabled");
|
||||
} catch (Exception e) {
|
||||
this.a.b("Fabric", "Exception while validating pinned certs", e);
|
||||
return null;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
@Override // io.fabric.sdk.android.services.network.HttpRequestFactory
|
||||
public HttpRequest a(HttpMethod httpMethod, String str, Map<String, String> map) {
|
||||
HttpRequest a;
|
||||
SSLSocketFactory a2;
|
||||
int i = AnonymousClass1.a[httpMethod.ordinal()];
|
||||
if (i == 1) {
|
||||
a = HttpRequest.a((CharSequence) str, (Map<?, ?>) map, true);
|
||||
} else if (i == 2) {
|
||||
a = HttpRequest.b((CharSequence) str, (Map<?, ?>) map, true);
|
||||
} else if (i == 3) {
|
||||
a = HttpRequest.f((CharSequence) str);
|
||||
} else {
|
||||
if (i != 4) {
|
||||
throw new IllegalArgumentException("Unsupported HTTP method!");
|
||||
}
|
||||
a = HttpRequest.b((CharSequence) str);
|
||||
}
|
||||
if (a(str) && this.b != null && (a2 = a()) != null) {
|
||||
((HttpsURLConnection) a.j()).setSSLSocketFactory(a2);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
public DefaultHttpRequestFactory(Logger logger) {
|
||||
this.a = logger;
|
||||
}
|
||||
|
||||
private boolean a(String str) {
|
||||
return str != null && str.toLowerCase(Locale.US).startsWith("https");
|
||||
}
|
||||
|
||||
private synchronized SSLSocketFactory a() {
|
||||
if (this.c == null && !this.d) {
|
||||
this.c = b();
|
||||
}
|
||||
return this.c;
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
package io.fabric.sdk.android.services.network;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public enum HttpMethod {
|
||||
GET,
|
||||
POST,
|
||||
PUT,
|
||||
DELETE
|
||||
}
|
698
sources/io/fabric/sdk/android/services/network/HttpRequest.java
Normal file
698
sources/io/fabric/sdk/android/services/network/HttpRequest.java
Normal file
@@ -0,0 +1,698 @@
|
||||
package io.fabric.sdk.android.services.network;
|
||||
|
||||
import com.ubt.jimu.unity.bluetooth.UnityActivity;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.Flushable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.Proxy;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CharsetEncoder;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class HttpRequest {
|
||||
private static ConnectionFactory k = ConnectionFactory.a;
|
||||
public final URL b;
|
||||
private final String c;
|
||||
private RequestOutputStream d;
|
||||
private boolean e;
|
||||
private String i;
|
||||
private int j;
|
||||
private HttpURLConnection a = null;
|
||||
private boolean f = true;
|
||||
private boolean g = false;
|
||||
private int h = UnityActivity.BLOCKLY_TYPE_NONE;
|
||||
|
||||
protected static abstract class CloseOperation<V> extends Operation<V> {
|
||||
private final Closeable a;
|
||||
private final boolean b;
|
||||
|
||||
protected CloseOperation(Closeable closeable, boolean z) {
|
||||
this.a = closeable;
|
||||
this.b = z;
|
||||
}
|
||||
|
||||
@Override // io.fabric.sdk.android.services.network.HttpRequest.Operation
|
||||
protected void a() throws IOException {
|
||||
Closeable closeable = this.a;
|
||||
if (closeable instanceof Flushable) {
|
||||
((Flushable) closeable).flush();
|
||||
}
|
||||
if (!this.b) {
|
||||
this.a.close();
|
||||
} else {
|
||||
try {
|
||||
this.a.close();
|
||||
} catch (IOException unused) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface ConnectionFactory {
|
||||
public static final ConnectionFactory a = new ConnectionFactory() { // from class: io.fabric.sdk.android.services.network.HttpRequest.ConnectionFactory.1
|
||||
@Override // io.fabric.sdk.android.services.network.HttpRequest.ConnectionFactory
|
||||
public HttpURLConnection a(URL url) throws IOException {
|
||||
return (HttpURLConnection) url.openConnection();
|
||||
}
|
||||
|
||||
@Override // io.fabric.sdk.android.services.network.HttpRequest.ConnectionFactory
|
||||
public HttpURLConnection a(URL url, Proxy proxy) throws IOException {
|
||||
return (HttpURLConnection) url.openConnection(proxy);
|
||||
}
|
||||
};
|
||||
|
||||
HttpURLConnection a(URL url) throws IOException;
|
||||
|
||||
HttpURLConnection a(URL url, Proxy proxy) throws IOException;
|
||||
}
|
||||
|
||||
public static class HttpRequestException extends RuntimeException {
|
||||
private static final long serialVersionUID = -1170466989781746231L;
|
||||
|
||||
protected HttpRequestException(IOException iOException) {
|
||||
super(iOException);
|
||||
}
|
||||
|
||||
@Override // java.lang.Throwable
|
||||
public IOException getCause() {
|
||||
return (IOException) super.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
protected static abstract class Operation<V> implements Callable<V> {
|
||||
protected Operation() {
|
||||
}
|
||||
|
||||
protected abstract void a() throws IOException;
|
||||
|
||||
protected abstract V b() throws HttpRequestException, IOException;
|
||||
|
||||
@Override // java.util.concurrent.Callable
|
||||
public V call() throws HttpRequestException {
|
||||
Throwable th;
|
||||
boolean z = true;
|
||||
try {
|
||||
try {
|
||||
V b = b();
|
||||
try {
|
||||
a();
|
||||
return b;
|
||||
} catch (IOException e) {
|
||||
throw new HttpRequestException(e);
|
||||
}
|
||||
} catch (HttpRequestException e2) {
|
||||
throw e2;
|
||||
} catch (IOException e3) {
|
||||
throw new HttpRequestException(e3);
|
||||
} catch (Throwable th2) {
|
||||
th = th2;
|
||||
z = false;
|
||||
try {
|
||||
a();
|
||||
} catch (IOException e4) {
|
||||
if (!z) {
|
||||
throw new HttpRequestException(e4);
|
||||
}
|
||||
}
|
||||
throw th;
|
||||
}
|
||||
} catch (Throwable th3) {
|
||||
th = th3;
|
||||
a();
|
||||
throw th;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class RequestOutputStream extends BufferedOutputStream {
|
||||
private final CharsetEncoder a;
|
||||
|
||||
public RequestOutputStream(OutputStream outputStream, String str, int i) {
|
||||
super(outputStream, i);
|
||||
this.a = Charset.forName(HttpRequest.f(str)).newEncoder();
|
||||
}
|
||||
|
||||
public RequestOutputStream a(String str) throws IOException {
|
||||
ByteBuffer encode = this.a.encode(CharBuffer.wrap(str));
|
||||
super.write(encode.array(), 0, encode.limit());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public HttpRequest(CharSequence charSequence, String str) throws HttpRequestException {
|
||||
try {
|
||||
this.b = new URL(charSequence.toString());
|
||||
this.c = str;
|
||||
} catch (MalformedURLException e) {
|
||||
throw new HttpRequestException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static StringBuilder b(String str, StringBuilder sb) {
|
||||
if (str.indexOf(58) + 2 == str.lastIndexOf(47)) {
|
||||
sb.append('/');
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
|
||||
public static String c(CharSequence charSequence) throws HttpRequestException {
|
||||
int i;
|
||||
try {
|
||||
URL url = new URL(charSequence.toString());
|
||||
String host = url.getHost();
|
||||
int port = url.getPort();
|
||||
if (port != -1) {
|
||||
host = host + ':' + Integer.toString(port);
|
||||
}
|
||||
try {
|
||||
String aSCIIString = new URI(url.getProtocol(), host, url.getPath(), url.getQuery(), null).toASCIIString();
|
||||
int indexOf = aSCIIString.indexOf(63);
|
||||
if (indexOf <= 0 || (i = indexOf + 1) >= aSCIIString.length()) {
|
||||
return aSCIIString;
|
||||
}
|
||||
return aSCIIString.substring(0, i) + aSCIIString.substring(i).replace("+", "%2B");
|
||||
} catch (URISyntaxException e) {
|
||||
IOException iOException = new IOException("Parsing URI failed");
|
||||
iOException.initCause(e);
|
||||
throw new HttpRequestException(iOException);
|
||||
}
|
||||
} catch (IOException e2) {
|
||||
throw new HttpRequestException(e2);
|
||||
}
|
||||
}
|
||||
|
||||
public static HttpRequest d(CharSequence charSequence) throws HttpRequestException {
|
||||
return new HttpRequest(charSequence, "GET");
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public static String f(String str) {
|
||||
return (str == null || str.length() <= 0) ? "UTF-8" : str;
|
||||
}
|
||||
|
||||
private HttpURLConnection p() {
|
||||
try {
|
||||
HttpURLConnection a = this.i != null ? k.a(this.b, q()) : k.a(this.b);
|
||||
a.setRequestMethod(this.c);
|
||||
return a;
|
||||
} catch (IOException e) {
|
||||
throw new HttpRequestException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private Proxy q() {
|
||||
return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(this.i, this.j));
|
||||
}
|
||||
|
||||
public int g() throws HttpRequestException {
|
||||
try {
|
||||
e();
|
||||
return j().getResponseCode();
|
||||
} catch (IOException e) {
|
||||
throw new HttpRequestException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String h() {
|
||||
return c("Content-Encoding");
|
||||
}
|
||||
|
||||
public int i() {
|
||||
return d("Content-Length");
|
||||
}
|
||||
|
||||
public HttpURLConnection j() {
|
||||
if (this.a == null) {
|
||||
this.a = p();
|
||||
}
|
||||
return this.a;
|
||||
}
|
||||
|
||||
public String k() {
|
||||
return j().getRequestMethod();
|
||||
}
|
||||
|
||||
protected HttpRequest l() throws IOException {
|
||||
if (this.d != null) {
|
||||
return this;
|
||||
}
|
||||
j().setDoOutput(true);
|
||||
this.d = new RequestOutputStream(j().getOutputStream(), b(j().getRequestProperty("Content-Type"), "charset"), this.h);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected HttpRequest m() throws IOException {
|
||||
if (this.e) {
|
||||
this.d.a("\r\n--00content0boundary00\r\n");
|
||||
} else {
|
||||
this.e = true;
|
||||
b("multipart/form-data; boundary=00content0boundary00");
|
||||
l();
|
||||
this.d.a("--00content0boundary00\r\n");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public InputStream n() throws HttpRequestException {
|
||||
InputStream inputStream;
|
||||
if (g() < 400) {
|
||||
try {
|
||||
inputStream = j().getInputStream();
|
||||
} catch (IOException e) {
|
||||
throw new HttpRequestException(e);
|
||||
}
|
||||
} else {
|
||||
inputStream = j().getErrorStream();
|
||||
if (inputStream == null) {
|
||||
try {
|
||||
inputStream = j().getInputStream();
|
||||
} catch (IOException e2) {
|
||||
throw new HttpRequestException(e2);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!this.g || !"gzip".equals(h())) {
|
||||
return inputStream;
|
||||
}
|
||||
try {
|
||||
return new GZIPInputStream(inputStream);
|
||||
} catch (IOException e3) {
|
||||
throw new HttpRequestException(e3);
|
||||
}
|
||||
}
|
||||
|
||||
public URL o() {
|
||||
return j().getURL();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return k() + ' ' + o();
|
||||
}
|
||||
|
||||
private static StringBuilder a(String str, StringBuilder sb) {
|
||||
int indexOf = str.indexOf(63);
|
||||
int length = sb.length() - 1;
|
||||
if (indexOf == -1) {
|
||||
sb.append('?');
|
||||
} else if (indexOf < length && str.charAt(length) != '&') {
|
||||
sb.append('&');
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
|
||||
public static HttpRequest e(CharSequence charSequence) throws HttpRequestException {
|
||||
return new HttpRequest(charSequence, "POST");
|
||||
}
|
||||
|
||||
public static HttpRequest f(CharSequence charSequence) throws HttpRequestException {
|
||||
return new HttpRequest(charSequence, "PUT");
|
||||
}
|
||||
|
||||
public int d(String str) throws HttpRequestException {
|
||||
return a(str, -1);
|
||||
}
|
||||
|
||||
public static HttpRequest b(CharSequence charSequence, Map<?, ?> map, boolean z) {
|
||||
String a = a(charSequence, map);
|
||||
if (z) {
|
||||
a = c((CharSequence) a);
|
||||
}
|
||||
return e((CharSequence) a);
|
||||
}
|
||||
|
||||
public String d(String str, String str2) {
|
||||
return b(c(str), str2);
|
||||
}
|
||||
|
||||
protected HttpRequest e() throws IOException {
|
||||
RequestOutputStream requestOutputStream = this.d;
|
||||
if (requestOutputStream == null) {
|
||||
return this;
|
||||
}
|
||||
if (this.e) {
|
||||
requestOutputStream.a("\r\n--00content0boundary00--\r\n");
|
||||
}
|
||||
if (this.f) {
|
||||
try {
|
||||
this.d.close();
|
||||
} catch (IOException unused) {
|
||||
}
|
||||
} else {
|
||||
this.d.close();
|
||||
}
|
||||
this.d = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected HttpRequest f() throws HttpRequestException {
|
||||
try {
|
||||
e();
|
||||
return this;
|
||||
} catch (IOException e) {
|
||||
throw new HttpRequestException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String d() {
|
||||
return d("Content-Type", "charset");
|
||||
}
|
||||
|
||||
public static HttpRequest b(CharSequence charSequence) throws HttpRequestException {
|
||||
return new HttpRequest(charSequence, "DELETE");
|
||||
}
|
||||
|
||||
public HttpRequest f(String str, String str2) throws HttpRequestException {
|
||||
a((CharSequence) str);
|
||||
a(": ");
|
||||
a((CharSequence) str2);
|
||||
a("\r\n");
|
||||
return this;
|
||||
}
|
||||
|
||||
public BufferedInputStream b() throws HttpRequestException {
|
||||
return new BufferedInputStream(n(), this.h);
|
||||
}
|
||||
|
||||
public static String a(CharSequence charSequence, Map<?, ?> map) {
|
||||
String charSequence2 = charSequence.toString();
|
||||
if (map == null || map.isEmpty()) {
|
||||
return charSequence2;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(charSequence2);
|
||||
b(charSequence2, sb);
|
||||
a(charSequence2, sb);
|
||||
Iterator<Map.Entry<?, ?>> it = map.entrySet().iterator();
|
||||
Map.Entry<?, ?> next = it.next();
|
||||
sb.append(next.getKey().toString());
|
||||
sb.append('=');
|
||||
Object value = next.getValue();
|
||||
if (value != null) {
|
||||
sb.append(value);
|
||||
}
|
||||
while (it.hasNext()) {
|
||||
sb.append('&');
|
||||
Map.Entry<?, ?> next2 = it.next();
|
||||
sb.append(next2.getKey().toString());
|
||||
sb.append('=');
|
||||
Object value2 = next2.getValue();
|
||||
if (value2 != null) {
|
||||
sb.append(value2);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
protected String b(String str, String str2) {
|
||||
String trim;
|
||||
int length;
|
||||
if (str != null && str.length() != 0) {
|
||||
int length2 = str.length();
|
||||
int indexOf = str.indexOf(59) + 1;
|
||||
if (indexOf != 0 && indexOf != length2) {
|
||||
int indexOf2 = str.indexOf(59, indexOf);
|
||||
if (indexOf2 == -1) {
|
||||
indexOf2 = length2;
|
||||
}
|
||||
while (indexOf < indexOf2) {
|
||||
int indexOf3 = str.indexOf(61, indexOf);
|
||||
if (indexOf3 != -1 && indexOf3 < indexOf2 && str2.equals(str.substring(indexOf, indexOf3).trim()) && (length = (trim = str.substring(indexOf3 + 1, indexOf2).trim()).length()) != 0) {
|
||||
if (length > 2 && '\"' == trim.charAt(0)) {
|
||||
int i = length - 1;
|
||||
if ('\"' == trim.charAt(i)) {
|
||||
return trim.substring(1, i);
|
||||
}
|
||||
}
|
||||
return trim;
|
||||
}
|
||||
indexOf = indexOf2 + 1;
|
||||
indexOf2 = str.indexOf(59, indexOf);
|
||||
if (indexOf2 == -1) {
|
||||
indexOf2 = length2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public HttpRequest e(String str, String str2) {
|
||||
a(str, (String) null, str2);
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Base64 {
|
||||
private static final byte[] a = {65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47};
|
||||
|
||||
private static byte[] a(byte[] bArr, int i, int i2, byte[] bArr2, int i3) {
|
||||
byte[] bArr3 = a;
|
||||
int i4 = (i2 > 0 ? (bArr[i] << 24) >>> 8 : 0) | (i2 > 1 ? (bArr[i + 1] << 24) >>> 16 : 0) | (i2 > 2 ? (bArr[i + 2] << 24) >>> 24 : 0);
|
||||
if (i2 == 1) {
|
||||
bArr2[i3] = bArr3[i4 >>> 18];
|
||||
bArr2[i3 + 1] = bArr3[(i4 >>> 12) & 63];
|
||||
bArr2[i3 + 2] = 61;
|
||||
bArr2[i3 + 3] = 61;
|
||||
return bArr2;
|
||||
}
|
||||
if (i2 == 2) {
|
||||
bArr2[i3] = bArr3[i4 >>> 18];
|
||||
bArr2[i3 + 1] = bArr3[(i4 >>> 12) & 63];
|
||||
bArr2[i3 + 2] = bArr3[(i4 >>> 6) & 63];
|
||||
bArr2[i3 + 3] = 61;
|
||||
return bArr2;
|
||||
}
|
||||
if (i2 != 3) {
|
||||
return bArr2;
|
||||
}
|
||||
bArr2[i3] = bArr3[i4 >>> 18];
|
||||
bArr2[i3 + 1] = bArr3[(i4 >>> 12) & 63];
|
||||
bArr2[i3 + 2] = bArr3[(i4 >>> 6) & 63];
|
||||
bArr2[i3 + 3] = bArr3[i4 & 63];
|
||||
return bArr2;
|
||||
}
|
||||
|
||||
public static byte[] b(byte[] bArr, int i, int i2) {
|
||||
if (bArr == null) {
|
||||
throw new NullPointerException("Cannot serialize a null array.");
|
||||
}
|
||||
if (i < 0) {
|
||||
throw new IllegalArgumentException("Cannot have negative offset: " + i);
|
||||
}
|
||||
if (i2 < 0) {
|
||||
throw new IllegalArgumentException("Cannot have length offset: " + i2);
|
||||
}
|
||||
if (i + i2 > bArr.length) {
|
||||
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Cannot have offset of %d and length of %d with array of length %d", Integer.valueOf(i), Integer.valueOf(i2), Integer.valueOf(bArr.length)));
|
||||
}
|
||||
byte[] bArr2 = new byte[((i2 / 3) * 4) + (i2 % 3 <= 0 ? 0 : 4)];
|
||||
int i3 = i2 - 2;
|
||||
int i4 = 0;
|
||||
int i5 = 0;
|
||||
while (i4 < i3) {
|
||||
a(bArr, i4 + i, 3, bArr2, i5);
|
||||
i4 += 3;
|
||||
i5 += 4;
|
||||
}
|
||||
if (i4 < i2) {
|
||||
a(bArr, i + i4, i2 - i4, bArr2, i5);
|
||||
i5 += 4;
|
||||
}
|
||||
if (i5 > bArr2.length - 1) {
|
||||
return bArr2;
|
||||
}
|
||||
byte[] bArr3 = new byte[i5];
|
||||
System.arraycopy(bArr2, 0, bArr3, 0, i5);
|
||||
return bArr3;
|
||||
}
|
||||
|
||||
public static String a(String str) {
|
||||
byte[] bytes;
|
||||
try {
|
||||
bytes = str.getBytes("US-ASCII");
|
||||
} catch (UnsupportedEncodingException unused) {
|
||||
bytes = str.getBytes();
|
||||
}
|
||||
return a(bytes);
|
||||
}
|
||||
|
||||
public static String a(byte[] bArr) {
|
||||
return a(bArr, 0, bArr.length);
|
||||
}
|
||||
|
||||
public static String a(byte[] bArr, int i, int i2) {
|
||||
byte[] b = b(bArr, i, i2);
|
||||
try {
|
||||
return new String(b, "US-ASCII");
|
||||
} catch (UnsupportedEncodingException unused) {
|
||||
return new String(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected ByteArrayOutputStream c() {
|
||||
int i = i();
|
||||
if (i > 0) {
|
||||
return new ByteArrayOutputStream(i);
|
||||
}
|
||||
return new ByteArrayOutputStream();
|
||||
}
|
||||
|
||||
public HttpRequest c(String str, String str2) {
|
||||
j().setRequestProperty(str, str2);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpRequest b(String str) {
|
||||
a(str, (String) null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String c(String str) throws HttpRequestException {
|
||||
f();
|
||||
return j().getHeaderField(str);
|
||||
}
|
||||
|
||||
protected HttpRequest b(String str, String str2, String str3) throws IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("form-data; name=\"");
|
||||
sb.append(str);
|
||||
if (str2 != null) {
|
||||
sb.append("\"; filename=\"");
|
||||
sb.append(str2);
|
||||
}
|
||||
sb.append('\"');
|
||||
f("Content-Disposition", sb.toString());
|
||||
if (str3 != null) {
|
||||
f("Content-Type", str3);
|
||||
}
|
||||
a("\r\n");
|
||||
return this;
|
||||
}
|
||||
|
||||
public static HttpRequest a(CharSequence charSequence, Map<?, ?> map, boolean z) {
|
||||
String a = a(charSequence, map);
|
||||
if (z) {
|
||||
a = c((CharSequence) a);
|
||||
}
|
||||
return d((CharSequence) a);
|
||||
}
|
||||
|
||||
public String a(String str) throws HttpRequestException {
|
||||
ByteArrayOutputStream c = c();
|
||||
try {
|
||||
a(b(), c);
|
||||
return c.toString(f(str));
|
||||
} catch (IOException e) {
|
||||
throw new HttpRequestException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String a() throws HttpRequestException {
|
||||
return a(d());
|
||||
}
|
||||
|
||||
public HttpRequest a(int i) {
|
||||
j().setConnectTimeout(i);
|
||||
return this;
|
||||
}
|
||||
|
||||
public int a(String str, int i) throws HttpRequestException {
|
||||
f();
|
||||
return j().getHeaderFieldInt(str, i);
|
||||
}
|
||||
|
||||
public HttpRequest a(boolean z) {
|
||||
j().setUseCaches(z);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpRequest a(String str, String str2) {
|
||||
if (str2 != null && str2.length() > 0) {
|
||||
c("Content-Type", str + "; charset=" + str2);
|
||||
return this;
|
||||
}
|
||||
c("Content-Type", str);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected HttpRequest a(final InputStream inputStream, final OutputStream outputStream) throws IOException {
|
||||
return new CloseOperation<HttpRequest>(inputStream, this.f) { // from class: io.fabric.sdk.android.services.network.HttpRequest.6
|
||||
@Override // io.fabric.sdk.android.services.network.HttpRequest.Operation
|
||||
public HttpRequest b() throws IOException {
|
||||
byte[] bArr = new byte[HttpRequest.this.h];
|
||||
while (true) {
|
||||
int read = inputStream.read(bArr);
|
||||
if (read == -1) {
|
||||
return HttpRequest.this;
|
||||
}
|
||||
outputStream.write(bArr, 0, read);
|
||||
}
|
||||
}
|
||||
}.call();
|
||||
}
|
||||
|
||||
public HttpRequest a(String str, String str2, String str3) throws HttpRequestException {
|
||||
a(str, str2, (String) null, str3);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpRequest a(String str, String str2, String str3, String str4) throws HttpRequestException {
|
||||
try {
|
||||
m();
|
||||
b(str, str2, str3);
|
||||
this.d.a(str4);
|
||||
return this;
|
||||
} catch (IOException e) {
|
||||
throw new HttpRequestException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public HttpRequest a(String str, Number number) throws HttpRequestException {
|
||||
a(str, (String) null, number);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpRequest a(String str, String str2, Number number) throws HttpRequestException {
|
||||
a(str, str2, number != null ? number.toString() : null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpRequest a(String str, String str2, String str3, InputStream inputStream) throws HttpRequestException {
|
||||
try {
|
||||
m();
|
||||
b(str, str2, str3);
|
||||
a(inputStream, this.d);
|
||||
return this;
|
||||
} catch (IOException e) {
|
||||
throw new HttpRequestException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public HttpRequest a(CharSequence charSequence) throws HttpRequestException {
|
||||
try {
|
||||
l();
|
||||
this.d.a(charSequence.toString());
|
||||
return this;
|
||||
} catch (IOException e) {
|
||||
throw new HttpRequestException(e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package io.fabric.sdk.android.services.network;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public interface HttpRequestFactory {
|
||||
HttpRequest a(HttpMethod httpMethod, String str, Map<String, String> map);
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package io.fabric.sdk.android.services.network;
|
||||
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class NetworkUtils {
|
||||
public static final SSLSocketFactory a(PinningInfoProvider pinningInfoProvider) throws KeyManagementException, NoSuchAlgorithmException {
|
||||
SSLContext sSLContext = SSLContext.getInstance("TLS");
|
||||
sSLContext.init(null, new TrustManager[]{new PinningTrustManager(new SystemKeyStore(pinningInfoProvider.c(), pinningInfoProvider.a()), pinningInfoProvider)}, null);
|
||||
return sSLContext.getSocketFactory();
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package io.fabric.sdk.android.services.network;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public interface PinningInfoProvider {
|
||||
String a();
|
||||
|
||||
long b();
|
||||
|
||||
InputStream c();
|
||||
|
||||
String[] d();
|
||||
}
|
@@ -0,0 +1,112 @@
|
||||
package io.fabric.sdk.android.services.network;
|
||||
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
class PinningTrustManager implements X509TrustManager {
|
||||
private static final X509Certificate[] f = new X509Certificate[0];
|
||||
private final TrustManager[] a;
|
||||
private final SystemKeyStore b;
|
||||
private final long c;
|
||||
private final List<byte[]> d = new LinkedList();
|
||||
private final Set<X509Certificate> e = Collections.synchronizedSet(new HashSet());
|
||||
|
||||
public PinningTrustManager(SystemKeyStore systemKeyStore, PinningInfoProvider pinningInfoProvider) {
|
||||
this.a = a(systemKeyStore);
|
||||
this.b = systemKeyStore;
|
||||
this.c = pinningInfoProvider.b();
|
||||
for (String str : pinningInfoProvider.d()) {
|
||||
this.d.add(a(str));
|
||||
}
|
||||
}
|
||||
|
||||
private TrustManager[] a(SystemKeyStore systemKeyStore) {
|
||||
try {
|
||||
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("X509");
|
||||
trustManagerFactory.init(systemKeyStore.a);
|
||||
return trustManagerFactory.getTrustManagers();
|
||||
} catch (KeyStoreException e) {
|
||||
throw new AssertionError(e);
|
||||
} catch (NoSuchAlgorithmException e2) {
|
||||
throw new AssertionError(e2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // javax.net.ssl.X509TrustManager
|
||||
public void checkClientTrusted(X509Certificate[] x509CertificateArr, String str) throws CertificateException {
|
||||
throw new CertificateException("Client certificates not supported!");
|
||||
}
|
||||
|
||||
@Override // javax.net.ssl.X509TrustManager
|
||||
public void checkServerTrusted(X509Certificate[] x509CertificateArr, String str) throws CertificateException {
|
||||
if (this.e.contains(x509CertificateArr[0])) {
|
||||
return;
|
||||
}
|
||||
a(x509CertificateArr, str);
|
||||
a(x509CertificateArr);
|
||||
this.e.add(x509CertificateArr[0]);
|
||||
}
|
||||
|
||||
@Override // javax.net.ssl.X509TrustManager
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return f;
|
||||
}
|
||||
|
||||
private boolean a(X509Certificate x509Certificate) throws CertificateException {
|
||||
try {
|
||||
byte[] digest = MessageDigest.getInstance("SHA1").digest(x509Certificate.getPublicKey().getEncoded());
|
||||
Iterator<byte[]> it = this.d.iterator();
|
||||
while (it.hasNext()) {
|
||||
if (Arrays.equals(it.next(), digest)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new CertificateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void a(X509Certificate[] x509CertificateArr, String str) throws CertificateException {
|
||||
for (TrustManager trustManager : this.a) {
|
||||
((X509TrustManager) trustManager).checkServerTrusted(x509CertificateArr, str);
|
||||
}
|
||||
}
|
||||
|
||||
private void a(X509Certificate[] x509CertificateArr) throws CertificateException {
|
||||
if (this.c != -1 && System.currentTimeMillis() - this.c > 15552000000L) {
|
||||
Fabric.g().w("Fabric", "Certificate pins are stale, (" + (System.currentTimeMillis() - this.c) + " millis vs 15552000000 millis) falling back to system trust.");
|
||||
return;
|
||||
}
|
||||
for (X509Certificate x509Certificate : CertificateChainCleaner.a(x509CertificateArr, this.b)) {
|
||||
if (a(x509Certificate)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new CertificateException("No valid pins found in chain!");
|
||||
}
|
||||
|
||||
private byte[] a(String str) {
|
||||
int length = str.length();
|
||||
byte[] bArr = new byte[length / 2];
|
||||
for (int i = 0; i < length; i += 2) {
|
||||
bArr[i / 2] = (byte) ((Character.digit(str.charAt(i), 16) << 4) + Character.digit(str.charAt(i + 1), 16));
|
||||
}
|
||||
return bArr;
|
||||
}
|
||||
}
|
@@ -0,0 +1,81 @@
|
||||
package io.fabric.sdk.android.services.network;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.Principal;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
class SystemKeyStore {
|
||||
final KeyStore a;
|
||||
private final HashMap<Principal, X509Certificate> b;
|
||||
|
||||
public SystemKeyStore(InputStream inputStream, String str) {
|
||||
KeyStore a = a(inputStream, str);
|
||||
this.b = a(a);
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
public X509Certificate a(X509Certificate x509Certificate) {
|
||||
X509Certificate x509Certificate2 = this.b.get(x509Certificate.getIssuerX500Principal());
|
||||
if (x509Certificate2 == null || x509Certificate2.getSubjectX500Principal().equals(x509Certificate.getSubjectX500Principal())) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
x509Certificate.verify(x509Certificate2.getPublicKey());
|
||||
return x509Certificate2;
|
||||
} catch (GeneralSecurityException unused) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean b(X509Certificate x509Certificate) {
|
||||
X509Certificate x509Certificate2 = this.b.get(x509Certificate.getSubjectX500Principal());
|
||||
return x509Certificate2 != null && x509Certificate2.getPublicKey().equals(x509Certificate.getPublicKey());
|
||||
}
|
||||
|
||||
private HashMap<Principal, X509Certificate> a(KeyStore keyStore) {
|
||||
try {
|
||||
HashMap<Principal, X509Certificate> hashMap = new HashMap<>();
|
||||
Enumeration<String> aliases = keyStore.aliases();
|
||||
while (aliases.hasMoreElements()) {
|
||||
X509Certificate x509Certificate = (X509Certificate) keyStore.getCertificate(aliases.nextElement());
|
||||
if (x509Certificate != null) {
|
||||
hashMap.put(x509Certificate.getSubjectX500Principal(), x509Certificate);
|
||||
}
|
||||
}
|
||||
return hashMap;
|
||||
} catch (KeyStoreException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private KeyStore a(InputStream inputStream, String str) {
|
||||
try {
|
||||
KeyStore keyStore = KeyStore.getInstance("BKS");
|
||||
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
|
||||
try {
|
||||
keyStore.load(bufferedInputStream, str.toCharArray());
|
||||
return keyStore;
|
||||
} finally {
|
||||
bufferedInputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
} catch (KeyStoreException e2) {
|
||||
throw new AssertionError(e2);
|
||||
} catch (NoSuchAlgorithmException e3) {
|
||||
throw new AssertionError(e3);
|
||||
} catch (CertificateException e4) {
|
||||
throw new AssertionError(e4);
|
||||
}
|
||||
}
|
||||
}
|
87
sources/io/fabric/sdk/android/services/network/UrlUtils.java
Normal file
87
sources/io/fabric/sdk/android/services/network/UrlUtils.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package io.fabric.sdk.android.services.network;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class UrlUtils {
|
||||
public static TreeMap<String, String> a(URI uri, boolean z) {
|
||||
return a(uri.getRawQuery(), z);
|
||||
}
|
||||
|
||||
public static String b(String str) {
|
||||
if (str == null) {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
return URLDecoder.decode(str, "UTF8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String c(String str) {
|
||||
if (str == null) {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
return URLEncoder.encode(str, "UTF8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static TreeMap<String, String> a(String str, boolean z) {
|
||||
TreeMap<String, String> treeMap = new TreeMap<>();
|
||||
if (str == null) {
|
||||
return treeMap;
|
||||
}
|
||||
for (String str2 : str.split("&")) {
|
||||
String[] split = str2.split("=");
|
||||
if (split.length == 2) {
|
||||
if (z) {
|
||||
treeMap.put(b(split[0]), b(split[1]));
|
||||
} else {
|
||||
treeMap.put(split[0], split[1]);
|
||||
}
|
||||
} else if (!TextUtils.isEmpty(split[0])) {
|
||||
if (z) {
|
||||
treeMap.put(b(split[0]), "");
|
||||
} else {
|
||||
treeMap.put(split[0], "");
|
||||
}
|
||||
}
|
||||
}
|
||||
return treeMap;
|
||||
}
|
||||
|
||||
public static String a(String str) {
|
||||
int i;
|
||||
if (str == null) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String c = c(str);
|
||||
int length = c.length();
|
||||
int i2 = 0;
|
||||
while (i2 < length) {
|
||||
char charAt = c.charAt(i2);
|
||||
if (charAt == '*') {
|
||||
sb.append("%2A");
|
||||
} else if (charAt == '+') {
|
||||
sb.append("%20");
|
||||
} else if (charAt == '%' && (i = i2 + 2) < length && c.charAt(i2 + 1) == '7' && c.charAt(i) == 'E') {
|
||||
sb.append('~');
|
||||
i2 = i;
|
||||
} else {
|
||||
sb.append(charAt);
|
||||
}
|
||||
i2++;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user