Prechádzať zdrojové kódy

Z991239-6413 #comment ConvertUtf8ToGBK 调整

80374374 2 mesiacov pred
rodič
commit
c154bce465

+ 3 - 0
Module/include/CommEntityUtil.hpp

@@ -209,6 +209,9 @@ inline ULLINT RVCGetTickCount()
 
 namespace Util
 {
+	/**
+	 * Need to delete *hexBuf if (*hexBuf) not null
+	 */
 static int StrBuf2HexBuf(const char* strBuf, PBYTE* hexBuf)
 {
     int len = strlen(strBuf);

+ 1 - 35
Module/mod_accessauth/AccessAuthFSM.cpp

@@ -26,43 +26,9 @@ using namespace PinPad;
 #include "WMIDeviceQuery.h"
 #include <WinCrypt.h>
 #include <Strsafe.h>
-#include "DeviceBaseClass.h"
 #define ALLOW_MULTI_NETWORKD_CARDS
 #endif // RVC_OS_WIN
 
-//TODO: CrossPlaform  [Gifur@2025730]
-int HexBuf2StrBuf(PBYTE hexBuf, char** strBuf, DWORD len)
-{
-	char* tmpStr = *strBuf;
-	int count = 0;
-	for (int i = 0; i < len; ++i) {
-		sprintf(tmpStr + count, "%0.2X", hexBuf[i]);
-		count += 2;
-	}
-	return 0;
-}
-
-//TODO: CrossPlaform  [Gifur@2025730]
-int StrBuf2HexBuf(LPCTSTR strBuf, PBYTE* hexBuf)
-{
-	int len = strlen(strBuf);
-	if (len == 0 || len % 2 != 0)
-		return 0;
-	BYTE* buf = new BYTE[len / 2];
-	if (buf == NULL)
-		return 0;
-	int j = 0;
-	for (int i = 0; i < len;) {
-		int tmpVal;
-		sscanf(strBuf + i, "%2X", &tmpVal);
-		buf[j] = tmpVal;
-		i += 2;
-		j++;
-	}
-	*hexBuf = buf;
-	return j;
-}
-
 CAccessAuthFSM::CAccessAuthFSM()
 	:m_finishAccess(0), m_nAccessFailedCount(0)
 	, m_accessAuthHost(true), m_initDeviceHost(true)
@@ -886,7 +852,7 @@ DWORD CAccessAuthFSM::GetTmk(string& tmk)
 	}
 	memcpy_s(&tmp[70], sizeof(tmp) - 70, priKey.m_pData, priKey.m_iLength);
 	char* pRet = new char[512];
-	HexBuf2StrBuf(tmp, &pRet, 140);
+	SP::Module::Util::HexBuf2StrBuf(tmp, &pRet, 140);
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("data=%s,%d", pRet, strlen(pRet));
 	tmk.assign(pRet);
 	delete[] pRet;

+ 7 - 10
Module/mod_accessauth/mod_AccessAuth.cpp

@@ -9,6 +9,7 @@
 #include "Event.h"
 #include "comm.h"
 #include "CommEntityRestful.hpp"
+#include "CommEntityUtil.hpp"
 #include "TokenKeeper_client_g.h"
 using namespace TokenKeeper;
 #include "PinPad_client_g.h"
@@ -24,10 +25,6 @@ using namespace PinPad;
 #include "DeviceBaseClass.h"
 #endif
 
-//TODO: CrossPlaform  [Gifur@2025730]
-extern int HexBuf2StrBuf(PBYTE hexBuf, char** strBuf, DWORD len);
-extern int StrBuf2HexBuf(LPCTSTR strBuf, PBYTE* hexBuf);
-
 struct InitializerInitMKTask : ITaskSp
 {
 	CAccessAuthFSM* m_fsm;
@@ -1216,14 +1213,13 @@ pair<string, string> CAccessAuthEntity::GenerateTmkToKMC()
 
 pair<string, string> CAccessAuthEntity::EncryptedByPubKey(CSimpleStringA pubKey, bool bNeed04Head)
 {
-	LOG_FUNCTION();
-
+	//TODO: New了那么多对象,什么时候Delete??  [Gifur@202585]
 	if (pubKey.GetLength() <= 0)
 		return make_pair("", "");
 	PCHAR strRam = new CHAR[512];
 	memset(strRam, 0, 512);
 	memcpy(strRam, &(m_btRam[0]), 16);
-	HexBuf2StrBuf((PBYTE)m_btRam, &strRam, 16);
+	SP::Module::Util::HexBuf2StrBuf((PBYTE)m_btRam, &strRam, 16);
 	const int MAX_KEY_SIZE = 256;
 	char random_enc_bypbk[MAX_KEY_SIZE];
 	memset(random_enc_bypbk, 0, MAX_KEY_SIZE);
@@ -1234,14 +1230,15 @@ pair<string, string> CAccessAuthEntity::EncryptedByPubKey(CSimpleStringA pubKey,
 	memset(pOldPubKey, 0, 256);
 	memset(pxxKey, 0, 256);
 
-	int size = StrBuf2HexBuf(pubKey.GetData(), &pOldPubKey);
+	int size = SP::Module::Util::StrBuf2HexBuf(pubKey.GetData(), &pOldPubKey);
 	if (bNeed04Head)
 	{
 		pxxKey[0] = 0x04;
 		memcpy(pxxKey + 1, pOldPubKey, size);
 	}
-	else
+	else {
 		memcpy(pxxKey, pOldPubKey, 65);
+	}
 	int retSM2 = EncWithSM2PubKey((unsigned char*)m_btRam, 16, (unsigned char*)random_enc_bypbk, &outMsgLen, (unsigned char*)pxxKey, 65);
 	if (!retSM2 || outMsgLen != 113)
 	{
@@ -1269,7 +1266,7 @@ pair<string, string> CAccessAuthEntity::EncryptedByPubKey(CSimpleStringA pubKey,
 	BYTE tmpRandomEnc[512];
 	memset(tmpRandomEnc, 0, 512);
 	memcpy(tmpRandomEnc, &(tmp_enc_bypbk[0]), outMsgLen - 1);
-	size = HexBuf2StrBuf((PBYTE)tmpRandomEnc, &pBlock, 112);
+	size = SP::Module::Util::HexBuf2StrBuf((PBYTE)tmpRandomEnc, &pBlock, 112);
 	return make_pair(pBlock, strRam);
 }
 

+ 0 - 5
Module/mod_accessauth/mod_AccessAuth.h

@@ -11,11 +11,6 @@ using namespace AccessAuthorization;
 #define DEFALT_WAIT_PINPAD_MS 0
 #define INTERVAL_WAIT_PINPAD_MS 200
 
-//TODO: CrossPlaform  [Gifur@2025725]
-int HexBuf2StrBuf(PBYTE hexBuf, char** strBuf, DWORD len);
-//TODO: CrossPlaform  [Gifur@2025725]
-int StrBuf2HexBuf(LPCTSTR strBuf, PBYTE* hexBuf);
-
 class CAccessAuthEntity;
 
 class CAccessAuthSession : public AccessAuthService_ServerSessionBase

+ 3 - 38
Module/mod_chromium/baseEx.cpp

@@ -27,6 +27,7 @@ using namespace boost::interprocess;
 #include <boost/property_tree/ini_parser.hpp>
 
 #if (defined _WIN32 || defined _WIN64)
+#include <ShellAPI.h>
 #define BOOST_INTERPROCESS_SHARED_DIR_PATH "C:\\"
 #else
 #include <sys/types.h>
@@ -50,24 +51,16 @@ const std::wstring specialStr = L"乗俓僜刓匼哱圽塡奬媆峔嶾廫慭怽
 #define MAX_LOG_LEN 4096
 #define MAX_CEFLOG_LEN 5120
 
-
-#if (defined _WIN32 || defined _WIN64)
-#include <ShellAPI.h>
-
-//TODO: CrossPlaform  [Gifur@2025728]
 std::string UtfToGbk(const char* utf8)
 {
+#if (defined _WIN32 || defined _WIN64)
 	std::string val(utf8);
 	SP::Module::Util::ConvertUtf82GBK(val);
 	return val;
-}
-
 #else
-std::string UtfToGbk(const char* utf8)
-{
 	return utf8;
-}
 #endif
+}
 
 struct cefclientLog {
 	LOG_LEVEL_E m_level;
@@ -381,34 +374,6 @@ std::pair<unsigned long, ErrMsgStruct> getErrMsgByRemark(std::string srcMsg, boo
 	}
 }
 
-std::pair<unsigned long, std::string> splitStrToUserCodeAndErrMsg(std::string srcMsg)
-{
-	const std::string headerStr = "UserError=";
-	if (srcMsg.find(headerStr) != 0)
-		return std::make_pair(0, srcMsg);
-
-	unsigned long userCode = std::stoi(srcMsg.substr(headerStr.length()));
-	std::string userCodeStr = CSimpleString::Format("0x%X", userCode).GetData();
-
-	if (g_usercodeTranslateFile.length() == 0)
-		return std::make_pair(userCode, srcMsg);
-
-	try
-	{
-		boost::property_tree::ptree ptr, tag;
-		boost::property_tree::ini_parser::read_ini(g_usercodeTranslateFile, ptr);
-
-		tag = ptr.get_child("UserCodeToMsgTip");
-		std::string tipMsg = tag.get<std::string>(userCodeStr);
-		return std::make_pair(userCode, UtfToGbk(tipMsg.c_str()));
-	}
-	catch (std::exception &e) {
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("ini_parse failed, reason:%s", e.what());
-	}
-	
-	return std::make_pair(userCode, srcMsg);
-}
-
 std::string hexdumpToString(const char* buf, const int num)
 {
 	char str[8192 * 2] = { 0 };

+ 0 - 1
Module/mod_chromium/baseEx.h

@@ -29,7 +29,6 @@ void DbgToFileLogger(std::string msg);
 
 bool deleteDir_byFileSystem(const std::string srcPath);
 void InitTranslateFile(std::string srcFile);
-std::pair<unsigned long, std::string> splitStrToUserCodeAndErrMsg(std::string srcMsg);
 void InitUserCodeToMsgTip(CAutoArray<CSimpleStringA>& strErrorCodeArr, CAutoArray<CSimpleStringA>& strDescriptionArr, CAutoArray<CSimpleStringA>& strRemarkArr);
 bool isMsgTipExist();
 

+ 0 - 1
Module/mod_chromium/mod_chromium.cpp

@@ -5,7 +5,6 @@
 #include <WinUser.h>
 #include <tchar.h>
 #include <corecrt_io.h>
-#define SPLIT_SLASH_STR "\\"
 #include "chromelink_export.h"
 #pragma comment(lib, "cefControl.lib")
 #else