Upload files to "src/openonyx/network"
This commit is contained in:
1 parent
43d62845c7
commit
9016332a98
5 files changed
+662
No files matched your search
@@ -0,0 +1,229 @@
|
||||
package openonyx.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import openonyx.core.OnyxClient;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public final class HttpProxyHandler extends ChannelDuplexHandler {
|
||||
private final InetSocketAddress inetSocketAddress;
|
||||
private InetSocketAddress inetSocketAddress2;
|
||||
private final String h;
|
||||
private static final byte[] l;
|
||||
private final String I;
|
||||
private final String d;
|
||||
private final int i;
|
||||
private ByteBuf byteBuf;
|
||||
private ScheduledFuture<?> scheduledFuture;
|
||||
private ChannelPromise channelPromise;
|
||||
|
||||
@Override
|
||||
public void handlerRemoved(ChannelHandlerContext channelHandlerContext) {
|
||||
if (this.byteBuf != null) {
|
||||
this.byteBuf.release();
|
||||
this.byteBuf = null;
|
||||
}
|
||||
|
||||
this.L();
|
||||
}
|
||||
|
||||
private void L() {
|
||||
if (this.scheduledFuture != null) {
|
||||
this.scheduledFuture.cancel(false);
|
||||
this.scheduledFuture = null;
|
||||
}
|
||||
}
|
||||
|
||||
public HttpProxyHandler(InetSocketAddress inetSocketAddress, String string, int i, String string1, String string2) {
|
||||
this.inetSocketAddress = inetSocketAddressx;
|
||||
this.I = string == null ? "" : string;
|
||||
this.i = ix;
|
||||
this.h = string1 == null ? "" : string1;
|
||||
this.d = string2 == null ? "" : string2;
|
||||
}
|
||||
|
||||
static {
|
||||
byte[] b = new byte[4];
|
||||
boolean bl = true;
|
||||
b[0] = 13;
|
||||
b[1] = 10;
|
||||
b[2] = 13;
|
||||
b[3] = 10;
|
||||
l = b;
|
||||
}
|
||||
|
||||
// $VF: Could not inline inconsistent finally blocks
|
||||
// Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext channelHandlerContext, Object i) {
|
||||
if (ix instanceof ByteBuf byteBufx) {
|
||||
HttpProxyHandler httpProxyHandler1 = this;
|
||||
|
||||
try {
|
||||
if (httpProxyHandler1.byteBuf == null) {
|
||||
this.byteBuf = channelHandlerContext.alloc().buffer(byteBufx.readableBytes());
|
||||
}
|
||||
|
||||
this.byteBuf.writeBytes(byteBufx);
|
||||
} catch (Throwable throwable) {
|
||||
byteBufx.release();
|
||||
throw throwable;
|
||||
}
|
||||
|
||||
byteBufx.release();
|
||||
if ((ix = L(this.byteBuf)) >= 0) {
|
||||
int j;
|
||||
if ((j = L(this.byteBuf.toString(this.byteBuf.readerIndex(), ix - this.byteBuf.readerIndex(), StandardCharsets.US_ASCII))) >= 200 && j < 300) {
|
||||
this.byteBuf.skipBytes(ix - this.byteBuf.readerIndex() + l.length);
|
||||
ByteBuf byteBuf1 = this.byteBuf.isReadable() ? this.byteBuf.readSlice(this.byteBuf.readableBytes()).retain() : null;
|
||||
this.L();
|
||||
Logger logger = OnyxClient.LOGGER;
|
||||
Object[] objects = new Object[2];
|
||||
boolean bl = true;
|
||||
objects[0] = this.I;
|
||||
objects[1] = this.i;
|
||||
logger.info("HTTP proxy tunnel established to {}:{}", objects);
|
||||
channelHandlerContext.fireChannelActive();
|
||||
this.channelPromise.trySuccess();
|
||||
if (byteBuf1 != null) {
|
||||
channelHandlerContext.fireChannelRead(byteBuf1);
|
||||
}
|
||||
|
||||
channelHandlerContext.pipeline().remove(this);
|
||||
} else {
|
||||
this.L(
|
||||
channelHandlerContext,
|
||||
new IllegalStateException(new StringBuilder().insert(0, "HTTP proxy CONNECT failed (").append(j).append(")").toString())
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
channelHandlerContext.fireChannelRead(ix);
|
||||
}
|
||||
}
|
||||
|
||||
private void L(ChannelHandlerContext channelHandlerContext, Throwable throwable) {
|
||||
this.L();
|
||||
Logger logger = OnyxClient.LOGGER;
|
||||
Object[] objects = new Object[3];
|
||||
boolean bl = true;
|
||||
objects[0] = this.I;
|
||||
objects[1] = this.i;
|
||||
objects[2] = throwable.getMessage();
|
||||
logger.warn("HTTP proxy tunnel to {}:{} failed: {}", objects);
|
||||
if (this.channelPromise != null) {
|
||||
this.channelPromise.tryFailure(throwable);
|
||||
}
|
||||
|
||||
channelHandlerContext.close();
|
||||
}
|
||||
|
||||
private static int L(String string) {
|
||||
String string1 = string;
|
||||
String[] strings;
|
||||
if ((strings = string1.split("\\s+", 3)).length < 2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
try {
|
||||
return Integer.parseInt(strings[1]);
|
||||
} catch (NumberFormatException numberFormatException) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext channelHandlerContext) {
|
||||
this.L(channelHandlerContext);
|
||||
}
|
||||
|
||||
private static int L(ByteBuf byteBuf) {
|
||||
ByteBuf byteBuf1 = byteBufx;
|
||||
|
||||
int ix;
|
||||
for (int k = ix = byteBuf1.readerIndex(); k <= byteBuf1.writerIndex() - l.length; k = ++ix) {
|
||||
boolean bl = true;
|
||||
int j;
|
||||
k = j = 0;
|
||||
|
||||
while (true) {
|
||||
if (k >= l.length) {
|
||||
bl1 = bl;
|
||||
break;
|
||||
}
|
||||
|
||||
if (byteBuf1.getByte(ix + j) != l[j]) {
|
||||
bl1 = bl = false;
|
||||
break;
|
||||
}
|
||||
|
||||
k = ++j;
|
||||
}
|
||||
|
||||
if (bl1) {
|
||||
return ix;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(ChannelHandlerContext channelHandlerContext, SocketAddress socketAddress, SocketAddress socketAddress1, ChannelPromise channelPromise) {
|
||||
if (socketAddress instanceof InetSocketAddress inetSocketAddressx) {
|
||||
this.inetSocketAddress2 = inetSocketAddressx;
|
||||
this.channelPromise = channelPromisex;
|
||||
this.scheduledFuture = channelHandlerContext.executor()
|
||||
.schedule(() -> this.L(channelHandlerContext, new IllegalStateException("HTTP proxy connection timed out")), 10L, TimeUnit.SECONDS);
|
||||
channelHandlerContext.connect(this.inetSocketAddress, socketAddress1, channelHandlerContext.newPromise()).addListener(future -> {
|
||||
if (!future.isSuccess()) {
|
||||
this.L(channelHandlerContext, future.cause());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
channelPromisex.tryFailure(new IllegalArgumentException("HTTP proxy requires an internet address"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext channelHandlerContext, Throwable throwable) {
|
||||
this.L(channelHandlerContext, throwable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext channelHandlerContext) {
|
||||
this.L(channelHandlerContext, new IllegalStateException("HTTP proxy closed the connection"));
|
||||
channelHandlerContext.fireChannelInactive();
|
||||
}
|
||||
|
||||
private void L(ChannelHandlerContext channelHandlerContext) {
|
||||
HttpProxyHandler httpProxyHandler1 = this;
|
||||
String string1 = httpProxyHandler1.I.isBlank() ? httpProxyHandler1.inetSocketAddress2.getAddress().getHostAddress() : httpProxyHandler1.I;
|
||||
if (string1.indexOf(58) >= 0) {
|
||||
string1 = new StringBuilder().insert(0, "[").append(string1).append("]").toString();
|
||||
}
|
||||
|
||||
String string2 = new StringBuilder().insert(0, string1).append(":").append(httpProxyHandler1.i).toString();
|
||||
String string3 = new StringBuilder().insert(0, "CONNECT ").append(string2).append(" HTTP/1.1\r\nHost: ").append(string2).append("\r\n").toString();
|
||||
if (!httpProxyHandler1.h.isBlank()) {
|
||||
String string = new StringBuilder().insert(0, httpProxyHandler1.h).append(":").append(httpProxyHandler1.d).toString();
|
||||
string3 = new StringBuilder()
|
||||
.insert(0, string3)
|
||||
.append("Proxy-Authorization: Basic ")
|
||||
.append(Base64.getEncoder().encodeToString(string.getBytes(StandardCharsets.UTF_8)))
|
||||
.append("\r\n")
|
||||
.toString();
|
||||
}
|
||||
|
||||
channelHandlerContext.writeAndFlush(Unpooled.copiedBuffer(new StringBuilder().insert(0, string3).append("\r\n").toString(), StandardCharsets.US_ASCII));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package openonyx.network;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import openonyx.connection.ProxySettingsMode;
|
||||
|
||||
record LocalProxyServerData(ProxySettingsMode protocol, InetSocketAddress upstream, String username, String password) {
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package openonyx.network;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
record LocalProxyServerData2(String host, int port) {
|
||||
private String d() {
|
||||
LocalProxyServerData2 localProxyServerData21 = this;
|
||||
String string = localProxyServerData21.host.indexOf(58) >= 0
|
||||
? new StringBuilder().insert(0, "[").append(localProxyServerData21.host).append("]").toString()
|
||||
: localProxyServerData21.host;
|
||||
return new StringBuilder().insert(0, string).append(":").append(localProxyServerData21.port).toString();
|
||||
}
|
||||
|
||||
// $VF: Handled exception range with multiple entry points by splitting it
|
||||
// $VF: Duplicated exception handlers to handle obfuscated exceptions
|
||||
private static LocalProxyServerData2 L(String string) throws IOException {
|
||||
String string3 = string;
|
||||
String string1;
|
||||
String string4;
|
||||
if (string3.startsWith("[")) {
|
||||
int i;
|
||||
if ((i = string3.indexOf(93)) < 0 || i + 2 > string3.length() || string3.charAt(i + 1) != ':') {
|
||||
throw new IOException("Invalid CONNECT target");
|
||||
}
|
||||
|
||||
string1 = string3.substring(1, i);
|
||||
string4 = string3.substring(i + 2);
|
||||
} else {
|
||||
int j;
|
||||
if ((j = string3.lastIndexOf(58)) <= 0 || j == string3.length() - 1) {
|
||||
throw new IOException("Invalid CONNECT target");
|
||||
}
|
||||
|
||||
string1 = string3.substring(0, j);
|
||||
String string2 = string3.substring(j + 1);
|
||||
|
||||
try {
|
||||
string4 = string2;
|
||||
} catch (NumberFormatException numberFormatException1) {
|
||||
throw new IOException("Invalid CONNECT target port", numberFormatException1);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
int k;
|
||||
if ((k = Integer.parseInt(string4)) >= 1 && k <= 65535) {
|
||||
return new LocalProxyServerData2(string1, k);
|
||||
} else {
|
||||
throw new IOException("Invalid CONNECT target port");
|
||||
}
|
||||
} catch (NumberFormatException numberFormatException) {
|
||||
throw new IOException("Invalid CONNECT target port", numberFormatException);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,349 @@
|
||||
package openonyx.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import openonyx.core.OnyxClient;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public final class Socks5ProxyHandler extends ChannelDuplexHandler {
|
||||
private final String J;
|
||||
private static final int D = 3;
|
||||
private static final int c = 2;
|
||||
private final InetSocketAddress inetSocketAddress;
|
||||
private static final int k = 0;
|
||||
private final int g;
|
||||
private final String M;
|
||||
private InetSocketAddress inetSocketAddress2;
|
||||
private final String j;
|
||||
private ByteBuf byteBuf;
|
||||
private static final int h = 5;
|
||||
private Socks5ProxyHandlerMode socks5ProxyHandlerMode = Socks5ProxyHandlerMode.CONNECTING;
|
||||
private ScheduledFuture<?> scheduledFuture;
|
||||
private static final int d = 1;
|
||||
private static final int i = 1;
|
||||
private ChannelPromise channelPromise;
|
||||
private static final int H = 4;
|
||||
private static final int e = 1;
|
||||
|
||||
@Override
|
||||
public void handlerRemoved(ChannelHandlerContext channelHandlerContext) {
|
||||
if (this.byteBuf != null) {
|
||||
this.byteBuf.release();
|
||||
this.byteBuf = null;
|
||||
}
|
||||
|
||||
this.L();
|
||||
}
|
||||
|
||||
private void i(ChannelHandlerContext channelHandlerContext) {
|
||||
Socks5ProxyHandler socks5ProxyHandler1 = this;
|
||||
byte[] b;
|
||||
if ((b = socks5ProxyHandler1.J.getBytes(StandardCharsets.UTF_8)).length > 0 && b.length <= 255) {
|
||||
ByteBuf byteBuf1 = Unpooled.buffer(7 + b.length);
|
||||
byteBuf1.writeByte(5);
|
||||
byteBuf1.writeByte(1);
|
||||
byteBuf1.writeByte(0);
|
||||
byteBuf1.writeByte(3);
|
||||
byteBuf1.writeByte(b.length);
|
||||
byteBuf1.writeBytes(b);
|
||||
byteBuf1.writeShort(socks5ProxyHandler1.g);
|
||||
channelHandlerContext.writeAndFlush(byteBuf1);
|
||||
} else {
|
||||
byte[] cx;
|
||||
int ix = (cx = socks5ProxyHandler1.inetSocketAddress2.getAddress().getAddress()).length == 4 ? 1 : 4;
|
||||
ByteBuf byteBufx;
|
||||
(byteBufx = Unpooled.buffer(6 + cx.length)).writeByte(5);
|
||||
byteBufx.writeByte(1);
|
||||
byteBufx.writeByte(0);
|
||||
byteBufx.writeByte(ix);
|
||||
byteBufx.writeBytes(cx);
|
||||
byteBufx.writeShort(socks5ProxyHandler1.g);
|
||||
channelHandlerContext.writeAndFlush(byteBufx);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean i(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) {
|
||||
switch (this.socks5ProxyHandlerMode) {
|
||||
case CONNECT:
|
||||
while (false) {
|
||||
}
|
||||
|
||||
return this.d(channelHandlerContext, byteBufx);
|
||||
case CONNECTED:
|
||||
return this.L(channelHandlerContext, byteBufx);
|
||||
case CONNECTING:
|
||||
return this.D(channelHandlerContext, byteBufx);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void L() {
|
||||
if (this.scheduledFuture != null) {
|
||||
this.scheduledFuture.cancel(false);
|
||||
this.scheduledFuture = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext channelHandlerContext) {
|
||||
if (this.socks5ProxyHandlerMode != Socks5ProxyHandlerMode.CONNECTED) {
|
||||
this.L(channelHandlerContext, new IllegalStateException("SOCKS5 proxy closed the connection"));
|
||||
}
|
||||
|
||||
channelHandlerContext.fireChannelInactive();
|
||||
}
|
||||
|
||||
private boolean D(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) {
|
||||
if (byteBufx.readableBytes() < 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
byteBufx.markReaderIndex();
|
||||
short s = byteBufx.readUnsignedByte();
|
||||
short t = byteBufx.readUnsignedByte();
|
||||
byteBufx.skipBytes(1);
|
||||
|
||||
short u = switch (byteBufx.readUnsignedByte()) {
|
||||
case 1 -> {
|
||||
yield 4;
|
||||
|
||||
while (false) {
|
||||
}
|
||||
}
|
||||
default -> -1;
|
||||
case 3 -> byteBufx.isReadable() ? byteBufx.readUnsignedByte() : -1;
|
||||
case 4 -> 16;
|
||||
};
|
||||
if (u < 0) {
|
||||
this.L(channelHandlerContext, new IllegalStateException("SOCKS5 proxy returned an invalid address"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (byteBufx.readableBytes() < u + 2) {
|
||||
byteBufx.resetReaderIndex();
|
||||
return false;
|
||||
}
|
||||
|
||||
byteBufx.skipBytes(u + 2);
|
||||
if (s == 5 && t == 0) {
|
||||
this.socks5ProxyHandlerMode = Socks5ProxyHandlerMode.CONNECTED;
|
||||
ByteBuf byteBuf1 = byteBufx.isReadable() ? byteBufx.readSlice(byteBufx.readableBytes()).retain() : null;
|
||||
this.L();
|
||||
Logger logger = OnyxClient.LOGGER;
|
||||
Object[] objects = new Object[2];
|
||||
boolean bl = true;
|
||||
objects[0] = this.J;
|
||||
objects[1] = this.g;
|
||||
logger.info("SOCKS5 tunnel established to {}:{}", objects);
|
||||
channelHandlerContext.fireChannelActive();
|
||||
this.channelPromise.trySuccess();
|
||||
if (byteBuf1 != null) {
|
||||
channelHandlerContext.fireChannelRead(byteBuf1);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
this.L(channelHandlerContext, new IllegalStateException(new StringBuilder().insert(0, "SOCKS5 CONNECT failed: ").append(L(t)).toString()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void D(ChannelHandlerContext channelHandlerContext) {
|
||||
Socks5ProxyHandler socks5ProxyHandler1 = this;
|
||||
boolean bl = !socks5ProxyHandler1.M.isBlank();
|
||||
ByteBuf byteBufx = Unpooled.buffer(3);
|
||||
byteBufx.writeByte(5);
|
||||
byteBufx.writeByte(1);
|
||||
byteBufx.writeByte(bl ? 2 : 0);
|
||||
channelHandlerContext.writeAndFlush(byteBufx);
|
||||
}
|
||||
|
||||
private void L(ChannelHandlerContext channelHandlerContext, Throwable throwable) {
|
||||
if (this.socks5ProxyHandlerMode != Socks5ProxyHandlerMode.FAILED && this.socks5ProxyHandlerMode != Socks5ProxyHandlerMode.CONNECTED) {
|
||||
this.socks5ProxyHandlerMode = Socks5ProxyHandlerMode.FAILED;
|
||||
this.L();
|
||||
Logger logger = OnyxClient.LOGGER;
|
||||
Object[] objects = new Object[3];
|
||||
boolean bl = true;
|
||||
objects[0] = this.J;
|
||||
objects[1] = this.g;
|
||||
objects[2] = throwable.getMessage();
|
||||
logger.warn("SOCKS5 tunnel to {}:{} failed: {}", objects);
|
||||
if (this.channelPromise != null) {
|
||||
this.channelPromise.tryFailure(throwable);
|
||||
}
|
||||
|
||||
channelHandlerContext.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void d(ChannelHandlerContext channelHandlerContext) {
|
||||
Socks5ProxyHandler socks5ProxyHandler1 = this;
|
||||
byte[] b = socks5ProxyHandler1.M.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] cx = socks5ProxyHandler1.j.getBytes(StandardCharsets.UTF_8);
|
||||
if (b.length != 0 && b.length <= 255 && cx.length <= 255) {
|
||||
ByteBuf byteBufx = Unpooled.buffer(3 + b.length + cx.length);
|
||||
byteBufx.writeByte(1);
|
||||
byteBufx.writeByte(b.length);
|
||||
byteBufx.writeBytes(b);
|
||||
byteBufx.writeByte(cx.length);
|
||||
byteBufx.writeBytes(cx);
|
||||
channelHandlerContext.writeAndFlush(byteBufx);
|
||||
} else {
|
||||
socks5ProxyHandler1.L(channelHandlerContext, new IllegalArgumentException("SOCKS5 credentials must be at most 255 bytes"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext channelHandlerContext, Throwable throwable) {
|
||||
this.L(channelHandlerContext, throwable);
|
||||
}
|
||||
|
||||
private boolean d(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) {
|
||||
if (byteBufx.readableBytes() < 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
short t = byteBufx.readUnsignedByte();
|
||||
short s = byteBufx.readUnsignedByte();
|
||||
if (t != 5) {
|
||||
this.L(channelHandlerContext, new IllegalStateException("SOCKS5 proxy returned an invalid greeting"));
|
||||
} else if (s == 0) {
|
||||
this.socks5ProxyHandlerMode = Socks5ProxyHandlerMode.CONNECT;
|
||||
this.i(channelHandlerContext);
|
||||
} else if (s == 2 && !this.M.isBlank()) {
|
||||
this.socks5ProxyHandlerMode = Socks5ProxyHandlerMode.AUTH;
|
||||
this.d(channelHandlerContext);
|
||||
} else {
|
||||
this.L(channelHandlerContext, new IllegalStateException("SOCKS5 proxy rejected the configured authentication"));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public Socks5ProxyHandler(InetSocketAddress inetSocketAddress, String string, int i, String string1, String string2) {
|
||||
this.inetSocketAddress = inetSocketAddressx;
|
||||
this.J = string == null ? "" : string;
|
||||
this.g = ix;
|
||||
this.M = string1 == null ? "" : string1;
|
||||
this.j = string2 == null ? "" : string2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(ChannelHandlerContext channelHandlerContext, SocketAddress socketAddress, SocketAddress socketAddress1, ChannelPromise channelPromise) {
|
||||
if (socketAddress instanceof InetSocketAddress inetSocketAddressx) {
|
||||
this.inetSocketAddress2 = inetSocketAddressx;
|
||||
this.channelPromise = channelPromisex;
|
||||
this.scheduledFuture = channelHandlerContext.executor()
|
||||
.schedule(() -> this.L(channelHandlerContext, new IllegalStateException("SOCKS5 proxy connection timed out")), 10L, TimeUnit.SECONDS);
|
||||
channelHandlerContext.connect(this.inetSocketAddress, socketAddress1, channelHandlerContext.newPromise()).addListener(future -> {
|
||||
if (!future.isSuccess()) {
|
||||
this.L(channelHandlerContext, future.cause());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
channelPromisex.tryFailure(new IllegalArgumentException("SOCKS5 requires an internet address"));
|
||||
}
|
||||
}
|
||||
|
||||
private static String L(int i) {
|
||||
switch (ix) {
|
||||
case 1:
|
||||
while (false) {
|
||||
}
|
||||
|
||||
return "general failure";
|
||||
case 2:
|
||||
return "connection not allowed by ruleset";
|
||||
case 3:
|
||||
return "network unreachable";
|
||||
case 4:
|
||||
return "host unreachable";
|
||||
case 5:
|
||||
return "connection refused";
|
||||
case 6:
|
||||
return "TTL expired";
|
||||
case 7:
|
||||
return "command not supported";
|
||||
case 8:
|
||||
return "address type not supported";
|
||||
default:
|
||||
return new StringBuilder().insert(0, "status ").append(ix).toString();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext channelHandlerContext) {
|
||||
if (this.socks5ProxyHandlerMode == Socks5ProxyHandlerMode.CONNECTING) {
|
||||
this.socks5ProxyHandlerMode = Socks5ProxyHandlerMode.GREETING;
|
||||
this.D(channelHandlerContext);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean L(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) {
|
||||
if (byteBufx.readableBytes() < 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
short t = byteBufx.readUnsignedByte();
|
||||
short s = byteBufx.readUnsignedByte();
|
||||
if (t == 1 && s == 0) {
|
||||
this.socks5ProxyHandlerMode = Socks5ProxyHandlerMode.CONNECT;
|
||||
this.i(channelHandlerContext);
|
||||
} else {
|
||||
this.L(channelHandlerContext, new IllegalStateException("SOCKS5 proxy rejected the username or password"));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// $VF: Could not inline inconsistent finally blocks
|
||||
// Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext channelHandlerContext, Object object) {
|
||||
Socks5ProxyHandler socks5ProxyHandler1 = this;
|
||||
if (object instanceof ByteBuf byteBufx) {
|
||||
Socks5ProxyHandler socks5ProxyHandler2 = socks5ProxyHandler1;
|
||||
|
||||
try {
|
||||
if (socks5ProxyHandler2.byteBuf == null) {
|
||||
socks5ProxyHandler1.byteBuf = channelHandlerContext.alloc().buffer(byteBufx.readableBytes());
|
||||
}
|
||||
|
||||
socks5ProxyHandler1.byteBuf.writeBytes(byteBufx);
|
||||
|
||||
while (
|
||||
socks5ProxyHandler1.socks5ProxyHandlerMode != Socks5ProxyHandlerMode.CONNECTED
|
||||
&& socks5ProxyHandler1.socks5ProxyHandlerMode != Socks5ProxyHandlerMode.FAILED
|
||||
&& socks5ProxyHandler1.byteBuf != null
|
||||
&& socks5ProxyHandler1.byteBuf.isReadable()
|
||||
&& socks5ProxyHandler1.i(channelHandlerContext, socks5ProxyHandler1.byteBuf)
|
||||
) {
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
byteBufx.release();
|
||||
throw throwable;
|
||||
}
|
||||
|
||||
byteBufx.release();
|
||||
if (socks5ProxyHandler1.socks5ProxyHandlerMode == Socks5ProxyHandlerMode.CONNECTED) {
|
||||
channelHandlerContext.pipeline().remove(socks5ProxyHandler1);
|
||||
} else {
|
||||
if (socks5ProxyHandler1.socks5ProxyHandlerMode != Socks5ProxyHandlerMode.CONNECTED && socks5ProxyHandler1.byteBuf != null) {
|
||||
socks5ProxyHandler1.byteBuf.discardReadBytes();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
channelHandlerContext.fireChannelRead(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package openonyx.network;
|
||||
|
||||
enum Socks5ProxyHandlerMode {
|
||||
GREETING,
|
||||
CONNECT,
|
||||
CONNECTED,
|
||||
CONNECTING,
|
||||
FAILED,
|
||||
AUTH;
|
||||
|
||||
private static Socks5ProxyHandlerMode[] L() {
|
||||
Socks5ProxyHandlerMode[] socks5ProxyHandlerModes = new Socks5ProxyHandlerMode[6];
|
||||
boolean bl = true;
|
||||
socks5ProxyHandlerModes[0] = CONNECTING;
|
||||
socks5ProxyHandlerModes[1] = GREETING;
|
||||
socks5ProxyHandlerModes[2] = AUTH;
|
||||
socks5ProxyHandlerModes[3] = CONNECT;
|
||||
socks5ProxyHandlerModes[4] = CONNECTED;
|
||||
socks5ProxyHandlerModes[5] = FAILED;
|
||||
return socks5ProxyHandlerModes;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user