|
@@ -6,23 +6,22 @@ import winter.com.ideaaedi.classwinter.util.BashUtil;
|
|
|
import winter.com.ideaaedi.classwinter.util.Constant;
|
|
import winter.com.ideaaedi.classwinter.util.Constant;
|
|
|
import winter.com.ideaaedi.classwinter.util.PathUtil;
|
|
import winter.com.ideaaedi.classwinter.util.PathUtil;
|
|
|
|
|
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* 测试originJarOrWar
|
|
* 测试originJarOrWar
|
|
|
*
|
|
*
|
|
|
* @author {@link JustryDeng}
|
|
* @author {@link JustryDeng}
|
|
|
* @since 2021/6/12 14:34:45
|
|
* @since 2021/6/12 14:34:45
|
|
|
*/
|
|
*/
|
|
|
|
|
+@SuppressWarnings("unused")
|
|
|
public class AlreadyProtectedLibs_Test {
|
|
public class AlreadyProtectedLibs_Test {
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
|
// 杀下进程(以保证端口没有被占用)
|
|
// 杀下进程(以保证端口没有被占用)
|
|
|
BashUtil.killProcessByPorts("8080");
|
|
BashUtil.killProcessByPorts("8080");
|
|
|
|
|
|
|
|
- test0();
|
|
|
|
|
|
|
+// test0();
|
|
|
// test1();
|
|
// test1();
|
|
|
-// test2();
|
|
|
|
|
|
|
+ test2();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -38,7 +37,7 @@ public class AlreadyProtectedLibs_Test {
|
|
|
*
|
|
*
|
|
|
* 期望结果:
|
|
* 期望结果:
|
|
|
* 启动后,不能正常使用encrypted-lib-no-pwd-1.0.0.jar包的功能。
|
|
* 启动后,不能正常使用encrypted-lib-no-pwd-1.0.0.jar包的功能。
|
|
|
- * 根据my-project-with-encrypted-lib-no-pwd.jar中的逻辑,启动后会报错。
|
|
|
|
|
|
|
+ * 根据我提供的jar中的代码逻辑,启动后会报错。
|
|
|
*/
|
|
*/
|
|
|
private static void test0() {
|
|
private static void test0() {
|
|
|
String projectRootDir = PathUtil.getProjectRootDir(AlreadyProtectedLibs_Test.class);
|
|
String projectRootDir = PathUtil.getProjectRootDir(AlreadyProtectedLibs_Test.class);
|
|
@@ -62,7 +61,7 @@ public class AlreadyProtectedLibs_Test {
|
|
|
*
|
|
*
|
|
|
* 期望结果:
|
|
* 期望结果:
|
|
|
* 项目正常启动,且能正常使用encrypted-lib-no-pwd-1.0.0.jar的功能。
|
|
* 项目正常启动,且能正常使用encrypted-lib-no-pwd-1.0.0.jar的功能。
|
|
|
- * 根据my-project-with-encrypted-lib-no-pwd.jar中的逻辑,启动后会调用encrypted-lib-no-pwd-1.0.0.jar中的类输出一个加密解密。
|
|
|
|
|
|
|
+ * 根据我提供的jar中的代码逻辑, 当有<我是业务逻辑的输出>输出时,即表示成功了。
|
|
|
*/
|
|
*/
|
|
|
private static void test1() {
|
|
private static void test1() {
|
|
|
String projectRootDir = PathUtil.getProjectRootDir(AlreadyProtectedLibs_Test.class);
|
|
String projectRootDir = PathUtil.getProjectRootDir(AlreadyProtectedLibs_Test.class);
|
|
@@ -73,58 +72,57 @@ public class AlreadyProtectedLibs_Test {
|
|
|
// 那么这里值随便填一个使其不匹配当前项目的包前缀即可
|
|
// 那么这里值随便填一个使其不匹配当前项目的包前缀即可
|
|
|
.includePrefix("non-exist")
|
|
.includePrefix("non-exist")
|
|
|
.alreadyProtectedLibs("encrypted-lib-no-pwd-1.0.0.jar")
|
|
.alreadyProtectedLibs("encrypted-lib-no-pwd-1.0.0.jar")
|
|
|
|
|
+ .debug(true)
|
|
|
.build();
|
|
.build();
|
|
|
String encryptedJar = encryptExecutor.process();
|
|
String encryptedJar = encryptExecutor.process();
|
|
|
System.out.println(encryptedJar);
|
|
System.out.println(encryptedJar);
|
|
|
|
|
|
|
|
// (解密)启动
|
|
// (解密)启动
|
|
|
// 使用javaagent运行加密后的jar,测试
|
|
// 使用javaagent运行加密后的jar,测试
|
|
|
- String javaagentArgs = "";
|
|
|
|
|
|
|
+ // String javaagentArgs = "";
|
|
|
|
|
+ String javaagentArgs = "=debug=true";
|
|
|
// String javaagentArgs = "=debug=true,password=xxx";
|
|
// String javaagentArgs = "=debug=true,password=xxx";
|
|
|
BashUtil.runCmdAndPrint(String.format("java -javaagent:%s%s -jar %s", encryptedJar, javaagentArgs, encryptedJar));
|
|
BashUtil.runCmdAndPrint(String.format("java -javaagent:%s%s -jar %s", encryptedJar, javaagentArgs, encryptedJar));
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- TimeUnit.SECONDS.sleep(3);
|
|
|
|
|
- } catch (InterruptedException e) {
|
|
|
|
|
- // ignore
|
|
|
|
|
- }
|
|
|
|
|
- // 杀下进程(以防下一个测试方法启动jar时因为端口被占用启动不起来)
|
|
|
|
|
- BashUtil.killProcessByPorts("8080");
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 场景:
|
|
* 场景:
|
|
|
- * 项目my-project-with-encrypted-lib-no-pwd.jar中的lib包
|
|
|
|
|
- * encrypted-lib-no-pwd-1.0.0.jar本身就是被class-winter以用户主动指定的密码加密过了的
|
|
|
|
|
- * 测试期望结果:
|
|
|
|
|
- * 正常启动项目my-project-with-encrypted-lib-no-pwd.jar,并
|
|
|
|
|
- * 正常使用encrypted-lib-no-pwd-1.0.0.jar中的功能
|
|
|
|
|
|
|
+ * 项目my-project-with-encrypted-lib-have-pwd.jar中依赖了encrypted-lib-have-pwd-1.0.0.jar包,
|
|
|
|
|
+ * 但是这个encrypted-lib-have-pwd-1.0.0.jar包是被class-winter混淆了的,
|
|
|
|
|
+ * 如过想要正常使用my-project-with-encrypted-lib-have-pwd.jar,那么必须
|
|
|
|
|
+ * 对my-project-with-encrypted-lib-have-pwd.jar进行class-winter混淆,
|
|
|
|
|
+ * 且在alreadyProtectedLibs中指定encrypted-lib-have-pwd-1.0.0.jar及其密码。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 注:对mencrypted-lib-have-pwd-1.0.0.jar加密时,我主动指定了密码为qwer123~。
|
|
|
|
|
+ * 所以这里在alreadyProtectedLibs中指定encrypted-lib-have-pwd-1.0.0.jar时,需要把密码带上。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 测试case:
|
|
|
|
|
+ * 对项目my-project-with-encrypted-lib-have-pwd.jar进行class-winter混淆,然后使用javaagent启动jar。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 期望结果:
|
|
|
|
|
+ * 项目正常启动,且能正常使用my-project-with-encrypted-lib-have-pwd.jar的功能。
|
|
|
|
|
+ * 根据我提供的jar中的代码逻辑, 当有<我是业务逻辑的输出>输出时,即表示成功了。
|
|
|
*/
|
|
*/
|
|
|
private static void test2() {
|
|
private static void test2() {
|
|
|
String projectRootDir = PathUtil.getProjectRootDir(AlreadyProtectedLibs_Test.class);
|
|
String projectRootDir = PathUtil.getProjectRootDir(AlreadyProtectedLibs_Test.class);
|
|
|
// 加密
|
|
// 加密
|
|
|
EncryptExecutor encryptExecutor = EncryptExecutor.builder()
|
|
EncryptExecutor encryptExecutor = EncryptExecutor.builder()
|
|
|
- .originJarOrWar(projectRootDir + Constant.LINUX_FILE_SEPARATOR + "my-project-with-encrypted-lib-no-pwd.jar")
|
|
|
|
|
|
|
+ .originJarOrWar(projectRootDir + Constant.LINUX_FILE_SEPARATOR + "my-project-with-encrypted-lib-have-pwd.jar")
|
|
|
// includePrefix字段是必填的,但是我们项目(my-project-with-encrypted-lib-no-pwd.jar)本身是没有混淆的,
|
|
// includePrefix字段是必填的,但是我们项目(my-project-with-encrypted-lib-no-pwd.jar)本身是没有混淆的,
|
|
|
// 只是其中的lib(encrypted-lib-no-pwd-1.0.0.jar)混淆了,我们项目是没必要进行解密的,所以这里值随便填什么都可以的
|
|
// 只是其中的lib(encrypted-lib-no-pwd-1.0.0.jar)混淆了,我们项目是没必要进行解密的,所以这里值随便填什么都可以的
|
|
|
.includePrefix("non-exist")
|
|
.includePrefix("non-exist")
|
|
|
- .alreadyProtectedLibs("my-project-with-encrypted-lib-have-pwd.jar:qwer123~")
|
|
|
|
|
|
|
+ // 多个之间使用逗号隔开,形如 xxx1.jar:password1,xxx2.jar:password2
|
|
|
|
|
+ .alreadyProtectedLibs("encrypted-lib-have-pwd-1.0.0.jar:qwer123~")
|
|
|
|
|
+ .debug(true)
|
|
|
.build();
|
|
.build();
|
|
|
String encryptedJar = encryptExecutor.process();
|
|
String encryptedJar = encryptExecutor.process();
|
|
|
System.out.println(encryptedJar);
|
|
System.out.println(encryptedJar);
|
|
|
|
|
|
|
|
// (解密)启动
|
|
// (解密)启动
|
|
|
// 使用javaagent运行加密后的jar,测试
|
|
// 使用javaagent运行加密后的jar,测试
|
|
|
- String javaagentArgs = "";
|
|
|
|
|
|
|
+ // String javaagentArgs = "";
|
|
|
|
|
+ String javaagentArgs = "=debug=true";
|
|
|
// String javaagentArgs = "=debug=true,password=xxx";
|
|
// String javaagentArgs = "=debug=true,password=xxx";
|
|
|
BashUtil.runCmdAndPrint(String.format("java -javaagent:%s%s -jar %s", encryptedJar, javaagentArgs, encryptedJar));
|
|
BashUtil.runCmdAndPrint(String.format("java -javaagent:%s%s -jar %s", encryptedJar, javaagentArgs, encryptedJar));
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- TimeUnit.SECONDS.sleep(3);
|
|
|
|
|
- } catch (InterruptedException e) {
|
|
|
|
|
- // ignore
|
|
|
|
|
- }
|
|
|
|
|
- // 杀下进程(以防下一个测试方法启动jar时因为端口被占用启动不起来)
|
|
|
|
|
- BashUtil.killProcessByPorts("8080");
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|