正在查看: Minits v4.9.3.32 应用的 XOneWebSocket.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Minits v4.9.3.32 应用的 XOneWebSocket.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.xone.android.script.runtimeobjects;
import Q8.k;
import Q8.m;
import R1.H;
import U9.f2;
import U9.g2;
import U9.j2;
import U9.k2;
import U9.l2;
import W1.h;
import W1.p;
import Z1.b;
import a2.E;
import a2.F;
import a2.T;
import a2.U;
import a2.d;
import a2.q;
import android.content.Context;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.text.TextUtils;
import androidx.annotation.Keep;
import com.xone.android.javascript.XOneJavascript;
import com.xone.android.script.runtimeobjects.XOneWebSocket;
import com.xone.android.utils.Utils;
import com.xone.annotations.ScriptAllowed;
import com.xone.interfaces.IRuntimeObject;
import da.C0594b;
import fb.t;
import ha.AbstractC0751f;
import ha.M;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import org.mozilla.javascript.BaseFunction;
import org.mozilla.javascript.C0893d0;
import org.mozilla.javascript.C0932x0;
import org.mozilla.javascript.Q0;
import org.mozilla.javascript.Scriptable;
import qa.EnumC0975b;
import ua.InterfaceC1038m0;
import ua.V;
import ua.W;
@Keep
public final class XOneWebSocket extends BaseFunction implements IRuntimeObject {
private static final String TAG = "WebSocket";
private final Context context;
private h httpClient;
private Set<X509Certificate> setExtraCas;
private T wsClient;
private b wsServer;
public XOneWebSocket(Context context) {
this.context = context.getApplicationContext();
}
private InterfaceC1038m0 getApp() {
return (InterfaceC1038m0) this.context;
}
private String[] getApprovedCipherSuites(SSLEngine sSLEngine) {
String[] enabledCipherSuites = sSLEngine.getEnabledCipherSuites();
HashSet hashSet = new HashSet();
for (String str : enabledCipherSuites) {
if (!TextUtils.isEmpty(str) && !str.contains("EXPORT") && !str.equals("TLS_DHE_RSA_WITH_AES_128_CBC_SHA") && !str.equals("TLS_DHE_RSA_WITH_AES_256_CBC_SHA")) {
hashSet.add(str);
}
}
if (hashSet.isEmpty()) {
throw new UnsupportedOperationException("No secure cipher suite found");
}
return (String[]) hashSet.toArray(new String[0]);
}
private String[] getApprovedProtocols(SSLEngine sSLEngine) {
String[] enabledProtocols = sSLEngine.getEnabledProtocols();
List asList = Arrays.asList(enabledProtocols);
return asList.contains("TLSv1.3") ? new String[]{"TLSv1.3"} : asList.contains("TLSv1.2") ? new String[]{"TLSv1.2"} : asList.contains("TLSv1.1") ? new String[]{"TLSv1.1"} : asList.contains("TLSv1") ? new String[]{"TLSv1"} : enabledProtocols;
}
private File getCertificateFile(String str) {
InterfaceC1038m0 app = getApp();
File q1 = Utils.q1(app.Y(), app.T(), str, false, 5);
if (!q1.exists()) {
throw new IllegalArgumentException("WebSocket(): Error, certificate file " + q1.getAbsolutePath() + " does not exist");
}
if (q1.isFile()) {
return q1;
}
throw new IllegalArgumentException("WebSocket(): Error, " + q1.getAbsolutePath() + " is not a certificate file");
}
private static X509Certificate getCertificateFromFile(File file) {
FileInputStream fileInputStream;
Throwable th;
Throwable e;
try {
try {
fileInputStream = new FileInputStream(file);
} catch (Throwable th2) {
th = th2;
}
} catch (FileNotFoundException e2) {
e = e2;
e = e;
throw AbstractC0751f.e(e);
} catch (CertificateException e3) {
e = e3;
e = e;
throw AbstractC0751f.e(e);
} catch (Throwable th3) {
fileInputStream = null;
th = th3;
file = null;
}
try {
BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
try {
X509Certificate x509Certificate = (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(bufferedInputStream);
Utils.P(bufferedInputStream, fileInputStream);
return x509Certificate;
} catch (FileNotFoundException e4) {
e = e4;
throw AbstractC0751f.e(e);
} catch (CertificateException e5) {
e = e5;
throw AbstractC0751f.e(e);
}
} catch (FileNotFoundException e6) {
e = e6;
e = e;
throw AbstractC0751f.e(e);
} catch (CertificateException e7) {
e = e7;
e = e;
throw AbstractC0751f.e(e);
} catch (Throwable th4) {
th = th4;
file = null;
Utils.P(file, fileInputStream);
throw th;
}
}
private C0932x0 getErrorObject(Throwable th) {
if (th == null) {
return null;
}
String simpleName = th.getClass().getSimpleName();
String message = th.getMessage();
if (message == null) {
message = "";
}
C0932x0 c0932x0 = new C0932x0();
Q0.putProperty(c0932x0, "name", "Error");
Q0.putProperty(c0932x0, "type", simpleName);
Q0.putProperty(c0932x0, "message", message);
return c0932x0;
}
private String getIpAddress() {
WifiManager wifiManager = (WifiManager) Utils.y2(this.context, "wifi");
WifiInfo connectionInfo = wifiManager.getConnectionInfo();
if (connectionInfo == null) {
return "";
}
int ipAddress = connectionInfo.getIpAddress();
if (ipAddress != 0) {
return intToStringAddress(ipAddress);
}
if (!isWifiApEnabled(wifiManager)) {
String ipAddressFromNetworkInterfaces = getIpAddressFromNetworkInterfaces();
return !TextUtils.isEmpty(ipAddressFromNetworkInterfaces) ? ipAddressFromNetworkInterfaces : "";
}
String wifiHotspotIpAddress = getWifiHotspotIpAddress();
if (!TextUtils.isEmpty(wifiHotspotIpAddress)) {
return wifiHotspotIpAddress;
}
String wifiHotspotIpAddressAlternative = getWifiHotspotIpAddressAlternative(wifiManager);
return !TextUtils.isEmpty(wifiHotspotIpAddressAlternative) ? wifiHotspotIpAddressAlternative : "192.168.43.1";
}
private String getIpAddressFromNetworkInterfaces() {
try {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
Enumeration<InetAddress> inetAddresses = networkInterfaces.nextElement().getInetAddresses();
while (inetAddresses.hasMoreElements()) {
InetAddress nextElement = inetAddresses.nextElement();
if ((nextElement instanceof Inet4Address) && !nextElement.isLoopbackAddress()) {
String hostAddress = nextElement.getHostAddress();
if (!TextUtils.isEmpty(hostAddress)) {
return hostAddress;
}
}
}
}
return "";
} catch (SocketException e) {
e.printStackTrace();
return "";
}
}
private Object getOnCloseCallback() {
return Q0.getProperty(this, "onclose");
}
private Object getOnErrorCallback() {
return Q0.getProperty(this, "onerror");
}
private Object getOnMessageCallback() {
return Q0.getProperty(this, "onmessage");
}
private Object getOnOpenCallback() {
return Q0.getProperty(this, "onopen");
}
private void getParameters(Object[] objArr) {
int i = 0;
Object obj = (objArr == null || objArr.length <= 0) ? null : objArr[0];
if (obj instanceof C0932x0) {
C0932x0 c0932x0 = (C0932x0) obj;
Q0.putProperty(this, "url", c0932x0.get("url"));
Q0.putProperty(this, "protocol", c0932x0.get("protocol"));
Q0.putProperty(this, "certificate", c0932x0.get("certificate"));
Q0.putProperty(this, "onopen", c0932x0.get("onOpen"));
Q0.putProperty(this, "onmessage", c0932x0.get("onMessage"));
Q0.putProperty(this, "onclose", c0932x0.get("onClose"));
Q0.putProperty(this, "onerror", c0932x0.get("onError"));
Q0.putProperty(this, "verifyWithSystemTrustManagers", c0932x0.get("verifyWithSystemTrustManagers"));
Q0.putProperty(this, "port", c0932x0.get("port"));
Q0.putProperty(this, "path", c0932x0.get("path"));
Q0.putProperty(this, "listenInsecure", c0932x0.get("listenInsecure"));
Q0.putProperty(this, "listenSecure", c0932x0.get("listenSecure"));
Q0.putProperty(this, "keyStore", c0932x0.get("keyStore"));
} else {
if (!(obj instanceof CharSequence)) {
if (obj == null) {
throw new IllegalArgumentException("WebSocket options argument cannot be null");
}
throw new IllegalArgumentException("Unknown options argument of type " + obj.getClass().getSimpleName());
}
String obj2 = obj.toString();
if (TextUtils.isEmpty(obj2)) {
throw new IllegalArgumentException("WebSocket URL argument cannot be empty");
}
Q0.putProperty(this, "url", obj2);
}
boolean z = isListenInsecure() || isListenSecure();
String url = getUrl();
if (!z && TextUtils.isEmpty(url)) {
throw new IllegalArgumentException("WebSocket(): URL argument cannot be empty is client mode");
}
HashSet hashSet = new HashSet();
Object property = Q0.getProperty(this, "certificate");
if (property instanceof CharSequence) {
hashSet.add(getCertificateFromFile(getCertificateFile(property.toString())));
} else if (property instanceof C0893d0) {
ArrayList j = m.j((C0893d0) property, String.class);
int size = j.size();
while (i < size) {
Object obj3 = j.get(i);
i++;
hashSet.add(getCertificateFromFile(getCertificateFile((String) obj3)));
}
}
this.setExtraCas = hashSet;
}
private String getPath() {
Object property = Q0.getProperty(this, "path");
return property instanceof CharSequence ? property.toString() : "";
}
private int getPort() {
Object property = Q0.getProperty(this, "port");
if (!(property instanceof Number)) {
return 0;
}
int intValue = ((Number) property).intValue();
if (intValue > 0) {
return intValue;
}
throw new IllegalArgumentException("WebSocket(): Invalid port number " + intValue);
}
private String getProtocol() {
Object property = Q0.getProperty(this, "protocol");
if (property instanceof CharSequence) {
return property.toString();
}
return null;
}
private SSLContext getServerSslContext(String... strArr) {
SSLContext sSLContext;
if (strArr == null || strArr.length == 0) {
throw AbstractC0751f.e(new NoSuchAlgorithmException("Empty TLS versions argument"));
}
NoSuchAlgorithmException e = null;
for (String str : strArr) {
if (TextUtils.isEmpty(str)) {
throw AbstractC0751f.e(new NoSuchAlgorithmException("Empty TLS version argument"));
}
try {
sSLContext = SSLContext.getInstance(str);
} catch (NoSuchAlgorithmException e2) {
e = e2;
}
if (sSLContext != null) {
return sSLContext;
}
}
if (e != null) {
throw AbstractC0751f.e(e);
}
throw new IllegalArgumentException("Dead code");
}
private String getUrl() {
Object property = Q0.getProperty(this, "url");
return property instanceof CharSequence ? property.toString().trim() : "";
}
private String getWifiHotspotIpAddress() {
try {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
NetworkInterface nextElement = networkInterfaces.nextElement();
try {
if (!nextElement.isLoopback() && !nextElement.isVirtual() && nextElement.isUp() && !nextElement.isPointToPoint() && nextElement.getHardwareAddress() != null) {
Enumeration<InetAddress> inetAddresses = nextElement.getInetAddresses();
while (inetAddresses.hasMoreElements()) {
InetAddress nextElement2 = inetAddresses.nextElement();
if (nextElement2.getAddress().length == 4) {
String hostAddress = nextElement2.getHostAddress();
if (!TextUtils.isEmpty(hostAddress)) {
return hostAddress;
}
}
}
}
} catch (SocketException unused) {
}
}
} catch (SocketException unused2) {
}
return "";
}
private String getWifiHotspotIpAddressAlternative(WifiManager wifiManager) {
int i = wifiManager.getDhcpInfo().serverAddress;
return i == 0 ? "" : intToStringAddress(i);
}
private String intToStringAddress(int i) {
byte[] byteArray = BigInteger.valueOf(i).toByteArray();
reverse(byteArray);
try {
String hostAddress = InetAddress.getByAddress(byteArray).getHostAddress();
return TextUtils.isEmpty(hostAddress) ? "" : hostAddress;
} catch (UnknownHostException e) {
e.printStackTrace();
return "";
}
}
private static void invokeCallback(Object obj, Object... objArr) {
if (obj == null) {
return;
}
try {
if (objArr == null) {
XOneJavascript.x(obj, null);
} else {
XOneJavascript.x(obj, objArr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
private boolean isListenInsecure() {
Object property = Q0.getProperty(this, "listenInsecure");
if (property instanceof Boolean) {
return ((Boolean) property).booleanValue();
}
return false;
}
private boolean isListenSecure() {
Object property = Q0.getProperty(this, "listenSecure");
if (property instanceof Boolean) {
return ((Boolean) property).booleanValue();
}
return false;
}
private boolean isWifiApEnabled(WifiManager wifiManager) {
Object m = M.m(wifiManager, "isWifiApEnabled", new Object[0]);
if (m instanceof Boolean) {
return ((Boolean) m).booleanValue();
}
if (Boolean.TYPE.isInstance(m)) {
return ((Boolean) m).booleanValue();
}
return false;
}
private void listenInsecure() {
int port = getPort();
String path = getPath();
if (this.wsServer == null) {
this.wsServer = new b();
}
this.wsServer.h(path, new f2(this));
this.wsServer.x(new g2(this));
this.wsServer.n(port);
Q0.putProperty(this, "ipAddress", getIpAddress());
}
private void listenSecure() {
try {
int port = getPort();
String path = getPath();
C0932x0 c0932x0 = (C0932x0) Q0.getProperty(this, "keyStore");
String E = k.E(c0932x0, "file", null);
String E2 = k.E(c0932x0, "password", null);
String E3 = k.E(c0932x0, "keyAlias", null);
if (TextUtils.isEmpty(E)) {
throw new IllegalArgumentException("Empty key store file path");
}
File certificateFile = getCertificateFile(E);
SSLContext serverSslContext = getServerSslContext("TLSv1.3", "TLSv1.2", "TLSv1.1", "TLS");
KeyStore keyStore = KeyStore.getInstance("BKS");
char[] charArray = E2.toCharArray();
FileInputStream fileInputStream = new FileInputStream(certificateFile);
try {
keyStore.load(fileInputStream, charArray);
Utils.N(fileInputStream);
if ((keyStore.containsAlias(E3) ? keyStore.getCertificate(E3) : null) == null) {
throw new NullPointerException("Error, cannot find SSL certificate for websocket server");
}
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("X509");
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, charArray);
trustManagerFactory.init(keyStore);
serverSslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
if (this.wsServer == null) {
this.wsServer = new b();
}
this.wsServer.w(new F() {
public final void a(Exception exc, a2.k kVar) {
XOneWebSocket.this.onHandshakeError(exc, kVar);
}
});
this.wsServer.v(new E() {
public final void a(Exception exc) {
XOneWebSocket.this.onDataErrorCallback(exc);
}
});
this.wsServer.h(path, new f2(this));
this.wsServer.x(new g2(this));
SSLEngine createSSLEngine = serverSslContext.createSSLEngine();
this.wsServer.p(port, serverSslContext, getApprovedCipherSuites(createSSLEngine), getApprovedProtocols(createSSLEngine));
Q0.putProperty(this, "ipAddress", getIpAddress());
} catch (Throwable th) {
Utils.N(fileInputStream);
throw th;
}
} catch (IOException e) {
e = e;
throw AbstractC0751f.e(e);
} catch (KeyManagementException e2) {
e = e2;
throw AbstractC0751f.e(e);
} catch (KeyStoreException e3) {
e = e3;
throw AbstractC0751f.e(e);
} catch (NoSuchAlgorithmException e4) {
e = e4;
throw AbstractC0751f.e(e);
} catch (UnrecoverableKeyException e5) {
e = e5;
throw AbstractC0751f.e(e);
} catch (CertificateException e6) {
e = e6;
throw AbstractC0751f.e(e);
}
}
public void onDataErrorCallback(Exception exc) {
invokeCallback(getOnErrorCallback(), getErrorObject(exc));
}
public void onHandshakeError(Exception exc, a2.k kVar) {
invokeCallback(getOnErrorCallback(), getErrorObject(exc));
}
public void onWebSocketClosed(Exception exc) {
invokeCallback(getOnCloseCallback(), getErrorObject(exc));
}
public void onWebSocketCompleted(Exception exc, T t) {
if (exc != null) {
exc.printStackTrace();
invokeCallback(getOnErrorCallback(), getErrorObject(exc));
return;
}
this.wsClient = t;
t.t(new j2(this));
this.wsClient.v(new k2(this));
this.wsClient.l(new l2(this));
invokeCallback(getOnOpenCallback(), new Object[0]);
}
public void onWebSocketConnected(T t, d dVar) {
this.wsClient = t;
t.t(new j2(this));
this.wsClient.v(new k2(this));
this.wsClient.l(new l2(this));
invokeCallback(getOnOpenCallback(), new Object[0]);
}
public void onWebSocketNotHttpError(a2.k kVar) {
invokeCallback(getOnErrorCallback(), "Request to WS server made, but it is not HTTP");
}
public void onWebSocketStringAvailable(String str) {
invokeCallback(getOnMessageCallback(), str);
}
private void reverse(byte[] bArr) {
if (bArr == null) {
return;
}
int length = bArr.length - 1;
for (int i = 0; length > i; i++) {
byte b = bArr[length];
bArr[length] = bArr[i];
bArr[i] = b;
length--;
}
}
private void setSecureCertificate() {
Set<X509Certificate> set;
String scheme = Uri.parse(getUrl()).getScheme();
if (TextUtils.isEmpty(scheme)) {
return;
}
if ((scheme.compareTo("wss") != 0 && scheme.compareTo("https") != 0) || (set = this.setExtraCas) == null || set.isEmpty()) {
return;
}
if (this.httpClient == null) {
this.httpClient = h.B();
}
C0594b a = new C0594b.C0014b().b(this.context).c(true).g(false).d(this.setExtraCas).a();
p r = this.httpClient.r();
r.M(a.s());
r.N(new TrustManager[]{a});
}
@Override
public Object GetPropertyManager(String str, Object[] objArr) {
return null;
}
@Override
public W GetTypeInfo(String str) {
return null;
}
@Override
public Object Invoke(String str, EnumC0975b enumC0975b, Object[] objArr) {
throw new UnsupportedOperationException("WebSocket object is not available on VBScript");
}
@Override
public Object call(org.mozilla.javascript.Context context, Scriptable scriptable, Scriptable scriptable2, Object[] objArr) {
return new XOneWebSocket(this.context, objArr);
}
@ScriptAllowed
public void close() {
T t = this.wsClient;
if (t != null) {
t.end();
this.wsClient.close();
}
b bVar = this.wsServer;
if (bVar != null) {
bVar.m(false);
}
}
@Override
public String getDefaultMethod() {
return null;
}
@Override
public String getName() {
return TAG;
}
@Override
public V getScope() {
return null;
}
@ScriptAllowed
public void send(Object... objArr) {
String y = t.y(objArr[0]);
T t = this.wsClient;
if (t != null) {
t.j(y);
}
}
public XOneWebSocket(Context context, Object[] objArr) {
this.context = context.getApplicationContext();
getParameters(objArr);
XOneJavascript.addFunctions(this);
setSecureCertificate();
if (isListenInsecure()) {
listenInsecure();
return;
}
if (isListenSecure()) {
listenSecure();
return;
}
String url = getUrl();
String protocol = getProtocol();
if (this.httpClient == null) {
this.httpClient = h.B();
C0594b a = new C0594b.C0014b().b(context).g(true).a();
p r = this.httpClient.r();
r.M(a.s());
r.N(new TrustManager[]{a});
}
this.httpClient.F(url, protocol, new U() {
public final void a(Exception exc, a2.T t) {
XOneWebSocket.this.onWebSocketCompleted(exc, t);
}
});
}
public void onWebSocketDataAvailable(q qVar, H h) {
}
}