|
@@ -10,6 +10,8 @@
|
|
|
#include "EventCode.h"
|
|
|
#include "libtoolkit/iniutil.h"
|
|
|
#include "PinPad_client_g.h"
|
|
|
+#include "comm.h"
|
|
|
+#include "fileutil.h"
|
|
|
using namespace PinPad;
|
|
|
|
|
|
#include "CenterSetting_client_g.h"
|
|
@@ -21,8 +23,6 @@ using namespace CardSwiper;
|
|
|
#include "MaintainWatcher_client_g.h"
|
|
|
using namespace MaintainWatcher;
|
|
|
|
|
|
-#include "comm.h"
|
|
|
-#include <fileutil.h>
|
|
|
#define BUF_SIZE 256
|
|
|
#define KEY_SIZE 16
|
|
|
|
|
@@ -69,16 +69,16 @@ void CInitializerSession::Handle_InitializeForBlueTooth(SpReqAnsContext<Initiali
|
|
|
|
|
|
void CInitializerEntity::OnStarted()
|
|
|
{
|
|
|
-
|
|
|
LOG_FUNCTION();
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
CSimpleStringA strKmclogPath;
|
|
|
GetFunction()->GetPath("Dbg", strKmclogPath);
|
|
|
- strKmclogPath += "/kmc/";
|
|
|
-
|
|
|
+ strKmclogPath += "\\kmc\\";
|
|
|
if (!ExistsDirA(strKmclogPath))
|
|
|
{
|
|
|
CreateDirA(strKmclogPath, TRUE);
|
|
|
}
|
|
|
+#endif // RVC_OS_WIN
|
|
|
|
|
|
m_bHasCkCode = false;
|
|
|
|
|
@@ -89,8 +89,6 @@ void CInitializerEntity::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPoint
|
|
|
{
|
|
|
m_FSM.PostExitEvent();
|
|
|
|
|
|
- CloseGUI();
|
|
|
-
|
|
|
pTransactionContext->SendAnswer(Error_Succeed);
|
|
|
}
|
|
|
|
|
@@ -139,9 +137,20 @@ CSimpleStringA CInitializerEntity::GetKMCLastErrMsg()
|
|
|
|
|
|
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)
|
|
@@ -239,6 +248,7 @@ DWORD CInitializerEntity::LoadKeysToPinPad(bool bSM)
|
|
|
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 = {};
|
|
@@ -265,17 +275,6 @@ DWORD CInitializerEntity::LoadKeysToPinPad(bool bSM)
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
-ErrorCodeEnum CInitializerEntity::CreateInitMKData(CBlob &blob, bool bSM)
|
|
|
-{
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-// 解析返回DES主密钥
|
|
|
-ErrorCodeEnum CInitializerEntity::ParseInitMKResult(CBlob &blob, bool bSM)
|
|
|
-{
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
bool CInitializerEntity::GetAuthAccessAddr(CSimpleStringA &strAddr, int &nPort)
|
|
|
{
|
|
|
CSmartPointer<IConfigInfo> pConfig;
|
|
@@ -327,7 +326,6 @@ bool CInitializerEntity::SetCenterSettingAddr(const char *pszAddr, int nPort)
|
|
|
GetFunction()->GetPath("CenterSetting", strPath);
|
|
|
|
|
|
auto strAuthAccessAddr = CSimpleStringA::Format("%s %d", pszAddr, nPort);
|
|
|
- //return !!WritePrivateProfileString("CenterSetting", "Server", strAuthAccessAddr, strPath);
|
|
|
return inifile_format_write(strPath.GetData(), "CenterSetting", "Server", "%s", strAuthAccessAddr.GetData());
|
|
|
}
|
|
|
|
|
@@ -537,6 +535,7 @@ void CInitializerEntity::BeginLogin(const char *pszAuthServer, int nAuthPort, co
|
|
|
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
|
|
@@ -583,6 +582,7 @@ void CInitializerEntity::BeginLogin(const char *pszAuthServer, int nAuthPort, co
|
|
|
(const char*)m_strAuthorizer,
|
|
|
(const char*)m_strAuthTime);
|
|
|
}
|
|
|
+ pClient->GetFunction()->CloseSession();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -691,41 +691,27 @@ void CInitializerEntity::EndLogin(DWORD rc, const char *pErrMsg)
|
|
|
m_eErrNum = rc;
|
|
|
m_strLastErrMsg = pErrMsg;
|
|
|
|
|
|
- //if (m_hGUIWindow == 0)
|
|
|
- {
|
|
|
- //判断是否为蓝牙多合一,登录失败,返回给上层
|
|
|
- if (m_type != 1 && m_ctx != NULL)
|
|
|
- {
|
|
|
- //详细错误码,成功rc的值为Error_Succeed
|
|
|
- m_ctx->Ans.Errcode = rc;
|
|
|
- m_ctx->Ans.ErrMsg = pErrMsg;
|
|
|
- //成功返回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 = pErrMsg;
|
|
|
- m_ctx_blue->Answer(Error_Succeed);
|
|
|
- }
|
|
|
- }
|
|
|
+ //判断是否为蓝牙多合一,登录失败,返回给上层
|
|
|
+ if (m_type != 1 && m_ctx != NULL)
|
|
|
+ {
|
|
|
+ //详细错误码,成功rc的值为Error_Succeed
|
|
|
+ m_ctx->Ans.Errcode = rc;
|
|
|
+ m_ctx->Ans.ErrMsg = pErrMsg;
|
|
|
+ //成功返回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 = pErrMsg;
|
|
|
+ m_ctx_blue->Answer(Error_Succeed);
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Dbg("登录成功。。。");
|
|
|
m_strLastErrMsg = "";
|
|
|
- }
|
|
|
-
|
|
|
- //if (m_hGUIWindow != 0)
|
|
|
- {
|
|
|
- //PostMessage(m_hGUIWindow, WM_LOGIN_RESULT, rc, 0);
|
|
|
- }
|
|
|
- //else
|
|
|
- {
|
|
|
- if (rc == Error_Succeed)
|
|
|
- {
|
|
|
- BeginGetKMCKey();
|
|
|
- }
|
|
|
+ BeginGetKMCKey();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -820,18 +806,7 @@ void CInitializerEntity::EndSyncPK(DWORD rc, const char *pszErrMsg)
|
|
|
{
|
|
|
Dbg("同步公钥成功。。。");
|
|
|
m_strLastErrMsg = "";
|
|
|
- }
|
|
|
-
|
|
|
- //if (m_hGUIWindow != 0)
|
|
|
- {
|
|
|
- //PostMessage(m_hGUIWindow, WM_SYNCPK_RESULT, rc, 0);
|
|
|
- }
|
|
|
- //else
|
|
|
- {
|
|
|
- if (rc == Error_Succeed)
|
|
|
- {
|
|
|
- BeginInitMK();
|
|
|
- }
|
|
|
+ BeginInitMK();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -856,37 +831,23 @@ void CInitializerEntity::EndGetKMCKey(DWORD rc, const char* pszErrMsg) {
|
|
|
|
|
|
m_eErrNum = rc;
|
|
|
m_strLastErrMsg = pszErrMsg;
|
|
|
-
|
|
|
- //if (m_hGUIWindow == 0)
|
|
|
- {
|
|
|
- if (m_type == 0 && m_ctx != NULL) {
|
|
|
- m_ctx->Ans.Errcode = rc;
|
|
|
- m_ctx->Ans.ErrMsg = pszErrMsg;
|
|
|
- m_ctx->Answer(Error_Succeed);
|
|
|
- }
|
|
|
- else if (m_type == 1 && m_ctx_blue != NULL) {
|
|
|
- m_ctx_blue->Ans.Errcode = rc;
|
|
|
- m_ctx_blue->Ans.ErrMsg = pszErrMsg;
|
|
|
- m_ctx_blue->Answer(Error_Succeed);
|
|
|
- }
|
|
|
+
|
|
|
+ if (m_type == 0 && m_ctx != NULL) {
|
|
|
+ m_ctx->Ans.Errcode = rc;
|
|
|
+ m_ctx->Ans.ErrMsg = pszErrMsg;
|
|
|
+ m_ctx->Answer(Error_Succeed);
|
|
|
+ }
|
|
|
+ else if (m_type == 1 && m_ctx_blue != NULL) {
|
|
|
+ m_ctx_blue->Ans.Errcode = rc;
|
|
|
+ m_ctx_blue->Ans.ErrMsg = pszErrMsg;
|
|
|
+ m_ctx_blue->Answer(Error_Succeed);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Dbg("获取KMC密钥成功。。。");
|
|
|
m_strLastErrMsg = "";
|
|
|
- }
|
|
|
-
|
|
|
- /*if (m_hGUIWindow != 0)
|
|
|
- {
|
|
|
- PostMessage(m_hGUIWindow, WM_SYNCPK_RESULT, rc, 0);
|
|
|
- }
|
|
|
- else*/
|
|
|
- {
|
|
|
- if (rc == Error_Succeed)
|
|
|
- {
|
|
|
- BeginInitMK();
|
|
|
- }
|
|
|
+ BeginInitMK();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -909,83 +870,7 @@ DWORD CInitializerEntity::ReportInitMKState(const char *pszUserID, DWORD dwErrCo
|
|
|
void CInitializerEntity::BeginInitMK()
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
|
- //国产化新框架只走国密
|
|
|
- /*
|
|
|
- {
|
|
|
- // 1:3des only; 2: sm4 only; 3: both 3des and sm4
|
|
|
- int nCapability = GetPinPadCapability();
|
|
|
- Dbg("pinpad capability: %d", nCapability);
|
|
|
-
|
|
|
- // check if pubkey file exists
|
|
|
- if (HasCkCodeFlg())
|
|
|
- {
|
|
|
- if ((nCapability == 1 || nCapability == 3) && (0 == m_iTDESPukeyLen))
|
|
|
- {
|
|
|
- Dbg("rsa public key buf not exists");
|
|
|
- EndInitMK(ERR_INITIALIZER_SYNC_PUBKEY_RSA_BUF_NO_EXIST, "RSA公钥缓存不存在,请联系分行技术部处理故障!");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if ((nCapability == 2 || nCapability == 3) && (0 == m_iSM2Pukeylen))
|
|
|
- {
|
|
|
- Dbg("sm2 public key buf not exists");
|
|
|
- //如果分行服务没有国密公钥,则不初始化国密
|
|
|
- //EndInitMK(ERR_INITIALIZER_SYNC_PUBKEY_SM2_BUF_NO_EXIST, "SM2公钥文件不存在");
|
|
|
- //return;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- CSimpleStringA strKmcPath;
|
|
|
- GetFunction()->GetPath("RunInfo", strKmcPath);
|
|
|
- strKmcPath += "\\kmc\\";
|
|
|
-
|
|
|
- CSimpleStringA strRsaPubKeyFile = strKmcPath + PUKFILENAME_RSA;
|
|
|
- if ((nCapability == 1 || nCapability == 3) && !ExistsFileA(strRsaPubKeyFile))
|
|
|
- {
|
|
|
- Dbg("rsa public key file %s not exists", PUKFILENAME_RSA);
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_SYNC_PUBKEY_RSA_FIL_NO_EXIST,
|
|
|
- GetOutPutStr("%s%s%s%s", "File", PUKFILENAME_RSA, "Desc", "RSA公钥文件不存在。。。").c_str());
|
|
|
- EndInitMK(ERR_INITIALIZER_SYNC_PUBKEY_RSA_FIL_NO_EXIST, "RSA公钥文件不存在,请联系分行技术部处理故障!");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- CSimpleStringA strSm2PubKeyFile = strKmcPath + PUKFILENAME_SM2;
|
|
|
- if ((nCapability == 2 || nCapability == 3) && !ExistsFileA(strSm2PubKeyFile))
|
|
|
- {
|
|
|
- Dbg("sm2 public key file %s not exists", PUKFILENAME_SM2);
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_SYNC_PUBKEY_SM2_FIL_NO_EXIST,
|
|
|
- GetOutPutStr("%s%s%s%s", "File", PUKFILENAME_SM2, "Desc", "Sm2公钥文件不存在。。。").c_str());
|
|
|
- //EndInitMK(Error_NotExist, "SM2公钥文件不存在");
|
|
|
- //return;
|
|
|
- }
|
|
|
-
|
|
|
- // delete key data file first
|
|
|
- CSimpleStringA strKeyFile = strKmcPath + PFKEYFILENAME_DES;
|
|
|
- if (ExistsFileA(strKeyFile))
|
|
|
- {
|
|
|
- Dbg("delete des data file");
|
|
|
- DeleteFileA(strKeyFile);
|
|
|
- }
|
|
|
-
|
|
|
- strKeyFile = strKmcPath + PFKEYFILENAME_SM4;
|
|
|
- if (ExistsFileA(strKeyFile))
|
|
|
- {
|
|
|
- Dbg("delete sm4 data file");
|
|
|
- DeleteFileA(strKeyFile);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- DWORD rc = InitKMC(nCapability);
|
|
|
- if (rc != Error_Succeed)
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_INIT_KMC,
|
|
|
- GetOutPutStr("%s%08X", "InitKMC", rc).c_str());
|
|
|
- EndInitMK(ERR_INITIALIZER_INIT_KMC, (const char*)CSimpleStringA::Format("InitKMC失败, %s, ,请联系分行技术部处理故障!", (const char*)m_strLastErrMsg));
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- */
|
|
|
+
|
|
|
// 开始连接
|
|
|
DWORD rc = SecureClientConnect();
|
|
|
if (rc != Error_Succeed)
|
|
@@ -1079,44 +964,29 @@ void CInitializerEntity::EndInitMK(DWORD rc, const char *pszErrMsg)
|
|
|
pEvent->param1 = bSuc ? 0 : 1;
|
|
|
m_FSM.PostEventFIFO(pEvent);
|
|
|
|
|
|
- // 通知UI窗口
|
|
|
- //if (m_hGUIWindow != 0)
|
|
|
+ int nInitializedFlg = 1;
|
|
|
+ GetInitializedFlg(nInitializedFlg);
|
|
|
+ if (IsIL() && 0 == nInitializedFlg && bSuc)
|
|
|
{
|
|
|
- //PostMessage(m_hGUIWindow, WM_INITMK_RESULT, rc, 0);
|
|
|
+ //修改初始化状态
|
|
|
+ SetInitializedFlg("1");
|
|
|
}
|
|
|
- //else
|
|
|
+ else
|
|
|
{
|
|
|
- int nInitializedFlg = 1;
|
|
|
- GetInitializedFlg(nInitializedFlg);
|
|
|
- if (IsIL() && 0 == nInitializedFlg && bSuc)
|
|
|
- {
|
|
|
- //修改初始化状态
|
|
|
- SetInitializedFlg("1");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (m_type != 1 && m_ctx != NULL) {
|
|
|
+ if (m_type != 1 && 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_ctx_blue->Answer(Error_Succeed);
|
|
|
- }
|
|
|
+ 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_ctx_blue->Answer(Error_Succeed);
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //初始化成功,关闭任务
|
|
|
- if (bSuc)
|
|
|
- {
|
|
|
- CloseTask();
|
|
|
}
|
|
|
-
|
|
|
- ReleaseKMC();
|
|
|
+ //release connect
|
|
|
+ SecureClientRelease();
|
|
|
}
|
|
|
|
|
|
void CInitializerEntity::CloseTask()
|
|
@@ -1143,7 +1013,6 @@ void CInitializerEntity::OnTimeout(DWORD dwTimerID)
|
|
|
}
|
|
|
else if (dwTimerID == 33) // 同步公钥超时
|
|
|
{
|
|
|
- //EndSyncPK(ERR_INITIALIZER_SYNC_PUBKEY_TIME_OUT, "同步公钥文件超时");
|
|
|
EndGetKMCKey(ERR_INITIALIZER_GET_KMC_KEY_TIME_OUT,"获取KMC密钥超时");
|
|
|
}
|
|
|
}
|
|
@@ -1167,52 +1036,8 @@ ErrorCodeEnum CInitializerEntity::ParseIPAddress(const char *str, CSimpleStringA
|
|
|
return Error;
|
|
|
}
|
|
|
|
|
|
-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;
|
|
|
-}
|
|
|
-
|
|
|
ErrorCodeEnum CInitializerEntity::StartGUI()
|
|
|
{
|
|
|
-// if (m_hGUIWindow != 0)
|
|
|
-// return Error_Duplication;
|
|
|
-//
|
|
|
-// if (m_hGUIReadyEvent == 0)
|
|
|
-// m_hGUIReadyEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
|
|
|
-//
|
|
|
-// if (m_hGUIClosedEvent == 0)
|
|
|
-// m_hGUIClosedEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
|
|
|
-//
|
|
|
-// HANDLE hGUIThread = (HANDLE)_beginthreadex(0, 0, &__GUIThreadEntry, this, 0, 0);
|
|
|
-// if (hGUIThread == 0)
|
|
|
-// return Error_Resource;
|
|
|
-//
|
|
|
-// CloseHandle(hGUIThread);
|
|
|
-//
|
|
|
-// if (WaitForSingleObject(m_hGUIReadyEvent, 10000) == WAIT_OBJECT_0)
|
|
|
-// return Error_Succeed;
|
|
|
-// else
|
|
|
-// return Error_TimeOut;
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
|
|
@@ -1237,16 +1062,34 @@ ErrorCodeEnum CInitializerEntity::StartGUINew()
|
|
|
|
|
|
ErrorCodeEnum CInitializerEntity::CloseGUI()
|
|
|
{
|
|
|
-
|
|
|
- /*if (m_hGUIWindow ==0)
|
|
|
- return Error_NotInit;
|
|
|
-
|
|
|
- ResetEvent(m_hGUIClosedEvent);
|
|
|
- PostMessage(m_hGUIWindow, WM_CLOSE, 0, 0);
|
|
|
- WaitForSingleObject(m_hGUIClosedEvent, INFINITE);*/
|
|
|
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()
|
|
|
{
|
|
|
|
|
@@ -1257,10 +1100,6 @@ bool CInitializerEntity::HasPinPad()
|
|
|
LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_SYSTEM_STATIC_INFO,
|
|
|
GetOutPutStr("%s%08X", "GetSystemStaticInfo", rc).c_str());
|
|
|
}
|
|
|
- //@test自测shi使用
|
|
|
- /*if (info.strMachineType.IsStartWith("RVC.Stand2S", true))
|
|
|
- return false;*/
|
|
|
-
|
|
|
|
|
|
if (info.strMachineType.IsStartWith("RPM", true) || info.strMachineType.IsStartWith("RVC.CardStore", true) || info.strMachineType.IsStartWith("RVC.IL", true)) // 回单打印机、简化版
|
|
|
return false;
|
|
@@ -1345,7 +1184,6 @@ int CInitializerEntity::GetPinPadCapability()
|
|
|
{
|
|
|
LogWarn(Severity_Middle,(ErrorCodeEnum) rc, ERR_INITIALIZER_FROM_PINPAD_QUERY_FUNC,
|
|
|
GetOutPutStr("%s%08X%s%s", "QueryFunc", rc ,"Desc","调用pinpad实体的QueryFunc失败。。。").c_str());
|
|
|
- //LogError(Severity_Low, rc, ERROR_ACCESSAUTH_GETPINPADCAPABILITY, "从PinPad获取主密钥类型失败");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -1384,56 +1222,6 @@ int CInitializerEntity::GetPinPadCapability()
|
|
|
return nCapability;
|
|
|
}
|
|
|
|
|
|
-//unsigned int CInitializerEntity::__GUIThreadEntry(void *arg)
|
|
|
-//{
|
|
|
-// CInitializerEntity *pThis = static_cast<CInitializerEntity *>(arg);
|
|
|
-// {
|
|
|
-// pThis->GetFunction()->InitLogCurrentThread();
|
|
|
-// }
|
|
|
-//
|
|
|
-// pThis->GUIThreadEntry();
|
|
|
-//
|
|
|
-// _endthreadex(0);
|
|
|
-// return 0;
|
|
|
-//}
|
|
|
-
|
|
|
-//int CInitializerEntity::GUIThreadEntry()
|
|
|
-//{
|
|
|
-// HRESULT hRes = ::CoInitialize(NULL);
|
|
|
-//// If you are running on NT 4.0 or higher you can use the following call instead to
|
|
|
-//// make the EXE free threaded. This means that calls come in on a random RPC thread.
|
|
|
-//// HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
|
|
-// ATLASSERT(SUCCEEDED(hRes));
|
|
|
-//
|
|
|
-// // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
|
|
|
-// ::DefWindowProc(NULL, 0, 0, 0L);
|
|
|
-//
|
|
|
-// AtlInitCommonControls(
|
|
|
-// ICC_WIN95_CLASSES |
|
|
|
-// ICC_DATE_CLASSES |
|
|
|
-// ICC_USEREX_CLASSES |
|
|
|
-// ICC_COOL_CLASSES |
|
|
|
-// ICC_PAGESCROLLER_CLASS |
|
|
|
-// ICC_NATIVEFNTCTL_CLASS);
|
|
|
-//
|
|
|
-// //hRes = _Module.Init(NULL, ModuleBase::GetModuleBase()->GetInstance());
|
|
|
-// //ATLASSERT(SUCCEEDED(hRes));
|
|
|
-//
|
|
|
-// int nRet = 0;
|
|
|
-// {
|
|
|
-// CMKInitDlg dlgMain(this);
|
|
|
-// nRet = dlgMain.DoModal();
|
|
|
-// }
|
|
|
-//
|
|
|
-// SetEvent(m_hGUIClosedEvent);
|
|
|
-// m_hGUIWindow = 0;
|
|
|
-//
|
|
|
-// //_Module.Term();
|
|
|
-//
|
|
|
-// ::CoUninitialize();
|
|
|
-// return nRet;
|
|
|
-//}
|
|
|
-
|
|
|
ErrorCodeEnum CInitializerEntity::SecureClientConnect()
|
|
|
{
|
|
|
if (m_pConnection != NULL && m_pConnection->IsConnectionOK())
|
|
@@ -1468,37 +1256,6 @@ void CInitializerEntity::OnSecureClientDisconnect()
|
|
|
|
|
|
bool CInitializerEntity::GetMD5Hash(const char *pStr, BYTE md5[16])
|
|
|
{
|
|
|
-// HCRYPTPROV hCryptProv;
|
|
|
-// bool bRet = false;
|
|
|
-// if (CryptAcquireContextA(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET))
|
|
|
-// {
|
|
|
-// HCRYPTHASH hHash;
|
|
|
-// if (CryptCreateHash(hCryptProv, CALG_MD5, 0, 0, &hHash))
|
|
|
-// {
|
|
|
-// CryptHashData(hHash, (LPBYTE)pStr, strlen(pStr), 0);
|
|
|
-//
|
|
|
-// DWORD dwLen = 16;
|
|
|
-// CryptGetHashParam(hHash, HP_HASHVAL, (LPBYTE)&md5[0], &dwLen, 0);
|
|
|
-// bRet = true;
|
|
|
-// }
|
|
|
-// else
|
|
|
-// {
|
|
|
-// //LogError(Severity_Low, Error_Unexpect, ERROR_ACCESSAUTH_GETMD5HASH, CSimpleStringA::Format("CryptCreateHash fail: %d", GetLastError()));
|
|
|
-// LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_MD5_HASH,
|
|
|
-// GetOutPutStr("%s%s%s%d", "CryptHashData", "False", "GetLastError", GetLastError()).c_str());
|
|
|
-// }
|
|
|
-//
|
|
|
-// CryptDestroyHash(hHash);
|
|
|
-// }
|
|
|
-// else
|
|
|
-// {
|
|
|
-// //LogError(Severity_Low, Error_Unexpect, ERROR_ACCESSAUTH_GETMD5HASH, CSimpleStringA::Format("CryptAcquireContextA fail: %d", GetLastError()));
|
|
|
-// LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_MD5_HASH,
|
|
|
-// GetOutPutStr("%s%s%s%d", "CryptAcquireContextA", "False", "GetLastError", GetLastError()).c_str());
|
|
|
-// }
|
|
|
-//
|
|
|
-// CryptReleaseContext(hCryptProv, 0);
|
|
|
-// return bRet;
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
|
|
@@ -1538,7 +1295,6 @@ bool CInitializerEntity::GetTerminalFingerPrint(BYTE *pBuf, int &nBufLen)
|
|
|
#ifdef RVC_OS_WIN
|
|
|
if (!QueryWMIDevice(Processor, "ProcessorId", szTmp, &nTmpBufLen))
|
|
|
#else
|
|
|
- //if(!get_cpu_id_by_asm(strTmp))
|
|
|
if(!get_cpu_id_by_system(strTmp))
|
|
|
#endif // RVC_OS_WIN
|
|
|
{
|
|
@@ -1549,7 +1305,6 @@ bool CInitializerEntity::GetTerminalFingerPrint(BYTE *pBuf, int &nBufLen)
|
|
|
}
|
|
|
|
|
|
#ifdef RVC_OS_WIN
|
|
|
- //Dbg("cpu id: %s", szTmp);
|
|
|
strRet = szTmp;
|
|
|
nTmpBufLen = 1024;
|
|
|
memset(szTmp, 0, sizeof(szTmp));
|
|
@@ -1568,7 +1323,6 @@ bool CInitializerEntity::GetTerminalFingerPrint(BYTE *pBuf, int &nBufLen)
|
|
|
}
|
|
|
strRet += "|";
|
|
|
#ifdef RVC_OS_WIN
|
|
|
- //Dbg("baseboard sn: %s", szTmp);
|
|
|
strRet += szTmp;
|
|
|
nTmpBufLen = 1024;
|
|
|
memset(szTmp, 0, sizeof(szTmp));
|
|
@@ -1588,7 +1342,6 @@ bool CInitializerEntity::GetTerminalFingerPrint(BYTE *pBuf, int &nBufLen)
|
|
|
|
|
|
strRet += "|";
|
|
|
#ifdef RVC_OS_WIN
|
|
|
- //Dbg("harddisk sn: %s", szTmp);
|
|
|
strRet += szTmp;
|
|
|
#else
|
|
|
strTmp = "";
|
|
@@ -1631,14 +1384,6 @@ bool CInitializerEntity::GetTerminalFingerPrint(BYTE *pBuf, int &nBufLen)
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-#define RSAPUBKEY_BITLEN 1024
|
|
|
-//struct PublicKeyBlob
|
|
|
-//{
|
|
|
-// PUBLICKEYSTRUC publickeystruc;
|
|
|
-// RSAPUBKEY rsapubkey;
|
|
|
-// BYTE modulus[RSAPUBKEY_BITLEN / 8];
|
|
|
-//};
|
|
|
-
|
|
|
int CInitializerEntity::ConvertStr2Byte(string input, BYTE* output,int outputLen) {
|
|
|
if (input.size() > outputLen) return 1;
|
|
|
for (int i = 0;i < input.size();i++) {
|
|
@@ -1769,36 +1514,9 @@ bool CInitializerEntity::GetTerminalPublicKey(BYTE *pBuf, int &nBufLen)
|
|
|
|
|
|
Dbg("sm4 encrypt pri key success.");
|
|
|
Dbg("cryptPrivateKeyLen=%d", cryptPrivateKeyLen);
|
|
|
- /*
|
|
|
- rc = pConfig->WriteConfigValueInt("TerminalPD", "PrivateKeyLen", cryptPrivateKeyLen);
|
|
|
- assert(rc == Error_Succeed);*/
|
|
|
-
|
|
|
- /*char pEncodedCryptPrivateKey[BUF_SIZE];
|
|
|
- if (!base64_encode(pEncodedCryptPrivateKey, (char*)pCryptPrivateKey, cryptPrivateKeyLen)) {
|
|
|
- Dbg("base64 encode cryptPrivateKey error.");
|
|
|
- rc = pConfig->WriteConfigValue("TerminalPD", "PublicKey", "");
|
|
|
- assert(rc == Error_Succeed);
|
|
|
- return false;
|
|
|
- }*/
|
|
|
- //char* pEncodedCryptPrivateKey = Str2Hex((char*)pCryptPrivateKey, cryptPrivateKeyLen);
|
|
|
+
|
|
|
char* pEncodedCryptPrivateKey = Str2Hex((char*)pCryptPrivateKey, cryptPrivateKeyLen);
|
|
|
Dbg("encode pri key success.");
|
|
|
- /*Dbg("pEncodedCryptPrivateKey=%s,%d;encodedPrivateKeyLen=%d", pEncodedCryptPrivateKey.get(),strlen(pEncodedCryptPrivateKey.get()), encodedPrivateKeyLen);
|
|
|
- int decodedLen = base64_decode_len(pEncodedCryptPrivateKey.get());
|
|
|
-
|
|
|
- boost::shared_array<char> pDecodedPrivateKey(new char[2 * decodedLen]);
|
|
|
-
|
|
|
- if (!base64_decode(&pDecodedPrivateKey[0], pEncodedCryptPrivateKey.get())) {
|
|
|
- Dbg("base64 decode publicKey error.");
|
|
|
- return false;
|
|
|
- }
|
|
|
- Dbg("decodedLen=%d,decodedPrivateKeyLen=%d", decodedLen, decodedPrivateKeyLen);
|
|
|
- boost::shared_array<char> pDecryptPrivateKey(new char[2 * decodedPrivateKeyLen]);
|
|
|
- int decryprtLen =2 * decodedPrivateKeyLen;
|
|
|
- if (!DecWithSM4_ECB((BYTE*)"s5da69gnh4!963@6s5da69gnh4!963@6", (BYTE*)& pDecodedPrivateKey[0], decodedPrivateKeyLen, (BYTE*)& pDecryptPrivateKey[0], &decryprtLen)) {
|
|
|
- Dbg("DecWithSM4_ECB decrypt privateKey error.");
|
|
|
- return false;
|
|
|
- }*/
|
|
|
|
|
|
rc = pConfig->WriteConfigValue("TerminalPD", "PrivateKey", pEncodedCryptPrivateKey);
|
|
|
if (rc != Error_Succeed) {
|
|
@@ -1983,7 +1701,6 @@ bool CInitializerEntity::HasCkCodeFlg()
|
|
|
{
|
|
|
LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_SYSTEM_STATIC_INFO,
|
|
|
GetOutPutStr("%s%08X", "GetSystemStaticInfo", rc).c_str());
|
|
|
- //LogError(Severity_Middle, rc, ERROR_ACCESSAUTH_GETSTATICINFO, "HasCkCodeFlg()=>GetSystemStaticInfo() fail");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -2093,8 +1810,6 @@ bool CInitializerEntity::GetAccessauthIsFirst()
|
|
|
}
|
|
|
runInfoPath += SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "AccessAuthorization.ini";
|
|
|
|
|
|
- //char isFirst[BUF_SIZE] = { 0 };
|
|
|
- //GetPrivateProfileString("SM", "IsFirst", "", isFirst, BUF_SIZE, runInfoPath.GetData());
|
|
|
char* isFirst;
|
|
|
isFirst = inifile_read_str(runInfoPath.GetData(), "SM", "IsFirst", "");
|
|
|
|