Skip to content

Commit

Permalink
Merge pull request #228 from yushijinhun/develop
Browse files Browse the repository at this point in the history
Release v1.2.4
  • Loading branch information
yushijinhun authored Nov 1, 2023
2 parents 6462c58 + c7670af commit 2b6bf9f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/deploy_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
build_number=$(grep -Pom1 '@@release\.build_number=\K.*(?=@@)' <<< $release_body)
version_number=$(grep -Pom1 '@@release\.version_number=\K.*(?=@@)' <<< $release_body)
asset_name='${{ github.event.release.assets[0].name }}'
release_published_at='${{ github.event.release.published_at }}'
cd ~/deploy
git config --local user.name "github-actions[bot]"
Expand All @@ -49,12 +50,14 @@ jobs:
jq -n \
--arg build_number "$build_number" \
--arg version "$version_number" \
--arg release_time "$release_published_at" \
--arg download_url "https://authlib-injector.yushi.moe/artifact/$build_number/$asset_name" \
--arg sha256 "$sha256" \
'
{
"build_number": $build_number|tonumber,
"version": $version,
"release_time": $release_time,
"download_url": $download_url,
"checksums": {
"sha256": $sha256
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'com.palantir.git-version' version '2.0.0'
id 'com.palantir.git-version' version '3.0.0'
id 'java'
}

Expand All @@ -9,8 +9,8 @@ repositories {
}

dependencies {
implementation 'org.ow2.asm:asm:9.4'
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2'
implementation 'org.ow2.asm:asm:9.6'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
}

tasks.withType(JavaCompile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
*/
package moe.yushi.authlibinjector.transform.support;

import static java.lang.invoke.MethodHandles.publicLookup;
import static java.lang.invoke.MethodType.methodType;
import static moe.yushi.authlibinjector.util.IOUtils.asBytes;
import static moe.yushi.authlibinjector.util.Logging.Level.DEBUG;
import static org.objectweb.asm.Opcodes.ALOAD;
import static org.objectweb.asm.Opcodes.ARETURN;
import static org.objectweb.asm.Opcodes.ASM9;
import static org.objectweb.asm.Opcodes.GETFIELD;
import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
import static org.objectweb.asm.Opcodes.IRETURN;
import java.io.IOException;
import java.io.InputStream;
import java.lang.invoke.MethodHandle;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.PrivateKey;
Expand Down Expand Up @@ -61,7 +62,32 @@ private static PublicKey loadMojangPublicKey() {
}

@CallbackMethod
public static boolean verifyPropertySignature(String propertyValue, String base64Signature) {
public static boolean verifyPropertySignature(Object propertyObj) {
String base64Signature;
String propertyValue;

try {
MethodHandle valueHandle;
try {
valueHandle = publicLookup().findVirtual(propertyObj.getClass(), "getValue", methodType(String.class));
} catch (NoSuchMethodException ignored) {
valueHandle = publicLookup().findVirtual(propertyObj.getClass(), "value", methodType(String.class));
}

MethodHandle signatureHandle;
try {
signatureHandle = publicLookup().findVirtual(propertyObj.getClass(), "getSignature", methodType(String.class));
} catch(NoSuchMethodException ignored) {
signatureHandle = publicLookup().findVirtual(propertyObj.getClass(), "signature", methodType(String.class));
}

base64Signature = (String) signatureHandle.invokeWithArguments(propertyObj);
propertyValue = (String) valueHandle.invokeWithArguments(propertyObj);
} catch (Throwable e) {
Logging.log(Level.ERROR, "Failed to get property attributes", e);
return false;
}

byte[] sig = Base64.getDecoder().decode(base64Signature);
byte[] data = propertyValue.getBytes();

Expand Down Expand Up @@ -145,9 +171,6 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, "com/mojang/authlib/properties/Property", "value", "Ljava/lang/String;");
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, "com/mojang/authlib/properties/Property", "signature", "Ljava/lang/String;");
ctx.invokeCallback(mv, YggdrasilKeyTransformUnit.class, "verifyPropertySignature");
mv.visitInsn(IRETURN);
mv.visitMaxs(-1, -1);
Expand All @@ -170,9 +193,6 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
mv.visitCode();
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, "com/mojang/authlib/properties/Property", "getValue", "()Ljava/lang/String;", false);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, "com/mojang/authlib/properties/Property", "getSignature", "()Ljava/lang/String;", false);
ctx.invokeCallback(mv, YggdrasilKeyTransformUnit.class, "verifyPropertySignature");
mv.visitInsn(IRETURN);
mv.visitMaxs(-1, -1);
Expand Down

0 comments on commit 2b6bf9f

Please sign in to comment.