Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3.x.x #45

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
32508a0
加密时签名
Jul 3, 2019
b2711d8
增加按文件路径加解密的方法
Jul 4, 2019
d59538c
增加Builder来创建加密解密器
Jul 4, 2019
810437e
增加Builder来创建加密解密器
Jul 4, 2019
fb36507
增加Builder来创建加密解密器
Jul 4, 2019
e01163b
增加Builder来创建加密解密器
Jul 4, 2019
133cbd0
增加Builder来创建加密解密器
Jul 4, 2019
cdfd498
增加Builder来创建加密解密器
Jul 4, 2019
30b198c
增加Builder来创建加密解密器
Jul 5, 2019
7ffd87b
重构摘要算法代码
Jul 5, 2019
d287bda
加密时签名
core-lib Jul 6, 2019
d2ef5df
重构摘要算法代码
Jul 8, 2019
4adee62
重构摘要算法代码
Jul 8, 2019
c62fd3c
重构摘要算法代码
Jul 8, 2019
21151d1
重构摘要算法代码
Jul 8, 2019
4348205
重构摘要算法代码
Jul 9, 2019
07c95f3
重构摘要算法代码
Jul 9, 2019
9e625c4
重构摘要算法代码
Jul 10, 2019
225a03e
重构摘要算法代码
Jul 11, 2019
faeb6ec
生成so库
Jul 15, 2019
97b2fbe
生成so库
Jul 15, 2019
5e7a3f2
生成so库
Jul 16, 2019
4f4deb2
生成so库
Jul 16, 2019
f1dcc57
生成so库
Jul 16, 2019
fabef41
生成so库
Jul 16, 2019
37870e7
生成so库
Jul 16, 2019
41ecb47
生成so库
Jul 16, 2019
11cb622
生成so库
Jul 17, 2019
df7be9b
解决多jar包启动时无法找到准确的MANIFEST.MF导致无法正常启动的问题
Jul 23, 2019
9b98407
解决多jar包启动时无法找到准确的MANIFEST.MF导致无法正常启动的问题
Jul 23, 2019
c3dedf4
解决多jar包启动时无法找到准确的MANIFEST.MF导致无法正常启动的问题
Jul 23, 2019
aaf1506
解决多jar包启动时无法找到准确的MANIFEST.MF导致无法正常启动的问题
Jul 23, 2019
fe47ad0
只编译cpp 文件
core-lib Jul 23, 2019
badc388
解决多jar包启动时无法找到准确的MANIFEST.MF导致无法正常启动的问题
Jul 23, 2019
531e85b
解决多jar包启动时无法找到准确的MANIFEST.MF导致无法正常启动的问题
Jul 24, 2019
5f1be8c
解决多jar包启动时无法找到准确的MANIFEST.MF导致无法正常启动的问题
Jul 24, 2019
5611c06
修复加密过滤问题
Jul 26, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.xjar</groupId>
<artifactId>xjar</artifactId>
<version>v2.0.5</version>
<version>v3.0.0-demo-build-3</version>

<name>xjar</name>

Expand Down Expand Up @@ -40,6 +40,18 @@
<version>2.0.1.RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.ibeetl</groupId>
<artifactId>beetl</artifactId>
<version>3.0.8.RELEASE</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/io/xjar/XArchiveDecryptor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.xjar;

import io.xjar.key.XKey;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
* 记录可过滤的加密器
*
* @author Payne [email protected]
* 2018/11/23 20:38
*/
public abstract class XArchiveDecryptor<E> extends XEntryDecryptor<E> implements XDecryptor, XEntryFilter<E> {

protected XArchiveDecryptor(XDecryptor xDecryptor, XEntryFilter<E> filter) {
super(xDecryptor, filter);
}

@Override
public void decrypt(XKey key, String src, String dest) throws IOException {
decrypt(key, new File(src), new File(dest));
}

@Override
public void decrypt(XKey key, File src, File dest) throws IOException {
try (
FileInputStream fis = new FileInputStream(src);
FileOutputStream fos = new FileOutputStream(dest)
) {
decrypt(key, fis, fos);
}
}

protected static abstract class XArchiveDecryptorBuilder<E, T extends XArchiveDecryptor<E>, B extends XArchiveDecryptorBuilder<E, T, B>> extends XEntryDecryptorBuilder<E, T, B> {
}
}
39 changes: 39 additions & 0 deletions src/main/java/io/xjar/XArchiveEncryptor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.xjar;

