-
Notifications
You must be signed in to change notification settings - Fork 70
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 #159 from yushijinhun/develop
Release v1.1.44
- Loading branch information
Showing
13 changed files
with
354 additions
and
102 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
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
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
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
47 changes: 47 additions & 0 deletions
47
src/main/java/moe/yushi/authlibinjector/httpd/DebugApiEndpoint.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,47 @@ | ||
/* | ||
* Copyright (C) 2022 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 moe.yushi.authlibinjector.httpd; | ||
|
||
import static moe.yushi.authlibinjector.util.IOUtils.CONTENT_TYPE_JSON; | ||
import moe.yushi.authlibinjector.AuthlibInjector; | ||
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.JSONObject; | ||
import moe.yushi.authlibinjector.transform.PerformanceMetrics; | ||
|
||
/** | ||
* Authlib-injector's debug API | ||
*/ | ||
public class DebugApiEndpoint { | ||
|
||
public Response serve(IHTTPSession session) { | ||
if (session.getUri().equals("/debug/metrics") && session.getMethod().equals("GET")) { | ||
PerformanceMetrics metrics = AuthlibInjector.getClassTransformer().performanceMetrics; | ||
JSONObject response = new JSONObject(); | ||
response.put("totalTime", metrics.getTotalTime()); | ||
response.put("matchTime", metrics.getMatchTime()); | ||
response.put("scanTime", metrics.getScanTime()); | ||
response.put("analysisTime", metrics.getAnalysisTime()); | ||
response.put("classesScanned", metrics.getClassesScanned()); | ||
response.put("classesSkipped", metrics.getClassesSkipped()); | ||
return Response.newFixedLength(Status.OK, CONTENT_TYPE_JSON, response.toJSONString()); | ||
} else { | ||
return Response.newFixedLength(Status.NOT_FOUND, null, null); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/moe/yushi/authlibinjector/httpd/ProfileKeyFilter.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,44 @@ | ||
/* | ||
* Copyright (C) 2022 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 moe.yushi.authlibinjector.httpd; | ||
|
||
import java.io.IOException; | ||
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; | ||
|
||
/** | ||
* Intercepts Minecraft's request to https://api.minecraftservices.com/player/certificates, | ||
* and returns an empty response. | ||
*/ | ||
public class ProfileKeyFilter 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("/player/certificates") && session.getMethod().equals("POST")) { | ||
return Optional.of(Response.newFixedLength(Status.NO_CONTENT, null, null)); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
} |
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) 2020 Haowei Wen <[email protected]> and contributors | ||
* Copyright (C) 2022 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 | ||
|
@@ -37,6 +37,7 @@ | |
import java.util.Set; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import moe.yushi.authlibinjector.Config; | ||
import moe.yushi.authlibinjector.internal.fi.iki.elonen.IHTTPSession; | ||
import moe.yushi.authlibinjector.internal.fi.iki.elonen.IStatus; | ||
import moe.yushi.authlibinjector.internal.fi.iki.elonen.NanoHTTPD; | ||
|
@@ -67,6 +68,10 @@ public URLProcessor(List<URLFilter> filters, URLRedirector redirector) { | |
* @return the transformed URL, or empty if it doesn't need to be transformed | ||
*/ | ||
public Optional<String> transformURL(String inputUrl) { | ||
if (!inputUrl.startsWith("http")) { | ||
// fast path | ||
return Optional.empty(); | ||
} | ||
Matcher matcher = URL_REGEX.matcher(inputUrl); | ||
if (!matcher.find()) { | ||
return Optional.empty(); | ||
|
@@ -98,6 +103,7 @@ private Optional<String> transform(String protocol, String domain, String path) | |
return redirector.redirect(domain, path); | ||
} | ||
|
||
private DebugApiEndpoint debugApi = new DebugApiEndpoint(); | ||
private volatile NanoHTTPD httpd; | ||
private final Object httpdLock = new Object(); | ||
|
||
|
@@ -117,9 +123,13 @@ private int getLocalApiPort() { | |
} | ||
|
||
private NanoHTTPD createHttpd() { | ||
return new NanoHTTPD("127.0.0.1", 0) { | ||
return new NanoHTTPD("127.0.0.1", Config.httpdPort) { | ||
@Override | ||
public Response serve(IHTTPSession session) { | ||
if (session.getUri().startsWith("/debug/")) { | ||
return debugApi.serve(session); | ||
} | ||
|
||
Matcher matcher = LOCAL_URL_REGEX.matcher(session.getUri()); | ||
if (matcher.find()) { | ||
String protocol = matcher.group("protocol"); | ||
|
Oops, something went wrong.