Add Dispatch Password authentication

This commit is contained in:
AnimeGitB
2022-07-13 12:03:57 +09:30
committed by Luke H-W
parent 42e3af4e39
commit bc2c5deb48
12 changed files with 503 additions and 124 deletions

View File

@@ -0,0 +1,24 @@
package emu.grasscutter.utils;
public class ByteHelper {
public static byte[] changeBytes(byte[] a) {
byte[] b = new byte[a.length];
for (int i = 0; i < a.length; i++) {
b[i] = a[a.length - i - 1];
}
return b;
}
public static byte[] longToBytes(long x) {
byte[] bytes = new byte[8];
bytes[0] = (byte) (x >> 56);
bytes[1] = (byte) (x >> 48);
bytes[2] = (byte) (x >> 40);
bytes[3] = (byte) (x >> 32);
bytes[4] = (byte) (x >> 24);
bytes[5] = (byte) (x >> 16);
bytes[6] = (byte) (x >> 8);
bytes[7] = (byte) (x);
return bytes;
}
}

View File

@@ -112,6 +112,7 @@ public class ConfigContainer {
public static class Account {
public boolean autoCreate = false;
public boolean EXPERIMENTAL_RealPassword = false;
public String[] defaultPermissions = {};
public int maxPlayer = -1;
}
@@ -210,6 +211,7 @@ public class ConfigContainer {
public int cap = 160;
public int rechargeTime = 480;
}
public boolean uaPatchCompatible = false;
}
public static class JoinOptions {

View File

@@ -1,13 +1,13 @@
package emu.grasscutter.utils;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.util.Base64;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.net.proto.GetPlayerTokenRspOuterClass.GetPlayerTokenRsp;
import emu.grasscutter.net.proto.QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp;
import static emu.grasscutter.Configuration.*;
public final class Crypto {
private static final SecureRandom secureRandom = new SecureRandom();
@@ -18,15 +18,34 @@ public final class Crypto {
public static byte[] ENCRYPT_KEY;
public static long ENCRYPT_SEED = Long.parseUnsignedLong("11468049314633205968");
public static byte[] ENCRYPT_SEED_BUFFER = new byte[0];
public static PublicKey CUR_OS_ENCRYPT_KEY;
public static PublicKey CUR_CN_ENCRYPT_KEY;
public static PrivateKey CUR_SIGNING_KEY;
public static void loadKeys() {
DISPATCH_KEY = FileUtils.readResource("/keys/dispatchKey.bin");
DISPATCH_SEED = FileUtils.readResource("/keys/dispatchSeed.bin");
ENCRYPT_KEY = FileUtils.readResource("/keys/secretKey.bin");
ENCRYPT_SEED_BUFFER = FileUtils.readResource("/keys/secretKeyBuffer.bin");
try {
//These should be loaded from ChannelConfig_whatever.json
CUR_SIGNING_KEY = KeyFactory.getInstance("RSA")
.generatePrivate(new PKCS8EncodedKeySpec(FileUtils.readResource("/keys/SigningKey.der")));
CUR_OS_ENCRYPT_KEY = KeyFactory.getInstance("RSA")
.generatePublic(new X509EncodedKeySpec(FileUtils.readResource("/keys/OSCB_Pub.der")));
CUR_CN_ENCRYPT_KEY = KeyFactory.getInstance("RSA")
.generatePublic(new X509EncodedKeySpec(FileUtils.readResource("/keys/OSCN_Pub.der")));
}
catch (Exception e) {
Grasscutter.getLogger().error("An error occurred while loading keys.", e);
}
}
public static void xor(byte[] packet, byte[] key) {
try {
for (int i = 0; i < packet.length; i++) {
@@ -36,7 +55,7 @@ public final class Crypto {
Grasscutter.getLogger().error("Crypto error.", e);
}
}
public static byte[] createSessionKey(int length) {
byte[] bytes = new byte[length];
secureRandom.nextBytes(bytes);