From 4ed0b90c2744ea872666b7e783a4c51d873b66af Mon Sep 17 00:00:00 2001 From: lilmayofuksu Date: Wed, 2 Nov 2022 01:28:04 +0300 Subject: [PATCH] Add the new keys (3.2 Support) (#1923) * Add the new keys * Some improvements to the key loading system & Bump the game version --- .../java/emu/grasscutter/GameConstants.java | 2 +- .../java/emu/grasscutter/utils/Crypto.java | 22 ++++++++++---- .../keys/{CNRel.pem => game_keys/2.pem} | 0 .../{CNRel_Pub.der => game_keys/2_Pub.der} | Bin .../keys/{OSRel.pem => game_keys/3.pem} | 0 .../{OSRel_Pub.der => game_keys/3_Pub.der} | Bin src/main/resources/keys/game_keys/4.pem | 27 ++++++++++++++++++ src/main/resources/keys/game_keys/4_Pub.der | Bin 0 -> 294 bytes src/main/resources/keys/game_keys/5.pem | 27 ++++++++++++++++++ src/main/resources/keys/game_keys/5_Pub.der | Bin 0 -> 294 bytes 10 files changed, 71 insertions(+), 7 deletions(-) rename src/main/resources/keys/{CNRel.pem => game_keys/2.pem} (100%) rename src/main/resources/keys/{CNRel_Pub.der => game_keys/2_Pub.der} (100%) rename src/main/resources/keys/{OSRel.pem => game_keys/3.pem} (100%) rename src/main/resources/keys/{OSRel_Pub.der => game_keys/3_Pub.der} (100%) create mode 100644 src/main/resources/keys/game_keys/4.pem create mode 100644 src/main/resources/keys/game_keys/4_Pub.der create mode 100644 src/main/resources/keys/game_keys/5.pem create mode 100644 src/main/resources/keys/game_keys/5_Pub.der diff --git a/src/main/java/emu/grasscutter/GameConstants.java b/src/main/java/emu/grasscutter/GameConstants.java index b39e5b29d..77d3102dd 100644 --- a/src/main/java/emu/grasscutter/GameConstants.java +++ b/src/main/java/emu/grasscutter/GameConstants.java @@ -6,7 +6,7 @@ import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Utils; public final class GameConstants { - public static String VERSION = "3.1.0"; + public static String VERSION = "3.2.0"; public static final int DEFAULT_TEAMS = 4; public static final int MAX_TEAMS = 10; diff --git a/src/main/java/emu/grasscutter/utils/Crypto.java b/src/main/java/emu/grasscutter/utils/Crypto.java index 2ef25e5a9..f0da36ea6 100644 --- a/src/main/java/emu/grasscutter/utils/Crypto.java +++ b/src/main/java/emu/grasscutter/utils/Crypto.java @@ -1,5 +1,7 @@ package emu.grasscutter.utils; +import java.io.File; +import java.nio.file.Path; import java.security.KeyFactory; import java.security.PrivateKey; import java.security.PublicKey; @@ -8,6 +10,7 @@ import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import java.util.Map; import java.util.HashMap; +import java.util.regex.Pattern; import emu.grasscutter.Grasscutter; @@ -36,14 +39,21 @@ public final class Crypto { CUR_SIGNING_KEY = KeyFactory.getInstance("RSA") .generatePrivate(new PKCS8EncodedKeySpec(FileUtils.readResource("/keys/SigningKey.der"))); - var CNRelSign = KeyFactory.getInstance("RSA") - .generatePublic(new X509EncodedKeySpec(FileUtils.readResource("/keys/CNRel_Pub.der"))); + Pattern pattern = Pattern.compile("([0-9]*)_Pub\\.der"); + for (Path path : FileUtils.getPathsFromResource("/keys/game_keys")) { + if (path.toString().endsWith("_Pub.der")) { - var OSRelSign = KeyFactory.getInstance("RSA") - .generatePublic(new X509EncodedKeySpec(FileUtils.readResource("/keys/OSRel_Pub.der"))); + var m = pattern.matcher(path.getFileName().toString()); - EncryptionKeys.put(2, CNRelSign); - EncryptionKeys.put(3, OSRelSign); + if (m.matches()) + { + var key = KeyFactory.getInstance("RSA") + .generatePublic(new X509EncodedKeySpec(FileUtils.read(path))); + + EncryptionKeys.put(Integer.valueOf(m.group(1)), key); + } + } + } } catch (Exception e) { Grasscutter.getLogger().error("An error occurred while loading keys.", e); diff --git a/src/main/resources/keys/CNRel.pem b/src/main/resources/keys/game_keys/2.pem similarity index 100% rename from src/main/resources/keys/CNRel.pem rename to src/main/resources/keys/game_keys/2.pem diff --git a/src/main/resources/keys/CNRel_Pub.der b/src/main/resources/keys/game_keys/2_Pub.der similarity index 100% rename from src/main/resources/keys/CNRel_Pub.der rename to src/main/resources/keys/game_keys/2_Pub.der diff --git a/src/main/resources/keys/OSRel.pem b/src/main/resources/keys/game_keys/3.pem similarity index 100% rename from src/main/resources/keys/OSRel.pem rename to src/main/resources/keys/game_keys/3.pem diff --git a/src/main/resources/keys/OSRel_Pub.der b/src/main/resources/keys/game_keys/3_Pub.der similarity index 100% rename from src/main/resources/keys/OSRel_Pub.der rename to src/main/resources/keys/game_keys/3_Pub.der diff --git a/src/main/resources/keys/game_keys/4.pem b/src/main/resources/keys/game_keys/4.pem new file mode 100644 index 000000000..314f0f837 --- /dev/null +++ b/src/main/resources/keys/game_keys/4.pem @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAyaxqjPJP5+Innfv5IdfQqY/ftS++lnDRe3EczNkIjESWXhHS +OljEw9b9C+/BtF+fO9QZL7Z742y06eIdvsMPQKdGflB26+9OZ8AF4SpXDn3aVWGr +8+9qpB7BELRZI/Ph2FlFL4cobCzMHunncW8zTfMId48+fgHkAzCjRl5rC6XT0Yge +6+eKpXmF+hr0vGYWiTzqPzTABl44WZo3rw0yurZTzkrmRE4kR2VzkjY/rBnQAbFK +KFUKsUozjCXvSag4l461wDkhmmyivpNkK5cAxuDbsmC39iqagMt9438fajLVvYOv +pVs9ci5tiLcbBtfB4Rf/QVAkqtTm86Z0O3e7DwIDAQABAoIBAQCyma226vTW35LE +N5zXWuAg+hhcxk6bvofWMUMXKvGF/0vHPTMXlvuSkDeDNa4vBivneRthBNPMgb3q +DuTWxrogQMOOI8ZdhY3DFexfDvcQD2anDJuSqSmg9Nd36q+yxk3xIoXB5Ilo23dd +vTnJXHhsBNovv7zRLO134cAHFqDoKzt5EEHre0skUcn6HjHOek6c53jvpKr5LSrr +iwx5gMuY/7ZSIUDo9WGY70qbQFGY6bOlX9x8uNjcFF+7SztEVQ+vhJ/+7EvwqaJr +ysweo0l91TKM9WaMuwoucKeceVWuynEw6GGTw8UTLtltekLGe6bS8YxY8fVwnKkT +RwJYwAJRAoGBAP2rhcfOA+1Ja37hUHKebfp9rHsex4+pGyt3Kdu7WdqOn4sexmya +BuiHQcUchPDVla/ruQZ20+8LHgzBDo0m8sY7gpf715UV9NSVIRD0wu26SKRklOFz +J4HBOwU9hBGLSnRUJzyvVlt5O7E9hAv61SCrvWBEcow2YnKNQLwvjMVJAoGBAMuG +oSb3A/ulqtp2zpxVAclYe/bSItZZTOUWP6Vb4hOiHxIJ0n1H9ap6grOYkJ/Yn4gg +yYzKm/noF1wXP7Rj/xOahnvMkzhGdmOabvE9LH5HwQTWxBBWTkZzgBbYtbg+J5MT +cKqJaychSRjJj+xX+d90rtlSu/c27chlSRKAHXWXAoGAFTcIHDq9l1XBmL3tRXi8 +h+uExlM/q2MgM5VmucrEbAPrke4D+Ec1drMBLCQDdkTWnPzg34qGlQJgA/8NYX61 +ZSDK/j0AvaY1cKX8OvfNaaZftuf2j5ha4H4xmnGXnwQAORRkp62eUk4kUOFtLrdO +pcnXL7rpvZI6z4vCszpi0okCgYEAp3lZEl8g/+oK9UneKfYpSi1tlGTGFevVwozU +QpWhKta1CnraogycsnOtKWvZVi9C1xljwF7YioPY9QaMfTvroY3+K9DjM+OHd96U +fB4Chsc0pW60V10te/t+403f+oPqvLO6ehop+kEBjUwPCkQ6cQ3q8xmJYpvofoYZ +4wdZNnECgYBwG8Vrv7Z+kX9Zuh1FvcRoY57bYLU0cWW92SA3Nvi8pZOIEaLHrQyZ +pvvaLIicR1m9+KsOAmii7ru0zL7KsrGW+5migQsaDi4gzahKQpad/R7MLKi/L53r +Ymo0aZKARLHW82GbomQ0zxdRoo9vaqfGNpXkxyyt3k3GGDunmrskYw== +-----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/src/main/resources/keys/game_keys/4_Pub.der b/src/main/resources/keys/game_keys/4_Pub.der new file mode 100644 index 0000000000000000000000000000000000000000..3e92994bae3b23f2a5d74f9bce65f8bd30a55294 GIT binary patch literal 294 zcmV+>0ondAf&n5h4F(A+hDe6@4FLfG1potr0S^E$f&mHwf&l>l$*gLO@=xdDC!PEG zA=l8UkKeT~zLs#&dvP4h*$9k8mR=FkI#|TR*8L0b!L(nWJJcC3wtM4jwCUmXTSyFDpwAD+Ernz^Y3b;9>EZ_StIk|*jYs{hbU|;%pU3Iac?tC^9Xm3 zK7Ik@12CgTUTX`b)6s|?>*tE4d4>8K^t@&ki9G5*G{6R4I9ZxEuMIM~wo}eZ=0r{; zM`d%8Hb1Nx&;hYZC{+rvN;8Zl?@6dQmyWf-IU$;CqP~-4E0+Mq;M=lbxArQUfXjX3 se;;Zx)xCqSrCU96E^Uan8wS_G;TQiwP$a6<=JTd>J9oPe0s{d60W8dhI{*Lx literal 0 HcmV?d00001 diff --git a/src/main/resources/keys/game_keys/5.pem b/src/main/resources/keys/game_keys/5.pem new file mode 100644 index 000000000..5ba7fef66 --- /dev/null +++ b/src/main/resources/keys/game_keys/5.pem @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAsJbFp3WcsiojjdQtVnTuvtawL2m4XxK93F6lCnFwcZqUP39t +xFGGlrogHMqreyawIUN7E5shtwGzigzjW8Ly5CryBJpXP3ehNTqJS7emb+9LlC19 +Oxa1eQuUQnatgcsd16DPH7kJ5JzN3vXnhvUyk4Qficdmm0uk7FRaNYFi7EJs4xyq +FTrp3rDZ0dzBHumlIeK1om7FNt6Nyivgp+UybO7kl0NLFEeSlV4S+7ofitWQsO5x +YqKAzSzz+KIRQcxJidGBlZ1JN/g5DPDpx/ztvOWYUlM7TYk6xN3focZpU0kBzAw/ +rn94yW9z8jpXfzk+MvWzVL/HAcPy4ySwkay0NwIDAQABAoIBADzKWpawbVYEHaM4 +lLb7oCjAPXzE9zx7djLDvisfLCdfoINPedkoe52ty1o+BtRpWB7LXTY9pFic1FLE +5wvyy6zyf8hH3ZsysqNhWFxhh4FnLmx/UGokAir+anaK5mYVJ1vQtxzjlV1HAbQs +kRyrklKoHDdRFqiFXOwiib97oDNWhD+RxfyG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Oag== +-----END RSA PRIVATE KEY----- diff --git a/src/main/resources/keys/game_keys/5_Pub.der b/src/main/resources/keys/game_keys/5_Pub.der new file mode 100644 index 0000000000000000000000000000000000000000..dc86f8e270fec81d1b5438e3f2622def9471e1e9 GIT binary patch literal 294 zcmV+>0ondAf&n5h4F(A+hDe6@4FLfG1potr0S^E$f&mHwf&l>lu$INAb)2#)BaPH8 zR&?&Z*03*WxL*>z++L*$ad2^(ls|uM#8HNpx*#0Nt9vG}Awzo;n<2LWvx*GkTf*|> zD)I!HS3h^5H9Cn)x2A9JOO!2rI~KKh3zR~3t%1uO*PzcIxe4T)&EECrhV?R&gdd5= zW}8c->{MDcfnw}JY~viN6*}qOu-Vbv!5-y^7ZpAj