Browse Source

Z991239-5462 #comment 记录密钥更新需求时返回的校验码,用于后续比对

oilyang 1 year ago
parent
commit
791e0fee0b

+ 2 - 2
Module/mod_accessauth/AccessAuthFSM.cpp

@@ -343,7 +343,7 @@ struct UpdateWKTask : ITaskSp
 
 
 			ErrorCodeEnum eLoadErr = m_entity->LoadKeysToPinPadACS(tmkpair.second, updateWKRet.tpk,
-				updateWKRet.edk, updateWKRet.keyIndex);
+				updateWKRet.edk, updateWKRet.keyIndex,updateWKRet.tpkKeyCheck,updateWKRet.edkKeyCheck);
 			if (eLoadErr == Error_Succeed) {
 				if (client) client->Destory();
 				return;
@@ -453,7 +453,7 @@ struct UpdateWKTask : ITaskSp
 			}
 			SP::Module::Restful::ExtractDataFromDebranchResponse(result.content, updateWKAns);
 
-			DWORD rc = m_entity->LoadKeysToPinPadACS(tmkpair.second, updateWKAns.tpk, updateWKAns.edk, updateWKAns.keyIndex);
+			DWORD rc = m_entity->LoadKeysToPinPadACS(tmkpair.second, updateWKAns.tpk, updateWKAns.edk, updateWKAns.keyIndex, updateWKAns.tpkKeyCheck, updateWKAns.edkKeyCheck);
 			if (rc == Error_Succeed) {
 				return;
 			}

+ 4 - 3
Module/mod_accessauth/mod_AccessAuth.cpp

