|
|
@@ -22,12 +22,10 @@ using namespace CardSwiper;
|
|
|
using namespace MaintainWatcher;
|
|
|
|
|
|
#include "comm.h"
|
|
|
-//#include "base64.h"
|
|
|
#include <fileutil.h>
|
|
|
-//#include "MyBase64.h"
|
|
|
#define BUF_SIZE 256
|
|
|
#define KEY_SIZE 16
|
|
|
-//CAppModule _Module;
|
|
|
+
|
|
|
|
|
|
void CInitializerSession::Handle_Initialize(SpOnewayCallContext<InitializerService_Initialize_Info>::Pointer ctx)
|
|
|
{
|
|
|
@@ -71,42 +69,17 @@ void CInitializerSession::Handle_InitializeForBlueTooth(SpReqAnsContext<Initiali
|
|
|
|
|
|
void CInitializerEntity::OnStarted()
|
|
|
{
|
|
|
- //auto hRes = _Module.Init(NULL, ModuleBase::GetModuleBase()->GetInstance());
|
|
|
- //ATLASSERT(SUCCEEDED(hRes));
|
|
|
-
|
|
|
- ////检查runinfo/kmc目录是否存在,存在则删除
|
|
|
- //CSimpleStringA strKmcPath;
|
|
|
- //GetFunction()->GetPath("runinfo", strKmcPath);
|
|
|
- //strKmcPath += "\\kmc\\";
|
|
|
-
|
|
|
- //if (ExistsDirA(strKmcPath))
|
|
|
- //{
|
|
|
- // RemoveDirRecursiveA(strKmcPath);
|
|
|
- //}
|
|
|
-
|
|
|
- //检查dbg/kmc目录是否存在,不存在则创建
|
|
|
+
|
|
|
LOG_FUNCTION();
|
|
|
CSimpleStringA strKmclogPath;
|
|
|
GetFunction()->GetPath("Dbg", strKmclogPath);
|
|
|
- strKmclogPath += "\\kmc\\";
|
|
|
+ strKmclogPath += "/kmc/";
|
|
|
|
|
|
if (!ExistsDirA(strKmclogPath))
|
|
|
{
|
|
|
CreateDirA(strKmclogPath, TRUE);
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- CUUID SubLogID1;
|
|
|
- auto pFunc = GetFunction();
|
|
|
- auto rc = pFunc->SubscribeLog(SubLogID1, this, Log_Event, Severity_None, Error_IgnoreAll, -1, "MaintainWatcher");
|
|
|
- if (rc != Error_Succeed)
|
|
|
- {
|
|
|
- //LogError(Severity_Middle, rc, ERROR_INITIALIZER_SUBSCRIBEEVENT, CSimpleStringA::Format("subscribe MaintainWatcher event fail, 0x%x", rc));
|
|
|
- LogWarn(Severity_Middle,Error_Unexpect,ERR_INITIALIZER_SUBSCRIBE,GetOutPutStr("%s%08X%s%s","SubscribeLog",rc,"Subscribe","MaintainWatcher").c_str());
|
|
|
- }
|
|
|
- else
|
|
|
- Dbg("subscribe MaintainWatcher event succeed");
|
|
|
- */
|
|
|
m_bHasCkCode = false;
|
|
|
|
|
|
m_FSM.Init(this);
|
|
|
@@ -117,34 +90,10 @@ void CInitializerEntity::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPoint
|
|
|
m_FSM.PostExitEvent();
|
|
|
|
|
|
CloseGUI();
|
|
|
- //_Module.Term();
|
|
|
|
|
|
pTransactionContext->SendAnswer(Error_Succeed);
|
|
|
}
|
|
|
|
|
|
-//void CInitializerEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
|
|
|
-// const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
|
|
|
-// const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage)
|
|
|
-//{
|
|
|
-// //Dbg("OnLog(entity = %s, syscode = 0x%X, usercode = 0x%X", pszEntityName, dwSysError, dwUserCode);
|
|
|
-//
|
|
|
-// //收到拔出事件,关闭初始化窗口
|
|
|
-// if (dwUserCode == EVENT_UKEY_PULLOUT) // 证书拔出
|
|
|
-// {
|
|
|
-// Dbg("收到EVENT_UKEY_PULLOUT");
|
|
|
-// m_strUserID = "";
|
|
|
-// /*
|
|
|
-// if (m_hGUIWindow != 0)
|
|
|
-// {
|
|
|
-// PostMessage(m_hGUIWindow, WM_CLOSE_DLG, 0, 0);
|
|
|
-// }
|
|
|
-// else
|
|
|
-// {
|
|
|
-// Dbg("密钥初始化窗口句柄为空");
|
|
|
-// }
|
|
|
-// */
|
|
|
-// }
|
|
|
-//}
|
|
|
|
|
|
ErrorCodeEnum CInitializerEntity::StartInitialize(const char *pszUserID, const char *pszPassword)
|
|
|
{
|
|
|
@@ -180,152 +129,16 @@ ErrorCodeEnum CInitializerEntity::StartInitializeNew(const char *pszAuthServer,
|
|
|
// KMC初始化
|
|
|
ErrorCodeEnum CInitializerEntity::InitKMC(int nPinPadCapability)
|
|
|
{
|
|
|
- /*
|
|
|
- CSystemStaticInfo si;
|
|
|
- ErrorCodeEnum rc = GetFunction()->GetSystemStaticInfo(si);
|
|
|
- if (rc != Error_Succeed)
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_SYSTEM_STATIC_INFO,
|
|
|
- GetOutPutStr("%s%08X", "GetSystemStaticInfo", rc).c_str());
|
|
|
- m_strLastErrMsg = "获取配置信息(GetSystemStaticInfo)失败";
|
|
|
- return rc;
|
|
|
- }
|
|
|
-
|
|
|
- int nRet = 0;
|
|
|
-
|
|
|
- if (HasCkCodeFlg())
|
|
|
- {
|
|
|
- CSimpleStringA strKmclogPath;
|
|
|
- GetFunction()->GetPath("Dbg", strKmclogPath);
|
|
|
- strKmclogPath += "\\kmc\\";
|
|
|
-
|
|
|
- //调用新接口,把公钥当成参数传入,日志路径改为dbg/kmc, add by zhangliang 20170225
|
|
|
- //允许分行服务没有国密,生产上没有国密公钥 add by zhangliang 20170306
|
|
|
-
|
|
|
- Dbg("m_cTDESPukey[%s]", m_cTDESPukey);
|
|
|
- Dbg("m_cSM2Pukey[%s]", m_cSM2Pukey);
|
|
|
- Dbg("m_iTDESPukeyLen[%d], m_iSM2Pukeylen[%d]", m_iTDESPukeyLen, m_iSM2Pukeylen);
|
|
|
- if (1 == nPinPadCapability)
|
|
|
- {
|
|
|
- if (0 != m_iTDESPukeyLen)
|
|
|
- {
|
|
|
- nRet = ::RvcInit((const char*)m_cTDESPukey, m_iTDESPukeyLen, NULL, 0, (char*)strKmclogPath.GetData(), DES);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LogError(Severity_Middle, Error_Unexpect, ERROR_INITIALIZER_INITKMC, "nPinPadCapability=1, m_iTDESPukeyLen=0, 请联系分行技术部检查分行服务RVCPubKey.ini!");
|
|
|
- m_strLastErrMsg = "nPinPadCapability=1, m_iTDESPukeyLen=0, 请联系分行技术部检查分行服务RVCPubKey.ini!";
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- else if (2 == nPinPadCapability)
|
|
|
- {
|
|
|
- if (0 != m_iSM2Pukeylen)
|
|
|
- {
|
|
|
- nRet = ::RvcInit(NULL, 0, (const char*)m_cSM2Pukey, m_iSM2Pukeylen, (char*)strKmclogPath.GetData(), SM4);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LogError(Severity_Middle, Error_Unexpect, ERROR_INITIALIZER_INITKMC, "nPinPadCapability=2, m_iSM2Pukeylen=0, 请联系分行技术部检查分行服务RVCSM2PubKey.ini!");
|
|
|
- m_strLastErrMsg = "nPinPadCapability=1, m_iSM2Pukeylen=0, 请联系分行技术部检查分行服务RVCSM2PubKey.ini!";
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- }
|
|
|
- else if (3 == nPinPadCapability)
|
|
|
- {
|
|
|
- if (0 != m_iSM2Pukeylen && 0 != m_iTDESPukeyLen)
|
|
|
- {
|
|
|
- nRet = ::RvcInit((const char*)m_cTDESPukey, m_iTDESPukeyLen, (const char*)m_cSM2Pukey, m_iSM2Pukeylen, (char*)strKmclogPath.GetData(), DES_SM4);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LogError(Severity_Middle, Error_Unexpect, ERROR_INITIALIZER_INITKMC, "nPinPadCapability=3, m_iSM2Pukeylen=0, m_iTDESPukeyLen=0, 请联系分行技术部检查分行服务RVCPubKey.ini和RVCSM2PubKey.ini!");
|
|
|
- m_strLastErrMsg = "nPinPadCapability=3, m_iSM2Pukeylen=0, m_iTDESPukeyLen=0, 请联系分行技术部检查分行服务RVCPubKey.ini和RVCSM2PubKey.ini!";
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LogError(Severity_Middle, Error_Unexpect, ERROR_INITIALIZER_INITKMC, CSimpleStringA::Format("nPinPadCapability[%d] is wrong, must be 1/2/3", nPinPadCapability));
|
|
|
- m_strLastErrMsg = CSimpleStringA::Format("密码键盘支持的密钥类型[%d]错误, 必须是1/2/3,请联系厂商维护人员", nPinPadCapability);
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- CSimpleStringA strPath;
|
|
|
- ErrorCodeEnum rc = GetFunction()->GetPath("RunInfo", strPath);
|
|
|
- LOG_ASSERT(rc == Error_Succeed);
|
|
|
-
|
|
|
- strPath.Append("\\kmc");
|
|
|
- nRet = ::Init((const char*)strPath, strPath.GetLength(), nPinPadCapability);
|
|
|
- }
|
|
|
-
|
|
|
- if (nRet == 1)
|
|
|
- {
|
|
|
- Dbg("DES WK need update, kmc init ret = %d", nRet);
|
|
|
- return Error_Succeed;
|
|
|
- }
|
|
|
- else if (nRet == 2)
|
|
|
- {
|
|
|
- Dbg("DES MK need init, kmc init ret = %d", nRet);
|
|
|
- return Error_Succeed;
|
|
|
- }
|
|
|
- else if (nRet == 11 || nRet == 12)
|
|
|
- {
|
|
|
- Dbg("SM WK need update, kmc init ret = %d", nRet);
|
|
|
- return Error_Succeed;
|
|
|
- }
|
|
|
- else if (nRet == 20 || nRet == 22 || nRet == 21)
|
|
|
- {
|
|
|
- Dbg("SM MK need init, kmc init ret = %d", nRet);
|
|
|
- return Error_Succeed;
|
|
|
- }
|
|
|
- else if (nRet != 0)
|
|
|
- {
|
|
|
- LogError(Severity_Middle, Error_Unexpect, ERROR_INITIALIZER_INITKMC, CSimpleStringA::Format("kmc init fail, GetKMCLastErrMsg[%s], Init return[%d]", (const char*)GetKMCLastErrMsg(), nRet));
|
|
|
- m_strLastErrMsg = CSimpleStringA::Format("KMC初始化失败, 错误信息[%s], 返回值[%d]", (const char*)GetKMCLastErrMsg(), nRet);
|
|
|
- return Error_DevLoadFileFailed;
|
|
|
- }
|
|
|
-
|
|
|
- Dbg("kmc init succeed!");
|
|
|
- */
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
|
|
|
CSimpleStringA CInitializerEntity::GetKMCLastErrMsg()
|
|
|
{
|
|
|
- /*
|
|
|
- char szBuf[256];
|
|
|
- memset(szBuf, 0, 256);
|
|
|
-
|
|
|
- int nBufLen = 256;
|
|
|
-
|
|
|
- if (HasCkCodeFlg())
|
|
|
- {
|
|
|
- RvcGetLastErrorMsg(szBuf, &nBufLen);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- GetLastErrorMsg(szBuf, &nBufLen);
|
|
|
- }
|
|
|
-
|
|
|
- return szBuf;
|
|
|
- */
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
ErrorCodeEnum CInitializerEntity::ReleaseKMC()
|
|
|
{
|
|
|
- /*if (HasCkCodeFlg())
|
|
|
- {
|
|
|
- ::RvcRelease();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ::Release();
|
|
|
- }*/
|
|
|
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
@@ -404,335 +217,6 @@ string CInitializerEntity::ByteArrayToHexStr(BYTE *pBuf, int nBufLen)
|
|
|
// 加载主密钥
|
|
|
DWORD CInitializerEntity::LoadKeysToPinPad(bool bSM)
|
|
|
{
|
|
|
- /*{
|
|
|
- // 取出主密钥
|
|
|
- char keyBuf[64];
|
|
|
- int nKeyBufLen = 64;
|
|
|
- memset(keyBuf, 0, 64);
|
|
|
-
|
|
|
- char chkBuf[16];
|
|
|
- int nChkBufLen = 16;
|
|
|
- memset(chkBuf, 0, 16);
|
|
|
-
|
|
|
- char* retKeyBuf = NULL;
|
|
|
-
|
|
|
- if (HasCkCodeFlg())
|
|
|
- {
|
|
|
- if (bSM)
|
|
|
- {
|
|
|
- retKeyBuf = ::RvcGetKey(m_pkeys, TMK, keyBuf);
|
|
|
- if (NULL == retKeyBuf)
|
|
|
- {
|
|
|
-
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_RVC_GET_KEY,
|
|
|
- GetOutPutStr("%s%s%s%s", "RvcGetKey", retKeyBuf, "strErrMsg", (const char*)GetKMCLastErrMsg()).c_str());
|
|
|
- return ERR_INITIALIZER_RVC_GET_KEY;
|
|
|
- }
|
|
|
-
|
|
|
- PinPadService_LoadKeysSM_Req req = {};
|
|
|
- req.initializeflag = true;
|
|
|
- req.smflag = 1;
|
|
|
- CSimpleStringA tempMasterkey(m_cSM2TMK, 32);
|
|
|
- req.masterkey = tempMasterkey;
|
|
|
- Dbg("req.masterkey[%s]", req.masterkey);
|
|
|
-
|
|
|
- // 读取工作密钥TPK
|
|
|
- memset(keyBuf, 0, 64);
|
|
|
- retKeyBuf = RvcGetKey(m_pkeys, TPK, keyBuf);
|
|
|
- if (NULL == retKeyBuf)
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_RVC_GET_KEY,
|
|
|
- GetOutPutStr("%s%s%s%s", "RvcGetKey", retKeyBuf, "strErrMsg", (const char*)GetKMCLastErrMsg()).c_str());
|
|
|
- return ERR_INITIALIZER_RVC_GET_KEY;
|
|
|
- }
|
|
|
-
|
|
|
- CSimpleStringA tempWorkingkey1(keyBuf, 32);
|
|
|
- req.workingkey1 = tempWorkingkey1;
|
|
|
- Dbg("req.workingkey1[%s]", req.workingkey1);
|
|
|
-
|
|
|
- // 读取加密密钥EDK
|
|
|
- memset(keyBuf, 0, 64);
|
|
|
- retKeyBuf = RvcGetKey(m_pkeys, EDK, keyBuf);
|
|
|
- if (NULL == retKeyBuf)
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_RVC_GET_KEY,
|
|
|
- GetOutPutStr("%s%s%s%s", "RvcGetKey", retKeyBuf, "strErrMsg", (const char*)GetKMCLastErrMsg()).c_str());
|
|
|
- return ERR_INITIALIZER_RVC_GET_KEY;
|
|
|
- }
|
|
|
-
|
|
|
- CSimpleStringA tempWorkingkey2(keyBuf, 32);
|
|
|
- req.workingkey2 = tempWorkingkey2;
|
|
|
- Dbg("req.workingkey2[%s]", req.workingkey2);
|
|
|
-
|
|
|
- Dbg("load sm key to pinpad...");
|
|
|
- PinPadService_ClientBase* pPinPad = new PinPadService_ClientBase(this);
|
|
|
- DWORD rc = pPinPad->Connect();
|
|
|
- if (rc == Error_Succeed)
|
|
|
- {
|
|
|
- PinPadService_LoadKeysSM_Ans ans = {};
|
|
|
- rc = pPinPad->LoadKeysSM(req, ans, 30000);
|
|
|
- if (rc == Error_Succeed)
|
|
|
- Dbg("load sm key to pinpad succ");
|
|
|
- else
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_LOAD_KEYS_TO_PINPAD,
|
|
|
- GetOutPutStr("%s%08x%s%s", "LoadKeys", rc, "strErrMsg", "加载SM密钥到PinPad失败").c_str());
|
|
|
- rc = ERR_INITIALIZER_LOAD_KEYS_TO_PINPAD;
|
|
|
- }
|
|
|
-
|
|
|
- pPinPad->GetFunction()->CloseSession();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_CONNECT_PINPAD,
|
|
|
- GetOutPutStr("%s%08x%s%s", "Connect", rc, "strErrMsg", "连接PinPad实体失败").c_str());
|
|
|
- rc = ERR_INITIALIZER_CONNECT_PINPAD;
|
|
|
- }
|
|
|
- pPinPad->SafeDelete();
|
|
|
-
|
|
|
- return rc;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- retKeyBuf = ::RvcGetKey(m_pkeys, TMK, keyBuf);
|
|
|
- if (NULL == retKeyBuf)
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_RVC_GET_KEY,
|
|
|
- GetOutPutStr("%s%s%s%s", "RvcGetKey", retKeyBuf, "strErrMsg", (const char*)GetKMCLastErrMsg()).c_str());
|
|
|
- return ERR_INITIALIZER_RVC_GET_KEY;
|
|
|
- }
|
|
|
-
|
|
|
- PinPadService_LoadKeys_Req req = {};
|
|
|
- req.initializeflag = true;
|
|
|
- CSimpleStringA temp(m_cTDESTMK, 32);
|
|
|
- req.masterkey = temp;
|
|
|
- Dbg("req.masterkey[%s]", req.masterkey);
|
|
|
-
|
|
|
- // 读取工作密钥TPK
|
|
|
- memset(keyBuf, 0, 64);
|
|
|
- retKeyBuf = RvcGetKey(m_pkeys, TPK, keyBuf);
|
|
|
- if (NULL == retKeyBuf)
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_RVC_GET_KEY,
|
|
|
- GetOutPutStr("%s%s%s%s", "RvcGetKey", retKeyBuf, "strErrMsg", (const char*)GetKMCLastErrMsg()).c_str());
|
|
|
- return ERR_INITIALIZER_RVC_GET_KEY;
|
|
|
- }
|
|
|
-
|
|
|
- CSimpleStringA temp1(keyBuf, 32);
|
|
|
- req.workingkey1 = temp1;
|
|
|
- Dbg("req.workingkey1[%s]", req.workingkey1);
|
|
|
-
|
|
|
- // 读取加密密钥EDK
|
|
|
- memset(keyBuf, 0, 64);
|
|
|
- retKeyBuf = RvcGetKey(m_pkeys, EDK, keyBuf);
|
|
|
- if (NULL == retKeyBuf)
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_RVC_GET_KEY,
|
|
|
- GetOutPutStr("%s%s%s%s", "RvcGetKey", retKeyBuf, "strErrMsg", (const char*)GetKMCLastErrMsg()).c_str());
|
|
|
- return ERR_INITIALIZER_RVC_GET_KEY;
|
|
|
- }
|
|
|
-
|
|
|
- CSimpleStringA temp2(keyBuf, 32);
|
|
|
- req.workingkey2 = temp2;
|
|
|
- Dbg("req.workingkey2[%s]", req.workingkey2);
|
|
|
-
|
|
|
- Dbg("load des key to pinpad...");
|
|
|
- PinPadService_ClientBase* pPinPad = new PinPadService_ClientBase(this);
|
|
|
- DWORD rc = pPinPad->Connect();
|
|
|
- if (rc == Error_Succeed)
|
|
|
- {
|
|
|
- PinPadService_LoadKeys_Ans ans = {};
|
|
|
- rc = pPinPad->LoadKeys(req, ans, 30000);
|
|
|
- if (rc == Error_Succeed)
|
|
|
- Dbg("load des key to pinpad succ");
|
|
|
- else
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_LOAD_KEYS_TO_PINPAD,
|
|
|
- GetOutPutStr("%s%08x%s%s", "LoadKeys", rc, "strErrMsg", "加载des密钥到PinPad失败").c_str());
|
|
|
- rc = ERR_INITIALIZER_LOAD_KEYS_TO_PINPAD;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- pPinPad->GetFunction()->CloseSession();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_CONNECT_PINPAD,
|
|
|
- GetOutPutStr("%s%08x%s%s", "Connect", rc, "strErrMsg", "连接PinPad实体失败").c_str());
|
|
|
- rc = ERR_INITIALIZER_CONNECT_PINPAD;
|
|
|
- }
|
|
|
- pPinPad->SafeDelete();
|
|
|
-
|
|
|
- return rc;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (bSM)
|
|
|
- {
|
|
|
- int nRet = ::GetKey(keyBuf, &nKeyBufLen, chkBuf, &nChkBufLen, csTMK);
|
|
|
- if (nRet != 0)
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_KEY,
|
|
|
- GetOutPutStr("%s%s%s%s", "GetKey", retKeyBuf, "strErrMsg", (const char*)GetKMCLastErrMsg()).c_str());
|
|
|
- return ERR_INITIALIZER_GET_KEY;
|
|
|
- }
|
|
|
-
|
|
|
- Dbg("get SM TMK succ, check: [%s]", ByteArrayToHexStr((BYTE*)chkBuf, nChkBufLen).c_str());
|
|
|
-
|
|
|
- PinPadService_LoadKeysSM_Req req = {};
|
|
|
- req.initializeflag = true;
|
|
|
- req.smflag = 1;
|
|
|
- req.masterkey = ByteArrayToHexStr((BYTE*)keyBuf, nKeyBufLen).c_str();
|
|
|
-
|
|
|
- // 读取工作密钥TPK
|
|
|
- nKeyBufLen = 64;
|
|
|
- memset(keyBuf, 0, 64);
|
|
|
-
|
|
|
- nChkBufLen = 16;
|
|
|
- memset(chkBuf, 0, 16);
|
|
|
-
|
|
|
- nRet = GetKey(keyBuf, &nKeyBufLen, chkBuf, &nChkBufLen, csTPK);
|
|
|
- if (nRet != 0)
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_KEY,
|
|
|
- GetOutPutStr("%s%s%s%s", "GetKey", retKeyBuf, "strErrMsg", (const char*)GetKMCLastErrMsg()).c_str());
|
|
|
- return ERR_INITIALIZER_GET_KEY;
|
|
|
- }
|
|
|
-
|
|
|
- Dbg("get SM TPK succ, check: [%s]", ByteArrayToHexStr((BYTE*)chkBuf, nChkBufLen).c_str());
|
|
|
- req.workingkey1 = ByteArrayToHexStr((BYTE*)keyBuf, nKeyBufLen).c_str();
|
|
|
-
|
|
|
- // 读取加密密钥EDK
|
|
|
- nKeyBufLen = 64;
|
|
|
- memset(keyBuf, 0, 64);
|
|
|
-
|
|
|
- nChkBufLen = 16;
|
|
|
- memset(chkBuf, 0, 16);
|
|
|
-
|
|
|
- nRet = GetKey(keyBuf, &nKeyBufLen, chkBuf, &nChkBufLen, csEDK);
|
|
|
- if (nRet != 0)
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_KEY,
|
|
|
- GetOutPutStr("%s%s%s%s", "GetKey", retKeyBuf, "strErrMsg", (const char*)GetKMCLastErrMsg()).c_str());
|
|
|
- return ERR_INITIALIZER_GET_KEY;
|
|
|
- }
|
|
|
-
|
|
|
- Dbg("get SM EDK succ, check: [%s]", ByteArrayToHexStr((BYTE*)chkBuf, nChkBufLen).c_str());
|
|
|
- req.workingkey2 = ByteArrayToHexStr((BYTE*)keyBuf, nKeyBufLen).c_str();
|
|
|
-
|
|
|
- Dbg("load sm key to pinpad...");
|
|
|
- PinPadService_ClientBase* pPinPad = new PinPadService_ClientBase(this);
|
|
|
- DWORD rc = pPinPad->Connect();
|
|
|
- if (rc == Error_Succeed)
|
|
|
- {
|
|
|
- PinPadService_LoadKeysSM_Ans ans = {};
|
|
|
- rc = pPinPad->LoadKeysSM(req, ans, 30000);
|
|
|
- if (rc == Error_Succeed)
|
|
|
- Dbg("load sm key to pinpad succ");
|
|
|
- else
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_LOAD_KEYS_TO_PINPAD,
|
|
|
- GetOutPutStr("%s%08x%s%s", "LoadKeys", rc, "strErrMsg", "加载des密钥到PinPad失败").c_str());
|
|
|
- rc = ERR_INITIALIZER_LOAD_KEYS_TO_PINPAD;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- pPinPad->GetFunction()->CloseSession();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_CONNECT_PINPAD,
|
|
|
- GetOutPutStr("%s%08x%s%s", "Connect", rc, "strErrMsg", "连接PinPad实体失败").c_str());
|
|
|
- rc = ERR_INITIALIZER_CONNECT_PINPAD;
|
|
|
- }
|
|
|
- pPinPad->SafeDelete();
|
|
|
-
|
|
|
- return rc;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- int nRet = ::GetKey(keyBuf, &nKeyBufLen, chkBuf, &nChkBufLen, cTMK);
|
|
|
- if (nRet != 0)
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_KEY,
|
|
|
- GetOutPutStr("%s%s%s%s", "GetKey", retKeyBuf, "strErrMsg", (const char*)GetKMCLastErrMsg()).c_str());
|
|
|
- return ERR_INITIALIZER_GET_KEY;
|
|
|
- }
|
|
|
-
|
|
|
- Dbg("get des TMK succ, check: [%s]", ByteArrayToHexStr((BYTE*)chkBuf, nChkBufLen).c_str());
|
|
|
-
|
|
|
- PinPadService_LoadKeys_Req req = {};
|
|
|
- req.initializeflag = true;
|
|
|
- req.masterkey = ByteArrayToHexStr((BYTE*)keyBuf, nKeyBufLen).c_str();
|
|
|
-
|
|
|
- // 读取工作密钥TPK
|
|
|
- nKeyBufLen = 64;
|
|
|
- memset(keyBuf, 0, 64);
|
|
|
-
|
|
|
- nChkBufLen = 16;
|
|
|
- memset(chkBuf, 0, 16);
|
|
|
-
|
|
|
- nRet = GetKey(keyBuf, &nKeyBufLen, chkBuf, &nChkBufLen, cTPK);
|
|
|
- if (nRet != 0)
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_KEY,
|
|
|
- GetOutPutStr("%s%s%s%s", "GetKey", retKeyBuf, "strErrMsg", (const char*)GetKMCLastErrMsg()).c_str());
|
|
|
- return ERR_INITIALIZER_GET_KEY;
|
|
|
- }
|
|
|
-
|
|
|
- Dbg("get des TPK succ, check: [%s]", ByteArrayToHexStr((BYTE*)chkBuf, nChkBufLen).c_str());
|
|
|
- req.workingkey1 = ByteArrayToHexStr((BYTE*)keyBuf, nKeyBufLen).c_str();
|
|
|
-
|
|
|
- // 读取加密密钥EDK
|
|
|
- nKeyBufLen = 64;
|
|
|
- memset(keyBuf, 0, 64);
|
|
|
-
|
|
|
- nChkBufLen = 16;
|
|
|
- memset(chkBuf, 0, 16);
|
|
|
-
|
|
|
- nRet = GetKey(keyBuf, &nKeyBufLen, chkBuf, &nChkBufLen, cEDK);
|
|
|
- if (nRet != 0)
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_KEY,
|
|
|
- GetOutPutStr("%s%s%s%s", "GetKey", retKeyBuf, "strErrMsg", (const char*)GetKMCLastErrMsg()).c_str());
|
|
|
- return ERR_INITIALIZER_GET_KEY;
|
|
|
- }
|
|
|
-
|
|
|
- Dbg("get des EDK succ, check: [%s]", ByteArrayToHexStr((BYTE*)chkBuf, nChkBufLen).c_str());
|
|
|
- req.workingkey2 = ByteArrayToHexStr((BYTE*)keyBuf, nKeyBufLen).c_str();
|
|
|
-
|
|
|
- Dbg("load des key to pinpad...");
|
|
|
- PinPadService_ClientBase* pPinPad = new PinPadService_ClientBase(this);
|
|
|
- DWORD rc = pPinPad->Connect();
|
|
|
- if (rc == Error_Succeed)
|
|
|
- {
|
|
|
- PinPadService_LoadKeys_Ans ans = {};
|
|
|
- rc = pPinPad->LoadKeys(req, ans, 30000);
|
|
|
- if (rc == Error_Succeed)
|
|
|
- Dbg("load des key to pinpad succ");
|
|
|
- else
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_LOAD_KEYS_TO_PINPAD,
|
|
|
- GetOutPutStr("%s%08x%s%s", "LoadKeys", rc, "strErrMsg", "加载des密钥到PinPad失败").c_str());
|
|
|
- rc = ERR_INITIALIZER_LOAD_KEYS_TO_PINPAD;
|
|
|
- }
|
|
|
-
|
|
|
- pPinPad->GetFunction()->CloseSession();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_CONNECT_PINPAD,
|
|
|
- GetOutPutStr("%s%08x%s%s", "Connect", rc, "strErrMsg", "连接PinPad实体失败").c_str());
|
|
|
- rc = ERR_INITIALIZER_CONNECT_PINPAD;
|
|
|
- }
|
|
|
- pPinPad->SafeDelete();
|
|
|
-
|
|
|
- return rc;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- */
|
|
|
LOG_FUNCTION();
|
|
|
Dbg("load sm key to pinpad...");
|
|
|
|
|
|
@@ -755,7 +239,6 @@ DWORD CInitializerEntity::LoadKeysToPinPad(bool bSM)
|
|
|
LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_KMC_KEY_NULL,
|
|
|
GetOutPutStr("%s%s", "m_bGetKMCKey", "False").c_str());
|
|
|
rc = ERR_INITIALIZER_GET_KMC_KEY_NULL;
|
|
|
- //pPinPad->SafeDelete();
|
|
|
return rc;
|
|
|
}
|
|
|
PinPadService_LoadKeysSM_Ans ans = {};
|
|
|
@@ -777,89 +260,19 @@ DWORD CInitializerEntity::LoadKeysToPinPad(bool bSM)
|
|
|
LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_CONNECT_PINPAD,
|
|
|
GetOutPutStr("%s%08x%s%s", "Connect", rc, "strErrMsg", "连接PinPad实体失败").c_str());
|
|
|
rc = ERR_INITIALIZER_CONNECT_PINPAD;
|
|
|
+ pPinPad->SafeDelete();
|
|
|
}
|
|
|
-
|
|
|
- //pPinPad->SafeDelete();
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
ErrorCodeEnum CInitializerEntity::CreateInitMKData(CBlob &blob, bool bSM)
|
|
|
{
|
|
|
- /*
|
|
|
- if (blob.m_iLength < 600)
|
|
|
- blob.Alloc(600);
|
|
|
-
|
|
|
- char TempKey[64] = {0};
|
|
|
- memset(TempKey, 0, 64);
|
|
|
- int TempKeyLen = 64;
|
|
|
-
|
|
|
- int nRet = 0;
|
|
|
-
|
|
|
- if (HasCkCodeFlg())
|
|
|
- {
|
|
|
- if (bSM)
|
|
|
- nRet = RvcCreateInitTMKReq(SM4, (char*)blob.m_pData, &blob.m_iLength);
|
|
|
- else
|
|
|
- nRet = RvcCreateInitTMKReq(DES, (char*)blob.m_pData, &blob.m_iLength);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (bSM)
|
|
|
- nRet = CreateInitSMTMKReq((char*)blob.m_pData, &blob.m_iLength);
|
|
|
- else
|
|
|
- nRet = CreateInitTMKReq((char*)blob.m_pData, &blob.m_iLength);
|
|
|
- }
|
|
|
-
|
|
|
- if (nRet != 0)
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_CREATE_INIT_MK,
|
|
|
- GetOutPutStr("%s%d","CreateInitTMK",nRet).c_str());
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- */
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
|
|
|
// 解析返回DES主密钥
|
|
|
ErrorCodeEnum CInitializerEntity::ParseInitMKResult(CBlob &blob, bool bSM)
|
|
|
{
|
|
|
- /*
|
|
|
- // 调用KMC解析返回
|
|
|
- int nRet = 0;
|
|
|
-
|
|
|
- //Dbg("parse %s TMK data: [%s], len: %d", bSM ? "SM" : "DES", blob.m_pData, blob.m_iLength);
|
|
|
-
|
|
|
- int nKeyBufLen = 64;
|
|
|
- memset(m_cTDESTMK, 0, 64);
|
|
|
- memset(m_cSM2TMK, 0, 64);
|
|
|
-
|
|
|
- if (HasCkCodeFlg())
|
|
|
- {
|
|
|
- if (bSM)
|
|
|
- {
|
|
|
- nRet = ::RvcParseTMKRes((char*)blob.m_pData, blob.m_iLength, SM4, m_cSM2TMK, &nKeyBufLen, &m_pkeys);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- nRet = ::RvcParseTMKRes((char*)blob.m_pData, blob.m_iLength, DES, m_cTDESTMK, &nKeyBufLen, &m_pkeys);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (bSM)
|
|
|
- nRet = ::ParseSMTMKRes((char*)blob.m_pData, blob.m_iLength);
|
|
|
- else
|
|
|
- nRet = ::ParseTMKRes((char*)blob.m_pData, blob.m_iLength);
|
|
|
- }
|
|
|
-
|
|
|
- if (nRet != 0)
|
|
|
- {
|
|
|
- LogError(Severity_Low, Error_Unexpect, ERROR_INITIALIZER_PARSEINITMKRES, (const char*)CSimpleStringA::Format("parse %s TMK return data fail, GetKMCLastErrMsg[%s], return [%d]",
|
|
|
- bSM ? "SM" : "DES",
|
|
|
- (const char*)GetKMCLastErrMsg(), nRet));
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- */
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
|
|
|
@@ -887,8 +300,6 @@ bool CInitializerEntity::SetAuthAccessAddr(const char *pszAddr, int nPort)
|
|
|
// 保存准入服务地址
|
|
|
auto strAuthAccessAddr = CSimpleStringA::Format("%s %d", pszAddr, nPort);
|
|
|
bool bRet = true;
|
|
|
- //bRet= !!WritePrivateProfileString("Initializer", "Server", strAuthAccessAddr, strPath);
|
|
|
- //bRet = bRet && WritePrivateProfileString("AccessAuthorization", "Server", strAuthAccessAddr, strPath);
|
|
|
if(!inifile_format_write(strPath.GetData(), "AccessAuthorization", "Server","%s", strAuthAccessAddr.GetData())) bRet = false;
|
|
|
if (!inifile_format_write(strPath.GetData(), "Initializer", "Server", "%s", strAuthAccessAddr.GetData())) bRet = false;
|
|
|
return bRet;
|
|
|
@@ -1011,7 +422,7 @@ DWORD CInitializerEntity::InitCardSwiper()
|
|
|
{
|
|
|
LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_CONNECT_CARDSWIPER, GetOutPutStr("%s%s", "Connect", "False").c_str());
|
|
|
m_strLastErrMsg = "连接CardSwiper实体失败";
|
|
|
- //pCardSwiperClient->SafeDelete();
|
|
|
+ pCardSwiperClient->SafeDelete();
|
|
|
pCardSwiperClient = NULL;
|
|
|
return Error_InvalidState;
|
|
|
}
|
|
|
@@ -1035,8 +446,6 @@ DWORD CInitializerEntity::InitCardSwiper()
|
|
|
}
|
|
|
|
|
|
pCardSwiperClient->GetFunction()->CloseSession();
|
|
|
- //pCardSwiperClient->SafeDelete();
|
|
|
- pCardSwiperClient = NULL;
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
@@ -1057,7 +466,7 @@ ErrorCodeEnum CInitializerEntity::DownloadCfg(const char *pszSettingServer, int
|
|
|
if (pCenterSettingClient->Connect() != Error_Succeed)
|
|
|
{
|
|
|
m_strLastErrMsg = "连接集中配置实体失败";
|
|
|
- //pCenterSettingClient->SafeDelete();
|
|
|
+ pCenterSettingClient->SafeDelete();
|
|
|
pCenterSettingClient = NULL;
|
|
|
return Error_InvalidState;
|
|
|
}
|
|
|
@@ -1072,8 +481,6 @@ ErrorCodeEnum CInitializerEntity::DownloadCfg(const char *pszSettingServer, int
|
|
|
m_strLastErrMsg = "集中配置实体Download接口调用失败";
|
|
|
|
|
|
pCenterSettingClient->GetFunction()->CloseSession();
|
|
|
- //pCenterSettingClient->SafeDelete();
|
|
|
- pCenterSettingClient = NULL;
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
@@ -1145,6 +552,8 @@ void CInitializerEntity::BeginLogin(const char *pszAuthServer, int nAuthPort, co
|
|
|
//如果连接电子钥匙失败,以传入的参数进行密钥初始化
|
|
|
m_strUserID = pszUserID;
|
|
|
m_strPassword = pszPassword;
|
|
|
+ pClient->SafeDelete();
|
|
|
+ pClient = NULL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -1174,9 +583,6 @@ void CInitializerEntity::BeginLogin(const char *pszAuthServer, int nAuthPort, co
|
|
|
(const char*)m_strAuthorizer,
|
|
|
(const char*)m_strAuthTime);
|
|
|
}
|
|
|
-
|
|
|
- //pClient->SafeDelete();
|
|
|
- pClient = NULL;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1872,6 +1278,8 @@ bool CInitializerEntity::HasPinPad()
|
|
|
m_ctx_blue->Answer(Error_Succeed);
|
|
|
}
|
|
|
Dbg("connect PinPad fail, assume no pinpad");
|
|
|
+ pPinPadClient->SafeDelete();
|
|
|
+ pPinPadClient = NULL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -1897,9 +1305,6 @@ bool CInitializerEntity::HasPinPad()
|
|
|
|
|
|
pPinPadClient->GetFunction()->CloseSession();
|
|
|
}
|
|
|
-
|
|
|
- //pPinPadClient->SafeDelete();
|
|
|
- pPinPadClient = NULL;
|
|
|
return bPinPadExist;
|
|
|
}
|
|
|
else
|
|
|
@@ -1927,6 +1332,8 @@ int CInitializerEntity::GetPinPadCapability()
|
|
|
m_ctx_blue->Ans.ErrMsg = "连接PinPad实体失败";
|
|
|
m_ctx_blue->Answer(Error_Succeed);
|
|
|
}
|
|
|
+ pPinPadClient->SafeDelete();
|
|
|
+ pPinPadClient = NULL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -1950,9 +1357,6 @@ int CInitializerEntity::GetPinPadCapability()
|
|
|
pPinPadClient->GetFunction()->CloseSession();
|
|
|
}
|
|
|
|
|
|
- //pPinPadClient->SafeDelete();
|
|
|
- pPinPadClient = NULL;
|
|
|
-
|
|
|
if (HasCkCodeFlg())
|
|
|
{
|
|
|
// 检查公钥缓存是否存在
|
|
|
@@ -2539,11 +1943,10 @@ int CInitializerEntity::GetPinPadIDAndDeviceID(CSimpleStringA &strPinPadID, CSim
|
|
|
m_ctx_blue->Ans.ErrMsg = "连接pinpad实体失败";
|
|
|
m_ctx_blue->Answer(Error_Succeed);
|
|
|
}
|
|
|
+ pPinPadClient->SafeDelete();
|
|
|
+ pPinPadClient = NULL;
|
|
|
}
|
|
|
|
|
|
- //pPinPadClient->SafeDelete();
|
|
|
- pPinPadClient = NULL;
|
|
|
-
|
|
|
if (bPinPadID)
|
|
|
{
|
|
|
if (bVendor)
|
|
|
@@ -2666,10 +2069,10 @@ bool CInitializerEntity::HasCkCodeFlg()
|
|
|
m_ctx_blue->Ans.ErrMsg = "连接PinPad实体失败";
|
|
|
m_ctx_blue->Answer(Error_Succeed);
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- //pPinPadClient->SafeDelete();
|
|
|
- pPinPadClient = NULL;
|
|
|
+ pPinPadClient->SafeDelete();
|
|
|
+ pPinPadClient = NULL;
|
|
|
+ }
|
|
|
|
|
|
return m_bHasCkCode? true:false;
|
|
|
}
|