"Autogenerate" data files with data fallbacks and moved keys folder into jar resources (#927)

* Autogenerate keys and data files

* Update gacha html files

Accidentally pushed with old html files

* Keys no longer copied. No more manually retrieving listing files. Recursive directory creation

Removed unused code from old GC as well.

* Moved somethings and better errors

* Fixed resources from loading twice

* Data files fallback
This commit is contained in:
4Benj_
2022-05-17 18:00:52 +08:00
committed by GitHub
parent 1adffc21c0
commit f473e44611
31 changed files with 266 additions and 127 deletions

View File

@@ -20,11 +20,11 @@ public final class Crypto {
public static byte[] ENCRYPT_SEED_BUFFER = new byte[0];
public static void loadKeys() {
DISPATCH_KEY = FileUtils.read(KEY("dispatchKey.bin"));
DISPATCH_SEED = FileUtils.read(KEY("dispatchSeed.bin"));
DISPATCH_KEY = FileUtils.readResource("/keys/dispatchKey.bin");
DISPATCH_SEED = FileUtils.readResource("/keys/dispatchSeed.bin");
ENCRYPT_KEY = FileUtils.read(KEY("secretKey.bin"));
ENCRYPT_SEED_BUFFER = FileUtils.read(KEY("secretKeyBuffer.bin"));
ENCRYPT_KEY = FileUtils.readResource("/keys/secretKey.bin");
ENCRYPT_SEED_BUFFER = FileUtils.readResource("/keys/secretKeyBuffer.bin");
}
public static void xor(byte[] packet, byte[] key) {
@@ -37,25 +37,6 @@ public final class Crypto {
}
}
public static void extractSecretKeyBuffer(byte[] data) {
try {
GetPlayerTokenRsp p = GetPlayerTokenRsp.parseFrom(data);
FileUtils.write(KEY("/secretKeyBuffer.bin"), p.getSecretKeyBytes().toByteArray());
Grasscutter.getLogger().info("Secret Key: " + p.getSecretKey());
} catch (Exception e) {
Grasscutter.getLogger().error("Crypto error.", e);
}
}
public static void extractDispatchSeed(String data) {
try {
QueryCurrRegionHttpRsp p = QueryCurrRegionHttpRsp.parseFrom(Base64.getDecoder().decode(data));
FileUtils.write(KEY("/dispatchSeed.bin"), p.getRegionInfo().getSecretKey().toByteArray());
} catch (Exception e) {
Grasscutter.getLogger().error("Crypto error.", e);
}
}
public static byte[] createSessionKey(int length) {
byte[] bytes = new byte[length];
secureRandom.nextBytes(bytes);