package 㿎.ሽ.ᨨ;

import android.os.Build;
import android.util.Log;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.security.NoSuchAlgorithmException;
import java.security.Security;
import java.security.cert.Certificate;
import java.security.cert.TrustAnchor;
import java.security.cert.X509Certificate;
import java.util.List;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;
import okhttp3.Protocol;
import ᨨ.C1492;
import 㿎.ሽ.C2540;
import 㿎.ሽ.㳳.AbstractC2571;
import 㿎.ሽ.㳳.AbstractC2572;
import 㿎.ሽ.㳳.C2574;

/* renamed from: 㿎.ሽ.ᨨ.K  reason: contains not printable characters */
/* compiled from: AndroidPlatform */
public class C2554 extends C2558 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public final Class<?> f8629;

    /* renamed from: ඓ  reason: contains not printable characters */
    public final C2552<Socket> f8630;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public final C2552<Socket> f8631;

    /* renamed from: 㴹  reason: contains not printable characters */
    public final C2552<Socket> f8632;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final C2552<Socket> f8633;

    /* renamed from: 㿎  reason: contains not printable characters */
    public final C2555 f8634;

    /* renamed from: 㿎.ሽ.ᨨ.K$ʬ  reason: contains not printable characters */
    /* compiled from: AndroidPlatform */
    public static final class C2555 {

        /* renamed from: ʬ  reason: contains not printable characters */
        public final Method f8635;

        /* renamed from: ῲ  reason: contains not printable characters */
        public final Method f8636;

        /* renamed from: K  reason: contains not printable characters */
        public final Method f8637;

        public C2555(Method method, Method method2, Method method3) {
            this.f8637 = method;
            this.f8636 = method2;
            this.f8635 = method3;
        }

        /* renamed from: K  reason: contains not printable characters */
        public boolean m6719(Object obj) {
            if (obj == null) {
                return false;
            }
            try {
                this.f8635.invoke(obj, new Object[0]);
                return true;
            } catch (Exception unused) {
                return false;
            }
        }
    }

    /* renamed from: 㿎.ሽ.ᨨ.K$ῲ  reason: contains not printable characters */
    /* compiled from: AndroidPlatform */
    public static final class C2556 implements AbstractC2572 {

        /* renamed from: ῲ  reason: contains not printable characters */
        public final Method f8638;

        /* renamed from: K  reason: contains not printable characters */
        public final X509TrustManager f8639;

        public C2556(X509TrustManager x509TrustManager, Method method) {
            this.f8638 = method;
            this.f8639 = x509TrustManager;
        }

        public boolean equals(Object obj) {
            if (obj == this) {
                return true;
            }
            if (!(obj instanceof C2556)) {
                return false;
            }
            C2556 r5 = (C2556) obj;
            if (!this.f8639.equals(r5.f8639) || !this.f8638.equals(r5.f8638)) {
                return false;
            }
            return true;
        }

        public int hashCode() {
            return (this.f8638.hashCode() * 31) + this.f8639.hashCode();
        }

        @Override // 㿎.ሽ.㳳.AbstractC2572
        /* renamed from: K  reason: contains not printable characters */
        public X509Certificate m6720(X509Certificate x509Certificate) {
            try {
                TrustAnchor trustAnchor = (TrustAnchor) this.f8638.invoke(this.f8639, x509Certificate);
                if (trustAnchor != null) {
                    return trustAnchor.getTrustedCert();
                }
                return null;
            } catch (IllegalAccessException e) {
                throw C2540.m6640("unable to get issues and signature", (Exception) e);
            } catch (InvocationTargetException unused) {
                return null;
            }
        }
    }

    /* renamed from: 㿎.ሽ.ᨨ.K$K  reason: contains not printable characters */
    /* compiled from: AndroidPlatform */
    public static final class C2557 extends AbstractC2571 {

        /* renamed from: ῲ  reason: contains not printable characters */
        public final Method f8640;

        /* renamed from: K  reason: contains not printable characters */
        public final Object f8641;

        public C2557(Object obj, Method method) {
            this.f8641 = obj;
            this.f8640 = method;
        }

        public boolean equals(Object obj) {
            return obj instanceof C2557;
        }

        public int hashCode() {
            return 0;
        }

        @Override // 㿎.ሽ.㳳.AbstractC2571
        /* renamed from: K  reason: contains not printable characters */
        public List<Certificate> m6721(List<Certificate> list, String str) throws SSLPeerUnverifiedException {
            try {
                return (List) this.f8640.invoke(this.f8641, (X509Certificate[]) list.toArray(new X509Certificate[list.size()]), "RSA", str);
            } catch (InvocationTargetException e) {
                SSLPeerUnverifiedException sSLPeerUnverifiedException = new SSLPeerUnverifiedException(e.getMessage());
                sSLPeerUnverifiedException.initCause(e);
                throw sSLPeerUnverifiedException;
            } catch (IllegalAccessException e2) {
                throw new AssertionError(e2);
            }
        }
    }

    public C2554(Class<?> cls, C2552<Socket> r9, C2552<Socket> r10, C2552<Socket> r11, C2552<Socket> r12) {
        Method method;
        Method method2;
        Method method3 = null;
        try {
            Class<?> cls2 = Class.forName("dalvik.system.CloseGuard");
            Method method4 = cls2.getMethod("get", new Class[0]);
            method = cls2.getMethod("open", String.class);
            method2 = cls2.getMethod("warnIfOpen", new Class[0]);
            method3 = method4;
        } catch (Exception unused) {
            method2 = null;
            method = null;
        }
        this.f8634 = new C2555(method3, method, method2);
        this.f8629 = cls;
        this.f8633 = r9;
        this.f8630 = r10;
        this.f8632 = r11;
        this.f8631 = r12;
    }

    @Override // 㿎.ሽ.ᨨ.C2558
    /* renamed from: ῲ  reason: contains not printable characters */
    public X509TrustManager m6708(SSLSocketFactory sSLSocketFactory) {
        Object r0 = C2558.m6722(sSLSocketFactory, this.f8629, "sslParameters");
        if (r0 == null) {
            try {
                r0 = C2558.m6722(sSLSocketFactory, Class.forName("com.google.android.gms.org.conscrypt.SSLParametersImpl", false, sSLSocketFactory.getClass().getClassLoader()), "sslParameters");
            } catch (ClassNotFoundException unused) {
                return super.m6725(sSLSocketFactory);
            }
        }
        X509TrustManager x509TrustManager = (X509TrustManager) C2558.m6722(r0, X509TrustManager.class, "x509TrustManager");
        if (x509TrustManager != null) {
            return x509TrustManager;
        }
        return (X509TrustManager) C2558.m6722(r0, X509TrustManager.class, "trustManager");
    }

    @Override // 㿎.ሽ.ᨨ.C2558
    /* renamed from: K  reason: contains not printable characters */
    public void m6716(Socket socket, InetSocketAddress inetSocketAddress, int i) throws IOException {
        try {
            socket.connect(inetSocketAddress, i);
        } catch (AssertionError e) {
            if (C2540.m6653(e)) {
                throw new IOException(e);
            }
            throw e;
        } catch (SecurityException e2) {
            IOException iOException = new IOException("Exception in connect");
            iOException.initCause(e2);
            throw iOException;
        } catch (ClassCastException e3) {
            if (Build.VERSION.SDK_INT == 26) {
                IOException iOException2 = new IOException("Exception in connect");
                iOException2.initCause(e3);
                throw iOException2;
            }
            throw e3;
        }
    }

    @Override // 㿎.ሽ.ᨨ.C2558
    /* renamed from: ῲ  reason: contains not printable characters */
    public String m6707(SSLSocket sSLSocket) {
        byte[] bArr;
        C2552<Socket> r0 = this.f8632;
        if (r0 == null) {
            return null;
        }
        if ((r0.m6698(sSLSocket.getClass()) != null) && (bArr = (byte[]) this.f8632.m6695(sSLSocket, new Object[0])) != null) {
            return new String(bArr, C2540.f8566);
        }
        return null;
    }

    @Override // 㿎.ሽ.ᨨ.C2558
    /* renamed from: ῲ  reason: contains not printable characters */
    public boolean m6710(String str) {
        try {
            Class<?> cls = Class.forName("android.security.NetworkSecurityPolicy");
            return m6718(str, cls, cls.getMethod("getInstance", new Class[0]).invoke(null, new Object[0]));
        } catch (ClassNotFoundException | NoSuchMethodException unused) {
            return true;
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            throw C2540.m6640("unable to determine cleartext support", e);
        }
    }

    @Override // 㿎.ሽ.ᨨ.C2558
    /* renamed from: K  reason: contains not printable characters */
    public void m6717(SSLSocket sSLSocket, String str, List<Protocol> list) {
        if (str != null) {
            this.f8633.m6696(sSLSocket, true);
            this.f8630.m6696(sSLSocket, str);
        }
        C2552<Socket> r8 = this.f8631;
        if (r8 != null) {
            if (r8.m6698(sSLSocket.getClass()) != null) {
                Object[] objArr = new Object[1];
                C1492 r0 = new C1492();
                int size = list.size();
                for (int i = 0; i < size; i++) {
                    Protocol protocol = list.get(i);
                    if (protocol != Protocol.HTTP_1_0) {
                        r0.writeByte(protocol.toString().length());
                        r0.m3792(protocol.toString());
                    }
                }
                objArr[0] = r0.m3805();
                this.f8631.m6695(sSLSocket, objArr);
            }
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public static C2558 m6706() {
        Class<?> cls;
        boolean z;
        C2552 r8;
        C2552 r7;
        try {
            cls = Class.forName("com.android.org.conscrypt.SSLParametersImpl");
        } catch (ClassNotFoundException unused) {
            try {
                cls = Class.forName("org.apache.harmony.xnet.provider.jsse.SSLParametersImpl");
            } catch (ClassNotFoundException unused2) {
                return null;
            }
        }
        C2552 r5 = new C2552(null, "setUseSessionTickets", Boolean.TYPE);
        C2552 r6 = new C2552(null, "setHostname", String.class);
        if (Security.getProvider("GMSCore_OpenSSL") == null) {
            try {
                Class.forName("android.net.Network");
            } catch (ClassNotFoundException unused3) {
                z = false;
            }
        }
        z = true;
        if (z) {
            C2552 r1 = new C2552(byte[].class, "getAlpnSelectedProtocol", new Class[0]);
            r8 = new C2552(null, "setAlpnProtocols", byte[].class);
            r7 = r1;
        } else {
            r7 = null;
            r8 = null;
        }
        return new C2554(cls, r5, r6, r7, r8);
    }

    @Override // 㿎.ሽ.ᨨ.C2558
    /* renamed from: K  reason: contains not printable characters */
    public void m6714(int i, String str, Throwable th) {
        int min;
        int i2 = 5;
        if (i != 5) {
            i2 = 3;
        }
        if (th != null) {
            str = str + '\n' + Log.getStackTraceString(th);
        }
        int i3 = 0;
        int length = str.length();
        while (i3 < length) {
            int indexOf = str.indexOf(10, i3);
            if (indexOf == -1) {
                indexOf = length;
            }
            while (true) {
                min = Math.min(indexOf, i3 + 4000);
                Log.println(i2, "OkHttp", str.substring(i3, min));
                if (min >= indexOf) {
                    break;
                }
                i3 = min;
            }
            i3 = min + 1;
        }
    }

    @Override // 㿎.ሽ.ᨨ.C2558
    /* renamed from: ῲ  reason: contains not printable characters */
    public AbstractC2572 m6709(X509TrustManager x509TrustManager) {
        try {
            Method declaredMethod = x509TrustManager.getClass().getDeclaredMethod("findTrustAnchorByIssuerAndSignature", X509Certificate.class);
            declaredMethod.setAccessible(true);
            return new C2556(x509TrustManager, declaredMethod);
        } catch (NoSuchMethodException unused) {
            return super.m6726(x509TrustManager);
        }
    }

    @Override // 㿎.ሽ.ᨨ.C2558
    /* renamed from: K  reason: contains not printable characters */
    public Object m6711(String str) {
        C2555 r0 = this.f8634;
        Method method = r0.f8637;
        if (method != null) {
            try {
                Object invoke = method.invoke(null, new Object[0]);
                r0.f8636.invoke(invoke, str);
                return invoke;
            } catch (Exception unused) {
            }
        }
        return null;
    }

    @Override // 㿎.ሽ.ᨨ.C2558
    /* renamed from: K  reason: contains not printable characters */
    public void m6715(String str, Object obj) {
        if (!this.f8634.m6719(obj)) {
            m6714(5, str, (Throwable) null);
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:7:?, code lost:
        return ((java.lang.Boolean) r7.getMethod("isCleartextTrafficPermitted", new java.lang.Class[0]).invoke(r8, new java.lang.Object[0])).booleanValue();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:8:?, code lost:
        return true;
     */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Missing exception handler attribute for start block: B:4:0x001d */
    /* renamed from: K  reason: contains not printable characters */
    public final boolean m6718(String str, Class<?> cls, Object obj) throws InvocationTargetException, IllegalAccessException {
        return ((Boolean) cls.getMethod("isCleartextTrafficPermitted", String.class).invoke(obj, str)).booleanValue();
    }

    @Override // 㿎.ሽ.ᨨ.C2558
    /* renamed from: K  reason: contains not printable characters */
    public AbstractC2571 m6713(X509TrustManager x509TrustManager) {
        try {
            Class<?> cls = Class.forName("android.net.http.X509TrustManagerExtensions");
            return new C2557(cls.getConstructor(X509TrustManager.class).newInstance(x509TrustManager), cls.getMethod("checkServerTrusted", X509Certificate[].class, String.class, String.class));
        } catch (Exception unused) {
            return new C2574(m6726(x509TrustManager));
        }
    }

    @Override // 㿎.ሽ.ᨨ.C2558
    /* renamed from: K  reason: contains not printable characters */
    public SSLContext m6712() {
        int i = Build.VERSION.SDK_INT;
        try {
            return SSLContext.getInstance("TLS");
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException("No TLS provider", e);
        }
    }
}
