1、修改了8017指令xml文档,兼容通过sn获取证书信息。添加通过sn获取证书信息的接口
This commit is contained in:
parent
45db61b1cd
commit
38327139b7
@ -6,10 +6,23 @@
|
|||||||
<bin>8017</bin>
|
<bin>8017</bin>
|
||||||
</command>
|
</command>
|
||||||
<data extend="data">
|
<data extend="data">
|
||||||
<userId cn="用户编号">
|
<pFlag len="1" required="false" cn="P标志">
|
||||||
用户编号
|
p标志
|
||||||
|
</pFlag>
|
||||||
|
<flag len="1" :if="'P' == $packet.data.pFlag" cn="flag标志">
|
||||||
|
仅当P存在时
|
||||||
|
0: SN
|
||||||
|
1: 机构号
|
||||||
|
</flag>
|
||||||
|
<dLength len="2" :value="dLen()" :if="'P' == $packet.data.pFlag" cn="长度">
|
||||||
|
仅当P存在时,根据flag标志确定是什么的长度
|
||||||
|
</dLength>
|
||||||
|
<userId cn="机构号或SN">
|
||||||
|
机构号不满16字节,后面补充0x00至16字节。
|
||||||
|
如果是SN或其他,则其长度根据SN长度确定
|
||||||
</userId>
|
</userId>
|
||||||
<type len="1" format="X" cn="证书类型">
|
<type len="1" format="X" cn="证书类型">
|
||||||
|
0x00签名证书,0x01加密证书
|
||||||
</type>
|
</type>
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
@ -93,7 +106,19 @@
|
|||||||
|
|
||||||
|
|
||||||
</res>
|
</res>
|
||||||
<script>function certLen() {
|
<script>
|
||||||
return Util.b2i( $final.getSection('data').getSection('certLen') )
|
function certLen() {
|
||||||
} </script>
|
return Util.b2i( $final.getSection('data').getSection('certLen') )
|
||||||
|
}
|
||||||
|
<![CDATA[
|
||||||
|
function dLen() {
|
||||||
|
def len = $packet.data.userId.length;
|
||||||
|
def data = new byte[2];
|
||||||
|
data[0] = (byte)(len >> 8 & 0xFF)
|
||||||
|
data[1] = (byte)(len & 0xFF)
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</script>
|
||||||
</packet>
|
</packet>
|
||||||
|
|||||||
Binary file not shown.
@ -69,6 +69,13 @@ public interface SydCertApi {
|
|||||||
String pCert
|
String pCert
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过SN获取 X509 证书信息
|
||||||
|
* @param sn sn,证书序号
|
||||||
|
* @param nCertType 证书类型,0:签名证书, 1:加密证书
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String GetX509CertFileBySN(String sn, int nCertType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过使用者 ID 获取的 X509 证书文件。
|
* 通过使用者 ID 获取的 X509 证书文件。
|
||||||
@ -81,7 +88,6 @@ public interface SydCertApi {
|
|||||||
int nCertType
|
int nCertType
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从签名中获取证书
|
* 从签名中获取证书
|
||||||
* @param orgData 待签名的原始数据
|
* @param orgData 待签名的原始数据
|
||||||
|
|||||||
@ -3196,11 +3196,32 @@ public class SydApi4j implements SydApi {
|
|||||||
return cinfo;
|
return cinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过SN获取证书信息
|
||||||
|
* @param sn sn
|
||||||
|
* @param nCertType 证书类型,0:签名证书, 1:加密证书
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String GetX509CertFileBySN(String sn, int nCertType) {
|
||||||
|
return GetX509CertFileC(0, sn, nCertType);
|
||||||
|
}
|
||||||
|
|
||||||
// 测试通过
|
// 测试通过
|
||||||
@Override
|
@Override
|
||||||
public String GetX509CertFileC(String userId, int nCertType) {
|
public String GetX509CertFileC(String userId, int nCertType) {
|
||||||
|
return GetX509CertFileC(1, userId, nCertType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过sn或机构号获取证书
|
||||||
|
* @param flag 0: SN,1: 机构号
|
||||||
|
* @param userId 根据flag确定传入的数据
|
||||||
|
* @param nCertType 证书类型,0:签名证书, 1:加密证书
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String GetX509CertFileC(int flag, String userId, int nCertType) {
|
||||||
|
|
||||||
//ProtocolRender render = pset.getProtocolReqRender(new byte[]{(byte) 0x80, 0x17});
|
|
||||||
Proto8017 proto = new Proto8017();
|
Proto8017 proto = new Proto8017();
|
||||||
HashMap<String, Object> packet = new HashMap<String, Object>();
|
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||||
HashMap<String, Object> data = new HashMap<String, Object>();
|
HashMap<String, Object> data = new HashMap<String, Object>();
|
||||||
@ -3208,12 +3229,20 @@ 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());
|
||||||
|
|
||||||
|
byte[] u;
|
||||||
|
|
||||||
if (userId.length() > 16) {
|
if (flag == 1) {
|
||||||
throw new SydApiException(-26);
|
if (userId.length() > 16) {
|
||||||
|
throw new SydApiException(-26);
|
||||||
|
}
|
||||||
|
u = new byte[16];
|
||||||
|
System.arraycopy(userId.getBytes(), 0, u, 0, userId.length());
|
||||||
|
} else {
|
||||||
|
u = userId.getBytes();
|
||||||
|
data.put("pFlag", "P");
|
||||||
|
data.put("flag", flag);
|
||||||
}
|
}
|
||||||
byte[] u = new byte[16];
|
|
||||||
System.arraycopy(userId.getBytes(), 0, u, 0, userId.length());
|
|
||||||
byte type = 0 == nCertType ? (byte) 0 : (byte) 1;
|
byte type = 0 == nCertType ? (byte) 0 : (byte) 1;
|
||||||
|
|
||||||
data.put("userId", u);
|
data.put("userId", u);
|
||||||
@ -3245,7 +3274,6 @@ public class SydApi4j implements SydApi {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sm2私钥签名
|
* sm2私钥签名
|
||||||
* 用户id默认为1234567812345678
|
* 用户id默认为1234567812345678
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import org.junit.After;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import racal.sunyard.main.SydApi4j;
|
import racal.sunyard.main.SydApi4j;
|
||||||
import racal.sunyard.main.SydApiBuilder;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
@ -32,10 +31,19 @@ public class TestAllMethods {
|
|||||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||||
api = (SydApi4j) new SydApi4j().connect("192.168.0.66", 8889, null, 1000);
|
api = (SydApi4j) new SydApi4j().connect("192.168.0.66", 8889, null, 1000);
|
||||||
// api = (SydApi4j) new SydApi4j().connect("192.168.0.100", 8889, null, 1000);
|
// api = (SydApi4j) new SydApi4j().connect("192.168.0.100", 8889, null, 1000);
|
||||||
|
// api = (SydApi4j) new SydApi4j().connect("192.168.0.99", 8889, null, 1000);
|
||||||
// api = (SydApi4j) new SydApi4j().connect("172.16.17.162", 8889, null, 1000);
|
// api = (SydApi4j) new SydApi4j().connect("172.16.17.162", 8889, null, 1000);
|
||||||
// api = (SydApi4j) new SydApi4j().connect("192.168.1.7", 8889, null, 5000);
|
// api = (SydApi4j) new SydApi4j().connect("192.168.1.7", 8889, null, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 测试通过
|
||||||
|
// Y8
|
||||||
|
@Test
|
||||||
|
public void testLink() {
|
||||||
|
String s = api.GenerateRandom(16);
|
||||||
|
System.out.println(s);
|
||||||
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void after() {
|
public void after() {
|
||||||
try {
|
try {
|
||||||
@ -1407,20 +1415,23 @@ public class TestAllMethods {
|
|||||||
"ODAMBggqgRzPVQGDdQUAA0gAMEUCIG0PqR+bbdNOb5Q4kfHq8cQZJ1wa/P+bqFfv\n" +
|
"ODAMBggqgRzPVQGDdQUAA0gAMEUCIG0PqR+bbdNOb5Q4kfHq8cQZJ1wa/P+bqFfv\n" +
|
||||||
"6bbL9RZCAiEAiH1LKCjq9p7MS7qOK+su5I0kenCQ505ZuuAWDMph0xk=\n" +
|
"6bbL9RZCAiEAiH1LKCjq9p7MS7qOK+su5I0kenCQ505ZuuAWDMph0xk=\n" +
|
||||||
"-----END CERTIFICATE-----";
|
"-----END CERTIFICATE-----";
|
||||||
System.out.println(api.importCert(getSafeBytes(cert), null));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
String cert2 = "-----BEGIN CERTIFICATE-----\n" +
|
||||||
|
"MIIB4TCCAYSgAwIBAgIIPJMAAAAAACswDAYIKoEcz1UBg3UFADAmMQswCQYDVQQG\n" +
|
||||||
|
"EwJDTjEXMBUGA1UEAwwOU3VueWFyZFNNMlJvb3QwHhcNMTcxMTE3MDIzMDUxWhcN\n" +
|
||||||
|
"MjMwMTI1MDIzMDUxWjBZMQswCQYDVQQGEwJDTjELMAkGA1UECAwCWkoxCzAJBgNV\n" +
|
||||||
|
"BAcMAkhaMQ4wDAYDVQQKDAVISkpZUzERMA8GA1UECwwIMDAwMDAwMDAxDTALBgNV\n" +
|
||||||
|
"BAMMBDIyMjIwWTATBgcqhkjOPQIBBggqgRzPVQGCLQNCAATxqegqlmc/lduzBaKR\n" +
|
||||||
|
"EyeNuPf78RA3wfJuhAv8zymLwQ6doefs1Iul+kMOukhfwY9aEhVdqws34FZMm2vs\n" +
|
||||||
|
"1+wXo2cwZTAOBgNVHQ8BAf8EBAMCAMAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwHwYD\n" +
|
||||||
|
"VR0jBBgwFoAU93/arv8hxtk6eq2g+6z+AqVO1cEwHQYDVR0OBBYEFHfjFl72707A\n" +
|
||||||
|
"6s+YVuGvEuyvFWTMMAwGCCqBHM9VAYN1BQADSQAwRgIhALzg7+QW7RU4phv+4arE\n" +
|
||||||
|
"v0IOeaA6dtR8VT4Bwin9oHTWAiEA9kLESGiYm8L5Htf7GBXgH+pk7BJ68clml41B\n" +
|
||||||
|
"/ejZglI=\n" +
|
||||||
|
"-----END CERTIFICATE-----";
|
||||||
|
|
||||||
public static byte[] getSafeBytes(String s) {
|
String jgh = "00000000";
|
||||||
if (null != s) {
|
System.out.println(api.importCert(Util.getSafeBytes(cert2), jgh.getBytes()));
|
||||||
byte[] b1 = s.getBytes();
|
|
||||||
byte[] b2 = new byte[b1.length + 1];
|
|
||||||
b2[b1.length] = 0;
|
|
||||||
System.arraycopy(b1, 0, b2, 0, b1.length);
|
|
||||||
return b2;
|
|
||||||
} else {
|
|
||||||
return new byte[]{0};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1645,11 +1656,27 @@ public class TestAllMethods {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetX509CertFileC() {
|
public void testGetX509CertFileC() {
|
||||||
String userId = "8012";
|
String userId = "8012";
|
||||||
|
String userId2 = "8001";
|
||||||
|
|
||||||
String s = api.GetX509CertFileC(userId, 0);
|
String s = api.GetX509CertFileC(userId2, 0);
|
||||||
System.out.println(s);
|
System.out.println(s);
|
||||||
|
|
||||||
|
X509 x509 = api.GetX509CertInfo(s);
|
||||||
|
System.out.println("颁发者DN为: " + x509.getIssuer());
|
||||||
|
System.out.println("证书主题: " + x509.getSubject());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 8017
|
||||||
|
@Test
|
||||||
|
public void testGetX509CertFileBySN() {
|
||||||
|
String sn = "1004282452";
|
||||||
|
String sn2 = "3C93000000000025";
|
||||||
|
|
||||||
|
String s = api.GetX509CertFileBySN(sn2, 0);
|
||||||
|
System.out.println(s);
|
||||||
|
X509 x509 = api.GetX509CertInfo(s);
|
||||||
|
System.out.println("证书序列号: " + x509.getSerialNumber());
|
||||||
|
System.out.println("证书主题DN: " + x509.getSubject());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 测试通过
|
// 测试通过
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import racal.sunyard.main.SydApi4j;
|
import racal.sunyard.main.SydApi4j;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,7 +26,7 @@ public class TestGSYH {
|
|||||||
public void before() {
|
public void before() {
|
||||||
// 通过设置debug的属性开启debug,如果不设置则默认不打开
|
// 通过设置debug的属性开启debug,如果不设置则默认不打开
|
||||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||||
api = (SydApi4j) new SydApi4j().connect("192.168.0.100", 8889, null, 1000);
|
api = (SydApi4j) new SydApi4j().connect("192.168.0.66", 8889, null, 1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,16 +93,16 @@ public class TestGSYH {
|
|||||||
// 测试通过
|
// 测试通过
|
||||||
// 8017
|
// 8017
|
||||||
@Test
|
@Test
|
||||||
public void testGetX509CertFileC() {
|
public void testGetX509CertFileBySN() {
|
||||||
String userId = "8001";
|
String sn2 = "3C93000000000025";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过使用者 ID 获取的 X509 证书文件。
|
* 通过证书序号 sn 获取的 X509 证书文件。
|
||||||
* @param userId 使用者的 ID,最大长度为 16 位数字(要与生成实体的机构号保持一致)。
|
* @param sn sn,证书序号
|
||||||
* @param nCertType 证书类型,0:签名证书, 1:加密证书
|
* @param nCertType 证书类型,0:签名证书, 1:加密证书
|
||||||
* @return base64 编码的证书
|
* @return base64 编码的证书
|
||||||
*/
|
*/
|
||||||
String s = api.GetX509CertFileC(userId, 1);
|
String s = api.GetX509CertFileBySN(sn2, 0);
|
||||||
System.out.println(s);
|
System.out.println(s);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,8 +112,36 @@ public class TestGSYH {
|
|||||||
* 证书信息类,包含:颁发者DN、 证书序列号、 证书主题、证书有效期的起始时间、证书有效期的终止时间、DER编码的公钥。
|
* 证书信息类,包含:颁发者DN、 证书序列号、 证书主题、证书有效期的起始时间、证书有效期的终止时间、DER编码的公钥。
|
||||||
*/
|
*/
|
||||||
X509 x509 = api.GetX509CertInfo(s);
|
X509 x509 = api.GetX509CertInfo(s);
|
||||||
byte[] pubKey = x509.getPubKey();
|
System.out.println("证书主题DN: " + x509.getSubject());
|
||||||
System.out.println("publicKey: " + Util.bytes2HexString(pubKey));
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImportCert2() throws IOException {
|
||||||
|
|
||||||
|
String cert2 = "-----BEGIN CERTIFICATE-----\n" +
|
||||||
|
"MIIB4TCCAYSgAwIBAgIIPJMAAAAAACswDAYIKoEcz1UBg3UFADAmMQswCQYDVQQG\n" +
|
||||||
|
"EwJDTjEXMBUGA1UEAwwOU3VueWFyZFNNMlJvb3QwHhcNMTcxMTE3MDIzMDUxWhcN\n" +
|
||||||
|
"MjMwMTI1MDIzMDUxWjBZMQswCQYDVQQGEwJDTjELMAkGA1UECAwCWkoxCzAJBgNV\n" +
|
||||||
|
"BAcMAkhaMQ4wDAYDVQQKDAVISkpZUzERMA8GA1UECwwIMDAwMDAwMDAxDTALBgNV\n" +
|
||||||
|
"BAMMBDIyMjIwWTATBgcqhkjOPQIBBggqgRzPVQGCLQNCAATxqegqlmc/lduzBaKR\n" +
|
||||||
|
"EyeNuPf78RA3wfJuhAv8zymLwQ6doefs1Iul+kMOukhfwY9aEhVdqws34FZMm2vs\n" +
|
||||||
|
"1+wXo2cwZTAOBgNVHQ8BAf8EBAMCAMAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwHwYD\n" +
|
||||||
|
"VR0jBBgwFoAU93/arv8hxtk6eq2g+6z+AqVO1cEwHQYDVR0OBBYEFHfjFl72707A\n" +
|
||||||
|
"6s+YVuGvEuyvFWTMMAwGCCqBHM9VAYN1BQADSQAwRgIhALzg7+QW7RU4phv+4arE\n" +
|
||||||
|
"v0IOeaA6dtR8VT4Bwin9oHTWAiEA9kLESGiYm8L5Htf7GBXgH+pk7BJ68clml41B\n" +
|
||||||
|
"/ejZglI=\n" +
|
||||||
|
"-----END CERTIFICATE-----";
|
||||||
|
|
||||||
|
String organizationId = "00000000";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传指定证书到加密设备
|
||||||
|
* @param certData 证书的字节数组
|
||||||
|
* @param organizationId 机构号的字节数组
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
RetWrap retWrap = api.importCert(Util.getSafeBytes(cert2), organizationId.getBytes());
|
||||||
|
System.out.println(retWrap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user