Quellcode durchsuchen

Z991239-5580 #comment feat: 合并http库使用,合并其他代码处理

陈纪林80310970 vor 1 Jahr
Ursprung
Commit
c3f859869c

+ 0 - 2
Framework/Common/SpBase.h

@@ -1663,7 +1663,6 @@ SPBASE_API void LogTrace(const char* pszMessage, const char* pszSourceFile, cons
 SPBASE_API CSimpleStringA GetSysErrMsg(int nErrCode);
 SPBASE_API const char *_GetFileName(const char *pszFilePath);
 
-#ifdef RVC_OS_LINUX
 /*
 基于当前mod中包含有restful模块,需要把数据从framework中传递到librestful,会比较困难
 (1)实际上大部分实体都没有加载restful模块,所以难以进行显示调用进行初始化。
@@ -1673,7 +1672,6 @@ SPBASE_API const char *_GetFileName(const char *pszFilePath);
 */
 #define MAX_TOKEN_LEN 256
 SPBASE_API void SpGetToken(char* channelId, char* token, char* terminalno, char* reserve1);
-#endif
 
 #ifdef RVC_OS_WIN //TODO: duplicate ?
 #define LOG_TRACE(pMsg, ...) \

+ 0 - 2
Framework/spbase/SpBase.cpp

@@ -422,7 +422,6 @@ SPBASE_API void LogTrace(const char* pszMessage, const char* pszFile, const int
 }
 
 #include "log.h"
-#ifdef RVC_OS_LINUX
 SPBASE_API void SpGetToken(char* channelId, char* token, char* terminalno, char* reserve1)
 {
 	sp_env_t* env = sp_get_env();
@@ -445,7 +444,6 @@ SPBASE_API void SpGetToken(char* channelId, char* token, char* terminalno, char*
 	else if (NULL == env->cfg->shell_ini->token)
 		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SpGetToken can not get token!env->cfg->shell_ini->token == NULL");
 }
-#endif
 
 
 

+ 8 - 265
Module/mod_accessauth/AccessAuthFSM.cpp

@@ -7,6 +7,8 @@
 #include  <stdlib.h>
 #include "fileutil.h"
 #include "CommEntityUtil.hpp"
+#include "CommEntityRestful.hpp"
+#include "SpUtility.h"
 #include "comm.h"
 #include "PinPad_client_g.h"
 using namespace PinPad;
@@ -22,10 +24,6 @@ using namespace PinPad;
 #include <algorithm>
 #pragma comment(lib, "IPHLPAPI.lib")
 #define ALLOW_MULTI_NETWORKD_CARDS
-
-#else
-#include "CommEntityRestful.hpp"
-#include "SpUtility.h"
 #endif // RVC_OS_WIN
 
 int HexBuf2StrBuf(PBYTE hexBuf, char** strBuf, DWORD len)
@@ -130,50 +128,6 @@ struct TimeSynTask : ITaskSp
 		CSystemStaticInfo si;
 		m_fsm->GetEntityBase()->GetFunction()->GetSystemStaticInfo(si);
 
-#ifdef RVC_OS_WIN
-		IHttpFunc* client;
-		client = create_http(m_fsm->HttpsLogCallBack);
-		CSessionkeySynReq timeSynReq;
-		CSessionkeySynRet timeSynRet;
-
-		timeSynReq.terminalNo = si.strTerminalID.GetData();
-		timeSynReq.curTime = CSmallDateTime::GetNow().GetTime64();
-		timeSynReq.m_url = m_fsm->GetmAccessAuthHost();
-		timeSynReq.m_url += "/api/v3/sessionkey";//v3 新接口,返回title、content
-		long beg = GetTickCount();
-		bool ret = client->Post(timeSynReq, timeSynRet);
-		long end = GetTickCount();
-
-		if (ret) {
-			if (timeSynRet.m_userCode.compare(ACS_SUCCESS)) {
-				m_fsm->AuthLogWarn(timeSynRet, timeSynReq.m_url, "获取会话密钥");
-				if (client) client->Destory();
-				return;
-			}
-
-
-			int decodedSessionKeyLen = 0;
-			char* decodedSessionKey = MyBase64::Hex2Str(timeSynRet.data.sessionKey.c_str(), decodedSessionKeyLen);
-
-			DWORD rc = m_fsm->HandleTimeSyn(timeSynRet.data.timeDiff, (BYTE*)decodedSessionKey);
-			delete decodedSessionKey;
-			if (rc == Error_Succeed) {
-				auto pEvent = new FSMEvent(CAccessAuthFSM::Event_EndSyncTime);
-				m_fsm->PostEventFIFO(pEvent);
-			}
-			else {
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("TimeSynTask HandleTimeSyn error = %08X", rc);
-			}
-		}
-		else {
-			m_fsm->AuthLogWarn(timeSynRet, timeSynReq.m_url, "获取会话密钥");
-
-			FSMEvent* pEvent = new FSMEvent(CAccessAuthFSM::Event_ReqTokenCancel);
-			pEvent->param1 = AccessAuthorization_UserErrorCode_ACS_FAIL;
-			m_fsm->PostEventFIFO(pEvent);
-		}
-		client->Destory();
-#else
 		struct TimeSynReqStructJson
 		{
 			std::string terminalNo;
@@ -220,7 +174,7 @@ struct TimeSynTask : ITaskSp
 				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("authVersion: %d", timeSyncAns.authVersion);
 				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("sessionKey: %s", timeSyncAns.sessionKey.c_str());
 				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("reserved: %s", timeSyncAns.reserved.c_str());
-			};
+	};
 			printFunc();
 
 			int decodedSessionKeyLen = 0;
@@ -236,7 +190,7 @@ struct TimeSynTask : ITaskSp
 			else {
 				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("TimeSynTask HandleTimeSyn error = %08X", rc);
 			}
-		}
+}
 		else {
 			std::string errDetail(result.WhatError());
 			if (errDetail.find("Error resolving address") != std::string::npos) {
@@ -266,7 +220,6 @@ struct TimeSynTask : ITaskSp
 			pEvent->param1 = AccessAuthorization_UserErrorCode_ACS_FAIL;
 			m_fsm->PostEventFIFO(pEvent);
 		}
-#endif // RVC_OS_WIN
 	}
 };
 
