diff --git a/DProto/8008.xml b/DProto/8008.xml index 4cbd3c0..115b701 100644 --- a/DProto/8008.xml +++ b/DProto/8008.xml @@ -7,18 +7,9 @@ - - - - - - + + 0:起始包 + 其他:传入上一个包返回的数据标志 @@ -75,10 +66,7 @@ - 0:起始包 - 1:中间包 - 2:结束包 - (可能hi因为字节对此,后三字节为垃圾值) + 已返回证书个数 diff --git a/pom.xml b/pom.xml index ad75304..f02cd96 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,11 @@ 4.12 test + + com.github.houbb + junitperf + 1.0.3 + diff --git a/src/main/java/racal/sunyard/main/SydApi4j.java b/src/main/java/racal/sunyard/main/SydApi4j.java index bed24b2..0c9f28e 100644 --- a/src/main/java/racal/sunyard/main/SydApi4j.java +++ b/src/main/java/racal/sunyard/main/SydApi4j.java @@ -1261,7 +1261,7 @@ public class SydApi4j implements SydApi { PacketSN sn = PacketSN.gen(); packet.put("header", sn.getSn().array()); - data.put("dataFlag$option", dataFlag); + data.put("dataFlag",Util.slenBytes(dataFlag,4)); String sqlite3 = "1 = 1 "; data.put("sqlite3", sqlite3); @@ -1293,13 +1293,17 @@ public class SydApi4j implements SydApi { RetWrap r = new RetWrap(); PacketSection resDataFlag = (PacketSection) ret.get("dataFlag"); - r.put("dataFlag", (int) resDataFlag.getBytes()[0]); PacketSection certAllNum = (PacketSection) ret.get("certAllNum"); - r.put("certAllNum", (int) certAllNum.getBytes()[0]); - PacketSection realCertNum = (PacketSection) ret.get("realCertNum"); - r.put("realCertNum", (int) realCertNum.getBytes()[0]); PacketSection dataAttrFlag = (PacketSection) ret.get("dataAttrFlag"); - r.put("dataAttrFlag", (int) dataAttrFlag.getBytes()[0]); + PacketSection realCertNum = (PacketSection) ret.get("realCertNum"); + try { + r.put("dataFlag",Util.smallLen(resDataFlag.getBytes()) ); + r.put("certAllNum", Util.smallLen(certAllNum.getBytes())); + r.put("dataAttrFlag", Util.smallLen(dataAttrFlag.getBytes())); + r.put("realCertNum", Util.smallLen(realCertNum.getBytes())); + } catch (Exception e) { + e.printStackTrace(); + } r.put("certLenMax", Integer.parseInt(Util.bytes2HexString(Util.toArray(bb)).substring(60, 62), 16)); List certs = new ArrayList(); @@ -1309,11 +1313,13 @@ public class SydApi4j implements SydApi { certs.add(new String(cert, "GBK")); } - r.put("certDNs", certs.toArray(new String[0])); - r.put("certDNlist", certs); +// r.put("certDNs",certs.toArray(new String[0]) ); + + r.put("certDNs",certs); return r; } + // 测试通过 @Override public RetWrap getAllCert(int dataFlag,String sqlite) throws UnsupportedEncodingException { diff --git a/src/test/java/com/sunyard/sydapi/test/CertTest.java b/src/test/java/com/sunyard/sydapi/test/CertTest.java new file mode 100644 index 0000000..611947c --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/CertTest.java @@ -0,0 +1,67 @@ +package com.sunyard.sydapi.test; + +import com.github.houbb.junitperf.core.annotation.JunitPerfConfig; +import com.github.houbb.junitperf.core.rule.JunitPerfRule; +import com.sunyard.RetWrap; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import racal.sunyard.main.SydApi4j; + +import java.io.UnsupportedEncodingException; + +import static com.sunyard.sydapi.util.PrintUtil.printRetWrap; + +public class CertTest { + + + public static void main(String[] args) { + System.setProperty("com.sunyard.sydapi4j.debug", "true"); + + SydApi4j api = (SydApi4j) new SydApi4j().connect("192.168.1.129", 8889, null, 1000); + try{ + RetWrap allCert = api.getAllCert(0); + printRetWrap(allCert); + + }catch (Exception e){ + e.printStackTrace(); + }finally { + api.disconnect(); + } + } + + // 测试参数 +// private static final int threads = 1; +// private static final long duration = 120000; +// private static final long warmUp = 30000; +// +// +// @Rule +// public JunitPerfRule junitPerfRule = new JunitPerfRule(); +// SydApi4j api = (SydApi4j) new SydApi4j().connect("192.168.1.129",8889,null,3000); +// +// +// @BeforeClass +// public static void init() throws UnsupportedEncodingException { +// System.out.println("begin"); +// +// } +// +// +// @AfterClass +// public static void after() { +// System.out.println("all over"); +// } +// +// @Test +// @JunitPerfConfig(threads = threads, warmUp = warmUp, duration = duration) +// public void getAllCert(){ +// try { +// api.getAllCert(0); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// +// } +} diff --git a/src/test/java/com/sunyard/sydapi/test/P1P7Test.java b/src/test/java/com/sunyard/sydapi/test/P1P7Test.java new file mode 100644 index 0000000..70a4f26 --- /dev/null +++ b/src/test/java/com/sunyard/sydapi/test/P1P7Test.java @@ -0,0 +1,114 @@ +package com.sunyard.sydapi.test; + +import com.sunyard.proto.Util; +import org.junit.runners.MethodSorters; +import racal.sunyard.main.SydApi4j; + +import com.github.houbb.junitperf.core.annotation.JunitPerfConfig; +import com.github.houbb.junitperf.core.rule.JunitPerfRule; +import org.junit.*; +import org.junit.Test; + +import java.io.UnsupportedEncodingException; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class P1P7Test { + // 全局配置 + private static final String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1"; + + // 测试参数 + private static final int threads = 1; + private static final long duration = 120000; + private static final long warmUp = 30000; + + // 原始数据 + private static final byte[] data1k = new byte[ 1024 * 4]; + + private static final byte[] data1m = new byte[ 1024 * 1024 ]; + + + // 临时数据 + private static String pk = null; + private static String dm_1k; + private static String dm_1m = null; + private static byte[] p1sign_1k; + private static byte[] p1sign_1m = null; + private static String p7dsign_1k; + private static String p7dsign_1m = null; + private static String p7asign_1k; + private static String p7asign_1m = null; + + @Rule + public JunitPerfRule junitPerfRule = new JunitPerfRule(); + SydApi4j api = (SydApi4j) new SydApi4j().connect("192.168.0.200",8889,null,3000); + + + + @BeforeClass + public static void init() throws UnsupportedEncodingException { + System.out.println("begin"); + + } + + + @AfterClass + public static void after() { + System.out.println("all over"); + } + + @Test + @JunitPerfConfig(threads = threads, warmUp = warmUp, duration = duration) + public void p1_sign_1k(){ + p1sign_1k= api.SYD_NakedSign(data1k, dn); + + } + + + @Test + @JunitPerfConfig(threads = threads, warmUp = warmUp, duration = duration) + public void p1_verify_1k(){ + api.SYD_NakedVerify( data1k, p1sign_1k, dn ); + } + + @Test + @JunitPerfConfig(threads = threads, warmUp = warmUp, duration = duration) + public void p7a_sign_1k() throws UnsupportedEncodingException { + p7asign_1k = api.attachedSign(data1k, dn); + } + + + @Test + @JunitPerfConfig(threads = threads, warmUp = warmUp, duration = duration) + public void p7a_verify_1k(){ + api.attachedVerifyAndGetAll( p7asign_1k ); + } + + + + @Test + @JunitPerfConfig(threads = threads, warmUp = warmUp, duration = duration) + public void p7d_sign_1k(){ + p7dsign_1k = api.sm3AndDetachedSign(data1k, pk, dn); + } + + + @Test + @JunitPerfConfig(threads = threads, warmUp = warmUp, duration = duration) + public void p7d_verify_1k(){ + api.sm3AndDetachedVerify(data1k, pk, p7dsign_1k ); + } + + + + @Test + @JunitPerfConfig(threads = threads, warmUp = warmUp, duration = duration) + public void dm_aen_1k() { + dm_1k = String.valueOf(api.generateDEByDn(dn, data1k)); + } + + @Test + @JunitPerfConfig(threads = threads, warmUp = warmUp, duration = duration) + public void dm_de_1k() { + api.decryptDEByDN(dn, Util.hexString2Bytes(dm_1k)); + } +} diff --git a/src/test/java/com/sunyard/sydapi/test/TestPKCS1.java b/src/test/java/com/sunyard/sydapi/test/TestPKCS1.java index 8381e77..5d00cd4 100644 --- a/src/test/java/com/sunyard/sydapi/test/TestPKCS1.java +++ b/src/test/java/com/sunyard/sydapi/test/TestPKCS1.java @@ -14,7 +14,7 @@ public class TestPKCS1 { public static void main(String[] args) { - + System.setProperty("com.sunyard.sydapi4j.debug","true"); // 连接加密机 SydApi4j api = (SydApi4j) new SydApi4j().connect("192.168.0.200", 8889, null, 1000); @@ -22,10 +22,10 @@ public class TestPKCS1 { try { // 原始数据模式 - // case1( api ); + case1( api ); // 外部 hash - case2( api ); +// case2( api ); } catch (Exception e) {