Format code [skip actions]

This commit is contained in:
github-actions 2023-09-16 21:40:49 +00:00
parent fb0c2dbc84
commit 1f15d6219b
4 changed files with 12 additions and 14 deletions

View File

@ -2,7 +2,6 @@ package emu.grasscutter.net.packet;
import com.google.protobuf.GeneratedMessageV3; import com.google.protobuf.GeneratedMessageV3;
import emu.grasscutter.net.proto.PacketHeadOuterClass.PacketHead; import emu.grasscutter.net.proto.PacketHeadOuterClass.PacketHead;
import emu.grasscutter.utils.Crypto;
import java.io.*; import java.io.*;
public class BasePacket { public class BasePacket {

View File

@ -119,8 +119,7 @@ public class HandlerGetPlayerTokenReq extends PacketHandler {
var clientSeedEncrypted = Utils.base64Decode(req.getClientRandKey()); var clientSeedEncrypted = Utils.base64Decode(req.getClientRandKey());
var clientSeed = ByteBuffer.wrap(cipher.doFinal(clientSeedEncrypted)).getLong(); var clientSeed = ByteBuffer.wrap(cipher.doFinal(clientSeedEncrypted)).getLong();
var seedBytes = var seedBytes = ByteBuffer.wrap(new byte[8]).putLong(encryptSeed ^ clientSeed).array();
ByteBuffer.wrap(new byte[8]).putLong(encryptSeed ^ clientSeed).array();
cipher.init(Cipher.ENCRYPT_MODE, Crypto.EncryptionKeys.get(req.getKeyId())); cipher.init(Cipher.ENCRYPT_MODE, Crypto.EncryptionKeys.get(req.getKeyId()));
var seedEncrypted = cipher.doFinal(seedBytes); var seedEncrypted = cipher.doFinal(seedBytes);

View File

@ -3,7 +3,6 @@ package emu.grasscutter.utils;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.server.http.objects.QueryCurRegionRspJson; import emu.grasscutter.server.http.objects.QueryCurRegionRspJson;
import emu.grasscutter.utils.algorithms.MersenneTwister64; import emu.grasscutter.utils.algorithms.MersenneTwister64;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.*; import java.security.*;
@ -36,9 +35,9 @@ public final class Crypto {
try { try {
CUR_SIGNING_KEY = CUR_SIGNING_KEY =
KeyFactory.getInstance("RSA") KeyFactory.getInstance("RSA")
.generatePrivate( .generatePrivate(
new PKCS8EncodedKeySpec(FileUtils.readResource("/keys/SigningKey.der"))); new PKCS8EncodedKeySpec(FileUtils.readResource("/keys/SigningKey.der")));
Pattern pattern = Pattern.compile("([0-9]*)_Pub\\.der"); Pattern pattern = Pattern.compile("([0-9]*)_Pub\\.der");
for (Path path : FileUtils.getPathsFromResource("/keys/game_keys")) { for (Path path : FileUtils.getPathsFromResource("/keys/game_keys")) {
@ -48,8 +47,8 @@ public final class Crypto {
if (m.matches()) { if (m.matches()) {
var key = var key =
KeyFactory.getInstance("RSA") KeyFactory.getInstance("RSA")
.generatePublic(new X509EncodedKeySpec(FileUtils.read(path))); .generatePublic(new X509EncodedKeySpec(FileUtils.read(path)));
EncryptionKeys.put(Integer.valueOf(m.group(1)), key); EncryptionKeys.put(Integer.valueOf(m.group(1)), key);
} }
@ -97,7 +96,7 @@ public final class Crypto {
} }
public static QueryCurRegionRspJson encryptAndSignRegionData(byte[] regionInfo, String key_id) public static QueryCurRegionRspJson encryptAndSignRegionData(byte[] regionInfo, String key_id)
throws Exception { throws Exception {
if (key_id == null) { if (key_id == null) {
throw new Exception("Key ID was not set"); throw new Exception("Key ID was not set");
} }
@ -115,8 +114,8 @@ public final class Crypto {
for (int i = 0; i < numChunks; i++) { for (int i = 0; i < numChunks; i++) {
byte[] chunk = byte[] chunk =
Arrays.copyOfRange( Arrays.copyOfRange(
regionInfo, i * chunkSize, Math.min((i + 1) * chunkSize, regionInfoLength)); regionInfo, i * chunkSize, Math.min((i + 1) * chunkSize, regionInfoLength));
byte[] encryptedChunk = cipher.doFinal(chunk); byte[] encryptedChunk = cipher.doFinal(chunk);
encryptedRegionInfoStream.write(encryptedChunk); encryptedRegionInfoStream.write(encryptedChunk);
} }

View File

@ -4,7 +4,8 @@ public final class MersenneTwister64 {
// Period parameters // Period parameters
private static final int N = 312; private static final int N = 312;
private static final int M = 156; private static final int M = 156;
private static final long MATRIX_A = 0xB5026F5AA96619E9L; // private static final * constant vector a private static final long MATRIX_A =
0xB5026F5AA96619E9L; // private static final * constant vector a
private static final long UPPER_MASK = 0xFFFFFFFF80000000L; // most significant w-r bits private static final long UPPER_MASK = 0xFFFFFFFF80000000L; // most significant w-r bits
private static final int LOWER_MASK = 0x7FFFFFFF; // least significant r bits private static final int LOWER_MASK = 0x7FFFFFFF; // least significant r bits
@ -23,7 +24,7 @@ public final class MersenneTwister64 {
long x; long x;
final long[] mag01 = {0x0L, MATRIX_A}; final long[] mag01 = {0x0L, MATRIX_A};
if (mti >= N) { // generate N words at one time if (mti >= N) { // generate N words at one time
if (mti == N + 1) { if (mti == N + 1) {
setSeed(5489L); setSeed(5489L);
} }