@@ -286,96 +239,6 @@ struct UpdateWKTask : ITaskSp
 		CSystemStaticInfo si;
 		m_fsm->GetEntityBase()->GetFunction()->GetSystemStaticInfo(si);
 		
-#ifdef RVC_OS_WIN
-		IHttpFunc* client;
-		client = create_http(m_fsm->HttpsLogCallBack);
-		CAccessAuthUpdateWKReq updateWKReq;
-		updateWKReq.terminalNo = si.strTerminalID.GetData();
-		auto tmkpair = m_entity->GenerateTmkToKMC();//first是加密的,seconde是没加密的
-		updateWKReq.encRandom = tmkpair.first;
-
-		PinPadService_ClientBase* pPinPad = new PinPadService_ClientBase(this->m_entity);
-		auto errRc = pPinPad->Connect();
-		if (errRc == Error_Succeed)
-		{
-			PinPadService_GetCheckCode_Req req = {};
-			PinPadService_GetCheckCode_Ans ans = {};
-
-			req.mSN.Init(1);
-			req.wSN.Init(1);
-			req.mSN[0] = 1;
-			req.wSN[0] = 0;
-			errRc = (*pPinPad)(EntityResource::getLink().upgradeLink())->GetCheckCode(req, ans, 10000);
-			if (errRc == Error_Succeed)
-			{
-				updateWKReq.tpkKeyCheck = ans.checkcode[0].GetData();
-				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("keyChek:%s.", updateWKReq.tpkKeyCheck.c_str());
-				updateWKReq.keyIndex = ans.index[0].GetData();
-				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Index:%s.", updateWKReq.keyIndex.c_str());
-			}
-			else
-			{
-				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get keyChek && keyIndex failed.");
-			}
-
-			pPinPad->GetFunction()->CloseSession();
-		}
-		else
-		{
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("connect to pinpad failed.error code:%d", errRc);
-		}
-
-		CAccessAuthUpdateWKRet updateWKRet;
-		updateWKReq.m_url = m_fsm->GetmAccessAuthHost();
-		updateWKReq.m_url += "/api/v5/wkupdate";
-		long beg = GetTickCount();
-		bool ret = client->Post(updateWKReq, updateWKRet);
-		long end = GetTickCount();
-
-		if (ret) {
-			if (updateWKRet.m_userCode.compare(ACS_SUCCESS)) {
-				m_fsm->doWarnMsg(ERR_ACCESSAUTH_UPDATE_WK,
-					GetOutPutStr("%s%s%s%s", "UpdateWKTask", updateWKRet.m_userCode.c_str(), "message", updateWKRet.m_errMsg.c_str()).c_str());
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)
-					(GetOutPutStr("%s%s%s%s", "UpdateWKTask", updateWKRet.m_userCode.c_str(), "message", updateWKRet.m_errMsg.c_str()).c_str());
-				if (client) client->Destory();
-				return;
-			}
-
-
-
-			ErrorCodeEnum eLoadErr = m_entity->LoadKeysToPinPadACS(tmkpair.second, updateWKRet.tpk,
-				updateWKRet.edk, updateWKRet.keyIndex,updateWKRet.tpkKeyCheck,updateWKRet.edkKeyCheck);
-			if (eLoadErr == Error_Succeed) {
-				if (client) client->Destory();
-				return;
-			}
-			else {
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("UpdateWKTask 密钥加载失败,请检查密码键盘连接. error = %08X", eLoadErr);
-			}
-		}
-		else {
-			CSimpleStringA acsResoultCode = "RTA520F";
-			int acsErrCode = ERROR_ACCESSAUTH_CONNECT_ACS_x;
-			if (updateWKRet.m_sysCode == 6)
-			{
-				acsResoultCode = "RTA520D";
-				acsErrCode = ERROR_ACCESSAUTH_CONNECT_ACS_6;
-			}
-			else if (updateWKRet.m_sysCode == 28)
-			{
-				acsResoultCode = "RTA520E";
-				acsErrCode = ERROR_ACCESSAUTH_CONNECT_ACS_28;
-			}
-			m_fsm->doWarnMsg(acsErrCode,
-				GetOutPutStr("%s%d", "连接总行ACS准入服务失败(StageReport).", updateWKRet.m_sysCode).c_str());
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setBeginTime(beg).setEndTime(end).
-				setResultCode(acsResoultCode.GetData()).
-				setResultMsg(updateWKRet.m_errMsg.c_str())
-				(GetOutPutStr("%s%d", "连接总行ACS准入服务失败(StageReport).", updateWKRet.m_sysCode).c_str());
-		}
-		client->Destory();
-#else
 		struct UpdateWKReq
 		{
 			std::string terminalNo;
@@ -467,13 +330,12 @@ struct UpdateWKTask : ITaskSp
 			m_fsm->doWarnMsg(ERROR_ACCESSAUTH_CONNECT_ACS,
 				GetOutPutStr("%s%s", "连接总行ACS准入服务失败(UpdateWKTask).", result.WhatError().c_str()).c_str(), true);
 			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA520G")("UpdateWKTask Connect Failed.");
-		}
+	}
 
 	UpdateWKRetError:
 
 		FSMEvent* pEvent = new FSMEvent(CAccessAuthFSM::Event_ReqTokenCancel);
 		m_fsm->PostEventFIFO(pEvent);
