导航菜单

页面标题

页面副标题

Chaupal v3.2 - Platform.java 源代码

正在查看: Chaupal v3.2 应用的 Platform.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package io.grpc.okhttp.internal;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.Socket;
import java.security.AccessController;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.security.Provider;
import java.security.Security;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocket;

public class Platform {
    public static final Logger b = Logger.getLogger(Platform.class.getName());
    private static final String[] c = {"com.google.android.gms.org.conscrypt.OpenSSLProvider", "org.conscrypt.OpenSSLProvider", "com.android.org.conscrypt.OpenSSLProvider", "org.apache.harmony.xnet.provider.jsse.OpenSSLProvider", "com.google.android.libraries.stitch.sslguard.SslGuardProvider"};
    private static final Platform d = d();
    private final Provider a;

    public enum TlsExtensionType {
        ALPN_AND_NPN,
        NPN,
        NONE
    }

    class a implements PrivilegedExceptionAction<Method> {
        a() {
        }

        @Override
        public Method run() throws Exception {
            return SSLEngine.class.getMethod("getApplicationProtocol", new Class[0]);
        }
    }

    class b implements PrivilegedExceptionAction<Method> {
        b() {
        }

        @Override
        public Method run() throws Exception {
            return SSLParameters.class.getMethod("setApplicationProtocols", String[].class);
        }
    }

    class c implements PrivilegedExceptionAction<Method> {
        c() {
        }

        @Override
        public Method run() throws Exception {
            return SSLSocket.class.getMethod("getApplicationProtocol", new Class[0]);
        }
    }

    private static class d extends Platform {
        private final io.grpc.okhttp.internal.d<Socket> e;
        private final io.grpc.okhttp.internal.d<Socket> f;
        private final Method g;
        private final Method h;
        private final io.grpc.okhttp.internal.d<Socket> i;
        private final io.grpc.okhttp.internal.d<Socket> j;
        private final TlsExtensionType k;

        public d(io.grpc.okhttp.internal.d<Socket> dVar, io.grpc.okhttp.internal.d<Socket> dVar2, Method method, Method method2, io.grpc.okhttp.internal.d<Socket> dVar3, io.grpc.okhttp.internal.d<Socket> dVar4, Provider provider, TlsExtensionType tlsExtensionType) {
            super(provider);
            this.e = dVar;
            this.f = dVar2;
            this.g = method;
            this.h = method2;
            this.i = dVar3;
            this.j = dVar4;
            this.k = tlsExtensionType;
        }

        @Override
        public void c(SSLSocket sSLSocket, String str, List<Protocol> list) {
            if (str != null) {
                this.e.e(sSLSocket, Boolean.TRUE);
                this.f.e(sSLSocket, str);
            }
            if (this.j.g(sSLSocket)) {
                this.j.f(sSLSocket, Platform.b(list));
            }
        }

        @Override
        public String h(SSLSocket sSLSocket) {
            byte[] bArr;
            if (this.i.g(sSLSocket) && (bArr = (byte[]) this.i.f(sSLSocket, new Object[0])) != null) {
                return new String(bArr, io.grpc.okhttp.internal.e.c);
            }
            return null;
        }

        @Override
        public TlsExtensionType i() {
            return this.k;
        }
    }

    private static class e extends Platform {
        private final Method e;
        private final Method f;

        e(Provider provider, Method method, Method method2, a aVar) {
            this(provider, method, method2);
        }

        @Override
        public void c(SSLSocket sSLSocket, String str, List<Protocol> list) {
            SSLParameters sSLParameters = sSLSocket.getSSLParameters();
            ArrayList arrayList = new ArrayList(list.size());
            for (Protocol protocol : list) {
                if (protocol != Protocol.HTTP_1_0) {
                    arrayList.add(protocol.toString());
                }
            }
            try {
                this.e.invoke(sSLParameters, arrayList.toArray(new String[arrayList.size()]));
                sSLSocket.setSSLParameters(sSLParameters);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            } catch (InvocationTargetException e2) {
                throw new RuntimeException(e2);
            }
        }

        @Override
        public String h(SSLSocket sSLSocket) {
            try {
                return (String) this.f.invoke(sSLSocket, new Object[0]);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            } catch (InvocationTargetException e2) {
                throw new RuntimeException(e2);
            }
        }

        @Override
        public TlsExtensionType i() {
            return TlsExtensionType.ALPN_AND_NPN;
        }

