1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867 |
- #include "stdafx2.h"
- #ifdef RVC_OS_WIN
- #include "WMIDeviceQuery.h"
- #endif // RVC_OS_WIN
- #include "mod_Initializer.h"
- #include "DeviceBaseClass.h"
- #include "RVCComm.h"
- #include "EventCode.h"
- #include "iniutil.h"
- #include "PinPad_client_g.h"
- #include "comm.h"
- #include "fileutil.h"
- #include "SpUtility.h"
- #include "CommEntityUtil.hpp"
- using namespace PinPad;
- #include "CenterSetting_client_g.h"
- using namespace CenterSetting;
- #include "CardSwiper_client_g.h"
- using namespace CardSwiper;
- #include "MaintainWatcher_client_g.h"
- using namespace MaintainWatcher;
- #define BUF_SIZE 256
- #define KEY_SIZE 16
- void CInitializerSession::Handle_Initialize(SpOnewayCallContext<InitializerService_Initialize_Info>::Pointer ctx)
- {
- m_pEntity->StartInitialize(ctx->Info.strUserID, ctx->Info.strPassword);
- }
- void CInitializerSession::Handle_InitializeNew(SpReqAnsContext<InitializerService_InitializeNew_Req, InitializerService_InitializeNew_Ans>::Pointer ctx)
- {
- m_pEntity->m_ctx = ctx;
- m_pEntity->m_type = Normal;
- ErrorCodeEnum er = m_pEntity->StartInitializeNew(ctx->Req.strAuthServer.GetData(), ctx->Req.nAuthPort, ctx->Req.strUserID.GetData(), ctx->Req.strPassword.GetData());
-
- ctx->Ans.Errcode = m_pEntity->m_eErrNum;
- ctx->Ans.ErrMsg = m_pEntity->m_strLastErrMsg;
- }
- void CInitializerSession::Handle_GetAuthServerInfo(SpReqAnsContext<InitializerService_GetAuthServerInfo_Req, InitializerService_GetAuthServerInfo_Ans>::Pointer ctx)
- {
- if (m_pEntity->GetAuthAccessAddr(ctx->Ans.strIP, ctx->Ans.nPort))
- {
- ctx->Answer(Error_Succeed);
- }
- else
- {
- ctx->Answer(Error_Unexpect);
- }
- }
- void CInitializerSession::Handle_InitializeForBlueTooth(SpReqAnsContext<InitializerService_InitializeForBlueTooth_Req, InitializerService_InitializeForBlueTooth_Ans>::Pointer ctx) {
- LOG_FUNCTION();
- m_pEntity->m_ctx_blue = ctx;
- m_pEntity->m_type = (CardSwiperConnectType)ctx->Req.type;
-
- ErrorCodeEnum er = m_pEntity->StartInitializeNew(ctx->Req.strAuthServer.GetData(), ctx->Req.nAuthPort, ctx->Req.strUserID.GetData(), ctx->Req.strPassword.GetData());
- ctx->Ans.Errcode = m_pEntity->m_eErrNum;
- ctx->Ans.ErrMsg = m_pEntity->m_strLastErrMsg;
- }
- void CInitializerEntity::OnStarted()
- {
- LOG_FUNCTION();
- #ifdef RVC_OS_WIN
- CSimpleStringA strKmclogPath;
- GetFunction()->GetPath("Dbg", strKmclogPath);
- strKmclogPath += "\\kmc\\";
- if (!ExistsDirA(strKmclogPath))
- {
- CreateDirA(strKmclogPath, TRUE);
- }
- #endif // RVC_OS_WIN
- m_bHasCkCode = false;
- m_FSM.Init(this);
- }
- void CInitializerEntity::OnPaused()
- {
- CSimpleStringA strAuthServer;
- int nAuthPort = 0;
- if (GetAuthAccessAddr(strAuthServer, nAuthPort)) {
- Dbg("begin initialize on clicked PAUSE btn.");
- StartInitializeNew(strAuthServer, nAuthPort, "admin", "88888888");
- }
- else {
- Dbg("get IP or port failed.");
- }
- }
- void CInitializerEntity::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- m_FSM.PostExitEvent();
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- ErrorCodeEnum CInitializerEntity::StartInitialize(const char *pszUserID, const char *pszPassword)
- {
- if (!m_FSM.IsInitializeSucc())
- {
- FSMEvent *pEvent = new FSMEvent(CInitializerFSM::Event_ShowGUI);
- m_FSM.PostEventFIFO(pEvent);
- }
- else
- {
- Dbg("already init succeed");
- }
-
- return Error_Succeed;
- }
- ErrorCodeEnum CInitializerEntity::StartInitializeNew(const char *pszAuthServer, int nAuthPort, const char *pszUserID, const char *pszPassword)
- {
- LOG_FUNCTION();
- Dbg("pszUserID=%s at StartInitializeNew", pszUserID);
- Dbg("pszPassword len=%d at StartInitializeNew", strlen(pszPassword));
- m_strAuthServer = pszAuthServer;
- m_nAuthPort = nAuthPort;
- m_strUserID = pszUserID;
- m_strPassword = pszPassword;
- FSMEvent* pEvent = new FSMEvent(CInitializerFSM::Event_ShowNewGUI);
- m_FSM.PostEventFIFO(pEvent);
-
- return Error_Succeed;
- }
- // KMC初始化
- ErrorCodeEnum CInitializerEntity::InitKMC(int nPinPadCapability)
- {
- return Error_Succeed;
- }
- CSimpleStringA CInitializerEntity::GetKMCLastErrMsg()
- {
- return "";
- }
- ErrorCodeEnum CInitializerEntity::ReleaseKMC()
- {
- return Error_Succeed;
- }
- ErrorCodeEnum CInitializerEntity::CreateInitMKData(CBlob& blob, bool bSM)
- {
- return Error_Succeed;
- }
- // 解析返回DES主密钥
- ErrorCodeEnum CInitializerEntity::ParseInitMKResult(CBlob& blob, bool bSM)
- {
- return Error_Succeed;
- }
-
- // 将16进制字符串转成BYTE数据
- bool CInitializerEntity::HexStrToByteArray(const char* pHex, BYTE *pBuf, int *pBufLen)
- {
- int nHexLen = strlen(pHex);
- if (nHexLen %2 != 0)
- {
- printf("error hex string length\n");
- return false;
- }
- if (nHexLen /2 > *pBufLen)
- {
- printf("not enough buf length\n");
- return false;
- }
- for(int i=0; i<nHexLen; i++)
- {
- BYTE b =0;
- char ch1 = pHex[i];
- if (ch1 >='0' && ch1<='9')
- b = ch1 - '0';
- else if (ch1 >='A' && ch1 <='F')
- b = ch1 - 'A' + 10;
- else
- {
- printf("invalid hex string\n");
- return false;
- }
- if (i %2 ==0)
- {
- pBuf[i/2] = b;
- }
- else
- {
- pBuf[i/2] = pBuf[i/2] << 4 | b;
- }
- }
- *pBufLen = nHexLen / 2;
- return true;
- }
- string CInitializerEntity::ByteArrayToHexStr(BYTE *pBuf, int nBufLen)
- {
- char szBuf[1024];
- memset(szBuf, 0, sizeof(szBuf));
- for(int i=0; i<nBufLen; i++)
- {
- BYTE b1 = (pBuf[i] >> 4) & 0x0F;
- BYTE b2 = pBuf[i] & 0x0F;
-
- if (b1 <= 9)
- szBuf[i*2] = '0' + b1;
- else
- szBuf[i*2] = 'A' + b1 - 10;
- if (b2 <= 9)
- szBuf[i*2+1] = '0' + b2;
- else
- szBuf[i*2+1] = 'A' + b2 - 10;
- }
- return szBuf;
- }
- // 加载主密钥
- DWORD CInitializerEntity::LoadKeysToPinPad(bool bSM)
- {
- LOG_FUNCTION();
- Dbg("load sm key to pinpad...");
-
- PinPadService_ClientBase* pPinPad = new PinPadService_ClientBase(this);
- DWORD rc = pPinPad->Connect();
- if (rc == Error_Succeed)
- {
- PinPadService_LoadKeysSM_Req req = {};
- req.initializeflag = true;
- req.smflag = 1;
- if (m_bGetKMCKey) {
- Dbg("使用云接口获取的KMC密钥");
- req.masterkey = m_TMK.c_str();
- req.workingkey1 = m_TPK.c_str();
- req.workingkey2 = m_EDK.c_str();
- req.reserved3 = m_index.c_str();
- }
- else {
- 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->GetFunction()->CloseSession();
- return rc;
- }
- 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", "LoadKeysSM", 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;
- }
- bool CInitializerEntity::GetAuthAccessAddr(CSimpleStringA &strAddr, int &nPort)
- {
- CSmartPointer<IConfigInfo> pConfig;
- auto rc = GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
- assert(rc == Error_Succeed);
- CSimpleStringA strValue;
- rc = pConfig->ReadConfigValue("Initializer", "Server", strValue);
- assert(rc == Error_Succeed);
- rc = ParseIPAddress(strValue, strAddr, nPort);
- return rc == Error_Succeed;
- }
- bool CInitializerEntity::SetAuthAccessAddr(const char *pszAddr, int nPort)
- {
- CSimpleStringA strPath;
- // 根据场所获取集中配置文件
- GetFunction()->GetPath("CenterSetting", strPath);
- // 保存准入服务地址
- auto strAuthAccessAddr = CSimpleStringA::Format("%s %d", pszAddr, nPort);
- bool bRet = true;
- 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;
- }
- bool CInitializerEntity::GetCenterSettingAddr(CSimpleStringA &strAddr, int &nPort)
- {
- CSmartPointer<IConfigInfo> pConfig;
- auto rc = GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
- assert(rc == Error_Succeed);
- CSimpleStringA strValue;
- rc = pConfig->ReadConfigValue("CenterSetting", "Server", strValue);
- assert(rc == Error_Succeed);
- rc = ParseIPAddress(strValue, strAddr, nPort);
- return rc == Error_Succeed;
- }
- bool CInitializerEntity::SetCenterSettingAddr(const char *pszAddr, int nPort)
- {
- CSimpleStringA strPath;
- // 根据场所获取集中配置文件
- GetFunction()->GetPath("CenterSetting", strPath);
-
- auto strAuthAccessAddr = CSimpleStringA::Format("%s %d", pszAddr, nPort);
- return inifile_format_write(strPath.GetData(), "CenterSetting", "Server", "%s", strAuthAccessAddr.GetData());
- }
- bool CInitializerEntity::GetInitUkeyFlg(int &nUkeyFlg)
- {
- ErrorCodeEnum rc(Error_Succeed);
- #if defined(RVC_OS_WIN)
- CSmartPointer<IConfigInfo> pConfig;
- rc = GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
- assert(rc == Error_Succeed);
- CSimpleStringA strValue;
- rc = pConfig->ReadConfigValueInt("Initializer", "SupportUkey", nUkeyFlg);
- Dbg("SupportUkey[%d]", nUkeyFlg);
- #else
- Dbg("Linux do not support ukey anymore!");
- nUkeyFlg = 0;
- #endif //RVC_OS_WIN
- return rc == Error_Succeed;
- }
- bool CInitializerEntity::GetInitializedFlg(int &nInitializedFlg)
- {
- CSimpleStringA strInitState;
- ErrorCodeEnum Error = GetFunction()->GetSysVar("InitState",strInitState);
- if (Error_NotExist == Error)
- {
- Dbg("strInitState is not exist, errcode=%d!", Error);
- return false;
- }
- else if (Error_Succeed != Error)
- {
- Dbg("Get strInitState failed, errcode=%d!", Error);
- return false;
- }
- Dbg("InitState[%s]", strInitState.GetData());
- if (strInitState.Compare("0", true) == 0)
- {
- nInitializedFlg = 0;
- }
- else if (strInitState.Compare("1", true) == 0)
- {
- Dbg("this machine has been initialized!", strInitState);
- nInitializedFlg = 1;
- }
- else
- {
- Dbg("InitState[%s] is wrong, must be 0 or 1!", strInitState);
- return false;
- }
- return true;
- }
- bool CInitializerEntity::SetInitializedFlg(CSimpleStringA strInitState)
- {
- ErrorCodeEnum Error = GetFunction()->SetSysVar("InitState",strInitState, false);
- if (Error_Succeed != Error)
- {
- Dbg("set strInitState failed, errcode=%d!", Error);
- return false;
- }
- return true;
- }
- bool CInitializerEntity::IsIL()
- {
- CSystemStaticInfo info;
- auto rc = GetFunction()->GetSystemStaticInfo(info);
- if (rc != Error_Succeed)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_SYSTEM_STATIC_INFO,
- GetOutPutStr("%s%08X", "GetSystemStaticInfo", rc).c_str());
- Dbg("GetSystemStaticInfo() fail: 0x%X", rc);
- return false;
- }
- Dbg("MachineType[%s]", info.strMachineType.GetData());
- if (info.strMachineType.IsStartWith("RVC.IL", true))
- {
- return true;
- }
- return false;
- }
- DWORD CInitializerEntity::InitCardSwiper()
- {
- // 调用刷卡器实体初始化
- auto pCardSwiperClient = new CardSwiperService_ClientBase(this);
- if (pCardSwiperClient->Connect() != Error_Succeed)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_CONNECT_CARDSWIPER, GetOutPutStr("%s%s", "Connect", "False").c_str());
- m_strLastErrMsg = "连接CardSwiper实体失败";
- pCardSwiperClient->SafeDelete();
- pCardSwiperClient = NULL;
- return Error_InvalidState;
- }
- CardSwiperService_MagTransferInit_Req req = {};
- CardSwiperService_MagTransferInit_Ans ans = {};
- DWORD rc = pCardSwiperClient->MagTransferInit(req, ans, 15000);
- if (rc != Error_Succeed)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_FROM_CARDSWIPER_TRASF_INIT, GetOutPutStr("%s%08X", "MagTransferInit", rc).c_str());
- m_strLastErrMsg = CSimpleStringA::Format("调用CardSwiper实体失败: 0x%x", rc);
- rc = ERR_INITIALIZER_FROM_CARDSWIPER_TRASF_INIT;
- }
- else if (ans.result != 0)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_FROM_CARDSWIPER_NO_RET, GetOutPutStr("%s%08X%s%d", "MagTransferInit", rc,"result",ans.result).c_str());
- m_strLastErrMsg = CSimpleStringA::Format("调用CardSwiper实体返回失败: %d", ans.result);
- rc = ERR_INITIALIZER_FROM_CARDSWIPER_NO_RET;
- }
- pCardSwiperClient->GetFunction()->CloseSession();
- return rc;
- }
- ErrorCodeEnum CInitializerEntity::DownloadCfg(const char *pszSettingServer, int nSettingPort)
- {
- if (!IsServiceAvailable(pszSettingServer, nSettingPort))
- {
- m_strLastErrMsg = CSimpleStringA::Format("集中配置服务[%s:%d]无法连接", pszSettingServer, nSettingPort);
- return Error_Param;
- }
- // 保存到集中配置中
- SetCenterSettingAddr(pszSettingServer, nSettingPort);
- // 调用集中配置实体下载配置
- auto pCenterSettingClient = new CenterSettingService_ClientBase(this);
- if (pCenterSettingClient->Connect() != Error_Succeed)
- {
- m_strLastErrMsg = "连接集中配置实体失败";
- pCenterSettingClient->SafeDelete();
- pCenterSettingClient = NULL;
- return Error_InvalidState;
- }
- CenterSettingService_Download_Req req = {};
- req.strAddr = pszSettingServer;
- req.nPort = nSettingPort;
- CenterSettingService_Download_Ans ans = {};
- auto rc = pCenterSettingClient->Download(req, ans, 10000);
- if (rc != Error_Succeed)
- m_strLastErrMsg = "集中配置实体Download接口调用失败";
- pCenterSettingClient->GetFunction()->CloseSession();
- return rc;
- }
- void CInitializerEntity::BeginLogin(const char *pszAuthServer, int nAuthPort, const char *pszUserID, const char *pszPassword)
- {
- LOG_FUNCTION();
- DWORD rc = Error_Succeed;
- // 修改状态机
- FSMEvent *pEvent = new FSMEvent(CInitializerFSM::Event_StartLogin);
- m_FSM.PostEventFIFO(pEvent);
-
- CSimpleStringA strOldAuthServer;
- int nOldAuthPort = 0;
- // 判断用户是否改变准入服务地址
- if (GetAuthAccessAddr(strOldAuthServer, nOldAuthPort) &&
- (strOldAuthServer.Compare(pszAuthServer) != 0 || nAuthPort != nOldAuthPort))
- {
- if (!IsServiceAvailable(pszAuthServer, nAuthPort))
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_AUTH_SERVER,
- GetOutPutStr("%s%s%s%s%s%d", "IsServiceAvailable", "False", "pszAuthServer", pszAuthServer, "nAuthPort", nAuthPort).c_str());
- auto strErrMsg = CSimpleStringA::Format("准入服务[%s:%d]无法连接(error:%d), 请确认网络是否正常", pszAuthServer, nAuthPort, WSAGetLastError());
- EndLogin(ERR_INITIALIZER_AUTH_SERVER, strErrMsg);
- return;
- }
- // 保存到集中配置中
- SetAuthAccessAddr(pszAuthServer, nAuthPort);
- }
- int nUkeyFlg = 0;
- if (!GetInitUkeyFlg(nUkeyFlg))
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_EKEY_FLG,
- GetOutPutStr("%s%s%s%d", "GetInitUkeyFlg", "False", "GetInitUkeyFlg", nUkeyFlg).c_str());
- auto strErrMsg = CSimpleStringA::Format("读出UkeyFlg配置失败, 请联系分行信息部确认集中配置");
- EndLogin(ERR_INITIALIZER_GET_EKEY_FLG, strErrMsg);
- return;
- }
- if (0 == nUkeyFlg)
- {
- m_strUserID = pszUserID;
- m_strPassword = pszPassword;
- }
- else
- {
- //获取电子钥匙持有人的用户ID
- MaintainCertificate_ClientBase *pClient = new MaintainCertificate_ClientBase(this);
- rc = pClient->Connect();
- if (rc != Error_Succeed)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_CONNECT_MAINTAINWATCHER,
- GetOutPutStr("%s%08X%s%s", "Connect", rc , "Desc" ,"在初始化登录阶段连接MaintainWatcher实体失败了").c_str());
- EndLogin(ERR_INITIALIZER_CONNECT_MAINTAINWATCHER, "连接MaintainWatcher实体失败。");
- pClient->SafeDelete();
- return;
- }
- else
- {
- MaintainCertificate_GetUserInfo_Req req = {};
- MaintainCertificate_GetUserInfo_Ans ans = {};
- rc = pClient->GetUserInfo(req, ans, 10000);
- if (rc != Error_Succeed)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_FROM_MAINTAINWATCHER_GETUSERINFO,
- GetOutPutStr("%s%08X%s%s", "GetUserInfo", rc ,"Desc", "在初始化登录阶段c从MaintainWatcher实体获取用户信息失败了").c_str());
- EndLogin(ERR_INITIALIZER_FROM_MAINTAINWATCHER_GETUSERINFO, "从MaintainWatcher实体获取用户信息失败。");
- //如果连接电子钥匙失败,以传入的参数进行密钥初始化
- m_strUserID = pszUserID;
- m_strPassword = pszPassword;
- pClient->GetFunction()->CloseSession();
- pClient = NULL;
- }
- else
- {
- // UserID=SP00000004;UserName=RVC0001;AuthorierID=SP00000001;AuthorizeTime=2014/8/13 18:46:29;RecommenderSAP=80274390;RecommenderOfficeID=274390;
- CSimpleStringA &str = ans.UserInfo;
- Dbg("get maintainer info: %s", (const char*)str);
- auto arr = str.Split(';');
- for (int i = 0; i < arr.GetCount(); i++)
- {
- auto arr2 = arr[i].Split('=');
- if (arr2.GetCount() != 2)
- continue;
- if (arr2[0] == "UserID")
- m_strUserID = arr2[1];
- else if (arr2[0] == "AuthorierID")
- m_strAuthorizer = arr2[1];
- else if (arr2[0] == "AuthorizeTime")
- m_strAuthTime = arr2[1];
- }
- m_strPassword = "88888888";
- Dbg("UserID=%s;Authorizer=%s;AuthTime=%s",
- (const char*)m_strUserID,
- (const char*)m_strAuthorizer,
- (const char*)m_strAuthTime);
- }
- pClient->GetFunction()->CloseSession();
- }
- }
- // 开始连接
- rc = SecureClientConnect();
- if (rc != Error_Succeed)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_NET_CONNECT,
- GetOutPutStr("%s%08X", "SecureClientConnect", rc).c_str());
- EndLogin(ERR_INITIALIZER_NET_CONNECT, "连接准入服务失败, 请确认网络是否正常");
- return;
- }
- m_strInitUserID = m_strUserID;
- // 设定初始化超时(10秒)
- GetFunction()->SetTimer(11, this, 10000);
- rc = m_pConnection->SendLoginPackage(m_strUserID, m_strPassword);
- if (rc != Error_Succeed)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_LOGIN_SEND_PKG,
- GetOutPutStr("%s%08X", "SendLoginPackage", rc).c_str());
- EndLogin(ERR_INITIALIZER_LOGIN_SEND_PKG, "发送登录请求失败, 请确认网络是否正常");
- return;
- }
- Dbg("send login pkg succ");
- return;
- }
- void CInitializerEntity::AutoBeginLogin(const char *pszAuthServer, int nAuthPort)
- {
- DWORD rc = Error_Succeed;
- // 修改状态机
- FSMEvent *pEvent = new FSMEvent(CInitializerFSM::Event_StartLogin);
- m_FSM.PostEventFIFO(pEvent);
- // 判断用户是否改变准入服务地址
- CSimpleStringA strOldAuthServer;
- int nOldAuthPort = 0;
- if (GetAuthAccessAddr(strOldAuthServer, nOldAuthPort) &&
- (strOldAuthServer.Compare(pszAuthServer) != 0 || nAuthPort != nOldAuthPort))
- {
- if (!IsServiceAvailable(pszAuthServer, nAuthPort))
- {
- auto strErrMsg = CSimpleStringA::Format("准入服务[%s:%d]无法连接(error:%d), 请确认网络是否正常", pszAuthServer, nAuthPort, WSAGetLastError());
- EndLogin(ERR_INITIALIZER_AUTH_SERVER, strErrMsg);
- return;
- }
- // 保存到集中配置中
- SetAuthAccessAddr(pszAuthServer, nAuthPort);
- }
-
- m_strUserID = "admin";
- m_strPassword = "88888888";
- Dbg("m_strUserID=%s;m_strPassword=%s",
- m_strUserID.GetData(),
- m_strPassword.GetData());
- // 开始连接
- rc = SecureClientConnect();
- if (rc != Error_Succeed)
- {
- EndLogin(ERR_INITIALIZER_NET_CONNECT, "连接准入服务失败, 请确认网络是否正常");
- return;
- }
- m_strInitUserID = m_strUserID;
- // 设定初始化超时(10秒)
- GetFunction()->SetTimer(11, this, 10000);
- rc = m_pConnection->SendLoginPackage(m_strUserID, m_strPassword);
- if (rc != Error_Succeed)
- {
- EndLogin(ERR_INITIALIZER_LOGIN_SEND_PKG, "发送登录请求失败, 请确认网络是否正常");
- return;
- }
- Dbg("send login pkg succ");
- return;
- }
- void CInitializerEntity::EndLogin(DWORD rc, const char *pErrMsg)
- {
- LOG_FUNCTION();
- GetFunction()->KillTimer(11);
- // 通知到状态机
- FSMEvent *pEvent = new FSMEvent(CInitializerFSM::Event_LoginResult);
- pEvent->param1 = ((rc == Error_Succeed) ? 0 : 1);
- m_FSM.PostEventFIFO(pEvent);
- if (rc != Error_Succeed)
- {
- ReportInitMKState(m_strInitUserID, rc, pErrMsg);
- SecureClientRelease();
- LogError(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_LOGIN,
- GetOutPutStr("%s%08X%s%s", "EndLogin", rc, "pErrMsg", pErrMsg).c_str());
-
- GetFunction()->ShowFatalError(pErrMsg);
- m_eErrNum = rc;
- m_strLastErrMsg = pErrMsg;
- //判断是否为蓝牙多合一,登录失败,返回给上层
- if (m_type != Bluetooth && m_ctx != NULL)
- {
- //详细错误码,成功rc的值为Error_Succeed
- m_ctx->Ans.Errcode = rc;
- m_ctx->Ans.ErrMsg = m_strLastErrMsg;
- Dbg("$ErrMsg$:%s", m_ctx->Ans.ErrMsg.GetData());
- //成功返回Error_Succeed,详细错误由Ans.Errcode体现
- m_ctx->Answer(Error_Succeed);
- }
- //蓝牙多合一自动初始化
- else if(m_ctx_blue != NULL){
- m_ctx_blue->Ans.Errcode = rc;
- m_ctx_blue->Ans.ErrMsg = m_strLastErrMsg;
- m_ctx_blue->Answer(Error_Succeed);
- }
- }
- else
- {
- Dbg("Login successfully!");
- m_strLastErrMsg = "";
- BeginGetKMCKey();
- }
- }
- void CInitializerEntity::BeginSyncPK()
- {
- // 立刻同步公钥文件
- LOG_FUNCTION();
- auto rc = SecureClientConnect();
- if (rc != Error_Succeed)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_NET_CONNECT,
- GetOutPutStr("%s%08X", "SecureClientConnect", rc).c_str());
- EndSyncPK(ERR_INITIALIZER_NET_CONNECT, "连接准入服务失败, 请确认网络是否正常");
- return;
- }
- assert(m_pConnection->IsConnectionOK());
- if (m_pConnection->SendSyncPubKeyPackage() != Error_Succeed)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_SYNC_PUBKEY_SEND_PKG,
- GetOutPutStr("%s%08X", "SendSyncPubKeyPackage", Error_Unexpect).c_str());
- EndSyncPK(ERR_INITIALIZER_SYNC_PUBKEY_SEND_PKG, "发送同步公钥请求失败, 请联系分行技术部");
- return;
- }
- // 设定超时(10秒)
- GetFunction()->SetTimer(33, this, 10000);
- }
- void CInitializerEntity::BeginGetKMCKey()
- {
- // 立刻同步公钥文件
- LOG_FUNCTION();
- auto rc = SecureClientConnect();
- if (rc != Error_Succeed)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_NET_CONNECT,
- GetOutPutStr("%s%08X", "SecureClientConnect", rc).c_str());
- return;
- }
- assert(m_pConnection->IsConnectionOK());
- CSystemStaticInfo si;
- GetFunction()->GetSystemStaticInfo(si);
- if (m_pConnection->SendGetKMCKey(si.strTerminalID.GetData()) != Error_Succeed)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_KMC_KEY_SEND_PKG,
- GetOutPutStr("%s%08X", "SendGetKMCKey", Error_Unexpect).c_str());
- return;
- }
- // 设定超时(10秒)
- GetFunction()->SetTimer(33, this, 10000);
- }
- void CInitializerEntity::EndSyncPK(DWORD rc, const char *pszErrMsg)
- {
- GetFunction()->KillTimer(33);
- if (rc != Error_Succeed)
- {
- // 通知到状态机,同步公钥失败当做初始化主密钥失败状态
- FSMEvent *pEvent = new FSMEvent(CInitializerFSM::Event_InitMKResult);
- pEvent->param1 = 1;
- m_FSM.PostEventFIFO(pEvent);
- ReportInitMKState(m_strInitUserID, rc, pszErrMsg);
- SecureClientRelease();
- std::string errStr = SP::Utility::GBK2UTF8(std::string(pszErrMsg));
- LogError(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_SYNC_PUBKEY,
- GetOutPutStr("%s%08X%s%s", "EndSyncPK", rc, "pszErrMsg", errStr.c_str()).c_str());
- GetFunction()->ShowFatalError(errStr.c_str());
-
- m_eErrNum = rc;
- m_strLastErrMsg = pszErrMsg;
- //if (m_hGUIWindow == 0)
- {
- if (m_type == Normal) {
- m_ctx->Ans.Errcode = rc;
- m_ctx->Ans.ErrMsg = m_strLastErrMsg;
- m_ctx->Answer(Error_Succeed);
- }
- else if (m_type == Bluetooth) {
- m_ctx_blue->Ans.Errcode = rc;
- m_ctx_blue->Ans.ErrMsg = m_strLastErrMsg;
- m_ctx_blue->Answer(Error_Succeed);
- }
- }
- }
- else
- {
- Dbg("同步公钥成功");
- m_strLastErrMsg = "";
- BeginInitMK();
- }
- }
- void CInitializerEntity::EndGetKMCKey(DWORD rc, const char* pszErrMsg) {
- LOG_FUNCTION();
- GetFunction()->KillTimer(33);
- if (rc != Error_Succeed)
- {
- // 通知到状态机,获取KMC密钥失败当做初始化主密钥失败状态
- FSMEvent* pEvent = new FSMEvent(CInitializerFSM::Event_InitMKResult);
- pEvent->param1 = 1;
- m_FSM.PostEventFIFO(pEvent);
- ReportInitMKState(m_strInitUserID, rc, pszErrMsg);
- SecureClientRelease();
- std::string errStr = SP::Utility::GBK2UTF8(std::string(pszErrMsg));
- LogError(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_SYNC_PUBKEY,
- GetOutPutStr("%s%08X%s%s", "EndGetKMCKey", rc, "pszErrMsg", errStr.c_str()).c_str());
- GetFunction()->ShowFatalError(errStr.c_str());
- m_eErrNum = rc;
- m_strLastErrMsg = pszErrMsg;
-
- if (m_type == Normal && m_ctx != NULL) {
- m_ctx->Ans.Errcode = rc;
- m_ctx->Ans.ErrMsg = m_strLastErrMsg;
- m_ctx->Answer(Error_Succeed);
- }
- else if (m_type == Bluetooth && m_ctx_blue != NULL) {
- m_ctx_blue->Ans.Errcode = rc;
- m_ctx_blue->Ans.ErrMsg = m_strLastErrMsg;
- m_ctx_blue->Answer(Error_Succeed);
- }
- }
- else
- {
- Dbg("获取KMC密钥成功");
- m_strLastErrMsg = "";
- BeginInitMK();
- }
- }
- DWORD CInitializerEntity::ReportInitMKState(const char *pszUserID, DWORD dwErrCode, const char *pszErrMsg)
- {
- LOG_FUNCTION();
- auto rc = SecureClientConnect();
- if (rc != Error_Succeed)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_NET_CONNECT,
- GetOutPutStr("%s%08X", "SecureClientConnect", rc).c_str());
- return rc;
- }
- assert(m_pConnection->IsConnectionOK());
- return m_pConnection->SendReportStatePackage("InitMK", pszUserID, dwErrCode, pszErrMsg);
- }
- void CInitializerEntity::BeginInitMK()
- {
- LOG_FUNCTION();
-
- // 开始连接
- DWORD rc = SecureClientConnect();
- if (rc != Error_Succeed)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_NET_CONNECT,
- GetOutPutStr("%s%08X", "SecureClientConnect", rc).c_str());
- EndInitMK(ERR_INITIALIZER_NET_CONNECT, "连接准入服务失败,请确认网络是否正常!");
- return;
- }
-
- assert(m_pConnection != NULL && m_pConnection->IsConnectionOK());
- rc = m_pConnection->SendInitMKPackage();
- if (rc != Error_Succeed)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_INIT_MK_SEND_PKG,
- GetOutPutStr("%s%08X", "SendInitMKPackage", rc).c_str());
- EndInitMK(ERR_INITIALIZER_INIT_MK_SEND_PKG, (const char*)CSimpleStringA::Format("发送MK初始化请求失败, %s", (const char*)m_strLastErrMsg));
- return;
- }
- Dbg("send InitMK req succ");
- // 设定初始化超时(30秒)
- GetFunction()->SetTimer(22, this, 30000);
- }
- void CInitializerEntity::EndInitMK(DWORD rc, const char *pszErrMsg)
- {
- LOG_FUNCTION();
- GetFunction()->KillTimer(22);
- m_strLastErrMsg = pszErrMsg;
- // 通知到中台
- ReportInitMKState(m_strInitUserID, rc, m_strLastErrMsg);
- if (rc != Error_Succeed)
- {
- LogError(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_INIT_MK,
- GetOutPutStr("%s%08X%s%s", "EndInitMK", rc,"pszErrMsg", pszErrMsg).c_str());
- GetFunction()->ShowFatalError(pszErrMsg);
- CSimpleStringA strErrMsg = CSimpleStringA::Format("初始化MK错误:%s", pszErrMsg);
- SP::Module::Comm::LogErrorNotiyStruct notifyItem(Error_Unexpect, ERR_INITIALIZER_SYNC_PUBKEY);
- SP::Module::Comm::LogNotiyMessageStruct notifyMsg(strErrMsg);
- notifyItem.Notify(notifyMsg);
- }
- else
- {
- Dbg("初始化成功");
- // 初始化刷卡器(只有配置外置PinPad的PAD终端才需要初始化)
- CSystemStaticInfo info;
- GetFunction()->GetSystemStaticInfo(info);
- if (rc != Error_Succeed) {
- LogWarn(Severity_Middle, (ErrorCodeEnum) rc, ERR_INITIALIZER_GET_SYSTEM_STATIC_INFO,
- GetOutPutStr("%s%08X", "GetSystemStaticInfo", rc).c_str());
- rc = ERR_INITIALIZER_FROM_CARDSWIPER;
- }
- else
- {
- if (stricmp(info.strMachineType, "RVC.Pad") == 0 && HasPinPad())
- {
- rc = InitCardSwiper();
- if (rc == Error_Succeed)
- Dbg("init card swiper succ");
- else
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_FROM_CARDSWIPER,
- GetOutPutStr("%s%08X", "InitCardSwiper", rc).c_str());
- //这里不能赋值,不然将覆盖具体错误码
- //rc = ERR_INITIALIZER_FROM_CARDSWIPER;
- }
-
- }
- }
- }
- m_eErrNum = rc;
-
- // 通知到状态机
- bool bSuc = rc == Error_Succeed;
- Dbg("m_afterSMIsFirst=%d,bSuc=%d", m_afterSMIsFirst, bSuc);
- if (m_afterSMIsFirst && bSuc)
- {
- //修改初始化状态
- Dbg("修改初始化完成标志位为1");
- SetInitializedFlg("1");
- //不重启应用的情况下
- m_afterSMIsFirst = false;
- }
- FSMEvent *pEvent = new FSMEvent(CInitializerFSM::Event_InitMKResult);
- pEvent->param1 = bSuc ? 0 : 1;
- m_FSM.PostEventFIFO(pEvent);
- int nInitializedFlg = 1;
- GetInitializedFlg(nInitializedFlg);
- if (IsIL() && 0 == nInitializedFlg && bSuc)
- {
- //修改初始化状态
- SetInitializedFlg("1");
- }
- else
- {
- if (m_type != Bluetooth && m_ctx != NULL) {
-
- m_ctx->Ans.Errcode = rc;
- m_ctx->Ans.ErrMsg = m_strLastErrMsg;
- m_ctx->Answer(Error_Succeed);
- }
- else if(m_ctx_blue != NULL) {
- m_ctx_blue->Ans.Errcode = rc;
- m_ctx_blue->Ans.ErrMsg = m_strLastErrMsg;
- m_ctx_blue->Answer(Error_Succeed);
- }
- }
- SecureClientRelease();
- }
- void CInitializerEntity::CloseTask()
- {
- LOG_FUNCTION();
- auto rc = m_pConnection->SendCloseTaskPackage(m_strUserID.GetData());
- if (rc != Error_Succeed)
- {
- Dbg("发送关闭任务请求失败");
- }
- Dbg("send close task pkg succ");
- }
- void CInitializerEntity::OnTimeout(DWORD dwTimerID)
- {
- if (dwTimerID == 11) // 登录超时
- {
- EndLogin(ERR_INITIALIZER_LOGIN_TIME_OUT, "登录超时");
- }
- else if (dwTimerID == 22) // 下载MK超时
- {
- EndInitMK(ERR_INITIALIZER_INIT_MK_TIME_OUT, "初始化主密钥超时");
- }
- else if (dwTimerID == 33) // 同步公钥超时
- {
- EndGetKMCKey(ERR_INITIALIZER_GET_KMC_KEY_TIME_OUT,"获取KMC密钥超时");
- }
- }
- ErrorCodeEnum CInitializerEntity::ParseIPAddress(const char *str, CSimpleStringA &ip, int &port)
- {
- ErrorCodeEnum Error = Error_Unexpect;
- if (str) {
- char tmp1[32] = {};
- char tmp2[16] = {};
- sscanf(str, "%s %s", tmp1, tmp2);
- if (tmp1[0] != 0 && tmp2[0] != 0)
- {
- ip = tmp1;
- port = atoi(tmp2);
- Error = Error_Succeed;
- }
- else
- return Error;
- }
- return Error;
- }
- ErrorCodeEnum CInitializerEntity::StartGUI()
- {
- return Error_Succeed;
- }
- ErrorCodeEnum CInitializerEntity::StartGUINew()
- {
- LOG_FUNCTION();
- int nInitializedFlg = 1;
- GetInitializedFlg(nInitializedFlg);
- if (IsIL() && 0 == nInitializedFlg)
- {
- AutoBeginLogin(m_strAuthServer.GetData(), m_nAuthPort);
- }
- else
- {
- CSimpleStringA tmpUserID = m_strUserID;
- CSimpleStringA tmpPswd = m_strPassword;
- Dbg("tmpUserID=%s at StartGUINew", tmpUserID.GetData());
- Dbg("tmpPswd=%s at StartGUINew", tmpPswd.GetData());
- BeginLogin(m_strAuthServer, m_nAuthPort, tmpUserID, tmpPswd);
- }
-
- return Error_Succeed;
- }
- ErrorCodeEnum CInitializerEntity::CloseGUI()
- {
- return Error_Succeed;
- }
- bool CInitializerEntity::IsServiceAvailable(const char* pszServiceAddr, int nServerPort)
- {
- if (pszServiceAddr == NULL || strlen(pszServiceAddr) <= 8 || nServerPort <= 0)
- return false;
- SOCKET s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- if (s == INVALID_SOCKET)
- return false;
- sockaddr_in addr = { 0 };
- addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = inet_addr(pszServiceAddr);
- addr.sin_port = htons(nServerPort);
- bool bRet = (connect(s, (SOCKADDR*)& addr, sizeof(addr)) != SOCKET_ERROR);
- closesocket(s);
- return bRet;
- }
- const char* CInitializerEntity::GetLastErrMsg()
- {
- return m_strLastErrMsg;
- }
- bool CInitializerEntity::HasPinPad()
- {
-
- CSystemStaticInfo info;
- auto rc = GetFunction()->GetSystemStaticInfo(info);
- if (rc != Error_Succeed)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_SYSTEM_STATIC_INFO,
- GetOutPutStr("%s%08X", "GetSystemStaticInfo", rc).c_str());
- }
- if (info.strMachineType.IsStartWith("RPM", true) || info.strMachineType.IsStartWith("RVC.CardStore", true) || info.strMachineType.IsStartWith("RVC.IL", true)) // 回单打印机、简化版
- return false;
- else if (stricmp(info.strMachineType, "RVC.PAD") == 0) // Pad机型
- {
- // 根据PinPad实体状态确定是否连接密码键盘
- bool bPinPadExist = false;
- auto pPinPadClient = new PinPadService_ClientBase(this);
- rc = pPinPadClient->Connect();
- if (rc != Error_Succeed)
- {
- if (m_type == Bluetooth) {
- m_ctx_blue->Ans.Errcode = ERR_INITIALIZER_CONNECT_PINPAD;
- m_ctx_blue->Ans.ErrMsg = "连接pinpad实体失败";
- m_ctx_blue->Answer(Error_Succeed);
- }
- Dbg("connect PinPad fail, assume no pinpad");
- pPinPadClient->SafeDelete();
- pPinPadClient = NULL;
- }
- else
- {
- PinPadService_GetDevInfo_Req req = {};
- PinPadService_GetDevInfo_Ans ans = {};
- auto rc = pPinPadClient->GetDevInfo(req, ans, 3000);
- if (rc != Error_Succeed)
- {
- Dbg("PinPad::GetDevInfo() fail: 0x%X", rc);
- if (m_type == Bluetooth)
- {
- m_ctx_blue->Ans.Errcode = ERR_INITIALIZER_FROM_PINPAD_GET_DEV_INFO;
- m_ctx_blue->Ans.ErrMsg = "pinpad not exist";
- m_ctx_blue->Answer(Error_Succeed);
- }
- }
- else
- {
- Dbg("PinPad::GetDevInfo() return state: %d", ans.state);
- bPinPadExist = ans.state != DEVICE_STATUS_NOT_READY;
- }
- pPinPadClient->GetFunction()->CloseSession();
- }
- return bPinPadExist;
- }
- else
- {
- // 其它VTM机型,全部有内置密码键盘
- return true;
- }
- }
- // 1:3des only; 2: sm4 only; 3: both 3des and sm4
- int CInitializerEntity::GetPinPadCapability()
- {
- auto pPinPadClient = new PinPadService_ClientBase(this);
- int nCapability = 1;
- DWORD rc = pPinPadClient->Connect();
- if (rc != Error_Succeed)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_CONNECT_PINPAD,
- GetOutPutStr("%s%s", "Connect", "False").c_str());
- rc = ERR_INITIALIZER_CONNECT_PINPAD;
- if (m_type == Bluetooth)
- {
- m_ctx_blue->Ans.Errcode = rc;
- m_ctx_blue->Ans.ErrMsg = "连接PinPad实体失败";
- m_ctx_blue->Answer(Error_Succeed);
- }
- pPinPadClient->SafeDelete();
- pPinPadClient = NULL;
- }
- else
- {
- PinPadService_QueryFunc_Req req = {};
- PinPadService_QueryFunc_Ans ans = {};
- rc = pPinPadClient->QueryFunc(req, ans, 3000);
- if (rc != Error_Succeed)
- {
- LogWarn(Severity_Middle,(ErrorCodeEnum) rc, ERR_INITIALIZER_FROM_PINPAD_QUERY_FUNC,
- GetOutPutStr("%s%08X%s%s", "QueryFunc", rc ,"Desc","调用pinpad实体的QueryFunc失败。。。").c_str());
- }
- else
- {
- // encryptkey 1: 3des only; 2: sm4 only; 3: both 3des and sm4
- Dbg("PinPad::QueryFunc() return: %d", ans.encryptkey);
- nCapability = ans.encryptkey;
- }
- pPinPadClient->GetFunction()->CloseSession();
- }
- if (HasCkCodeFlg())
- {
- // 检查公钥缓存是否存在
- if (nCapability == 3 && (0 == m_iSM2Pukeylen))
- {
- Dbg("not SM2Pukeylen = 0, init des only");
- nCapability = 1;
- }
- }
- else
- {
- // 检查公钥文件是否存在
- CSimpleStringA strKmcPath;
- GetFunction()->GetPath("RunInfo", strKmcPath);
- strKmcPath += "\\kmc\\";
- CSimpleStringA strSm2PubKeyFile = strKmcPath + PUKFILENAME_SM2;
- if (nCapability == 3 && !ExistsFileA(strSm2PubKeyFile))
- {
- Dbg("not find RVCSM2PubKey.ini, init des only");
- nCapability = 1;
- }
- }
- return nCapability;
- }
- ErrorCodeEnum CInitializerEntity::SecureClientConnect()
- {
- if (m_pConnection != NULL && m_pConnection->IsConnectionOK())
- return Error_Succeed;
- SecureClientRelease();
- m_pConnection = new CInitializerConn(this);
- if (m_pConnection->ConnectFromCentralSetting() && m_pConnection->IsConnectionOK())
- return Error_Succeed;
- SecureClientRelease();
- return Error_PeerReject;
- }
- ErrorCodeEnum CInitializerEntity::SecureClientRelease()
- {
- if (m_pConnection != NULL)
- {
- m_pConnection->Close();
- m_pConnection->DecRefCount();
- m_pConnection = NULL;
- }
- return Error_Succeed;
- }
- void CInitializerEntity::OnSecureClientDisconnect()
- {
- m_FSM.PostEventFIFO(new FSMEvent(CInitializerFSM::Event_Disconnect));
- }
- bool CInitializerEntity::GetMD5Hash(const char *pStr, BYTE md5[16])
- {
- return Error_Succeed;
- }
- static char* ConvertBytesToHexStr(BYTE *pBuf, int nLen)
- {
- char *pRet = (char*)malloc(nLen * 2 + 1);
- memset(pRet, 0, nLen * 2 + 1);
- char *p = pRet;
- for (int i = 0; i < nLen; i++)
- {
- BYTE b = pBuf[i];
- BYTE l = (b >> 4) & 0x0F;
- if (l >= 10)
- *p = l - 10 + 'A';
- else
- *p = l + '0';
- p++;
- BYTE r = b & 0x0F;
- if (r >= 10)
- *p = r - 10 + 'A';
- else
- *p = r + '0';
- p++;
- }
- return pRet;
- }
- bool CInitializerEntity::GetTerminalFingerPrint(BYTE *pBuf, int &nBufLen)
- {
- char szTmp[1024] = {0};
- string strTmp;
- int nTmpBufLen = 1024;
- CSimpleStringA strRet;
- #ifdef RVC_OS_WIN
- if (!QueryWMIDevice(Processor, "ProcessorId", szTmp, &nTmpBufLen))
- #else
- CSimpleStringA runInfoPath;
- auto rc = GetFunction()->GetPath("runinfo", runInfoPath);
- if (rc != Error_Succeed) {
- Dbg("GetPath runinfo error=%d.", rc);
- return false;
- }
- runInfoPath += SPLIT_SLASH_STR "runcfg";
- if(!get_cpu_id_by_system(strTmp, runInfoPath.GetData()))
- #endif // RVC_OS_WIN
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_PROCCESSOR_ID,
- GetOutPutStr("%s%s", "Processor", "False").c_str());
- m_strLastErrMsg = CSimpleStringA::Format("查询CPU ID失败,请重启机器并重新初始化");
- return false;
- }
-
- #ifdef RVC_OS_WIN
- strRet = szTmp;
- nTmpBufLen = 1024;
- memset(szTmp, 0, sizeof(szTmp));
- if (!QueryWMIDevice(BaseBoard, "SerialNumber", szTmp, &nTmpBufLen))
- #else
- Dbg("cpu id: %s", strTmp.c_str());
- strRet = strTmp.c_str();
- strTmp.clear();
- if(!get_board_serial_by_system(strTmp, runInfoPath.GetData()))
- #endif // RVC_OS_WIN
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_BASEBOARD_ID,
- GetOutPutStr("%s%s", "BaseBoard", "False").c_str());
- m_strLastErrMsg = CSimpleStringA::Format("查询主板序列号失败, 请重启机器并重新初始化");
- return false;
- }
- strRet += "|";
- #ifdef RVC_OS_WIN
- strRet += szTmp;
- nTmpBufLen = 1024;
- memset(szTmp, 0, sizeof(szTmp));
- if (!QueryWMIDevice(DiskDrive, "SerialNumber", szTmp, &nTmpBufLen))
- #else
- Dbg("baseboard sn: %s", strTmp.c_str());
- strRet += strTmp.c_str();
- vector<string> disk;
- int errCode = 0;
- if(!get_disk_serial_by_system(disk, errCode,runInfoPath.GetData()))
- #endif // RVC_OS_WIN
- {
- Dbg("get_disk_serial_by_system errCode:%d", errCode);
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_DISKDRIVE_ID,
- GetOutPutStr("%s%s", "DiskDrive", "False").c_str());
- m_strLastErrMsg = CSimpleStringA::Format("查询磁盘序列号失败, 请重启机器并重新初始化");
- return false;
- }
-
- strRet += "|";
- #ifdef RVC_OS_WIN
- strRet += szTmp;
- #else
- strTmp = "";
- vector<string>::iterator it = disk.begin();
- while (it != disk.end()) {
- strTmp += *it;
- it++;
- }
- Dbg("harddisk sn: %s", strTmp.c_str());
- strRet += strTmp.c_str();
- #endif // RVC_OS_WIN
- Dbg("device info: [%s]", (const char*)strRet);
- // SM3 hash
- BYTE sm3[32] = {};
- if (!SM3Hash((BYTE*)strRet.GetData(),strRet.GetLength(), sm3))
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_STR_HASH,
- GetOutPutStr("%s%s", "GetMD5Hash", "False").c_str());
-
- m_strLastErrMsg = "get md5 hash as fingerprint fail";
- return false;
- }
- if (nBufLen < sizeof(sm3))
- {
- LogError(Severity_Low, Error_Unexpect, ERROR_ACCESSAUTH_GETSM3HASH, "GetTerminalFingerPrint, buf len is too small");
- m_strLastErrMsg = "GetTerminalFingerPrint, buf len is too small";
- Dbg("GetTerminalFingerPrint, buf len is too small.");
- return false;
- }
- nBufLen = sizeof(sm3);
- memcpy(pBuf, sm3, nBufLen);
- char *pszSM3 = ConvertBytesToHexStr(sm3, nBufLen);
- Dbg("fringerprint: [%s]", pszSM3);
- free(pszSM3);
- return true;
- }
- int CInitializerEntity::ConvertStr2Byte(string input, BYTE* output,int outputLen) {
- if (input.size() > outputLen) return 1;
- for (int i = 0;i < input.size();i++) {
- output[i] =(BYTE) input[i];
- }
- return 0;
- }
- int CInitializerEntity::GetOrSetIsFirstSM(int type) {
- LOG_FUNCTION();
- CSmartPointer<IConfigInfo> pConfig;
- int isFirst = 0;
- auto rc = GetFunction()->OpenConfig(Config_Run, pConfig);
- if (rc != Error_Succeed) {
- Dbg("OpenConfig Config_Run error=%d.", rc);
- return isFirst;
- }
- CSimpleStringA sIsFirst;
- if (type == 0) {
- rc = pConfig->ReadConfigValue("SM", "IsFirst", sIsFirst);
- if (rc != Error_Succeed || sIsFirst.IsNullOrEmpty()) {
- rc = pConfig->WriteConfigValue("SM", "IsFirst", "Yes");
- if (rc != Error_Succeed) {
- Dbg("WriteConfigValue Config_Run SM IsFirst error.");
- return isFirst;
- }
- isFirst = 1;
- }
- else if (sIsFirst == "Yes") {
- isFirst = 1;
- }
- else isFirst = 0;
- return isFirst;
- }
- else {
- rc = pConfig->WriteConfigValue("SM", "IsFirst", "No");
- if (rc != Error_Succeed) {
- Dbg("WriteConfigValue Config_Run SM IsFirst error.");
- return isFirst;
- }
- else {
- isFirst = 1;
- }
- return isFirst;
- }
- }
- // 生成RSA密钥对,并导出公钥
- bool CInitializerEntity::GetTerminalPublicKey(BYTE *pBuf, int &nBufLen)
- {
- LOG_FUNCTION();
- CSimpleString runInfoPath;
- auto rc = GetFunction()->GetPath("runinfo", runInfoPath);
- if (rc != Error_Succeed) {
- Dbg("GetPath runinfo error=%d.",rc);
- return false;
- }
- runInfoPath += SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR;
- /*if (!boost::filesystem::exists(runInfoPath.GetData())) {
- boost::filesystem::create_directories(runInfoPath.GetData());
- }*/
- #ifdef RVC_OS_WIN
- DWORD dwAttr = GetFileAttributes(runInfoPath.GetData());
- if (dwAttr == 0xFFFFFFFF) //目录不存在则创建
- {
- if (!CreateDirectory(runInfoPath.GetData(), NULL))
- #else
- if(!dir_is_exist(runInfoPath.GetData()))
- {
- if(dir_create(runInfoPath.GetData()) != 0)
- #endif
- {
- Dbg("Create %s dir failed!", runInfoPath.GetData());
- }
- }
- Dbg("Dir=%s", runInfoPath.GetData());
- //CSimpleString runFile = runInfoPath + GetEntityName();
- CSmartPointer<IConfigInfo> pConfig;
- rc = GetFunction()->OpenConfig(Config_Run, pConfig);
- if (rc != Error_Succeed) {
- Dbg("OpenConfig Config_Run error=%d.", rc);
- return false;
- }
- CSimpleString publicKey;
- rc = pConfig->ReadConfigValue("TerminalPD","PublicKey",publicKey);
- if (rc != Error_Succeed || publicKey.IsNullOrEmpty()) {
- Dbg("ReadConfig publicKey error=%d or publicKey is NULL.", rc);
- BYTE btPublicKey[BUF_SIZE] = { 0 }, btPrivateKey[BUF_SIZE] = { 0 };
- int iPublicKeyLen = sizeof(btPublicKey);
- int iPrivateKeyLen = sizeof(btPrivateKey);
- if (!CreateSM2KeyPair(btPublicKey, &iPublicKeyLen, btPrivateKey, &iPrivateKeyLen)) {
- Dbg("Create SM2 key pair error.");
- return false;
- }
- Dbg("iPublicKeyLen=%d,iPrivateKeyLen=%d", iPublicKeyLen, iPrivateKeyLen);
- Dbg("[btPublicKey=%s]", (char*)btPublicKey);
-
- char* pEncode = Str2Hex((char*)btPublicKey,iPublicKeyLen);
- Dbg("pEncode=%s,%d", pEncode,strlen(pEncode));
- //尝试解码
- /*int pDecodeLen = 0;
- char* pDecode = Hex2Str(pEncode,pDecodeLen);
- Dbg("pDecode=%s", pDecode);
- Dbg("pDecodeLen=%d", pDecodeLen);
- char *ret = Str2Hex(pDecode, pDecodeLen);
- Dbg("ret=%s,%d", ret, strlen(ret));
-
- if (strcmp(ret, pEncode)!=0) {
-
- Dbg("No");
- return false;
- }
- Dbg("Yes");
- delete[] pDecode;
- delete[] ret;*/
- rc = pConfig->WriteConfigValue("TerminalPD", "PublicKey", pEncode);
- assert(rc == Error_Succeed);
- Dbg("write public key success.");
- BYTE pCryptPrivateKey[BUF_SIZE] = { 0 };
- int cryptPrivateKeyLen = BUF_SIZE;
- if (!EncWithSM4_ECB("s5da69gnh4!963@6s5da69gnh4!963@6", btPrivateKey, iPrivateKeyLen, pCryptPrivateKey, &cryptPrivateKeyLen)) {
- Dbg("sm4 crypt privateKey error.");
- rc = pConfig->WriteConfigValue("TerminalPD", "PublicKey", "");
- delete[] pEncode;
- return false;
- }
-
- Dbg("sm4 encrypt pri key success.");
- Dbg("cryptPrivateKeyLen=%d", cryptPrivateKeyLen);
-
- char* pEncodedCryptPrivateKey = Str2Hex((char*)pCryptPrivateKey, cryptPrivateKeyLen);
- Dbg("encode pri key success.");
- rc = pConfig->WriteConfigValue("TerminalPD", "PrivateKey", pEncodedCryptPrivateKey);
- if (rc != Error_Succeed) {
- rc = pConfig->WriteConfigValue("TerminalPD", "PublicKey", "");
- delete[] pEncodedCryptPrivateKey;
- return false;
- }
- Dbg("write pri key success.");
- publicKey = pEncode;
- delete[] pEncode;
- delete[] pEncodedCryptPrivateKey;
- }
- Dbg("PublicKey: %s(%d)", publicKey.GetData(), publicKey.GetLength());
- char *pDecode = Hex2Str(publicKey.GetData(),nBufLen);
-
- memcpy(pBuf, pDecode, nBufLen);
- Dbg("pBuf[0]=%02X,nBufLen=%d", pBuf[0], nBufLen);
- return true;
- }
- // 返回1:只有PinPadID;2:只有DeviceID;3:两者都有;0:没有;-1表示失败
- int CInitializerEntity::GetPinPadIDAndDeviceID(CSimpleStringA &strPinPadID, CSimpleStringA &strDeviceID)
- {
- CSystemStaticInfo info;
- auto rc = GetFunction()->GetSystemStaticInfo(info);
- if (rc != Error_Succeed)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_SYSTEM_STATIC_INFO,
- GetOutPutStr("%s%08X", "GetSystemStaticInfo", rc).c_str());
- return -1;
- }
- if (info.strMachineType.IsStartWith("RPM", true) || info.strMachineType.IsStartWith("RVC.CardStore", true) || info.strMachineType.IsStartWith("RVC.IL", true)) // 回单打印机、简化版
- return 0;
- int nRet = -1;
- auto pPinPadClient = new PinPadService_ClientBase(this);
- bool bPinPadID = false;
- bool bDeviceID = false;
- bool bVendor = false;
- bool bBluetooth = false;
- CSimpleStringA strBluetoothID;
- CSimpleStringA strVendor;
- CSimpleStringA strPID;
- CSimpleStringA strMID;
- rc = pPinPadClient->Connect();
- if (rc == Error_Succeed)
- {
- PinPadService_GetDevInfo_Req req = {};
- PinPadService_GetDevInfo_Ans ans = {};
- auto rc1 = pPinPadClient->GetDevInfo(req, ans, 3000);
- if (rc1 == Error_Succeed)
- {
- if (ans.state == DEVICE_STATUS_NORMAL)
- {
- nRet = 0;
- Dbg("pinpad model: %s", (const char*)ans.model);
- // CM = V2.0#PM = V1.0#MID = 75500001#PID = 12345678#FWID = V1234567#Vendor = nantian
- // 密码键盘ID,PID,8到16字节; 设备ID,MID,8到16字节; 固件版本号,FWID,8字节
- CSimpleStringA str = ans.model;
- if (!str.IsNullOrEmpty())
- {
- auto arr = str.Split('#');
- if (arr.GetCount() > 0)
- {
- for (int i = 0; i < arr.GetCount(); i++)
- {
- auto arr2 = arr[i].Split('=');
- if (arr2.GetCount() != 2)
- continue;
- //if (arr2[0] == "PID")
- if(!strnicmp((LPCTSTR)arr2[0], "PID", strlen("PID")))
- {
- strPID = arr2[1];
- if (!strPID.IsNullOrEmpty())
- bPinPadID = true;
- }
- //else if (arr2[0] == "MID")
- else if(!strnicmp((LPCTSTR)arr2[0], "MID", strlen("MID")))
- {
- strMID = arr2[1];
- if (!strMID.IsNullOrEmpty())
- bDeviceID = true;
- }
- //else if (arr2[0] == "Vendor")
- else if(!strnicmp((LPCTSTR)arr2[0], "Vendor", strlen("Vendor")))
- {
- strVendor = arr2[1];
- if (!strVendor.IsNullOrEmpty())
- bVendor = true;
- }
- else if (!strnicmp((LPCTSTR)arr2[0], "FWBID", strlen("FWBID")))
- {
- strBluetoothID = arr2[1];
- Dbg("strBluetoothID=%s", strBluetoothID);
- if (!strBluetoothID.IsNullOrEmpty())
- bBluetooth = true;
- }
- }
- }
- }
- }
- else
- {
- if (m_type == Bluetooth)
- {
- m_ctx_blue->Ans.Errcode = ERR_INITIALIZER_FROM_PINPAD_NO_STATE;
- m_ctx_blue->Ans.ErrMsg = "pinpad not exist";
- m_ctx_blue->Answer(Error_Succeed);
- }
- Dbg("pinpad not exist, state: %d", ans.state);
- }
- }
- else
- {
- LogWarn(Severity_Middle, rc1, ERR_INITIALIZER_FROM_PINPAD_GET_DEV_INFO,
- GetOutPutStr("%s%08X%s%s", "GetDevInfo", rc, "strErrMsg", "PinPad::GetDevInfo() fail").c_str());
- if (m_type == Bluetooth)
- {
- m_ctx_blue->Ans.Errcode = ERR_INITIALIZER_FROM_PINPAD_GET_DEV_INFO;
- m_ctx_blue->Ans.ErrMsg = "pinpad not exist";
- m_ctx_blue->Answer(Error_Succeed);
- }
- }
- pPinPadClient->GetFunction()->CloseSession();
- }
- else
- {
- LogWarn(Severity_Middle, rc, ERR_INITIALIZER_CONNECT_PINPAD,
- GetOutPutStr("%s%08X%s%s", "connect", rc,"strErrMsg","连接PinPad实体失败").c_str());
- if (m_type == Bluetooth)
- {
- m_ctx_blue->Ans.Errcode = ERR_INITIALIZER_CONNECT_PINPAD;
- m_ctx_blue->Ans.ErrMsg = "连接pinpad实体失败";
- m_ctx_blue->Answer(Error_Succeed);
- }
- pPinPadClient->SafeDelete();
- pPinPadClient = NULL;
- }
- if (bPinPadID)
- {
- if (bVendor)
- strPinPadID = strVendor + "_" + strPID;
- else
- strPinPadID = strPID;
- nRet += 1;
- }
- if (bDeviceID)
- {
- if (bVendor)
- strDeviceID = strVendor + "_" + strMID;
- else
- strDeviceID = strMID;
- if (bBluetooth)
- strDeviceID = strDeviceID +"_" + strBluetoothID;
- nRet += 2;
- }
- return nRet;
- }
- bool CInitializerEntity::HasCkCodeFlg()
- {
- if (!m_bHasCkCode)
- {
- CSystemStaticInfo info;
- DWORD rc = GetFunction()->GetSystemStaticInfo(info);
- if (rc != Error_Succeed)
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_SYSTEM_STATIC_INFO,
- GetOutPutStr("%s%08X", "GetSystemStaticInfo", rc).c_str());
- return false;
- }
- if (info.strMachineType.IsStartWith("RPM", true) || info.strMachineType.IsStartWith("RVC.CardStore", true) || info.strMachineType.IsStartWith("RVC.IL", true)) // 回单打印机、简化版
- return false;
- auto pPinPadClient = new PinPadService_ClientBase(this);
- bool bCheckCode = false;
- CSimpleStringA strSpeficiCM;
- rc = pPinPadClient->Connect();
- if (rc == Error_Succeed)
- {
- PinPadService_GetDevInfo_Req req = {};
- PinPadService_GetDevInfo_Ans ans = {};
- rc = pPinPadClient->GetDevInfo(req, ans, 3000);
- if (rc == Error_Succeed)
- {
- if (ans.state == DEVICE_STATUS_NORMAL)
- {
- Dbg("pinpad model: %s", (const char*)ans.model);
- // CM = V2.0#PM = V1.0#MID = 75500001#PID = 12345678#FWID = V1234567#Vendor = nantian
- // 加密通道的(磁条)版本号,CM; 密码加密的版本号,PM,是否支持国密; 设备ID,MID,8到16字节; 密码键盘ID,PID,8到16字节; 固件版本号,FWID,8字节
- CSimpleStringA str = ans.model;
- if (!str.IsNullOrEmpty())
- {
- auto arr = str.Split('#');
- if (arr.GetCount() > 0)
- {
- for (int i = 0; i < arr.GetCount(); i++)
- {
- auto arr2 = arr[i].Split('=');
- if (arr2.GetCount() != 2)
- continue;
- if(!strnicmp((LPCTSTR)arr2[0], "CM", strlen("CM")))
- {
- strSpeficiCM = arr2[1];
- if (strSpeficiCM.GetLength() > 3 && _strnicmp(strSpeficiCM, "V2.0", strlen("V2.0")) == 0)
- {
- //Support checkcode, then operate checkcode routine..
- m_bHasCkCode = true;
- }
- }
- }
- }
- }
- }
- else
- {
- if (m_type == Bluetooth) {
- m_ctx_blue->Ans.Errcode = ERR_INITIALIZER_FROM_PINPAD_NO_STATE;
- m_ctx_blue->Ans.ErrMsg = "pinpad not exist";
- m_ctx_blue->Answer(Error_Succeed);
- }
- Dbg("pinpad not exist, state: %d", ans.state);
- }
- }
- else
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_FROM_PINPAD_GET_DEV_INFO,
- GetOutPutStr("%s%08X", "GetDevInfo", rc).c_str());
- //LogError(Severity_Middle, rc, ERROR_ACCESSAUTH_GETPINPADINFO, "PinPad::GetDevInfo() fail");
- if (m_type == Bluetooth) {
- m_ctx_blue->Ans.Errcode = rc;
- m_ctx_blue->Ans.ErrMsg = "调用pinpad接口(GetDevInfo)失败";
- m_ctx_blue->Answer(Error_Succeed);
- }
- }
- pPinPadClient->GetFunction()->CloseSession();
- }
- else
- {
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_CONNECT_PINPAD,
- GetOutPutStr("%s%s", "Connect", "False").c_str());
- rc = ERR_INITIALIZER_CONNECT_PINPAD;
- if (m_type == Bluetooth)
- {
- m_ctx_blue->Ans.Errcode = rc;
- m_ctx_blue->Ans.ErrMsg = "连接PinPad实体失败";
- m_ctx_blue->Answer(Error_Succeed);
- }
- pPinPadClient->SafeDelete();
- pPinPadClient = NULL;
- }
- return m_bHasCkCode? true:false;
- }
- else
- {
- return true;
- }
- }
- //判断是否国密改造后的第一次准入,如果是则自动初始化
- bool CInitializerEntity::GetAccessauthIsFirst()
- {
- CSimpleString runInfoPath;
- auto rc = GetFunction()->GetPath("runinfo", runInfoPath);
- if (rc != Error_Succeed) {
- Dbg("GetPath runinfo error=%d.", rc);
- return false;
- }
- runInfoPath += SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "AccessAuthorization.ini";
- char* isFirst;
- isFirst = inifile_read_str(runInfoPath.GetData(), "SM", "IsFirst", "");
- Dbg("isFirst=%s,%d", isFirst, strlen(isFirst));
- if (strlen(isFirst) <= 0) {
- Dbg("没有读取到 IsFirst 字段");
- if (isFirst != NULL) delete isFirst;
- return true;
- }
- else if(stricmp(isFirst,"Yes")==0){
- if (isFirst != NULL) delete isFirst;
- return true;
- }
- else {
- if (isFirst != NULL) delete isFirst;
- return false;
- }
- if (isFirst != NULL) delete isFirst;
- return true;
- }
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(CInitializerEntity)
- SP_END_ENTITY_MAP()
|