Compare commits

...

3 Commits

2 changed files with 30 additions and 94 deletions

87
pom.xml
View File

@ -4,7 +4,7 @@
<groupId>com.sunyard</groupId> <groupId>com.sunyard</groupId>
<artifactId>sydapi4j</artifactId> <artifactId>sydapi4j</artifactId>
<version>1.0.2022-SNAPSHOT</version> <version>1.13.20220909-1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>sydapi4j</name> <name>sydapi4j</name>
@ -26,59 +26,11 @@
<version>4.12</version> <version>4.12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.github.houbb</groupId>
<artifactId>junitperf</artifactId>
<version>1.0.3</version>
<scope>test</scope>
</dependency>
<!-- &lt;!&ndash; https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>org.apache.commons</groupId>-->
<!-- <artifactId>commons-pool2</artifactId>-->
<!-- <version>2.11.1</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.jetbrains.kotlin</groupId>-->
<!-- <artifactId>kotlin-test</artifactId>-->
<!-- <version>${kotlin.version}</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<!-- &lt;!&ndash; https://mvnrepository.com/artifact/dom4j/dom4j &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>dom4j</groupId>-->
<!-- <artifactId>dom4j</artifactId>-->
<!-- <version>1.6.1</version>-->
<!-- </dependency>-->
<!-- &lt;!&ndash; https://mvnrepository.com/artifact/com.alibaba/fastjson &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>com.alibaba</groupId>-->
<!-- <artifactId>fastjson</artifactId>-->
<!-- <version>1.2.80</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.jetbrains.kotlin</groupId>-->
<!-- <artifactId>kotlin-stdlib-jdk8</artifactId>-->
<!-- <version>${kotlin.version}</version>-->
<!-- </dependency>-->
<!--<dependency>-->
<!--<groupId>com.sunyard</groupId>-->
<!--<artifactId>Converter</artifactId>-->
<!--<version>[1.0.201807251700, 1.1-SNAPSHOT)</version>-->
<!--</dependency>-->
<dependency> <dependency>
<groupId>com.sunyard</groupId> <groupId>com.sunyard</groupId>
<artifactId>proto</artifactId> <artifactId>proto</artifactId>
<version>1.1.20221215</version> <version>1.0.20221215</version>
</dependency> </dependency>
<dependency> <dependency>
@ -87,35 +39,6 @@
<version>5.4.3</version> <version>5.4.3</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.65</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.65</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.4.M1</version>
</dependency>
<!--<dependency>-->
<!--<groupId>club.fullstack</groupId>-->
<!--<artifactId>serialize</artifactId>-->
<!--<version>[1.0.201806051035, 1.1.SNAPSHOT)</version>-->
<!--</dependency>-->
<!-- https://mvnrepository.com/artifact/com.github.wvengen/proguard-maven-plugin -->
<!-- https://mvnrepository.com/artifact/com.github.wvengen/proguard-maven-plugin -->
</dependencies> </dependencies>
<build> <build>
<finalName>sydapi4j</finalName> <finalName>sydapi4j</finalName>
@ -149,8 +72,8 @@
</execution> </execution>
</executions> </executions>
<configuration> <configuration>
<source>6</source> <source>1.6</source>
<target>6</target> <target>1.6</target>
<compilerId>groovy-eclipse-compiler</compilerId> <compilerId>groovy-eclipse-compiler</compilerId>
<verbose>true</verbose> <verbose>true</verbose>
<fork>true</fork> <fork>true</fork>
@ -243,7 +166,7 @@
<configuration> <configuration>
<archive> <archive>
<manifest> <manifest>
<mainClass>com.Sample.TestDemo</mainClass> <mainClass>racal.sunyard.main.Version</mainClass>
</manifest> </manifest>
</archive> </archive>
<descriptorRefs> <descriptorRefs>

View File

