错误码优化

This commit is contained in:
jiangr.wu@sunyard.com 2025-08-11 10:20:26 +08:00
parent d9bde5df32
commit d40594bce1
7 changed files with 3235 additions and 258 deletions

View File

@ -1,5 +1,6 @@
package com.sunyard.sge.database;
import com.sunyard.SydApiException;
import com.sunyard.log.ILogFactory;
import com.sunyard.log.ILogger;
import com.sunyard.sge.database.pool.HsmLinkInfo;
@ -33,7 +34,7 @@ public class SydApi4Database extends SydApiBaseFunction {
}
if ( iKeyIndex.length != pcData.size() ) {
throw new IllegalArgumentException("批量输入数据密钥和数据数量不等");
throw new SydApiException("批量输入数据密钥和数据数量不等", 0x01000001);
}
if ( 0 == iKeyIndex.length ) {

View File

@ -161,10 +161,10 @@ public class SydApiBaseFunction implements SydApi {
}
if (null == pcData) {
throw new SydApiException("输入内容为 null", 19);
throw new SydApiException("输入内容为 null", 0x01000001);
}
if (pcData.length > 1024) {
throw new SydApiException("输入内容为空", 19);
throw new SydApiException("输入数据长度超过限制", 0x01000001);
}
SydApiException le = new SydApiException(-1);
@ -222,8 +222,16 @@ public class SydApiBaseFunction implements SydApi {
if (null == this.hsms || this.hsms.length < 1) {
throw new SydApiException(-1);
}
if ( iPkgNum < 0 || iPkgNum > 3) {
throw new SydApiException("参数错误(入参不符合接口条件)", 0x01000001);
}
byte[] procData = null;
if (2 == iPkgNum || 3 == iPkgNum) {
if(null == pcProcData){
throw new SydApiException("参数错误(入参不符合接口条件)", 0x01000001);
}
procData = pcProcData;
log.debug("Util.hexString2Bytes方法返回值{}", Arrays.toString(procData));
@ -298,10 +306,12 @@ public class SydApiBaseFunction implements SydApi {
if (0 == pcData.length || pcData.length > 1024) {
throw new SydApiException("输入内容长度错误", 0x01000001);
}
} else {
} else if(Consts.ECB_DEC == iFlag){
if (0 == pcData.length || pcData.length % 16 != 0 || pcData.length > 1040) {
throw new SydApiException("输入密文数据长度错误", 0x01000014);
}
} else {
throw new SydApiException("加解密标识错误", 0x01000001);
}
updateLastUseTime();
String keyIndex = String.format("%08d", iKeyIndex);
@ -381,16 +391,20 @@ public class SydApiBaseFunction implements SydApi {
return new ArrayList<>();
}
if(iFlag !=Consts.ECB_DEC && iFlag != Consts.ECB_ENC){
throw new SydApiException("加解密标识错误", 0x01000001);
}
if (iFlag == Consts.ECB_DEC) {
for (byte[] pcdata : pcData) {
if (pcdata.length == 0 || pcdata.length % 16 != 0 || pcdata.length > 1040) {
throw new SydApiException(0x01000015);
throw new SydApiException("数据长度错误",0x01000001);
}
}
} else {
for (byte[] pcdata : pcData) {
if (pcdata.length > 1024) {
throw new SydApiException(19);
throw new SydApiException("数据长度错误",0x01000001);
}
}
}
@ -466,9 +480,18 @@ public class SydApiBaseFunction implements SydApi {
throw new SydApiException(0x01000001);
}
if(iFlag != Consts.ECB_ENC && iFlag != Consts.ECB_DEC){
throw new SydApiException("加解密标识错误", 0x01000001);
}
if (iFlag == Consts.ECB_DEC && (null == pcData || pcData.length == 0 || pcData.length % 16 != 0)) {
throw new SydApiException(0x01000015);
}
if(null == pcData || pcData.length > 4064){
throw new SydApiException("数据长度错误", 0x01000001);
}
if (null == this.hsms || this.hsms.length < 1) {
throw new SydApiException(-1);
}
@ -706,12 +729,23 @@ public class SydApiBaseFunction implements SydApi {
throw new SydApiException(-1);
}
if(iPkgNum<0 || iPkgNum>3){
throw new SydApiException("包序号错误", 0x01000001);
}
if(pcData != null && pcData.length > 4064){
throw new SydApiException("数据长度超过限制", 0x01000001);
}
String keyIndex = String.format("%08d", iKeyIndex);
byte[] iv = null;
// 仅一包 第一包 忽略 pcProcData 参数
if (Consts.PkgNumAll != iPkgNum && Consts.PkgNumHead != iPkgNum) {
if(null == pcProcData){
throw new SydApiException("中间包为空", 0x01000001);
}
iv = Util.bytes2HexString(pcProcData).getBytes();
}
SydApiException le = new SydApiException(-1);
@ -876,22 +910,22 @@ public class SydApiBaseFunction implements SydApi {
public boolean SYD_SM4Mac_ShortData(int iKeyIndex, byte[] pcData, int limitDataLen, byte[] pcMac) {
if (null == pcMac) {
throw new SydApiException("mac为空", 0x01000001);
}
if (log.isDebugEnabled()) {
log.debug("SYD_SM4Mac_ShortData 方法接收参数:{}", iKeyIndex, Util.bytes2HexString(pcData), Util.bytes2HexString(pcMac));
}
if (null == pcData || pcData.length > limitDataLen) {
throw new SydApiException("输入内容超长", 19);
throw new SydApiException("输入内容超长", 0x01000001);
}
if (null == this.hsms || this.hsms.length < 1) {
throw new SydApiException(-1);
}
if (null == pcMac) {
throw new IllegalArgumentException();
}
updateLastUseTime();
byte[] mac = this.SYD_SM4Mac_ShortData(iKeyIndex, pcData, limitDataLen);
log.debug(this + ".SYD_SM4Mac_ShortData方法返回值{}", mac);

View File

@ -396,6 +396,9 @@ public class SydApiLongLinkWrap implements SydApi {
try {
return task.get();
} catch (Exception e) {
if (e.getCause() instanceof SydApiException) {
throw (SydApiException) e.getCause();
}
throw new SydApiException("并行任务执行失败", 0xC101, e);
}
}
@ -517,6 +520,9 @@ public class SydApiLongLinkWrap implements SydApi {
try {
return task.get();
} catch (Exception e) {
if (e.getCause() instanceof SydApiException) {
throw (SydApiException) e.getCause();
}
throw new SydApiException("并行任务执行失败", 0xC101, e);
}
}
@ -545,7 +551,7 @@ public class SydApiLongLinkWrap implements SydApi {
}
if (iKeyIndex.length != pcData.size()) {
throw new IllegalArgumentException("批量输入数据密钥和数据数量不等");
throw new SydApiException("批量输入数据密钥和数据数量不等", 0x01000001);
}
if (0 == iKeyIndex.length) {
@ -624,7 +630,7 @@ public class SydApiLongLinkWrap implements SydApi {
}
if (iKeyIndex.length != pcData.size()) {
throw new IllegalArgumentException("批量输入数据密钥和数据数量不等");
throw new SydApiException("批量输入数据密钥和数据数量不等", 0x01000001);
}
if (0 == iKeyIndex.length) {
@ -699,7 +705,7 @@ public class SydApiLongLinkWrap implements SydApi {
}
if (iKeyIndex.length != pcData.size()) {
throw new IllegalArgumentException("批量输入数据密钥和数据数量不等");
throw new SydApiException("批量输入数据密钥和数据数量不等", 0x01000001);
}
if (0 == iKeyIndex.length) {

View File

@ -20,7 +20,7 @@ public class SydSM3 implements ISM3 {
pcData = new byte[0];
}
if (pcData.length > 4064) {
throw new IllegalArgumentException();
throw new SydApiException(0x01000001);
}
if (null == this.pcProcData) {
LongDataReturn<byte[], byte[]> stringStringLongDataReturn = api.SYD_SM3_Hash_LongData(pcData, 1, null);

View File

@ -33,7 +33,7 @@ public class SydSM4 implements ISM4 {
throw new SydApiException(0x8007);
}
if (plength > 4064) {
throw new SydApiException(0x8006);
throw new SydApiException(0x01000001);
}
if (iFlag == 1) {
if (0 == queue.getLength()) {

View File

@ -32,16 +32,21 @@ public class SydSM4Mac implements ISM4Mac {
throw new SydApiException(0x8007);
}
if (length > 4064) {
throw new SydApiException(0x8006);
throw new SydApiException(0x01000001);
}
if (0 == queue.getLength()) {
if (length < 16) {
queue.push(pcData);
}
if (length % 16 != 0) {
queue.push(pcData);
pcdataResult = queue.pop(16, 0);
// if (length < 16) {
// queue.push(pcData);
// }
// if (length % 16 != 0) {
// }
queue.push(pcData);
pcdataResult = queue.pop(16, 0);
if ( null == pcdataResult || pcdataResult.length == 0 ) {
return;
}
if (null == this.pcMac || this.pcMac.length == 0) {
LongDataReturn<byte[], byte[]> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pcdataResult, iPkgNum, pcProcData);
pcProcData = stringStringLongDataReturn.getProcData();
@ -74,6 +79,7 @@ public class SydSM4Mac implements ISM4Mac {
@Override
public boolean checkDigest(byte[] mac) {
this.pcMac = this.digest();
return mac != null && Arrays.equals(this.pcMac, mac);
}
@ -92,7 +98,8 @@ public class SydSM4Mac implements ISM4Mac {
byte[] pop = queue.pop();
LongDataReturn<byte[], byte[]> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pop, iPkgNum, pcProcData);
return stringStringLongDataReturn.getData();
this.pcMac = stringStringLongDataReturn.getData();
return this.pcMac;
}

File diff suppressed because it is too large Load Diff