import io.xjar.key.XKey;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
* 记录可过滤的加密器
*
* @author Payne [email protected]
* 2018/11/23 20:38
*/
public abstract class XArchiveEncryptor<E> extends XEntryEncryptor<E> implements XEncryptor, XEntryFilter<E> {

protected XArchiveEncryptor(XEncryptor xEncryptor, XEntryFilter<E> filter) {
super(xEncryptor, filter);
}

@Override
public void encrypt(XKey key, String src, String dest) throws IOException {
encrypt(key, new File(src), new File(dest));
}

@Override
public void encrypt(XKey key, File src, File dest) throws IOException {
try (
FileInputStream fis = new FileInputStream(src);
FileOutputStream fos = new FileOutputStream(dest)
) {
encrypt(key, fis, fos);
}
}

protected static abstract class XArchiveEncryptorBuilder<E, T extends XArchiveEncryptor<E>, B extends XArchiveEncryptorBuilder<E, T, B>> extends XEntryEncryptorBuilder<E, T, B> {
}
}
26 changes: 26 additions & 0 deletions src/main/java/io/xjar/XCompiler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.xjar;

import io.xjar.key.XKey;

import java.io.File;
import java.io.IOException;

/**
* 编译器
*
* @author Payne [email protected]
* 2019/7/15 10:33
*/
public interface XCompiler {

/**
* 编译
*
* @param xKey 密钥
* @param xSignature 签名
* @return 编译后文件
* @throws IOException I/O异常
*/
File compile(XKey xKey, XSignature xSignature) throws IOException;

}
10 changes: 0 additions & 10 deletions src/main/java/io/xjar/XConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ public interface XConstants {
String BOOT_INF_CLASSES = "BOOT-INF/classes/";
String BOOT_INF_LIB = "BOOT-INF/lib/";

String WEB_INF_CLASSES = "WEB-INF/classes/";
String WEB_INF_LIB = "WEB-INF/lib/";

String META_INF_MANIFEST = "META-INF/MANIFEST.MF";
String XJAR_SRC_DIR = XConstants.class.getPackage().getName().replace('.', '/') + "/";
String XJAR_INF_DIR = "XJAR-INF/";
Expand Down Expand Up @@ -40,11 +37,4 @@ public interface XConstants {
int DEFAULT_KEYSIZE = 128;
int DEFAULT_IVSIZE = 128;

// 保留密钥在 META-INF/MANIFEST.MF 中,启动时无需输入密钥。
int FLAG_DANGER = 1;
// 危险模式:保留密钥
int MODE_DANGER = FLAG_DANGER;
// 普通模式
int MODE_NORMAL = 0;

}
10 changes: 10 additions & 0 deletions src/main/java/io/xjar/XDecryptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
*/
public interface XDecryptor {

/**
* 解密,将目标文件解密输出至目标文件。
*
* @param key 密钥
* @param src 源文件
* @param dest 目标文件
* @throws IOException I/O 异常
*/
void decrypt(XKey key, String src, String dest) throws IOException;

/**
* 解密,将目标文件解密输出至目标文件。
*
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/io/xjar/XDigest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.xjar;

/**
* 摘要算法
*
* @author Payne [email protected]
* 2019/7/3 22:25
*/
public interface XDigest {

/**
* 计算数据摘要
*
* @param buf 缓冲
* @param off 下标
* @param len 长度
*/
void digest(byte[] buf, int off, int len);

/**
* 结束计算并返回摘要值
*
* @return 最终摘要值
*/
byte[] finish();

/**
* 恢复初始状态
*/
void resume();

}
30 changes: 30 additions & 0 deletions src/main/java/io/xjar/XDigestFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.xjar;

import java.security.NoSuchAlgorithmException;

/**
* 摘要算法对象工厂
*
* @author Payne [email protected]
* 2019/7/5 10:16
*/
public interface XDigestFactory {

/**
* 生产摘要算法对象
*
* @param algorithm 摘要算法
* @return 摘要算法对象
* @throws NoSuchAlgorithmException 摘要算法不支持
*/
XDigest acquire(String algorithm) throws NoSuchAlgorithmException;

/**
* 回收摘要算法对象
*
* @param algorithm 摘要算法
* @param digest 摘要算法对象
*/
void release(String algorithm, XDigest digest);

}
35 changes: 35 additions & 0 deletions src/main/java/io/xjar/XDigestedInputStream.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.xjar;

import org.apache.commons.compress.archivers.jar.JarArchiveInputStream;

import java.io.IOException;
import java.io.InputStream;

/**
* 摘要计算的输入流
*
* @author Payne [email protected]
* 2019/7/3 22:31
*/
public class XDigestedInputStream extends JarArchiveInputStream {
private final XDigest xDigest;

public XDigestedInputStream(InputStream in, XDigest xDigest) {
super(in);
this.xDigest = xDigest;
}

public XDigestedInputStream(InputStream in, String encoding, XDigest xDigest) {
super(in, encoding);
this.xDigest = xDigest;
}

@Override
public int read(byte[] buffer, int offset, int length) throws IOException {
length = super.read(buffer, offset, length);
if (length > 0) {
xDigest.digest(buffer, offset, length);
}
return length;
}
}
34 changes: 34 additions & 0 deletions src/main/java/io/xjar/XDigestedOutputStream.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.xjar;

import org.apache.commons.compress.archivers.jar.JarArchiveOutputStream;

import java.io.IOException;
import java.io.OutputStream;

/**
* 摘要计算的输出流
*
* @author Payne [email protected]
* 2019/7/3 22:30
*/
public class XDigestedOutputStream extends JarArchiveOutputStream {
private final XDigest xDigest;

public XDigestedOutputStream(OutputStream out, XDigest xDigest) {
super(out);
this.xDigest = xDigest;
}

public XDigestedOutputStream(OutputStream out, String encoding, XDigest xDigest) {
super(out, encoding);
this.xDigest = xDigest;
}

@Override
public void write(byte[] buffer, int offset, int length) throws IOException {
super.write(buffer, offset, length);
if (length > 0) {
xDigest.digest(buffer, offset, length);
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/io/xjar/XEncryptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
*/
public interface XEncryptor {

/**
* 加密,将目标文件加密输出至目标文件。
*
* @param key 密钥
* @param src 源文件
* @param dest 目标文件
* @throws IOException I/O 异常
*/
void encrypt(XKey key, String src, String dest) throws IOException;

/**
* 加密,将目标文件加密输出至目标文件。
*
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/io/xjar/XEntryDecryptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ public abstract class XEntryDecryptor<E> extends XWrappedDecryptor implements XD
protected final XEntryFilter<E> filter;
protected final XNopDecryptor xNopDecryptor = new XNopDecryptor();

protected XEntryDecryptor(XDecryptor xDecryptor) {
this(xDecryptor, null);
}

protected XEntryDecryptor(XDecryptor xDecryptor, XEntryFilter<E> filter) {
super(xDecryptor);
this.filter = filter;
Expand All @@ -23,4 +19,13 @@ protected XEntryDecryptor(XDecryptor xDecryptor, XEntryFilter<E> filter) {
public boolean filtrate(E entry) {
return filter == null || filter.filtrate(entry);
}

protected static abstract class XEntryDecryptorBuilder<E, T extends XEntryDecryptor<E>, B extends XEntryDecryptorBuilder<E, T, B>> extends XWrappedDecryptorBuilder<T, B> {
protected XEntryFilter<E> filter;

public B filter(XEntryFilter<E> filter) {
this.filter = filter;
return (B) this;
}
}
}
13 changes: 9 additions & 4 deletions src/main/java/io/xjar/XEntryEncryptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ public abstract class XEntryEncryptor<E> extends XWrappedEncryptor implements XE
protected final XEntryFilter<E> filter;
protected final XNopEncryptor xNopEncryptor = new XNopEncryptor();

protected XEntryEncryptor(XEncryptor xEncryptor) {
this(xEncryptor, null);
}

protected XEntryEncryptor(XEncryptor xEncryptor, XEntryFilter<E> filter) {
super(xEncryptor);
this.filter = filter;
Expand All @@ -23,4 +19,13 @@ protected XEntryEncryptor(XEncryptor xEncryptor, XEntryFilter<E> filter) {
public boolean filtrate(E entry) {
return filter == null || filter.filtrate(entry);
}

protected static abstract class XEntryEncryptorBuilder<E, T extends XEntryEncryptor<E>, B extends XEntryEncryptorBuilder<E, T, B>> extends XWrappedEncryptorBuilder<T, B> {
protected XEntryFilter<E> filter;

public B filter(XEntryFilter<E> filter) {
this.filter = filter;
return (B) this;
}
}
}
7 changes: 4 additions & 3 deletions src/main/java/io/xjar/XInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ public class XInjector {
* 往JAR包中注入XJar框架的classes
*
* @param zos jar包输出流
* @param ant 资源路径ANT表达式
* @throws IOException I/O 异常
*/
public static void inject(JarArchiveOutputStream zos) throws IOException {
public static void inject(JarArchiveOutputStream zos, String ant) throws IOException {
Set<String> directories = new HashSet<>();
Enumeration<Resource> resources = Loaders.ant().load("io/xjar/**");
Enumeration<Resource> resources = Loaders.ant().load(ant);
while (resources.hasMoreElements()) {
Resource resource = resources.nextElement();
String name = resource.getName();
Expand All @@ -42,7 +43,7 @@ public static void inject(JarArchiveOutputStream zos) throws IOException {
xJarEntry.setTime(System.currentTimeMillis());
zos.putArchiveEntry(xJarEntry);
try (InputStream ris = resource.getInputStream()) {
XKit.transfer(ris, zos);
XTool.transfer(ris, zos);
}
zos.closeArchiveEntry();
}
Expand Down
Loading