Merge remote-tracking branch 'origin/dev-shangqing' into dev-shangqing

# Conflicts:
#	DProto/8003.xml
This commit is contained in:
yihzhou 2022-12-15 17:38:09 +08:00
commit 758a4ea116
11 changed files with 144 additions and 130 deletions

1
.gitignore vendored
View File

@ -13,3 +13,4 @@ src/test/java/com/sunyard/sydapi/sample/*.*
*.p7 *.p7
~$* ~$*
/pack/ /pack/
/.logs/

View File

@ -1,124 +1,127 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<packet extend="base"> <packet extend="base">
<req> <req>
<command> <command>
<bin>8003</bin> <bin>8003</bin>
</command> </command>
<data extend="data"> <data extend="data">
<signatureDataType len="1" cn="获取公私钥标记位"> <rFlag len="1" required="false" cn="RSA标志">
<options> 可选存在则固定值为P
<option cn="索引方式"> </rFlag>
<bin>00</bin> <signatureDataType len="1" cn="获取公私钥标记位">
</option> <options>
<option cn="DN 方式"> <option cn="索引方式">
<bin>01</bin> <bin>00</bin>
</option> </option>
</options> <option cn="DN 方式">
</signatureDataType> <bin>01</bin>
</option>
</options>
</signatureDataType>
<DN cn="DN 或 DN索引"> <DN cn="DN 或 DN索引">
若上面的标志为1则此域为证书DN若为0则此域为两个字节的证书索引 若上面的标志为1则此域为证书DN若为0则此域为两个字节的证书索引
</DN> </DN>
<hashFlag len="1" :if="null != $packet.data.hash" cn="外部 hash 标记"> <hashFlag len="1" :if="null != $packet.data.hash" cn="外部 hash 标记">
<text>P</text> <text>P</text>
</hashFlag> </hashFlag>
<hash len="32" :if="null != $packet.data.hash" cn="外部 hash"> <hash len="32" :if="null != $packet.data.hash" cn="外部 hash">
</hash> </hash>
<dataLength len="2" :value="dataLen()" :if="null == $packet.data.hash" cn="待签名数据长度"> <dataLength len="2" :value="dataLen()" cn="待签名数据长度">
待签名数据长度 待签名数据长度
</dataLength> </dataLength>
<signData cn="待签名数据" :if="null == $packet.data.hash"> <signData cn="待签名数据">
待签名数据 待签名数据
</signData> </signData>
</data> </data>
</req> </req>
<res> <res>
<command> <command>
<bin>8004</bin> <bin>8004</bin>
</command> </command>
<data> <data>
<error len="2" cn="错误码" format="X" :catch="catchError('%s')"> <error len="2" cn="错误码" format="X" :catch="catchError('%s')">
<options> <options>
<option cn="无错误"> <option cn="无错误">
<hex>00</hex> <hex>00</hex>
</option> </option>
<option cn="无效的私钥类型"> <option cn="无效的私钥类型">
<hex>03</hex> <hex>03</hex>
</option> </option>
<option cn="无效私钥标记"> <option cn="无效私钥标记">
<hex>04</hex> <hex>04</hex>
</option> </option>
<option cn="无效的哈希标识"> <option cn="无效的哈希标识">
<hex>05</hex> <hex>05</hex>
</option> </option>
<option cn="无效的签名标识"> <option cn="无效的签名标识">
<hex>06</hex> <hex>06</hex>
</option> </option>
<option cn="无效的附加标识"> <option cn="无效的附加标识">
<hex>07</hex> <hex>07</hex>
</option> </option>
<option cn="LMK 错误"> <option cn="LMK 错误">
LMK 错误;报告给管理员。 LMK 错误;报告给管理员。
<hex>13</hex> <hex>13</hex>
</option> </option>
<option cn="输入数据错"> <option cn="输入数据错">
<hex>15</hex> <hex>15</hex>
</option> </option>
<option cn="DSP 错误"> <option cn="DSP 错误">
DSP 错误;报告给管理员。 DSP 错误;报告给管理员。
<hex>47</hex> <hex>47</hex>
</option> </option>
<option cn="私钥错误"> <option cn="私钥错误">
私钥错误;报告给管理员。 私钥错误;报告给管理员。
<hex>49</hex> <hex>49</hex>
</option> </option>
<option cn="无效摘要信息语法(仅仅无哈希模式)"> <option cn="无效摘要信息语法(仅仅无哈希模式)">
<hex>74</hex> <hex>74</hex>
</option> </option>
<option cn="公钥长度错误"> <option cn="公钥长度错误">
<hex>76</hex> <hex>76</hex>
</option> </option>
<option cn="私钥长度错误"> <option cn="私钥长度错误">
<hex>78</hex> <hex>78</hex>
</option> </option>
<option cn="输入数据长度错误"> <option cn="输入数据长度错误">
<hex>80</hex> <hex>80</hex>
</option> </option>
</options> </options>
</error> </error>
<signatureLen len="2" cn="签名的字节长度"> <signatureLen len="2" cn="签名的字节长度">
签名的字节长度 签名的字节长度
</signatureLen> </signatureLen>
<signature :len="signatureLen()" cn="签名的 DER 编码"> <signature :len="signatureLen()" cn="签名的 DER 编码">
签名的 DER 编码 签名的 DER 编码
</signature> </signature>
<tailSep len="1" required="false" cn="尾分隔"> <tailSep len="1" required="false" cn="尾分隔">
可选项。如果显示消息尾域,则该域必须显示。值为 “X19”。 可选项。如果显示消息尾域,则该域必须显示。值为 “X19”。
<hex>19</hex> <hex>19</hex>
</tailSep> </tailSep>
<tail maxLen="32" required="false" cn="尾部"> <tail maxLen="32" required="false" cn="尾部">
可选项。最大长度为 32个字符。 可选项。最大长度为 32个字符。
</tail> </tail>
</data> </data>
</res> </res>
<script type="javascript"><![CDATA[ <script type="javascript"><![CDATA[
function dataLen(){ function dataLen(){
def len = $packet.data.signData.length def len = $packet.data.signData.length
def ret = new byte[2] def ret = new byte[2]

BIN
doc/JAVA接口文档.pdf Normal file

Binary file not shown.

View File

@ -79,7 +79,7 @@
"func": "zip", "func": "zip",
"from": "%out_path%/*", "from": "%out_path%/*",
"to": "%out_path%/sydapi-%version%.%project.git_commit_hash%.zip", "to": "%out_path%/sydapi-%version%.%project.git_commit_hash%.zip",
"vc" : "12M" "vc" : "10M"
}, },
{ {
"func": "open", "func": "open",

View File

@ -1,6 +0,0 @@
06CE000000000000000080110000
06C0 = 1728 3456
2D2D2D2D2D424547494E2043455254494649434154452D2D2D2D2D0A4D4949453044434341376967417749424167494649414E4843544D774451594A4B6F5A496876634E41514546425141775754454C4D416B474131554542684D430A513034784D44417542674E5642416F544A304E6F6157356849455A70626D467559326C68624342445A584A3061575A70593246306157397549454631644768760A636D6C30655445594D4259474131554541784D5051305A445153425552564E5549453944515445784D423458445445314D444D784D7A41324D7A4D784D566F580A445449774D444D784D7A41324D7A4D784D566F77647A454C4D416B474131554542684D43593234784654415442674E5642416F5444454E4751304567564556540A564342445154454E4D4173474131554543784D45546B4E544D6A45554D4249474131554543784D4C525735305A584A77636D6C7A5A584D784C44417142674E560A42414D55497A41304D5542614E4441794E4455784D4441774D44457751464E6F595735456232356E514441774D4441774D4441784D494942496A414E42676B710A686B6947397730424151454641414F43415138414D49494243674B4341514541356A556E487733425870517064416D64766B4B4B766A6A34334166615670664B0A6C77704345532B475233386B4D4D5279594563323538305A4F36394E52525970515561635951316A585A5177567276324B787476556E54746E77756F324571450A7A77414D5963566163646345426D462F716F6A727745314844712F334E6352442F44753231676339634450474B62374B384862712F717138364B7042716754380A326466305331344E645770796135746B51544B417A34496B3346443733456C72537137336766614A2B623764526C634E4649306D77725A4A36684F7945764E660A537975553165475273775A455965586357576C3832472F6D464C6B3064746D34734E5930344E4A38724F51586B6569386D65494C6D687538537330654961346C0A794A556C4865487732316F566A75326835754B667848665670547669337258636E4E796851374550755A6272635364697845427256774944415141426F3449420A667A434341587377487759445652306A42426777466F41552F417538524A6F4F4D614744715947484A7834465173612F567667775341594456523067424545770A507A4139426768676752794737796F42416A41784D43384743437347415155464277494246694E6F644852774F693876643364334C6D4E6D59324575593239740A4C6D4E754C33567A4C33567A4C5445314C6D6830625443427A41594456523066424948454D4948424D49474F6F49474C6F494749686F47466247526863446F760A4C7A49784D4334334E4334304D5334784F4441364D7A67354C324E7550574E79624449774E6A677362335539556C4E424C45395650554E535443785050554E470A5130456756455654564342445153784450554E4F50324E6C636E52705A6D6C6A5958526C556D563262324E6864476C76626B78706333512F596D467A5A5439760A596D706C5933526A6247467A637A316A556B784561584E30636D6C69645852706232355162326C75644441756F4379674B6F596F6148523063446F764C7A49780A4D4334334E4334304D69347A4C303944515445784C314A545153396A636D77794D4459344C6D4E796244414C42674E564851384542414D43412B6777485159440A5652304F424259454642784838423835612B337A71464F416C48677054574F2B666646734D424D47413155644A51514D4D416F47434373474151554642774D430A4D413047435371475349623344514542425155414134494241514358457A464655352F447936724C50707A495361536934772B352B747351304C496156314E540A376277372F2F7A4D304A694974575A5A53354F54767859705951325466534A544D354F506B3045696F366856456B454651354F697457704D656E54674D3244320A572B4F4534494A44737652635551717565394B674E4A4171722F4B732F2B325A484D6C4C496B374669494C504F4B30354B585176574D413938396E3552744A770A7357743378443276504C2B46484976784C65627455584850595676462B49774B514E2F644F41684F625437386D6B327162534C47345473694F314A6A627250750A4A5774633564624A704933643876506E327A5A486258577055494D3457634F595133457858657341633258566842654F7A754E3373567A774C684550577235430A306A5964443777346E64657854543845754147644F43324B4F5655633551312B614B516A2B5351356A666D474F4235470A2D2D2D2D2D454E442043455254494649434154452D2D2D2D2D0A
HEXÊý¾Ý: 00200000000000000000374530303FD9071FE57D552F8E4564F991C7FCEF25B4DD5C
HEXÊý¾Ý: 002C00000000000000003745303047381495D90480EEFAA38B04811AF6EA0BC41617F4F6023C1860DB6DE2870F23

View File

@ -91,6 +91,9 @@ public class SydApiException extends RuntimeException{
msg = "证书删除错误"; msg = "证书删除错误";
break; break;
case 0xC101 :
msg = "证书识别异常";
break;
default: default:
msg = "未定义的错误"; msg = "未定义的错误";
} }

View File

@ -2,6 +2,7 @@ package com.sunyard.util;
import cn.hutool.core.codec.Base64; import cn.hutool.core.codec.Base64;
import com.sunyard.RetWrap; import com.sunyard.RetWrap;
import com.sunyard.SydApiException;
import com.sunyard.constant.CertUsage; import com.sunyard.constant.CertUsage;
import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.jce.provider.BouncyCastleProvider;
import sun.misc.BASE64Encoder; import sun.misc.BASE64Encoder;
@ -78,7 +79,7 @@ public class CertUtil {
* @param cert 证书 base64 字符 * @param cert 证书 base64 字符
* @return true 国密 false 非国密 * @return true 国密 false 非国密
*/ */
public static boolean isSM2Cert(String cert) throws CertificateException, NoSuchProviderException { public static boolean isSM2Cert(String cert) {
String pemCert; String pemCert;
if(cert.contains("-----BEGIN CERTIFICATE-----")){ if(cert.contains("-----BEGIN CERTIFICATE-----")){
pemCert =cert; pemCert =cert;
@ -87,7 +88,12 @@ public class CertUtil {
String end_cert = "\n-----END CERTIFICATE-----"; String end_cert = "\n-----END CERTIFICATE-----";
pemCert = cert_begin + cert + end_cert; pemCert = cert_begin + cert + end_cert;
} }
X509Certificate certificate = convertToX509Cert(pemCert); X509Certificate certificate = null;
try {
certificate = convertToX509Cert(pemCert);
} catch (Exception e) {
throw new SydApiException( 0xC101, e );
}
String signAlg = certificate.getSigAlgName(); String signAlg = certificate.getSigAlgName();
return signAlg.toUpperCase().indexOf("SM2") >= 0; return signAlg.toUpperCase().indexOf("SM2") >= 0;
} }

View File

@ -484,12 +484,15 @@ public class SydApi4j implements SydApi {
PacketSN sn = PacketSN.gen(); PacketSN sn = PacketSN.gen();
packet.put("header", sn.getSn().array()); packet.put("header", sn.getSn().array());
if (rFlag == 1) { if (rFlag == 1) {
// MD5
data.put("rFlag", 'M'); data.put("rFlag", 'M');
} }
if (rFlag == 2) { if (rFlag == 2) {
// SHA-1
data.put("rFlag", 'S'); data.put("rFlag", 'S');
} }
if (rFlag == 3) { if (rFlag == 3) {
// SHA-256
data.put("rFlag", 'R'); data.put("rFlag", 'R');
} }
data.put("signatureDataType$option", 1); data.put("signatureDataType$option", 1);
@ -1366,6 +1369,7 @@ public class SydApi4j implements SydApi {
List<String> partcerts = (List<String>)partCert.get("certDNs"); List<String> partcerts = (List<String>)partCert.get("certDNs");
m_certs.addAll(partcerts); m_certs.addAll(partcerts);
} }
return m_certs; return m_certs;
} }

