|
@@ -1,44 +1,99 @@
|
|
|
package winter.com.ideaaedi.classwinter;
|
|
package winter.com.ideaaedi.classwinter;
|
|
|
|
|
|
|
|
import winter.com.ideaaedi.classwinter.author.JustryDeng;
|
|
import winter.com.ideaaedi.classwinter.author.JustryDeng;
|
|
|
-import winter.com.ideaaedi.classwinter.executor.EncryptExecutor;
|
|
|
|
|
import winter.com.ideaaedi.classwinter.util.BashUtil;
|
|
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
|
|
|
|
|
- *
|
|
|
|
|
|
|
+ * 测试excludePrefix
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * excludePrefix: 对includePrefix定位出来的加密范围,进行排除
|
|
|
|
|
+ * </p>
|
|
|
* @author {@link JustryDeng}
|
|
* @author {@link JustryDeng}
|
|
|
* @since 2021/6/12 14:34:45
|
|
* @since 2021/6/12 14:34:45
|
|
|
*/
|
|
*/
|
|
|
public class ExcludePrefix_Test {
|
|
public class ExcludePrefix_Test {
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
|
- String projectRootDir = PathUtil.getProjectRootDir(ExcludePrefix_Test.class);
|
|
|
|
|
|
|
+ // 杀下进程(以保证端口没有被占用)
|
|
|
|
|
+ BashUtil.killProcessByPorts("8080");
|
|
|
|
|
+ test0();
|
|
|
|
|
+// test1();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * case:
|
|
|
|
|
+ * 根据前缀匹配,以com.aspire.ssm.util.AesEncryptDecryptUtil和com.aspire.ssm.util.DbSecurityBeanUtil为前缀的类都会被加密
|
|
|
|
|
+ * 观察输入日志:
|
|
|
|
|
+ * 2021-06-13 15:54:32 [DEBUG] winter.com.ideaaedi.classwinter.executor.EncryptExecutor: Encrypt class[com.aspire.ssm.util.AesEncryptDecryptUtil] start.
|
|
|
|
|
+ * 2021-06-13 15:54:34 [DEBUG] winter.com.ideaaedi.classwinter.executor.EncryptExecutor: Encrypt class[com.aspire.ssm.util.AesEncryptDecryptUtil] end.
|
|
|
|
|
+ * 2021-06-13 15:54:34 [DEBUG] winter.com.ideaaedi.classwinter.executor.EncryptExecutor: Encrypt class[com.aspire.ssm.util.DbSecurityBeanUtil$NotSupportedEncryptDecryptException] start.
|
|
|
|
|
+ * 2021-06-13 15:54:34 [DEBUG] winter.com.ideaaedi.classwinter.executor.EncryptExecutor: Encrypt class[com.aspire.ssm.util.DbSecurityBeanUtil$NotSupportedEncryptDecryptException] end.
|
|
|
|
|
+ * 2021-06-13 15:54:34 [DEBUG] winter.com.ideaaedi.classwinter.executor.EncryptExecutor: Encrypt class[com.aspire.ssm.util.DbSecurityBeanUtil] start.
|
|
|
|
|
+ * 2021-06-13 15:54:34 [DEBUG] winter.com.ideaaedi.classwinter.executor.EncryptExecutor: Encrypt class[com.aspire.ssm.util.DbSecurityBeanUtil] end.
|
|
|
|
|
+ * 可知确实以com.aspire.ssm.util.AesEncryptDecryptUtil和com.aspire.ssm.util.DbSecurityBeanUtil为前缀的类都被加密了
|
|
|
|
|
+ */
|
|
|
|
|
+ public static void test0() {
|
|
|
|
|
+ String projectRootDir = PathUtil.getProjectRootDir(AlreadyProtectedLibs_Test.class);
|
|
|
|
|
+ // 加密(模拟命令行输入对jar包进行加密)
|
|
|
|
|
+ String originJarOrWar = projectRootDir + "boot-jar.jar";
|
|
|
|
|
+ String includePrefix = "com.aspire.ssm.util.AesEncryptDecryptUtil,com.aspire.ssm.util.DbSecurityBeanUtil";
|
|
|
|
|
+
|
|
|
|
|
+ String startBat = "java -jar class-winter-core.jar"
|
|
|
|
|
+ + " originJarOrWar=" + originJarOrWar
|
|
|
|
|
+ + " includePrefix=" + includePrefix
|
|
|
|
|
+ + " debug=" + true
|
|
|
|
|
+ ;
|
|
|
|
|
|
|
|
- // 加密
|
|
|
|
|
- EncryptExecutor encryptExecutor = EncryptExecutor.builder()
|
|
|
|
|
- .originJarOrWar(projectRootDir + Constant.LINUX_FILE_SEPARATOR + "boot-jar.jar")
|
|
|
|
|
- .includePrefix("non-exist")
|
|
|
|
|
- .build();
|
|
|
|
|
- String encryptedJar = encryptExecutor.process();
|
|
|
|
|
- System.out.println(encryptedJar);
|
|
|
|
|
|
|
+ String[] args = startBat.replace("java -jar class-winter-core.jar" , "").trim().split(" ");
|
|
|
|
|
+ Forward.main(args);
|
|
|
|
|
|
|
|
- // (解密)启动
|
|
|
|
|
- // 使用javaagent运行加密后的jar,测试
|
|
|
|
|
- String javaagentArgs = "";
|
|
|
|
|
- //String javaagentArgs = "=debug=true,password=xxx";
|
|
|
|
|
|
|
+
|
|
|
|
|
+ String encryptedJar = originJarOrWar.replace(".jar", "-encrypted.jar");
|
|
|
|
|
+
|
|
|
|
|
+ // 解密(模拟启动加密后的jar包)
|
|
|
|
|
+ // String javaagentArgs = "";
|
|
|
|
|
+ String javaagentArgs = "=debug=true";
|
|
|
|
|
+ // String javaagentArgs = "=debug=true,password=xxx";
|
|
|
|
|
+ BashUtil.runCmdAndPrint(String.format("java -javaagent:%s%s -jar %s", encryptedJar, javaagentArgs, encryptedJar));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * case:
|
|
|
|
|
+ * 根据前缀匹配,本来以com.aspire.ssm.util.AesEncryptDecryptUtil和com.aspire.ssm.util.DbSecurityBeanUtil为前缀的类都会被加密的,
|
|
|
|
|
+ * 但是excludePrefix对以com.aspire.ssm.util.DbSecurityBeanUtil为前缀的类进行了排除,所以最
|
|
|
|
|
+ * 终只会有以com.aspire.ssm.util.AesEncryptDecryptUtil为前缀的类会被加密
|
|
|
|
|
+ * 观察输入日志:
|
|
|
|
|
+ * 2021-06-13 15:51:57 [DEBUG] winter.com.ideaaedi.classwinter.executor.EncryptExecutor: Encrypt class[com.aspire.ssm.util.AesEncryptDecryptUtil] start.
|
|
|
|
|
+ * 2021-06-13 15:52:01 [DEBUG] winter.com.ideaaedi.classwinter.executor.EncryptExecutor: Encrypt class[com.aspire.ssm.util.AesEncryptDecryptUtil] end.
|
|
|
|
|
+ * 可知确实只有AesEncryptDecryptUtil被加密了,DbSecurityBeanUtil没有被加密
|
|
|
|
|
+ */
|
|
|
|
|
+ public static void test1() {
|
|
|
|
|
+ String projectRootDir = PathUtil.getProjectRootDir(AlreadyProtectedLibs_Test.class);
|
|
|
|
|
+ // 加密(模拟命令行输入对jar包进行加密)
|
|
|
|
|
+ String originJarOrWar = projectRootDir + "boot-jar.jar";
|
|
|
|
|
+ String includePrefix = "com.aspire.ssm.util.AesEncryptDecryptUtil,com.aspire.ssm.util.DbSecurityBeanUtil";
|
|
|
|
|
+ String excludePrefix = "com.aspire.ssm.util.DbSecurityBeanUtil";
|
|
|
|
|
+
|
|
|
|
|
+ String startBat = "java -jar class-winter-core.jar"
|
|
|
|
|
+ + " originJarOrWar=" + originJarOrWar
|
|
|
|
|
+ + " includePrefix=" + includePrefix
|
|
|
|
|
+ + " excludePrefix=" + excludePrefix
|
|
|
|
|
+ + " debug=" + true
|
|
|
|
|
+ ;
|
|
|
|
|
+
|
|
|
|
|
+ String[] args = startBat.replace("java -jar class-winter-core.jar" , "").trim().split(" ");
|
|
|
|
|
+ Forward.main(args);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ String encryptedJar = originJarOrWar.replace(".jar", "-encrypted.jar");
|
|
|
|
|
+
|
|
|
|
|
+ // 解密(模拟启动加密后的jar包)
|
|
|
|
|
+ // String javaagentArgs = "";
|
|
|
|
|
+ String javaagentArgs = "=debug=true";
|
|
|
|
|
+ // 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");
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|