-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from YuxuanZuo/develop
Release v0.2.1
- Loading branch information
Showing
7 changed files
with
126 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2022 Haowei Wen <[email protected]> and contributors | ||
* Copyright (C) 2023 Haowei Wen <[email protected]> and contributors | ||
* Copyright (C) 2022 Ethan Zuo <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
|
@@ -49,6 +49,7 @@ | |
import xyz.zuoyx.multiyggdrasil.httpd.DefaultURLRedirector; | ||
import xyz.zuoyx.multiyggdrasil.httpd.LegacySkinAPIFilter; | ||
import xyz.zuoyx.multiyggdrasil.httpd.ProfileKeyFilter; | ||
import xyz.zuoyx.multiyggdrasil.httpd.PublickeysFilter; | ||
import xyz.zuoyx.multiyggdrasil.httpd.AntiFeaturesFilter; | ||
import xyz.zuoyx.multiyggdrasil.httpd.MultiHasJoinedServerFilter; | ||
import xyz.zuoyx.multiyggdrasil.httpd.MultiQueryProfileFilter; | ||
|
@@ -59,6 +60,7 @@ | |
import xyz.zuoyx.multiyggdrasil.httpd.URLProcessor; | ||
import xyz.zuoyx.multiyggdrasil.transform.ClassTransformer; | ||
import xyz.zuoyx.multiyggdrasil.transform.DumpClassListener; | ||
import xyz.zuoyx.multiyggdrasil.transform.support.AccountTypeTransformer; | ||
import xyz.zuoyx.multiyggdrasil.transform.support.AuthServerNameInjector; | ||
import xyz.zuoyx.multiyggdrasil.transform.support.AuthlibLogInterceptor; | ||
import xyz.zuoyx.multiyggdrasil.transform.support.BungeeCordAllowedCharactersTransformer; | ||
|
@@ -283,6 +285,8 @@ private static List<URLFilter> createFilters(APIMetadata config) { | |
filters.add(new ProfileKeyFilter()); | ||
} | ||
|
||
filters.add(new PublickeysFilter()); | ||
|
||
return filters; | ||
} | ||
|
||
|
@@ -322,6 +326,7 @@ private static ClassTransformer createTransformer(APIMetadata config) { | |
config.getDecodedPublickey().ifPresent(YggdrasilKeyTransformUnit.PUBLIC_KEYS::add); | ||
transformer.units.add(new VelocityProfileKeyTransformUnit()); | ||
transformer.units.add(new BungeeCordProfileKeyTransformUnit()); | ||
MainArgumentsTransformer.getArgumentsListeners().add(new AccountTypeTransformer()::transform); | ||
|
||
return transformer; | ||
} | ||
|
64 changes: 64 additions & 0 deletions
64
src/main/java/xyz/zuoyx/multiyggdrasil/httpd/PublickeysFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (C) 2023 Haowei Wen <[email protected]> and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package xyz.zuoyx.multiyggdrasil.httpd; | ||
|
||
import static xyz.zuoyx.multiyggdrasil.util.IOUtils.CONTENT_TYPE_JSON; | ||
import static xyz.zuoyx.multiyggdrasil.util.JsonUtils.toJsonString; | ||
|
||
import java.io.IOException; | ||
import java.security.PublicKey; | ||
import java.util.Base64; | ||
import java.util.Optional; | ||
import xyz.zuoyx.multiyggdrasil.internal.fi.iki.elonen.IHTTPSession; | ||
import xyz.zuoyx.multiyggdrasil.internal.fi.iki.elonen.Response; | ||
import xyz.zuoyx.multiyggdrasil.internal.fi.iki.elonen.Status; | ||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonObject; | ||
import xyz.zuoyx.multiyggdrasil.transform.support.YggdrasilKeyTransformUnit; | ||
|
||
public class PublickeysFilter implements URLFilter { | ||
|
||
@Override | ||
public boolean canHandle(String domain) { | ||
return domain.equals("api.minecraftservices.com"); | ||
} | ||
|
||
@Override | ||
public Optional<Response> handle(String domain, String path, IHTTPSession session) throws IOException { | ||
if (domain.equals("api.minecraftservices.com") && path.equals("/publickeys") && session.getMethod().equals("GET")) { | ||
return Optional.of(Response.newFixedLength(Status.OK, CONTENT_TYPE_JSON, toJsonString(makePublickeysResponse()))); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
private JsonObject makePublickeysResponse() { | ||
JsonObject response = new JsonObject(); | ||
JsonArray profilePropertyKeys = new JsonArray(); | ||
JsonArray playerCertificateKeys = new JsonArray(); | ||
|
||
for (PublicKey key : YggdrasilKeyTransformUnit.PUBLIC_KEYS) { | ||
JsonObject entry = new JsonObject(); | ||
entry.addProperty("publicKey", Base64.getEncoder().encodeToString(key.getEncoded())); | ||
profilePropertyKeys.add(entry); | ||
playerCertificateKeys.add(entry); | ||
} | ||
|
||
response.add("profilePropertyKeys", profilePropertyKeys); | ||
response.add("playerCertificateKeys", playerCertificateKeys); | ||
return response; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/xyz/zuoyx/multiyggdrasil/transform/support/AccountTypeTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (C) 2023 Haowei Wen <[email protected]> and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package xyz.zuoyx.multiyggdrasil.transform.support; | ||
|
||
import static xyz.zuoyx.multiyggdrasil.util.Logging.log; | ||
import static xyz.zuoyx.multiyggdrasil.util.Logging.Level.INFO; | ||
|
||
public class AccountTypeTransformer { | ||
|
||
public String[] transform(String[] args) { | ||
boolean userTypeMatched = false; | ||
for (int i = 0; i < args.length; i++) { | ||
String arg = args[i]; | ||
if ("--userType".equals(arg)) { | ||
userTypeMatched = true; | ||
} else if (userTypeMatched && "mojang".equals(arg)) { | ||
args[i] = "msa"; | ||
log(INFO, "Setting accountType to msa"); | ||
break; | ||
} | ||
} | ||
return args; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2022 Haowei Wen <[email protected]> and contributors | ||
* Copyright (C) 2023 Haowei Wen <[email protected]> and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
|
@@ -128,7 +128,18 @@ private static void registerLogHandle(ClassLoader cl) throws ReflectiveOperation | |
Array.set(appenderRefs, 0, appenderRef); | ||
|
||
Object loggerConfig; | ||
{ | ||
try { | ||
Object builder = classLoggerConfig.getDeclaredMethod("newBuilder").invoke(null); | ||
Class<?> classBuilder = cl.loadClass("org.apache.logging.log4j.core.config.LoggerConfig$Builder"); | ||
classBuilder.getMethod("withConfig", classConfiguration).invoke(builder, configuration); | ||
classBuilder.getMethod("withAdditivity", boolean.class).invoke(builder, false); | ||
classBuilder.getMethod("withLevel", classLevel).invoke(builder, classLevel.getDeclaredField("ALL").get(null)); | ||
classBuilder.getMethod("withLoggerName", String.class).invoke(builder, loggerName); | ||
classBuilder.getMethod("withIncludeLocation", String.class).invoke(builder, authlibPackageName); | ||
classBuilder.getMethod("withRefs", appenderRefs.getClass()).invoke(builder, appenderRefs); | ||
loggerConfig = classBuilder.getMethod("build").invoke(builder); | ||
} catch (NoSuchMethodException ex) { | ||
ex.printStackTrace(); | ||
Map<String, Object> values = new HashMap<>(); | ||
values.put("additivity", false); | ||
values.put("level", classLevel.getDeclaredField("ALL").get(null)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.