|
@@ -32,9 +32,9 @@ using namespace PinPad;
|
|
|
#define BUF_SIZE 256
|
|
|
|
|
|
extern int HexBuf2StrBuf(PBYTE hexBuf, char** strBuf, DWORD len);
|
|
|
-extern int StrBuf2HexBuf(LPCTSTR strBuf, PBYTE * hexBuf);
|
|
|
+extern int StrBuf2HexBuf(LPCTSTR strBuf, PBYTE* hexBuf);
|
|
|
|
|
|
-struct InitializerInitMKTask : ITaskSp
|
|
|
+struct InitializerInitMKTask : ITaskSp
|
|
|
{
|
|
|
CAccessAuthFSM* m_fsm;
|
|
|
CAccessAuthEntity* m_entity;
|
|
@@ -218,35 +218,40 @@ typedef struct _REG_TZI_FORMAT
|
|
|
|
|
|
void CAccessAuthSession::Handle_Regist(SpOnewayCallContext<AccessAuthService_Regist_Info>::Pointer ctx)
|
|
|
{
|
|
|
+ DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setAPI("Regist")("call Handle_Regist");
|
|
|
m_pEntity->Regist();
|
|
|
}
|
|
|
|
|
|
void CAccessAuthSession::Handle_UpdateWK(SpOnewayCallContext<AccessAuthService_UpdateWK_Info>::Pointer ctx)
|
|
|
{
|
|
|
+ DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setAPI("UpdateWK")("call Handle_UpdateWK");
|
|
|
m_pEntity->UpdateWK();
|
|
|
}
|
|
|
|
|
|
void CAccessAuthSession::Handle_InitializeNew(SpReqAnsContext<AccessAuthService_InitializeNew_Req, AccessAuthService_InitializeNew_Ans>::Pointer ctx)
|
|
|
{
|
|
|
+ DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
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();
|
|
|
+ m_pEntity->BeginInitMKACS();
|
|
|
}
|
|
|
|
|
|
void CAccessAuthSession::Handle_InitDev(SpReqAnsContext<AccessAuthService_InitDev_Req, AccessAuthService_InitDev_Ans>::Pointer ctx)
|
|
|
{
|
|
|
+ DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setAPI("InitDevice")("call Handle_InitDev");
|
|
|
m_pEntity->InitDevice(ctx);
|
|
|
}
|
|
|
|
|
|
void CAccessAuthSession::Handle_GetNetMsg(SpReqAnsContext<AccessAuthService_GetNetMsg_Req, AccessAuthService_GetNetMsg_Ans>::Pointer ctx)
|
|
|
{
|
|
|
+ DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
m_pEntity->GetNetMsg(ctx);
|
|
|
}
|
|
|
|
|
@@ -268,7 +273,7 @@ void CAccessAuthEntity::OnStarted()
|
|
|
auto rc = GetFunction()->GetSystemStaticInfo(m_info);
|
|
|
if (rc != Error_Succeed)
|
|
|
{
|
|
|
- strErrMsg = "HasPinPad()=>GetSystemStaticInfo() fail";
|
|
|
+ strErrMsg = "GetSystemStaticInfo fail";
|
|
|
SetAuthErrMsg((const char*)strErrMsg);
|
|
|
|
|
|
m_FSM.doWarnMsg(ERR_ACCESSAUTH_GET_SYSTEM_STATIC_INFO,
|
|
@@ -317,7 +322,7 @@ ErrorCodeEnum CAccessAuthEntity::Regist()
|
|
|
m_FSM.PostEventFIFO(new FSMEvent(CAccessAuthFSM::Event_StartRegist));
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
string CAccessAuthEntity::ByteArrayToHexStr(BYTE *pBuf, int nBufLen)
|
|
|
{
|
|
|
char szBuf[1024];
|
|
@@ -358,7 +363,7 @@ DWORD CAccessAuthEntity::CreateSM2KeyPair(CBlob &pubKey, CBlob &priKey)
|
|
|
CSmartPointer<IEntityFunction> spFunction = this->GetFunction();
|
|
|
|
|
|
m_FSM.doWarnMsg(ERR_ACCESSAUTH_CREATE_RSA_KEY_PAIR,
|
|
|
- GetOutPutStr("%s%s","CreateRsaKeyPair","False").c_str(), "创建SM2密钥对失败");
|
|
|
+ GetOutPutStr("%s%s","CreateRsaKeyPair","False").c_str(), true, "创建SM2密钥对失败");
|
|
|
DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI("CreateSM2KeyPair")("创建SM2密钥对失败");
|
|
|
return ERR_ACCESSAUTH_CREATE_RSA_KEY_PAIR;
|
|
|
}
|
|
@@ -394,7 +399,7 @@ DWORD CAccessAuthEntity::SaveSM2KeyPair(const CBlob &pubKey, const CBlob &priKey
|
|
|
req.pub_key = pubKey;
|
|
|
req.pri_key = priKey;
|
|
|
TokenService_SetKeyPair_Ans ans;
|
|
|
- rc = (*pTokenServiceClient)(EntityResource::getLink().upgradeLink())->SetKeyPair(req, ans, 3000);
|
|
|
+ rc = pTokenServiceClient->SetKeyPair(req, ans, 3000);
|
|
|
pTokenServiceClient->GetFunction()->CloseSession();
|
|
|
if (rc != Error_Succeed)
|
|
|
{
|
|
@@ -438,7 +443,7 @@ ErrorCodeEnum CAccessAuthEntity::SaveTokenAndSharedSK(const CBlob &token, const
|
|
|
TokenService_SetToken_Req req = {};
|
|
|
req.token = token;
|
|
|
TokenService_SetToken_Ans ans;
|
|
|
- rc = (*pTokenServiceClient)(EntityResource::getLink().upgradeLink())->SetToken(req, ans, 5000);
|
|
|
+ rc = pTokenServiceClient->SetToken(req, ans, 5000);
|
|
|
if (rc == Error_Succeed)
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SetToken")
|
|
|
("save token succ, token: [%s]", ByteArrayToHexStr((BYTE*)token.m_pData, token.m_iLength).c_str());
|
|
@@ -456,7 +461,7 @@ ErrorCodeEnum CAccessAuthEntity::SaveTokenAndSharedSK(const CBlob &token, const
|
|
|
TokenService_SetSharedSK_Req req2 = {};
|
|
|
req2.ssk = sharedSK;
|
|
|
TokenService_SetSharedSK_Ans ans2 = {};
|
|
|
- rc = (*pTokenServiceClient)(EntityResource::getLink().upgradeLink())->SetSharedSK(req2, ans2, 5000);
|
|
|
+ rc = pTokenServiceClient->SetSharedSK(req2, ans2, 5000);
|
|
|
if (rc == Error_Succeed)
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SetSharedSK")
|
|
|
("save shared session key succ");
|
|
@@ -557,10 +562,10 @@ int CAccessAuthEntity::GetPinPadCapability()
|
|
|
PinPadService_QueryFunc_Req req;
|
|
|
PinPadService_QueryFunc_Ans ans;
|
|
|
|
|
|
- rc = (*pPinPad)(EntityResource::getLink().upgradeLink())->QueryFunc(req,ans, 3000);
|
|
|
+ rc = pPinPad->QueryFunc(req, ans, 3000);
|
|
|
if (rc == Error_Succeed)
|
|
|
{
|
|
|
- nCapability = ans.reserved1;
|
|
|
+ nCapability = ans.encryptkey;
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("QueryFunc")
|
|
|
("QueryFunc from pinpad succ, nCapability[%d]", nCapability);
|
|
|
}
|
|
@@ -618,7 +623,7 @@ bool CAccessAuthEntity::SaveAuthKey(BYTE *pKey)
|
|
|
char privateKey[BUF_SIZE] = { 0 };
|
|
|
#ifdef RVC_OS_WIN
|
|
|
iniPath = runInfoPath + "\\runcfg\\AccessAuthorization.ini";
|
|
|
- GetPrivateProfileString("TerminalPD", "PrivateKey", "", privateKey, BUF_SIZE, runInfoPath.GetData());
|
|
|
+ GetPrivateProfileString("TerminalPD", "PrivateKey", "", privateKey, BUF_SIZE, iniPath.GetData());
|
|
|
#else
|
|
|
iniPath = runInfoPath + SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "AccessAuthorization.ini";
|
|
|
Dbg("path ex:%s", iniPath.GetData());
|
|
@@ -643,14 +648,14 @@ bool CAccessAuthEntity::SaveAuthKey(BYTE *pKey)
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
int decodedPrivateKeyLen;
|
|
|
|
|
|
#ifdef RVC_OS_WIN
|
|
|
char* pDecodedPrivateKey = MyBase64::Hex2Str(privateKey, decodedPrivateKeyLen);
|
|
|
#else
|
|
|
char* pDecodedPrivateKey = Hex2Str(privateKey, decodedPrivateKeyLen);
|
|
|
-#endif // RVC_OS_WIN
|
|
|
+#endif // RVC_OS_WIN
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SaveAuthVerAndKey")
|
|
|
("privateKey len:%d, decodedPrivateKeyLen=%d", strlen(privateKey), decodedPrivateKeyLen);
|
|
|
|
|
@@ -671,7 +676,11 @@ bool CAccessAuthEntity::SaveAuthKey(BYTE *pKey)
|
|
|
char pKeyLen[4] = { 0 };
|
|
|
memcpy(pKeyLen, pKey, 4);
|
|
|
int kenLen = Char2Int(pKeyLen);
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ char* pEncodeKey = MyBase64::Str2Hex((char*)pKey,kenLen + 4);
|
|
|
+#else
|
|
|
char* pEncodeKey = Str2Hex((char*)pKey, kenLen + 4);
|
|
|
+#endif
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SaveAuthVerAndKey")
|
|
|
("kenLen=%d", kenLen);
|
|
|
delete pEncodeKey;
|
|
@@ -726,13 +735,15 @@ ErrorCodeEnum CAccessAuthEntity::EncryptDataWithSessionKey(const CBlob &raw, CBl
|
|
|
int pEncDataSize = 1024;
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("EncryptDataWithSessionKey")
|
|
|
("pEncDataSize=%d", pEncDataSize);
|
|
|
-
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ char* pPlainInfo = MyBase64::Str2Hex((char*)raw.m_pData, raw.m_iLength);
|
|
|
+#else
|
|
|
char* pPlainInfo = Str2Hex((char*)raw.m_pData, raw.m_iLength);
|
|
|
+#endif
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("EncryptDataWithSessionKey")
|
|
|
("raw Length=%d", raw.m_iLength);
|
|
|
delete[] pPlainInfo;
|
|
|
|
|
|
- //char *sessionKey = Str2Hex((char*)m_AuthSessionKey, KEY_SIZE);
|
|
|
char sessionKey[KEY_SIZE] = { 0 };
|
|
|
memcpy(sessionKey,m_AuthSessionKey,KEY_SIZE);
|
|
|
#ifdef RVC_OS_WIN
|
|
@@ -912,7 +923,7 @@ struct PublicKeyBlob
|
|
|
// 生成SM2密钥对,并导出公钥
|
|
|
bool CAccessAuthEntity::GetTerminalPublicKey(BYTE *pBuf, int &nBufLen)
|
|
|
{
|
|
|
- CSimpleString runInfoPath, iniPath;
|
|
|
+ CSimpleStringA runInfoPath, iniPath;
|
|
|
auto rc = GetFunction()->GetPath("runinfo", runInfoPath);
|
|
|
if (rc != Error_Succeed) {
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")
|
|
@@ -920,7 +931,7 @@ bool CAccessAuthEntity::GetTerminalPublicKey(BYTE *pBuf, int &nBufLen)
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- char publicKey[BUF_SIZE] = { 0 };
|
|
|
+ char publicKey[BUF_SIZE] = { 0 };
|
|
|
#ifdef RVC_OS_WIN
|
|
|
iniPath = runInfoPath + "\\runcfg\\AccessAuthorization.ini";
|
|
|
GetPrivateProfileString("TerminalPD", "PublicKey", "", publicKey, BUF_SIZE, iniPath.GetData());
|
|
@@ -964,13 +975,13 @@ bool CAccessAuthEntity::GetTerminalPublicKey(BYTE *pBuf, int &nBufLen)
|
|
|
}
|
|
|
|
|
|
// 生成RSA密钥对,并导出公钥
|
|
|
-bool CAccessAuthEntity::GetTerminalPublicKey(BYTE *pBuf, int &nBufLen,string &pubkey)
|
|
|
+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);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("GetPath runinfo error=%d.",rc);
|
|
|
return false;
|
|
|
}
|
|
|
#ifdef RVC_OS_WIN
|
|
@@ -981,7 +992,7 @@ bool CAccessAuthEntity::GetTerminalPublicKey(BYTE *pBuf, int &nBufLen,string &pu
|
|
|
if (!CreateDirectory(runInfoPath.GetData(), NULL))
|
|
|
{
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("Create %s dir failed!", runInfoPath.GetData());
|
|
|
-}
|
|
|
+ }
|
|
|
}
|
|
|
#else
|
|
|
runInfoPath += SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR;
|
|
@@ -989,7 +1000,7 @@ bool CAccessAuthEntity::GetTerminalPublicKey(BYTE *pBuf, int &nBufLen,string &pu
|
|
|
{
|
|
|
if (dir_create(runInfoPath.GetData()) != 0)
|
|
|
{
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("Create %s dir failed!", runInfoPath.GetData());;
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("Create %s dir failed!", runInfoPath.GetData());
|
|
|
}
|
|
|
}
|
|
|
#endif // RVC_OS_WIN
|
|
@@ -1100,10 +1111,10 @@ int CAccessAuthEntity::GetPinPadIDAndDeviceID(CSimpleStringA &strPinPadID, CSimp
|
|
|
PinPadService_GetDevInfo_Req req = {};
|
|
|
PinPadService_GetDevInfo_Ans ans = {};
|
|
|
|
|
|
- rc = (*pPinPadClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(req, ans, 3000);
|
|
|
- if (rc == Error_Succeed)
|
|
|
+ rc = pPinPadClient->GetDevInfo(req, ans, 3000);
|
|
|
+ if (rc == Error_Succeed)
|
|
|
{
|
|
|
- if (ans.state == DEVICE_STATUS_NORMAL)
|
|
|
+ if (ans.state == DEVICE_STATUS_NORMAL)
|
|
|
{
|
|
|
nRet = 0;
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetDevInfo")
|
|
@@ -1507,7 +1518,7 @@ bool CAccessAuthEntity::SendInitMKReqACS(CInitlizerMKReq& initMKReq)
|
|
|
initMKReq.enrolGPS = "00000A4500000A4E";//oiltmp
|
|
|
initMKReq.enrolAddr = si.strEnrolAddr;
|
|
|
initMKReq.installVersion = si.InstallVersion.ToString();
|
|
|
-
|
|
|
+
|
|
|
#ifdef RVC_OS_WIN
|
|
|
hostent* ent = gethostbyname(NULL);
|
|
|
if (ent && ent->h_addr_list[0] != NULL)
|
|
@@ -1680,7 +1691,7 @@ ErrorCodeEnum CAccessAuthEntity::LoadKeysToPinPadACS(string TMK, string TPK, str
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("LoadKeysToPinPadACS")("req.reserved3=%s", req.reserved3.GetData());
|
|
|
|
|
|
PinPadService_LoadKeysSM_Ans ans = {};
|
|
|
- rc = (*pPinPad)(EntityResource::getLink().upgradeLink())->LoadKeysSM(req, ans, 30000);
|
|
|
+ rc = pPinPad->LoadKeysSM(req, ans, 30000);
|
|
|
if (rc == Error_Succeed)
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("LoadKeysToPinPadACS")("load sm key to pinpad succ");
|
|
|
else
|
|
@@ -1865,11 +1876,11 @@ void CAccessAuthEntity::GetTermSysInfo()
|
|
|
CSimpleStringA strRet;
|
|
|
if (!QueryWMIDevice(Processor, "ProcessorId", szTmp, &nTmpBufLen))
|
|
|
{
|
|
|
- strErrMsg = CSimpleStringA::Format("query cpu id fail: %d, 请重启设备", GetLastError());
|
|
|
+ strErrMsg = CSimpleStringA::Format("查询 cpu id 失败: %d, 请尝试重启应用", GetLastError());
|
|
|
SetAuthErrMsg((const char*)strErrMsg);
|
|
|
|
|
|
m_FSM.doWarnMsg(ERR_ACCESSAUTH_GET_TERMINAL_FINGERPRINT,
|
|
|
- GetOutPutStr("%s%s%s%d", "QueryWMIDevice", "False", "Processor", GetLastError()).c_str(), strErrMsg.GetData());
|
|
|
+ GetOutPutStr("%s%s%s%d", "QueryWMIDevice", "False", "Processor", GetLastError()).c_str(), true, strErrMsg.GetData());
|
|
|
DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI("QueryWMIDevice")
|
|
|
(GetOutPutStr("%s%s%s%d", "QueryWMIDevice", "False", "Processor", GetLastError()).c_str());
|
|
|
m_iGetTermSysInfo = -1;
|
|
@@ -1881,11 +1892,11 @@ void CAccessAuthEntity::GetTermSysInfo()
|
|
|
memset(szTmp, 0, sizeof(szTmp));
|
|
|
if (!QueryWMIDevice(BaseBoard, "SerialNumber", szTmp, &nTmpBufLen))
|
|
|
{
|
|
|
- strErrMsg = CSimpleStringA::Format("query baseboard sn fail: %d, 请重启设备", GetLastError());
|
|
|
+ strErrMsg = CSimpleStringA::Format("查询 baseboard sn 失败: %d, 请尝试重启应用", GetLastError());
|
|
|
SetAuthErrMsg((const char*)strErrMsg);
|
|
|
|
|
|
m_FSM.doWarnMsg(ERR_ACCESSAUTH_GET_TERMINAL_FINGERPRINT,
|
|
|
- GetOutPutStr("%s%s%s%d", "QueryWMIDevice", "False", "BaseBoard", GetLastError()).c_str(), strErrMsg.GetData());
|
|
|
+ GetOutPutStr("%s%s%s%d", "QueryWMIDevice", "False", "BaseBoard", GetLastError()).c_str(), true, strErrMsg.GetData());
|
|
|
DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI("QueryWMIDevice")
|
|
|
(GetOutPutStr("%s%s%s%d", "QueryWMIDevice", "False", "BaseBoard", GetLastError()).c_str());
|
|
|
m_iGetTermSysInfo = -1;
|
|
@@ -1899,11 +1910,11 @@ void CAccessAuthEntity::GetTermSysInfo()
|
|
|
memset(szTmp, 0, sizeof(szTmp));
|
|
|
if (!QueryWMIDevice(DiskDrive, "SerialNumber", szTmp, &nTmpBufLen))
|
|
|
{
|
|
|
- strErrMsg = CSimpleStringA::Format("query harddisk sn fail: %d, 请重启设备", GetLastError());
|
|
|
+ strErrMsg = CSimpleStringA::Format("查询 harddisk sn 失败: %d, 请尝试重启应用", GetLastError());
|
|
|
SetAuthErrMsg((const char*)strErrMsg);
|
|
|
|
|
|
m_FSM.doWarnMsg(ERR_ACCESSAUTH_GET_TERMINAL_FINGERPRINT,
|
|
|
- GetOutPutStr("%s%s%s%d", "QueryWMIDevice", "False", "DiskDrive", GetLastError()).c_str(), strErrMsg.GetData());
|
|
|
+ GetOutPutStr("%s%s%s%d", "QueryWMIDevice", "False", "DiskDrive", GetLastError()).c_str(), true, strErrMsg.GetData());
|
|
|
DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI("QueryWMIDevice")
|
|
|
(GetOutPutStr("%s%s%s%d", "QueryWMIDevice", "False", "DiskDrive", GetLastError()).c_str());
|
|
|
m_iGetTermSysInfo = -1;
|