77#pragma comment(lib,"XEngine_SystemSdk/XEngine_SystemApi")
88#ifdef _WIN64
99#pragma comment(lib,"../../XEngine_Source/x64/Debug/jsoncpp")
10- #pragma comment(lib,"../../XEngine_Source/x64/Debug/AuthorizeModule_CDKey ")
10+ #pragma comment(lib,"../../XEngine_Source/x64/Debug/XEngine_Verification ")
1111#else
1212#pragma comment(lib,"../../XEngine_Source/Debug/jsoncpp")
13- #pragma comment(lib,"../../XEngine_Source/Debug/AuthorizeModule_CDKey ")
13+ #pragma comment(lib,"../../XEngine_Source/Debug/XEngine_Verification ")
1414#endif
1515#endif
1616#include < stdio.h>
2727#include < XEngine_Include/XEngine_Core/Cryption_Error.h>
2828#include < XEngine_Include/XEngine_SystemSdk/SystemApi_Define.h>
2929#include < XEngine_Include/XEngine_SystemSdk/SystemApi_Error.h>
30+ #include " ../../XEngine_Source/XEngine_DependLibrary/XEngine_Module/XEngine_Verification/Verification_Define.h"
31+ #include " ../../XEngine_Source/XEngine_DependLibrary/XEngine_Module/XEngine_Verification/Verification_Error.h"
3032#include " ../../XEngine_Source/XAuth_Protocol.h"
31- #include " ../../XEngine_Source/AuthorizeModule_CDKey/CDKey_Define.h"
32- #include " ../../XEngine_Source/AuthorizeModule_CDKey/CDKey_Error.h"
3333
3434// 需要优先配置XEngine
3535// WINDOWS支持VS2022 x86 debug 编译调试
36- // g++ -std=c++17 -Wall -g Authorize_APPLocal.cpp -o Authorize_APPLocal.exe -I ../../XEngine_Source/XEngine_DependLibrary/XEngine_Module/jsoncpp -L ../../XEngine_Release -lXEngine_BaseLib -lXEngine_Cryption -lXEngine_SystemApi -lAuthorizeModule_CDKey -ljsoncpp -Wl,-rpath=../../XEngine_Release
36+ // g++ -std=c++17 -Wall -g Authorize_APPLocal.cpp -o Authorize_APPLocal.exe -I ../../XEngine_Source/XEngine_DependLibrary/XEngine_Module/jsoncpp -L ../../XEngine_Release -lXEngine_BaseLib -lXEngine_Cryption -lXEngine_SystemApi -lXEngine_Verification -ljsoncpp -Wl,-rpath=../../XEngine_Release
3737
3838XCHAR tszSerialStr[XPATH_MAX] = {};
3939// 1.创建CDKEY.或者由管理员创建.
4040bool Authorize_APPLocal_Create (LPCXSTR lpszKeyFile, LPCXSTR lpszPasswd)
4141{
42- int nRet = 0 ;
43- XCHAR tszENCodecBuffer[4096 ] = {};
44- XCHAR tszDECodecBuffer[4096 ] = {};
45- XENGINE_AUTHORIZE_LOCAL st_AuthLocal = {};
46- SYSTEMAPI_SERIAL_INFOMATION st_SDKSerial = {};
42+ VERIFICATION_XAUTHKEY st_AuthLocal = {};
4743
48- SystemApi_HardWare_GetSerial (&st_SDKSerial);
49- // 网络信息
50- st_AuthLocal.nPort = 5302 ;
51- _tcsxcpy (st_AuthLocal.tszAddr , _X (" http://app.xyry.org" ));
52- // 软件信息
53- st_AuthLocal.st_AuthAppInfo .bInit = false ;
54- st_AuthLocal.st_AuthAppInfo .nExecTime = 0 ;
55- _xstprintf (st_AuthLocal.st_AuthAppInfo .tszAppName , _X (" XEngine_Authorize" ));
56- _xstprintf (st_AuthLocal.st_AuthAppInfo .tszAppVer , _X (" V1.0.0.1" ));
57- // 注册信息
58- st_AuthLocal.st_AuthRegInfo .enHWType = ENUM_AUTHORIZE_MODULE_HW_TYPE_BIOS;
59- st_AuthLocal.st_AuthRegInfo .enRegType = ENUM_AUTHORIZE_MODULE_CDKEY_TYPE_TRY;
60- st_AuthLocal.st_AuthRegInfo .enSerialType = ENUM_AUTHORIZE_MODULE_SERIAL_TYPE_TIME;
61- st_AuthLocal.st_AuthRegInfo .enVModeType = ENUM_AUTHORIZE_MODULE_VERMODE_TYPE_LOCAL;
62- st_AuthLocal.st_AuthRegInfo .nHasTime = 0 ;
63- BaseLib_Time_TimeToStr (st_AuthLocal.st_AuthRegInfo .tszCreateTime );
64- _tcsxcpy (st_AuthLocal.st_AuthRegInfo .tszHardware , st_SDKSerial.tszBoardSerial );
65- _xstprintf (st_AuthLocal.st_AuthRegInfo .tszLeftTime , _X (" 0" )); // 0次试用
66- // 序列号信息.可以不写,如果不想启用用户自己注册.或者交给管理员填充
67- int nSerialCount = 3 ;
68- XCHAR** pptszSerialList;
69- Authorize_Serial_Create (&pptszSerialList, _X (" XAUTH" ), nSerialCount, 9 );
70- _tcsxcpy (tszSerialStr, pptszSerialList[0 ]);
71-
72- st_AuthLocal.st_AuthSerial .st_TimeLimit .nTimeCount = 5 ;
73- _tcsxcpy (st_AuthLocal.st_AuthSerial .st_TimeLimit .tszTimeSerial , pptszSerialList[0 ]);
74-
75- st_AuthLocal.st_AuthSerial .st_DataLimit .bTimeAdd = false ;
76- _tcsxcpy (st_AuthLocal.st_AuthSerial .st_DataLimit .tszDataSerial , pptszSerialList[1 ]);
77- XCHAR tszTimeStr[128 ] = {};
78- XENGINE_LIBTIME st_LibTime = {};
79- BaseLib_Time_GetSysTime (&st_LibTime);
80- st_LibTime.wYear += 1 ; // 一年后过期
81- BaseLib_Time_TimeToStr (tszTimeStr, NULL , true , &st_LibTime);
82-
83- _tcsxcpy (st_AuthLocal.st_AuthSerial .st_DataLimit .tszDataTime , tszTimeStr);
84-
85- _tcsxcpy (st_AuthLocal.st_AuthSerial .st_UNLimit .tszUNLimitSerial , pptszSerialList[2 ]);
86- // 用户信息
87- _xstprintf (st_AuthLocal.st_AuthUserInfo .tszUserName , _X (" qyt" ));
88- _xstprintf (st_AuthLocal.
st_AuthUserInfo .
tszUserContact ,
_X (
" [email protected] " ));
89-
90- Authorize_CDKey_WriteMemory (tszDECodecBuffer, &nRet, &st_AuthLocal);
91- Cryption_XCrypto_Encoder (tszDECodecBuffer, &nRet, (XBYTE*)tszENCodecBuffer, lpszPasswd);
92- FILE* pSt_File = _xtfopen (lpszKeyFile, _X (" wb" ));
93- if (NULL == pSt_File)
44+ if (!Verification_XAuthKey_KeyInit (&st_AuthLocal))
9445 {
95- printf (" create key file is failed\n " );
46+ printf (" Verification_XAuthKey_KeyInit is failed\n " );
9647 return false ;
9748 }
98- fwrite (tszENCodecBuffer, 1 , nRet, pSt_File);
99- fclose (pSt_File);
49+ _tcsxcpy (tszSerialStr, st_AuthLocal.st_AuthSerial .st_TimeLimit .tszTimeSerial );
50+ // 用户信息
51+ _xstprintf (st_AuthLocal.st_AuthUserInfo .tszUserName , _X (" qyt" ));
52+ _xstprintf (st_AuthLocal.
st_AuthUserInfo .
tszUserContact ,
_X (
" [email protected] " ));
10053
54+ Verification_XAuthKey_FileWrite (&st_AuthLocal, lpszKeyFile, lpszPasswd);
10155 return true ;
10256}
10357// 2.打开CDKEY并且授权(授权只能通过自我授权或者由管理员授权,用户不应该可以自己随意授权)
104- bool Authorize_APPLocal_Auth (LPCXSTR lpszKeyFile, LPCXSTR lpszPasswd, LPCXSTR lpszSerialStr )
58+ bool Authorize_APPLocal_Auth (LPCXSTR lpszKeyFile, LPCXSTR lpszPasswd)
10559{
106- XCHAR tszENCodecBuffer[4096 ] = {};
107- XCHAR tszDECodecBuffer[4096 ] = {};
108- XENGINE_AUTHORIZE_LOCAL st_AuthLocal = {};
60+ VERIFICATION_XAUTHKEY st_AuthLocal = {};
10961
110- FILE* pSt_File = _xtfopen (lpszKeyFile, _X (" rb" ));
111- if (NULL == pSt_File)
62+ if (!Verification_XAuthKey_FileRead (&st_AuthLocal, lpszKeyFile, lpszPasswd))
11263 {
113- printf (" open key file is failed\n " );
64+ printf (" Verification_XAuthKey_FileRead is failed\n " );
11465 return false ;
11566 }
116- int nRet = fread (tszENCodecBuffer, 1 , sizeof (tszENCodecBuffer), pSt_File);
117- fclose (pSt_File);
118-
119- Cryption_XCrypto_Decoder (tszENCodecBuffer, &nRet, tszDECodecBuffer, lpszPasswd);
120- // printf("大小:%d,内容:\n%s\n", nRet, tszDECodecBuffer);
121-
122- Authorize_CDKey_ReadMemory (tszDECodecBuffer, nRet, &st_AuthLocal);
123- if (!Authorize_CDKey_UserRegister (&st_AuthLocal, lpszSerialStr))
67+ if (!Verification_XAuthKey_UserRegister (&st_AuthLocal, tszSerialStr))
12468 {
125- printf (" serila verifacation is failed,error code:%lX\n " , Authorize_GetLastError ());
69+ printf (" serila verifacation is failed,error code:%lX\n " , Verification_GetLastError ());
12670 return false ;
12771 }
128-
129- memset (tszENCodecBuffer, ' \0 ' , sizeof (tszENCodecBuffer));
130- memset (tszDECodecBuffer, ' \0 ' , sizeof (tszDECodecBuffer));
131- Authorize_CDKey_WriteMemory (tszDECodecBuffer, &nRet, &st_AuthLocal);
132- Cryption_XCrypto_Encoder (tszDECodecBuffer, &nRet, (XBYTE*)tszENCodecBuffer, lpszPasswd);
133- pSt_File = _xtfopen (lpszKeyFile, _X (" wb" ));
134- fwrite (tszENCodecBuffer, 1 , nRet, pSt_File);
135- fclose (pSt_File);
72+ Verification_XAuthKey_FileWrite (&st_AuthLocal, lpszKeyFile, lpszPasswd);
13673 return true ;
13774}
13875// 3.验证CDkey
139- bool Authorize_APPLocal_Auth (LPCXSTR lpszKeyFile, LPCXSTR lpszPasswd)
76+ bool Authorize_APPLocal_Ver (LPCXSTR lpszKeyFile, LPCXSTR lpszPasswd)
14077{
141- XCHAR tszENCodecBuffer[4096 ] = {};
142- XCHAR tszDECodecBuffer[4096 ] = {};
143- XENGINE_AUTHORIZE_LOCAL st_AuthLocal = {};
144-
145- FILE* pSt_File = _xtfopen (lpszKeyFile, _X (" rb" ));
146- if (NULL == pSt_File)
78+ VERIFICATION_XAUTHKEY st_AuthLocal = {};
79+ if (!Verification_XAuthKey_FileRead (&st_AuthLocal, lpszKeyFile, lpszPasswd))
14780 {
148- printf (" open key file is failed\n " );
81+ printf (" Verification_XAuthKey_FileRead is failed\n " );
14982 return false ;
15083 }
151- int nRet = fread (tszENCodecBuffer, 1 , sizeof (tszENCodecBuffer), pSt_File);
152- fclose (pSt_File);
153-
154- Cryption_XCrypto_Decoder (tszENCodecBuffer, &nRet, tszDECodecBuffer, lpszPasswd);
155- // printf("大小:%d,内容:\n%s\n", nRet, tszDECodecBuffer);
156- Authorize_CDKey_ReadMemory (tszDECodecBuffer, nRet, &st_AuthLocal);
157- if (!Authorize_CDKey_GetLeftTimer (&st_AuthLocal))
84+ if (!Verification_XAuthKey_KeyParse (&st_AuthLocal))
15885 {
159- // 失败也需要重写CDKEY
160- memset (tszENCodecBuffer, ' \0 ' , sizeof (tszENCodecBuffer));
161- memset (tszDECodecBuffer, ' \0 ' , sizeof (tszDECodecBuffer));
162- Authorize_CDKey_WriteMemory (tszDECodecBuffer, &nRet, &st_AuthLocal);
163- Cryption_XCrypto_Encoder (tszDECodecBuffer, &nRet, (XBYTE*)tszENCodecBuffer, lpszPasswd);
164- pSt_File = _xtfopen (lpszKeyFile, _X (" wb" ));
165- fwrite (tszENCodecBuffer, 1 , nRet, pSt_File);
166- fclose (pSt_File);
167-
16886 printf (" verifaction is failed\n " );
169- return false ;
170- }
171- SYSTEMAPI_SERIAL_INFOMATION st_SDKSerial = {};
172- SystemApi_HardWare_GetSerial (&st_SDKSerial);
173-
174- if (ENUM_AUTHORIZE_MODULE_VERMODE_TYPE_LOCAL != st_AuthLocal.st_AuthRegInfo .enVModeType )
175- {
176- printf (" cdkey does not support local verification\n " );
177- return false ;
17887 }
179- if (ENUM_AUTHORIZE_MODULE_HW_TYPE_BIOS != st_AuthLocal.st_AuthRegInfo .enHWType )
180- {
181- printf (" cdkey serial type is incorrect\n " );
182- return false ;
183- }
184- if (0 != _tcsxnicmp (st_SDKSerial.tszBoardSerial , st_AuthLocal.st_AuthRegInfo .tszHardware , _tcsxlen (st_SDKSerial.tszBoardSerial )))
185- {
186- printf (" cdkey serial verification is failed\n " );
187- return false ;
188- }
189-
190- memset (tszENCodecBuffer, ' \0 ' , sizeof (tszENCodecBuffer));
191- memset (tszDECodecBuffer, ' \0 ' , sizeof (tszDECodecBuffer));
192- Authorize_CDKey_WriteMemory (tszDECodecBuffer, &nRet, &st_AuthLocal);
193- Cryption_XCrypto_Encoder (tszDECodecBuffer, &nRet, (XBYTE*)tszENCodecBuffer, lpszPasswd);
194- pSt_File = _xtfopen (lpszKeyFile, _X (" wb" ));
195- fwrite (tszENCodecBuffer, 1 , nRet, pSt_File);
196- fclose (pSt_File);
88+ Verification_XAuthKey_FileWrite (&st_AuthLocal, lpszKeyFile, lpszPasswd);
19789 return true ;
19890}
19991int main ()
@@ -213,14 +105,14 @@ int main()
213105 }
214106 Authorize_APPLocal_Auth (lpszFileStr, lpszPasswd);
215107
216- if (!Authorize_APPLocal_Auth (lpszFileStr, lpszPasswd, tszSerialStr ))
108+ if (!Authorize_APPLocal_Ver (lpszFileStr, lpszPasswd))
217109 {
218110 return -1 ;
219111 }
220112
221113 for (int i = 0 ; i < 10 ; i++)
222114 {
223- if (!Authorize_APPLocal_Auth (lpszFileStr, lpszPasswd))
115+ if (!Authorize_APPLocal_Ver (lpszFileStr, lpszPasswd))
224116 {
225117 break ;
226118 }
0 commit comments