@ -1049,11 +1049,9 @@ public class SydApi4j implements SydApi {
} }
// 测试通过 public boolean detachedVerify(int dataType, byte[] orgData, String sign, Boolean checkCert) {
@Override
public boolean detachedVerify(int dataType, byte[] orgData, String sign) {
Proto8006 proto = new Proto8006(); Proto8006 proto = new Proto8006();
// 填充数据 // 填充数据
HashMap<String, Object> packet = new HashMap<String, Object>(); HashMap<String, Object> packet = new HashMap<String, Object>();
PacketSN sn = PacketSN.gen(); PacketSN sn = PacketSN.gen();
@ -1071,7 +1069,7 @@ public class SydApi4j implements SydApi {
data.put("signData", sign.getBytes()); data.put("signData", sign.getBytes());
data.put("flag$option", 0); data.put("flag$option", checkCert ? 1 : 0);
// 渲染发送 // 渲染发送
ByteBuffer bb = proto.rend(packet); ByteBuffer bb = proto.rend(packet);
@ -1102,6 +1100,12 @@ public class SydApi4j implements SydApi {
return true; return true;
} }
// 测试通过
@Override
public boolean detachedVerify(int dataType, byte[] orgData, String sign) {
return detachedVerify(dataType, orgData, sign, false);
}
public boolean detachedVerifyAll(int rFlag,byte[] orgData, String sign){ public boolean detachedVerifyAll(int rFlag,byte[] orgData, String sign){
try { try {
boolean sm2Cert = CertUtil.isSignedBySM2Cert(sign); boolean sm2Cert = CertUtil.isSignedBySM2Cert(sign);
@ -12120,7 +12124,7 @@ public class SydApi4j implements SydApi {
byte[] pk = (byte[]) ret.get("pk"); byte[] pk = (byte[]) ret.get("pk");
byte[] hash = this.SM3Hash(Util.bytes2HexString(pk), orgData); byte[] hash = this.SM3Hash(Util.bytes2HexString(pk), orgData);
String sign2 = (String) ret.get("sign"); String sign2 = (String) ret.get("sign");
boolean pass = this.detachedVerify(0, hash, sign2); boolean pass = this.detachedVerify(0, hash, sign2, true);
if (pass) { if (pass) {
ret.put("oData", orgData); ret.put("oData", orgData);
String certInfo = (String) ret.get("cert"); String certInfo = (String) ret.get("cert");
@ -12409,9 +12413,9 @@ public class SydApi4j implements SydApi {
@Override @Override
public byte[] attachedVerifyRD(byte[] sign) { public byte[] attachedVerifyRD(byte[] sign) {
RetWrap retWrap = attachedVerifyAndGetAll(sign); RetWrap retWrap = attachedVerifyAndGetAll(sign);
if (retWrap == null) if (retWrap == null) {
return null; return null;
}
return (byte[]) retWrap.get("oData"); return (byte[]) retWrap.get("oData");
} }
@ -12422,23 +12426,29 @@ public class SydApi4j implements SydApi {
* @param sign 已签名数据 * @param sign 已签名数据
* @return 返回CERT_INFO结构的证书数据 * @return 返回CERT_INFO结构的证书数据
*/ */
@Override
public X509 attachedVerifyAndGetX509(String sign) { public X509 attachedVerifyAndGetX509(String sign) {
return attachedVerifyAndGetX509( sign.getBytes() ); return attachedVerifyAndGetX509( sign.getBytes() );
} }
@Override
public X509 attachedVerifyAndGetX509(byte[] sign) { public X509 attachedVerifyAndGetX509(byte[] sign) {
RetWrap retWrap = attachedVerifyAndGetAll( sign); RetWrap retWrap = attachedVerifyAndGetAll( sign);
if (retWrap == null)
if (retWrap == null) {
return null; return null;
}
return (X509) retWrap.get("x509"); return (X509) retWrap.get("x509");
} }
public RetWrap attachedVerifyAndGetAll(String sign) { public RetWrap attachedVerifyAndGetAll(String sign) {
return attachedVerifyAndGetAll( sign.getBytes() ); return attachedVerifyAndGetAll( sign.getBytes() );
} }
// 大数据兼容处理 // 大数据兼容处理
@Override
public RetWrap attachedVerifyAndGetAll(byte[] sign) { public RetWrap attachedVerifyAndGetAll(byte[] sign) {
if( sign.length > 4096 ) { if( sign.length > 4096 ) {
@ -12483,7 +12493,10 @@ public class SydApi4j implements SydApi {
PacketSection error = (PacketSection) ret.get("error"); PacketSection error = (PacketSection) ret.get("error");
byte[] be = error.getBytes(); byte[] be = error.getBytes();
if ((0 != (be[0] ^ be[1]))) { if ((0 != (be[0] ^ be[1]))) {
return null; SydApiException e = new SydApiException(error.getInfo(), error.autoInt());
// println("验签失败=" + e.toString());
// return null;
throw e;
} }
PacketSection info = (PacketSection) ret.get("info"); PacketSection info = (PacketSection) ret.get("info");