From fdbcf5d43bb46d272087cf6eaa7113d0529f3d8b Mon Sep 17 00:00:00 2001 From: cheney Date: Thu, 10 Jul 2025 20:29:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A5=E5=8F=82=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sge/database/SydApiBaseFunction.java | 63 ++++++++++++++++--- 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/sunyard/sge/database/SydApiBaseFunction.java b/src/main/java/com/sunyard/sge/database/SydApiBaseFunction.java index 0c46a4b..6bb15ba 100644 --- a/src/main/java/com/sunyard/sge/database/SydApiBaseFunction.java +++ b/src/main/java/com/sunyard/sge/database/SydApiBaseFunction.java @@ -265,7 +265,7 @@ public class SydApiBaseFunction implements SydApi { } if (Consts.ECB_ENC == iFlag) { if ( 0 == pcData.length || pcData.length > 1024 ) { - throw new SydApiException("输入内容超长",0x01000001); + throw new SydApiException("输入内容长度错误",0x01000001); } } else { if ( 0 == pcData.length || pcData.length % 16 != 0 || pcData.length > 1040 ) { @@ -342,15 +342,23 @@ public class SydApiBaseFunction implements SydApi { log.debug("SYD_SM4_BatchData方法接收参数:iKeyIndex:{},pcData元素个数为:{},iFlag:{}", iKeyIndex, pcData.size(), iFlag); } + if ( null == pcData ) { + throw new SydApiException("输入参数错误", 0x01000001); + } + + if (pcData.isEmpty()) { + return new ArrayList<>(); + } + if (iFlag == Consts.ECB_DEC) { for (byte[] pcdata : pcData) { - if (null == pcData || pcdata.length == 0 || pcdata.length > 1040) { - throw new SydApiException(19); + if ( pcdata.length == 0 || pcdata.length % 16 != 0 || pcdata.length > 1040) { + throw new SydApiException(0x01000015); } } } else { for (byte[] pcdata : pcData) { - if (null == pcData || pcdata.length > 1024) { + if ( pcdata.length > 1024) { throw new SydApiException(19); } } @@ -363,6 +371,9 @@ public class SydApiBaseFunction implements SydApi { String[] keys = new String[iKeyIndex.length]; updateLastUseTime(); for (int i = 0; i < iKeyIndex.length; i++) { + if ( iKeyIndex[i] < 0 ) { + throw new SydApiException(0x01000001); + } keys[i] = "SK" + SYMUtil.genPrivateKeyMark("000000", "00A", String.format("%08d", iKeyIndex[i])); } @@ -419,8 +430,13 @@ public class SydApiBaseFunction implements SydApi { if (LogFactory.iLogLevel == 3) { log.debug("SYD_SM4_LongData方法接收参数:iKeyIndex:{},pcData:{},iPkgNum:{},iFlag:{}", iKeyIndex, Arrays.toString(pcData), iPkgNum, iFlag); } - if (iFlag == Consts.ECB_DEC && (null == pcData || pcData.length == 0)) { - throw new SydApiException(19); + + if ( iKeyIndex < 0 ) { + throw new SydApiException(0x01000001); + } + + if (iFlag == Consts.ECB_DEC && (null == pcData || pcData.length == 0 || pcData.length % 16 != 0)) { + throw new SydApiException(0x01000015); } if (null == this.hsms || this.hsms.length < 1) { throw new SydApiException(-1); @@ -504,6 +520,11 @@ public class SydApiBaseFunction implements SydApi { if (LogFactory.iLogLevel == 3) { log.debug("SYD_SM4Mac_BatchData:iKeyIndex:{},pcData元素个数为:{}", iKeyIndex, pcData.size()); } + + if (pcData.isEmpty()) { + return new String[0]; + } + if (null == this.hsms || this.hsms.length < 1) { throw new SydApiException(-1); } @@ -511,6 +532,9 @@ public class SydApiBaseFunction implements SydApi { String[] keys = new String[iKeyIndex.length]; updateLastUseTime(); for (int i = 0; i < iKeyIndex.length; i++) { + if ( iKeyIndex[i] < 0 ) { + throw new SydApiException(0x01000001); + } keys[i] = "SK" + SYMUtil.genPrivateKeyMark("000000", "00A", String.format("%08d", iKeyIndex[i])); } SydApiException le = new SydApiException(-1); @@ -574,6 +598,11 @@ public class SydApiBaseFunction implements SydApi { if (LogFactory.iLogLevel == 3) { log.debug("SYD_SM4Mac_BatchData方法接收参数:iKeyIndex:{},pcData元素个数为:{},pcMac:{}", iKeyIndex, pcData.size(), Arrays.toString(pcMac)); } + + if (pcData.isEmpty()) { + return new boolean[0]; + } + if (null == this.hsms || this.hsms.length < 1) { throw new SydApiException(-1); } @@ -913,6 +942,15 @@ public class SydApiBaseFunction implements SydApi { @Override public List SYD_SM4_EncryptAndMac_BatchData(int[] iEncKeyIndex, int[] iMacKeyIndex, List pcData) { + + if (LogFactory.iLogLevel == 3) { + log.debug("SYD_SM4_EncryptAndMac_BatchData"); + } + + if (pcData.isEmpty()) { + return new ArrayList<>(); + } + if (null == this.hsms || null == iMacKeyIndex || null == pcData) { throw new SydApiException("输入内容为空",15); } @@ -932,6 +970,15 @@ public class SydApiBaseFunction implements SydApi { @Override public List SYD_SM4_CheckMacAndDecrypt_BatchData(int[] iEncKeyIndex, int[] iMacKeyIndex, List pcData) { + + if (LogFactory.iLogLevel == 3) { + log.debug("SYD_SM4_CheckMacAndDecrypt_BatchData"); + } + + if (pcData.isEmpty()) { + return new ArrayList<>(); + } + if (null == this.hsms || null == iMacKeyIndex || null == pcData) { throw new SydApiException("输入内容为空",15); } @@ -977,7 +1024,7 @@ public class SydApiBaseFunction implements SydApi { protected static int[] toIntArray(List list) { - if (null == list || 0 == list.size()) { + if (null == list || list.isEmpty()) { return new int[0]; } int[] ia = new int[list.size()]; @@ -988,7 +1035,7 @@ public class SydApiBaseFunction implements SydApi { } protected static boolean[] toBoolArray(List list) { - if (null == list || 0 == list.size()) { + if (null == list || list.isEmpty()) { return new boolean[0]; } boolean[] ia = new boolean[list.size()];