[ANY] IDEA Reformat

This commit is contained in:
Gravit 2020-09-27 00:49:45 +07:00
parent 78c0e0d54d
commit ef3fbaef18
No known key found for this signature in database
GPG key ID: 98A079490768CCE5
9 changed files with 60 additions and 84 deletions

View file

@ -13,12 +13,10 @@
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL;
import java.net.http.HttpClient; import java.net.http.HttpClient;
import java.net.http.HttpRequest; import java.net.http.HttpRequest;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
import java.time.Duration; import java.time.Duration;
import java.time.temporal.TemporalUnit;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;

View file

@ -1,7 +1,5 @@
package pro.gravit.launchserver.command.service; package pro.gravit.launchserver.command.service;
import org.bouncycastle.cert.jcajce.JcaCertStore;
import org.bouncycastle.util.Store;
import org.fusesource.jansi.Ansi; import org.fusesource.jansi.Ansi;
import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
@ -12,17 +10,9 @@
import pro.gravit.launchserver.auth.provider.AcceptAuthProvider; import pro.gravit.launchserver.auth.provider.AcceptAuthProvider;
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.config.LaunchServerConfig;
import pro.gravit.launchserver.helper.SignHelper;
import pro.gravit.utils.helper.FormatHelper; import pro.gravit.utils.helper.FormatHelper;
import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.LogHelper;
import java.io.File;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
public class SecurityCheckCommand extends Command { public class SecurityCheckCommand extends Command {
@ -57,21 +47,16 @@ public void invoke(String... args) throws Exception {
}); });
if (config.protectHandler instanceof NoProtectHandler) { if (config.protectHandler instanceof NoProtectHandler) {
printCheckResult(LogHelper.Level.INFO, "protectHandler", "protectHandler none", false); printCheckResult(LogHelper.Level.INFO, "protectHandler", "protectHandler none", false);
} } else if (config.protectHandler instanceof AdvancedProtectHandler) {
else if(config.protectHandler instanceof AdvancedProtectHandler) {
printCheckResult(LogHelper.Level.INFO, "protectHandler", "", true); printCheckResult(LogHelper.Level.INFO, "protectHandler", "", true);
if(!((AdvancedProtectHandler) config.protectHandler).enableHardwareFeature) if (!((AdvancedProtectHandler) config.protectHandler).enableHardwareFeature) {
{
printCheckResult(LogHelper.Level.INFO, "protectHandler.hardwareId", "you can improve security by using hwid provider", null); printCheckResult(LogHelper.Level.INFO, "protectHandler.hardwareId", "you can improve security by using hwid provider", null);
} } else {
else {
printCheckResult(LogHelper.Level.INFO, "protectHandler.hardwareId", "", true); printCheckResult(LogHelper.Level.INFO, "protectHandler.hardwareId", "", true);
} }
} } else if (config.protectHandler instanceof StdProtectHandler) {
else if(config.protectHandler instanceof StdProtectHandler) {
printCheckResult(LogHelper.Level.INFO, "protectHandler", "you can improve security by using advanced", null); printCheckResult(LogHelper.Level.INFO, "protectHandler", "you can improve security by using advanced", null);
} } else {
else {
printCheckResult(LogHelper.Level.INFO, "protectHandler", "unknown protectHandler", null); printCheckResult(LogHelper.Level.INFO, "protectHandler", "unknown protectHandler", null);
} }
if (config.netty.address.startsWith("ws://")) { if (config.netty.address.startsWith("ws://")) {
@ -110,8 +95,7 @@ else if(config.protectHandler instanceof StdProtectHandler) {
if (!config.sign.enabled) { if (!config.sign.enabled) {
printCheckResult(LogHelper.Level.INFO, "sign", "it is recommended to use a signature", null); printCheckResult(LogHelper.Level.INFO, "sign", "it is recommended to use a signature", null);
} } else {
else {
/*boolean bad = false; /*boolean bad = false;
KeyStore keyStore = SignHelper.getStore(new File(config.sign.keyStore).toPath(), config.sign.keyStorePass, config.sign.keyStoreType); KeyStore keyStore = SignHelper.getStore(new File(config.sign.keyStore).toPath(), config.sign.keyStorePass, config.sign.keyStoreType);
X509Certificate[] certChain = (X509Certificate[]) keyStore.getCertificateChain(config.sign.keyAlias); X509Certificate[] certChain = (X509Certificate[]) keyStore.getCertificateChain(config.sign.keyAlias);
@ -144,8 +128,7 @@ else if(config.protectHandler instanceof StdProtectHandler) {
printCheckResult(LogHelper.Level.INFO, "launcher.stripLineNumbers", "", true); printCheckResult(LogHelper.Level.INFO, "launcher.stripLineNumbers", "", true);
} }
switch (config.env) switch (config.env) {
{
case DEV: case DEV:
printCheckResult(LogHelper.Level.INFO, "env", "found env DEV", false); printCheckResult(LogHelper.Level.INFO, "env", "found env DEV", false);
@ -162,20 +145,17 @@ else if(config.protectHandler instanceof StdProtectHandler) {
} }
//Profiles //Profiles
for(ClientProfile profile : server.getProfiles()) for (ClientProfile profile : server.getProfiles()) {
{
boolean bad = false; boolean bad = false;
String profileModuleName = String.format("profiles.%s", profile.getTitle()); String profileModuleName = String.format("profiles.%s", profile.getTitle());
for(String exc : profile.getUpdateExclusions()) for (String exc : profile.getUpdateExclusions()) {
{
StringTokenizer tokenizer = new StringTokenizer(exc, "\\/"); StringTokenizer tokenizer = new StringTokenizer(exc, "\\/");
if (exc.endsWith(".jar")) { if (exc.endsWith(".jar")) {
printCheckResult(LogHelper.Level.INFO, profileModuleName, String.format("updateExclusions %s not safe. Cheats may be injected very easy!", exc), false); printCheckResult(LogHelper.Level.INFO, profileModuleName, String.format("updateExclusions %s not safe. Cheats may be injected very easy!", exc), false);
bad = true; bad = true;
continue; continue;
} }
if(tokenizer.hasMoreTokens() && tokenizer.nextToken().equals("mods")) if (tokenizer.hasMoreTokens() && tokenizer.nextToken().equals("mods")) {
{
if (!tokenizer.hasMoreTokens()) { if (!tokenizer.hasMoreTokens()) {
printCheckResult(LogHelper.Level.INFO, profileModuleName, String.format("updateExclusions %s not safe. Cheats may be injected very easy!", exc), false); printCheckResult(LogHelper.Level.INFO, profileModuleName, String.format("updateExclusions %s not safe. Cheats may be injected very easy!", exc), false);
bad = true; bad = true;
@ -194,8 +174,7 @@ else if(config.protectHandler instanceof StdProtectHandler) {
LogHelper.info("Check completed"); LogHelper.info("Check completed");
} }
public static void printCheckResult(LogHelper.Level level, String module, String comment, Boolean status) public static void printCheckResult(LogHelper.Level level, String module, String comment, Boolean status) {
{
LogHelper.rawLog(() -> FormatHelper.rawFormat(level, LogHelper.getDataTime(), false).concat(String.format("[%s] %s - %s", module, comment, status == null ? "WARN" : (status ? "OK" : "FAIL"))), LogHelper.rawLog(() -> FormatHelper.rawFormat(level, LogHelper.getDataTime(), false).concat(String.format("[%s] %s - %s", module, comment, status == null ? "WARN" : (status ? "OK" : "FAIL"))),
() -> FormatHelper.rawAnsiFormat(level, LogHelper.getDataTime(), false) () -> FormatHelper.rawAnsiFormat(level, LogHelper.getDataTime(), false)
.fgBright(Ansi.Color.WHITE) .fgBright(Ansi.Color.WHITE)

View file

@ -60,8 +60,7 @@ protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) {
// ping and pong frames already handled // ping and pong frames already handled
try { try {
if (hooks.hook(ctx, frame)) return; if (hooks.hook(ctx, frame)) return;
} catch (Throwable ex) } catch (Throwable ex) {
{
LogHelper.error(ex); LogHelper.error(ex);
} }
if (frame instanceof TextWebSocketFrame) { if (frame instanceof TextWebSocketFrame) {
@ -70,12 +69,10 @@ protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) {
} catch (Throwable ex) { } catch (Throwable ex) {
if (LogHelper.isDebugEnabled()) { if (LogHelper.isDebugEnabled()) {
LogHelper.warning("Client %s send invalid request. Connection force closed.", context.ip == null ? IOHelper.getIP(ctx.channel().remoteAddress()) : context.ip); LogHelper.warning("Client %s send invalid request. Connection force closed.", context.ip == null ? IOHelper.getIP(ctx.channel().remoteAddress()) : context.ip);
if(LogHelper.isDevEnabled()) if (LogHelper.isDevEnabled()) {
{
LogHelper.dev("Client message: %s", ((TextWebSocketFrame) frame).text()); LogHelper.dev("Client message: %s", ((TextWebSocketFrame) frame).text());
} }
if(LogHelper.isStacktraceEnabled()) if (LogHelper.isStacktraceEnabled()) {
{
LogHelper.error(ex); LogHelper.error(ex);
} }
} }

View file

@ -16,14 +16,17 @@
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.time.Clock; import java.time.Clock;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.*; import java.time.temporal.ChronoField;
import java.util.*; import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAccessor;
import java.util.Arrays;
import java.util.Locale;
import java.util.Objects;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static io.netty.handler.codec.http.HttpMethod.GET; import static io.netty.handler.codec.http.HttpMethod.GET;

View file

@ -6,7 +6,6 @@
import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.AuthProviderPair;
import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.Client;
import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.launchserver.socket.response.SimpleResponse;
import pro.gravit.utils.helper.LogHelper;
import java.util.UUID; import java.util.UUID;