|
@@ -4,9 +4,11 @@
|
|
|
#include "RVCComm.h"
|
|
|
#include "access_basefun.h"
|
|
|
#include <fileutil.h>
|
|
|
+#include <iniutil.h>
|
|
|
#include <cmath>
|
|
|
#include "Event.h"
|
|
|
#include "comm.h"
|
|
|
+#include "CommEntityRestful.hpp"
|
|
|
#include "TokenKeeper_client_g.h"
|
|
|
using namespace TokenKeeper;
|
|
|
#include "PinPad_client_g.h"
|
|
@@ -19,9 +21,7 @@ using namespace PinPad;
|
|
|
#include "DeviceBaseClass.h"
|
|
|
#include "MyBase64.h"
|
|
|
#else
|
|
|
-#include "CommEntityRestful.hpp"
|
|
|
#include "DeviceBaseClass.h"
|
|
|
-#include <iniutil.h>
|
|
|
#endif
|
|
|
|
|
|
#define KEY_SIZE 16
|
|
@@ -40,67 +40,6 @@ struct InitializerInitMKTask : ITaskSp
|
|
|
{
|
|
|
CSystemStaticInfo si;
|
|
|
m_fsm->GetEntityBase()->GetFunction()->GetSystemStaticInfo(si);
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- IHttpFunc* client;
|
|
|
- client = create_http(m_fsm->HttpsLogCallBack);
|
|
|
- CInitlizerMKReq initMKReq;
|
|
|
- CInitlizerMKRet initMKRet;
|
|
|
- bool initFlag = m_entity->SendInitMKReqACS(initMKReq);
|
|
|
-
|
|
|
- if (!initFlag)
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5204")("连接密码键盘异常");
|
|
|
- m_entity->EndInitMK(ERR_ACCESSAUTH_CONNECT_PINPAD, "连接密码键盘异常,请检查");//,待完善细化错误码oiltest
|
|
|
- client->Destory();
|
|
|
- }
|
|
|
-
|
|
|
- auto tmkpair = m_entity->GenerateTmkToKMC();
|
|
|
- initMKReq.encRandom = tmkpair.first;
|
|
|
- initMKReq.m_url = m_entity->GetInitUrl();
|
|
|
- initMKReq.m_url += "/api/v5/initmk";
|
|
|
- long beg = GetTickCount();
|
|
|
- bool ret = client->Post(initMKReq, initMKRet);
|
|
|
- long end = GetTickCount();
|
|
|
-
|
|
|
- if (ret) {
|
|
|
- if (initMKRet.m_userCode.compare(ACS_SUCCESS)) {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InitializerInitMKTask")("initmk failed.");
|
|
|
- if (client) client->Destory();
|
|
|
- m_entity->EndInitMK(ERR_INITIALIZER_EXCEPTION, CSimpleStringA::Format("%s,%s"
|
|
|
- , initMKRet.m_userCode.c_str(), initMKRet.m_errMsg.c_str()));
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- //服务端返回成功再将数据写入AcessAuthourization.ini
|
|
|
- CSmartPointer<IConfigInfo> pConfig;
|
|
|
- auto rc = m_entity->GetFunction()->OpenConfig(Config_Run, pConfig);
|
|
|
- rc = pConfig->WriteConfigValue("TerminalPD", "PrivateKey", m_entity->m_privateKey);
|
|
|
- if (rc != Error_Succeed) {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("write pri key failed.");
|
|
|
- m_entity->EndInitMK(ERR_INITIALIZER_EXCEPTION, "私钥写入失败,请重新初始化。");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (m_entity->HasPinPad()) {
|
|
|
- if (m_entity->LoadKeysToPinPadACS(tmkpair.second, initMKRet.tpk, initMKRet.edk, initMKRet.keyIndex,initMKRet.tpkKeyCheck,initMKRet.edkKeyCheck) == Error_Succeed)
|
|
|
- m_entity->EndInitMK(Error_Succeed, "");
|
|
|
- else
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5204")("连接密码键盘异常");
|
|
|
- m_entity->EndInitMK(ERR_ACCESSAUTH_CONNECT_PINPAD, "密钥加载失败,请检查密码键盘连接。");//,待完善细化错误码oiltest
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- m_entity->EndInitMK(Error_Succeed, "");
|
|
|
- }
|
|
|
- else {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI("InitializerInitMKTask").setBeginTime(beg).setEndTime(end).
|
|
|
- setResultCode(std::to_string(LONGLONG(initMKRet.m_sysCode)).c_str()).
|
|
|
- setResultMsg(initMKRet.m_errMsg.c_str())("InitializerInitMKTask Connect Failed.");
|
|
|
- m_entity->EndInitMK(ERR_INITIALIZER_EXCEPTION, CSimpleStringA::Format("初始化服务连接失败。%d", ret).GetData());
|
|
|
- }
|
|
|
- client->Destory();
|
|
|
-#else
|
|
|
CInitlizerMKReq initMKReq;//oiltest dev module count
|
|
|
bool initFlag = m_entity->SendInitMKReqACS(initMKReq);
|
|
|
if (!initFlag)
|
|
@@ -229,7 +168,6 @@ struct InitializerInitMKTask : ITaskSp
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("post wk failed: %s", result.WhatError().c_str());
|
|
|
m_entity->EndInitMK(ERR_INITIALIZER_EXCEPTION, CSimpleStringA::Format("初始化服务连接失败。%s", result.WhatError().c_str()).GetData());
|
|
|
}
|
|
|
-#endif //RVC_OS_WIN
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -592,26 +530,16 @@ 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, iniPath.GetData());
|
|
|
-#else
|
|
|
iniPath = runInfoPath + SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "AccessAuthorization.ini";
|
|
|
char* tmp = inifile_read_str(iniPath.GetData(), "TerminalPD", "PrivateKey", "");
|
|
|
strcpy(privateKey, tmp);
|
|
|
delete tmp;
|
|
|
-#endif // RVC_OS_WIN
|
|
|
|
|
|
if (strlen(privateKey) <= 0) {
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- iniPath = runInfoPath + "\\runcfg\\Initializer.ini";
|
|
|
- GetPrivateProfileString("TerminalPD", "PrivateKey", "", privateKey, BUF_SIZE, iniPath.GetData());
|
|
|
-#else
|
|
|
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;
|
|
|
-#endif // RVC_OS_WIN
|
|
|
if (strlen(privateKey) <= 0)
|
|
|
{
|
|
|
printPasswdError("私钥为空,请重置秘钥进行初始化");
|
|
@@ -621,11 +549,7 @@ bool CAccessAuthEntity::SaveAuthKey(BYTE *pKey)
|
|
|
|
|
|
int decodedPrivateKeyLen;
|
|
|
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- char* pDecodedPrivateKey = MyBase64::Hex2Str(privateKey, decodedPrivateKeyLen);
|
|
|
-#else
|
|
|
char* pDecodedPrivateKey = Hex2Str(privateKey, decodedPrivateKeyLen);
|
|
|
-#endif // RVC_OS_WIN
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("privateKey len:%d, decodedPrivateKeyLen=%d", strlen(privateKey), decodedPrivateKeyLen);
|
|
|
|
|
|
char pDecryptPrivateKey[BUF_SIZE] = { 0 };
|
|
@@ -643,11 +567,7 @@ 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)("kenLen=%d", kenLen);
|
|
|
delete pEncodeKey;
|
|
|
char* key = new char[kenLen + 1];
|
|
@@ -699,21 +619,13 @@ ErrorCodeEnum CAccessAuthEntity::EncryptDataWithSessionKey(const CBlob &raw, CBl
|
|
|
BYTE* pEncData = new BYTE[1024];
|
|
|
int pEncDataSize = 1024;
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("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)("raw Length=%d", raw.m_iLength);
|
|
|
delete[] pPlainInfo;
|
|
|
|
|
|
char sessionKey[KEY_SIZE] = { 0 };
|
|
|
memcpy(sessionKey,m_AuthSessionKey,KEY_SIZE);
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- char* tmpKey = MyBase64::Str2Hex((char*)m_AuthSessionKey, KEY_SIZE);
|
|
|
-#else
|
|
|
char* tmpKey = Str2Hex((char*)m_AuthSessionKey, KEY_SIZE);
|
|
|
-#endif // RVC_OS_WIN
|
|
|
delete[] tmpKey;
|
|
|
|
|
|
if (!EncWithSM4_ECB((BYTE*)sessionKey, (BYTE*)(raw.m_pData), raw.m_iLength, pEncData, &pEncDataSize)) {
|
|
@@ -723,19 +635,11 @@ ErrorCodeEnum CAccessAuthEntity::EncryptDataWithSessionKey(const CBlob &raw, CBl
|
|
|
|
|
|
enc.Attach(pEncData,pEncDataSize);
|
|
|
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- char* tmp = MyBase64::Str2Hex((char*)pEncData, pEncDataSize);
|
|
|
-#else
|
|
|
char* tmp = Str2Hex((char*)pEncData, pEncDataSize);
|
|
|
-#endif // RVC_OS_WIN
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("pEncData size:%d", pEncDataSize);
|
|
|
delete[] tmp;
|
|
|
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- tmp = MyBase64::Str2Hex((char*)enc.m_pData, enc.m_iLength);
|
|
|
-#else
|
|
|
tmp = Str2Hex((char*)enc.m_pData, enc.m_iLength);
|
|
|
-#endif // RVC_OS_WIN
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("EncWithSM4_ECB data size:%d", enc.m_iLength);
|
|
|
delete[] tmp;
|
|
|
|
|
@@ -872,16 +776,6 @@ bool CAccessAuthEntity::GetTerminalFingerPrint(BYTE *pBuf, int &nBufLen)
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
-#define RSAPUBKEY_BITLEN 1024
|
|
|
-struct PublicKeyBlob
|
|
|
-{
|
|
|
- PUBLICKEYSTRUC publickeystruc;
|
|
|
- RSAPUBKEY rsapubkey;
|
|
|
- BYTE modulus[RSAPUBKEY_BITLEN / 8];
|
|
|
-};
|
|
|
-#endif // RVC_OS_WIN
|
|
|
-
|
|
|
// 生成RSA密钥对,并导出公钥
|
|
|
bool CAccessAuthEntity::GetTerminalPublicKey(BYTE* pBuf, int& nBufLen, string& pubkey)
|
|
|
{
|
|
@@ -892,8 +786,8 @@ bool CAccessAuthEntity::GetTerminalPublicKey(BYTE* pBuf, int& nBufLen, string& p
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("GetPath runinfo error=%d.", rc);
|
|
|
return false;
|
|
|
}
|
|
|
+ runInfoPath += SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR;
|
|
|
#ifdef RVC_OS_WIN
|
|
|
- runInfoPath += "\\runcfg\\";
|
|
|
DWORD dwAttr = GetFileAttributes(runInfoPath.GetData());
|
|
|
if (dwAttr == 0xFFFFFFFF) //目录不存在则创建
|
|
|
{
|
|
@@ -903,7 +797,6 @@ bool CAccessAuthEntity::GetTerminalPublicKey(BYTE* pBuf, int& nBufLen, string& p
|
|
|
}
|
|
|
}
|
|
|
#else
|
|
|
- runInfoPath += SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR;
|
|
|
if (!dir_is_exist(runInfoPath.GetData()))
|
|
|
{
|
|
|
if (dir_create(runInfoPath.GetData()) != 0)
|
|
@@ -935,11 +828,7 @@ bool CAccessAuthEntity::GetTerminalPublicKey(BYTE* pBuf, int& nBufLen, string& p
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("iPublicKeyLen=%d,iPrivateKeyLen=%d", iPublicKeyLen, iPrivateKeyLen);
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("[btPublicKey=%s]", (char*)btPublicKey);
|
|
|
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- char* pEncode = MyBase64::Str2Hex((char*)btPublicKey, iPublicKeyLen);
|
|
|
-#else
|
|
|
char* pEncode = Str2Hex((char*)btPublicKey, iPublicKeyLen);
|
|
|
-#endif // RVC_OS_WIN
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("pEncode=%s,%d", pEncode, strlen(pEncode));
|
|
|
|
|
|
/*rc = pConfig->WriteConfigValue("TerminalPD", "PublicKey", pEncode);
|
|
@@ -962,11 +851,7 @@ bool CAccessAuthEntity::GetTerminalPublicKey(BYTE* pBuf, int& nBufLen, string& p
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("sm4 encrypt pri key success.");
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("cryptPrivateKeyLen=%d", cryptPrivateKeyLen);
|
|
|
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- char* pEncodedCryptPrivateKey = MyBase64::Str2Hex((char*)pCryptPrivateKey, cryptPrivateKeyLen);
|
|
|
-#else
|
|
|
char* pEncodedCryptPrivateKey = Str2Hex((char*)pCryptPrivateKey, cryptPrivateKeyLen);
|
|
|
-#endif // RVC_OS_WIN
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("encode pri key success.");
|
|
|
|
|
|
m_privateKey = pEncodedCryptPrivateKey;
|
|
@@ -982,11 +867,7 @@ bool CAccessAuthEntity::GetTerminalPublicKey(BYTE* pBuf, int& nBufLen, string& p
|
|
|
delete[] pEncode;
|
|
|
delete[] pEncodedCryptPrivateKey;
|
|
|
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- char* pDecode = MyBase64::Hex2Str(publicKey.GetData(), nBufLen);
|
|
|
-#else
|
|
|
char* pDecode = Hex2Str(publicKey.GetData(), nBufLen);
|
|
|
-#endif // RVC_OS_WIN
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetTerminalPublicKey")("pDecode=[%s],len=%d", pDecode, nBufLen);
|
|
|
|
|
|
memcpy(pBuf, pDecode, nBufLen);
|
|
@@ -1000,7 +881,6 @@ int CAccessAuthEntity::GetPinPadIDAndDeviceID(CSimpleStringA &strPinPadID, CSimp
|
|
|
{
|
|
|
isPinPadMac = false;
|
|
|
bPinPadOnline = false;
|
|
|
- m_bNewSMFWB = false;
|
|
|
CSimpleStringA strErrMsg;
|
|
|
CSmartPointer<IEntityFunction> spFunction = this->GetFunction();
|
|
|
|
|
@@ -1079,15 +959,6 @@ int CAccessAuthEntity::GetPinPadIDAndDeviceID(CSimpleStringA &strPinPadID, CSimp
|
|
|
if (!strBluetoothID.IsNullOrEmpty())
|
|
|
bBluetooth = true;
|
|
|
}
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- else if (!strnicmp((LPCTSTR)arr2[0], "PM", strlen("PM")))
|
|
|
- {
|
|
|
- CSimpleStringA strPM = arr2[1];
|
|
|
-
|
|
|
- if (!strPM.IsNullOrEmpty() && strPM.Compare("V3.0", true) == 0)
|
|
|
- m_bNewSMFWB = true;
|
|
|
- }
|
|
|
-#endif // RVC_OS_WIN
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1370,42 +1241,6 @@ bool CAccessAuthEntity::SendInitMKReqACS(CInitlizerMKReq& initMKReq)
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
|
CSmartPointer<IEntityFunction> pFunc = GetFunction();
|
|
|
-#ifdef RVC_OS_LINUX
|
|
|
- if (HasPinPad())
|
|
|
- {
|
|
|
- CSmartPointer<IConfigInfo> pConfig;
|
|
|
- DWORD rc = pFunc->OpenConfig(Config_CenterSetting, pConfig);
|
|
|
- if (rc != Error_Succeed)
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, (ErrorCodeEnum)rc, ERR_INITIALIZER_FILE_ERROR,
|
|
|
- GetOutPutStr("%s%08X%s%s", "OpenConfig", rc, "File", "Config_CenterSetting").c_str());
|
|
|
- rc = ERR_INITIALIZER_FILE_ERROR;
|
|
|
- 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_FILE_ERROR,
|
|
|
- GetOutPutStr("%s%08X%s%s", "ReadConfigValue", rc, "File", "SubBankNo & BranchNo").c_str());
|
|
|
- rc = ERR_INITIALIZER_FILE_ERROR;
|
|
|
- return rc;
|
|
|
- }
|
|
|
-
|
|
|
- // 1:3des only; 2: sm4 only; 3: both 3des and sm4
|
|
|
- int nCapability = GetPinPadCapability();
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("pinpad capability: %d", nCapability);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("has no pinpad, not need init MK");
|
|
|
- }
|
|
|
-#endif // RVC_OS_LINUX
|
|
|
-
|
|
|
CSimpleStringA strPinPadID = "", strDeviceID = "";
|
|
|
bool isPinPadMac, bPinPadOnline;
|
|
|
int nRet = GetPinPadIDAndDeviceID(strPinPadID, strDeviceID, isPinPadMac, bPinPadOnline);
|
|
@@ -1579,13 +1414,6 @@ void CAccessAuthEntity::EndInitMK(DWORD rc, const char *pszErrMsg)
|
|
|
ErrorCodeEnum CAccessAuthEntity::LoadKeysToPinPadACS(string TMK, string TPK, string EDK, string index, string tpkCheck, string edkCheck)
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- if (m_bNewSMFWB && m_FSM.GetDevPubKey().GetLength() <= 0)
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("新蓝牙多合一密钥初始化依赖加密通道建立时的设备公钥,不具备,跳过密钥初始化");
|
|
|
- return Error_Succeed;
|
|
|
- }
|
|
|
-#endif // RVC_OS_WIN
|
|
|
//加载到密码键盘
|
|
|
PinPadService_ClientBase* pPinPad = new PinPadService_ClientBase(this);
|
|
|
auto rc = pPinPad->Connect();
|
|
@@ -1593,24 +1421,8 @@ ErrorCodeEnum CAccessAuthEntity::LoadKeysToPinPadACS(string TMK, string TPK, str
|
|
|
{
|
|
|
PinPadService_LoadKeysSM_Req req = {};
|
|
|
req.initializeflag = true;
|
|
|
- if (m_bNewSMFWB)
|
|
|
- {
|
|
|
- //oilyang@20220902 to encrypte tmp using device public key
|
|
|
- req.smflag = 11;
|
|
|
- auto tmkpairDev = GenerateTmkToDevice();
|
|
|
- if (tmkpairDev.first.length() <= 0)
|
|
|
- {
|
|
|
- //oiltest todo 补充错误信息
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- else
|
|
|
- req.masterkey = tmkpairDev.first.c_str();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- req.smflag = 1;
|
|
|
- req.masterkey = TMK.c_str();
|
|
|
- }
|
|
|
+ req.smflag = 1;
|
|
|
+ req.masterkey = TMK.c_str();
|
|
|
|
|
|
req.workingkey1 = TPK.c_str();
|
|
|
req.workingkey2 = EDK.c_str();
|
|
@@ -1713,31 +1525,18 @@ pair<string, string> CAccessAuthEntity::EncryptedByPubKey(CSimpleStringA pubKey,
|
|
|
if (pubKey.GetLength() <= 0)
|
|
|
return make_pair("", "");
|
|
|
PCHAR strRam = new CHAR[512];
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- ZeroMemory(strRam, 512);
|
|
|
-#else
|
|
|
memset(strRam, 0, 512);
|
|
|
-#endif // RVC_OS_WIN
|
|
|
memcpy(strRam, &(m_btRam[0]), 16);
|
|
|
HexBuf2StrBuf((PBYTE)m_btRam, &strRam, 16);
|
|
|
const int MAX_KEY_SIZE = 256;
|
|
|
char random_enc_bypbk[MAX_KEY_SIZE];
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- ZeroMemory(random_enc_bypbk, MAX_KEY_SIZE);
|
|
|
-#else
|
|
|
memset(random_enc_bypbk, 0, MAX_KEY_SIZE);
|
|
|
-#endif // RVC_OS_WIN
|
|
|
//公钥加密随机数
|
|
|
int outMsgLen = MAX_KEY_SIZE;
|
|
|
PBYTE pxxKey = new BYTE[256];
|
|
|
PBYTE pOldPubKey = new BYTE[256];
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- ZeroMemory(pxxKey, 256);
|
|
|
- ZeroMemory(pOldPubKey, 256);
|
|
|
-#else
|
|
|
memset(pOldPubKey, 0, 256);
|
|
|
memset(pxxKey, 0, 256);
|
|
|
-#endif // RVC_OS_WIN
|
|
|
|
|
|
int size = StrBuf2HexBuf(pubKey.GetData(), &pOldPubKey);
|
|
|
if (bNeed04Head)
|
|
@@ -1755,12 +1554,8 @@ pair<string, string> CAccessAuthEntity::EncryptedByPubKey(CSimpleStringA pubKey,
|
|
|
}
|
|
|
|
|
|
PBYTE tmp_enc_bypbk = new BYTE[112];
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- ZeroMemory(tmp_enc_bypbk, 112);
|
|
|
-#else
|
|
|
memset(tmp_enc_bypbk, 0, 112);
|
|
|
-#endif // RVC_OS_WIN
|
|
|
- //tmp_enc_bypbk[0] = 0x04;
|
|
|
+
|
|
|
if (bNeed04Head)
|
|
|
{
|
|
|
memcpy(tmp_enc_bypbk, &(random_enc_bypbk[1]), 112);
|
|
@@ -1774,11 +1569,7 @@ pair<string, string> CAccessAuthEntity::EncryptedByPubKey(CSimpleStringA pubKey,
|
|
|
|
|
|
|
|
|
PCHAR pBlock = new CHAR[512];
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- ZeroMemory(pBlock, 512);
|
|
|
-#else
|
|
|
memset(pBlock, 0, 512);
|
|
|
-#endif // RVC_OS_WIN
|
|
|
BYTE tmpRandomEnc[512];
|
|
|
memset(tmpRandomEnc, 0, 512);
|
|
|
memcpy(tmpRandomEnc, &(tmp_enc_bypbk[0]), outMsgLen - 1);
|