OCT 1. 增加服务端接口签名验证BASE64编码功能
This commit is contained in:
parent
dc9d15267a
commit
4a046bd6e2
|
@ -6,6 +6,8 @@
|
||||||
#include <bcrypt.h>
|
#include <bcrypt.h>
|
||||||
#include <wincrypt.h>
|
#include <wincrypt.h>
|
||||||
#include <shlwapi.h>
|
#include <shlwapi.h>
|
||||||
|
#include <strsafe.h>
|
||||||
|
#include <cppcodec/base64_url_unpadded.hpp>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#pragma comment(lib, "Bcrypt.lib")
|
#pragma comment(lib, "Bcrypt.lib")
|
||||||
|
@ -271,15 +273,8 @@ int CalcHmacHash(HASH_TYPE type,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outBase64) {
|
if (outBase64) {
|
||||||
DWORD len;
|
using base64 = cppcodec::base64_url_unpadded;
|
||||||
if (!CryptBinaryToString(pbHash, cbHash, CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, outHash, &len)) {
|
StringCbCopy(outHash, 256, base64::encode(pbHash, cbHash).c_str());
|
||||||
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;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
binToHexString(outHash, pbHash, cbHash);
|
binToHexString(outHash, pbHash, cbHash);
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ int GetIpV4InfoFromCIDR(const TCHAR *pIpStr, PIP_INFO pInfo);
|
||||||
|
|
||||||
int GetIpV4InfoFromHostname(int family, const char *host, PIP_INFO pInfo);
|
int GetIpV4InfoFromHostname(int family, const char *host, PIP_INFO pInfo);
|
||||||
|
|
||||||
int InitializeWireGuardLibrary();
|
int InitializeWireGuardLibrary();
|
||||||
void UnInitializeWireGuardLibrary();
|
void UnInitializeWireGuardLibrary();
|
||||||
|
|
||||||
void StopUDPProxyServer();
|
void StopUDPProxyServer();
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "globalcfg.h"
|
#include "globalcfg.h"
|
||||||
#include "httplib.h"
|
#include "httplib.h"
|
||||||
|
#include "misc.h"
|
||||||
#include "usrerr.h"
|
#include "usrerr.h"
|
||||||
|
|
||||||
#include <strsafe.h>
|
#include <strsafe.h>
|
||||||
|
@ -95,6 +96,7 @@ template<class T> int CreateProtocolRequest(T *pReqParams, TCHAR **pOutJson) {
|
||||||
if (!g_httpCtx && lstrlen(GetGlobalCfgInfo()->platformServerUrl) > 0) {
|
if (!g_httpCtx && lstrlen(GetGlobalCfgInfo()->platformServerUrl) > 0) {
|
||||||
g_httpCtx = new httplib::Client(GetGlobalCfgInfo()->platformServerUrl);
|
g_httpCtx = new httplib::Client(GetGlobalCfgInfo()->platformServerUrl);
|
||||||
if (g_httpCtx) {
|
if (g_httpCtx) {
|
||||||
|
g_httpCtx->enable_server_certificate_verification(false);
|
||||||
g_httpCtx->set_connection_timeout(0, 300000); // 300 milliseconds
|
g_httpCtx->set_connection_timeout(0, 300000); // 300 milliseconds
|
||||||
g_httpCtx->set_read_timeout(5, 0); // 5 seconds
|
g_httpCtx->set_read_timeout(5, 0); // 5 seconds
|
||||||
g_httpCtx->set_write_timeout(5, 0); // 5 seconds
|
g_httpCtx->set_write_timeout(5, 0); // 5 seconds
|
||||||
|
@ -342,12 +344,11 @@ template<class T1, class T2> int PlatformProtolPostMessage(const TCHAR *pUrlPath
|
||||||
lstrlen(GetGlobalCfgInfo()->clientSecret),
|
lstrlen(GetGlobalCfgInfo()->clientSecret),
|
||||||
hashValeu,
|
hashValeu,
|
||||||
true) == ERR_SUCCESS) {
|
true) == ERR_SUCCESS) {
|
||||||
|
|
||||||
if (lstrcmp(typeid(T1).name(), TEXT("class PlatformReqClientCfgParms")) == 0) {
|
if (lstrcmp(typeid(T1).name(), TEXT("class PlatformReqClientCfgParms")) == 0) {
|
||||||
const auto *p = reinterpret_cast<PlatformReqClientCfgParms *>(pReq);
|
const auto *p = reinterpret_cast<PlatformReqClientCfgParms *>(pReq);
|
||||||
const httplib::Headers headers = {
|
const httplib::Headers headers = {
|
||||||
{"gzs-client-id", GetGlobalCfgInfo()->clientId},
|
{"gzs-client-id", GetGlobalCfgInfo()->clientId},
|
||||||
{"gzs-sign", hashValeu },
|
{"gzs-sign", hashValeu },
|
||||||
{"gzs-timestamp", timestamp },
|
{"gzs-timestamp", timestamp },
|
||||||
{"gzs-userid", p->token.c_str() },
|
{"gzs-userid", p->token.c_str() },
|
||||||
};
|
};
|
||||||
|
@ -356,7 +357,7 @@ template<class T1, class T2> int PlatformProtolPostMessage(const TCHAR *pUrlPath
|
||||||
} else {
|
} else {
|
||||||
const httplib::Headers headers = {
|
const httplib::Headers headers = {
|
||||||
{"gzs-client-id", GetGlobalCfgInfo()->clientId},
|
{"gzs-client-id", GetGlobalCfgInfo()->clientId},
|
||||||
{"gzs-sign", hashValeu },
|
{"gzs-sign", hashValeu },
|
||||||
{"gzs-timestamp", timestamp },
|
{"gzs-timestamp", timestamp },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,14 @@ int main() {
|
||||||
int ret;
|
int ret;
|
||||||
//https://xajhuang.com:9276
|
//https://xajhuang.com:9276
|
||||||
//http://172.21.40.39:32549
|
//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);
|
wprintf(L"Init SCC SDK Error: %d\n", ret);
|
||||||
return -1;
|
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);
|
wprintf(L"GetUserServerConfigure Error: %d\n", ret);
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +30,7 @@ int main() {
|
||||||
wprintf(L"Press Key 'X' to exit......\n");
|
wprintf(L"Press Key 'X' to exit......\n");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
ret = _getch();
|
ret = _getch();
|
||||||
} while (ret != 'X' && ret != 'x');
|
} while (ret != 'X' && ret != 'x');
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -2,7 +2,12 @@
|
||||||
#include "CppUnitTest.h"
|
#include "CppUnitTest.h"
|
||||||
|
|
||||||
#include "sccsdk.h"
|
#include "sccsdk.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <strsafe.h>
|
#include <strsafe.h>
|
||||||
|
#include <cppcodec/base64_url_unpadded.hpp>
|
||||||
|
#include <cppcodec/base64_rfc4648.hpp>
|
||||||
|
#include <cppcodec/base64_url.hpp>
|
||||||
|
|
||||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||||
|
|
||||||
|
@ -11,7 +16,7 @@ TEST_MODULE_INITIALIZE(ModuleInitialize) {
|
||||||
const TCHAR *path = TEXT(
|
const TCHAR *path = TEXT(
|
||||||
"C:\\Users\\HuangXin\\Documents\\development\\visual_studio\\tunnel_windows\\NetTunnelApp\\bin\\Debug");
|
"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,
|
Assert::AreEqual(0,
|
||||||
TunnelSDKInitEnv(path,
|
TunnelSDKInitEnv(path,
|
||||||
"http://172.21.40.39:32549",
|
"http://172.21.40.39:32549",
|
||||||
|
@ -24,7 +29,7 @@ TEST_MODULE_INITIALIZE(ModuleInitialize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_MODULE_CLEANUP(ModuleCleanup) {
|
TEST_MODULE_CLEANUP(ModuleCleanup) {
|
||||||
Logger::WriteMessage("In Module Cleanup");
|
Logger::WriteMessage("In Module Cleanup\n");
|
||||||
TunnelSDKUnInit();
|
TunnelSDKUnInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,6 +197,26 @@ public:
|
||||||
//Assert::AreEqual(RET_OK, SetNetConnectionNetworkCategory());
|
//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) {
|
TEST_METHOD(TestUserLogin) {
|
||||||
PUSER_CLIENT_CONFIG pCfg;
|
PUSER_CLIENT_CONFIG pCfg;
|
||||||
Assert::AreEqual(RET_OK, GetUserClientConfigure(TEXT("admin"), TEXT("1689189114026041344"), &pCfg));
|
Assert::AreEqual(RET_OK, GetUserClientConfigure(TEXT("admin"), TEXT("1689189114026041344"), &pCfg));
|
||||||
|
@ -210,12 +235,12 @@ public:
|
||||||
|
|
||||||
//Sleep(30 * 1000);
|
//Sleep(30 * 1000);
|
||||||
Assert::AreEqual(RET_OK, LocalWireGuardControl(false, false));
|
Assert::AreEqual(RET_OK, LocalWireGuardControl(false, false));
|
||||||
Assert::AreEqual(RET_OK, RemoteWireGuardControl(false));
|
Assert::AreEqual(RET_OK, RemoteWireGuardControl(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(TestClientProgressFree) {
|
TEST_METHOD(TestClientProgressFree) {
|
||||||
Assert::AreEqual(RET_OK, LocalWireGuardControl(false, false));
|
Assert::AreEqual(RET_OK, LocalWireGuardControl(false, false));
|
||||||
Assert::AreEqual(RET_OK, RemoteWireGuardControl(false));
|
Assert::AreEqual(RET_OK, RemoteWireGuardControl(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(TestGetSDKErrorMessage) {
|
TEST_METHOD(TestGetSDKErrorMessage) {
|
||||||
|
|
Loading…
Reference in New Issue