NetTunnelWindows/NetTunnelSDK/include/tunnel.h

179 lines
6.3 KiB
C
Raw Normal View History

2023-06-15 01:35:37 +00:00
#pragma once
#include "sccsdk.h"
2023-06-15 01:35:37 +00:00
typedef enum {
CHK_SYSTEM_INIT,
CHK_WIREGUARD_CONFIG,
CHK_WIREGUARD_SERVICE,
CHK_WG_INTERFACE_PRIVATE,
CHK_MAX
} CHECK_FUNCTION;
typedef struct {
CHECK_FUNCTION chk;
bool result;
TCHAR errMsg[MAX_PATH];
} CHK_RESULT, *PCHK_RESULT;
/**
* @brief WireGuard
*/
typedef struct {
TCHAR Name[64]; ///< WireGuard 网卡名称
TCHAR Address[32]; ///< WireGuard 本地网络IP地址
TCHAR PrivateKey[64]; ///< WireGuard 本机私钥
int ListenPort; ///< WireGuard 服务端监听端口
// 根据系统设计,不支持多个客户端同时连接
TCHAR CliPubKey[64]; ///< WireGuard 客户端公钥
TCHAR AllowNet[256]; ///< WireGuard 允许对端访问本地网络的配置
} WGSERVER_CONFIG, *PWGSERVER_CONFIG;
/**
* @brief WireGuard
*/
typedef struct {
TCHAR Name[64]; ///< WireGuard 网卡名称
TCHAR PrivateKey[64]; ///< WireGuard 本机私钥
TCHAR Address[32]; ///< WireGuard 本地网络IP地址
// Peer Server
TCHAR SvrPubKey[64]; ///< WireGuard 服务端公钥
TCHAR AllowNet[256]; ///< WireGuard 允许对端访问本地网络的配置
TCHAR ServerURL[256]; ///< WireGuard 服务端IP地址和端口
} WGCLIENT_CONFIG, *PWGCLIENT_CONFIG;
2023-06-15 01:35:37 +00:00
#ifdef __cplusplus // If used by C++ code,
extern "C" {
// we need to export the C interface
#endif
/**
* @brief CRYPTO_NONE
* @param[in] type @see PROTO_CRYPTO_TYPE
* @param[in] pProKey CRYPTO_NONE CRYPTO_BASE64
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - ERR_SUCCESS
*/
int SetProtocolEncryptType(const PROTO_CRYPTO_TYPE type, const TCHAR *pProKey);
/**
* @brief WireGuard
* @param[in] pWgConfig @see WGSERVER_CONFIG
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - -ERR_OPEN_FILE
* - -ERR_MEMORY_STR
* - ERR_SUCCESS
*/
int WireGuardCreateServerConfig(const PWGSERVER_CONFIG pWgConfig);
/**
* @brief WireGuard
* @param[in] pWgConfig @see WGCLIENT_CONFIG
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - -ERR_OPEN_FILE
* - -ERR_MEMORY_STR
* - ERR_SUCCESS
*/
int WireGuardCreateClientConfig(const PWGCLIENT_CONFIG pWgConfig);
/**
* @brief WireGuard
* @param pInterfaceName
* @param pWGConfigFilePath
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_ITEM_UNEXISTS
* - -ERR_OPEN_SCM
* - -ERR_OPEN_SERVICE
* - -ERR_CREATE_SERVICE
* - -ERR_CONFIG_SERVICE
* - -ERR_START_SERVICE
* - ERR_SUCCESS
*/
int CreateWireGuardService(const TCHAR *pInterfaceName, const TCHAR *pWGConfigFilePath);
int GetWireGuradTunnelInfo(const TCHAR *pTunnelName);
/**
* @brief WireGuard
* @param pTunnelName
* @param bIsWaitStop TRUE: , FALSE:
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_OPEN_SCM
* - -ERR_OPEN_SERVICE
* - -ERR_STOP_SERVICE
* - -ERR_DELETE_SERVICE
* - ERR_SUCCESS
*/
int RemoveGuardService(const TCHAR *pTunnelName, bool bIsWaitStop);
/**
* @brief / WireGuard
* @param[in] bInstall TRUE , FALSE
* @return 0: 0 @see USER_ERRNO
*/
int WireGuardInstallDefaultServerService(bool bInstall);
/**
* @brief WireGuard
* @param[in] pTunnelCfgPath
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_ITEM_UNEXISTS
* - -ERR_CALL_SHELL WireGuard
* - ERR_SUCCESS
*/
int WireGuardInstallServerService(const TCHAR *pTunnelCfgPath);
/**
* @brief WireGuard
* @param[in] pTunnelName
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_ITEM_UNEXISTS
* - -ERR_CALL_SHELL WireGuard
* - ERR_SUCCESS
*/
int WireGuardUnInstallServerService(const TCHAR *pTunnelName);
2023-06-21 10:04:16 +00:00
/**
* @brief WireGuard
* @param[out] pIsInstalled WireGuard
* - TRUE
* - FALSE
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_OPEN_SCM,
* - -ERR_OPEN_SERVICE,
* - -ERR_GET_SERVICESSTATUS,
* - ERR_SUCCESS
*/
int IsWireGuardServerInstalled(bool *pIsInstalled);
/**
* @brief Hash
* @param[in] type Hash @see HASH_TYPE
* @param[in] pPath Hash
* @param[out] outHash
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_ITEM_UNEXISTS
* - -ERR_OPEN_FILE
* - -ERR_BCRYPT_OPEN
* - -ERR_BCRYPT_GETPROPERTY
* - -ERR_BCRYPT_CREATEHASH Hash
* - -ERR_BCRYPT_HASHDATA Hash
* - -ERR_BCRYPT_FINISHHASH Hash
* - ERR_SUCCESS
*/
int CalcFileHash(const HASH_TYPE type, const TCHAR *pPath, TCHAR outHash[]);
2023-06-15 01:35:37 +00:00
#ifdef __cplusplus
}
#endif