aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.gradle15
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/Authenticator.java14
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/NetworkClassLoader.java20
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java2
4 files changed, 27 insertions, 24 deletions
diff --git a/build.gradle b/build.gradle
index b3c8de1c..f51bae14 100644
--- a/build.gradle
+++ b/build.gradle
@@ -40,14 +40,8 @@ minecraft {
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
}
-configurations {
- shade
- compile.extendsFrom shade
-}
-
dependencies {
implementation 'org.jetbrains:annotations-java5:19.0.0'
- compile 'com.auth0:java-jwt:3.11.0'
// you may put jars on which you depend on in ./libs
// or you may define them like so..
@@ -76,11 +70,6 @@ dependencies {
testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'
}
-shadowJar {
- dependencies {
- }
-}
-
processResources
{
@@ -100,6 +89,4 @@ processResources
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
-}
-
-build.dependsOn shadowJar \ No newline at end of file
+} \ No newline at end of file
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();