Fix other players' skins are not visible in Minecraft 1.20

This commit is contained in:
Haowei Wen 2023-06-12 01:14:50 +08:00
parent 648464df24
commit 18a0ce2669
2 changed files with 66 additions and 1 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Haowei Wen <yushijinhun@gmail.com> and contributors
* Copyright (C) 2023 Haowei Wen <yushijinhun@gmail.com> 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
@ -46,6 +46,7 @@ import moe.yushi.authlibinjector.httpd.AntiFeaturesFilter;
import moe.yushi.authlibinjector.httpd.DefaultURLRedirector;
import moe.yushi.authlibinjector.httpd.LegacySkinAPIFilter;
import moe.yushi.authlibinjector.httpd.ProfileKeyFilter;
import moe.yushi.authlibinjector.httpd.PublickeysFilter;
import moe.yushi.authlibinjector.httpd.QueryProfileFilter;
import moe.yushi.authlibinjector.httpd.QueryUUIDsFilter;
import moe.yushi.authlibinjector.httpd.URLFilter;
@ -258,6 +259,8 @@ public final class AuthlibInjector {
filters.add(new ProfileKeyFilter());
}
filters.add(new PublickeysFilter());
return filters;
}

View file

@ -0,0 +1,62 @@
/*
* Copyright (C) 2023 Haowei Wen <yushijinhun@gmail.com> 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 moe.yushi.authlibinjector.httpd;
import static moe.yushi.authlibinjector.util.IOUtils.CONTENT_TYPE_JSON;
import java.io.IOException;
import java.security.PublicKey;
import java.util.Base64;
import java.util.Optional;
import moe.yushi.authlibinjector.internal.fi.iki.elonen.IHTTPSession;
import moe.yushi.authlibinjector.internal.fi.iki.elonen.Response;
import moe.yushi.authlibinjector.internal.fi.iki.elonen.Status;
import moe.yushi.authlibinjector.internal.org.json.simple.JSONArray;
import moe.yushi.authlibinjector.internal.org.json.simple.JSONObject;
import moe.yushi.authlibinjector.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, makePublickeysResponse().toJSONString()));
}
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.put("publicKey", Base64.getEncoder().encodeToString(key.getEncoded()));
profilePropertyKeys.add(entry);
playerCertificateKeys.add(entry);
}
response.put("profilePropertyKeys", profilePropertyKeys);
response.put("playerCertificateKeys", playerCertificateKeys);
return response;
}
}