Commit ae8b5e30 authored by Yazawazi's avatar Yazawazi Committed by Luke H-W
Browse files

Full support for both parties

parent 0a557ccf
......@@ -103,12 +103,6 @@ public final class DefaultAuthenticators {
String responseMessage = translate("messages.dispatch.account.username_error");
String loggerMessage = "";
String decryptedPassword = "";
// Get Password
if (GAME_OPTIONS.uaPatchCompatible) {
// Make sure your patch can send passwords in plain text
decryptedPassword = request.getPasswordRequest().password;
} else {
try {
byte[] key = FileUtils.readResource("/keys/auth_private-key.der");
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(key);
......@@ -121,8 +115,7 @@ public final class DefaultAuthenticators {
decryptedPassword = new String(cipher.doFinal(Utils.base64Decode(request.getPasswordRequest().password)), StandardCharsets.UTF_8);
} catch (Exception ignored) {
ignored.printStackTrace();
}
decryptedPassword = request.getPasswordRequest().password;
}
if (decryptedPassword == null) {
......
......@@ -11,6 +11,7 @@ import emu.grasscutter.server.event.dispatch.QueryCurrentRegionEvent;
import emu.grasscutter.server.http.Router;
import emu.grasscutter.server.http.objects.QueryCurRegionRspJson;
import emu.grasscutter.utils.Crypto;
import emu.grasscutter.utils.FileUtils;
import emu.grasscutter.utils.Utils;
import express.Express;
import express.http.Request;
......@@ -19,6 +20,11 @@ import io.javalin.Javalin;
import javax.crypto.Cipher;
import java.io.ByteArrayOutputStream;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.security.Signature;
......@@ -139,9 +145,8 @@ public final class RegionHandler implements Router {
try {
QueryCurrentRegionEvent event = new QueryCurrentRegionEvent(regionData); event.call();
if (GAME_OPTIONS.uaPatchCompatible) {
if (request.query("dispatchSeed") == null) {
// More love for UA Patch players
var rsp = new QueryCurRegionRspJson();
rsp.content = event.getRegionInfo();
......
......@@ -101,19 +101,7 @@ public class HandlerGetPlayerTokenReq extends PacketHandler {
// Only >= 2.7.50 has this
if (req.getKeyId() > 0) {
if (GAME_OPTIONS.uaPatchCompatible) {
// More love for ua patch plz 😭
byte[] clientBytes = Utils.base64Decode(req.getClientSeed());
byte[] seed = ByteHelper.longToBytes(Crypto.ENCRYPT_SEED);
Crypto.xor(clientBytes, seed);
String base64str = Utils.base64Encode(clientBytes);
session.send(new PacketGetPlayerTokenRsp(session, base64str, "bm90aGluZyBoZXJl"));
return;
}
try {
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.DECRYPT_MODE, Crypto.CUR_SIGNING_KEY);
......@@ -134,6 +122,16 @@ public class HandlerGetPlayerTokenReq extends PacketHandler {
privateSignature.update(seed_bytes);
session.send(new PacketGetPlayerTokenRsp(session, Utils.base64Encode(seed_encrypted), Utils.base64Encode(privateSignature.sign())));
} catch (Exception ignore) {
// Only UA Patch users will have exception
byte[] clientBytes = Utils.base64Decode(req.getClientSeed());
byte[] seed = ByteHelper.longToBytes(Crypto.ENCRYPT_SEED);
Crypto.xor(clientBytes, seed);
String base64str = Utils.base64Encode(clientBytes);
session.send(new PacketGetPlayerTokenRsp(session, base64str, "bm90aGluZyBoZXJl"));
}
}
else {
// Send packet
......
......@@ -211,7 +211,6 @@ public class ConfigContainer {
public int cap = 160;
public int rechargeTime = 480;
}
public boolean uaPatchCompatible = false;
}
public static class JoinOptions {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment