Search in sources :

Example 1 with AES

use of net.ME1312.SubData.Client.Encryption.AES in project SubServers-2 by ME1312.

the class SubPlugin method onEnable.

/**
 * Enable Plugin
 */
@Override
public void onEnable() {
    try {
        Bukkit.getLogger().info("SubServers > Loading SubServers.Client.Bukkit v" + version.toString() + " Libraries (for Minecraft " + api.getGameVersion() + ")");
        dir = new File(getDataFolder().getParentFile(), "SubServers-Client");
        if (getDataFolder().exists()) {
            Files.move(getDataFolder().toPath(), dir.toPath(), StandardCopyOption.REPLACE_EXISTING);
        } else
            dir.mkdirs();
        ConfigUpdater.updateConfig(new File(dir, "config.yml"));
        config = new YAMLConfig(new File(dir, "config.yml"));
        if (new File(new File(System.getProperty("user.dir")), "subdata.json").exists()) {
            FileReader reader = new FileReader(new File(new File(System.getProperty("user.dir")), "subdata.json"));
            config.get().getMap("Settings").set("SubData", new YAMLSection(parseJSON(Util.readAll(reader))));
            config.save();
            reader.close();
            new File(new File(System.getProperty("user.dir")), "subdata.json").delete();
        }
        if (new File(new File(System.getProperty("user.dir")), "subdata.rsa.key").exists()) {
            if (new File(dir, "subdata.rsa.key").exists())
                new File(dir, "subdata.rsa.key").delete();
            Files.move(new File(new File(System.getProperty("user.dir")), "subdata.rsa.key").toPath(), new File(dir, "subdata.rsa.key").toPath());
        }
        getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
        reload(false);
        subprotocol = SubProtocol.get();
        subprotocol.registerCipher("DHE", DHE.get(128));
        subprotocol.registerCipher("DHE-128", DHE.get(128));
        subprotocol.registerCipher("DHE-192", DHE.get(192));
        subprotocol.registerCipher("DHE-256", DHE.get(256));
        api.name = config.get().getMap("Settings").getMap("SubData").getString("Name", System.getenv("name"));
        server_address = config.get().getMap("Settings").getString("Connect-Address", System.getenv("address"));
        if (config.get().getMap("Settings").getMap("SubData").getString("Password", "").length() > 0) {
            subprotocol.registerCipher("AES", new AES(128, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            subprotocol.registerCipher("AES-128", new AES(128, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            subprotocol.registerCipher("AES-192", new AES(192, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            subprotocol.registerCipher("AES-256", new AES(256, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            Bukkit.getLogger().info("SubData > AES Encryption Available");
        }
        if (new File(dir, "subdata.rsa.key").exists()) {
            try {
                subprotocol.registerCipher("RSA", new RSA(new File(dir, "subdata.rsa.key")));
                Bukkit.getLogger().info("SubData > RSA Encryption Available");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        reconnect = true;
        Bukkit.getLogger().info("SubData > ");
        Bukkit.getLogger().info("SubData > Connecting to /" + config.get().getMap("Settings").getMap("SubData").getString("Address", "127.0.0.1:4391"));
        connect(null);
        gui = new DefaultUIHandler(this);
        if (api.access.value > NO_COMMANDS.value && !config.get().getMap("Settings").getBoolean("API-Only-Mode", false)) {
            Bukkit.getPluginManager().registerEvents(new SubSigns(this, new File(dir, "signs.dat")), this);
            CommandMap cmd = Util.reflect(Bukkit.getServer().getClass().getDeclaredField("commandMap"), Bukkit.getServer());
            cmd.register("subservers", new SubCommand(this, "subservers"));
            cmd.register("subservers", new SubCommand(this, "subserver"));
            cmd.register("subservers", new SubCommand(this, "sub"));
        }
        if (api.access.value > NO_INTEGRATIONS.value) {
            if (config.get().getMap("Settings").getBoolean("PlaceholderAPI-Ready", false))
                phi.start();
            if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null)
                new PlaceholderImpl(this).register();
        }
        new Metrics(this, 2334);
        Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
            try {
                YAMLSection tags = new YAMLSection(parseJSON("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}'));
                List<Version> versions = new LinkedList<Version>();
                Version updversion = version;
                int updcount = 0;
                for (ObjectMap<String> tag : tags.getMapList("tags")) versions.add(Version.fromString(tag.getString("ref").substring(10)));
                Collections.sort(versions);
                for (Version version : versions) {
                    if (version.compareTo(updversion) > 0) {
                        updversion = version;
                        updcount++;
                    }
                }
                if (updcount > 0)
                    Bukkit.getLogger().info("SubServers > SubServers.Client.Bukkit v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1) ? "" : "s") + " behind.");
            } catch (Throwable e) {
            }
        }, 0, TimeUnit.DAYS.toSeconds(2) * 20);
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : YAMLSection(net.ME1312.Galaxi.Library.Config.YAMLSection) RSA(net.ME1312.SubData.Client.Encryption.RSA) YAMLConfig(net.ME1312.Galaxi.Library.Config.YAMLConfig) DefaultUIHandler(net.ME1312.SubServers.Client.Bukkit.Graphic.DefaultUIHandler) InvocationTargetException(java.lang.reflect.InvocationTargetException) URL(java.net.URL) AES(net.ME1312.SubData.Client.Encryption.AES) Metrics(net.ME1312.SubServers.Client.Bukkit.Library.Metrics) Version(net.ME1312.Galaxi.Library.Version.Version) PlaceholderImpl(net.ME1312.SubServers.Client.Bukkit.Library.Compatibility.PlaceholderImpl) CommandMap(org.bukkit.command.CommandMap)

Example 2 with AES

use of net.ME1312.SubData.Client.Encryption.AES in project SubServers-2 by ME1312.

the class ExProxy method initialize.

/**
 * Load Hosts, Servers, SubServers, and SubData Direct
 */
@Subscribe
public void initialize(ProxyInitializeEvent e) {
    try {
        running = true;
        SmartFallback.dns_forward = config.get().getMap("Settings").getMap("Smart-Fallback", new ObjectMap<>()).getBoolean("DNS-Forward", false);
        resetDate = Calendar.getInstance().getTime().getTime();
        ConfigUpdater.updateConfig(new File(dir, "SubServers/sync.yml"));
        config.reload();
        synchronized (rPlayers) {
            for (Player local : proxy.getAllPlayers()) {
                CachedPlayer player = new CachedPlayer(local);
                rPlayerLinkP.put(player.getUniqueId(), player.getProxyName().toLowerCase());
                rPlayers.put(player.getUniqueId(), player);
                ServerInfo server = local.getCurrentServer().map(ServerConnection::getServerInfo).orElse(null);
                if (servers.containsKey(server))
                    rPlayerLinkS.put(player.getUniqueId(), servers.get(server));
            }
        }
        subprotocol.unregisterCipher("AES");
        subprotocol.unregisterCipher("AES-128");
        subprotocol.unregisterCipher("AES-192");
        subprotocol.unregisterCipher("AES-256");
        subprotocol.unregisterCipher("RSA");
        api.name = config.get().getMap("Settings").getMap("SubData").getString("Name");
        if (config.get().getMap("Settings").getMap("SubData").getString("Password", "").length() > 0) {
            subprotocol.registerCipher("AES", new AES(128, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            subprotocol.registerCipher("AES-128", new AES(128, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            subprotocol.registerCipher("AES-192", new AES(192, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            subprotocol.registerCipher("AES-256", new AES(256, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            Logger.get("SubData").info("AES Encryption Available");
        }
        if (new File(dir, "SubServers/subdata.rsa.key").exists()) {
            try {
                subprotocol.registerCipher("RSA", new RSA(new File(dir, "SubServers/subdata.rsa.key")));
                Logger.get("SubData").info("RSA Encryption Available");
            } catch (Exception x) {
                x.printStackTrace();
            }
        }
        reconnect = true;
        Logger.get("SubData").info("");
        Logger.get("SubData").info("Connecting to /" + config.get().getMap("Settings").getMap("SubData").getString("Address", "127.0.0.1:4391"));
        connect(Logger.get("SubData"), null);
        if (!posted) {
            posted = true;
            post();
        }
    } catch (IOException x) {
        x.printStackTrace();
    }
}
Also used : CachedPlayer(net.ME1312.SubServers.Velocity.Server.CachedPlayer) RSA(net.ME1312.SubData.Client.Encryption.RSA) Player(com.velocitypowered.api.proxy.Player) CachedPlayer(net.ME1312.SubServers.Velocity.Server.CachedPlayer) PacketDisconnectPlayer(net.ME1312.SubServers.Client.Common.Network.Packet.PacketDisconnectPlayer) PacketExSyncPlayer(net.ME1312.SubServers.Velocity.Network.Packet.PacketExSyncPlayer) ServerInfo(com.velocitypowered.api.proxy.server.ServerInfo) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) AES(net.ME1312.SubData.Client.Encryption.AES) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 3 with AES

use of net.ME1312.SubData.Client.Encryption.AES in project SubServers-2 by ME1312.

the class ConfigUpdater method updateConfig.

/**
 * Update SubServers' config.yml
 *
 * @param file File to bring up-to-date
 */
public static void updateConfig(File file) throws IOException {
    YAMLConfig config = new YAMLConfig(file);
    YAMLSection existing = config.get().clone();
    YAMLSection updated = existing.clone();
    YAMLSection rewritten = new YAMLSection();
    Version was = existing.getMap("Settings", new ObjectMap<>()).getVersion("Version", new Version(0));
    Version now = SubAPI.getInstance().getWrapperBuild();
    int i = 0;
    if (now == null)
        now = UNSIGNED;
    if (!existing.contains("Settings") || !existing.getMap("Settings").contains("Version")) {
        YAMLSection hosts = new YAMLSection();
        YAMLSection host = new YAMLSection();
        host.set("Enabled", true);
        host.set("Display", "Default");
        hosts.set("~", host);
        updated.set("Hosts", hosts);
        i++;
        Logger.get("SubServers").info("Created ./SubServers/config.yml");
    } else {
        if (was.compareTo(new Version("19w17a")) <= 0) {
            if (existing.getMap("Settings", new YAMLSection()).contains("Log-Creator"))
                for (String name : existing.getMap("Hosts", new YAMLSection()).getKeys()) updated.getMap("Hosts").getMap(name).safeSet("Log-Creator", existing.getMap("Settings").getBoolean("Log-Creator"));
            if (existing.getMap("Settings", new YAMLSection()).contains("SubData") && !existing.getMap("Settings", new YAMLSection()).getMap("SubData").contains("Encryption"))
                updated.getMap("Settings").getMap("SubData").set("Encryption", "NONE");
            if (existing.contains("Servers")) {
                YAMLConfig sc = new YAMLConfig(new File(file.getParentFile(), "servers.yml"));
                YAMLSection settings = new YAMLSection();
                settings.set("Version", was.toString());
                settings.set("Run-On-Launch-Timeout", (existing.getMap("Settings", new YAMLSection()).contains("Run-On-Launch-Timeout")) ? existing.getMap("Settings").getInt("Run-On-Launch-Timeout") : 0);
                sc.get().safeSet("Settings", settings);
                sc.get().safeSet("Servers", new YAMLSection());
                sc.get().getMap("Servers").safeSetAll(existing.getMap("Servers"));
                Logger.get("SubServers").info("Created ./SubServers/servers.yml (using existing data)");
                sc.save();
            }
            existing = updated.clone();
            i++;
        }
        if (was.compareTo(new Version("19w35c")) <= 0) {
            if (existing.getMap("Settings", new YAMLSection()).contains("SubData")) {
                LinkedList<String> whitelist = new LinkedList<>();
                LinkedList<String> newWhitelist = new LinkedList<>();
                whitelist.addAll(existing.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getStringList("Allowed-Connections", Collections.emptyList()));
                whitelist.addAll(existing.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getStringList("Whitelist", Collections.emptyList()));
                boolean warnPls = false;
                for (String address : whitelist) {
                    Matcher regAddress = Pattern.compile("^(\\d{1,3}|%)\\.(\\d{1,3}|%)\\.(\\d{1,3}|%)\\.(\\d{1,3}|%)$").matcher(address);
                    if (regAddress.find()) {
                        StringBuilder newAddress = new StringBuilder();
                        int subnet = -1;
                        boolean warn = false;
                        for (int o = 1; o <= 4; o++) {
                            if (o > 1)
                                newAddress.append('.');
                            if (subnet == -1) {
                                if (!regAddress.group(o).equals("%")) {
                                    newAddress.append(regAddress.group(o));
                                } else {
                                    subnet = 8 * (o - 1);
                                    newAddress.append('0');
                                }
                            } else {
                                if (!regAddress.group(o).equals("%"))
                                    warn = warnPls = true;
                                newAddress.append('0');
                            }
                        }
                        if (subnet < 0)
                            subnet = 32;
                        if (warn)
                            Logger.get("SubServers").warning("Updating non-standard mask: " + address);
                        newAddress.append('/');
                        newAddress.append(subnet);
                        newWhitelist.add(newAddress.toString());
                    }
                }
                updated.getMap("Settings").getMap("SubData").set("Whitelist", newWhitelist);
                if (warnPls)
                    Logger.get("SubServers").warning("Non-standard masks have been updated. This may expose SubData to unintended networks!");
            }
            existing = updated.clone();
            i++;
        }
        if (was.compareTo(new Version("20w08d")) <= 0) {
            if (existing.contains("Hosts")) {
                for (String name : existing.getMap("Hosts", new YAMLSection()).getKeys()) {
                    if (existing.getMap("Hosts").getMap(name).getString("Driver", "BUILT_IN").replace('-', '_').replace(' ', '_').equalsIgnoreCase("BUILT_IN"))
                        updated.getMap("Hosts").getMap(name).set("Driver", "VIRTUAL");
                }
            }
            existing = updated.clone();
            i++;
        }
        if (was.compareTo(new Version("20w34a")) <= 0) {
            if (existing.getMap("Settings", new YAMLSection()).contains("Smart-Fallback") && existing.getMap("Settings").isBoolean("Smart-Fallback")) {
                YAMLSection smart_fallback = new YAMLSection();
                smart_fallback.set("Enabled", existing.getMap("Settings").getBoolean("Smart-Fallback"));
                smart_fallback.set("Fallback", existing.getMap("Settings").getBoolean("Smart-Fallback"));
                updated.getMap("Settings").set("Smart-Fallback", smart_fallback);
            }
            if (existing.getMap("Settings", new YAMLSection()).contains("Override-Bungee-Commands") && existing.getMap("Settings").isBoolean("Override-Bungee-Commands")) {
                List<String> overrides = new LinkedList<>();
                if (!existing.getMap("Settings").getBoolean("Override-Bungee-Commands")) {
                    overrides.add("/server");
                    overrides.add("/glist");
                }
                updated.getMap("Settings").set("Disabled-Overrides", overrides);
            }
            existing = updated.clone();
            i++;
        } else if (was.compareTo(new Version("21w27b")) <= 0) {
            // existing = updated.clone();
            i++;
        }
        if (i > 0)
            Logger.get("SubServers").info("Updated ./SubServers/config.yml (" + i + " pass" + ((i != 1) ? "es" : "") + ")");
    }
    if (i > 0) {
        YAMLSection settings = new YAMLSection();
        settings.set("Version", ((now.compareTo(was) <= 0) ? was : now).toString());
        if (updated.getMap("Settings", new YAMLSection()).contains("RPEC-Check-Interval"))
            settings.set("RPEC-Check-Interval", updated.getMap("Settings").getString("RPEC-Check-Interval"));
        settings.set("Strict-Server-Linking", updated.getMap("Settings", new YAMLSection()).getBoolean("Strict-Server-Linking", true));
        settings.set("Disabled-Overrides", updated.getMap("Settings", new YAMLSection()).getStringList("Disabled-Overrides", Collections.emptyList()));
        YAMLSection smart_fallback = new YAMLSection();
        smart_fallback.set("Enabled", updated.getMap("Settings", new YAMLSection()).getMap("Smart-Fallback", new YAMLSection()).getBoolean("Enabled", true));
        smart_fallback.set("Fallback", updated.getMap("Settings", new YAMLSection()).getMap("Smart-Fallback", new YAMLSection()).getBoolean("Fallback", true));
        smart_fallback.set("Reconnect", updated.getMap("Settings", new YAMLSection()).getMap("Smart-Fallback", new YAMLSection()).getBoolean("Reconnect", false));
        smart_fallback.set("DNS-Forward", updated.getMap("Settings", new YAMLSection()).getMap("Smart-Fallback", new YAMLSection()).getBoolean("DNS-Forward", false));
        settings.set("Smart-Fallback", smart_fallback);
        YAMLSection upnp = new YAMLSection();
        upnp.set("Forward-Proxy", updated.getMap("Settings", new YAMLSection()).getMap("UPnP", new YAMLSection()).getBoolean("Forward-Proxy", true));
        upnp.set("Forward-SubData", updated.getMap("Settings", new YAMLSection()).getMap("UPnP", new YAMLSection()).getBoolean("Forward-SubData", false));
        upnp.set("Forward-Servers", updated.getMap("Settings", new YAMLSection()).getMap("UPnP", new YAMLSection()).getBoolean("Forward-Servers", false));
        settings.set("UPnP", upnp);
        YAMLSection subdata = new YAMLSection();
        subdata.set("Address", updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getString("Address", "127.0.0.1:4391"));
        if (updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Password"))
            subdata.set("Password", updated.getMap("Settings").getMap("SubData").getString("Password"));
        subdata.set("Encryption", updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getString("Encryption", "RSA/AES"));
        subdata.set("Whitelist", updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getStringList("Whitelist", Collections.emptyList()));
        settings.set("SubData", subdata);
        rewritten.set("Settings", settings);
        YAMLSection hosts = new YAMLSection();
        for (String name : updated.getMap("Hosts", new YAMLSection()).getKeys()) {
            YAMLSection host = new YAMLSection();
            host.set("Enabled", updated.getMap("Hosts").getMap(name).getBoolean("Enabled", false));
            host.set("Display", updated.getMap("Hosts").getMap(name).getString("Display", ""));
            host.set("Driver", updated.getMap("Hosts").getMap(name).getString("Driver", "VIRTUAL"));
            host.set("Address", updated.getMap("Hosts").getMap(name).getString("Address", "127.0.0.1"));
            host.set("Port-Range", updated.getMap("Hosts").getMap(name).getString("Port-Range", "25500-25559"));
            host.set("Directory", updated.getMap("Hosts").getMap(name).getString("Directory", (host.getString("Driver").equalsIgnoreCase("VIRTUAL")) ? "./SubServers/Servers" : "./Servers"));
            host.set("Git-Bash", updated.getMap("Hosts").getMap(name).getString("Git-Bash", "%ProgramFiles%\\Git"));
            host.set("Log-Creator", updated.getMap("Hosts").getMap(name).getBoolean("Log-Creator", true));
            if (updated.getMap("Hosts").getMap(name).contains("Extra"))
                host.set("Extra", updated.getMap("Hosts").getMap(name).getMap("Extra"));
            hosts.set(name, host);
        }
        rewritten.set("Hosts", hosts);
        config.set(rewritten);
        config.save();
    }
}
Also used : YAMLSection(net.ME1312.Galaxi.Library.Config.YAMLSection) Matcher(java.util.regex.Matcher) YAMLConfig(net.ME1312.Galaxi.Library.Config.YAMLConfig) Version(net.ME1312.Galaxi.Library.Version.Version) ObjectMap(net.ME1312.Galaxi.Library.Map.ObjectMap) File(java.io.File)

Example 4 with AES

use of net.ME1312.SubData.Client.Encryption.AES in project SubServers-2 by ME1312.

the class SubProxy method startDataListeners.

private void startDataListeners() throws IOException {
    if (subdata == null) {
        subprotocol.unregisterCipher("AES");
        subprotocol.unregisterCipher("AES-128");
        subprotocol.unregisterCipher("AES-192");
        subprotocol.unregisterCipher("AES-256");
        subprotocol.unregisterCipher("RSA");
        subprotocol.setTimeout(TimeUnit.SECONDS.toMillis(config.get().getMap("Settings").getMap("SubData").getInt("Timeout", 30)));
        String cipher = config.get().getMap("Settings").getMap("SubData").getString("Encryption", "NULL");
        String[] ciphers = (cipher.contains("/")) ? cipher.split("/") : new String[] { cipher };
        if (ciphers[0].equals("AES") || ciphers[0].equals("AES-128") || ciphers[0].equals("AES-192") || ciphers[0].equals("AES-256")) {
            if (config.get().getMap("Settings").getMap("SubData").getString("Password", "").length() == 0) {
                byte[] bytes = new byte[32];
                new SecureRandom().nextBytes(bytes);
                String random = Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);
                if (random.length() > bytes.length)
                    random = random.substring(0, bytes.length);
                config.get().getMap("Settings").getMap("SubData").set("Password", random);
                config.save();
            }
            subprotocol.registerCipher("AES", new AES(128, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            subprotocol.registerCipher("AES-128", new AES(128, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            subprotocol.registerCipher("AES-192", new AES(192, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            subprotocol.registerCipher("AES-256", new AES(256, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            Logger.get("SubData").info("Encrypting SubData with AES:");
            Logger.get("SubData").info("Use the password field in config.yml to allow clients to connect");
        } else if (ciphers[0].equals("DHE") || ciphers[0].equals("DHE-128") || ciphers[0].equals("DHE-192") || ciphers[0].equals("DHE-256")) {
            Logger.get("SubData").info("Encrypting SubData with DHE/AES:");
            Logger.get("SubData").info("SubData will negotiate what password to use automatically using the Diffie-Hellman Exchange");
        } else if (ciphers[0].equals("RSA") || ciphers[0].equals("RSA-2048") || ciphers[0].equals("RSA-3072") || ciphers[0].equals("RSA-4096")) {
            try {
                int length = (ciphers[0].contains("-")) ? Integer.parseInt(ciphers[0].split("-")[1]) : 2048;
                if (!(new File("SubServers/Cache").exists()))
                    new File("SubServers/Cache").mkdirs();
                subprotocol.registerCipher("RSA", new RSA(length, new File("SubServers/Cache/private.rsa.key"), new File("SubServers/subdata.rsa.key")));
                cipher = "RSA" + cipher.substring(ciphers[0].length());
                Logger.get("SubData").info("Encrypting SubData with RSA:");
                Logger.get("SubData").info("Copy your subdata.rsa.key to clients to allow them to connect");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        Logger.get("SubData").info("");
        subdata = subprotocol.open((config.get().getMap("Settings").getMap("SubData").getString("Address", "127.0.0.1:4391").split(":")[0].equals("0.0.0.0")) ? null : InetAddress.getByName(config.get().getMap("Settings").getMap("SubData").getString("Address", "127.0.0.1:4391").split(":")[0]), Integer.parseInt(config.get().getMap("Settings").getMap("SubData").getString("Address", "127.0.0.1:4391").split(":")[1]), cipher);
    }
    // Add new entries to Allowed-Connections
    for (String s : config.get().getMap("Settings").getMap("SubData").getStringList("Whitelist", new ArrayList<String>())) {
        try {
            subdata.whitelist(s);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : RSA(net.ME1312.SubData.Server.Encryption.RSA) SecureRandom(java.security.SecureRandom) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidServerException(net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException) InvalidHostException(net.ME1312.SubServers.Bungee.Library.Exception.InvalidHostException) AES(net.ME1312.SubData.Server.Encryption.AES)

Example 5 with AES

use of net.ME1312.SubData.Client.Encryption.AES in project SubServers-2 by ME1312.

the class SubPlugin method enable.

/**
 * Enable Plugin
 */
@Listener
@SuppressWarnings("unchecked")
public void enable(GameInitializationEvent event) {
    api = new SubAPI(this);
    try {
        log.info("Loading SubServers.Client.Sponge v" + version.toString() + " Libraries (for Minecraft " + api.getGameVersion() + ")");
        dir = new File(xdir.getParentFile(), "subservers-client");
        if (xdir.exists()) {
            Files.move(xdir.toPath(), dir.toPath(), StandardCopyOption.REPLACE_EXISTING);
        } else
            dir.mkdirs();
        ConfigUpdater.updateConfig(new File(dir, "config.yml"));
        config = new YAMLConfig(new File(dir, "config.yml"));
        if (new File(new File(System.getProperty("user.dir")), "subdata.json").exists()) {
            FileReader reader = new FileReader(new File(new File(System.getProperty("user.dir")), "subdata.json"));
            config.get().getMap("Settings").set("SubData", new ObjectMap<String>(new Gson().fromJson(Util.readAll(reader), Map.class)));
            config.save();
            reader.close();
            new File(new File(System.getProperty("user.dir")), "subdata.json").delete();
        }
        if (new File(new File(System.getProperty("user.dir")), "subdata.rsa.key").exists()) {
            if (new File(dir, "subdata.rsa.key").exists())
                new File(dir, "subdata.rsa.key").delete();
            Files.move(new File(new File(System.getProperty("user.dir")), "subdata.rsa.key").toPath(), new File(dir, "subdata.rsa.key").toPath());
        }
        running = true;
        reload(false);
        subprotocol = SubProtocol.get();
        subprotocol.registerCipher("DHE", DHE.get(128));
        subprotocol.registerCipher("DHE-128", DHE.get(128));
        subprotocol.registerCipher("DHE-192", DHE.get(192));
        subprotocol.registerCipher("DHE-256", DHE.get(256));
        api.name = config.get().getMap("Settings").getMap("SubData").getString("Name", System.getenv("name"));
        server_address = config.get().getMap("Settings").getString("Connect-Address", System.getenv("address"));
        Logger log = LoggerFactory.getLogger("SubData");
        if (config.get().getMap("Settings").getMap("SubData").getString("Password", "").length() > 0) {
            subprotocol.registerCipher("AES", new AES(128, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            subprotocol.registerCipher("AES-128", new AES(128, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            subprotocol.registerCipher("AES-192", new AES(192, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            subprotocol.registerCipher("AES-256", new AES(256, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            log.info("AES Encryption Available");
        }
        if (new File(dir, "subdata.rsa.key").exists()) {
            try {
                subprotocol.registerCipher("RSA", new RSA(new File(dir, "subdata.rsa.key")));
                log.info("RSA Encryption Available");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        reconnect = true;
        log.info(" ");
        log.info("Connecting to /" + config.get().getMap("Settings").getMap("SubData").getString("Address", "127.0.0.1:4391"));
        connect(null);
        // gui = new InternalUIHandler(this);
        if (api.access.value > NO_COMMANDS.value && !config.get().getMap("Settings").getBoolean("API-Only-Mode", false)) {
            Sponge.getCommandManager().register(plugin, new SubCommand(this).spec(), "sub", "subserver", "subservers");
        }
        new Metrics(this);
        game.getScheduler().createTaskBuilder().async().execute(() -> {
            try {
                ObjectMap<String> tags = new ObjectMap<String>(new Gson().fromJson("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}', Map.class));
                List<Version> versions = new LinkedList<Version>();
                Version updversion = version;
                int updcount = 0;
                for (ObjectMap<String> tag : tags.getMapList("tags")) versions.add(Version.fromString(tag.getString("ref").substring(10)));
                Collections.sort(versions);
                for (Version version : versions) {
                    if (version.compareTo(updversion) > 0) {
                        updversion = version;
                        updcount++;
                    }
                }
                if (updcount > 0)
                    log.info("SubServers.Client.Sponge v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1) ? "" : "s") + " behind.");
            } catch (Exception e) {
            }
        }).delay(0, TimeUnit.MILLISECONDS).interval(2, TimeUnit.DAYS).submit(plugin);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : RSA(net.ME1312.SubData.Client.Encryption.RSA) YAMLConfig(net.ME1312.Galaxi.Library.Config.YAMLConfig) Gson(com.google.gson.Gson) Logger(org.slf4j.Logger) InvocationTargetException(java.lang.reflect.InvocationTargetException) URL(java.net.URL) AES(net.ME1312.SubData.Client.Encryption.AES) Metrics(net.ME1312.SubServers.Client.Sponge.Library.Metrics) ObjectMap(net.ME1312.Galaxi.Library.Map.ObjectMap) Version(net.ME1312.Galaxi.Library.Version.Version) Listener(org.spongepowered.api.event.Listener)

Aggregations

AES (net.ME1312.SubData.Client.Encryption.AES)4 RSA (net.ME1312.SubData.Client.Encryption.RSA)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 SecureRandom (java.security.SecureRandom)3 YAMLConfig (net.ME1312.Galaxi.Library.Config.YAMLConfig)3 ObjectMap (net.ME1312.Galaxi.Library.Map.ObjectMap)3 Version (net.ME1312.Galaxi.Library.Version.Version)3 File (java.io.File)2 URL (java.net.URL)2 YAMLSection (net.ME1312.Galaxi.Library.Config.YAMLSection)2 ContainedPair (net.ME1312.Galaxi.Library.Container.ContainedPair)2 Gson (com.google.gson.Gson)1 Subscribe (com.velocitypowered.api.event.Subscribe)1 Player (com.velocitypowered.api.proxy.Player)1 ServerInfo (com.velocitypowered.api.proxy.server.ServerInfo)1 IOException (java.io.IOException)1 Matcher (java.util.regex.Matcher)1 AES (net.ME1312.SubData.Server.Encryption.AES)1 RSA (net.ME1312.SubData.Server.Encryption.RSA)1 InvalidHostException (net.ME1312.SubServers.Bungee.Library.Exception.InvalidHostException)1