-#endif // RVC_OS_WIN
 	}
 };
 
@@ -498,62 +360,6 @@ struct GetTokenTask : ITaskSp
 		CSystemStaticInfo si;
 		m_fsm->GetEntityBase()->GetFunction()->GetSystemStaticInfo(si);
 		
-#ifdef RVC_OS_WIN
-		IHttpFunc* client;
-		client = create_http(m_fsm->HttpsLogCallBack);
-		CAccessAuthGetTokenReq getTokenReq;
-
-		if (m_fsm->GetTokenReq(&getTokenReq) != Error_Succeed) {
-			if (client) client->Destory();
-			return;
-		}
-
-		CAccessAuthGetTokenRet getTokenRet;
-		getTokenReq.m_url = m_fsm->GetmAccessAuthHost();
-		getTokenReq.m_url += "/api/v3/access"; //v3新接口,返回title,content
-
-		long beg = GetTickCount();
-		bool ret = client->Post(getTokenReq, getTokenRet);
-		long end = GetTickCount();
-
-		if (ret) {
-			if (getTokenRet.m_userCode.compare(ACS_SUCCESS)) {
-				m_fsm->AuthLogWarn(getTokenRet, getTokenReq.m_url, "获取准入token");
-				if (client) client->Destory();
-				return;
-			}
-
-
-			if (getTokenRet.data.flag != 0 /*&& flag?*/) //判断是否需要告警,通过标志位,标志位待确定
-			{
-				CSimpleStringA tmsg = CSimpleStringA::Format("{\"errcode\": \"%s\", \"message\": %s}",
-					getTokenRet.m_userCode.c_str(), getTokenRet.data.warnMessage.c_str());
-				m_fsm->GetEntityBase()->GetFunction()->SetSysVar("AuthErrMsg", tmsg.GetData(), true);
-			}
-			else
-			{
-				m_fsm->GetEntityBase()->GetFunction()->SetSysVar("AuthErrMsg", "", true);
-			}
-
-			DWORD rc = m_fsm->HandleGetToken((BYTE*)getTokenRet.data.sharedKey.enToken.c_str(), (BYTE*)getTokenRet.data.sharedKey.sharedSK.c_str(),
-				(BYTE*)getTokenRet.data.accessToken.enToken.c_str(), (BYTE*)getTokenRet.data.accessToken.retHash.c_str());
-			if (rc == Error_Succeed) {
-				FSMEvent* pEvent = new FSMEvent(CAccessAuthFSM::Event_ReqTokenSucc);
-				m_fsm->PostEventFIFO(pEvent);
-				if (client) client->Destory();
-				return;
-			}
-			else {
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("GetTokenTask HandleGetToken error = %08X", rc);
-			}
-		}
-		else {
-			m_fsm->AuthLogWarn(getTokenRet, getTokenReq.m_url, "获取准入token");
-		}
-		FSMEvent* pEvent = new FSMEvent(CAccessAuthFSM::Event_ReqTokenFail);
-		m_fsm->PostEventFIFO(pEvent);
-		if (client) client->Destory();
-#else
 		CAutoArray<CSimpleStringA> devNames;
 		DWORD rc = m_fsm->GetAllDevices(m_entity, devNames);
 
@@ -644,7 +450,7 @@ struct GetTokenTask : ITaskSp
 			{
 				m_fsm->GetEntityBase()->GetFunction()->SetSysVar("AuthErrMsg", "", true);
 			}
-				
+
 			DWORD rc = m_fsm->HandleGetToken((BYTE*)getTokenAns.sharedKey.enToken.c_str(), (BYTE*)getTokenAns.sharedKey.sharedSK.c_str(),
 				(BYTE*)getTokenAns.accessToken.enToken.c_str(), (BYTE*)getTokenAns.accessToken.retHash.c_str());
 
@@ -685,7 +491,6 @@ struct GetTokenTask : ITaskSp
 		}
 		FSMEvent* pEvent = new FSMEvent(CAccessAuthFSM::Event_ReqTokenFail);
 		m_fsm->PostEventFIFO(pEvent);
-#endif // RVC_OS_WIN
 	}
 };
 
@@ -697,52 +502,7 @@ struct InitDeviceTask :public ITaskSp
 
 	void Process()
 	{
-#ifdef RVC_OS_WIN
-		if (m_fsm->GetmInitDeviceHost().IsNullOrEmpty()) {
-			LogWarn(Severity_Middle, Error_Unexpect, AccessAuthorization_UserErrorCode_InitDev_NULL, "加密通道Url为空");
-			return;
-		}
-		m_fsm->SetDevPubKey("");
-		IHttpFunc* client;
-		client = create_http(m_fsm->HttpsLogCallBack);
-		CAccessAuthInitDeviceReq initDeviceReq;
-		initDeviceReq.cr1 = m_req.CR1;
-		initDeviceReq.cr3 = m_req.CR3;
-		initDeviceReq.cDevPubKey = m_req.CDevPubKey;
-		initDeviceReq.r2 = m_req.R2;
-		initDeviceReq.vendor = m_req.Verdor;
-		CSystemStaticInfo si;
-		m_fsm->GetEntityBase()->GetFunction()->GetSystemStaticInfo(si);
-		initDeviceReq.terminalNo = si.strTerminalID;
-		CAccessAuthInitDeviceRet initDeviceRet;
-		initDeviceReq.m_url = m_fsm->GetmInitDeviceHost();
-		initDeviceReq.m_url = initDeviceReq.m_url + "/api/v3/initdevice";
-		long beg = GetTickCount();
-		bool ret = client->Post(initDeviceReq, initDeviceRet);
-		long end = GetTickCount();
-
-		if (ret) {
-			if (initDeviceRet.m_userCode.compare(ACS_SUCCESS)) {
-				m_fsm->AuthLogWarn(initDeviceRet, initDeviceReq.m_url, "初始设备", false);
-			}
-			else {
-				if (m_fsm->m_ctxInitDev != NULL) {
-					m_fsm->m_ctxInitDev->Ans.R1 = initDeviceRet.r1.c_str();
-					m_fsm->m_ctxInitDev->Ans.EncR2 = initDeviceRet.cr2.c_str();
-					m_fsm->m_ctxInitDev->Ans.R3 = initDeviceRet.r3.c_str();
-					m_fsm->SetDevPubKey(initDeviceRet.devPubKey.c_str());
-					m_fsm->m_ctxInitDev->Answer(Error_Succeed);
-					m_fsm->m_ctxInitDev.Clear();
-				}
-			}
-		}
-		else {
-			m_fsm->AuthLogWarn(initDeviceRet, initDeviceReq.m_url, "初始设备", false);
-		}
-		if (client) client->Destory();
-#else
 		return;
-#endif // RVC_OS_WIN
 	}
 };
 
@@ -1455,27 +1215,15 @@ template<class T>
 void CAccessAuthFSM::AuthLogWarn(const T& ret, const string& url, const string& method, bool bNeedEvent)
 {
 	CSimpleStringA msg;
-#ifdef RVC_OS_WIN
-	if (ret.m_userCode != "0" && ret.m_sysCode != 200)
-#else
 	if (!ret.ResponseOK())
-#endif // RVC_OS_WIN
 	{
 		int acsErrCode = ERROR_ACCESSAUTH_CONNECT_ACS_x;
-#ifdef RVC_OS_WIN
-	if (ret.m_sysCode == 6) {
-#else
-	if (ret.statusCode == 6) {
-#endif
+		if (ret.statusCode == 6) {
 			acsErrCode = ERROR_ACCESSAUTH_CONNECT_ACS_6;
 			msg = CSimpleStringA::Format("%s失败:域名解析失败,请尝试重启应用", method.c_str());
 
 		}
-#ifdef RVC_OS_WIN
-	else if (ret.m_sysCode == 28) {
-#else
-	else if (ret.statusCode == 28) {
-#endif
+		else if (ret.statusCode == 28) {
 			acsErrCode = ERROR_ACCESSAUTH_CONNECT_ACS_28;
 			msg = CSimpleStringA::Format("%s失败:连接总行服务超时,请尝试重启应用", method.c_str());
 		}
@@ -1485,15 +1233,10 @@ void CAccessAuthFSM::AuthLogWarn(const T& ret, const string& url, const string&
 		doWarnMsg(acsErrCode, msg.GetData(), bNeedEvent);
 	}
 	else {
-#ifdef RVC_OS_WIN
-		msg = CSimpleStringA::Format("{\"errcode\": \"%s\", \"message\": %s}",
-			ret.m_userCode.c_str(), ret.m_errMsg.c_str());
-#else
 		SP::Module::Restful::CommResponseJson responseStatus;
 		SP::Module::Restful::GetStatusFromDebranchResponse(ret.content, responseStatus);
 		msg = CSimpleStringA::Format("{\"errcode\": \"%s\", \"message\": %s}",
 			responseStatus.errorCode.c_str(), responseStatus.errorMsg.c_str());
-#endif // RVC_OS_WIN
 		doWarnMsg(ERR_ACCESSAUTH_SERVICE_FAILED, msg.GetData(), bNeedEvent);
 		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA520A")("准入服务端报错");
 	}

+ 6 - 215
Module/mod_accessauth/mod_AccessAuth.cpp

@@ -4,9 +4,11 @@
 #include "RVCComm.h"
 #include "access_basefun.h"
 #include <fileutil.h>
+#include <iniutil.h>
 #include <cmath>
 #include "Event.h"
 #include "comm.h"
+#include "CommEntityRestful.hpp"
 #include "TokenKeeper_client_g.h"
 using namespace TokenKeeper;
 #include "PinPad_client_g.h"
@@ -19,9 +21,7 @@ using namespace PinPad;
 #include "DeviceBaseClass.h"
 #include "MyBase64.h"
 #else
-#include "CommEntityRestful.hpp"
 #include "DeviceBaseClass.h"
-#include <iniutil.h>
 #endif
 
 #define KEY_SIZE 16
@@ -40,67 +40,6 @@ struct InitializerInitMKTask : ITaskSp
 	{
 		CSystemStaticInfo si;
 		m_fsm->GetEntityBase()->GetFunction()->GetSystemStaticInfo(si);
-#ifdef RVC_OS_WIN
-		IHttpFunc* client;
-		client = create_http(m_fsm->HttpsLogCallBack);
-		CInitlizerMKReq initMKReq;
-		CInitlizerMKRet initMKRet;
-		bool initFlag = m_entity->SendInitMKReqACS(initMKReq);
-
-		if (!initFlag)
-		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5204")("连接密码键盘异常");
-			m_entity->EndInitMK(ERR_ACCESSAUTH_CONNECT_PINPAD, "连接密码键盘异常,请检查");//,待完善细化错误码oiltest
-			client->Destory();
-		}
-
-		auto tmkpair = m_entity->GenerateTmkToKMC();
-		initMKReq.encRandom = tmkpair.first;
-		initMKReq.m_url = m_entity->GetInitUrl();
-		initMKReq.m_url += "/api/v5/initmk";
-		long beg = GetTickCount();
-		bool ret = client->Post(initMKReq, initMKRet);
-		long end = GetTickCount();
-
-		if (ret) {
-			if (initMKRet.m_userCode.compare(ACS_SUCCESS)) {
-				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InitializerInitMKTask")("initmk failed.");
-				if (client) client->Destory();
-				m_entity->EndInitMK(ERR_INITIALIZER_EXCEPTION, CSimpleStringA::Format("%s,%s"
-					, initMKRet.m_userCode.c_str(), initMKRet.m_errMsg.c_str()));
-				return;
-			}
-
-			//服务端返回成功再将数据写入AcessAuthourization.ini
-			CSmartPointer<IConfigInfo> pConfig;
-			auto rc = m_entity->GetFunction()->OpenConfig(Config_Run, pConfig);
-			rc = pConfig->WriteConfigValue("TerminalPD", "PrivateKey", m_entity->m_privateKey);
-			if (rc != Error_Succeed) {
-				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("write pri key failed.");
-				m_entity->EndInitMK(ERR_INITIALIZER_EXCEPTION, "私钥写入失败,请重新初始化。");
-				return;
-			}
-
-			if (m_entity->HasPinPad()) {
-				if (m_entity->LoadKeysToPinPadACS(tmkpair.second, initMKRet.tpk, initMKRet.edk, initMKRet.keyIndex,initMKRet.tpkKeyCheck,initMKRet.edkKeyCheck) == Error_Succeed)
-					m_entity->EndInitMK(Error_Succeed, "");
-				else
-				{
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5204")("连接密码键盘异常");
-					m_entity->EndInitMK(ERR_ACCESSAUTH_CONNECT_PINPAD, "密钥加载失败,请检查密码键盘连接。");//,待完善细化错误码oiltest
-				}
-			}
-			else
-				m_entity->EndInitMK(Error_Succeed, "");
-		}
-		else {
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI("InitializerInitMKTask").setBeginTime(beg).setEndTime(end).
-				setResultCode(std::to_string(LONGLONG(initMKRet.m_sysCode)).c_str()).
-				setResultMsg(initMKRet.m_errMsg.c_str())("InitializerInitMKTask Connect Failed.");
-			m_entity->EndInitMK(ERR_INITIALIZER_EXCEPTION, CSimpleStringA::Format("初始化服务连接失败。%d", ret).GetData());
-		}
-		client->Destory();
-#else
 		CInitlizerMKReq initMKReq;//oiltest dev module count
 		bool initFlag = m_entity->SendInitMKReqACS(initMKReq);
 		if (!initFlag)
@@ -229,7 +168,6 @@ struct InitializerInitMKTask : ITaskSp
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("post wk failed: %s", result.WhatError().c_str());
 			m_entity->EndInitMK(ERR_INITIALIZER_EXCEPTION, CSimpleStringA::Format("初始化服务连接失败。%s", result.WhatError().c_str()).GetData());
 		}
-#endif //RVC_OS_WIN
 	}
 };
 
@@ -592,26 +530,16 @@ bool CAccessAuthEntity::SaveAuthKey(BYTE *pKey)
 	}
 
 	char privateKey[BUF_SIZE] = { 0 };
-#ifdef RVC_OS_WIN
-	iniPath = runInfoPath + "\\runcfg\\AccessAuthorization.ini";
-	GetPrivateProfileString("TerminalPD", "PrivateKey", "", privateKey, BUF_SIZE, iniPath.GetData());
-#else
 	iniPath = runInfoPath + SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "AccessAuthorization.ini";
 	char* tmp = inifile_read_str(iniPath.GetData(), "TerminalPD", "PrivateKey", "");
 	strcpy(privateKey, tmp);
 	delete tmp;
-#endif // RVC_OS_WIN
 
 	if (strlen(privateKey) <= 0) {
-#ifdef RVC_OS_WIN
-		iniPath = runInfoPath + "\\runcfg\\Initializer.ini";
-		GetPrivateProfileString("TerminalPD", "PrivateKey", "", privateKey, BUF_SIZE, iniPath.GetData());
-#else
 		iniPath = runInfoPath + SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "Initializer.ini";
 		char* tmp2 = inifile_read_str(iniPath.GetData(), "TerminalPD", "PrivateKey", "");
 		strcpy(privateKey, tmp2);
 		delete tmp2;
-#endif // RVC_OS_WIN
 		if (strlen(privateKey) <= 0)
 		{
 			printPasswdError("私钥为空,请重置秘钥进行初始化");
@@ -621,11 +549,7 @@ bool CAccessAuthEntity::SaveAuthKey(BYTE *pKey)
 
 	int decodedPrivateKeyLen;
 
-#ifdef RVC_OS_WIN
-	char* pDecodedPrivateKey = MyBase64::Hex2Str(privateKey, decodedPrivateKeyLen);
-#else
 	char* pDecodedPrivateKey = Hex2Str(privateKey, decodedPrivateKeyLen);
-#endif // RVC_OS_WIN
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("privateKey len:%d, decodedPrivateKeyLen=%d", strlen(privateKey), decodedPrivateKeyLen);
 
 	char pDecryptPrivateKey[BUF_SIZE] = { 0 };
@@ -643,11 +567,7 @@ bool CAccessAuthEntity::SaveAuthKey(BYTE *pKey)
 	char pKeyLen[4] = { 0 };
 	memcpy(pKeyLen, pKey, 4);
 	int kenLen = Char2Int(pKeyLen);
-#ifdef RVC_OS_WIN
-	char* pEncodeKey = MyBase64::Str2Hex((char*)pKey,kenLen + 4);
-#else
 	char* pEncodeKey = Str2Hex((char*)pKey, kenLen + 4);
-#endif
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("kenLen=%d", kenLen);
 	delete pEncodeKey;
 	char* key = new char[kenLen + 1];
@@ -699,21 +619,13 @@ ErrorCodeEnum CAccessAuthEntity::EncryptDataWithSessionKey(const CBlob &raw, CBl
 	BYTE* pEncData = new BYTE[1024];
 	int pEncDataSize = 1024;
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("pEncDataSize=%d", pEncDataSize);
-#ifdef RVC_OS_WIN
-	char* pPlainInfo = MyBase64::Str2Hex((char*)raw.m_pData, raw.m_iLength);
-#else
 	char* pPlainInfo = Str2Hex((char*)raw.m_pData, raw.m_iLength);
-#endif
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("raw Length=%d", raw.m_iLength);
 	delete[] pPlainInfo;
 	
 	char sessionKey[KEY_SIZE] = { 0 };
 	memcpy(sessionKey,m_AuthSessionKey,KEY_SIZE);
-#ifdef RVC_OS_WIN
-	char* tmpKey = MyBase64::Str2Hex((char*)m_AuthSessionKey, KEY_SIZE);
-#else
 	char* tmpKey = Str2Hex((char*)m_AuthSessionKey, KEY_SIZE);
-#endif // RVC_OS_WIN
 	delete[] tmpKey;
 
 	if (!EncWithSM4_ECB((BYTE*)sessionKey, (BYTE*)(raw.m_pData), raw.m_iLength, pEncData, &pEncDataSize)) {
@@ -723,19 +635,11 @@ ErrorCodeEnum CAccessAuthEntity::EncryptDataWithSessionKey(const CBlob &raw, CBl
 	
 	enc.Attach(pEncData,pEncDataSize);
 
-#ifdef RVC_OS_WIN
-	char* tmp = MyBase64::Str2Hex((char*)pEncData, pEncDataSize);
-#else
 	char* tmp = Str2Hex((char*)pEncData, pEncDataSize);
-#endif // RVC_OS_WIN
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("pEncData size:%d", pEncDataSize);
 	delete[] tmp;
 
-#ifdef RVC_OS_WIN
-	tmp = MyBase64::Str2Hex((char*)enc.m_pData, enc.m_iLength);
-#else
 	tmp = Str2Hex((char*)enc.m_pData, enc.m_iLength);
-#endif // RVC_OS_WIN
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("EncWithSM4_ECB data size:%d", enc.m_iLength);
 	delete[] tmp;
 
@@ -872,16 +776,6 @@ bool CAccessAuthEntity::GetTerminalFingerPrint(BYTE *pBuf, int &nBufLen)
 	return true;
 }
 
-#ifdef RVC_OS_WIN
-#define RSAPUBKEY_BITLEN 1024
-struct PublicKeyBlob
-{
-	PUBLICKEYSTRUC  publickeystruc;
-	RSAPUBKEY rsapubkey;
-	BYTE modulus[RSAPUBKEY_BITLEN / 8];
-};
-#endif // RVC_OS_WIN
-
 // 生成RSA密钥对,并导出公钥
 bool CAccessAuthEntity::GetTerminalPublicKey(BYTE* pBuf, int& nBufLen, string& pubkey)
 {
@@ -892,8 +786,8 @@ bool CAccessAuthEntity::GetTerminalPublicKey(BYTE* pBuf, int& nBufLen, string& p
 		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("GetPath runinfo error=%d.", rc);
 		return false;
 	}
+	runInfoPath += SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR;
 #ifdef RVC_OS_WIN
-	runInfoPath += "\\runcfg\\";
 	DWORD dwAttr = GetFileAttributes(runInfoPath.GetData());
 	if (dwAttr == 0xFFFFFFFF)  //目录不存在则创建   
 	{
@@ -903,7 +797,6 @@ bool CAccessAuthEntity::GetTerminalPublicKey(BYTE* pBuf, int& nBufLen, string& p
 		}
 	}
 #else
-	runInfoPath += SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR;
 	if (!dir_is_exist(runInfoPath.GetData()))
 	{
 		if (dir_create(runInfoPath.GetData()) != 0)
@@ -935,11 +828,7 @@ bool CAccessAuthEntity::GetTerminalPublicKey(BYTE* pBuf, int& nBufLen, string& p
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("iPublicKeyLen=%d,iPrivateKeyLen=%d", iPublicKeyLen, iPrivateKeyLen);
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("[btPublicKey=%s]", (char*)btPublicKey);
 
-#ifdef RVC_OS_WIN
-	char* pEncode = MyBase64::Str2Hex((char*)btPublicKey, iPublicKeyLen);
-#else
 	char* pEncode = Str2Hex((char*)btPublicKey, iPublicKeyLen);
-#endif // RVC_OS_WIN
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("pEncode=%s,%d", pEncode, strlen(pEncode));
 
 	/*rc = pConfig->WriteConfigValue("TerminalPD", "PublicKey", pEncode);
@@ -962,11 +851,7 @@ bool CAccessAuthEntity::GetTerminalPublicKey(BYTE* pBuf, int& nBufLen, string& p
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("sm4 encrypt pri key success.");
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("cryptPrivateKeyLen=%d", cryptPrivateKeyLen);
 
-#ifdef RVC_OS_WIN
-	char* pEncodedCryptPrivateKey = MyBase64::Str2Hex((char*)pCryptPrivateKey, cryptPrivateKeyLen);
-#else
 	char* pEncodedCryptPrivateKey = Str2Hex((char*)pCryptPrivateKey, cryptPrivateKeyLen);
-#endif // RVC_OS_WIN
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("encode pri key success.");
 
 	m_privateKey = pEncodedCryptPrivateKey;
@@ -982,11 +867,7 @@ bool CAccessAuthEntity::GetTerminalPublicKey(BYTE* pBuf, int& nBufLen, string& p
 	delete[] pEncode;
 	delete[] pEncodedCryptPrivateKey;
 
-#ifdef RVC_OS_WIN
-	char* pDecode = MyBase64::Hex2Str(publicKey.GetData(), nBufLen);
-#else
 	char* pDecode = Hex2Str(publicKey.GetData(), nBufLen);
-#endif // RVC_OS_WIN
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("pDecode=[%s],len=%d", pDecode, nBufLen);
 
 	memcpy(pBuf, pDecode, nBufLen);
@@ -1000,7 +881,6 @@ int CAccessAuthEntity::GetPinPadIDAndDeviceID(CSimpleStringA &strPinPadID, CSimp
 {
 	isPinPadMac = false;
 	bPinPadOnline = false;
-	m_bNewSMFWB = false;
 	CSimpleStringA strErrMsg;
 	CSmartPointer<IEntityFunction> spFunction = this->GetFunction();
 
@@ -1079,15 +959,6 @@ int CAccessAuthEntity::GetPinPadIDAndDeviceID(CSimpleStringA &strPinPadID, CSimp
 								if (!strBluetoothID.IsNullOrEmpty())
 									bBluetooth = true;
 							}
-#ifdef RVC_OS_WIN
-							else if (!strnicmp((LPCTSTR)arr2[0], "PM", strlen("PM")))
-							{
-								CSimpleStringA strPM = arr2[1];
-
-								if (!strPM.IsNullOrEmpty() && strPM.Compare("V3.0", true) == 0)
-									m_bNewSMFWB = true;
-							}
-#endif // RVC_OS_WIN
 						}
 					}
 				}
@@ -1370,42 +1241,6 @@ bool CAccessAuthEntity::SendInitMKReqACS(CInitlizerMKReq& initMKReq)
 {
 	LOG_FUNCTION();
 	CSmartPointer<IEntityFunction> pFunc = GetFunction();
-#ifdef RVC_OS_LINUX
-	if (HasPinPad())
-	{
-		CSmartPointer<IConfigInfo> pConfig;
-		DWORD rc = pFunc->OpenConfig(Config_CenterSetting, pConfig);
-		if (rc != Error_Succeed)
-		{
-			LogWarn(Severity_Middle, (ErrorCodeEnum)rc, ERR_INITIALIZER_FILE_ERROR,
-				GetOutPutStr("%s%08X%s%s", "OpenConfig", rc, "File", "Config_CenterSetting").c_str());
-			rc = ERR_INITIALIZER_FILE_ERROR;
-			return rc;
-		}
-
-		CSimpleStringA strSubBankNo, strBranchNo;
-		rc = pConfig->ReadConfigValue("Initializer", "SubBankNo", strSubBankNo);
-		if (rc == Error_Succeed)
-			rc = pConfig->ReadConfigValue("Initializer", "BranchNo", strBranchNo);
-
-		if (rc != Error_Succeed)
-		{
-			LogWarn(Severity_Low, (ErrorCodeEnum)rc, ERR_INITIALIZER_FILE_ERROR,
-				GetOutPutStr("%s%08X%s%s", "ReadConfigValue", rc, "File", "SubBankNo & BranchNo").c_str());
-			rc = ERR_INITIALIZER_FILE_ERROR;
-			return rc;
-		}
-
-		// 1:3des only; 2: sm4 only; 3: both 3des and sm4
-		int nCapability = GetPinPadCapability();
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("pinpad capability: %d", nCapability);
-	}
-	else
-	{
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("has no pinpad, not need init MK");
-	}
-#endif // RVC_OS_LINUX
-
 	CSimpleStringA strPinPadID = "", strDeviceID = "";
 	bool isPinPadMac, bPinPadOnline;
 	int nRet = GetPinPadIDAndDeviceID(strPinPadID, strDeviceID, isPinPadMac, bPinPadOnline);
@@ -1579,13 +1414,6 @@ void CAccessAuthEntity::EndInitMK(DWORD rc, const char *pszErrMsg)
 ErrorCodeEnum CAccessAuthEntity::LoadKeysToPinPadACS(string TMK, string TPK, string EDK, string index, string tpkCheck, string edkCheck)
 {
 	LOG_FUNCTION();
-#ifdef RVC_OS_WIN
-	if (m_bNewSMFWB && m_FSM.GetDevPubKey().GetLength() <= 0)
-	{
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("新蓝牙多合一密钥初始化依赖加密通道建立时的设备公钥,不具备,跳过密钥初始化");
-		return Error_Succeed;
-	}
-#endif // RVC_OS_WIN
 	//加载到密码键盘
 	PinPadService_ClientBase* pPinPad = new PinPadService_ClientBase(this);
 	auto rc = pPinPad->Connect();
@@ -1593,24 +1421,8 @@ ErrorCodeEnum CAccessAuthEntity::LoadKeysToPinPadACS(string TMK, string TPK, str
 	{
 		PinPadService_LoadKeysSM_Req req = {};
 		req.initializeflag = true;
-		if (m_bNewSMFWB)
-		{
-			//oilyang@20220902 to encrypte tmp using device public key
-			req.smflag = 11;
-			auto tmkpairDev = GenerateTmkToDevice();
-			if (tmkpairDev.first.length() <= 0)
-			{
-				//oiltest todo 补充错误信息
-				return Error_Unexpect;
-			}
-			else
-				req.masterkey = tmkpairDev.first.c_str();
-		}
-		else
-		{
-			req.smflag = 1;
-			req.masterkey = TMK.c_str();
-		}
+		req.smflag = 1;
+		req.masterkey = TMK.c_str();
 
 		req.workingkey1 = TPK.c_str();
 		req.workingkey2 = EDK.c_str();
@@ -1713,31 +1525,18 @@ pair<string, string> CAccessAuthEntity::EncryptedByPubKey(CSimpleStringA pubKey,
 	if (pubKey.GetLength() <= 0)
 		return make_pair("", "");
 	PCHAR strRam = new CHAR[512];
-#ifdef RVC_OS_WIN
-	ZeroMemory(strRam, 512);
-#else
 	memset(strRam, 0, 512);
-#endif // RVC_OS_WIN
 	memcpy(strRam, &(m_btRam[0]), 16);
 	HexBuf2StrBuf((PBYTE)m_btRam, &strRam, 16);
 	const int MAX_KEY_SIZE = 256;
 	char random_enc_bypbk[MAX_KEY_SIZE];
-#ifdef RVC_OS_WIN
-	ZeroMemory(random_enc_bypbk, MAX_KEY_SIZE);
-#else
 	memset(random_enc_bypbk, 0, MAX_KEY_SIZE);
-#endif // RVC_OS_WIN
 	//公钥加密随机数
 	int outMsgLen = MAX_KEY_SIZE;
 	PBYTE pxxKey = new BYTE[256];
 	PBYTE pOldPubKey = new BYTE[256];
-#ifdef RVC_OS_WIN
-	ZeroMemory(pxxKey, 256);
-	ZeroMemory(pOldPubKey, 256);
-#else
 	memset(pOldPubKey, 0, 256);
 	memset(pxxKey, 0, 256);
-#endif // RVC_OS_WIN
 
 	int size = StrBuf2HexBuf(pubKey.GetData(), &pOldPubKey);
 	if (bNeed04Head)
@@ -1755,12 +1554,8 @@ pair<string, string> CAccessAuthEntity::EncryptedByPubKey(CSimpleStringA pubKey,
 	}
 
 	PBYTE tmp_enc_bypbk = new BYTE[112];
-#ifdef RVC_OS_WIN
-	ZeroMemory(tmp_enc_bypbk, 112);
-#else
 	memset(tmp_enc_bypbk, 0, 112);
-#endif // RVC_OS_WIN
-	//tmp_enc_bypbk[0] = 0x04;
+	
 	if (bNeed04Head)
 	{
 		memcpy(tmp_enc_bypbk, &(random_enc_bypbk[1]), 112);
@@ -1774,11 +1569,7 @@ pair<string, string> CAccessAuthEntity::EncryptedByPubKey(CSimpleStringA pubKey,
 
 
 	PCHAR pBlock = new CHAR[512];
-#ifdef RVC_OS_WIN
-	ZeroMemory(pBlock, 512);
-#else
 	memset(pBlock, 0, 512);
-#endif // RVC_OS_WIN
 	BYTE tmpRandomEnc[512];
 	memset(tmpRandomEnc, 0, 512);
 	memcpy(tmpRandomEnc, &(tmp_enc_bypbk[0]), outMsgLen - 1);

+ 0 - 1
Module/mod_accessauth/mod_AccessAuth.h

@@ -193,7 +193,6 @@ protected:
 
 private:
 	bool GenerateRandomNum();
-	bool m_bNewSMFWB;
 	BYTE m_btRam[16], m_btTermSysInfoSM3[32];
 	int m_iGetTermSysInfo;//0:初始值,尚未完成获取过程 1:成功 -1:失败
 };