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 emu.grasscutter.net.proto.PacketHeadOuterClass.PacketHead;
import emu.grasscutter.utils.Crypto;
import java.io.*;
public class BasePacket {

View File

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

View File

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

View File

@ -4,7 +4,8 @@ public final class MersenneTwister64 {
// Period parameters
private static final int N = 312;
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 int LOWER_MASK = 0x7FFFFFFF; // least significant r bits
@ -23,7 +24,7 @@ public final class MersenneTwister64 {
long x;
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) {
setSeed(5489L);
}