Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
a4747abf
Unverified
Commit
a4747abf
authored
Oct 15, 2022
by
lilmayofuksu
Committed by
GitHub
Oct 16, 2022
Browse files
Add a dictionary for Encryption public keys (#1862)
parent
f3a5bc16
Changes
7
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/server/http/dispatch/RegionHandler.java
View file @
a4747abf
...
@@ -154,8 +154,12 @@ public final class RegionHandler implements Router {
...
@@ -154,8 +154,12 @@ public final class RegionHandler implements Router {
}
}
String
key_id
=
ctx
.
queryParam
(
"key_id"
);
String
key_id
=
ctx
.
queryParam
(
"key_id"
);
if
(
key_id
==
null
)
throw
new
Exception
(
"Key ID was not set"
);
Cipher
cipher
=
Cipher
.
getInstance
(
"RSA/ECB/PKCS1Padding"
);
Cipher
cipher
=
Cipher
.
getInstance
(
"RSA/ECB/PKCS1Padding"
);
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
key_id
.
equals
(
"3"
)
?
Crypto
.
CUR_OS_ENCRYPT_KEY
:
Crypto
.
CUR_CN_ENCRYPT_KEY
);
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
Crypto
.
EncryptionKeys
.
get
(
Integer
.
valueOf
(
key_id
))
);
var
regionInfo
=
Utils
.
base64Decode
(
event
.
getRegionInfo
());
var
regionInfo
=
Utils
.
base64Decode
(
event
.
getRegionInfo
());
//Encrypt regionInfo in chunks
//Encrypt regionInfo in chunks
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java
View file @
a4747abf
...
@@ -114,8 +114,7 @@ public class HandlerGetPlayerTokenReq extends PacketHandler {
...
@@ -114,8 +114,7 @@ public class HandlerGetPlayerTokenReq extends PacketHandler {
.
putLong
(
Crypto
.
ENCRYPT_SEED
^
client_seed
)
.
putLong
(
Crypto
.
ENCRYPT_SEED
^
client_seed
)
.
array
();
.
array
();
//Kind of a hack, but whatever
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
Crypto
.
EncryptionKeys
.
get
(
req
.
getKeyId
()));
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
req
.
getKeyId
()
==
3
?
Crypto
.
CUR_OS_ENCRYPT_KEY
:
Crypto
.
CUR_CN_ENCRYPT_KEY
);
var
seed_encrypted
=
cipher
.
doFinal
(
seed_bytes
);
var
seed_encrypted
=
cipher
.
doFinal
(
seed_bytes
);
Signature
privateSignature
=
Signature
.
getInstance
(
"SHA256withRSA"
);
Signature
privateSignature
=
Signature
.
getInstance
(
"SHA256withRSA"
);
...
...
src/main/java/emu/grasscutter/utils/Crypto.java
View file @
a4747abf
...
@@ -6,6 +6,8 @@ import java.security.PublicKey;
...
@@ -6,6 +6,8 @@ import java.security.PublicKey;
import
java.security.SecureRandom
;
import
java.security.SecureRandom
;
import
java.security.spec.PKCS8EncodedKeySpec
;
import
java.security.spec.PKCS8EncodedKeySpec
;
import
java.security.spec.X509EncodedKeySpec
;
import
java.security.spec.X509EncodedKeySpec
;
import
java.util.Map
;
import
java.util.HashMap
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
...
@@ -19,10 +21,10 @@ public final class Crypto {
...
@@ -19,10 +21,10 @@ public final class Crypto {
public
static
long
ENCRYPT_SEED
=
Long
.
parseUnsignedLong
(
"11468049314633205968"
);
public
static
long
ENCRYPT_SEED
=
Long
.
parseUnsignedLong
(
"11468049314633205968"
);
public
static
byte
[]
ENCRYPT_SEED_BUFFER
=
new
byte
[
0
];
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
PrivateKey
CUR_SIGNING_KEY
;
public
static
Map
<
Integer
,
PublicKey
>
EncryptionKeys
=
new
HashMap
<>();
public
static
void
loadKeys
()
{
public
static
void
loadKeys
()
{
DISPATCH_KEY
=
FileUtils
.
readResource
(
"/keys/dispatchKey.bin"
);
DISPATCH_KEY
=
FileUtils
.
readResource
(
"/keys/dispatchKey.bin"
);
DISPATCH_SEED
=
FileUtils
.
readResource
(
"/keys/dispatchSeed.bin"
);
DISPATCH_SEED
=
FileUtils
.
readResource
(
"/keys/dispatchSeed.bin"
);
...
@@ -31,15 +33,17 @@ public final class Crypto {
...
@@ -31,15 +33,17 @@ public final class Crypto {
ENCRYPT_SEED_BUFFER
=
FileUtils
.
readResource
(
"/keys/secretKeyBuffer.bin"
);
ENCRYPT_SEED_BUFFER
=
FileUtils
.
readResource
(
"/keys/secretKeyBuffer.bin"
);
try
{
try
{
//These should be loaded from ChannelConfig_whatever.json
CUR_SIGNING_KEY
=
KeyFactory
.
getInstance
(
"RSA"
)
CUR_SIGNING_KEY
=
KeyFactory
.
getInstance
(
"RSA"
)
.
generatePrivate
(
new
PKCS8EncodedKeySpec
(
FileUtils
.
readResource
(
"/keys/SigningKey.der"
)));
.
generatePrivate
(
new
PKCS8EncodedKeySpec
(
FileUtils
.
readResource
(
"/keys/SigningKey.der"
)));
CUR_OS_ENCRYPT_KEY
=
KeyFactory
.
getInstance
(
"RSA"
)
var
CNRelSign
=
KeyFactory
.
getInstance
(
"RSA"
)
.
generatePublic
(
new
X509EncodedKeySpec
(
FileUtils
.
readResource
(
"/keys/OSCB_Pub.der"
)));
.
generatePublic
(
new
X509EncodedKeySpec
(
FileUtils
.
readResource
(
"/keys/CNRel_Pub.der"
)));
var
OSRelSign
=
KeyFactory
.
getInstance
(
"RSA"
)
.
generatePublic
(
new
X509EncodedKeySpec
(
FileUtils
.
readResource
(
"/keys/OSRel_Pub.der"
)));
CUR_CN_ENCRYPT_KEY
=
KeyFactory
.
getInstance
(
"RSA"
)
EncryptionKeys
.
put
(
2
,
CNRelSign
);
.
generatePublic
(
new
X509EncodedKeySpec
(
FileUtils
.
readResource
(
"/keys/OSCN_Pub.der"
))
);
EncryptionKeys
.
put
(
3
,
OSRelSign
);
}
}
catch
(
Exception
e
)
{
catch
(
Exception
e
)
{
Grasscutter
.
getLogger
().
error
(
"An error occurred while loading keys."
,
e
);
Grasscutter
.
getLogger
().
error
(
"An error occurred while loading keys."
,
e
);
...
...
src/main/resources/keys/
OS
CN.pem
→
src/main/resources/keys/CN
Rel
.pem
View file @
a4747abf
File moved
src/main/resources/keys/
OS
CN_Pub.der
→
src/main/resources/keys/CN
Rel
_Pub.der
View file @
a4747abf
File moved
src/main/resources/keys/OS
CB
.pem
→
src/main/resources/keys/OS
Rel
.pem
View file @
a4747abf
File moved
src/main/resources/keys/OS
CB
_Pub.der
→
src/main/resources/keys/OS
Rel
_Pub.der
View file @
a4747abf
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment