NetTunnelWindows/NetTunnelSDK/tunnel.h

368 lines
12 KiB
C
Raw Normal View History

2023-06-15 01:35:37 +00:00
#pragma once
#include <Windows.h>
#ifdef NETTUNNELSDK_EXPORTS
#define TUNNEL_API __declspec(dllexport)
2023-06-15 01:35:37 +00:00
#else
#define TUNNEL_API __declspec(dllimport)
2023-06-15 01:35:37 +00:00
#endif
/**
* @brief WireGuard key
*/
constexpr auto WG_KEY_MAX = (64);
/**
* @brief
*/
#define NET_CARD_MAX (32)
2023-06-21 10:04:16 +00:00
/**
* @brief IP (IPv6)
*/
#define MAX_IP_LEN (48)
/**
* @brief IP
*/
#define MIN_IP_LEN (7)
/**
* @brief (IPv6)
*/
#define MAX_NETCARD_NAME (64)
2023-06-21 10:04:16 +00:00
/**
* @brief
*
*/
typedef enum {
CRYPTO_NONE = 0, ///< 不加密
CRYPTO_BASE64 = 1, ///< BASE64 字符串编码
CRYPTO_AES128 = 2, ///< AES 128位秘钥 加密
CRYPTO_3DES = 3, ///< 3DES 加密
CRYPTO_AES256 = 4, ///< AES 256 位秘钥加密
2023-06-15 01:35:37 +00:00
CRYPTO_MAX,
} PROTO_CRYPTO_TYPE;
2023-06-15 01:35:37 +00:00
/**
* @brief
*
*/
enum LOG_LEVEL {
LOG_TRACE = 0, ///< TRACE 日志等级
LOG_DEBUG, ///< DEBUG 日志等级
LOG_INFO, ///< INFO 日志等级
LOG_WARN, ///< WARN 日志等级
LOG_ERROR, ///< ERROR 日志等级
LOG_CRITICAL, ///< CRITICAL 日志等级
LOG_OFF ///< 关闭日志
};
/**
* @brief Hash
*
*/
typedef enum {
HASH_MD2 = 0, ///< MD2 HASH 算法
HASH_MD4, ///< MD4 HASH 算法
HASH_MD5, ///< MD5 HASH 算法
HASH_SHA1, ///< SHA1 HASH 算法
HASH_SHA256, ///< SHA256 HASH 算法
HASH_SHA384, ///< SHA384 HASH 算法
HASH_SHA512 ///< SHA512 HASH 算法
} HASH_TYPE;
typedef enum {
CHK_SYSTEM_INIT,
CHK_WIREGUARD_INSTALL,
CHK_WG_INSTALL,
CHK_WIREGUARD_CONFIG,
CHK_WIREGUARD_SERVICE,
CHK_WG_INTERFACE_PRIVATE,
CHK_MAX
} CHECK_FUNCTION;
/**
* @brief
*
*/
typedef enum {
ICS_SHARE_MODE = 0, ///< Internet Share Mode(ICS) 模式
NAT_SHARE_MODE = 1 ///< Net Address Translation(NAT) 模式
} NET_SHARE_MODE;
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
* @return @see NET_SHARE_MODE
*/
TUNNEL_API NET_SHARE_MODE __cdecl GetCurrentNetShareMode();
/**
* @brief
* @param shareMode @see NET_SHARE_MODE
*/
TUNNEL_API void __cdecl SetCurrentNetShareMode(NET_SHARE_MODE shareMode);
/**
* @brief SDK
* @param[in] pWorkDir
* @param[in] pSvrUrl URL example: http://localhost:2313, https://localhost:2313
* @param[in] pLogFile /
* @param[in] level
* @param[in] isWorkServer SDK
* - TRUE
* - FALSE
* @return 0: 0 @see USER_ERRNO
* - -ERR_ITEM_EXISTS WireGuard
* - -ERR_SYS_CALL
* - -ERR_CREATE_FILE
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl TunnelSDKInitEnv(const TCHAR *pWorkDir,
const TCHAR *pSvrUrl,
const TCHAR *pLogFile,
LOG_LEVEL level,
bool isWorkServer);
/**
* @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
*/
TUNNEL_API int __cdecl SetProtocolEncryptType(const PROTO_CRYPTO_TYPE type, const TCHAR *pProKey);
/**
* @brief / SDK
* @param enLog
* - TRUE
* - FALSE
*/
TUNNEL_API void __cdecl TunnelLogEnable(bool enLog);
/**
* @brief WireGuard
* @param[out] pFullPath wireguard.exe
* @param[in] maxSize pFullPath
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - -ERR_FILE_NOT_EXISTS
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl FindWireguardExe(TCHAR *pFullPath, int maxSize);
/**
* @brief wireguard.exe
* @param[in] pPath wireguard.exe
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_ITEM_UNEXISTS
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl SetWireguardPath(const TCHAR *pPath);
/**
* @brief WireGuard
* @param[out] pPubKey
* @param[in] pubkeySize ()
* @param[out] pPrivKey
* @param[in] privKeySize ()
* @return 0: 0 @see USER_ERRNO
* - -ERR_ITEM_UNEXISTS WireGuard
* - -ERR_CALL_SHELL
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl GenerateWireguardKeyPairs(TCHAR *pPubKey, int pubkeySize, TCHAR *pPrivKey, int privKeySize);
/**
* @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
*/
TUNNEL_API int __cdecl 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
*/
TUNNEL_API int __cdecl WireGuardCreateClientConfig(const PWGCLIENT_CONFIG pWgConfig);
/**
* @brief / WireGuard
* @param[in] bInstall TRUE , FALSE
* @return 0: 0 @see USER_ERRNO
*/
TUNNEL_API int __cdecl 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
*/
TUNNEL_API int __cdecl 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
*/
TUNNEL_API int __cdecl WireGuardUnInstallServerService(const TCHAR *pTunnelName);
/**
* @brief /
* @param[out] pIsWorkServer
* - TRUE
* - FALSE
2023-06-21 10:04:16 +00:00
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl GetWireGuardWorkMode(bool *pIsWorkServer);
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
*/
TUNNEL_API int __cdecl IsWireGuardServerInstalled(bool *pIsInstalled);
/**
* @brief WireGuard
* @param[in] pIfName WireGuard
* @param[out] pIsRunning WireGuard
* - TRUE
* - FALSE
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl IsWireGuardServerRunning(const TCHAR *pIfName, bool *pIsRunning);
/**
* @brief SDK
*/
TUNNEL_API void __cdecl TunnelSDKUnInit();
/**
* @brief SCG
* @param isEnable TRUE: SCG , FALSE: SCG
*/
TUNNEL_API void __cdecl EnableSCGProxy(bool isEnable);
/**
* @brief SCG
* @return TRUE: SCG , FALSE: SCG
*/
TUNNEL_API bool __cdecl GetSCGProxyStatus();
/**
* @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
*/
TUNNEL_API int __cdecl CalcFileHash(const HASH_TYPE type, const TCHAR *pPath, TCHAR outHash[]);
//+++++++++++++++++++++++++++++++++++++++++Temp Interface
//TUNNEL_API int __cdecl ProtoGetUserConfigure(const TCHAR *pUser, const TCHAR *pToken);
//TUNNEL_API const TCHAR* __cdecl GetInterfaceGUIDByName(const TCHAR *pInterfaceName, GUID* pGuid);
//------------------------------------------End Temp Interface
#if 0
/**
* @brief Windows NAT PowerShell
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_OPEN_FILE
* - -ERR_MEMORY_STR
* - -ERR_ITEM_UNEXISTS
* - -ERR_CALL_SHELL
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl InstallWindowsNATCommand();
TUNNEL_API int __cdecl WireGuardNetConnectionSharingEnable();
#endif
2023-06-15 01:35:37 +00:00
#ifdef __cplusplus
}
#endif