Skip to content

Commit a90c97c

Browse files
committed
modify:pass encrypt via client only
1 parent c81cd40 commit a90c97c

File tree

10 files changed

+47
-73
lines changed

10 files changed

+47
-73
lines changed

XEngine_Release/XEngine_Config/XEngine_Config.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
"tszKeyFile":"./APPVer.key",
3030
"tszKeyPass":"123123qa"
3131
},
32-
"st_PassCrypto":{
33-
"bEnable":false,
34-
"nCodec":2
35-
},
3632
"st_XToken":{
3733
"bAutoRenewal":false,
3834
"nRenewalTime":-1

XEngine_Source/AuthorizeModule_Client/AuthClient_Connector/AuthClient_Connector.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,17 @@ bool CAuthClient_Connector::AuthClient_Connector_GetAuth(bool* pbAuth /* = NULL
140140
类型:句柄型
141141
可空:Y
142142
意思:输入动态码绑定的句柄
143+
参数.五:dwCryption
144+
In/Out:In
145+
类型:整数型
146+
可空:Y
147+
意思:输入密码加密类型
143148
返回值
144149
类型:逻辑型
145150
意思:是否成功
146151
备注:
147152
*********************************************************************/
148-
bool CAuthClient_Connector::AuthClient_Connector_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, int nDYCode /* = 0 */, XNETHANDLE xhToken /* = 0 */)
153+
bool CAuthClient_Connector::AuthClient_Connector_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, int nDYCode /* = 0 */, XNETHANDLE xhToken /* = 0 */, XLONG dwCryption /* = 0 */)
149154
{
150155
AuthClient_IsErrorOccur = false;
151156

@@ -174,7 +179,18 @@ bool CAuthClient_Connector::AuthClient_Connector_Login(LPCXSTR lpszUser, LPCXSTR
174179
st_AuthUser.enDeviceType = ENUM_PROTOCOL_FOR_DEVICE_TYPE_PC_MACOS;
175180
#endif
176181
_tcsxcpy(st_AuthUser.tszUserName, lpszUser);
177-
_tcsxcpy(st_AuthUser.tszUserPass, lpszPass);
182+
183+
if (dwCryption > 0)
184+
{
185+
int nPLen = _tcsxlen(lpszPass);
186+
XBYTE byMD5Buffer[MAX_PATH] = {};
187+
Cryption_Api_Digest(lpszPass, byMD5Buffer, &nPLen, false, dwCryption);
188+
BaseLib_String_StrToHex((LPCXSTR)byMD5Buffer, nPLen, st_AuthUser.tszUserPass);
189+
}
190+
else
191+
{
192+
_tcsxcpy(st_AuthUser.tszUserPass, lpszPass);
193+
}
178194
//是否有动态码
179195
if (nDYCode > 0)
180196
{

XEngine_Source/AuthorizeModule_Client/AuthClient_Connector/AuthClient_Connector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CAuthClient_Connector
2626
bool AuthClient_Connector_Connect(LPCXSTR lpszClientAddr, int nPort, LPCXSTR lpszPass = NULL);
2727
bool AuthClient_Connector_Close();
2828
bool AuthClient_Connector_GetAuth(bool* pbAuth = NULL);
29-
bool AuthClient_Connector_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, int nDYCode = 0, XNETHANDLE xhToken = 0);
29+
bool AuthClient_Connector_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, int nDYCode = 0, XNETHANDLE xhToken = 0, XLONG dwCryption = 0);
3030
bool AuthClient_Connector_Heart(bool bEnable = true);
3131
protected:
3232
static XHTHREAD CALLBACK AuthClient_Connector_Thread(XPVOID lParam);

XEngine_Source/AuthorizeModule_Client/AuthClient_Define.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,17 @@ extern "C" bool AuthClient_Connector_GetAuth(bool* pbAuth = NULL);
8787
类型:句柄型
8888
可空:Y
8989
意思:输入动态码绑定的句柄
90+
参数.五:dwCryption
91+
In/Out:In
92+
类型:整数型
93+
可空:Y
94+
意思:输入密码加密类型
9095
返回值
9196
类型:逻辑型
9297
意思:是否成功
9398
备注:
9499
*********************************************************************/
95-
extern "C" bool AuthClient_Connector_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, int nDYCode = 0, XNETHANDLE xhToken = 0);
100+
extern "C" bool AuthClient_Connector_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, int nDYCode = 0, XNETHANDLE xhToken = 0, XLONG dwCryption = 0);
96101
/********************************************************************
97102
函数名称:AuthClient_Connector_Heart
98103
函数功能:启用禁用客户端心跳

XEngine_Source/AuthorizeModule_Client/pch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ extern "C" bool AuthClient_Connector_GetAuth(bool* pbAuth)
4343
{
4444
return m_Connector.AuthClient_Connector_GetAuth(pbAuth);
4545
}
46-
extern "C" bool AuthClient_Connector_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, int nDYCode, XNETHANDLE xhToken)
46+
extern "C" bool AuthClient_Connector_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, int nDYCode, XNETHANDLE xhToken, XLONG dwCryption)
4747
{
48-
return m_Connector.AuthClient_Connector_Login(lpszUser, lpszPass, nDYCode, xhToken);
48+
return m_Connector.AuthClient_Connector_Login(lpszUser, lpszPass, nDYCode, xhToken, dwCryption);
4949
}
5050
extern "C" bool AuthClient_Connector_Heart(bool bEnable)
5151
{

XEngine_Source/AuthorizeModule_Configure/Config_Define.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ typedef struct
4545
XCHAR tszKeyFile[MAX_PATH]; //本地CDKEY文件地址
4646
XCHAR tszKeyPass[MAX_PATH]; //本地CDKEY密码
4747
}st_XCDKey;
48-
struct
49-
{
50-
bool bEnable; //是否启用
51-
int nCodec; //加密方法:ENUM_XENGINE_OPENSSL_DIGEST
52-
}st_PassCrypto;
5348
struct
5449
{
5550
bool bAutoRenewal; //自动续期

XEngine_Source/AuthorizeModule_Configure/ModuleConfigure_Json/ModuleConfigure_Json.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE
113113
pSt_ServerConfig->st_XTime.nWSTime = st_JsonXTime["nWSTime"].asInt();
114114
pSt_ServerConfig->st_XTime.nHTTPTime = st_JsonXTime["nHTTPTime"].asInt();
115115
//验证配置
116-
if (st_JsonRoot["XVerification"].empty() || (9 != st_JsonRoot["XVerification"].size()))
116+
if (st_JsonRoot["XVerification"].empty() || (8 != st_JsonRoot["XVerification"].size()))
117117
{
118118
Config_IsErrorOccur = true;
119119
Config_dwErrorCode = ERROR_AUTHORIZE_MODULE_CONFIGURE_XVER;
@@ -130,9 +130,6 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE
130130
_tcsxcpy(pSt_ServerConfig->st_XVerification.st_XCDKey.tszKeyFile, st_JsonXVerification["st_XCDKey"]["tszKeyFile"].asCString());
131131
_tcsxcpy(pSt_ServerConfig->st_XVerification.st_XCDKey.tszKeyPass, st_JsonXVerification["st_XCDKey"]["tszKeyPass"].asCString());
132132

133-
pSt_ServerConfig->st_XVerification.st_PassCrypto.bEnable = st_JsonXVerification["st_PassCrypto"]["bEnable"].asBool();
134-
pSt_ServerConfig->st_XVerification.st_PassCrypto.nCodec = st_JsonXVerification["st_PassCrypto"]["nCodec"].asInt();
135-
136133
pSt_ServerConfig->st_XVerification.st_XToken.bAutoRenewal = st_JsonXVerification["st_XToken"]["bAutoRenewal"].asBool();
137134
pSt_ServerConfig->st_XVerification.st_XToken.nRenewalTime = st_JsonXVerification["st_XToken"]["nRenewalTime"].asInt();
138135
//登录配置

XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Client.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,6 @@ bool XEngine_AuthorizeHTTP_Client(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, L
107107
memset(&st_UserTable, '\0', sizeof(AUTHREG_USERTABLE));
108108

109109
Protocol_Parse_HttpParseTable(lpszMsgBuffer, nMsgLen, &st_UserTable);
110-
111-
if (st_AuthConfig.st_XVerification.st_PassCrypto.bEnable)
112-
{
113-
int nPLen = _tcsxlen(st_UserTable.st_UserInfo.tszUserPass);
114-
XBYTE byMD5Buffer[MAX_PATH] = {};
115-
Cryption_Api_Digest(st_UserTable.st_UserInfo.tszUserPass, byMD5Buffer, &nPLen, false, st_AuthConfig.st_XVerification.st_PassCrypto.nCodec);
116-
memset(st_UserTable.st_UserInfo.tszUserPass, '\0', sizeof(st_UserTable.st_UserInfo.tszUserPass));
117-
BaseLib_String_StrToHex((LPCXSTR)byMD5Buffer, nPLen, st_UserTable.st_UserInfo.tszUserPass);
118-
}
119110
bool bSuccess = false;
120111
if (0 == st_AuthConfig.st_XSql.nDBType)
121112
{

XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_User.cpp

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,6 @@ bool XEngine_AuthorizeHTTP_User(XNETHANDLE xhToken, LPCXSTR lpszClientAddr, LPCX
132132
return false;
133133
}
134134
bSuccess = false;
135-
136-
if (st_AuthConfig.st_XVerification.st_PassCrypto.bEnable)
137-
{
138-
int nPLen = _tcsxlen(st_UserTable.st_UserInfo.tszUserPass);
139-
XBYTE byMD5Buffer[MAX_PATH] = {};
140-
Cryption_Api_Digest(st_UserTable.st_UserInfo.tszUserPass, byMD5Buffer, &nPLen, false, st_AuthConfig.st_XVerification.st_PassCrypto.nCodec);
141-
memset(st_UserTable.st_UserInfo.tszUserPass, '\0', sizeof(st_UserTable.st_UserInfo.tszUserPass));
142-
BaseLib_String_StrToHex((LPCXSTR)byMD5Buffer, nPLen, st_UserTable.st_UserInfo.tszUserPass);
143-
}
144-
145135
if (0 == st_AuthConfig.st_XSql.nDBType)
146136
{
147137
bSuccess = DBModule_SQLite_UserRegister(&st_UserTable);
@@ -247,32 +237,23 @@ bool XEngine_AuthorizeHTTP_User(XNETHANDLE xhToken, LPCXSTR lpszClientAddr, LPCX
247237
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,用户名:%s,找回重置密码失败,验证信息失败"), lpszClientAddr, st_UserInfo.tszUserName);
248238
return false;
249239
}
250-
//是否开启了密码加密
251-
if (st_AuthConfig.st_XVerification.st_PassCrypto.bEnable)
252-
{
253-
//开启了,密码重置
254-
int nPLen = _tcsxlen(st_UserInfo.tszUserPass);
255-
XBYTE byMD5Buffer[MAX_PATH] = {};
256-
Cryption_Api_Digest(st_UserInfo.tszUserPass, byMD5Buffer, &nPLen, false, st_AuthConfig.st_XVerification.st_PassCrypto.nCodec);
257-
memset(st_UserTable.st_UserInfo.tszUserPass, '\0', sizeof(st_UserTable.st_UserInfo.tszUserPass));
258-
BaseLib_String_StrToHex((LPCXSTR)byMD5Buffer, nPLen, st_UserTable.st_UserInfo.tszUserPass);
259-
//重置密码
260-
if (0 == st_AuthConfig.st_XSql.nDBType)
261-
{
262-
bSuccess = DBModule_SQLite_UserSet(&st_UserTable);
263-
}
264-
else
265-
{
266-
bSuccess = DBModule_MySQL_UserSet(&st_UserTable);
267-
}
268-
if (!bSuccess)
269-
{
270-
Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen, ERROR_AUTHORIZE_PROTOCOL_NOTFOUND, "not found client");
271-
XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP);
272-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,请求修改密码失败:%s 错误码:%lX"), lpszClientAddr, st_UserTable.st_UserInfo.tszUserName, DBModule_GetLastError());
273-
return false;
274-
}
240+
//重置密码
241+
if (0 == st_AuthConfig.st_XSql.nDBType)
242+
{
243+
bSuccess = DBModule_SQLite_UserSet(&st_UserTable);
244+
}
245+
else
246+
{
247+
bSuccess = DBModule_MySQL_UserSet(&st_UserTable);
275248
}
249+
if (!bSuccess)
250+
{
251+
Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen, ERROR_AUTHORIZE_PROTOCOL_SERVER, "server set db failed");
252+
XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP);
253+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,请求修改密码失败:%s 错误码:%lX"), lpszClientAddr, st_UserTable.st_UserInfo.tszUserName, DBModule_GetLastError());
254+
return false;
255+
}
256+
276257
XENGINE_PROTOCOL_USERAUTH st_AuthProtocol = {};
277258
_tcsxcpy(st_AuthProtocol.tszUserName, st_UserTable.st_UserInfo.tszUserName);
278259
_tcsxcpy(st_AuthProtocol.tszUserPass, st_UserTable.st_UserInfo.tszUserPass);

XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_Net.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,9 @@ bool XEngine_SendMsg(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen,
197197
}
198198
else
199199
{
200-
XCHAR* ptszCodecBuffer = (XCHAR*)ManagePool_Memory_Alloc(xhMemPool, XENGINE_MEMORY_SIZE_MAX);
201-
if (NULL == ptszCodecBuffer)
202-
{
203-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("客户端:%s,网络类型:%d 发送数据失败,内存申请失败,错误码:%d"), lpszClientAddr, nNetType, errno);
204-
return false;
205-
}
206-
207-
Cryption_XCrypto_Encoder(lpszMsgBuffer, &nMsgLen, (XBYTE*)ptszCodecBuffer, lpszPass);
208-
HttpProtocol_Server_SendMsgEx(xhHttpPacket, m_HTTPMemory.get(), &nSDSize, &st_HDRParam, ptszCodecBuffer, nMsgLen);
209-
ManagePool_Memory_Free(xhMemPool, ptszCodecBuffer);
200+
CHttpMemory_PoolEx m_CodecMemory(XENGINE_MEMORY_SIZE_MAX);
201+
Cryption_XCrypto_Encoder(lpszMsgBuffer, &nMsgLen, (XBYTE*)m_CodecMemory.get(), lpszPass);
202+
HttpProtocol_Server_SendMsgEx(xhHttpPacket, m_HTTPMemory.get(), &nSDSize, &st_HDRParam, m_CodecMemory.get(), nMsgLen);
210203
}
211204
NetCore_TCPXCore_SendEx(xhHttpSocket, lpszClientAddr, m_HTTPMemory.get(), nSDSize);
212205
SocketOpt_HeartBeat_ActiveAddrEx(xhHTTPHeart, lpszClientAddr);

0 commit comments

Comments
 (0)