|
|
@@ -19,11 +19,240 @@ using namespace PinPad;
|
|
|
#include <Strsafe.h>
|
|
|
#endif
|
|
|
|
|
|
+#ifdef WITH_CPPRESTSDK
|
|
|
+#include "CommEntityRestful.hpp"
|
|
|
+#else
|
|
|
+#define SAFE_DELETE_HTTPCLIENT(obj) \
|
|
|
+ do{if(obj != NULL) { obj->Destory(); obj = NULL; }}while(false)
|
|
|
+#endif
|
|
|
+
|
|
|
#define KEY_SIZE 16
|
|
|
#define BUF_SIZE 256
|
|
|
/** TODO(gifur): expand the time to 10s*/
|
|
|
#define DEFUALT_INVOKE_PINPAD_TIMEOUT 3000
|
|
|
|
|
|
+
|
|
|
+struct InitializerInitMKTask : ITaskSp {
|
|
|
+ CAccessAuthFSM* m_fsm;
|
|
|
+ CAccessAuthEntity* m_entity;
|
|
|
+ InitializerInitMKTask(CAccessAuthFSM* fsm, CAccessAuthEntity* entity) :m_fsm(fsm), m_entity(entity) {}
|
|
|
+
|
|
|
+ void Process()
|
|
|
+ {
|
|
|
+ CSystemStaticInfo si;
|
|
|
+ m_fsm->GetEntityBase()->GetFunction()->GetSystemStaticInfo(si);
|
|
|
+ CInitlizerMKReq initMKReq(1);//oiltest dev module count
|
|
|
+ m_entity->SendInitMKReqACS(initMKReq);
|
|
|
+
|
|
|
+#ifdef WITH_CPPRESTSDK
|
|
|
+
|
|
|
+ struct MKD_NEW1JSON
|
|
|
+ {
|
|
|
+ string enrolAddr;
|
|
|
+ string enrolGPS;
|
|
|
+ string installVersion;
|
|
|
+ string ip;
|
|
|
+ string machineModel;
|
|
|
+ string machineType;
|
|
|
+ string padDeviceID;
|
|
|
+ string site;
|
|
|
+ string terminalNo;
|
|
|
+
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_REGISTER(enrolAddr, enrolGPS, installVersion, ip, machineModel, machineType, padDeviceID, site, terminalNo)
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ struct MKD_REQ2JSON
|
|
|
+ {
|
|
|
+ string branchNo;
|
|
|
+ string kmcData;
|
|
|
+ string subBankNo;
|
|
|
+
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_REGISTER(branchNo, kmcData, subBankNo)
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ struct MKD_REQ3JSON
|
|
|
+ {
|
|
|
+ string factory;
|
|
|
+ string modal;
|
|
|
+ string type;
|
|
|
+ string version;
|
|
|
+
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_REGISTER(factory, modal, type, version)
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ struct MKD_REQ4JSON
|
|
|
+ {
|
|
|
+ string fingerPrint;
|
|
|
+ string fingerPrintSM;
|
|
|
+ string pinPadID;
|
|
|
+ string publicKey;
|
|
|
+ string reserverd;
|
|
|
+
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_REGISTER(fingerPrint, fingerPrintSM, pinPadID, publicKey, reserverd)
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ struct MKD_REQ5JSON
|
|
|
+ {
|
|
|
+ int isFirstSM;
|
|
|
+ int isSM;
|
|
|
+
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_REGISTER(isFirstSM, isSM)
|
|
|
+ };
|
|
|
+
|
|
|
+ struct MKD_SMR2JSON
|
|
|
+ {
|
|
|
+ string branchNo;
|
|
|
+ string kmcData;
|
|
|
+ string subBankNo;
|
|
|
+
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_REGISTER(branchNo, kmcData, subBankNo)
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ struct InstanceReqJson
|
|
|
+ {
|
|
|
+ MKD_NEW1JSON MKD_NEW1;
|
|
|
+ MKD_REQ2JSON MKD_REQ2;
|
|
|
+ std::vector<MKD_REQ3JSON> MKD_REQ3;
|
|
|
+ MKD_REQ4JSON MKD_REQ4;
|
|
|
+ MKD_REQ5JSON MKD_REQ5;
|
|
|
+ MKD_SMR2JSON MKD_SMR2;
|
|
|
+
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_REGISTER(MKD_NEW1, MKD_REQ2, MKD_REQ3, MKD_REQ4, MKD_REQ5, MKD_SMR2)
|
|
|
+
|
|
|
+ } instanceReq;
|
|
|
+
|
|
|
+ instanceReq.MKD_NEW1.enrolAddr = initMKReq.MKD_NEW1.enrolAddr;
|
|
|
+ instanceReq.MKD_NEW1.enrolGPS = initMKReq.MKD_NEW1.enrolGPS;
|
|
|
+ instanceReq.MKD_NEW1.installVersion = initMKReq.MKD_NEW1.installVersion;
|
|
|
+ instanceReq.MKD_NEW1.ip = initMKReq.MKD_NEW1.ip;
|
|
|
+ instanceReq.MKD_NEW1.machineModel = initMKReq.MKD_NEW1.machineModel;
|
|
|
+ instanceReq.MKD_NEW1.machineType = initMKReq.MKD_NEW1.machineType;
|
|
|
+ instanceReq.MKD_NEW1.padDeviceID = initMKReq.MKD_NEW1.padDeviceID;
|
|
|
+ instanceReq.MKD_NEW1.site = initMKReq.MKD_NEW1.site;
|
|
|
+ instanceReq.MKD_NEW1.terminalNo = initMKReq.MKD_NEW1.terminalNo;
|
|
|
+
|
|
|
+ instanceReq.MKD_REQ2.branchNo = initMKReq.MKD_REQ2.branchNo;
|
|
|
+ instanceReq.MKD_REQ2.kmcData = initMKReq.MKD_REQ2.kmcData;
|
|
|
+ instanceReq.MKD_REQ2.subBankNo = initMKReq.MKD_REQ2.subBankNo;
|
|
|
+
|
|
|
+ for (int i = 0; i < initMKReq.iReq3Count; ++i) {
|
|
|
+ MKD_REQ3JSON item;
|
|
|
+ item.type = initMKReq.MKD_REQ3[i]->type;
|
|
|
+ item.modal = initMKReq.MKD_REQ3[i]->modal;
|
|
|
+ item.factory = initMKReq.MKD_REQ3[i]->factory;
|
|
|
+ item.version = initMKReq.MKD_REQ3[i]->version;
|
|
|
+
|
|
|
+ instanceReq.MKD_REQ3.push_back(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ instanceReq.MKD_REQ4.fingerPrint = initMKReq.MKD_REQ4.fingerPrint;
|
|
|
+ instanceReq.MKD_REQ4.fingerPrintSM = initMKReq.MKD_REQ4.fingerPrintSM;
|
|
|
+ instanceReq.MKD_REQ4.pinPadID = initMKReq.MKD_REQ4.pinPadID;
|
|
|
+ instanceReq.MKD_REQ4.publicKey = initMKReq.MKD_REQ4.publicKey;
|
|
|
+ instanceReq.MKD_REQ4.reserverd = initMKReq.MKD_REQ4.reserverd;
|
|
|
+
|
|
|
+ instanceReq.MKD_REQ5.isFirstSM = initMKReq.MKD_REQ5.isFirstSM;
|
|
|
+ instanceReq.MKD_REQ5.isSM = initMKReq.MKD_REQ5.isSM;
|
|
|
+
|
|
|
+ instanceReq.MKD_SMR2.branchNo = initMKReq.MKD_SMR2.branchNo;
|
|
|
+ instanceReq.MKD_SMR2.subBankNo = initMKReq.MKD_SMR2.subBankNo;
|
|
|
+ instanceReq.MKD_SMR2.kmcData = initMKReq.MKD_SMR2.kmcData;
|
|
|
+
|
|
|
+ struct InstanceAnsJson
|
|
|
+ {
|
|
|
+ string TMK;
|
|
|
+ string TPK;
|
|
|
+ string EDK;
|
|
|
+ string index;
|
|
|
+ string reserved;
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_REGISTER(TMK, TPK, EDK, index)
|
|
|
+ JSONCONVERT2OBJECT_MEMEBER_RENAME_REGISTER("tmk", "tpk", "edk", "index")
|
|
|
+
|
|
|
+
|
|
|
+ } instanceAns;
|
|
|
+
|
|
|
+ HttpClientResponseResult result;
|
|
|
+ HttpClientRequestConfig config(HttpRequestMethod::POST, m_entity->GetInitUrl().GetData());
|
|
|
+ config.SetChildUri("/api/initmk");
|
|
|
+ SP::Module::Restful::FulfillRequestJsonBody(&config, instanceReq);
|
|
|
+
|
|
|
+ RestfulClient client = RestfulClient::getInstance();
|
|
|
+ config.PreDo();
|
|
|
+ client.Do(&config, &result);
|
|
|
+ if (result.ResponseOK()) {
|
|
|
+
|
|
|
+ Dbg("InitializerInitMKTask Connect Success.");
|
|
|
+ SP::Module::Restful::CommResponseJson responseStatus;
|
|
|
+ SP::Module::Restful::GetStatusFromDebranchResponse(result.content, responseStatus);
|
|
|
+ if (!responseStatus.IsOperatedOK()) {
|
|
|
+ Dbg("update wk failed: %s", responseStatus.errorMsg.c_str());
|
|
|
+ m_entity->EndInitMK(ERR_INITIALIZER_INIT_EXCEPTION, responseStatus.errorMsg.c_str());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (m_entity->HasPinPad()) {
|
|
|
+ const bool testResult = SP::Module::Restful::ExtractDataFromDebranchResponse(result.content, instanceAns);
|
|
|
+ Dbg("ExtractDataFromDebranchResponse returned: %d", testResult);
|
|
|
+ if (m_entity->LoadKeysToPinPadACS(instanceAns.TMK, instanceAns.TPK, instanceAns.EDK, instanceAns.index) == Error_Succeed) {
|
|
|
+ m_entity->EndInitMK(Error_Succeed, "");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ m_entity->EndInitMK(ERR_INITIALIZER_INIT_EXCEPTION, "加载秘钥到密码键盘失败");//,待完善细化错误码oiltest
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ m_entity->EndInitMK(Error_Succeed, "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Dbg("post wk failed: %s", result.WhatError().c_str());
|
|
|
+ m_entity->EndInitMK(ERR_INITIALIZER_INIT_EXCEPTION, result.WhatError().c_str());
|
|
|
+ }
|
|
|
+
|
|
|
+#else
|
|
|
+
|
|
|
+ IHttpFunc* client;
|
|
|
+ client = create_http(m_fsm->HttpsLogCallBack);
|
|
|
+ initMKReq.m_bTransCode = false;
|
|
|
+ CInitlizerMKRet initMKRet;
|
|
|
+ initMKReq.m_url = m_entity->GetInitUrl();
|
|
|
+ initMKReq.m_url += "/api/initmk";
|
|
|
+ bool ret = client->Post(initMKReq, initMKRet);
|
|
|
+ Dbg("code=%d", initMKRet.m_sysCode);
|
|
|
+ if (ret) {
|
|
|
+ Dbg("InitializerInitMKTask Connect Success.");
|
|
|
+ if (initMKRet.m_userCode.compare(ACS_SUCCESS)) {
|
|
|
+ Dbg("update wk failed: %s", initMKRet.m_errMsg.c_str());
|
|
|
+ std::string errStr("#ACS#");
|
|
|
+ errStr += initMKRet.m_errMsg;
|
|
|
+ m_entity->EndInitMK(ERR_INITIALIZER_INIT_EXCEPTION, errStr.c_str());
|
|
|
+ SAFE_DELETE_HTTPCLIENT(client);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (m_entity->HasPinPad()) {
|
|
|
+ if (m_entity->LoadKeysToPinPadACS(initMKRet.data.TMK, initMKRet.data.TPK, initMKRet.data.EDK, initMKRet.data.index) == Error_Succeed)
|
|
|
+ m_entity->EndInitMK(Error_Succeed, "");
|
|
|
+ else
|
|
|
+ m_entity->EndInitMK(ERR_INITIALIZER_INIT_EXCEPTION, "加载秘钥到密码键盘失败");//,待完善细化错误码oiltest
|
|
|
+ }
|
|
|
+ else
|
|
|
+ m_entity->EndInitMK(Error_Succeed, "");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Dbg("UpdateWKTask Connect Failed.");
|
|
|
+ }
|
|
|
+ SAFE_DELETE_HTTPCLIENT(client);
|
|
|
+
|
|
|
+#endif //WITH_CPPRESTSDK
|
|
|
+
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
typedef struct _REG_TZI_FORMAT
|
|
|
{
|
|
|
LONG Bias;
|
|
|
@@ -33,6 +262,8 @@ typedef struct _REG_TZI_FORMAT
|
|
|
SYSTEMTIME DaylightDate;
|
|
|
} REG_TZI_FORMAT;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
void CAccessAuthSession::Handle_Regist(SpOnewayCallContext<AccessAuthService_Regist_Info>::Pointer ctx)
|
|
|
{
|
|
|
m_pEntity->Regist();
|
|
|
@@ -43,19 +274,16 @@ void CAccessAuthSession::Handle_Unregist(SpOnewayCallContext<AccessAuthService_U
|
|
|
m_pEntity->Unregist(ctx->Info.nReason, ctx->Info.nWay);
|
|
|
}
|
|
|
|
|
|
-void CAccessAuthSession::Handle_Reregist(SpOnewayCallContext<AccessAuthService_Reregist_Info>::Pointer ctx)
|
|
|
-{
|
|
|
- m_pEntity->Reregist();
|
|
|
-}
|
|
|
|
|
|
-void CAccessAuthSession::Handle_PushTerminalStage(SpOnewayCallContext<AccessAuthService_PushTerminalStage_Info>::Pointer ctx)
|
|
|
+void CAccessAuthSession::Handle_InitDev(SpReqAnsContext<AccessAuthService_InitDev_Req, AccessAuthService_InitDev_Ans>::Pointer ctx)
|
|
|
{
|
|
|
- m_pEntity->PushTerminalStage(ctx->Info.cNewStage, ctx->Info.dwNewStageTime, ctx->Info.cOldStage, ctx->Info.dwOldStageTime);
|
|
|
+ m_pEntity->InitDevice(ctx);
|
|
|
}
|
|
|
|
|
|
-void CAccessAuthSession::Handle_InitDev(SpReqAnsContext<AccessAuthService_InitDev_Req, AccessAuthService_InitDev_Ans>::Pointer ctx)
|
|
|
+void CAccessAuthSession::Handle_UpdateWK(SpOnewayCallContext<AccessAuthService_UpdateWK_Info>::Pointer ctx)
|
|
|
{
|
|
|
- m_pEntity->InitDevice(ctx);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setAPI("UpdateWK")("call Handle_UpdateWK");
|
|
|
+ m_pEntity->UpdateWK();
|
|
|
}
|
|
|
|
|
|
void CAccessAuthSession::Handle_SyncTime(SpOnewayCallContext<AccessAuthService_SyncTime_Info>::Pointer ctx)
|
|
|
@@ -63,6 +291,19 @@ void CAccessAuthSession::Handle_SyncTime(SpOnewayCallContext<AccessAuthService_S
|
|
|
m_pEntity->SyncTime();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+void CAccessAuthSession::Handle_InitializeNew(SpReqAnsContext<AccessAuthService_InitializeNew_Req, AccessAuthService_InitializeNew_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("StartInitializeNew")("Handle_InitializeNew");
|
|
|
+ m_pEntity->m_ctx = ctx;
|
|
|
+
|
|
|
+ m_pEntity->m_strUserID = ctx->Req.strUserID.GetData();
|
|
|
+ m_pEntity->m_strPassword = ctx->Req.strPassword.GetData();
|
|
|
+
|
|
|
+ m_pEntity->BeginInitMKACS();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
void CAccessAuthEntity::OnStarted()
|
|
|
{
|
|
|
//设置时区为北京标准时区
|
|
|
@@ -113,17 +354,17 @@ ErrorCodeEnum CAccessAuthEntity::Regist()
|
|
|
// 重新准入
|
|
|
ErrorCodeEnum CAccessAuthEntity::Reregist()
|
|
|
{
|
|
|
- m_FSM.PostEventFIFO(new FSMEvent(CAccessAuthFSM::Event_StartReregist));
|
|
|
+ //m_FSM.PostEventFIFO(new FSMEvent(CAccessAuthFSM::Event_StartReregist));
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
|
|
|
// 准入退出
|
|
|
ErrorCodeEnum CAccessAuthEntity::Unregist(int nReason, int nWay)
|
|
|
{
|
|
|
- FSMEvent *pEvent = new FSMEvent(CAccessAuthFSM::Event_StartUnregist);
|
|
|
+ /*FSMEvent *pEvent = new FSMEvent(CAccessAuthFSM::Event_StartUnregist);
|
|
|
pEvent->param1 = nReason;
|
|
|
pEvent->param2 = nWay;
|
|
|
- m_FSM.PostEventFIFO(pEvent);
|
|
|
+ m_FSM.PostEventFIFO(pEvent);*/
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
|
|
|
@@ -135,8 +376,8 @@ DWORD CAccessAuthEntity::SyncTime()
|
|
|
ErrorCodeEnum CAccessAuthEntity::PushTerminalStage(char cNewStage, DWORD dwNewStageTime, char cOldStage, DWORD dwOldStageTime)
|
|
|
{
|
|
|
Dbg("on PushTerminalStage, cNewStage: %c", cNewStage);
|
|
|
- CAccessAuthFSM::ReportStateEvent *pEvent = new CAccessAuthFSM::ReportStateEvent(cNewStage, dwNewStageTime, cOldStage, dwOldStageTime);
|
|
|
- m_FSM.PostEventFIFO(pEvent);
|
|
|
+ /*CAccessAuthFSM::ReportStateEvent *pEvent = new CAccessAuthFSM::ReportStateEvent(cNewStage, dwNewStageTime, cOldStage, dwOldStageTime);
|
|
|
+ m_FSM.PostEventFIFO(pEvent);*/
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
|
|
|
@@ -658,7 +899,7 @@ void CAccessAuthEntity::printPasswdError(){
|
|
|
string strErrMsg = "密钥集丢失,请重新初始化密钥!";
|
|
|
SetAuthErrMsg(strErrMsg.c_str());
|
|
|
GetFunction()->SetSysVar("AuthErrMsg", strErrMsg.c_str(), true);
|
|
|
- m_FSM.doWarnMsg( ERROR_ACCESSAUTH_OPENCRYPTCONTEXT, strErrMsg.c_str(),false, strErrMsg);
|
|
|
+ m_FSM.doWarnMsg( ERROR_ACCESSAUTH_OPENCRYPTCONTEXT, strErrMsg.c_str(),true, strErrMsg);
|
|
|
}
|
|
|
int Char2Int(char * ch) {
|
|
|
int num = 0;
|
|
|
@@ -676,7 +917,7 @@ bool CAccessAuthEntity::SaveAuthVerAndKey(int nAuthVer, BYTE *pKey)
|
|
|
|
|
|
if (m_nAuthVersion == 2)
|
|
|
{
|
|
|
- CSimpleString runInfoPath;
|
|
|
+ CSimpleString runInfoPath, iniPath;
|
|
|
auto rc = GetFunction()->GetPath("runinfo", runInfoPath);
|
|
|
if (rc != Error_Succeed) {
|
|
|
Dbg("GetPath runinfo error=%d.", rc);
|
|
|
@@ -684,20 +925,29 @@ bool CAccessAuthEntity::SaveAuthVerAndKey(int nAuthVer, BYTE *pKey)
|
|
|
}
|
|
|
|
|
|
char privateKey[BUF_SIZE] = { 0 };
|
|
|
- runInfoPath += SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "Initializer.ini";
|
|
|
+ iniPath = runInfoPath + SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "AccessAuthorization.ini";
|
|
|
+ //runInfoPath += SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "Initializer.ini";
|
|
|
|
|
|
#ifdef RVC_OS_WIN
|
|
|
GetPrivateProfileString("TerminalPD", "PrivateKey", "", privateKey, BUF_SIZE, runInfoPath.GetData());
|
|
|
#else
|
|
|
- Dbg("path ex:%s", runInfoPath.GetData());
|
|
|
- char* tmp = inifile_read_str(runInfoPath.GetData(),"TerminalPD", "PrivateKey", "");
|
|
|
+ Dbg("path ex:%s", iniPath.GetData());
|
|
|
+ char* tmp = inifile_read_str(iniPath.GetData(),"TerminalPD", "PrivateKey", "");
|
|
|
strcpy(privateKey, tmp);
|
|
|
delete tmp;
|
|
|
#endif // RVC_OS_WIN
|
|
|
|
|
|
if (strlen(privateKey) <= 0) {
|
|
|
- printPasswdError();
|
|
|
- return false;
|
|
|
+ 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;
|
|
|
+
|
|
|
+ if (strlen(privateKey) <= 0)
|
|
|
+ {
|
|
|
+ printPasswdError();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
Dbg("privateKey=%s,%d", privateKey, strlen(privateKey));
|
|
|
|
|
|
@@ -964,26 +1214,36 @@ bool CAccessAuthEntity::GetTerminalFingerPrint(BYTE *pBuf, int &nBufLen)
|
|
|
// 生成SM2密钥对,并导出公钥
|
|
|
bool CAccessAuthEntity::GetTerminalPublicKey(BYTE *pBuf, int &nBufLen)
|
|
|
{
|
|
|
- CSimpleString runInfoPath;
|
|
|
+ CSimpleString runInfoPath, iniPath;
|
|
|
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 "Initializer.ini";
|
|
|
+
|
|
|
+ iniPath = runInfoPath + SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "AccessAuthorization.ini";
|
|
|
+ //runInfoPath += SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "Initializer.ini";
|
|
|
char publicKey[BUF_SIZE] = { 0 };
|
|
|
|
|
|
#ifdef RVC_OS_WIN
|
|
|
GetPrivateProfileString("TerminalPD", "PublicKey", "", publicKey, BUF_SIZE, runInfoPath.GetData());
|
|
|
#else
|
|
|
- char* tmp = inifile_read_str(runInfoPath.GetData(), "TerminalPD", "PublicKey", "");
|
|
|
+ char* tmp = inifile_read_str(iniPath.GetData(), "TerminalPD", "PublicKey", "");
|
|
|
strcpy(publicKey, tmp);
|
|
|
delete tmp;
|
|
|
#endif // RVC_OS_WIN
|
|
|
if (strlen(publicKey) <= 0) {
|
|
|
- Dbg("读取公钥失败,公钥长度小于等于零!");
|
|
|
- printPasswdError();
|
|
|
- return false;
|
|
|
+ iniPath = runInfoPath + SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "Initializer.ini";
|
|
|
+ char* tmp2 = inifile_read_str(iniPath.GetData(), "TerminalPD", "PublicKey", "");
|
|
|
+ strcpy(publicKey, tmp2);
|
|
|
+ delete tmp2;
|
|
|
+
|
|
|
+ if (strlen(publicKey) <= 0)
|
|
|
+ {
|
|
|
+ Dbg("读取公钥失败,公钥长度小于等于零!");
|
|
|
+ printPasswdError();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
Dbg("publickey=%s,%d",publicKey,strlen(publicKey));
|
|
|
|
|
|
@@ -995,6 +1255,119 @@ bool CAccessAuthEntity::GetTerminalPublicKey(BYTE *pBuf, int &nBufLen)
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+// 生成RSA密钥对,并导出公钥
|
|
|
+bool CAccessAuthEntity::GetTerminalPublicKey(BYTE *pBuf, int &nBufLen,string &pubkey)
|
|
|
+{
|
|
|
+ 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);
|
|
|
+ pubkey = pEncode;
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pubkey = publicKey;
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
DWORD CAccessAuthEntity::InitDevice(SpReqAnsContext<AccessAuthService_InitDev_Req, AccessAuthService_InitDev_Ans>::Pointer &ctx)
|
|
|
{
|
|
|
return m_FSM.InitDevice(ctx);
|
|
|
@@ -1436,6 +1809,356 @@ bool CAccessAuthEntity::IsMachineTypeConfigurePinPad(CSimpleStringA strMachineTy
|
|
|
else
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+void CAccessAuthEntity::UpdateWK()
|
|
|
+{
|
|
|
+ m_FSM.UpdateWK();
|
|
|
+}
|
|
|
+
|
|
|
+void CAccessAuthEntity::BeginInitMKACS()
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ // 1:3des only; 2: sm4 only; 3: both 3des and sm4
|
|
|
+ int nCapability = GetPinPadCapability();
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("BeginInitMKACS")("pinpad capability: %d", nCapability);
|
|
|
+
|
|
|
+ CSmartPointer<IConfigInfo> spConfig;
|
|
|
+ ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
|
|
|
+ if (Error_Succeed == Error)
|
|
|
+ {
|
|
|
+ Error = spConfig->ReadConfigValue("AccessAuthorization", "HostInitUrl", m_strInitUrl);
|
|
|
+ if (Error_Succeed == Error)
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("BeginLoginACS")("get InitUrl=%s from CenterSetting.ini", m_strInitUrl);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("BeginLoginACS")("get InitUrl from CenterSetting.ini failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ CSmartPointer<InitializerInitMKTask> initUpdateWKTask = new InitializerInitMKTask(&this->m_FSM, this);
|
|
|
+ GetFunction()->PostThreadPoolTask(initUpdateWKTask.GetRawPointer());
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ErrorCodeEnum CAccessAuthEntity::LoadKeysToPinPadACS(string TMK, string TPK, string EDK, string index)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ //获取私钥
|
|
|
+ CSmartPointer<IConfigInfo> pConfigRun;
|
|
|
+ auto rc = GetFunction()->OpenConfig(Config_Run, pConfigRun);
|
|
|
+ if (rc != Error_Succeed) {
|
|
|
+ Dbg("OpenConfig Config_Run error=%d.", rc);
|
|
|
+ return Error_Unexpect;
|
|
|
+ }
|
|
|
+ CSimpleStringA csPrivateKey("");
|
|
|
+ pConfigRun->ReadConfigValue("TerminalPD", "PrivateKey", csPrivateKey);
|
|
|
+ Dbg("privateKey len:%d", csPrivateKey.GetLength());
|
|
|
+
|
|
|
+ int decodedPrivateKeyLen;
|
|
|
+
|
|
|
+ char* pDecodedPrivateKey = Hex2Str(csPrivateKey.GetData(), decodedPrivateKeyLen);
|
|
|
+ Dbg("decodedPrivateKeyLen=%d", decodedPrivateKeyLen);
|
|
|
+
|
|
|
+ char pDecryptPrivateKey[BUF_SIZE] = { 0 };
|
|
|
+ int decryprtLen = BUF_SIZE;
|
|
|
+ if (!DecWithSM4_ECB("s5da69gnh4!963@6s5da69gnh4!963@6", (BYTE*)pDecodedPrivateKey, decodedPrivateKeyLen, (BYTE*)pDecryptPrivateKey, &decryprtLen)) {
|
|
|
+ Dbg("DecWithSM4_ECB decrypt privateKey error.");
|
|
|
+ delete[] pDecodedPrivateKey;
|
|
|
+ return Error_Unexpect;
|
|
|
+ }
|
|
|
+ delete[] pDecodedPrivateKey;
|
|
|
+ Dbg("DecWithSM4_ECB succeess.len:%d.", decryprtLen);
|
|
|
+
|
|
|
+ char pPlainTMK[BUF_SIZE], pPlainTPK[BUF_SIZE], pPlainEDK[BUF_SIZE];
|
|
|
+ memset(pPlainTMK, 0, BUF_SIZE);
|
|
|
+ memset(pPlainTPK, 0, BUF_SIZE);
|
|
|
+ memset(pPlainEDK, 0, BUF_SIZE);
|
|
|
+ int plainKeyLen = BUF_SIZE;
|
|
|
+
|
|
|
+ char* pxx = new char[1024];
|
|
|
+ memset(pxx, 0, 1024);
|
|
|
+ HexBuf2StrBuf((BYTE*)pDecryptPrivateKey, &pxx, decryprtLen);
|
|
|
+ PBYTE pBt = new BYTE[512];
|
|
|
+ memset(pBt, 0, 512);
|
|
|
+ StrBuf2HexBuf(TMK.c_str(), &pBt);
|
|
|
+
|
|
|
+ if (!DecWithSM2PriKey(pBt, TMK.size() / 2, (BYTE*)pPlainTMK, &plainKeyLen, (BYTE*)pDecryptPrivateKey, decryprtLen)) {
|
|
|
+ Dbg("使用私钥解密TMK失败!");
|
|
|
+ return Error_Unexpect;
|
|
|
+ }
|
|
|
+ //char* pEncodeTPK = MyBase64::Str2Hex(TPK.c_str(), TPK.size());
|
|
|
+ PBYTE pTPK = new BYTE[512];
|
|
|
+ memset(pTPK, 0, 512);
|
|
|
+ int len = StrBuf2HexBuf(TPK.c_str(), &pTPK);
|
|
|
+ plainKeyLen = BUF_SIZE;
|
|
|
+ Dbg("001,len:%d", len);
|
|
|
+ if (!DecWithSM2PriKey(pTPK, TPK.size() / 2, (BYTE*)pPlainTPK, &plainKeyLen, (BYTE*)pDecryptPrivateKey, decryprtLen)) {
|
|
|
+ Dbg("使用私钥解密TPK失败!");
|
|
|
+ //delete[]pEncodeTPK;
|
|
|
+ return Error_Unexpect;
|
|
|
+ }
|
|
|
+ //char* pEncodeEDK = MyBase64::Str2Hex(EDK.c_str(), EDK.size());
|
|
|
+ PBYTE pEDK = new BYTE[512];
|
|
|
+ memset(pEDK, 0, 512);
|
|
|
+ StrBuf2HexBuf(EDK.c_str(), &pEDK);
|
|
|
+ plainKeyLen = BUF_SIZE;
|
|
|
+ if (!DecWithSM2PriKey(pEDK, EDK.size() / 2, (BYTE*)pPlainEDK, &plainKeyLen, (BYTE*)pDecryptPrivateKey, decryprtLen)) {
|
|
|
+ Dbg("使用私钥解密EDK失败!");
|
|
|
+ //delete[]pEncodeEDK;
|
|
|
+ return Error_Unexpect;
|
|
|
+ }
|
|
|
+ Dbg("解密秘钥成功");
|
|
|
+ //加载到密码键盘
|
|
|
+ Dbg("load sm key to pinpad...");
|
|
|
+
|
|
|
+ PinPadService_ClientBase* pPinPad = new PinPadService_ClientBase(this);
|
|
|
+ rc = pPinPad->Connect();
|
|
|
+ if (rc == Error_Succeed)
|
|
|
+ {
|
|
|
+ PinPadService_LoadKeysSM_Req req = {};
|
|
|
+ req.initializeflag = true;
|
|
|
+ req.smflag = 1;
|
|
|
+
|
|
|
+
|
|
|
+ Dbg("使用云接口获取的KMC密钥");
|
|
|
+ req.masterkey = pPlainTMK;
|
|
|
+ req.workingkey1 = pPlainTPK;
|
|
|
+ req.workingkey2 = pPlainEDK;
|
|
|
+ req.reserved3 = index.c_str();
|
|
|
+
|
|
|
+ if (req.initializeflag) Dbg("initializeflag is true");
|
|
|
+ else Dbg("initializeflag is false");
|
|
|
+ Dbg("req.smflag=%d", req.smflag);
|
|
|
+ Dbg("req.masterkey=%s", req.masterkey.GetData());
|
|
|
+ Dbg("req.workingkey1=%s", req.workingkey1.GetData());
|
|
|
+ Dbg("req.workingkey2=%s", req.workingkey2.GetData());
|
|
|
+ Dbg("req.reserved3=%s", req.reserved3.GetData());
|
|
|
+
|
|
|
+ PinPadService_LoadKeysSM_Ans ans = {};
|
|
|
+ rc = pPinPad->LoadKeysSM(req, ans, 30000);
|
|
|
+ if (rc == Error_Succeed)
|
|
|
+ Dbg("load sm key to pinpad succ");
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Dbg("load sm key to pinpad failed.");
|
|
|
+ return Error_Unexpect;
|
|
|
+ //SetAuthErrMsg("加载SM密钥到PinPad失败");
|
|
|
+ //doWarnMsg(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
|
|
|
+ {
|
|
|
+ Dbg("oiltest connect to pinpad failed.");
|
|
|
+ return Error_Unexpect;
|
|
|
+ }
|
|
|
+
|
|
|
+ return Error_Succeed;
|
|
|
+}
|
|
|
+
|
|
|
+bool CAccessAuthEntity::SendInitMKReqACS(CInitlizerMKReq& initMKReq)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ CSmartPointer<IEntityFunction> pFunc = GetFunction();
|
|
|
+
|
|
|
+ //auto pEntity = ((CInitializerEntity*)m_pEntity);
|
|
|
+
|
|
|
+ // 如果有外置PinPad,则需要初始化主密钥
|
|
|
+ if (HasPinPad())
|
|
|
+ {
|
|
|
+ CSmartPointer<IConfigInfo> pConfig;
|
|
|
+ DWORD rc = pFunc->OpenConfig(Config_CenterSetting, pConfig);
|
|
|
+ if (rc != Error_Succeed)
|
|
|
+ {
|
|
|
+ LogWarn(Severity_Middle, (ErrorCodeEnum)rc, ERR_INITIALIZER_READ_WRITE_FILE,
|
|
|
+ GetOutPutStr("%s%08X%s%s", "OpenConfig", rc, "File", "Config_CenterSetting").c_str());
|
|
|
+ rc = ERR_INITIALIZER_READ_WRITE_FILE;
|
|
|
+ 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_READ_WRITE_FILE,
|
|
|
+ GetOutPutStr("%s%08X%s%s", "ReadConfigValue", rc, "File", "SubBankNo & BranchNo").c_str());
|
|
|
+ rc = ERR_INITIALIZER_READ_WRITE_FILE;
|
|
|
+ return rc;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1:3des only; 2: sm4 only; 3: both 3des and sm4
|
|
|
+ int nCapability = GetPinPadCapability();
|
|
|
+ Dbg("pinpad capability: %d", nCapability);
|
|
|
+
|
|
|
+ //gui console中,用户桌面,蓝牙多合一绑定时的初始化会重置kmc密钥,自动初始化不会重置密钥,自动初始化的目的仅用在非国密
|
|
|
+ //版本到国密版本的升级无缝切换
|
|
|
+ //if (m_bHandWork && !m_afterSMIsFirst) {
|
|
|
+ if (false) {//oiltest@20211113
|
|
|
+ Dbg("初始化开始重置密钥。。。");
|
|
|
+ if (nCapability == 1 || nCapability == 3)
|
|
|
+ {
|
|
|
+ // support des key
|
|
|
+ initMKReq.MKD_REQ2.branchNo = strSubBankNo;
|
|
|
+ initMKReq.MKD_REQ2.subBankNo = strBranchNo;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (nCapability == 2 || nCapability == 3)
|
|
|
+ {
|
|
|
+ // support sm key
|
|
|
+ initMKReq.MKD_SMR2.branchNo = strSubBankNo;
|
|
|
+ initMKReq.MKD_SMR2.subBankNo = strBranchNo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Dbg("has no pinpad, not need init MK");
|
|
|
+ }
|
|
|
+
|
|
|
+ bool bHasPinPad = false;
|
|
|
+ CSimpleStringA strPinPadID = "", strDeviceID = "";
|
|
|
+ int nRet = GetPinPadIDAndDeviceID(strPinPadID, strDeviceID, bHasPinPad);
|
|
|
+ Dbg("GetPinPadIDAndDeviceID ret: %d, PinPadID: %s, DeviceID: %s", nRet, (const char*)strPinPadID, (const char*)strDeviceID);
|
|
|
+ // 从系统获取设备信息和硬件信息
|
|
|
+ // 变长结构初始化
|
|
|
+ char buf2[512];
|
|
|
+ memset(buf2, 0, 512);
|
|
|
+
|
|
|
+ CSystemStaticInfo si;
|
|
|
+ pFunc->GetSystemStaticInfo(si);
|
|
|
+ initMKReq.MKD_NEW1.terminalNo = si.strTerminalID;
|
|
|
+ initMKReq.MKD_NEW1.installVersion = si.InstallVersion.ToString();
|
|
|
+ if (nRet == 2 || nRet == 3) {
|
|
|
+ initMKReq.MKD_NEW1.padDeviceID = strDeviceID;
|
|
|
+ }
|
|
|
+
|
|
|
+ initMKReq.MKD_NEW1.machineType = si.strMachineType;
|
|
|
+ initMKReq.MKD_NEW1.site = si.strSite;
|
|
|
+ BYTE xIP[64] = {};
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ hostent* ent = gethostbyname(NULL);
|
|
|
+ if (ent && ent->h_addr_list[0] != NULL)
|
|
|
+ {
|
|
|
+ int i = 0;
|
|
|
+ for (; ent->h_addr_list[i] != NULL; ++i)
|
|
|
+ {
|
|
|
+ struct in_addr* in = (struct in_addr*)ent->h_addr_list[i];
|
|
|
+ if (in->S_un.S_un_b.s_b1 == 99 || in->S_un.S_un_b.s_b1 == 10)
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ent->h_addr_list[i] == NULL)
|
|
|
+ i = 0;
|
|
|
+
|
|
|
+ auto in = (struct in_addr*)ent->h_addr_list[i];
|
|
|
+
|
|
|
+ sprintf(xIP, "%d.%d.%d.%d", in->S_un.S_un_b.s_b1, in->S_un.S_un_b.s_b2, in->S_un.S_un_b.s_b3, in->S_un.S_un_b.s_b4);
|
|
|
+ initMKReq.MKD_NEW1.ip = xIP;
|
|
|
+ Dbg("ip:%s", xIP);
|
|
|
+ }
|
|
|
+#else
|
|
|
+ char ip[32] = { 0 };
|
|
|
+ if (getIPFromLinux(ip)) Dbg("Get IP From Linux Error ex.");
|
|
|
+ else {
|
|
|
+ if (ip2byte(ip, xIP)) Dbg("Ip 2 Byte Error");
|
|
|
+ else {
|
|
|
+ for (int i = 0; i < 4; i++) {
|
|
|
+ Dbg("ip[%d]=%d", i, xIP[i]);
|
|
|
+ }
|
|
|
+ char strIP[64];
|
|
|
+ memset(strIP, 0, 64);
|
|
|
+ sprintf(strIP, "%d.%d.%d.%d", xIP[0], xIP[1], xIP[2], xIP[3]);
|
|
|
+ initMKReq.MKD_NEW1.ip = strIP;
|
|
|
+ }
|
|
|
+ }
|
|
|
+#endif //RVC_OS_WIN
|
|
|
+
|
|
|
+ initMKReq.MKD_NEW1.enrolGPS = "00000A4500000A4E";//oiltmp
|
|
|
+ initMKReq.MKD_NEW1.enrolAddr = si.strEnrolAddr;
|
|
|
+
|
|
|
+ initMKReq.MKD_REQ3[0]->modal = "";
|
|
|
+ initMKReq.MKD_REQ3[0]->factory = "";
|
|
|
+ initMKReq.MKD_REQ3[0]->type = "";
|
|
|
+ initMKReq.MKD_REQ3[0]->version = "";
|
|
|
+ BYTE fingerPrint[32] = { 0 };
|
|
|
+ int nBufLen = sizeof(fingerPrint);
|
|
|
+ if (!GetTerminalFingerPrint(fingerPrint, nBufLen))
|
|
|
+ {
|
|
|
+ LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_TERMINAL_FINGERPRINT,
|
|
|
+ GetOutPutStr("%s%s", "GetTerminalFingerPrint", "False").c_str());
|
|
|
+ return ERR_INITIALIZER_GET_TERMINAL_FINGERPRINT;
|
|
|
+ }
|
|
|
+ string xFingerPrint = ConvertBytesToHexStr(fingerPrint, nBufLen);
|
|
|
+ initMKReq.MKD_REQ4.fingerPrint = xFingerPrint.substr(0, 32);
|
|
|
+ initMKReq.MKD_REQ4.fingerPrintSM = xFingerPrint.substr(32, 64);
|
|
|
+
|
|
|
+ BYTE xPublicKey[148];
|
|
|
+ nBufLen = sizeof(xPublicKey);
|
|
|
+ Dbg("开始获取公钥。。。");
|
|
|
+ memset(xPublicKey, 0, nBufLen);
|
|
|
+ Dbg("nBufLen=%d", nBufLen);
|
|
|
+ if (!GetTerminalPublicKey(xPublicKey, nBufLen, initMKReq.MKD_REQ4.publicKey))
|
|
|
+ {
|
|
|
+ LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_TERMINAL_PUBKEY,
|
|
|
+ GetOutPutStr("%s%s", "GetTerminalPublicKey", "False").c_str());
|
|
|
+ return ERR_INITIALIZER_GET_TERMINAL_PUBKEY;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (nRet == 1 || nRet == 3)
|
|
|
+ //strncpy(req4.PinPadID, (const char*)strPinPadID, sizeof(req4.PinPadID) - 1);
|
|
|
+ initMKReq.MKD_REQ4.pinPadID = strPinPadID;
|
|
|
+
|
|
|
+ //国密改造
|
|
|
+ initMKReq.MKD_REQ5.isFirstSM = GetOrSetIsFirstSM(0);
|
|
|
+ initMKReq.MKD_REQ5.isSM = 1;
|
|
|
+ Dbg("rinitMKReq.MKD_REQ5.isFirstSM=%d", initMKReq.MKD_REQ5.isFirstSM);
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+void CAccessAuthEntity::EndInitMK(DWORD rc, const char *pszErrMsg)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("EndInitMK")("EndInitMK:rc:%d,errMsg:%s", rc, pszErrMsg);
|
|
|
+ GetFunction()->KillTimer(22);
|
|
|
+
|
|
|
+ m_strLastErrMsg = pszErrMsg;
|
|
|
+
|
|
|
+ if (rc != Error_Succeed)
|
|
|
+ {
|
|
|
+ LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_INIT_MK,
|
|
|
+ GetOutPutStr("%s%08X%s%s", "EndInitMK", rc,"pszErrMsg", pszErrMsg).c_str());
|
|
|
+
|
|
|
+ GetFunction()->ShowFatalError(pszErrMsg);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("EndInitMK")("初始化成功。。。");
|
|
|
+ }
|
|
|
+
|
|
|
+ m_eErrNum = rc;
|
|
|
+
|
|
|
+ bool bSuc = rc == Error_Succeed;
|
|
|
+
|
|
|
+ // 通知UI窗口
|
|
|
+ if (m_ctx != NULL) {
|
|
|
+ Dbg("success");
|
|
|
+ m_ctx->Ans.Errcode = rc;
|
|
|
+ m_ctx->Ans.ErrMsg = m_strLastErrMsg;
|
|
|
+ m_ctx->Answer(Error_Succeed);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
SP_BEGIN_ENTITY_MAP()
|
|
|
SP_ENTITY(CAccessAuthEntity)
|
|
|
SP_END_ENTITY_MAP()
|