From f6a3ae6948b940d0bcc2deddde37cdf2349cfa46 Mon Sep 17 00:00:00 2001 From: syeyoung <42869671+cyoung06@users.noreply.github.com> Date: Tue, 8 Dec 2020 22:11:33 +0900 Subject: put cap for readin --- .../kr/syeyoung/dungeonsguide/Authenticator.java | 14 +++++++++----- .../syeyoung/dungeonsguide/NetworkClassLoader.java | 20 +++++++++++++++----- .../dungeon/roomfinder/DungeonRoomInfoRegistry.java | 2 ++ 3 files changed, 26 insertions(+), 10 deletions(-) (limited to 'src/main/java/kr/syeyoung/dungeonsguide') diff --git a/src/main/java/kr/syeyoung/dungeonsguide/Authenticator.java b/src/main/java/kr/syeyoung/dungeonsguide/Authenticator.java index e41fadbe..cc2a6243 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/Authenticator.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/Authenticator.java @@ -1,7 +1,5 @@ package kr.syeyoung.dungeonsguide; -import com.auth0.jwt.JWT; -import com.auth0.jwt.interfaces.DecodedJWT; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.mojang.authlib.GameProfile; @@ -52,14 +50,20 @@ public class Authenticator { String jwt = requestAuth(session.getProfile()); MinecraftSessionService yggdrasilMinecraftSessionService = Minecraft.getMinecraft().getSessionService(); - DecodedJWT jwt2 = JWT.decode(jwt); - String hash = calculateAuthHash(DatatypeConverter.parseBase64Binary(jwt2.getClaim("sharedSecret").asString()), - DatatypeConverter.parseBase64Binary(jwt2.getClaim("publicKey").asString())); + JsonObject jwt2 = parseJWT(jwt); + String hash = calculateAuthHash(DatatypeConverter.parseBase64Binary(jwt2.get("sharedSecret").getAsString()), + DatatypeConverter.parseBase64Binary(jwt2.get("publicKey").getAsString())); yggdrasilMinecraftSessionService.joinServer(session.getProfile(), token, hash); this.token = requestAuth2(jwt, keyPair.getPublic()); return this.token; } + public JsonObject parseJWT(String jwt) { + String payload = jwt.split("\\.")[1].replace("+", "-").replace("/", "_"); + String json = new String(DatatypeConverter.parseBase64Binary(payload)); + return (JsonObject) new JsonParser().parse(json); + } + private String requestAuth(GameProfile profile) throws IOException { HttpURLConnection huc = (HttpURLConnection) new URL(DOMAIN+"auth/requestAuth").openConnection(); huc.setRequestProperty("User-Agent", "DungeonsGuide/1.0"); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/NetworkClassLoader.java b/src/main/java/kr/syeyoung/dungeonsguide/NetworkClassLoader.java index dc440405..e3a7e255 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/NetworkClassLoader.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/NetworkClassLoader.java @@ -44,16 +44,26 @@ public class NetworkClassLoader extends ClassLoader { } private byte[] loadClassFromFile(String fileName) throws BadPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException, IllegalBlockSizeException, NoSuchPaddingException, InvalidKeyException { - byte[] buffer; InputStream inputStream = authenticator.getInputStream(fileName.replace('.', '/')+ ".class"); + long length = 0; + { + for (int i = 4; i >= 0; i--) { + length |= (inputStream.read() & 0xFF) << i * 8; + } + } + ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); int nextValue = 0; try { - while ( (nextValue = inputStream.read()) != -1 ) { - byteStream.write(nextValue); + byte[] buffer = new byte[1024]; + while ( (inputStream.read(buffer)) != -1 ) { + byteStream.write(buffer); } } catch (Exception e) {} - buffer = byteStream.toByteArray(); - return buffer; + byte[] byte1 = byteStream.toByteArray(); + byte[] byte2 = new byte[(int) length]; + System.arraycopy(byte1, 0, byte2, 0, byte2.length); + + return byte2; } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java index 3119311a..2fc225df 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java @@ -68,6 +68,7 @@ public class DungeonRoomInfoRegistry { uuidMap.clear(); Authenticator authenticator = DungeonsGuide.getDungeonsGuide().getAuthenticator(); InputStream inputStream = authenticator.getInputStream("roomdata/datas.txt"); + inputStream.read(new byte[4]); BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); String name; while ((name = br.readLine()) != null) { @@ -75,6 +76,7 @@ public class DungeonRoomInfoRegistry { if (name.endsWith(".roomdata")) continue; try { InputStream fis = authenticator.getInputStream(name); + fis.read(new byte[4]); ObjectInputStream ois = new ObjectInputStream(fis); DungeonRoomInfo dri = (DungeonRoomInfo) ois.readObject(); ois.close(); -- cgit