View File

@ -11,6 +11,7 @@ import racal.sunyard.main.SydApi4j;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import static com.sunyard.sydapi.util.PrintUtil.printRetWrap; import static com.sunyard.sydapi.util.PrintUtil.printRetWrap;
@ -21,27 +22,29 @@ public class CertTest {
public static void main(String[] args) { public static void main(String[] args) {
//System.setProperty("com.sunyard.sydapi4j.debug", "true"); //System.setProperty("com.sunyard.sydapi4j.debug", "true");
SydApi4j api = (SydApi4j) new SydApi4j().connect("192.168.0.200", 8889, null, 1000); SydApi4j api = (SydApi4j) new SydApi4j().connect("192.168.1.129", 8889, null, 1000);
try{ try{
String sql=" certtype in (0,2) "; //签名解密 List<String>dns = api.getAllCert();
String sql2=" certtype in (1,3) "; //验签加密 System.out.println(Arrays.toString( dns.toArray() ) );
// String sql=" certtype in (0,2) "; //签名解密
ArrayList<String> m_certs =new ArrayList<String>(); // String sql2=" certtype in (1,3) "; //验签加密
//查出证书总数一次次的拿出来 //
RetWrap allCert = api.getAllCert(0); // ArrayList<String> m_certs =new ArrayList<String>();
printRetWrap(allCert); // //查出证书总数一次次的拿出来
Integer allnum =(Integer) allCert.get("certAllNum");//总数 // RetWrap allCert = api.getAllCert(0);
List<String> certs = (List<String>)allCert.get("certDNs");//部分证书列表 // printRetWrap(allCert);
System.out.println(certs.toString()); // Integer allnum = (Integer) allCert.get("certAllNum");//总数
m_certs.addAll(certs); // List<String> certs = (List<String>)allCert.get("certDNs");//部分证书列表
int loop = allnum%16;//循环次数 // System.out.println(certs.toString());
for (int i = 1; i < loop; i++) { // m_certs.addAll(certs);
RetWrap partCert= api.getAllCert(16*i); // int loop = allnum%16;//循环次数
List<String> partcerts = (List<String>)partCert.get("certDNs"); // for (int i = 1; i < loop; i++) {
m_certs.addAll(partcerts); // RetWrap partCert= api.getAllCert(16*i);
} // List<String> partcerts = (List<String>)partCert.get("certDNs");
System.out.println("证书:"+m_certs); // m_certs.addAll(partcerts);
System.out.println("aa"+m_certs.get(20)); // }
// System.out.println("证书:"+m_certs);
// System.out.println("aa"+m_certs.get(20));
}catch (Exception e){ }catch (Exception e){