OCT 1. 联调基本功能完成

This commit is contained in:
黄昕 2023-08-15 11:01:31 +08:00
parent 4eb3a1da22
commit dc9d15267a
17 changed files with 560 additions and 50 deletions

View File

@ -69,6 +69,18 @@
}
"Entry"
{
"MsmKey" = "8:_C492C60DB8E550E830CE1C2C460B4AD3"
"OwnerKey" = "8:_051B58ED18044668A8D8F5D293AEFB1B"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_D0A1E4927356B199FDD97B12CBDBC86E"
"OwnerKey" = "8:_051B58ED18044668A8D8F5D293AEFB1B"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_D64BF7F7A4C54240763CB0C07962C5D9"
"OwnerKey" = "8:_051B58ED18044668A8D8F5D293AEFB1B"
"MsmSig" = "8:_UNDEFINED"
@ -81,6 +93,12 @@
}
"Entry"
{
"MsmKey" = "8:_DC0B62A757A10195CC98D20A71CB2871"
"OwnerKey" = "8:_051B58ED18044668A8D8F5D293AEFB1B"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_E42C46DD524A1F15E4C053C79430527B"
"OwnerKey" = "8:_051B58ED18044668A8D8F5D293AEFB1B"
"MsmSig" = "8:_UNDEFINED"
@ -127,6 +145,22 @@
"PrivateKeyFile" = "8:"
"TimeStampServer" = "8:"
"InstallerBootstrapper" = "3:2"
"BootstrapperCfg:{63ACBE69-63AA-4F98-B2B6-99F9E24495F2}"
{
"Enabled" = "11:TRUE"
"PromptEnabled" = "11:TRUE"
"PrerequisitesLocation" = "2:1"
"Url" = "8:"
"ComponentsUrl" = "8:"
"Items"
{
"{EDC2488A-8267-493A-A98E-7D9C3B36CDF3}:.NETFramework,Version=v4.7.2"
{
"Name" = "8:Microsoft .NET Framework 4.7.2 (x86 and x64)"
"ProductCode" = "8:.NETFramework,Version=v4.7.2"
}
}
}
}
"Release"
{
@ -143,6 +177,14 @@
"PrivateKeyFile" = "8:"
"TimeStampServer" = "8:"
"InstallerBootstrapper" = "3:2"
"BootstrapperCfg:{63ACBE69-63AA-4F98-B2B6-99F9E24495F2}"
{
"Enabled" = "11:TRUE"
"PromptEnabled" = "11:TRUE"
"PrerequisitesLocation" = "2:1"
"Url" = "8:"
"ComponentsUrl" = "8:"
}
}
}
"Deployable"
@ -304,6 +346,46 @@
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_C492C60DB8E550E830CE1C2C460B4AD3"
{
"SourcePath" = "8:libssl-3-x64.dll"
"TargetName" = "8:libssl-3-x64.dll"
"Tag" = "8:"
"Folder" = "8:_0777490231CD48A0970C1FCD623EA32A"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_D0A1E4927356B199FDD97B12CBDBC86E"
{
"SourcePath" = "8:CRYPT32.dll"
"TargetName" = "8:CRYPT32.dll"
"Tag" = "8:"
"Folder" = "8:_0777490231CD48A0970C1FCD623EA32A"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:TRUE"
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_D64BF7F7A4C54240763CB0C07962C5D9"
{
"SourcePath" = "8:ucrtbased.dll"
@ -324,6 +406,26 @@
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_DC0B62A757A10195CC98D20A71CB2871"
{
"SourcePath" = "8:libcrypto-3-x64.dll"
"TargetName" = "8:libcrypto-3-x64.dll"
"Tag" = "8:"
"Folder" = "8:_0777490231CD48A0970C1FCD623EA32A"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_E42C46DD524A1F15E4C053C79430527B"
{
"SourcePath" = "8:VCRUNTIME140D.dll"
@ -441,7 +543,7 @@
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:SCCServer"
"ProductCode" = "8:{E00CE8DB-D79F-4890-910F-64AE0F37AEED}"
"PackageCode" = "8:{2881D34B-31F4-4DA0-AE7A-7FAF55389480}"
"PackageCode" = "8:{4A613EBB-74F1-4F04-9B7F-CC39E5BDC4D4}"
"UpgradeCode" = "8:{3089869A-5F6B-4EC2-B2CA-54B51499079F}"
"AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE"

View File

@ -45,8 +45,8 @@ public partial class MainForm : Form
var path = Environment.CurrentDirectory + "\\tunnelsdk_" +
string.Format("{0:yyyyMMdd}", DateTime.Now) + ".log";
//NetTunnelLib.InitTunnelSDKLog(path, LogLevel.LOG_DEBUG);
NetTunnelLib.TunnelSDKInitEnv(Environment.CurrentDirectory, "http://xajhuang.com:9276", path, LogLevel.LOG_TRACE, menuSetModeServer.Checked);
NetTunnelLib.EnableSCGProxy(true, "efc.xajhuang.com", 10001);
NetTunnelLib.TunnelSDKInitEnv(Environment.CurrentDirectory, "http://172.21.40.39:32549", path, LogLevel.LOG_TRACE, menuSetModeServer.Checked);
//NetTunnelLib.EnableSCGProxy(true, "efc.xajhuang.com", 10001);
GetCurrentNetCard();
NetCardMenuItems menuItems = new NetCardMenuItems(_curNetCard);
@ -189,7 +189,7 @@ public partial class MainForm : Form
IntPtr pt = new IntPtr();
if (NetTunnelLib.GetUserClientConfigure(args.HashArgs["UserName"] as string,
args.HashArgs["Password"] as string,
"1689189114026041344",
out pt) == 0)
{
IntPtr p = new IntPtr(pt.ToInt64());
@ -334,21 +334,22 @@ public partial class MainForm : Form
private void menuControlSvrStop_Click(object sender, EventArgs e)
{
var ret = NetTunnelLib.RemoteWireGuardControl(false);
if (ret != 0)
{
MessageBox.Show("RemoteWireGuardControl Error: " + ret.ToString());
return;
}
ret = NetTunnelLib.LocalWireGuardControl(false);
var ret = NetTunnelLib.LocalWireGuardControl(false);
if (ret != 0)
{
MessageBox.Show("LocalWireGuardControl Error: " + ret.ToString());
return;
}
ret = NetTunnelLib.RemoteWireGuardControl(false);
if (ret != 0)
{
MessageBox.Show("RemoteWireGuardControl Error: " + ret.ToString());
return;
}
}
private void menuControlHeartStart_Click(object sender, EventArgs e)

View File

@ -404,8 +404,13 @@ int GetUserServerConfigure(const TCHAR *pUserName, const TCHAR *pToken, PUSER_SE
PUSER_CONFIG pUser = &GetGlobalCfgInfo()->userCfg;
PUSER_SERVER_CONFIG pUserCfg = &pUser->svrConfig;
#if USER_REAL_PLATFORM
ProtocolRequest<ReqGetUserCfgParams> req;
ProtocolResponse<RspUserSevrCfgParams> rsp;
#else
PlatformReqServerCfgParms req;
PlatformRspServerCfgParams rsp;
#endif
if (pSvrCfg == nullptr) {
SPDLOG_ERROR(TEXT("Input pSvrCfg params error"));
@ -426,6 +431,7 @@ int GetUserServerConfigure(const TCHAR *pUserName, const TCHAR *pToken, PUSER_SE
StringCbCopy(pUser->userToken, MAX_PATH, pToken);
#if USER_REAL_PLATFORM
req.msgContent.token = pToken;
req.msgContent.user = pUser->userName;
@ -439,6 +445,26 @@ int GetUserServerConfigure(const TCHAR *pUserName, const TCHAR *pToken, PUSER_SE
StringCbCopy(pUserCfg->svrPrivateKey, 64, rsp.msgContent.svrPrivateKey.c_str());
StringCbCopy(pUserCfg->svrAddress, MAX_IP_LEN, rsp.msgContent.svrAddress.c_str());
#else
req.vmIp = pToken;
ret = PlatformProtolPostMessage(GET_SERVERCFG_PATH, &req, &rsp);
if (ret != ERR_SUCCESS) {
return ret;
}
ret = strtol(rsp.code.c_str(), nullptr, 10);
if (ret != 0) {
SPDLOG_ERROR(TEXT("Server response error code: {0}"), ret);
return -ERR_HTTP_SERVER_RSP;
}
pUserCfg->svrListenPort = rsp.data.svrPort;
StringCbCopy(pUserCfg->svrPrivateKey, 64, rsp.data.svrPriKey.c_str());
StringCbCopy(pUserCfg->svrAddress, MAX_IP_LEN, rsp.data.svrHost.c_str());
#endif
*pSvrCfg = pUserCfg;
return ERR_SUCCESS;
}
@ -449,8 +475,13 @@ int GetUserClientConfigure(const TCHAR *pUserName, const TCHAR *pToken, PUSER_CL
TCHAR userPath[MAX_PATH];
int ret;
#if USER_REAL_PLATFORM
ProtocolRequest<ReqGetUserCfgParams> req;
ProtocolResponse<RspUsrCliConfigParams> rsp;
#else
PlatformReqClientCfgParms req;
PlatformRspClientCfgParams rsp;
#endif
if (pUserName == nullptr || lstrlen(pUserName) == 0) {
SPDLOG_ERROR(TEXT("Input pUserName params error: {0}"), pUserName);
@ -482,6 +513,7 @@ int GetUserClientConfigure(const TCHAR *pUserName, const TCHAR *pToken, PUSER_CL
}
StringCbCopy(pUser->userToken, MAX_PATH, pToken);
#if USER_REAL_PLATFORM
req.msgContent.token = pToken;
req.msgContent.user = pUserName;
@ -523,7 +555,55 @@ int GetUserClientConfigure(const TCHAR *pUserName, const TCHAR *pToken, PUSER_CL
pVm++;
}
}
#else
req.userName = pUserName;
req.token = pToken;
ret = PlatformProtolPostMessage(GET_CLIENTCFG_PATH, &req, &rsp);
if (ret != ERR_SUCCESS) {
return ret;
}
ret = strtol(rsp.code.c_str(), nullptr, 10);
if (ret != 0) {
SPDLOG_ERROR(TEXT("Server response error code: {0}"), ret);
return -ERR_HTTP_SERVER_RSP;
}
StringCbCopy(pUserCfg->cliPrivateKey, 64, rsp.data.cliPriKey.c_str());
StringCbCopy(pUserCfg->cliPublicKey, 64, rsp.data.cliPubKey.c_str());
StringCbCopy(pUserCfg->cliAddress, MAX_IP_LEN, rsp.data.cliHost.c_str());
if (!rsp.data.vmInfoList.empty()) {
PVM_CFG pVm;
unsigned int memSize = sizeof(VM_CFG) * static_cast<UINT>(rsp.data.vmInfoList.size());
pUserCfg->pVMConfig = static_cast<PVM_CFG>(CoTaskMemAlloc(memSize));
if (pUserCfg->pVMConfig == nullptr) {
SPDLOG_ERROR(TEXT("Error allocating memory {0} bytes"), memSize);
return -ERR_MALLOC_MEMORY;
}
memset(pUserCfg->pVMConfig, 0, memSize);
pUserCfg->tolVM = static_cast<int>(rsp.data.vmInfoList.size());
pVm = pUserCfg->pVMConfig;
for (auto vm : rsp.data.vmInfoList) {
pVm->vmId = vm.vmId;
StringCbCopy(pVm->vmName, MAX_PATH, vm.vmName.c_str());
StringCbCopy(pVm->svrPublicKey, 64, vm.svrPubKey.c_str());
StringCbCopy(pVm->vmNetwork, MAX_IP_LEN, vm.vmNetwork.c_str());
//StringCbCopy(pVm->scgGateWay, MAX_PATH, vm.scgGateway.c_str());
StringCbPrintf(pVm->scgGateWay, MAX_PATH, TEXT("http://%s:%d"), vm.scgIp.c_str(), vm.scgPort);
httplib::Client cli(pVm->scgGateWay);
StringCbPrintf(pVm->scgTunnelGw, MAX_PATH, TEXT("%s:%d"), cli.host().c_str(), cli.port() - 1);
pVm++;
}
}
#endif
*pCliCfg = pUserCfg;
return ERR_SUCCESS;
}

View File

@ -1,6 +1,8 @@
#pragma once
#include "AIGCJson.hpp"
#define USER_REAL_PLATFORM (0)
class ProtocolBase {
public:
ProtocolBase() {
@ -15,8 +17,8 @@ public:
AIGC_JSON_HELPER(ver, cryptoType, timeStamp)
void SetVersion(unsigned int ver) {
this->ver = ver;
void SetVersion(unsigned int versino) {
this->ver = versino;
}
void SetTimeStamp(unsigned int ts) {
@ -24,7 +26,7 @@ public:
}
void SetCryptoType(unsigned int crypto) {
this->cryptoType = cryptoType;
this->cryptoType = crypto;
}
};

View File

@ -25,6 +25,15 @@
*/
#define MAX_NETCARD_NAME (64)
/**
* @brief SCG ID
*
*/
typedef enum {
WG_TUNNEL_SCG_ID = 3, ///< 隧道服务
WG_CTRL_SCG_ID = 4 ///< 隧道控制服务
} SCG_SVR_ID;
/**
* @brief
*

View File

@ -1,5 +1,7 @@
#pragma once
#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容
#define CPPHTTPLIB_OPENSSL_SUPPORT
// Windows 头文件
#include <windows.h>

View File

@ -1,6 +1,94 @@
#pragma once
#include "ProtocolBase.h"
#if !USER_REAL_PLATFORM
class PlatformReqServerCfgParms {
public:
std::string vmIp;
AIGC_JSON_HELPER(vmIp)
};
class PlatformReqClientCfgParms {
public:
std::string userName;
std::string token;
AIGC_JSON_HELPER(userName)
};
class PlatformRspUserSvrCfgParams {
public:
PlatformRspUserSvrCfgParams() {
this->svrHost = TEXT("");
this->svrPort = 0;
this->svrPriKey = TEXT("");
}
int svrPort;
std::string svrPriKey;
std::string svrHost;
AIGC_JSON_HELPER(svrPort, svrPriKey, svrHost)
};
class VitrualMathineInfo {
public:
VitrualMathineInfo() {
this->vmId = 0;
this->scgPort = 0;
this->vmName = TEXT("");
this->scgIp = TEXT("");
this->vmNetwork = TEXT("");
this->svrPubKey = TEXT("");
}
int vmId;
std::string vmName;
std::string svrPubKey;
std::string vmNetwork;
std::string scgIp;
int scgPort;
AIGC_JSON_HELPER(vmId, vmName, svrPubKey, vmNetwork, scgIp, scgPort)
};
class PlatformRspUserClientCfgParams {
public:
PlatformRspUserClientCfgParams() {
this->scgTunnelAppId = WG_TUNNEL_SCG_ID;
this->scgCtrlAppId = WG_CTRL_SCG_ID;
this->cliHost = TEXT("");
}
int scgCtrlAppId;
int scgTunnelAppId;
std::string cliPriKey;
std::string cliPubKey;
std::string cliHost;
std::list<VitrualMathineInfo> vmInfoList;
AIGC_JSON_HELPER(scgCtrlAppId, scgTunnelAppId, cliPriKey, cliPubKey, vmInfoList, cliHost)
};
class PlatformRspServerCfgParams {
public:
std::string code;
std::string message;
PlatformRspUserSvrCfgParams data;
AIGC_JSON_HELPER(code, data)
};
class PlatformRspClientCfgParams {
public:
std::string code;
std::string message;
PlatformRspUserClientCfgParams data;
AIGC_JSON_HELPER(code, data)
};
#endif
class ReqClientCfgParams {
public:
std::string identifier;
@ -102,8 +190,13 @@ public:
AIGC_JSON_HELPER(scgCtrlAppId, scgTunnelAppId, cliPrivateKey, cliPublicKey, cliAddress, vmConfig)
};
#if USER_REAL_PLATFORM
#define GET_CLIENTCFG_PATH TEXT("/tunnel/getuserconfig")
#define GET_SERVERCFG_PATH TEXT("/tunnel/getserverconfig")
#else
#define GET_CLIENTCFG_PATH TEXT("/sc/open-portal/openapi/scc/cliTunnelCfg")
#define GET_SERVERCFG_PATH TEXT("/sc/open-portal/openapi/scc/svrTunnelCfg")
#endif
#define SET_CLIENTCFG_PATH TEXT("/tunnel/setconfig")
#define SET_CLIENTSTART_TUNNEL TEXT("/tunnel/start")
@ -157,3 +250,22 @@ extern template int ProtolPostMessage(const TCHAR *pUrlPath
ProtocolRequest<ReqHeartParams> *pReq,
ProtocolResponse<RspHeartParams> *pRsp,
bool platformServer);
#if !USER_REAL_PLATFORM
template<class T1, class T2> int PlatformProtolPostMessage(const TCHAR *pUrlPath, T1 *pReq, T2 *pRsp);
extern template int PlatformProtolPostMessage(const TCHAR *pUrlPath,
PlatformReqServerCfgParms *pReq,
PlatformRspServerCfgParams *pRsp);
extern template int PlatformProtolPostMessage(const TCHAR *pUrlPath,
PlatformReqClientCfgParms *pReq,
PlatformRspClientCfgParams *pRsp);
#if 0
template<class T1> int PlatformProtolGetMessage(const TCHAR *pUrlPath, T1 *pRsp);
extern template int PlatformProtolGetMessage(const TCHAR *pUrlPath,
PlatformRspUserClientCfgParams *pRsp);
#endif
#endif

View File

@ -1,11 +1,6 @@
#pragma once
#include "sccsdk.h"
typedef enum {
WG_TUNNEL_SCG_ID = 3,
WG_CTRL_SCG_ID = 4
} SCG_SVR_ID;
typedef enum {
CHK_SYSTEM_INIT,
CHK_WIREGUARD_CONFIG,

View File

@ -219,6 +219,190 @@ int ProtolPostMessage(const TCHAR *pUrlPath,
return ERR_SUCCESS;
}
#if 0
template<class T1> int PlatformProtolGetMessage(const TCHAR *pUrlPath, T1 *pRsp) {
httplib::Result res;
TCHAR *pJson = nullptr;
std::string timestamp = std::to_string(time(nullptr)) + "000";
TCHAR hashValeu[MAX_PATH] = {0};
TCHAR hashBuf[1024] = {};
if (lstrlen(GetGlobalCfgInfo()->platformServerUrl) == 0) {
SPDLOG_ERROR(TEXT("Platform Server URL uninitialize."));
return -ERR_SYSTEM_UNINITIALIZE;
}
if (pRsp == nullptr) {
SPDLOG_ERROR(TEXT("Input ProtocolResponse<T2> *pRsp params error"));
return -ERR_INPUT_PARAMS;
}
StringCbPrintf(hashBuf,
1024,
TEXT("%s|%s|%s|%s"),
GetGlobalCfgInfo()->clientId,
GetGlobalCfgInfo()->clientSecret,
timestamp.c_str(),
pJson);
if (lstrlen(GetGlobalCfgInfo()->clientSecret) > 0 &&
CalcHmacHash(HASH_SHA256,
reinterpret_cast<PUCHAR>(hashBuf),
lstrlen(hashBuf),
reinterpret_cast<PUCHAR>(GetGlobalCfgInfo()->clientSecret),
lstrlen(GetGlobalCfgInfo()->clientSecret),
hashValeu,
true) == ERR_SUCCESS) {
const httplib::Headers headers = {
{"gzs-client-id", GetGlobalCfgInfo()->clientId},
{"gzs-sign", hashValeu },
{"gzs-timestamp", timestamp },
};
res = g_httpCtx->Get(pUrlPath, headers);
} else {
res = g_httpCtx->Get(pUrlPath);
}
if (res.error() != httplib::Error::Success) {
SPDLOG_ERROR(TEXT("[{0}]:Post Data {1} error: {2}"), pUrlPath, pJson, httplib::to_string(res.error()));
free(pJson);
return -ERR_HTTP_POST_DATA;
}
if (res->status != 200) {
SPDLOG_ERROR(TEXT("[{0}]:Post Data {1} server return HTTP error: {2}"), pUrlPath, pJson, res->status);
free(pJson);
return -ERR_HTTP_SERVER_RSP;
}
SPDLOG_DEBUG(TEXT("+++++ Http Request {0}\n---- Http Response {1}"), pJson, res->body.c_str());
free(pJson);
if (lstrlen(res->body.c_str()) == 0) {
SPDLOG_ERROR(TEXT("Server response empty message"));
return -ERR_READ_FILE;
}
if (DecodeProtocolResponse(pRsp, res->body.c_str()) != ERR_SUCCESS) {
SPDLOG_ERROR(TEXT("Decode JSON {0} to ProtocolResponse<{1}> error"), res->body, typeid(T1).name());
return -ERR_JSON_DECODE;
}
return ERR_SUCCESS;
}
#endif
template<class T1, class T2> int PlatformProtolPostMessage(const TCHAR *pUrlPath, T1 *pReq, T2 *pRsp) {
int ret;
httplib::Result res;
TCHAR *pJson = nullptr;
std::string timestamp = std::to_string(time(nullptr)) + "000";
TCHAR hashValeu[MAX_PATH] = {0};
TCHAR hashBuf[1024] = {};
if (lstrlen(GetGlobalCfgInfo()->platformServerUrl) == 0) {
SPDLOG_ERROR(TEXT("Platform Server URL uninitialize."));
return -ERR_SYSTEM_UNINITIALIZE;
}
if (pReq == nullptr) {
SPDLOG_ERROR(TEXT("Input pToken params error"));
SPDLOG_ERROR(TEXT("Input ProtocolRequest<T1> *pReq params error"));
return -ERR_INPUT_PARAMS;
}
if (pRsp == nullptr) {
SPDLOG_ERROR(TEXT("Input ProtocolResponse<T2> *pRsp params error"));
return -ERR_INPUT_PARAMS;
}
ret = CreateProtocolRequest(pReq, &pJson);
if (ret != ERR_SUCCESS) {
if (pJson) {
free(pJson);
}
return ret;
}
StringCbPrintf(hashBuf,
1024,
TEXT("%s|%s|%s|%s"),
GetGlobalCfgInfo()->clientId,
GetGlobalCfgInfo()->clientSecret,
timestamp.c_str(),
pJson);
if (lstrlen(GetGlobalCfgInfo()->clientSecret) > 0 &&
CalcHmacHash(HASH_SHA256,
reinterpret_cast<PUCHAR>(hashBuf),
lstrlen(hashBuf),
reinterpret_cast<PUCHAR>(GetGlobalCfgInfo()->clientSecret),
lstrlen(GetGlobalCfgInfo()->clientSecret),
hashValeu,
true) == ERR_SUCCESS) {
if (lstrcmp(typeid(T1).name(), TEXT("class PlatformReqClientCfgParms")) == 0) {
const auto *p = reinterpret_cast<PlatformReqClientCfgParms *>(pReq);
const httplib::Headers headers = {
{"gzs-client-id", GetGlobalCfgInfo()->clientId},
{"gzs-sign", hashValeu },
{"gzs-timestamp", timestamp },
{"gzs-userid", p->token.c_str() },
};
res = g_httpCtx->Post(pUrlPath, headers, pJson, HTTP_JSON_CONTENT);
} else {
const httplib::Headers headers = {
{"gzs-client-id", GetGlobalCfgInfo()->clientId},
{"gzs-sign", hashValeu },
{"gzs-timestamp", timestamp },
};
res = g_httpCtx->Post(pUrlPath, headers, pJson, HTTP_JSON_CONTENT);
}
} else {
if (lstrcmp(typeid(T1).name(), TEXT("class PlatformReqClientCfgParms")) == 0) {
const auto *p = reinterpret_cast<PlatformReqClientCfgParms *>(pReq);
const httplib::Headers headers = {
{"gzs-userid", p->token.c_str()},
};
res = g_httpCtx->Post(pUrlPath, headers, pJson, HTTP_JSON_CONTENT);
} else {
res = g_httpCtx->Post(pUrlPath, pJson, HTTP_JSON_CONTENT);
}
}
if (res.error() != httplib::Error::Success) {
SPDLOG_ERROR(TEXT("[{0}]:Post Data {1} error: {2}"), pUrlPath, pJson, httplib::to_string(res.error()));
free(pJson);
return -ERR_HTTP_POST_DATA;
}
if (res->status != 200) {
SPDLOG_ERROR(TEXT("[{0}]:Post Data {1} server return HTTP error: {2}"), pUrlPath, pJson, res->status);
free(pJson);
return -ERR_HTTP_SERVER_RSP;
}
SPDLOG_DEBUG(TEXT("+++++ Http Request {0}\n---- Http Response {1}"), pJson, res->body.c_str());
free(pJson);
if (lstrlen(res->body.c_str()) == 0) {
SPDLOG_ERROR(TEXT("Server response empty message"));
return -ERR_READ_FILE;
}
if (DecodeProtocolResponse(pRsp, res->body.c_str()) != ERR_SUCCESS) {
SPDLOG_ERROR(TEXT("Decode JSON {0} to ProtocolResponse<{1}> error"), res->body, typeid(T2).name());
return -ERR_JSON_DECODE;
}
return ERR_SUCCESS;
}
template int ProtolPostMessage(const TCHAR *pUrlPath,
ProtocolRequest<ReqGetUserCfgParams> *pReq,
ProtocolResponse<RspUserSevrCfgParams> *pRsp,
@ -243,3 +427,15 @@ template int ProtolPostMessage(const TCHAR *pUrlPath,
ProtocolRequest<ReqHeartParams> *pReq,
ProtocolResponse<RspHeartParams> *pRsp,
bool platformServer);
#if !USER_REAL_PLATFORM
template int PlatformProtolPostMessage(const TCHAR *pUrlPath,
PlatformReqServerCfgParms *pReq,
PlatformRspServerCfgParams *pRsp);
template int PlatformProtolPostMessage(const TCHAR *pUrlPath,
PlatformReqClientCfgParms *pReq,
PlatformRspClientCfgParams *pRsp);
//template int PlatformProtolGetMessage(const TCHAR *pUrlPath, PlatformRspUserClientCfgParams *pRsp);
#endif

View File

@ -25,6 +25,15 @@
*/
#define MAX_NETCARD_NAME (64)
/**
* @brief SCG ·þÎñ ID
*
*/
typedef enum {
WG_TUNNEL_SCG_ID = 3, ///< ËíµÀ·þÎñ
WG_CTRL_SCG_ID = 4 ///< ËíµÀ¿ØÖÆ·þÎñ
} SCG_SVR_ID;
/**
* @brief Đ­ŇéźÓĂÜŔŕĐÍ
*

View File

@ -35,7 +35,7 @@ int InitializeWireGuardLibrary() {
TCHAR dllPath[MAX_PATH];
StringCbPrintf(dllPath, MAX_PATH, TEXT("%s\\wireguard.dll"), GetGlobalCfgInfo()->workDirectory);
if(!PathFileExists(dllPath)) {
if (!PathFileExists(dllPath)) {
SPDLOG_ERROR(TEXT("WireGuard DLL Not Found: {0}"), dllPath);
return -ERR_ITEM_UNEXISTS;
}

View File

@ -141,6 +141,7 @@ int TunnelSDKInitEnv(const TCHAR *pWorkDir,
StringCbCat(g_globalConfig.configDirectory, MAX_PATH, "\\NetTunnel");
SPDLOG_DEBUG(TEXT("Configure directory: {0}."), g_globalConfig.configDirectory);
SPDLOG_DEBUG(TEXT("Platform Server: {}, Work Module: {}"), pSvrUrl, isWorkServer? TEXT("SERVER") : TEXT("Client"));
// 如果配置目录不存在则自动创建
if (!PathFileExists(g_globalConfig.configDirectory)) {

View File

@ -8,8 +8,9 @@
int main() {
PUSER_SERVER_CONFIG pSvrCfg;
int ret;
if ((ret = TunnelSDKInitEnv(nullptr, "http://xajhuang.com:9276", nullptr, LOG_DEBUG, true)) != ERR_SUCCESS) {
//https://xajhuang.com:9276
//http://172.21.40.39:32549
if ((ret = TunnelSDKInitEnv(nullptr, "http://172.21.40.39:32549", nullptr, LOG_DEBUG, true)) != ERR_SUCCESS) {
wprintf(L"Init SCC SDK Error: %d\n", ret);
return -1;
}

View File

@ -14,13 +14,13 @@ TEST_MODULE_INITIALIZE(ModuleInitialize) {
Logger::WriteMessage("In Module Initialize");
Assert::AreEqual(0,
TunnelSDKInitEnv(path,
"http://xajhuang.com:9276",
"http://172.21.40.39:32549",
TEXT("C:\\Users\\HuangXin\\Documents\\development\\visual_studio\\tunnel_"
"windows\\NetTunnelApp\\bin\\Debug\\utest.log"),
LOG_TRACE,
false));
Assert::AreEqual(0, EnableVerifySignature(TEXT("123"), TEXT("123456")));
Assert::AreEqual(0, EnableSCGProxy(true, TEXT("efc.xajhuang.com"), 10001));
//Assert::AreEqual(0, EnableVerifySignature(TEXT("123"), TEXT("123456")));
//Assert::AreEqual(0, EnableSCGProxy(true, TEXT("efc.xajhuang.com"), 10001));
}
TEST_MODULE_CLEANUP(ModuleCleanup) {
@ -194,7 +194,7 @@ public:
TEST_METHOD(TestUserLogin) {
PUSER_CLIENT_CONFIG pCfg;
Assert::AreEqual(RET_OK, GetUserClientConfigure(TEXT("admin"), TEXT("123455"), &pCfg));
Assert::AreEqual(RET_OK, GetUserClientConfigure(TEXT("admin"), TEXT("1689189114026041344"), &pCfg));
}
TEST_METHOD(TestClientProgress) {
@ -209,13 +209,13 @@ public:
//EnableSCGProxy(true, 10000);
//Sleep(30 * 1000);
Assert::AreEqual(RET_OK, RemoteWireGuardControl(false));
Assert::AreEqual(RET_OK, LocalWireGuardControl(false, false));
Assert::AreEqual(RET_OK, RemoteWireGuardControl(false));
}
TEST_METHOD(TestClientProgressFree) {
Assert::AreEqual(RET_OK, RemoteWireGuardControl(false));
Assert::AreEqual(RET_OK, LocalWireGuardControl(false, false));
Assert::AreEqual(RET_OK, RemoteWireGuardControl(false));
}
TEST_METHOD(TestGetSDKErrorMessage) {