        private e(Provider provider, Method method, Method method2) {
            super(provider);
            this.e = method;
            this.f = method2;
        }
    }

    private static class f extends Platform {
        private final Method e;
        private final Method f;
        private final Method g;
        private final Class<?> h;
        private final Class<?> i;

        public f(Method method, Method method2, Method method3, Class<?> cls, Class<?> cls2, Provider provider) {
            super(provider);
            this.e = method;
            this.f = method2;
            this.g = method3;
            this.h = cls;
            this.i = cls2;
        }

        @Override
        public void a(SSLSocket sSLSocket) {
            try {
                this.g.invoke(null, sSLSocket);
            } catch (IllegalAccessException unused) {
                throw new AssertionError();
            } catch (InvocationTargetException e) {
                Platform.b.log(Level.FINE, "Failed to remove SSLSocket from Jetty ALPN", (Throwable) e);
            }
        }

        @Override
        public void c(SSLSocket sSLSocket, String str, List<Protocol> list) {
            ArrayList arrayList = new ArrayList(list.size());
            int size = list.size();
            for (int i = 0; i < size; i++) {
                Protocol protocol = list.get(i);
                if (protocol != Protocol.HTTP_1_0) {
                    arrayList.add(protocol.toString());
                }
            }
            try {
                this.e.invoke(null, sSLSocket, Proxy.newProxyInstance(Platform.class.getClassLoader(), new Class[]{this.h, this.i}, new g(arrayList)));
            } catch (IllegalAccessException e) {
                throw new AssertionError(e);
            } catch (InvocationTargetException e2) {
                throw new AssertionError(e2);
            }
        }

        @Override
        public String h(SSLSocket sSLSocket) {
            try {
                g gVar = (g) Proxy.getInvocationHandler(this.f.invoke(null, sSLSocket));
                if (!gVar.b && gVar.c == null) {
                    Platform.b.log(Level.INFO, "ALPN callback dropped: SPDY and HTTP/2 are disabled. Is alpn-boot on the boot class path?");
                    return null;
                }
                if (gVar.b) {
                    return null;
                }
                return gVar.c;
            } catch (IllegalAccessException unused) {
                throw new AssertionError();
            } catch (InvocationTargetException unused2) {
                throw new AssertionError();
            }
        }

        @Override
        public TlsExtensionType i() {
            return TlsExtensionType.ALPN_AND_NPN;
        }
    }

    private static class g implements InvocationHandler {
        private final List<String> a;
        private boolean b;
        private String c;

        public g(List<String> list) {
            this.a = list;
        }

        @Override
        public Object invoke(Object obj, Method method, Object[] objArr) throws Throwable {
            String name = method.getName();
            Class<?> returnType = method.getReturnType();
            if (objArr == null) {
                objArr = io.grpc.okhttp.internal.e.b;
            }
            if (name.equals("supports") && Boolean.TYPE == returnType) {
                return Boolean.TRUE;
            }
            if (name.equals("unsupported") && Void.TYPE == returnType) {
                this.b = true;
                return null;
            }
            if (name.equals("protocols") && objArr.length == 0) {
                return this.a;
            }
            if ((!name.equals("selectProtocol") && !name.equals("select")) || String.class != returnType || objArr.length != 1 || !(objArr[0] instanceof List)) {
                if ((!name.equals("protocolSelected") && !name.equals("selected")) || objArr.length != 1) {
                    return method.invoke(this, objArr);
                }
                this.c = (String) objArr[0];
                return null;
            }
            List list = (List) objArr[0];
            int size = list.size();
            for (int i = 0; i < size; i++) {
                if (this.a.contains(list.get(i))) {
                    String str = (String) list.get(i);
                    this.c = str;
                    return str;
                }
            }
            String str2 = this.a.get(0);
            this.c = str2;
            return str2;
        }
    }

    public Platform(Provider provider) {
        this.a = provider;
    }

    public static byte[] b(List<Protocol> list) {
        okio.e eVar = new okio.e();
        int size = list.size();
        for (int i = 0; i < size; i++) {
            Protocol protocol = list.get(i);
            if (protocol != Protocol.HTTP_1_0) {
                eVar.G0(protocol.toString().length());
                eVar.a0(protocol.toString());
            }
        }
        return eVar.E0();
    }

