增加配置项开关控制dn反序
This commit is contained in:
parent
0f28395ce9
commit
3f6d316d8b
@ -7,37 +7,40 @@ public class DnUtil {
|
||||
|
||||
|
||||
public static LinkedHashMap<String, String> dnToMap(String dn) {
|
||||
LinkedHashMap<String, String>map = new LinkedHashMap<String, String>();
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
|
||||
String[] kvs = dn.split(",");
|
||||
for ( String kv : kvs ) {
|
||||
for (String kv : kvs) {
|
||||
String[] ps = kv.split("=");
|
||||
map.put( ps[0].trim() , ps[1].trim() );
|
||||
map.put(ps[0].trim(), ps[1].trim());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static String verifyDn( String dn ) {
|
||||
if ( dn.startsWith("C=") || dn.startsWith("c=")) {
|
||||
return dn;
|
||||
}
|
||||
// 反转顺序
|
||||
String[] kvs = dn.split(",");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for ( String kv : kvs ) {
|
||||
|
||||
if ( sb.length() > 0 ) {
|
||||
sb.insert(0, ",");
|
||||
public static String verifyDn(String dn) {
|
||||
if ( "true".equals(System.getProperty("com.sunyard.dnsort", "true"))) {
|
||||
if (dn.startsWith("C=") || dn.startsWith("c=")) {
|
||||
return dn;
|
||||
}
|
||||
sb.insert(0, kv );
|
||||
// 反转顺序
|
||||
String[] kvs = dn.split(",");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (String kv : kvs) {
|
||||
|
||||
if (sb.length() > 0) {
|
||||
sb.insert(0, ",");
|
||||
}
|
||||
sb.insert(0, kv);
|
||||
|
||||
// if ( sb.length() > 0 ) {
|
||||
// sb.append(",");
|
||||
// }
|
||||
// sb.append( key + "=" + map.get( key ) );
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
return sb.toString();
|
||||
}
|
||||
else return dn;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -46,6 +46,8 @@ import java.security.cert.X509Certificate;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
import static com.sunyard.util.DnUtil.verifyDn;
|
||||
|
||||
public class SydApi4j implements SydApi {
|
||||
|
||||
static {
|
||||
@ -775,7 +777,7 @@ public class SydApi4j implements SydApi {
|
||||
byte[] dn = new byte[256];
|
||||
byte[] s = null;
|
||||
try {
|
||||
sCertDN = DnUtil.verifyDn(sCertDN);
|
||||
sCertDN = verifyDn(sCertDN);
|
||||
s = sCertDN.getBytes("GBK");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
@ -1094,7 +1096,7 @@ public class SydApi4j implements SydApi {
|
||||
byte[] dn = new byte[256];
|
||||
byte[] s = null;
|
||||
try {
|
||||
sCertDN = DnUtil.verifyDn(sCertDN);
|
||||
sCertDN = verifyDn(sCertDN);
|
||||
s = sCertDN.getBytes("GBK");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
@ -2848,7 +2850,7 @@ public class SydApi4j implements SydApi {
|
||||
|
||||
public RetWrap generateDEByDnHsm(String certSerial, byte[] oData) {
|
||||
|
||||
certSerial = DnUtil.verifyDn(certSerial);
|
||||
certSerial = verifyDn(certSerial);
|
||||
|
||||
byte[] dnBytes = null;
|
||||
try {
|
||||
@ -2861,7 +2863,7 @@ public class SydApi4j implements SydApi {
|
||||
|
||||
public RetWrap generateDEByDnHsmRSA(int alg, String certSerial, byte[] oData) {
|
||||
|
||||
certSerial = DnUtil.verifyDn(certSerial);
|
||||
certSerial = verifyDn(certSerial);
|
||||
|
||||
byte[] dnBytes = null;
|
||||
try {
|
||||
@ -2988,7 +2990,7 @@ public class SydApi4j implements SydApi {
|
||||
|
||||
public RetWrap decryptDEByDNHsm(String certSerial, String pCipherKey) {
|
||||
|
||||
certSerial = DnUtil.verifyDn(certSerial);
|
||||
certSerial = verifyDn(certSerial);
|
||||
|
||||
byte[] dnBytes = null;
|
||||
try {
|
||||
@ -3001,7 +3003,7 @@ public class SydApi4j implements SydApi {
|
||||
|
||||
public RetWrap decryptDEByDNHsmRSA(String certSerial, String pCipherKey) {
|
||||
|
||||
certSerial = DnUtil.verifyDn(certSerial);
|
||||
certSerial = verifyDn(certSerial);
|
||||
|
||||
byte[] dnBytes = null;
|
||||
try {
|
||||
@ -3022,7 +3024,8 @@ public class SydApi4j implements SydApi {
|
||||
public String getCertByDn(String dn) throws UnsupportedEncodingException {
|
||||
byte[] dnBytes = null;
|
||||
try {
|
||||
dnBytes = dn.getBytes("gbk");
|
||||
String dnsort = verifyDn(dn);
|
||||
dnBytes = dnsort.getBytes("gbk");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
@ -3094,7 +3097,7 @@ public class SydApi4j implements SydApi {
|
||||
|
||||
public RetWrap generateDEByDnSoft(String certSerial, byte[] oData) {
|
||||
|
||||
certSerial = DnUtil.verifyDn(certSerial);
|
||||
certSerial = verifyDn(certSerial);
|
||||
|
||||
RetWrap ret = new RetWrap();
|
||||
byte[] dnBytes = null;
|
||||
@ -3158,7 +3161,7 @@ public class SydApi4j implements SydApi {
|
||||
|
||||
public RetWrap generateDEByDnSoftRSA(int alg, String certSerial, byte[] oData) {
|
||||
|
||||
certSerial = DnUtil.verifyDn(certSerial);
|
||||
certSerial = verifyDn(certSerial);
|
||||
|
||||
RetWrap ret = new RetWrap();
|
||||
byte[] dnBytes = null;
|
||||
@ -3351,7 +3354,7 @@ public class SydApi4j implements SydApi {
|
||||
|
||||
public RetWrap decryptDEByDNSoft(String certSerial, String pCipherKey) {
|
||||
|
||||
certSerial = DnUtil.verifyDn(certSerial);
|
||||
certSerial = verifyDn(certSerial);
|
||||
|
||||
byte[] dnBytes = null;
|
||||
try {
|
||||
@ -3390,7 +3393,7 @@ public class SydApi4j implements SydApi {
|
||||
|
||||
public RetWrap decryptDEByDNSoftRSA(String certSerial, String pCipherKey) {
|
||||
|
||||
certSerial = DnUtil.verifyDn(certSerial);
|
||||
certSerial = verifyDn(certSerial);
|
||||
|
||||
byte[] dnBytes = null;
|
||||
try {
|
||||
@ -11500,7 +11503,7 @@ public class SydApi4j implements SydApi {
|
||||
}
|
||||
|
||||
public String attachedSignSoft(byte[] orgData, String sCertDN) throws UnsupportedEncodingException {
|
||||
sCertDN = DnUtil.verifyDn(sCertDN);
|
||||
sCertDN = verifyDn(sCertDN);
|
||||
String pk = this.GetDNPublicKey(SydApi.FOR_SIGN, sCertDN.getBytes("GBK"));
|
||||
try {
|
||||
byte[] hash = this.SM3Hash(pk, orgData);
|
||||
@ -11618,7 +11621,7 @@ public class SydApi4j implements SydApi {
|
||||
|
||||
|
||||
public String attachedSignRSASoft(int rFlag,byte[] orgData, String sCertDN) throws UnsupportedEncodingException {
|
||||
sCertDN = DnUtil.verifyDn( sCertDN );
|
||||
sCertDN = verifyDn( sCertDN );
|
||||
try {
|
||||
RetWrap hashData = countHash(0, 0, orgData, null);
|
||||
byte[] hash = (byte[]) hashData.get("hash");
|
||||
@ -11631,7 +11634,7 @@ public class SydApi4j implements SydApi {
|
||||
}
|
||||
|
||||
public String attachedSignRSAHsm(int rFlag,byte[] orgData, String sCertDN) {
|
||||
sCertDN = DnUtil.verifyDn( sCertDN );
|
||||
sCertDN = verifyDn( sCertDN );
|
||||
|
||||
Proto8018 proto = new Proto8018();
|
||||
byte[] dn = new byte[256];
|
||||
@ -11693,7 +11696,7 @@ public class SydApi4j implements SydApi {
|
||||
|
||||
|
||||
public String attachedSignHsm(byte[] orgData, String sCertDN) {
|
||||
sCertDN = DnUtil.verifyDn( sCertDN );
|
||||
sCertDN = verifyDn( sCertDN );
|
||||
|
||||
Proto8018 proto = new Proto8018();
|
||||
byte[] dn = new byte[256];
|
||||
|
||||
@ -91,5 +91,12 @@ public class Shanghairenhang {
|
||||
byte[] bytes = api.SYD_NakedSign(orgData2k, pcDnEN);
|
||||
System.out.println(Util.bytes2HexString(bytes));
|
||||
}
|
||||
@Test
|
||||
public void aboutCert(){
|
||||
//System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
SydApiBuilder builder = new SydApiBuilder().setIp("192.168.0.200");
|
||||
SydApi4j api = (SydApi4j) builder.build();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user