Skip to content

Commit

Permalink
Merge pull request #15 from YuxuanZuo/develop
Browse files Browse the repository at this point in the history
Release v0.2.1
  • Loading branch information
YuxuanZuo authored Jun 25, 2023
2 parents 1a132f6 + 013fc99 commit fba2e09
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 226 deletions.
7 changes: 6 additions & 1 deletion src/main/java/xyz/zuoyx/multiyggdrasil/MultiYggdrasil.java
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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -283,6 +285,8 @@ private static List<URLFilter> createFilters(APIMetadata config) {
filters.add(new ProfileKeyFilter());
}

filters.add(new PublickeysFilter());

return filters;
}

Expand Down Expand Up @@ -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;
}
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/xyz/zuoyx/multiyggdrasil/httpd/PublickeysFilter.java
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;
}
}
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;
}

}
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
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static boolean isWhitelistedDomain(String url) {

@Override
public Optional<ClassVisitor> transform(ClassLoader classLoader, String className, ClassVisitor writer, TransformContext ctx) {
if ("com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService".equals(className)) {
if ("com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService".equals(className) || "com.mojang.authlib.yggdrasil.TextureUrlChecker".equals(className)) {
return Optional.of(new ClassVisitor(ASM9, writer) {

@Override
Expand Down
Loading

0 comments on commit fba2e09

Please sign in to comment.