    private static Platform d() {
        Method method;
        Method method2;
        Provider f3 = f();
        a aVar = null;
        if (f3 != null) {
            io.grpc.okhttp.internal.d dVar = new io.grpc.okhttp.internal.d(null, "setUseSessionTickets", Boolean.TYPE);
            io.grpc.okhttp.internal.d dVar2 = new io.grpc.okhttp.internal.d(null, "setHostname", String.class);
            io.grpc.okhttp.internal.d dVar3 = new io.grpc.okhttp.internal.d(byte[].class, "getAlpnSelectedProtocol", new Class[0]);
            io.grpc.okhttp.internal.d dVar4 = new io.grpc.okhttp.internal.d(null, "setAlpnProtocols", byte[].class);
            try {
                Class<?> cls = Class.forName("android.net.TrafficStats");
                method = cls.getMethod("tagSocket", Socket.class);
                try {
                    method2 = cls.getMethod("untagSocket", Socket.class);
                } catch (ClassNotFoundException | NoSuchMethodException unused) {
                    method2 = null;
                    return new d(dVar, dVar2, method, method2, dVar3, dVar4, f3, (!f3.getName().equals("GmsCore_OpenSSL") || f3.getName().equals("Conscrypt") || f3.getName().equals("Ssl_Guard")) ? TlsExtensionType.ALPN_AND_NPN : k() ? TlsExtensionType.ALPN_AND_NPN : j() ? TlsExtensionType.NPN : TlsExtensionType.NONE);
                }
            } catch (ClassNotFoundException | NoSuchMethodException unused2) {
                method = null;
            }
            return new d(dVar, dVar2, method, method2, dVar3, dVar4, f3, (!f3.getName().equals("GmsCore_OpenSSL") || f3.getName().equals("Conscrypt") || f3.getName().equals("Ssl_Guard")) ? TlsExtensionType.ALPN_AND_NPN : k() ? TlsExtensionType.ALPN_AND_NPN : j() ? TlsExtensionType.NPN : TlsExtensionType.NONE);
        }
        try {
            Provider provider = SSLContext.getDefault().getProvider();
            try {
                SSLContext sSLContext = SSLContext.getInstance("TLS", provider);
                sSLContext.init(null, null, null);
                ((Method) AccessController.doPrivileged(new a())).invoke(sSLContext.createSSLEngine(), new Object[0]);
                return new e(provider, (Method) AccessController.doPrivileged(new b()), (Method) AccessController.doPrivileged(new c()), aVar);
            } catch (IllegalAccessException | InvocationTargetException | KeyManagementException | NoSuchAlgorithmException | PrivilegedActionException unused3) {
                try {
                    Class<?> cls2 = Class.forName("org.eclipse.jetty.alpn.ALPN");
                    Class<?> cls3 = Class.forName("org.eclipse.jetty.alpn.ALPN$Provider");
                    return new f(cls2.getMethod("put", SSLSocket.class, cls3), cls2.getMethod("get", SSLSocket.class), cls2.getMethod("remove", SSLSocket.class), Class.forName("org.eclipse.jetty.alpn.ALPN$ClientProvider"), Class.forName("org.eclipse.jetty.alpn.ALPN$ServerProvider"), provider);
                } catch (ClassNotFoundException | NoSuchMethodException unused4) {
                    return new Platform(provider);
                }
            }
        } catch (NoSuchAlgorithmException e2) {
            throw new RuntimeException(e2);
        }
    }

    public static Platform e() {
        return d;
    }

    private static Provider f() {
        for (Provider provider : Security.getProviders()) {
            for (String str : c) {
                if (str.equals(provider.getClass().getName())) {
                    b.log(Level.FINE, "Found registered provider {0}", str);
                    return provider;
                }
            }
        }
        b.log(Level.WARNING, "Unable to find Conscrypt");
        return null;
    }

    private static boolean j() {
        try {
            Platform.class.getClassLoader().loadClass("android.app.ActivityOptions");
            return true;
        } catch (ClassNotFoundException e2) {
            b.log(Level.FINE, "Can't find class", (Throwable) e2);
            return false;
        }
    }

    private static boolean k() {
        try {
            Platform.class.getClassLoader().loadClass("android.net.Network");
            return true;
        } catch (ClassNotFoundException e2) {
            b.log(Level.FINE, "Can't find class", (Throwable) e2);
            return false;
        }
    }

    public void a(SSLSocket sSLSocket) {
    }

    public void c(SSLSocket sSLSocket, String str, List<Protocol> list) {
    }

    public Provider g() {
        return this.a;
    }

    public String h(SSLSocket sSLSocket) {
        return null;
    }

    public TlsExtensionType i() {
        return TlsExtensionType.NONE;
    }
}