diff --git a/NetTunnelSDK/crypto/HashDigest.cpp b/NetTunnelSDK/crypto/HashDigest.cpp index 1ecebb4..d276b41 100644 --- a/NetTunnelSDK/crypto/HashDigest.cpp +++ b/NetTunnelSDK/crypto/HashDigest.cpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include #pragma comment(lib, "Bcrypt.lib") @@ -271,15 +273,8 @@ int CalcHmacHash(HASH_TYPE type, } if (outBase64) { - DWORD len; - if (!CryptBinaryToString(pbHash, cbHash, CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, outHash, &len)) { - SPDLOG_ERROR(TEXT("Error {0} returned by BCryptFinishHash"), status); - BCryptCloseAlgorithmProvider(hAlg, 0); - BCryptDestroyHash(hHash); - HeapFree(GetProcessHeap(), 0, pbHashObject); - HeapFree(GetProcessHeap(), 0, pbHash); - return -ERR_BCRYPT_FINISHHASH; - } + using base64 = cppcodec::base64_url_unpadded; + StringCbCopy(outHash, 256, base64::encode(pbHash, cbHash).c_str()); } else { binToHexString(outHash, pbHash, cbHash); } diff --git a/NetTunnelSDK/include/misc.h b/NetTunnelSDK/include/misc.h index 3e536b4..d341c5d 100644 --- a/NetTunnelSDK/include/misc.h +++ b/NetTunnelSDK/include/misc.h @@ -109,7 +109,7 @@ int GetIpV4InfoFromCIDR(const TCHAR *pIpStr, PIP_INFO pInfo); int GetIpV4InfoFromHostname(int family, const char *host, PIP_INFO pInfo); -int InitializeWireGuardLibrary(); +int InitializeWireGuardLibrary(); void UnInitializeWireGuardLibrary(); void StopUDPProxyServer(); diff --git a/NetTunnelSDK/protocol/protocol.cpp b/NetTunnelSDK/protocol/protocol.cpp index 2e1f2fe..5a06151 100644 --- a/NetTunnelSDK/protocol/protocol.cpp +++ b/NetTunnelSDK/protocol/protocol.cpp @@ -5,6 +5,7 @@ #include "globalcfg.h" #include "httplib.h" +#include "misc.h" #include "usrerr.h" #include @@ -95,6 +96,7 @@ template int CreateProtocolRequest(T *pReqParams, TCHAR **pOutJson) { if (!g_httpCtx && lstrlen(GetGlobalCfgInfo()->platformServerUrl) > 0) { g_httpCtx = new httplib::Client(GetGlobalCfgInfo()->platformServerUrl); if (g_httpCtx) { + g_httpCtx->enable_server_certificate_verification(false); g_httpCtx->set_connection_timeout(0, 300000); // 300 milliseconds g_httpCtx->set_read_timeout(5, 0); // 5 seconds g_httpCtx->set_write_timeout(5, 0); // 5 seconds @@ -342,12 +344,11 @@ template int PlatformProtolPostMessage(const TCHAR *pUrlPath lstrlen(GetGlobalCfgInfo()->clientSecret), hashValeu, true) == ERR_SUCCESS) { - if (lstrcmp(typeid(T1).name(), TEXT("class PlatformReqClientCfgParms")) == 0) { const auto *p = reinterpret_cast(pReq); const httplib::Headers headers = { {"gzs-client-id", GetGlobalCfgInfo()->clientId}, - {"gzs-sign", hashValeu }, + {"gzs-sign", hashValeu }, {"gzs-timestamp", timestamp }, {"gzs-userid", p->token.c_str() }, }; @@ -356,7 +357,7 @@ template int PlatformProtolPostMessage(const TCHAR *pUrlPath } else { const httplib::Headers headers = { {"gzs-client-id", GetGlobalCfgInfo()->clientId}, - {"gzs-sign", hashValeu }, + {"gzs-sign", hashValeu }, {"gzs-timestamp", timestamp }, }; diff --git a/NetTunnelServerApp/NetTunnelServerApp.cpp b/NetTunnelServerApp/NetTunnelServerApp.cpp index 3efca8b..1356080 100644 --- a/NetTunnelServerApp/NetTunnelServerApp.cpp +++ b/NetTunnelServerApp/NetTunnelServerApp.cpp @@ -10,12 +10,14 @@ int main() { int ret; //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) { + if ((ret = TunnelSDKInitEnv(nullptr, "https://112.17.28.201:1443", nullptr, LOG_DEBUG, true)) != ERR_SUCCESS) { wprintf(L"Init SCC SDK Error: %d\n", ret); return -1; } - if (ERR_SUCCESS != (ret = GetUserServerConfigure("tunnel_svr", "asfdafdafdaf", &pSvrCfg))) { + EnableVerifySignature("sc-winvdisdk-efa9v12xwtz5eppr", "lh5r8sw6m9m416nm"); + + if (ERR_SUCCESS != (ret = GetUserServerConfigure("tunnel_svr", "172.21.97.100", &pSvrCfg))) { wprintf(L"GetUserServerConfigure Error: %d\n", ret); return -2; } @@ -28,7 +30,7 @@ int main() { wprintf(L"Press Key 'X' to exit......\n"); do { - ret = _getch(); + ret = _getch(); } while (ret != 'X' && ret != 'x'); return 0; diff --git a/TestNetTunnelSDK/TestNetTunnelSDK.cpp b/TestNetTunnelSDK/TestNetTunnelSDK.cpp index b60a3c1..593dbcd 100644 --- a/TestNetTunnelSDK/TestNetTunnelSDK.cpp +++ b/TestNetTunnelSDK/TestNetTunnelSDK.cpp @@ -2,7 +2,12 @@ #include "CppUnitTest.h" #include "sccsdk.h" + +#include #include +#include +#include +#include using namespace Microsoft::VisualStudio::CppUnitTestFramework; @@ -11,7 +16,7 @@ TEST_MODULE_INITIALIZE(ModuleInitialize) { const TCHAR *path = TEXT( "C:\\Users\\HuangXin\\Documents\\development\\visual_studio\\tunnel_windows\\NetTunnelApp\\bin\\Debug"); - Logger::WriteMessage("In Module Initialize"); + Logger::WriteMessage("In Module Initialize\n"); Assert::AreEqual(0, TunnelSDKInitEnv(path, "http://172.21.40.39:32549", @@ -24,7 +29,7 @@ TEST_MODULE_INITIALIZE(ModuleInitialize) { } TEST_MODULE_CLEANUP(ModuleCleanup) { - Logger::WriteMessage("In Module Cleanup"); + Logger::WriteMessage("In Module Cleanup\n"); TunnelSDKUnInit(); } @@ -192,6 +197,26 @@ public: //Assert::AreEqual(RET_OK, SetNetConnectionNetworkCategory()); } + TEST_METHOD(TestBase64UrlEncode) { + const std::string src = "iTeBvsuhkSOIoLB/t8qC/dBOu1lhLWwIZ675nF37MwM="; + using base64urlunPad = cppcodec::base64_url_unpadded; + using base64url = cppcodec::base64_url; + using base64 = cppcodec::base64_rfc4648; + + std::string base = base64::encode(src); + std::string baseurl = base64url::encode(src); + std::string baseunpad = base64urlunPad::encode(src); + + //std::string dbase = base64::decode(base); + + + //std::cout << base64::encode(pSrc, lstrlen(pSrc)) << std::endl; + //std::string encode = ::encode(pSrc); + Logger::WriteMessage("["); + Logger::WriteMessage(base64::encode(src).c_str()); + Logger::WriteMessage("]\n"); + } + TEST_METHOD(TestUserLogin) { PUSER_CLIENT_CONFIG pCfg; Assert::AreEqual(RET_OK, GetUserClientConfigure(TEXT("admin"), TEXT("1689189114026041344"), &pCfg)); @@ -210,12 +235,12 @@ public: //Sleep(30 * 1000); Assert::AreEqual(RET_OK, LocalWireGuardControl(false, false)); - Assert::AreEqual(RET_OK, RemoteWireGuardControl(false)); + Assert::AreEqual(RET_OK, RemoteWireGuardControl(false)); } TEST_METHOD(TestClientProgressFree) { Assert::AreEqual(RET_OK, LocalWireGuardControl(false, false)); - Assert::AreEqual(RET_OK, RemoteWireGuardControl(false)); + Assert::AreEqual(RET_OK, RemoteWireGuardControl(false)); } TEST_METHOD(TestGetSDKErrorMessage) {