|
@@ -24,6 +24,10 @@ using namespace PinPad;
|
|
|
#include <ws2tcpip.h>
|
|
|
#include <Winsock2.h>
|
|
|
#include <algorithm>
|
|
|
+#include "WMIDeviceQuery.h"
|
|
|
+#include <WinCrypt.h>
|
|
|
+#include <Strsafe.h>
|
|
|
+#include "DeviceBaseClass.h"
|
|
|
#pragma comment(lib, "IPHLPAPI.lib")
|
|
|
#define ALLOW_MULTI_NETWORKD_CARDS
|
|
|
#endif // RVC_OS_WIN
|
|
@@ -1219,4 +1223,216 @@ CSimpleStringA CAccessAuthFSM::GetOsVersion()
|
|
|
osInfo["OsBuild"] = tmp;
|
|
|
return generateJsonStr(osInfo).second.c_str();
|
|
|
#endif
|
|
|
+}
|
|
|
+
|
|
|
+void CAccessAuthFSM::GetIPandMac(CSimpleStringA& ip, CSimpleStringA& mac)
|
|
|
+{
|
|
|
+ CAutoArray<SP::Module::Net::NetworkAdapterItem> netList;
|
|
|
+ ErrorCodeEnum rc = SP::Module::Net::GetINETMacAddresses(netList);
|
|
|
+ if (rc != Error_Succeed)
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Get sys netinfo failed!. rc=%d.", rc);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ CSimpleStringA csMac(""), csIP(""), csDNS("");
|
|
|
+ for (int i = 0; i < netList.GetCount(); i++) {
|
|
|
+ if (!csMac.IsNullOrEmpty()) {
|
|
|
+ csMac += ";";
|
|
|
+ }
|
|
|
+ csMac += netList[i].mac.c_str();
|
|
|
+ }
|
|
|
+ mac = csMac;
|
|
|
+
|
|
|
+ for (int i = 0; i < netList.GetCount(); i++) {
|
|
|
+ if (!csIP.IsNullOrEmpty()) {
|
|
|
+ csIP += ";";
|
|
|
+ }
|
|
|
+ csIP += netList[i].ip.c_str();
|
|
|
+ }
|
|
|
+ ip = csIP;
|
|
|
+
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
+void CAccessAuthFSM::GetHardWareInfo(CSimpleStringA & cpu, CSimpleStringA & mainBoard, CSimpleStringA & disk)
|
|
|
+{
|
|
|
+ auto pEntity = (CAccessAuthEntity*)m_pEntity;
|
|
|
+
|
|
|
+#ifdef RVC_OS_LINUX
|
|
|
+ char szTmp[1024] = {};
|
|
|
+ string strTmp;
|
|
|
+ int nTmpBufLen = 1024;
|
|
|
+ CSimpleStringA strErrMsg;
|
|
|
+ CSmartPointer<IEntityFunction> spFunction = GetEntityBase()->GetFunction();
|
|
|
+
|
|
|
+ CSimpleStringA strRet;
|
|
|
+ CSimpleStringA runInfoPath;
|
|
|
+ auto rc = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
|
|
|
+ if (rc != Error_Succeed) {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetPath runinfo error=%d.", rc);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ runInfoPath += SPLIT_SLASH_STR "runcfg";
|
|
|
+ if (!get_cpu_id_by_system(strTmp, runInfoPath.GetData()))
|
|
|
+ {
|
|
|
+ strErrMsg = CSimpleStringA::Format("查询CPU ID失败,请重启机器并重新初始化");
|
|
|
+ pEntity->SetAuthErrMsg((const char*)strErrMsg);
|
|
|
+
|
|
|
+ doWarnMsg(ERROR_ACCESSAUTH_GETCPUID,
|
|
|
+ GetOutPutStr("%s%s", "Processor", "False").c_str());
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5213")
|
|
|
+ (GetOutPutStr("%s%s", "Processor", "False").c_str());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ cpu = strTmp.c_str();
|
|
|
+ strRet = strTmp.c_str();
|
|
|
+ strTmp.clear();
|
|
|
+ if (!get_board_serial_by_system(strTmp, runInfoPath.GetData()))
|
|
|
+ {
|
|
|
+ strErrMsg = CSimpleStringA::Format("查询主板序列号失败, 请重启机器并重新初始化");
|
|
|
+ pEntity->SetAuthErrMsg((const char*)strErrMsg);
|
|
|
+
|
|
|
+ doWarnMsg(ERROR_ACCESSAUTH_GETBASEBOARDSN,
|
|
|
+ GetOutPutStr("%s%s", "BaseBoard", "False").c_str());
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5214")
|
|
|
+ (GetOutPutStr("%s%s", "BaseBoard", "False").c_str());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ strRet += "|";
|
|
|
+
|
|
|
+ mainBoard = strTmp.c_str();
|
|
|
+ strRet += strTmp.c_str();
|
|
|
+ vector<string> diskArr;
|
|
|
+ int errCode = 0;
|
|
|
+ if (!get_disk_serial_by_system(diskArr, errCode, runInfoPath.GetData()))
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get_disk_serial_by_system errCode:%d", errCode);
|
|
|
+ strErrMsg = CSimpleStringA::Format("查询磁盘序列号失败, 请重启机器并重新初始化");
|
|
|
+ pEntity->SetAuthErrMsg((const char*)strErrMsg);
|
|
|
+
|
|
|
+ doWarnMsg(ERROR_ACCESSAUTH_DISKDRIVESN,
|
|
|
+ GetOutPutStr("%s%s", "DiskDrive", "False").c_str());
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5215")
|
|
|
+ (GetOutPutStr("%s%s", "DiskDrive", "False").c_str());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ strRet += "|";
|
|
|
+
|
|
|
+ strTmp = "";
|
|
|
+ vector<string>::iterator it = diskArr.begin();
|
|
|
+ while (it != diskArr.end()) {
|
|
|
+ strTmp += *it;
|
|
|
+ it++;
|
|
|
+ }
|
|
|
+ strRet += strTmp.c_str();
|
|
|
+ disk = strTmp.c_str();
|
|
|
+
|
|
|
+ BYTE m_btTermSysInfoSM3[32] = { 0 };
|
|
|
+ if (!SM3Hash(reinterpret_cast<BYTE*>(const_cast<char*>(strRet.GetData())), strRet.GetLength(), m_btTermSysInfoSM3))
|
|
|
+ {
|
|
|
+ strErrMsg = "get sm3 hash as fingerprint fail";
|
|
|
+ pEntity->SetAuthErrMsg((const char*)strErrMsg);
|
|
|
+ spFunction->SetSysVar("AuthErrMsg", (const char*)strErrMsg, true);
|
|
|
+ doWarnMsg(ERROR_ACCESSAUTH_GETSM3HASH, (const char*)strErrMsg);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+#else
|
|
|
+ //oilyang@20231008 to get system info from runcfg first
|
|
|
+ //no matter calculating from runcfg succeed or not,we also get system info from system api for update runcfg
|
|
|
+ bool bCalcFromRunCfg = false;
|
|
|
+ CSimpleString csInfo, strErrMsg, strRet;
|
|
|
+ CSmartPointer<IConfigInfo> pConfigRun;
|
|
|
+ ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, pConfigRun);
|
|
|
+ if (eErr == Error_Succeed && pConfigRun->ReadConfigValue("system", "info", csInfo) == Error_Succeed && !csInfo.IsNullOrEmpty()) {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("read device info from runcfg: [%s]", csInfo.GetData());
|
|
|
+ CAutoArray<CSimpleStringA> sysInfo = csInfo.Split('|');
|
|
|
+ if (sysInfo.GetCount() == 3)
|
|
|
+ {
|
|
|
+ cpu = sysInfo[0];
|
|
|
+ mainBoard = sysInfo[1];
|
|
|
+ disk = sysInfo[2];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("GetTermSysInfo, OpenConfig Config_Run error=%d.", eErr);
|
|
|
+
|
|
|
+ ULONGLONG ullStart = GetTickCount64();
|
|
|
+ char szTmp[1024] = {};
|
|
|
+ int nTmpBufLen = 1024;
|
|
|
+ CSmartPointer<IEntityFunction> spFunction = GetEntityBase()->GetFunction();
|
|
|
+ if (!QueryWMIDevice(Processor, "ProcessorId", szTmp, &nTmpBufLen))
|
|
|
+ {
|
|
|
+ strErrMsg = CSimpleStringA::Format("查询 cpu id 失败: %d, 请尝试重启应用", GetLastError());
|
|
|
+ pEntity->SetAuthErrMsg((const char*)strErrMsg);
|
|
|
+
|
|
|
+ LogWarn(Severity_Middle, Error_Unexpect, ERR_ACCESSAUTH_GET_TERMINAL_FINGERPRINT,
|
|
|
+ GetOutPutStr("%s%s%s%d", "QueryWMIDevice", "False", "Processor", GetLastError()).c_str());
|
|
|
+
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5203")
|
|
|
+ (GetOutPutStr("%s%s%s%d", "QueryWMIDevice", "False", "Processor", GetLastError()).c_str());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ strRet = szTmp;
|
|
|
+ cpu = szTmp;
|
|
|
+
|
|
|
+ nTmpBufLen = 1024;
|
|
|
+ memset(szTmp, 0, sizeof(szTmp));
|
|
|
+ if (!QueryWMIDevice(BaseBoard, "SerialNumber", szTmp, &nTmpBufLen))
|
|
|
+ {
|
|
|
+ strErrMsg = CSimpleStringA::Format("查询 baseboard sn 失败: %d, 请尝试重启应用", GetLastError());
|
|
|
+ pEntity->SetAuthErrMsg((const char*)strErrMsg);
|
|
|
+
|
|
|
+ LogWarn(Severity_Middle, Error_Unexpect, ERR_ACCESSAUTH_GET_TERMINAL_FINGERPRINT,
|
|
|
+ GetOutPutStr("%s%s%s%d", "QueryWMIDevice", "False", "BaseBoard", GetLastError()).c_str());
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5203")
|
|
|
+ (GetOutPutStr("%s%s%s%d", "QueryWMIDevice", "False", "BaseBoard", GetLastError()).c_str());
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ strRet += "|";
|
|
|
+ strRet += szTmp;
|
|
|
+ mainBoard = szTmp;
|
|
|
+
|
|
|
+ nTmpBufLen = 1024;
|
|
|
+ memset(szTmp, 0, sizeof(szTmp));
|
|
|
+ if (!QueryWMIDevice(DiskDrive, "SerialNumber", szTmp, &nTmpBufLen))
|
|
|
+ {
|
|
|
+ strErrMsg = CSimpleStringA::Format("查询 harddisk sn 失败: %d, 请尝试重启应用", GetLastError());
|
|
|
+ pEntity->SetAuthErrMsg((const char*)strErrMsg);
|
|
|
+
|
|
|
+ LogWarn(Severity_Middle, Error_Unexpect, ERR_ACCESSAUTH_GET_TERMINAL_FINGERPRINT,
|
|
|
+ GetOutPutStr("%s%s%s%d", "QueryWMIDevice", "False", "DiskDrive", GetLastError()).c_str());
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)(GetOutPutStr("%s%s%s%d", "QueryWMIDevice", "False", "DiskDrive", GetLastError()).c_str());
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ strRet += "|";
|
|
|
+ strRet += szTmp;
|
|
|
+ disk = szTmp;
|
|
|
+
|
|
|
+ if (!bCalcFromRunCfg || csInfo.Compare(strRet) != 0)
|
|
|
+ {
|
|
|
+ eErr = pConfigRun->WriteConfigValue("system", "info", strRet.GetData());
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("device info changed,before[%s],current[%s],write to runcfg:%d"
|
|
|
+ , csInfo.GetData(), strRet.GetData(), eErr);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("device info: [%s]", strRet.GetData());
|
|
|
+
|
|
|
+
|
|
|
+ ULONGLONG ullEnd = GetTickCount64();
|
|
|
+ if (ullEnd - ullStart > 5000)
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5201")
|
|
|
+ ("获取系统信息耗时过长:%d秒", (ullEnd - ullStart) / 1000);
|
|
|
+ LogWarn(Severity_Middle, Error_Unexpect, AccessAuthorization_UserErrorCode_GetTermCostTooLong,
|
|
|
+ CSimpleStringA::Format("获取系统信息耗时过长:%d秒", (ullEnd - ullStart) / 1000));
|
|
|
+ }
|
|
|
+ return;
|
|
|
+#endif // RVC_OS_LINUX
|
|
|
+
|
|
|
}
|