@@ -82,7 +82,7 @@ struct InitializerInitMKTask : ITaskSp
 			}
 
 			if (m_entity->HasPinPad()) {
-				if (m_entity->LoadKeysToPinPadACS(tmkpair.second, initMKRet.tpk, initMKRet.edk, initMKRet.keyIndex) == Error_Succeed)
+				if (m_entity->LoadKeysToPinPadACS(tmkpair.second, initMKRet.tpk, initMKRet.edk, initMKRet.keyIndex,initMKRet.tpkKeyCheck,initMKRet.edkKeyCheck) == Error_Succeed)
 					m_entity->EndInitMK(Error_Succeed, "");
 				else
 				{
@@ -212,7 +212,7 @@ struct InitializerInitMKTask : ITaskSp
 
 				if (m_entity->HasPinPad()) {
 					const bool testResult = SP::Module::Restful::ExtractDataFromDebranchResponse(result.content, instanceAns);
-					if (m_entity->LoadKeysToPinPadACS(tmkpair.second, instanceAns.TPK, instanceAns.EDK, instanceAns.keyIndex) == Error_Succeed) {
+					if (m_entity->LoadKeysToPinPadACS(tmkpair.second, instanceAns.TPK, instanceAns.EDK, instanceAns.keyIndex, instanceAns.tpkKeyCheck, instanceAns.edkKeyCheck) == Error_Succeed) {
 						m_entity->EndInitMK(Error_Succeed, "");
 					}
 					else {
@@ -1693,7 +1693,7 @@ void CAccessAuthEntity::EndInitMK(DWORD rc, const char *pszErrMsg)
 
 }
 
-ErrorCodeEnum CAccessAuthEntity::LoadKeysToPinPadACS(string TMK, string TPK, string EDK, string index)
+ErrorCodeEnum CAccessAuthEntity::LoadKeysToPinPadACS(string TMK, string TPK, string EDK, string index, string tpkCheck, string edkCheck)
 {
 	LOG_FUNCTION();
 #ifdef RVC_OS_WIN
@@ -1732,6 +1732,7 @@ ErrorCodeEnum CAccessAuthEntity::LoadKeysToPinPadACS(string TMK, string TPK, str
 		req.workingkey1 = TPK.c_str();
 		req.workingkey2 = EDK.c_str();
 		req.reserved3 = index.c_str();
+		req.reserved4 = tpkCheck.c_str();
 
 		if (!req.initializeflag) DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("LoadKeysToPinPadACS")("initializeflag is false");
 		PinPadService_LoadKeysSM_Ans ans = {};

+ 1 - 1
Module/mod_accessauth/mod_AccessAuth.h

@@ -172,7 +172,7 @@ public:
 		return m_strInitUrl;
 	}
 	void EndInitMK(DWORD rc, const char* pszErrMsg);
-	ErrorCodeEnum LoadKeysToPinPadACS(string TMK, string TPK, string EDK, string index);
+	ErrorCodeEnum LoadKeysToPinPadACS(string TMK, string TPK, string EDK, string index, string tpkCheck, string edkCheck);
 	DWORD InitDevice(SpReqAnsContext<AccessAuthService_InitDev_Req, AccessAuthService_InitDev_Ans>::Pointer& ctx);
 	void GetNetMsg(SpReqAnsContext<AccessAuthService_GetNetMsg_Req, AccessAuthService_GetNetMsg_Ans>::Pointer& ctx);
 	DWORD m_eErrNum;

+ 3 - 34
Module/mod_pinpad/PinPadFSM.cpp

@@ -943,6 +943,7 @@ Err:
 		memset(tmpCheckCode, 0, MAX_PIN_BLOCK_SIZE);
 		//HexBuf2StrBuf(dstInfo.data,&tmpCheckCode,dstInfo.dwSize);
 		memcpy(tmpCheckCode, dstInfo.data, dstInfo.dwSize);
+
 		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ckckck[%s], m_keySNSM:%s", tmpCheckCode, m_keySNSM.GetData());
 
 
@@ -1160,40 +1161,8 @@ int CPinPadFSM::LoadKeySM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadSe
 	//oilyang@20220308 to calc checkcode if called Initializer
 	if (ctx->Req.initializeflag)
 	{
-		PBYTE pCtMasterKey = new BYTE[48];
-		PBYTE pCtPinKey = new BYTE[48];
-		BYTE pinKey[16] = { 0 };
-		int pinKeyLen = 16;
-
-		int ctMLen = SP::Module::Util::StrBuf2HexBuf(ctx->Req.masterkey.GetData(), &pCtMasterKey);
-		int ctPinLen = SP::Module::Util::StrBuf2HexBuf(ctx->Req.workingkey1.GetData(), &pCtPinKey);
-		//sm4 decrypt
-		sm4_context sm4Contxt;
-		sm4_setkey_dec(&sm4Contxt, pCtMasterKey);
-		sm4_crypt_ecb(&sm4Contxt, SM4_DECRYPT, ctPinLen, pCtPinKey, (BYTE*)pinKey);
-
-		BYTE ck[16] = { 0 };
-		BYTE ckCode[128] = { 0 };
-		sm4_setkey_enc(&sm4Contxt, pinKey);
-		sm4_crypt_ecb(&sm4Contxt, SM4_ENCRYPT, 8, ck, (BYTE*)ckCode);
-		char* strCkCode = new char[256];
-		memset(strCkCode, 0, 256);
-		SP::Module::Util::HexBuf2StrBuf((PBYTE)ckCode, &strCkCode, 16);
-		LogWarn(Severity_Low, Error_Unexpect, PinPad_UserErrorCode_PinPad_CkCode_While_Load_SM, strCkCode);
-
-		BYTE ckMaster[16] = { 0 };
-		BYTE ckCodeMaster[128] = { 0 };
-		sm4_setkey_enc(&sm4Contxt, pCtMasterKey);
-		sm4_crypt_ecb(&sm4Contxt, SM4_ENCRYPT, 8, ckMaster, (BYTE*)ckCodeMaster);
-		char* strCkCodeMaster = new char[256];
-		memset(strCkCodeMaster, 0, 256);
-		SP::Module::Util::HexBuf2StrBuf((PBYTE)ckCodeMaster, &strCkCodeMaster, 16);
-		GetEntityBase()->GetFunction()->SetSysVar("ckCode", strCkCodeMaster, true);
-
-		delete[] pCtMasterKey;
-		delete[] pCtPinKey;
-		delete[] strCkCode;
-		delete[] strCkCodeMaster;
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the new check code:%s", ctx->Req.reserved4.GetData());
+		LogWarn(Severity_Low, Error_Unexpect, PinPad_UserErrorCode_PinPad_CkCode_While_Load_SM, ctx->Req.reserved4);
 	}
 
 	m_ullBeginTime = SP::Module::Comm::RVCGetTickCount();