|
@@ -1,7 +1,4 @@
|
|
|
#include "stdafx.h"
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- #include <wincrypt.h>
|
|
|
-#endif // RVC_OS_WIN
|
|
|
#include "CenterSettingConn.h"
|
|
|
#include "Event.h"
|
|
|
#include <map>
|
|
@@ -12,7 +9,6 @@ using namespace std;
|
|
|
|
|
|
#include "fileutil.h"
|
|
|
#include "iniutil.h"
|
|
|
-#include "md5.h"
|
|
|
|
|
|
CCenterSettingConn::CCenterSettingConn(CEntityBase *pEntity)
|
|
|
: SpSecureClient(pEntity)
|
|
@@ -34,7 +30,7 @@ void CCenterSettingConn::OnPkgAnswer(const CSmartPointer<IPackage> &pRecvPkg)
|
|
|
string serviceCode = pRecvPkg->GetServiceCode();
|
|
|
auto pEntity = (CCenterSettingEntity*) m_pEntity;
|
|
|
|
|
|
- if (serviceCode == "PollCfg2")
|
|
|
+ if (serviceCode == "PollSM")
|
|
|
{
|
|
|
auto rc = OnEndPollConfig(pRecvPkg);
|
|
|
|
|
@@ -101,13 +97,13 @@ ErrorCodeEnum CCenterSettingConn::BeginPollConfig()
|
|
|
auto rc = pFunc->GetSystemStaticInfo(info);
|
|
|
assert(rc == Error_Succeed);
|
|
|
|
|
|
- auto pPackage = CreateNewPackage("PollCfg2");
|
|
|
+ auto pPackage = CreateNewPackage("PollSM");
|
|
|
auto &syncFiles = pEntity->m_SyncFileInfo;
|
|
|
int nArrayNum = syncFiles.size();
|
|
|
if (nArrayNum> 0)
|
|
|
{
|
|
|
- PollCfgReq *pReq = new PollCfgReq[nArrayNum];
|
|
|
- memset(pReq, 0, sizeof(PollCfgReq)*nArrayNum);
|
|
|
+ PollSMR *pReq = new PollSMR[nArrayNum];
|
|
|
+ memset(pReq, 0, sizeof(PollSMR)*nArrayNum);
|
|
|
int nIndex = 0;
|
|
|
for (auto it = pEntity->m_SyncFileInfo.begin(); it != pEntity->m_SyncFileInfo.end(); it++)
|
|
|
{
|
|
@@ -128,12 +124,12 @@ ErrorCodeEnum CCenterSettingConn::BeginPollConfig()
|
|
|
nIndex++;
|
|
|
}
|
|
|
|
|
|
- pPackage->AddStruct("PollReq", false, false, (BYTE*) pReq, sizeof(PollCfgReq)*nArrayNum, nArrayNum);
|
|
|
+ pPackage->AddStruct("PollSMR", false, false, (BYTE*) pReq, sizeof(PollSMR)*nArrayNum, nArrayNum);
|
|
|
delete[] pReq;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- PollCfgReq req = {};
|
|
|
+ PollSMR req = {};
|
|
|
#ifdef RVC_OS_WIN
|
|
|
strncpy_s(req.TerminalNo, sizeof(req.TerminalNo), info.strTerminalID, _TRUNCATE);
|
|
|
strncpy_s(req.MachineType, sizeof(req.MachineType), info.strMachineType, _TRUNCATE);
|
|
@@ -144,8 +140,7 @@ ErrorCodeEnum CCenterSettingConn::BeginPollConfig()
|
|
|
strncpy(req.Sites, info.strSite, strlen(info.strSite));
|
|
|
#endif
|
|
|
|
|
|
-
|
|
|
- pPackage->AddStruct("PollReq", false, false, (BYTE*)&req, sizeof(PollCfgReq));
|
|
|
+ pPackage->AddStruct("PollSMR", false, false, (BYTE*)&req, sizeof(PollSMR));
|
|
|
}
|
|
|
|
|
|
SendPackage(pPackage);
|
|
@@ -170,7 +165,7 @@ ErrorCodeEnum CCenterSettingConn::OnEndPollConfig(const CSmartPointer<IPackage>
|
|
|
int nIndex = 1;
|
|
|
while (true)
|
|
|
{
|
|
|
- CSimpleStringA strCurStructName = CSimpleStringA::Format("PollRet%d", nIndex);
|
|
|
+ CSimpleStringA strCurStructName = CSimpleStringA::Format("PollSMA%d", nIndex);
|
|
|
|
|
|
int nRetLen = pRecvPkg->GetStructLen(strCurStructName);
|
|
|
if (nRetLen == -1)
|
|
@@ -188,25 +183,22 @@ ErrorCodeEnum CCenterSettingConn::OnEndPollConfig(const CSmartPointer<IPackage>
|
|
|
int nBufLen = nRetLen;
|
|
|
bool bSuc = pRecvPkg->GetStructData(strCurStructName, pBuf, &nBufLen, &nArrayNum);
|
|
|
assert(bSuc && nRetLen == nBufLen);
|
|
|
- PollCfgRet *pRet = (PollCfgRet*)pBuf;
|
|
|
+ PollSMA*pRet = (PollSMA*)pBuf;
|
|
|
|
|
|
Dbg("center config changed, hash: %s, file: %s", (const char*)pRet->FileHash, (const char*)pRet->FileName);
|
|
|
|
|
|
// 校验Hash是否匹配
|
|
|
- //BYTE md5digest[16] = {};
|
|
|
- //if(0 != md5(md5digest, (BYTE*)pRet->FileContent, nRetLen - sizeof(PollCfgRet)))
|
|
|
-
|
|
|
- BYTE md5[16] = {};
|
|
|
- if (!MD5Hash((BYTE*)pRet->FileContent, nRetLen - sizeof(PollCfgRet), md5))
|
|
|
+ BYTE sm3[32] = {};
|
|
|
+ if(!SM3Hash((BYTE*)pRet->FileContent, nRetLen - sizeof(PollSMA), sm3))
|
|
|
{
|
|
|
- Dbg("compute md5 hash fail");
|
|
|
+ Dbg("compute sm3 hash fail");
|
|
|
delete[] pBuf;
|
|
|
return Error_Unexpect;
|
|
|
}
|
|
|
|
|
|
CSimpleStringA strHash;
|
|
|
- for (int i = 0; i < 16; i++)
|
|
|
- strHash += CSimpleStringA::Format("%02x", md5[i]);
|
|
|
+ for (int i = 0; i < 32; i++)
|
|
|
+ strHash += CSimpleStringA::Format("%02x", sm3[i]);
|
|
|
|
|
|
if (stricmp(strHash, pRet->FileHash) != 0)
|
|
|
{
|
|
@@ -224,13 +216,13 @@ ErrorCodeEnum CCenterSettingConn::OnEndPollConfig(const CSmartPointer<IPackage>
|
|
|
// 保存新配置文件
|
|
|
CSimpleStringA strNewFile = strCurFile + ".new";
|
|
|
auto hFile = fopen(strNewFile, "wb");
|
|
|
- int nLen = fwrite(pRet->FileContent, 1, nRetLen - sizeof(PollCfgRet), hFile);
|
|
|
+ int nLen = fwrite(pRet->FileContent, 1, nRetLen - sizeof(PollSMA), hFile);
|
|
|
fflush(hFile);
|
|
|
fclose(hFile);
|
|
|
|
|
|
- if (nLen < nRetLen - sizeof(PollCfgRet))
|
|
|
+ if (nLen < nRetLen - sizeof(PollSMA))
|
|
|
{
|
|
|
- Dbg("save %s fail, fwrite len: %d, act len: %d", pRet->FileName, nLen, nRetLen - sizeof(PollCfgRet));
|
|
|
+ Dbg("save %s fail, fwrite len: %d, act len: %d", pRet->FileName, nLen, nRetLen - sizeof(PollSMA));
|
|
|
delete[] pBuf;
|
|
|
return Error_Unexpect;
|
|
|
}
|
|
@@ -327,49 +319,3 @@ ErrorCodeEnum CCenterSettingConn::OnEndPollConfig(const CSmartPointer<IPackage>
|
|
|
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
-
|
|
|
-bool CCenterSettingConn::MD5Hash(BYTE *pData, int nDataLen, BYTE hash[16])
|
|
|
-{
|
|
|
-
|
|
|
-#if !defined(RVC_OS_WIN)
|
|
|
- md5_ctx_t ctx;
|
|
|
- md5_init(&ctx);
|
|
|
- if (0 != md5_update(&ctx, pData, nDataLen))
|
|
|
- return false;
|
|
|
-
|
|
|
- if (0 != md5_final(hash, &ctx))
|
|
|
- return false;
|
|
|
-
|
|
|
- return true;
|
|
|
-#else
|
|
|
- bool bRet = false;
|
|
|
- HCRYPTPROV hCryptProv;
|
|
|
- if (CryptAcquireContextA(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET)) {
|
|
|
- int rc = Error_Unexpect;
|
|
|
- HCRYPTHASH hHash;
|
|
|
- if (CryptCreateHash(hCryptProv, CALG_MD5, 0, 0, &hHash)) {
|
|
|
- if (!CryptHashData(hHash, pData, nDataLen, 0))
|
|
|
- Dbg("CryptHashData fail");
|
|
|
- else {
|
|
|
- DWORD dwLen = 16;
|
|
|
- if (CryptGetHashParam(hHash, HP_HASHVAL, (LPBYTE)&hash[0], &dwLen, 0))
|
|
|
- bRet = true;
|
|
|
- else
|
|
|
- Dbg("CryptGetHashParam fail");
|
|
|
- }
|
|
|
- CryptDestroyHash(hHash);
|
|
|
- }
|
|
|
- else {
|
|
|
- Dbg("CryptCreateHash failed");
|
|
|
- }
|
|
|
- CryptReleaseContext(hCryptProv, 0);
|
|
|
- }
|
|
|
- else {
|
|
|
- Dbg("CryptAcquireContextA failed");
|
|
|
- }
|
|
|
- return bRet;
|
|
|
-#endif // RVC_OS_WIN
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-}
|