[FIX] Удалена функциональность прокси, хук pipeline

This commit is contained in:
Gravit 2019-08-09 22:26:14 +07:00
parent 58f8269c19
commit 9f5c2666b0
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
8 changed files with 5 additions and 142 deletions

View file

@ -290,7 +290,6 @@ public class NettyConfig {
public NettyPerformanceConfig performance; public NettyPerformanceConfig performance;
public NettyBindAddress[] binds; public NettyBindAddress[] binds;
public LogLevel logLevel = LogLevel.DEBUG; public LogLevel logLevel = LogLevel.DEBUG;
public NettyProxyConfig proxy = new NettyProxyConfig();
} }
public class NettyPerformanceConfig { public class NettyPerformanceConfig {
@ -299,15 +298,6 @@ public class NettyPerformanceConfig {
public int workerThread; public int workerThread;
} }
public class NettyProxyConfig {
public boolean enabled;
public String address = "ws://localhost:9275/api";
public String login = "login";
public String password = "password";
public String auth_id = "std";
public ArrayList<String> requests = new ArrayList<>();
}
public class NettyBindAddress { public class NettyBindAddress {
public String address; public String address;
public int port; public int port;

View file

@ -8,7 +8,6 @@
public class Client { public class Client {
public long session; public long session;
public boolean proxy;
public String auth_id; public String auth_id;
public long timestamp; public long timestamp;
public Type type; public Type type;

View file

@ -22,6 +22,8 @@
import pro.gravit.launchserver.socket.handlers.NettyIpForwardHandler; import pro.gravit.launchserver.socket.handlers.NettyIpForwardHandler;
import pro.gravit.launchserver.socket.handlers.WebSocketFrameHandler; import pro.gravit.launchserver.socket.handlers.WebSocketFrameHandler;
import pro.gravit.launchserver.socket.handlers.fileserver.FileServerHandler; import pro.gravit.launchserver.socket.handlers.fileserver.FileServerHandler;
import pro.gravit.utils.BiHookSet;
import pro.gravit.utils.HookSet;
import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.JVMHelper;
import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.LogHelper;
@ -30,6 +32,7 @@ public class LauncherNettyServer implements AutoCloseable {
public final EventLoopGroup bossGroup; public final EventLoopGroup bossGroup;
public final EventLoopGroup workerGroup; public final EventLoopGroup workerGroup;
public final WebSocketService service; public final WebSocketService service;
public final BiHookSet<NettyConnectContext,SocketChannel> pipelineHook = new BiHookSet<>();
private static final String WEBSOCKET_PATH = "/api"; private static final String WEBSOCKET_PATH = "/api";
public LauncherNettyServer(LaunchServer server) { public LauncherNettyServer(LaunchServer server) {
@ -65,19 +68,9 @@ public void initChannel(SocketChannel ch) {
if (server.config.netty.fileServerEnabled) if (server.config.netty.fileServerEnabled)
pipeline.addLast(new FileServerHandler(server.updatesDir, true)); pipeline.addLast(new FileServerHandler(server.updatesDir, true));
pipeline.addLast(new WebSocketFrameHandler(context, server, service)); pipeline.addLast(new WebSocketFrameHandler(context, server, service));
pipelineHook.hook(context, ch);
} }
}); });
if (config.proxy != null && config.proxy.enabled) {
LogHelper.info("Connect to main server %s");
Request.service = StandartClientWebSocketService.initWebSockets(config.proxy.address, false);
AuthRequest authRequest = new AuthRequest(config.proxy.login, config.proxy.password, config.proxy.auth_id, AuthRequest.ConnectTypes.PROXY);
authRequest.initProxy = true;
try {
authRequest.request();
} catch (Exception e) {
LogHelper.error(e);
}
}
} }
public ChannelFuture bind(InetSocketAddress address) { public ChannelFuture bind(InetSocketAddress address) {

View file

@ -2,8 +2,6 @@
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.HashMap; import java.util.HashMap;
import java.util.Random;
import java.util.UUID;
import com.google.gson.Gson; import com.google.gson.Gson;
@ -15,18 +13,13 @@
import pro.gravit.launcher.Launcher; import pro.gravit.launcher.Launcher;
import pro.gravit.launcher.events.ExceptionEvent; import pro.gravit.launcher.events.ExceptionEvent;
import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.events.RequestEvent;
import pro.gravit.launcher.events.request.AuthRequestEvent;
import pro.gravit.launcher.events.request.ErrorRequestEvent; import pro.gravit.launcher.events.request.ErrorRequestEvent;
import pro.gravit.launcher.request.Request;
import pro.gravit.launcher.request.RequestException;
import pro.gravit.launcher.request.WebSocketEvent; import pro.gravit.launcher.request.WebSocketEvent;
import pro.gravit.launcher.request.admin.ProxyRequest;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.socket.response.WebSocketServerResponse; import pro.gravit.launchserver.socket.response.WebSocketServerResponse;
import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.launchserver.socket.response.SimpleResponse;
import pro.gravit.launchserver.socket.response.admin.AddLogListenerResponse; import pro.gravit.launchserver.socket.response.admin.AddLogListenerResponse;
import pro.gravit.launchserver.socket.response.admin.ExecCommandResponse; import pro.gravit.launchserver.socket.response.admin.ExecCommandResponse;
import pro.gravit.launchserver.socket.response.admin.ProxyCommandResponse;
import pro.gravit.launchserver.socket.response.auth.*; import pro.gravit.launchserver.socket.response.auth.*;
import pro.gravit.launchserver.socket.response.profile.BatchProfileByUsername; import pro.gravit.launchserver.socket.response.profile.BatchProfileByUsername;
import pro.gravit.launchserver.socket.response.profile.ProfileByUUIDResponse; import pro.gravit.launchserver.socket.response.profile.ProfileByUUIDResponse;
@ -61,58 +54,6 @@ public WebSocketService(ChannelGroup channels, LaunchServer server) {
public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) { public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) {
String request = frame.text(); String request = frame.text();
WebSocketServerResponse response = gson.fromJson(request, WebSocketServerResponse.class); WebSocketServerResponse response = gson.fromJson(request, WebSocketServerResponse.class);
if (server.config.netty.proxy.enabled) {
if (server.config.netty.proxy.requests.contains(response.getType())) {
UUID origRequestUUID = null;
if (response instanceof SimpleResponse) {
SimpleResponse simpleResponse = (SimpleResponse) response;
simpleResponse.server = server;
simpleResponse.service = this;
simpleResponse.ctx = ctx;
if (ip != null) simpleResponse.ip = ip;
else simpleResponse.ip = IOHelper.getIP(ctx.channel().remoteAddress());
origRequestUUID = simpleResponse.requestUUID;
}
LogHelper.debug("Proxy %s request", response.getType());
if (client.session == 0) client.session = new Random().nextLong();
ProxyRequest proxyRequest = new ProxyRequest(response, client.session);
if (response instanceof SimpleResponse) {
((SimpleResponse) response).requestUUID = proxyRequest.requestUUID;
}
proxyRequest.isCheckSign = client.checkSign;
try {
WebSocketEvent result = proxyRequest.request();
if (result instanceof AuthRequestEvent) {
LogHelper.debug("Client auth params get successful");
AuthRequestEvent authRequestEvent = (AuthRequestEvent) result;
client.isAuth = true;
client.session = authRequestEvent.session;
if (authRequestEvent.playerProfile != null)
client.username = authRequestEvent.playerProfile.username;
}
if (result instanceof Request && response instanceof SimpleResponse) {
((Request) result).requestUUID = origRequestUUID;
}
sendObject(ctx, result);
} catch (RequestException e) {
sendObject(ctx, new ErrorRequestEvent(e.getMessage()));
} catch (Exception e) {
LogHelper.error(e);
RequestEvent event;
if (server.config.netty.sendExceptionEnabled) {
event = new ExceptionEvent(e);
} else {
event = new ErrorRequestEvent("Fatal server error. Contact administrator");
}
if (response instanceof SimpleResponse) {
event.requestUUID = ((SimpleResponse) response).requestUUID;
}
sendObject(ctx, event);
}
return;
}
}
process(ctx, response, client, ip); process(ctx, response, client, ip);
} }
@ -168,7 +109,6 @@ public static void registerResponses() {
providers.register("getSecureToken", GetSecureTokenResponse.class); providers.register("getSecureToken", GetSecureTokenResponse.class);
providers.register("verifySecureToken", VerifySecureTokenResponse.class); providers.register("verifySecureToken", VerifySecureTokenResponse.class);
providers.register("getAvailabilityAuth", GetAvailabilityAuthResponse.class); providers.register("getAvailabilityAuth", GetAvailabilityAuthResponse.class);
providers.register("proxy", ProxyCommandResponse.class);
providers.register("register", RegisterResponse.class); providers.register("register", RegisterResponse.class);
} }

View file

@ -1,28 +0,0 @@
package pro.gravit.launchserver.socket.response.admin;
import io.netty.channel.ChannelHandlerContext;
import pro.gravit.launchserver.socket.Client;
import pro.gravit.launchserver.socket.response.WebSocketServerResponse;
import pro.gravit.launchserver.socket.response.SimpleResponse;
public class ProxyCommandResponse extends SimpleResponse {
public WebSocketServerResponse response;
public long session;
public boolean isCheckSign;
@Override
public void execute(ChannelHandlerContext ctx, Client client) throws Exception {
if (!client.proxy) {
sendError("Proxy server error");
return;
}
Client real_client = server.sessionManager.getOrNewClient(session);
real_client.checkSign = isCheckSign;
response.execute(ctx, real_client);
}
@Override
public String getType() {
return "proxy";
}
}

View file

@ -45,12 +45,11 @@ public AuthResponse(String login, String password, String auth_id, OshiHWID hwid
} }
public String auth_id; public String auth_id;
public boolean initProxy;
public ConnectTypes authType; public ConnectTypes authType;
public HWID hwid; public HWID hwid;
public enum ConnectTypes { public enum ConnectTypes {
SERVER, CLIENT, BOT, API SERVER, CLIENT, API
} }
@Override @Override
@ -111,9 +110,6 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti
clientData.username = login; clientData.username = login;
result.accessToken = aresult.accessToken; result.accessToken = aresult.accessToken;
result.permissions = clientData.permissions; result.permissions = clientData.permissions;
if (authType == ConnectTypes.BOT && !clientData.permissions.canBot) {
AuthProvider.authError("authType: BOT not allowed for this account");
}
if (authType == ConnectTypes.SERVER && !clientData.permissions.canServer) { if (authType == ConnectTypes.SERVER && !clientData.permissions.canServer) {
AuthProvider.authError("authType: SERVER not allowed for this account"); AuthProvider.authError("authType: SERVER not allowed for this account");
} }
@ -124,10 +120,6 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti
} }
result.session = clientData.session; result.session = clientData.session;
} }
if (initProxy) {
if (!clientData.permissions.canProxy) throw new AuthException("initProxy not allow");
clientData.proxy = true;
}
if (authType != ConnectTypes.API && server.config.protectHandler.allowGetAccessToken(context)) { if (authType != ConnectTypes.API && server.config.protectHandler.allowGetAccessToken(context)) {
UUID uuid = pair.handler.auth(aresult); UUID uuid = pair.handler.auth(aresult);
result.playerProfile = ProfileByUUIDResponse.getProfile(uuid, aresult.username, client, clientData.auth.textureProvider); result.playerProfile = ProfileByUUIDResponse.getProfile(uuid, aresult.username, client, clientData.auth.textureProvider);

View file

@ -20,8 +20,6 @@ public class ClientPermissions {
public boolean canUSR3; public boolean canUSR3;
@LauncherAPI @LauncherAPI
public boolean canBot; public boolean canBot;
@LauncherAPI
public boolean canProxy;
public ClientPermissions(HInput input) throws IOException { public ClientPermissions(HInput input) throws IOException {
this(input.readLong()); this(input.readLong());

View file

@ -1,21 +0,0 @@
package pro.gravit.launcher.request.admin;
import pro.gravit.launcher.request.Request;
import pro.gravit.launcher.request.WebSocketEvent;
import pro.gravit.launcher.request.websockets.WebSocketRequest;
public class ProxyRequest extends Request<WebSocketEvent> implements WebSocketRequest {
public WebSocketRequest response;
public long session;
public boolean isCheckSign;
public ProxyRequest(WebSocketRequest response, long session) {
this.response = response;
this.session = session;
}
@Override
public String getType() {
return "proxy";
}
}