diff --git a/.appveyor.yml b/.appveyor.yml
index fe724bac..1844693e 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -1,8 +1,6 @@
version: '{build}'
-image:
- - Ubuntu1604
- - Ubuntu1804
+image: Ubuntu1804
configuration: Release
@@ -19,38 +17,20 @@ skip_commits:
init:
- ps: Update-AppveyorBuild -Version "build-$env:APPVEYOR_BUILD_NUMBER-$($env:APPVEYOR_REPO_COMMIT.substring(0,7))"
-install: git submodule update --init --recursive
-
-for:
--
- matrix:
- only:
- - image: Ubuntu1604
- before_build:
- - ./configure
- build_script:
- - make package -C build -j $(nproc || sysctl -n hw.ncpu || echo 4)
- test_script:
- - .ci/appveyor-deb-install-test.sh
- - sudo apt-get update && sudo apt-get -y install autoconf libtool liblzo2-dev libpam-dev fping unzip # openvpn build deps
- - sudo .ci/start-se-openvpn.sh
- - sudo .ci/run-openvpn-tests.sh
-
--
- matrix:
- only:
- - image: Ubuntu1804
- before_build:
- - sh: "if [ ${APPVEYOR_REPO_TAG} == \"true\" ]; then .ci/appveyor-create-release-tarball.sh\nfi"
- - ./configure
- build_script:
- - make package -C build -j $(nproc || sysctl -n hw.ncpu || echo 4)
- - .ci/memory-leak-test.sh
- test_script:
- - .ci/appveyor-deb-install-test.sh
- - sudo apt-get update && sudo apt-get -y install autoconf libtool liblzo2-dev libpam-dev fping unzip # openvpn build deps
- - sudo .ci/start-se-openvpn.sh
- - sudo .ci/run-openvpn-tests.sh
+install:
+ - sudo apt-get -y install libsodium-dev
+before_build:
+ - sh: "if [ ${APPVEYOR_REPO_TAG} == \"true\" ]; then .ci/appveyor-create-release-tarball.sh\nfi"
+ - git submodule update --init --recursive
+ - ./configure
+build_script:
+ - make package -C build -j $(nproc || sysctl -n hw.ncpu || echo 4)
+ - .ci/memory-leak-test.sh
+test_script:
+ - .ci/appveyor-deb-install-test.sh
+ - sudo apt-get update && sudo apt-get -y install autoconf libtool liblzo2-dev libpam-dev fping unzip liblz4-dev # openvpn build deps
+ - sudo .ci/start-se-openvpn.sh
+ - sudo .ci/run-openvpn-tests.sh
deploy:
description: 'automatic release'
diff --git a/.ci/azure-pipelines/linux.yml b/.ci/azure-pipelines/linux.yml
index d8f1512c..d2f0a0ba 100644
--- a/.ci/azure-pipelines/linux.yml
+++ b/.ci/azure-pipelines/linux.yml
@@ -1,10 +1,9 @@
jobs:
-- job: ubuntu_x86_64
- displayName: 'Ubuntu (x86_64)'
+- job: Ubuntu_x64
pool:
- vmImage: ubuntu-16.04
+ vmImage: ubuntu-18.04
steps:
- - script: sudo apt-get -y install cmake gcc g++ ninja-build libncurses5-dev libreadline-dev libssl-dev make zlib1g-dev
+ - script: sudo apt update && sudo apt-get -y install cmake gcc g++ ninja-build libncurses5-dev libreadline-dev libsodium-dev libssl-dev make zlib1g-dev
displayName: 'Prepare environment'
- script: "$(Build.SourcesDirectory)/.ci/azure-pipelines/linux_build.sh"
env:
diff --git a/.ci/azure-pipelines/macos.yml b/.ci/azure-pipelines/macos.yml
index acbd76e1..2e29f5e9 100644
--- a/.ci/azure-pipelines/macos.yml
+++ b/.ci/azure-pipelines/macos.yml
@@ -3,7 +3,7 @@ jobs:
pool:
vmImage: macOS-latest
steps:
- - script: brew install cmake ninja ncurses readline openssl zlib
+ - script: brew install pkg-config cmake ninja ncurses readline libsodium openssl zlib
displayName: 'Prepare environment'
- script: '$(Build.SourcesDirectory)/.ci/azure-pipelines/macos_build.sh'
env:
diff --git a/.ci/azure-pipelines/windows-steps.yml b/.ci/azure-pipelines/windows-steps.yml
index 9d053434..8e9168d3 100644
--- a/.ci/azure-pipelines/windows-steps.yml
+++ b/.ci/azure-pipelines/windows-steps.yml
@@ -15,7 +15,7 @@ steps:
path: 'C:/vcpkg/installed'
displayName: 'Environment storage'
- script: |
- vcpkg install openssl zlib --triplet ${{parameters.vcpkgTriplet}}
+ vcpkg install libsodium openssl zlib --triplet ${{parameters.vcpkgTriplet}}
workingDirectory: C:/vcpkg
displayName: 'Prepare environment'
- script: '$(Build.SourcesDirectory)/.ci/azure-pipelines/windows_build.bat'
diff --git a/.ci/azure-pipelines/windows.yml b/.ci/azure-pipelines/windows.yml
index f8cff95f..111d9bb3 100644
--- a/.ci/azure-pipelines/windows.yml
+++ b/.ci/azure-pipelines/windows.yml
@@ -1,17 +1,15 @@
jobs:
-- job: windows_x86_64
- displayName: 'Windows (x86_64)'
+- job: Windows_x64
pool:
vmImage: windows-latest
steps:
- template: "windows-steps.yml"
parameters:
- architecture: "x86_64"
+ architecture: "x64"
compilerPath: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/Llvm/x64/bin/clang-cl.exe"
vcpkgTriplet: "x64-windows-static-md"
vcvarsPath: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build/vcvars64.bat"
-- job: windows_x86
- displayName: 'Windows (x86)'
+- job: Windows_x86
pool:
vmImage: windows-latest
steps:
diff --git a/.cirrus.yml b/.cirrus.yml
index 5172b1f4..63b67383 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -13,7 +13,7 @@ FreeBSD_task:
freebsd_instance:
image_family: freebsd-12-1
prepare_script:
- - pkg install -y cmake git $SSL
+ - pkg install -y pkgconf cmake git libsodium $SSL
- git submodule update --init --recursive
configure_script:
- ./configure
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 92f5893e..f6c1cedd 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -9,7 +9,7 @@
- .cirrus.yml
before_script:
- REPOSITORY="$PWD" && cd ..
- - apt-get update && apt-get install -y dpkg-dev wget g++ gcc libncurses5-dev libreadline-dev libssl-dev make zlib1g-dev git file
+ - apt-get update && apt-get install -y dpkg-dev wget g++ gcc libncurses5-dev libreadline-dev libsodium-dev libssl-dev make zlib1g-dev git file
- wget https://cmake.org/files/v${CMAKE_VERSION%.*}/cmake-${CMAKE_VERSION}.tar.gz && tar -xzf cmake-${CMAKE_VERSION}.tar.gz
- cd cmake-${CMAKE_VERSION} && ./bootstrap && make install
- cd "$REPOSITORY" && git submodule update --init --recursive
diff --git a/.gitmodules b/.gitmodules
index e1dee0ef..1dca04b4 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -4,3 +4,9 @@
[submodule "3rdparty/tinydir"]
path = 3rdparty/tinydir
url = https://github.com/cxong/tinydir.git
+[submodule "3rdparty/BLAKE2"]
+ path = 3rdparty/BLAKE2
+ url = https://github.com/BLAKE2/BLAKE2.git
+[submodule "src/libhamcore"]
+ path = src/libhamcore
+ url = https://github.com/SoftEtherVPN/libhamcore.git
diff --git a/.travis.yml b/.travis.yml
index 61dee691..bff3cbae 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,5 @@
sudo: required
-dist: xenial
+dist: bionic
language: c
@@ -20,7 +20,8 @@ matrix:
os: linux
compiler: gcc
- env: OPENSSL_VERSION="1.1.1c" LABEL="linux-ppc64le" CMAKE_VERSION="3.9.6"
- os: linux-ppc64le
+ arch: ppc64le
+ os: linux
compiler: gcc
install:
- wget https://cmake.org/files/v${CMAKE_VERSION%.*}/cmake-${CMAKE_VERSION}.tar.gz && tar -xzf cmake-${CMAKE_VERSION}.tar.gz
@@ -35,6 +36,7 @@ matrix:
os: linux
compiler: gcc
before_install:
+ - sudo apt-get -y install libsodium-dev
- bash .ci/build-libressl.sh > build-deps.log 2>&1 || (cat build-deps.log && exit 1)
- env: LABEL="check stb files"
os: linux
@@ -49,7 +51,7 @@ matrix:
- os: osx
compiler: clang
before_install:
- - true
+ - brew install libsodium
script:
- ./configure
- make -C build
@@ -62,6 +64,7 @@ cache:
- ${HOME}/opt
before_install:
+ - sudo apt-get -y install libsodium-dev
- bash .ci/build-openssl.sh > build-deps.log 2>&1 || (cat build-deps.log && exit 1)
script:
diff --git a/3rdparty/BLAKE2 b/3rdparty/BLAKE2
new file mode 160000
index 00000000..b52178a3
--- /dev/null
+++ b/3rdparty/BLAKE2
@@ -0,0 +1 @@
+Subproject commit b52178a376ca85a8ffe50492263c2a5bc0fa4f46
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e74dd5a7..ed042987 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.7)
+cmake_minimum_required(VERSION 3.10)
set(BUILD_NUMBER CACHE STRING "The number of the current build.")
@@ -25,7 +25,7 @@ else()
endif()
# Check that submodules are present only if source was downloaded with git
-if(EXISTS "${TOP_DIRECTORY}/.git" AND NOT EXISTS "${TOP_DIRECTORY}/src/Mayaqua/3rdparty/cpu_features/CMakeLists.txt")
+if(EXISTS "${TOP_DIRECTORY}/.git" AND NOT EXISTS "${TOP_DIRECTORY}/src/libhamcore/CMakeLists.txt")
message (FATAL_ERROR "Submodules are not initialized. Run\n\tgit submodule update --init --recursive")
endif()
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
new file mode 100644
index 00000000..15d347d9
--- /dev/null
+++ b/CODE_OF_CONDUCT.md
@@ -0,0 +1,5 @@
+# Contributor Code of Conduct
+
+This project adheres to No Code of Conduct. We are all adults. We accept anyone's contributions. Nothing else matters.
+
+For more information please visit the [No Code of Conduct](https://nocodeofconduct.com) homepage.
diff --git a/src/BUILD_UNIX.md b/src/BUILD_UNIX.md
index d0a032e7..6386d627 100644
--- a/src/BUILD_UNIX.md
+++ b/src/BUILD_UNIX.md
@@ -33,18 +33,18 @@ You need to install the following software to build SoftEther VPN for UNIX.
```bash
sudo yum -y groupinstall "Development Tools"
-sudo yum -y install cmake ncurses-devel openssl-devel readline-devel zlib-devel
+sudo yum -y install cmake ncurses-devel openssl-devel libsodium-devel readline-devel zlib-devel
```
## Install requirements on Debian/Ubuntu
```bash
-sudo apt -y install cmake gcc g++ libncurses5-dev libreadline-dev libssl-dev make zlib1g-dev
+sudo apt -y install cmake gcc g++ make libncurses5-dev libssl-dev libsodium-dev libreadline-dev zlib1g-dev
```
## Install requirements on macOS
```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
-brew install cmake openssl readline
+brew install cmake openssl libsodium readline
```
# Build from source code and install
diff --git a/src/BuildFiles/Manifests/common.manifest b/src/BuildFiles/Manifests/common.manifest
new file mode 100644
index 00000000..2e279a09
--- /dev/null
+++ b/src/BuildFiles/Manifests/common.manifest
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+
diff --git a/src/BuildFiles/Manifests/x64_admin.manifest b/src/BuildFiles/Manifests/x64_admin.manifest
deleted file mode 100644
index 58caa97d..00000000
--- a/src/BuildFiles/Manifests/x64_admin.manifest
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
-
-
-
diff --git a/src/BuildFiles/Manifests/x64_user.manifest b/src/BuildFiles/Manifests/x64_user.manifest
deleted file mode 100644
index 2c19b412..00000000
--- a/src/BuildFiles/Manifests/x64_user.manifest
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
-
-
-
diff --git a/src/BuildFiles/Manifests/x86_admin.manifest b/src/BuildFiles/Manifests/x86_admin.manifest
deleted file mode 100644
index 7feaa3c2..00000000
--- a/src/BuildFiles/Manifests/x86_admin.manifest
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
-
-
-
diff --git a/src/BuildFiles/Manifests/x86_user.manifest b/src/BuildFiles/Manifests/x86_user.manifest
deleted file mode 100644
index 61ee3699..00000000
--- a/src/BuildFiles/Manifests/x86_user.manifest
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
-
-
-
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 951595e4..86bac60c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -50,10 +50,7 @@ else()
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
- set(COMPILER_ARCHITECTURE "x64")
add_definitions(-DCPU_64)
-else()
- set(COMPILER_ARCHITECTURE "x86")
endif()
add_definitions(-D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -D_FILE_OFFSET_BITS=64)
@@ -62,7 +59,7 @@ add_definitions(-D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_S
include_directories(.)
if(WIN32)
- add_definitions(-DWIN32 -D_WINDOWS -D_CRT_SECURE_NO_WARNINGS)
+ add_definitions(-DWIN32 -D_WINDOWS -DOS_WIN32 -D_CRT_SECURE_NO_WARNINGS)
endif()
if(UNIX)
@@ -70,7 +67,7 @@ if(UNIX)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
- add_definitions(-DUNIX)
+ add_definitions(-DUNIX -DOS_UNIX)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
add_definitions(-DUNIX_LINUX)
@@ -123,9 +120,6 @@ add_subdirectory(Cedar)
# Mayaqua kernel
add_subdirectory(Mayaqua)
-# hamcorebuilder utility
-add_subdirectory(hamcorebuilder)
-
# vpnserver
add_subdirectory(vpnserver)
@@ -141,6 +135,12 @@ add_subdirectory(vpncmd)
# vpntest
add_subdirectory(vpntest)
+# libhamcore
+add_subdirectory(libhamcore)
+
+# hamcorebuilder utility
+add_subdirectory(hamcorebuilder)
+
# hamcore.se2 archive file
add_custom_target(hamcore-archive-build
ALL
diff --git a/src/Cedar/Account.c b/src/Cedar/Account.c
index 31b5397a..37d69bd5 100644
--- a/src/Cedar/Account.c
+++ b/src/Cedar/Account.c
@@ -5,7 +5,18 @@
// Account.c
// Account Manager
-#include "CedarPch.h"
+#include "Account.h"
+
+#include "Hub.h"
+#include "Layer3.h"
+#include "Proto_PPP.h"
+
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Kernel.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Table.h"
// Policy items
POLICY_ITEM policy_item[] =
diff --git a/src/Cedar/Account.h b/src/Cedar/Account.h
index 633e9919..e4466cfb 100644
--- a/src/Cedar/Account.h
+++ b/src/Cedar/Account.h
@@ -8,6 +8,10 @@
#ifndef ACCOUNT_H
#define ACCOUNT_H
+#include "CedarType.h"
+
+#include "Mayaqua/Encrypt.h"
+
#define USER_MAC_STR_PREFIX L"MAC:"
#define USER_IPV4_STR_PREFIX L"IPv4:"
diff --git a/src/Cedar/Admin.c b/src/Cedar/Admin.c
index 556d90be..298a9881 100644
--- a/src/Cedar/Admin.c
+++ b/src/Cedar/Admin.c
@@ -5,7 +5,42 @@
// Admin.c
// RPC Module for Management
-#include "CedarPch.h"
+#include "Admin.h"
+
+#include "Account.h"
+#include "AzureClient.h"
+#include "BridgeUnix.h"
+#include "BridgeWin32.h"
+#include "Connection.h"
+#include "DDNS.h"
+#include "Layer3.h"
+#include "Link.h"
+#include "Listener.h"
+#include "Nat.h"
+#include "Remote.h"
+#include "Proto.h"
+#include "Proto_IPsec.h"
+#include "Proto_OpenVPN.h"
+#include "Proto_PPP.h"
+#include "Protocol.h"
+#include "Sam.h"
+#include "SecureNAT.h"
+#include "Server.h"
+#include "Session.h"
+#include "Virtual.h"
+#include "Wpc.h"
+
+#include "Mayaqua/Cfg.h"
+#include "Mayaqua/FileIO.h"
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/HTTP.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Microsoft.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Pack.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Table.h"
+#include "Mayaqua/Tick64.h"
// Macro for RPC function declaration
#define DECLARE_RPC_EX(rpc_name, data_type, function, in_rpc, out_rpc, free_rpc) \
@@ -1509,6 +1544,9 @@ PACK *AdminDispatch(RPC *rpc, char *name, PACK *p)
DECLARE_RPC_EX("GetServerCipherList", RPC_STR, StGetServerCipherList, InRpcStr, OutRpcStr, FreeRpcStr)
DECLARE_RPC_EX("GetServerCipher", RPC_STR, StGetServerCipher, InRpcStr, OutRpcStr, FreeRpcStr)
DECLARE_RPC_EX("SetServerCipher", RPC_STR, StSetServerCipher, InRpcStr, OutRpcStr, FreeRpcStr)
+ DECLARE_RPC_EX("AddWgk", RPC_WGK, StAddWgk, InRpcWgk, OutRpcWgk, FreeRpcWgk)
+ DECLARE_RPC_EX("DeleteWgk", RPC_WGK, StDeleteWgk, InRpcWgk, OutRpcWgk, FreeRpcWgk)
+ DECLARE_RPC_EX("EnumWgk", RPC_WGK, StEnumWgk, InRpcWgk, OutRpcWgk, FreeRpcWgk)
DECLARE_RPC("CreateHub", RPC_CREATE_HUB, StCreateHub, InRpcCreateHub, OutRpcCreateHub)
DECLARE_RPC("SetHub", RPC_CREATE_HUB, StSetHub, InRpcCreateHub, OutRpcCreateHub)
DECLARE_RPC("GetHub", RPC_CREATE_HUB, StGetHub, InRpcCreateHub, OutRpcCreateHub)
@@ -1693,6 +1731,9 @@ DECLARE_SC_EX("GetServerCert", RPC_KEY_PAIR, ScGetServerCert, InRpcKeyPair, OutR
DECLARE_SC_EX("GetServerCipherList", RPC_STR, ScGetServerCipherList, InRpcStr, OutRpcStr, FreeRpcStr)
DECLARE_SC_EX("GetServerCipher", RPC_STR, ScGetServerCipher, InRpcStr, OutRpcStr, FreeRpcStr)
DECLARE_SC_EX("SetServerCipher", RPC_STR, ScSetServerCipher, InRpcStr, OutRpcStr, FreeRpcStr)
+DECLARE_SC_EX("AddWgk", RPC_WGK, ScAddWgk, InRpcWgk, OutRpcWgk, FreeRpcWgk)
+DECLARE_SC_EX("DeleteWgk", RPC_WGK, ScDeleteWgk, InRpcWgk, OutRpcWgk, FreeRpcWgk)
+DECLARE_SC_EX("EnumWgk", RPC_WGK, ScEnumWgk, InRpcWgk, OutRpcWgk, FreeRpcWgk)
DECLARE_SC("CreateHub", RPC_CREATE_HUB, ScCreateHub, InRpcCreateHub, OutRpcCreateHub)
DECLARE_SC("SetHub", RPC_CREATE_HUB, ScSetHub, InRpcCreateHub, OutRpcCreateHub)
DECLARE_SC("GetHub", RPC_CREATE_HUB, ScGetHub, InRpcCreateHub, OutRpcCreateHub)
@@ -5390,7 +5431,7 @@ UINT StGetSessionStatus(ADMIN *a, RPC_SESSION_STATUS *t)
t->ClientIp = IPToUINT(&s->Connection->ClientIp);
if (IsIP6(&s->Connection->ClientIp))
{
- Copy(&t->ClientIp6, &s->Connection->ClientIp.ipv6_addr, sizeof(t->ClientIp6));
+ Copy(&t->ClientIp6, &s->Connection->ClientIp.address, sizeof(t->ClientIp6));
}
CopyIP(&t->ClientIpAddress, &s->Connection->ClientIp);
@@ -9061,9 +9102,12 @@ UINT StGetHub(ADMIN *a, RPC_CREATE_HUB *t)
{
StrCpy(t->HubName, sizeof(t->HubName), h->Name);
t->Online = h->Offline ? false : true;
+ t->HubType = h->Type;
+
+ t->HubOption.DefaultGateway = h->Option->DefaultGateway;
+ t->HubOption.DefaultSubnet = h->Option->DefaultSubnet;
t->HubOption.MaxSession = h->Option->MaxSession;
t->HubOption.NoEnum = h->Option->NoEnum;
- t->HubType = h->Type;
}
Unlock(h->lock);
@@ -9090,7 +9134,6 @@ UINT StSetHub(ADMIN *a, RPC_CREATE_HUB *t)
return ERR_INVALID_PARAMETER;
}
-
CHECK_RIGHT;
NO_SUPPORT_FOR_BRIDGE;
@@ -9157,7 +9200,7 @@ UINT StSetHub(ADMIN *a, RPC_CREATE_HUB *t)
if (Cmp(t->HashedPassword, hash2, SHA1_SIZE) == 0 || Cmp(t->SecurePassword, hash1, SHA1_SIZE) == 0)
{
- if (a->ServerAdmin == false && a->Rpc->Sock->RemoteIP.addr[0] != 127)
+ if (a->ServerAdmin == false && IsLocalHostIP(&a->Rpc->Sock->RemoteIP) == false)
{
// Refuse to set a blank password to hub admin from remote host
ReleaseHub(h);
@@ -9175,8 +9218,12 @@ UINT StSetHub(ADMIN *a, RPC_CREATE_HUB *t)
else
{
h->Type = t->HubType;
+
+ h->Option->DefaultGateway = t->HubOption.DefaultGateway;
+ h->Option->DefaultSubnet = t->HubOption.DefaultSubnet;
h->Option->MaxSession = t->HubOption.MaxSession;
h->Option->NoEnum = t->HubOption.NoEnum;
+
if (IsZero(t->HashedPassword, sizeof(t->HashedPassword)) == false &&
IsZero(t->SecurePassword, sizeof(t->SecurePassword)) == false)
{
@@ -9234,8 +9281,6 @@ UINT StCreateHub(ADMIN *a, RPC_CREATE_HUB *t)
return ERR_NOT_FARM_CONTROLLER;
}
-
-
if (IsEmptyStr(t->HubName) || IsSafeStr(t->HubName) == false)
{
return ERR_INVALID_PARAMETER;
@@ -9279,6 +9324,8 @@ UINT StCreateHub(ADMIN *a, RPC_CREATE_HUB *t)
// Create a hub object
Zero(&o, sizeof(o));
+ o.DefaultGateway = t->HubOption.DefaultGateway;
+ o.DefaultSubnet = t->HubOption.DefaultSubnet;
o.MaxSession = t->HubOption.MaxSession;
o.NoEnum = t->HubOption.NoEnum;
@@ -9497,6 +9544,144 @@ UINT StSetServerCert(ADMIN *a, RPC_KEY_PAIR *t)
return ERR_NO_ERROR;
}
+// Add a WireGuard key to the allowed key list
+UINT StAddWgk(ADMIN *a, RPC_WGK *t)
+{
+ UINT ret = ERR_NO_ERROR;
+ SERVER *s = a->Server;
+ CEDAR *c = s->Cedar;
+ LIST *to_add;
+
+ SERVER_ADMIN_ONLY;
+
+ to_add = NewListFast(NULL);
+
+ LockList(c->WgkList);
+ {
+ UINT i;
+ for (i = 0; i < t->Num; ++i)
+ {
+ WGK *rpc_wgk = &t->Wgks[i];
+ WGK *wgk;
+
+ if (IsEmptyStr(rpc_wgk->Key))
+ {
+ ret = ERR_INVALID_PARAMETER;
+ break;
+ }
+
+ if (Search(c->WgkList, rpc_wgk) != NULL)
+ {
+ ret = ERR_OBJECT_EXISTS;
+ break;
+ }
+
+ wgk = Malloc(sizeof(WGK));
+ StrCpy(wgk->Key, sizeof(wgk->Key), rpc_wgk->Key);
+ StrCpy(wgk->Hub, sizeof(wgk->Hub), rpc_wgk->Hub);
+ StrCpy(wgk->User, sizeof(wgk->User), rpc_wgk->User);
+
+ Add(to_add, wgk);
+ }
+
+ for (i = 0; i < LIST_NUM(to_add); ++i)
+ {
+ WGK *wgk = LIST_DATA(to_add, i);
+ ret == ERR_NO_ERROR ? Add(c->WgkList, wgk) : Free(wgk);
+ }
+ }
+ UnlockList(c->WgkList);
+
+ if (ret == ERR_NO_ERROR)
+ {
+ ALog(a, NULL, "LA_ADD_WGK", LIST_NUM(to_add));
+ IncrementServerConfigRevision(a->Server);
+ }
+
+ ReleaseList(to_add);
+
+ return ret;
+}
+
+// Delete a WireGuard key from the allowed key list
+UINT StDeleteWgk(ADMIN *a, RPC_WGK *t)
+{
+ UINT ret = ERR_NO_ERROR;
+ SERVER *s = a->Server;
+ CEDAR *c = s->Cedar;
+ LIST *to_delete;
+
+ SERVER_ADMIN_ONLY;
+
+ to_delete = NewListFast(NULL);
+
+ LockList(c->WgkList);
+ {
+ UINT i;
+ for (i = 0; i < t->Num; ++i)
+ {
+ WGK *wgk = Search(c->WgkList, &t->Wgks[i]);
+ if (wgk == NULL)
+ {
+ ret = ERR_OBJECT_NOT_FOUND;
+ break;
+ }
+
+ Add(to_delete, wgk);
+ }
+
+ if (ret == ERR_NO_ERROR)
+ {
+ for (i = 0; i < LIST_NUM(to_delete); ++i)
+ {
+ WGK *wgk = LIST_DATA(to_delete, i);
+ Delete(c->WgkList, wgk);
+ Free(wgk);
+ }
+ }
+ }
+ UnlockList(c->WgkList);
+
+ if (ret == ERR_NO_ERROR)
+ {
+ ALog(a, NULL, "LA_DELETE_WGK", LIST_NUM(to_delete));
+ IncrementServerConfigRevision(a->Server);
+ }
+
+ ReleaseList(to_delete);
+
+ return ret;
+}
+
+// List the allowed WireGuard keys
+UINT StEnumWgk(ADMIN *a, RPC_WGK *t)
+{
+ SERVER *s = a->Server;
+ CEDAR *c = s->Cedar;
+
+ SERVER_ADMIN_ONLY;
+
+ LockList(c->WgkList);
+ {
+ UINT i;
+ t->Num = LIST_NUM(c->WgkList);
+ t->Wgks = Malloc(sizeof(WGK) * t->Num);
+
+ for (i = 0; i < t->Num; ++i)
+ {
+ WGK *wgk = LIST_DATA(c->WgkList, i);
+ WGK *rpc_wgk = &t->Wgks[i];
+
+ StrCpy(rpc_wgk->Key, sizeof(rpc_wgk->Key), wgk->Key);
+ StrCpy(rpc_wgk->Hub, sizeof(rpc_wgk->Hub), wgk->Hub);
+ StrCpy(rpc_wgk->User, sizeof(rpc_wgk->User), wgk->User);
+ }
+ }
+ UnlockList(c->WgkList);
+
+ return ERR_NO_ERROR;
+}
+
// Get status of connection to cluster controller
UINT StGetFarmConnectionStatus(ADMIN *a, RPC_FARM_CONNECTION_STATUS *t)
{
@@ -10021,6 +10206,8 @@ UINT StGetProtoOptions(ADMIN *a, RPC_PROTO_OPTIONS *t)
UINT ret = ERR_NO_ERROR;
LIST *options;
+ SERVER_ADMIN_ONLY;
+
if (proto == NULL)
{
return ERR_NOT_SUPPORTED;
@@ -12885,6 +13072,8 @@ void InRpcHubOption(RPC_HUB_OPTION *t, PACK *p)
}
Zero(t, sizeof(RPC_HUB_OPTION));
+ t->DefaultGateway = PackGetInt(p, "DefaultGateway");
+ t->DefaultSubnet = PackGetInt(p, "DefaultSubnet");
t->MaxSession = PackGetInt(p, "MaxSession");
t->NoEnum = PackGetBool(p, "NoEnum");
}
@@ -12896,6 +13085,8 @@ void OutRpcHubOption(PACK *p, RPC_HUB_OPTION *t)
return;
}
+ PackAddInt(p, "DefaultGateway", t->DefaultGateway);
+ PackAddInt(p, "DefaultSubnet", t->DefaultSubnet);
PackAddInt(p, "MaxSession", t->MaxSession);
PackAddBool(p, "NoEnum", t->NoEnum);
}
@@ -14455,6 +14646,64 @@ void FreeRpcKeyPair(RPC_KEY_PAIR *t)
FreeK(t->Key);
}
+// RPC_WGK
+void InRpcWgk(RPC_WGK *t, PACK *p)
+{
+ UINT i;
+ // Validate arguments
+ if (t == NULL || p == NULL)
+ {
+ return;
+ }
+
+ Zero(t, sizeof(RPC_WGK));
+
+ t->Num = PackGetIndexCount(p, "Key");
+ if (t->Num == 0)
+ {
+ return;
+ }
+
+ t->Wgks = ZeroMalloc(sizeof(WGK) * t->Num);
+
+ for (i = 0; i < t->Num; ++i)
+ {
+ WGK *wgk = &t->Wgks[i];
+
+ PackGetStrEx(p, "Key", wgk->Key, sizeof(wgk->Key), i);
+ PackGetStrEx(p, "Hub", wgk->Hub, sizeof(wgk->Hub), i);
+ PackGetStrEx(p, "User", wgk->User, sizeof(wgk->User), i);
+ }
+}
+void OutRpcWgk(PACK *p, RPC_WGK *t)
+{
+ UINT i;
+ // Validate arguments
+ if (t == NULL || p == NULL)
+ {
+ return;
+ }
+
+ for (i = 0; i < t->Num; ++i)
+ {
+ WGK *wgk = &t->Wgks[i];
+
+ PackAddStrEx(p, "Key", wgk->Key, i, t->Num);
+ PackAddStrEx(p, "Hub", wgk->Hub, i, t->Num);
+ PackAddStrEx(p, "User", wgk->User, i, t->Num);
+ }
+}
+void FreeRpcWgk(RPC_WGK *t)
+{
+ // Validate arguments
+ if (t == NULL)
+ {
+ return;
+ }
+
+ Free(t->Wgks);
+}
+
// NODE_INFO
void InRpcNodeInfo(NODE_INFO *t, PACK *p)
{
@@ -15121,7 +15370,7 @@ UINT AdminAccept(CONNECTION *c, PACK *p)
if (Cmp(secure_null_password, secure_password, SHA1_SIZE) == 0)
{
- if (sock->RemoteIP.addr[0] != 127)
+ if (IsLocalHostIP(&sock->RemoteIP) == false)
{
// The client tried to use blank password for hub admin mode from remote
if (StrLen(hubname) != 0)
diff --git a/src/Cedar/Admin.h b/src/Cedar/Admin.h
index 0872c9f6..b176a6f0 100644
--- a/src/Cedar/Admin.h
+++ b/src/Cedar/Admin.h
@@ -8,6 +8,14 @@
#ifndef ADMIN_H
#define ADMIN_H
+#include "Account.h"
+#include "Cedar.h"
+#include "Client.h"
+#include "Hub.h"
+#include "Logging.h"
+
+#include "Mayaqua/Kernel.h"
+
// Windows version
struct RPC_WINVER
{
@@ -226,9 +234,18 @@ struct RPC_KEY_PAIR
UINT Flag1; // Flag1
};
+// WireGuard keys
+struct RPC_WGK
+{
+ UINT Num; // Number of keys
+ WGK *Wgks; // Keys
+};
+
// HUB option
struct RPC_HUB_OPTION
{
+ UINT DefaultGateway; // Default gateway address
+ UINT DefaultSubnet; // Default subnet mask
UINT MaxSession; // Maximum number of sessions
bool NoEnum; // Not listed
};
@@ -987,6 +1004,9 @@ UINT StGetServerCert(ADMIN *a, RPC_KEY_PAIR *t);
UINT StGetServerCipherList(ADMIN *a, RPC_STR *t);
UINT StGetServerCipher(ADMIN *a, RPC_STR *t);
UINT StSetServerCipher(ADMIN *a, RPC_STR *t);
+UINT StAddWgk(ADMIN *a, RPC_WGK *t);
+UINT StDeleteWgk(ADMIN *a, RPC_WGK *t);
+UINT StEnumWgk(ADMIN *a, RPC_WGK *t);
UINT StCreateHub(ADMIN *a, RPC_CREATE_HUB *t);
UINT StSetHub(ADMIN *a, RPC_CREATE_HUB *t);
UINT StGetHub(ADMIN *a, RPC_CREATE_HUB *t);
@@ -1135,6 +1155,9 @@ UINT ScGetServerCert(RPC *r, RPC_KEY_PAIR *t);
UINT ScGetServerCipherList(RPC *r, RPC_STR *t);
UINT ScGetServerCipher(RPC *r, RPC_STR *t);
UINT ScSetServerCipher(RPC *r, RPC_STR *t);
+UINT ScAddWgk(RPC *r, RPC_WGK *t);
+UINT ScDeleteWgk(RPC *r, RPC_WGK *t);
+UINT ScEnumWgk(RPC *r, RPC_WGK *t);
UINT ScCreateHub(RPC *r, RPC_CREATE_HUB *t);
UINT ScSetHub(RPC *r, RPC_CREATE_HUB *t);
UINT ScGetHub(RPC *r, RPC_CREATE_HUB *t);
@@ -1392,6 +1415,9 @@ void OutRpcMemInfo(PACK *p, MEMINFO *t);
void InRpcKeyPair(RPC_KEY_PAIR *t, PACK *p);
void OutRpcKeyPair(PACK *p, RPC_KEY_PAIR *t);
void FreeRpcKeyPair(RPC_KEY_PAIR *t);
+void InRpcWgk(RPC_WGK *t, PACK *p);
+void OutRpcWgk(PACK *p, RPC_WGK *t);
+void FreeRpcWgk(RPC_WGK *t);
void InRpcAddAccess(RPC_ADD_ACCESS *t, PACK *p);
void OutRpcAddAccess(PACK *p, RPC_ADD_ACCESS *t);
void InRpcDeleteAccess(RPC_DELETE_ACCESS *t, PACK *p);
diff --git a/src/Cedar/AzureClient.c b/src/Cedar/AzureClient.c
index 65b0106c..ea6a966c 100644
--- a/src/Cedar/AzureClient.c
+++ b/src/Cedar/AzureClient.c
@@ -5,7 +5,23 @@
// AzureClient.c
// VPN Azure Client
-#include "CedarPch.h"
+#include "AzureClient.h"
+
+#include "Cedar.h"
+#include "Command.h"
+#include "Wpc.h"
+
+#include "Mayaqua/Encrypt.h"
+#include "Mayaqua/Mayaqua.h"
+#include "Mayaqua/MayaType.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Network.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Pack.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Tick64.h"
+
+#include
// Wait for connection request
void AcWaitForRequest(AZURE_CLIENT *ac, SOCK *s, AZURE_PARAM *param)
diff --git a/src/Cedar/AzureClient.h b/src/Cedar/AzureClient.h
index 6ffa8bf7..4e8050b9 100644
--- a/src/Cedar/AzureClient.h
+++ b/src/Cedar/AzureClient.h
@@ -8,6 +8,11 @@
#ifndef AZURE_CLIENT_H
#define AZURE_CLIENT_H
+#include "Cedar.h"
+#include "DDNS.h"
+
+#include "Mayaqua/MayaType.h"
+
// Constants
#define AZURE_SERVER_PORT 443
#define AZURE_PROTOCOL_CONTROL_SIGNATURE "ACTL"
diff --git a/src/Cedar/AzureServer.c b/src/Cedar/AzureServer.c
deleted file mode 100644
index 0a1a000e..00000000
--- a/src/Cedar/AzureServer.c
+++ /dev/null
@@ -1,10 +0,0 @@
-// SoftEther VPN Source Code - Developer Edition Master Branch
-// Cedar Communication Module
-
-
-// AzureServer.c
-// VPN Azure Server
-
-#include "CedarPch.h"
-
-
diff --git a/src/Cedar/AzureServer.h b/src/Cedar/AzureServer.h
deleted file mode 100644
index 6e86bd8f..00000000
--- a/src/Cedar/AzureServer.h
+++ /dev/null
@@ -1,14 +0,0 @@
-// SoftEther VPN Source Code - Developer Edition Master Branch
-// Cedar Communication Module
-
-
-// AzureServer.h
-// Header of AzureServer.c
-
-#ifndef AZURE_SERVER_H
-#define AZURE_SERVER_H
-
-
-#endif // AZURE_SERVER_H
-
-
diff --git a/src/Cedar/Bridge.c b/src/Cedar/Bridge.c
index 3a4ca7b2..48bc806a 100644
--- a/src/Cedar/Bridge.c
+++ b/src/Cedar/Bridge.c
@@ -5,25 +5,19 @@
// Bridge.c
// Ethernet Bridge Program (Local Bridge)
-#include
+#include "Bridge.h"
+#include "BridgeUnix.h"
+#include "BridgeWin32.h"
-#define BRIDGE_C
+#include "Connection.h"
+#include "Hub.h"
+#include "Session.h"
+#include "Virtual.h"
-#ifdef WIN32
-#define OS_WIN32
-#endif
-
-#ifdef OS_WIN32
-
-// Win32
-#include "BridgeWin32.c"
-
-#else
-
-// Unix
-#include "BridgeUnix.c"
-
-#endif // OS_WIN32
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Microsoft.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
// Hash the list of current Ethernet devices
UINT GetEthDeviceHash()
diff --git a/src/Cedar/Bridge.h b/src/Cedar/Bridge.h
index c3ff9815..f2dc510e 100644
--- a/src/Cedar/Bridge.h
+++ b/src/Cedar/Bridge.h
@@ -8,20 +8,10 @@
#ifndef BRIDGE_H
#define BRIDGE_H
-#ifdef OS_WIN32
-
-// For Win32
-#include
-
-#else
-
-// For Unix
-#include
-
-#endif // OS_WIN32
+#include "Cedar.h"
// Constants
-#define BRIDGE_SPECIAL_IPRAW_NAME "ipv4_rawsocket_virtual_router"
+#define BRIDGE_SPECIAL_IPRAW_NAME "ipv4_rawsocket_virtual_router"
// Bridge
struct BRIDGE
diff --git a/src/Cedar/BridgeUnix.c b/src/Cedar/BridgeUnix.c
index 5fa21762..b883bb47 100644
--- a/src/Cedar/BridgeUnix.c
+++ b/src/Cedar/BridgeUnix.c
@@ -4,22 +4,31 @@
// BridgeUnix.c
// Ethernet Bridge Program (for UNIX)
-//#define BRIDGE_C
-//#define UNIX_LINUX
-#include
+#ifdef OS_UNIX
-#ifdef BRIDGE_C
+#include "BridgeUnix.h"
+
+#include "Server.h"
+#include "VLanUnix.h"
+
+#include "Mayaqua/Cfg.h"
+#include "Mayaqua/FileIO.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/TcpIp.h"
+#include "Mayaqua/Unix.h"
-#include
-#include
#include
-#include
-#include
-#include
+
#include
-#include
-#include
+#include
+
+#include
+#include
+#include
+#include
#ifdef UNIX_SOLARIS
#include
@@ -27,17 +36,18 @@
#ifdef BRIDGE_PCAP
#include
-#endif // BRIDGE_PCAP
+#endif
#ifdef BRIDGE_BPF
-#include
+#include
#include
#include
#include
-#include
-#endif // BRIDGE_BPF
+#endif
+
+#ifdef UNIX_LINUX
+#include
-#ifdef UNIX_LINUX
struct my_tpacket_auxdata
{
UINT tp_status;
@@ -2688,5 +2698,4 @@ void EthPutPacketLinuxIpRaw(ETH *e, void *data, UINT size)
Free(data);
}
-
-#endif // BRIDGE_C
+#endif
diff --git a/src/Cedar/BridgeUnix.h b/src/Cedar/BridgeUnix.h
index 7c1b7465..65cf4f31 100644
--- a/src/Cedar/BridgeUnix.h
+++ b/src/Cedar/BridgeUnix.h
@@ -5,9 +5,15 @@
// BridgeUnix.h
// Header of BridgeUnix.c
+#ifdef OS_UNIX
+
#ifndef BRIDGEUNIX_H
#define BRIDGEUNIX_H
+#include "Bridge.h"
+
+#include "Mayaqua/Network.h"
+
// Macro
#ifndef SOL_PACKET
#define SOL_PACKET 263
@@ -128,6 +134,6 @@ bool DlipBindRequest(int fd);
int UnixEthOpenRawSocket();
-#endif // BRIDGEUNIX_H
-
+#endif // BRIDGEUNIX_H
+#endif // OS_UNIX
diff --git a/src/Cedar/BridgeWin32.c b/src/Cedar/BridgeWin32.c
index eca7952a..00d3ada0 100644
--- a/src/Cedar/BridgeWin32.c
+++ b/src/Cedar/BridgeWin32.c
@@ -5,24 +5,27 @@
// BridgeWin32.c
// Ethernet Bridge Program (Win32)
-#include
+#ifdef OS_WIN32
-#ifdef BRIDGE_C
+#define BRIDGE_C
+
+#include "BridgeWin32.h"
+
+#include "Admin.h"
+#include "Connection.h"
+#include "SeLowUser.h"
+
+#include "Mayaqua/Cfg.h"
+#include "Mayaqua/FileIO.h"
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Microsoft.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Tick64.h"
+#include "Mayaqua/Str.h"
-#include
#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
static WP *wp = NULL;
static LIST *eth_list = NULL;
@@ -466,11 +469,6 @@ bool EnumEthVLanWin32(RPC_ENUM_ETH_VLAN *t)
Zero(t, sizeof(RPC_ENUM_ETH_VLAN));
- if (MsIsWin2000OrGreater() == false)
- {
- return false;
- }
-
if (IsEthSupported() == false)
{
return false;
@@ -1488,7 +1486,7 @@ LIST *GetEthAdapterListInternal()
i = 0;
- if (OS_IS_WINDOWS_NT(GetOsInfo()->OsType))
+ if (true)
{
// Windows NT
if (size >= 2 && buf[0] != 0 && buf[1] != 0)
@@ -1526,7 +1524,6 @@ LIST *GetEthAdapterListInternal()
}
else
{
- // Windows 9x
ANSI_STR:
while (true)
{
@@ -1564,18 +1561,6 @@ ANSI_STR:
StrCpy(a->Title, sizeof(a->Title), &buf[i]);
i += StrSize(a->Title);
- // If device description is "Unknown" in Win9x, skip 1 byte
- if (OS_IS_WINDOWS_9X(GetOsInfo()->OsType))
- {
- if (StrCmp(a->Title, "Unknown") == 0)
- {
- if (buf[i] == 0)
- {
- i+=sizeof(char);
- }
- }
- }
-
TrimCrlf(a->Title);
Trim(a->Title);
TrimCrlf(a->Title);
@@ -1790,31 +1775,7 @@ bool IsEthSupportedInner()
// Is the PCD driver supported in current OS
bool IsPcdSupported()
{
- UINT type;
- OS_INFO *info = GetOsInfo();
-
- if (MsIsWindows10())
- {
- // Windows 10 or later never supports PCD driver.
- return false;
- }
-
- type = info->OsType;
-
- if (OS_IS_WINDOWS_NT(type) == false)
- {
- // Only on Windows NT series
- return false;
- }
-
- if (GET_KETA(type, 100) >= 2)
- {
- // Good for Windows 2000 or later
- return true;
- }
-
- // Not good for Windows NT 4.0 or Longhorn
- return false;
+ return !MsIsWindows10();
}
// Save build number of PCD driver
@@ -2085,8 +2046,7 @@ void GetEthNetworkConnectionName(wchar_t *dst, UINT size, char *device_name)
UniStrCpy(dst, size, L"");
// Validate arguments
- if (device_name == NULL || IsEthSupported() == false ||
- IsNt() == false || MsIsWin2000OrGreater() == false)
+ if (device_name == NULL || IsEthSupported() == false)
{
return;
}
@@ -2134,6 +2094,4 @@ void GetEthNetworkConnectionName(wchar_t *dst, UINT size, char *device_name)
Free(ncname);
}
-#endif // BRIDGE_C
-
-
+#endif
diff --git a/src/Cedar/BridgeWin32.h b/src/Cedar/BridgeWin32.h
index da08850d..06184380 100644
--- a/src/Cedar/BridgeWin32.h
+++ b/src/Cedar/BridgeWin32.h
@@ -5,9 +5,15 @@
// BridgeWin32.h
// Header of BridgeWin32.c
+#ifdef OS_WIN32
+
#ifndef BRIDGEWIN32_H
#define BRIDGEWIN32_H
+#include "Bridge.h"
+
+#include
+
#define BRIDGE_WIN32_PACKET_DLL "Packet.dll"
#define BRIDGE_WIN32_PCD_DLL "|see.dll"
#define BRIDGE_WIN32_PCD_SYS "|DriverPackages\\See\\x86\\See_x86.sys"
@@ -18,10 +24,7 @@
#define BRIDGE_WIN32_ETH_BUFFER (1048576)
-
-typedef void *HANDLE;
-
-#ifdef BRIDGE_C
+#ifdef BRIDGE_C
// Header for Internal function (for BridgeWin32.c)
typedef struct WP
@@ -157,6 +160,6 @@ bool Win32IsUsingSeLow();
void Win32SetEnableSeLow(bool b);
bool Win32GetEnableSeLow();
-#endif // BRIDGEWIN32_H
-
+#endif // BRIDGEWIN32_H
+#endif // OS_WIN32
diff --git a/src/Cedar/CM.c b/src/Cedar/CM.c
index fda76b33..3d311cf9 100644
--- a/src/Cedar/CM.c
+++ b/src/Cedar/CM.c
@@ -5,46 +5,33 @@
// CM.c
// VPN Client Connection Manager for Win32
-#include
+#ifdef OS_WIN32
-#ifdef WIN32
+#define WINUI_C
+#define MICROSOFT_C
-#define CM_C
-#define SM_C
-#define MICROSOFT_C
-
-#define _WIN32_WINNT 0x0502
-#define WINVER 0x0502
-#define SECURITY_WIN32
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
#include "CMInner.h"
+
+#include "Nat.h"
+#include "Protocol.h"
+#include "Remote.h"
#include "SMInner.h"
-#include "NMInner.h"
-#include "EMInner.h"
+#include "UT.h"
+#include "Win32Com.h"
+#include "WinUi.h"
+
+#include "Mayaqua/FileIO.h"
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Microsoft.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Secure.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Win32.h"
+
#include "../PenCore/resource.h"
+#include
// Get the proxy server settings from the registry string of IE
bool CmGetProxyServerNameAndPortFromIeProxyRegStr(char *name, UINT name_size, UINT *port, char *str, char *server_type)
@@ -232,14 +219,7 @@ UINT CmGetSecureBitmapId(char *dest_hostname)
// Activate the window of UAC
void CmSetUacWindowActive()
{
- HWND hWnd;
-
- if (MsIsVista() == false)
- {
- return;
- }
-
- hWnd = FindWindowA("$$$Secure UAP Dummy Window Class For Interim Dialog", NULL);
+ HWND hWnd = FindWindowA("$$$Secure UAP Dummy Window Class For Interim Dialog", NULL);
if (hWnd == NULL)
{
return;
@@ -1485,22 +1465,8 @@ void CmTrafficRunDlgAddStr(HWND hWnd, wchar_t *str)
UniReplaceStrEx(tmp, tmp_size, tmp, L"\r\n", L"\n", false);
UniReplaceStrEx(tmp, tmp_size, tmp, L"\n", L"\r\n", false);
- if (MsIsNt())
- {
- SendMsg(hWnd, E_EDIT, EM_SETSEL, 0x7fffffff, 0x7fffffff);
- SendMsg(hWnd, E_EDIT, EM_REPLACESEL, false, (LPARAM)tmp);
- }
- else
- {
- char *s = CopyUniToStr(tmp);
- UINT len;
-
- len = GetWindowTextLength(DlgItem(hWnd, E_EDIT));
- SendMsg(hWnd, E_EDIT, EM_SETSEL, 0x7fffffff, 0x7fffffff);
- SendMsg(hWnd, E_EDIT, EM_SETSEL, len, len);
- SendMsg(hWnd, E_EDIT, EM_REPLACESEL, false, (LPARAM)s);
- Free(s);
- }
+ SendMsg(hWnd, E_EDIT, EM_SETSEL, 0x7fffffff, 0x7fffffff);
+ SendMsg(hWnd, E_EDIT, EM_REPLACESEL, false, (LPARAM)tmp);
Free(tmp);
}
@@ -3568,11 +3534,6 @@ bool CmStopInstallVLan(HWND hWnd)
// There is no need to be prohibited if the client is an UNIX
return true;
}
- if (cm->Client->Win9x)
- {
- // There is no need to prohibit if the client is a Win9x
- return true;
- }
return true;
@@ -5474,27 +5435,12 @@ void CmMainWindowOnCommandEx(HWND hWnd, WPARAM wParam, LPARAM lParam, bool easy)
name = CmNewVLanDlg(hWnd);
if (name != NULL)
{
- wchar_t tmp[MAX_SIZE];
void *helper = NULL;
RPC_CLIENT_CREATE_VLAN c;
Zero(&c, sizeof(c));
StrCpy(c.DeviceName, sizeof(c.DeviceName), name);
- if (MsIsNt() == false)
- {
- // Change the title of the window
- GetTxt(hWnd, 0, tmp, sizeof(tmp));
- SetText(hWnd, 0, _UU("CM_VLAN_INSTALLING"));
- }
- // Minimize
- if (MsIsVista() == false)
- {
- ShowWindow(hWnd, SW_SHOWMINIMIZED);
- }
- if (MsIsVista())
- {
- helper = CmStartUacHelper();
- }
+ helper = CmStartUacHelper();
if (CALL(hWnd, CcCreateVLan(cm->Client, &c)))
{
@@ -5503,17 +5449,9 @@ void CmMainWindowOnCommandEx(HWND hWnd, WPARAM wParam, LPARAM lParam, bool easy)
CmStopUacHelper(helper);
- if (MsIsNt() == false)
- {
- // Restore the title of the window
- SetText(hWnd, 0, tmp);
- }
- // Restore
- if (MsIsVista() == false)
- {
- ShowWindow(hWnd, SW_SHOWNORMAL);
- }
Free(name);
+
+ CmRefresh(hWnd);
}
break;
case CMD_DELETE_VLAN:
@@ -5521,39 +5459,29 @@ void CmMainWindowOnCommandEx(HWND hWnd, WPARAM wParam, LPARAM lParam, bool easy)
index = LvGetSelected(hWnd, L_VLAN);
if (index != INFINITE)
{
- if (cm->Client->Win9x == false)
+ // Windows 2000 or later
+ wchar_t *s = LvGetStr(hWnd, L_VLAN, index, 0);
+ if (s != NULL)
{
- // Windows 2000 or later
- wchar_t *s = LvGetStr(hWnd, L_VLAN, index, 0);
- if (s != NULL)
+ RPC_CLIENT_CREATE_VLAN c;
+ char str[MAX_SIZE];
+ CmVoice("delete_vlan_1");
+ if (MsgBoxEx(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2, _UU("CM_DELETE_VLAN"), s) == IDYES)
{
- RPC_CLIENT_CREATE_VLAN c;
- char str[MAX_SIZE];
- CmVoice("delete_vlan_1");
- if (MsgBoxEx(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2, _UU("CM_DELETE_VLAN"), s) == IDYES)
+ Zero(&c, sizeof(c));
+ UniToStr(str, sizeof(str), s);
+ if (CmPrintNameToVLanName(c.DeviceName, sizeof(c.DeviceName), str))
{
- Zero(&c, sizeof(c));
- UniToStr(str, sizeof(str), s);
- if (CmPrintNameToVLanName(c.DeviceName, sizeof(c.DeviceName), str))
+ if (CALL(hWnd, CcDeleteVLan(cm->Client, &c)))
{
- if (CALL(hWnd, CcDeleteVLan(cm->Client, &c)))
- {
- CmVoice("delete_vlan_2");
- }
+ CmVoice("delete_vlan_2");
}
}
- Free(s);
- }
- }
- else
- {
- // Windows 9x
- if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO, _UU("CM_9X_VLAN_UNINSTALL")) == IDYES)
- {
- Run("rundll32.exe", "shell32.dll,Control_RunDLL NETCPL.CPL",
- false, false);
}
+ Free(s);
}
+
+ CmRefresh(hWnd);
}
break;
case CMD_ENABLE_VLAN:
@@ -5573,6 +5501,8 @@ void CmMainWindowOnCommandEx(HWND hWnd, WPARAM wParam, LPARAM lParam, bool easy)
CALL(hWnd, CcEnableVLan(cm->Client, &c));
}
Free(s);
+
+ CmRefresh(hWnd);
}
}
break;
@@ -5593,6 +5523,8 @@ void CmMainWindowOnCommandEx(HWND hWnd, WPARAM wParam, LPARAM lParam, bool easy)
CALL(hWnd, CcDisableVLan(cm->Client, &c));
}
Free(s);
+
+ CmRefresh(hWnd);
}
}
break;
@@ -5621,28 +5553,15 @@ void CmMainWindowOnCommandEx(HWND hWnd, WPARAM wParam, LPARAM lParam, bool easy)
UniToStr(str, sizeof(str), s);
if (CmPrintNameToVLanName(c.DeviceName, sizeof(c.DeviceName), str))
{
- void *helper = NULL;
-
- if (MsIsVista() == false)
- {
- ShowWindow(hWnd, SW_SHOWMINIMIZED);
- }
-
- if (MsIsVista())
- {
- helper = CmStartUacHelper();
- }
+ void *helper = CmStartUacHelper();
CALL(hWnd, CcUpgradeVLan(cm->Client, &c));
CmStopUacHelper(helper);
-
- if (MsIsVista() == false)
- {
- ShowWindow(hWnd, SW_SHOWNORMAL);
- }
}
Free(s);
+
+ CmRefresh(hWnd);
}
}
break;
@@ -5710,11 +5629,7 @@ void CmMainWindowOnCommandEx(HWND hWnd, WPARAM wParam, LPARAM lParam, bool easy)
break;
case CMD_MMCSS:
// Optimization utility for Windows Vista
- if (MsIsVista() == false)
- {
- MsgBox(hWnd, MB_ICONINFORMATION, _UU("VISTA_MMCSS_MSG_4"));
- }
- else
+ if (true)
{
if (MsIsAdmin() == false)
{
@@ -5782,7 +5697,6 @@ void CmConfigDlgInit(HWND hWnd)
{
bool use_alpha;
UINT alpha_value;
- UINT os;
CLIENT_CONFIG c;
// Validate arguments
if (hWnd == NULL)
@@ -5817,15 +5731,7 @@ void CmConfigDlgInit(HWND hWnd)
SetInt(hWnd, E_ALPHA_VALUE, alpha_value == 0 ? 50 : alpha_value);
Check(hWnd, R_ALPHA, use_alpha);
- os = GetOsInfo()->OsType;
- if (OS_IS_WINDOWS_NT(os) && GET_KETA(os, 100) >= 2)
- {
- Enable(hWnd, R_ALPHA);
- }
- else
- {
- Disable(hWnd, R_ALPHA);
- }
+ Enable(hWnd, R_ALPHA);
CmConfigDlgRefresh(hWnd);
}
@@ -6427,8 +6333,8 @@ UINT CmNewVLanDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *p
switch (msg)
{
case WM_INITDIALOG:
- LimitText(hWnd, E_NAME, cm->Client->Win9x ? MAX_DEVICE_NAME_LEN_9X : MAX_DEVICE_NAME_LEN);
- FormatText(hWnd, S_INFO, cm->Client->Win9x ? MAX_DEVICE_NAME_LEN_9X : MAX_DEVICE_NAME_LEN);
+ LimitText(hWnd, E_NAME, MAX_DEVICE_NAME_LEN);
+ FormatText(hWnd, S_INFO, MAX_DEVICE_NAME_LEN);
Zero(&ver, sizeof(ver));
@@ -6453,15 +6359,7 @@ UINT CmNewVLanDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *p
switch (wParam)
{
case IDOK:
- if (cm->Client->Win9x)
- {
- // For Windows 9x, show a confirmation message
- if (MsgBox(hWnd, MB_ICONQUESTION | MB_OKCANCEL, _UU("CM_9X_VLAN_INSTALL")) == IDCANCEL)
- {
- break;
- }
- }
- GetTxtA(hWnd, E_NAME, tmp, (cm->Client->Win9x ? MAX_DEVICE_NAME_LEN_9X : MAX_DEVICE_NAME_LEN) + 1);
+ GetTxtA(hWnd, E_NAME, tmp, MAX_DEVICE_NAME_LEN + 1);
Trim(tmp);
if (CcGetClientVersion(cm->Client, &ver) == ERR_NO_ERROR)
@@ -9923,30 +9821,6 @@ void CmConnect(HWND hWnd, wchar_t *account_name)
return;
}
- if (hWnd == cm->hMainWnd)
- {
- if (LvNum(hWnd, L_VLAN) == 0 && cm->Client->Win9x)
- {
- if (MsgBox(hWnd, MB_ICONINFORMATION | MB_YESNO, _UU("CM_NO_VLAN_2")) == IDNO)
- {
- return;
- }
- else
- {
- if (cm->server_name == NULL || cm->Client->Unix)
- {
- Command(hWnd, CMD_NEW_VLAN);
- return;
- }
- else
- {
- MsgBox(hWnd, MB_ICONINFORMATION, _UU("CM_VLAN_REMOTE_ERROR"));
- }
- return;
- }
- }
- }
-
// (If necessary) display a warning
if (CmWarningDesktop(hWnd, account_name) == false)
{
@@ -10085,7 +9959,7 @@ bool CmIsEnabled(HWND hWnd, UINT id)
switch (id)
{
case CMD_LANGUAGE:
- return MsIsNt();
+ return true;
case CMD_SHOWPORT:
case CMD_GRID:
if (cm->IconView)
@@ -10094,7 +9968,7 @@ bool CmIsEnabled(HWND hWnd, UINT id)
}
return true;
case CMD_MMCSS:
- if (MsIsVista() == false || IsEmptyStr(cm->server_name) == false)
+ if (IsEmptyStr(cm->server_name) == false)
{
return false;
}
@@ -10105,12 +9979,7 @@ bool CmIsEnabled(HWND hWnd, UINT id)
return true;
case CMD_TRAYICON:
case CMD_TRAFFIC:
- return (cm->server_name == NULL);
case CMD_NETIF:
- if (MsIsNt() == false)
- {
- return false;
- }
return (cm->server_name == NULL);
case CMD_CM_SETTING:
return cm->CmSettingSupported;
@@ -10172,7 +10041,7 @@ bool CmIsEnabled(HWND hWnd, UINT id)
}
case CMD_SHORTCUT:
// Create a shortcut
- if (cm->Client->Rpc->Sock->RemoteIP.addr[0] != 127)
+ if (IsLocalHostIP(&cm->Client->Rpc->Sock->RemoteIP) == false)
{
return false;
}
@@ -10247,21 +10116,11 @@ bool CmIsEnabled(HWND hWnd, UINT id)
}
break;
case CMD_NEW_VLAN:
- if (cm->Client->Unix == false && cm->Client->Win9x == false)
+ if (cm->Client->Unix == false && cm->server_name != NULL)
{
- if (cm->server_name != NULL)
- {
- return false;
- }
- }
- if (cm->Client->Win9x)
- {
- if (LvNum(hWnd, L_VLAN) >= 1)
- {
- // You can not install two or more virtual LAN cards in Win9x
- return false;
- }
+ return false;
}
+
break;
case CMD_PROPERTY:
name = LvGetSelectedStr(hWnd, L_ACCOUNT, 0);
@@ -10286,10 +10145,6 @@ bool CmIsEnabled(HWND hWnd, UINT id)
}
return LvIsSelected(hWnd, L_VLAN);
case CMD_ENABLE_VLAN:
- if (cm->Client->Win9x)
- {
- return false;
- }
if (LvIsMultiMasked(hWnd, L_VLAN))
{
return false;
@@ -10315,10 +10170,6 @@ bool CmIsEnabled(HWND hWnd, UINT id)
}
break;
case CMD_DISABLE_VLAN:
- if (cm->Client->Win9x)
- {
- return false;
- }
if (LvIsMultiMasked(hWnd, L_VLAN))
{
return false;
@@ -10348,7 +10199,7 @@ bool CmIsEnabled(HWND hWnd, UINT id)
{
return false;
}
- if (cm->Client->Win9x || cm->Client->Unix)
+ if (cm->Client->Unix)
{
// Upgrading the virtual LAN card on a UNIX system or Win9x is unavailable
return false;
@@ -10359,24 +10210,7 @@ bool CmIsEnabled(HWND hWnd, UINT id)
}
return LvIsSelected(hWnd, L_VLAN);
case CMD_WINNET:
- {
- UINT os_type = GetOsInfo()->OsType;
-
- if (OS_IS_WINDOWS_NT(os_type) && GET_KETA(os_type, 100) >= 2)
- {
- if (cm->server_name != NULL)
- {
- return false;
- }
-
- return true;
- }
- else
- {
- return false;
- }
- }
- break;
+ return (cm->server_name == NULL);
case CMD_EXIT:
return cm->TrayInited;
}
@@ -11264,7 +11098,7 @@ void CmMainWindowOnInit(HWND hWnd)
}
else
{
- cm->VistaStyle = MsIsVista();
+ cm->VistaStyle = true;
}
if (MsRegIsValue(REG_CURRENT_USER, CM_REG_KEY, "ShowPort"))
@@ -12068,10 +11902,6 @@ RETRY:
{
cm->CmSettingSupported = true;
cm->CmEasyModeSupported = true;
- if (OS_IS_WINDOWS_9X(a.OsType))
- {
- cm->CmEasyModeSupported = false;
- }
}
return true;
diff --git a/src/Cedar/CM.h b/src/Cedar/CM.h
index f4124f30..c6b12078 100644
--- a/src/Cedar/CM.h
+++ b/src/Cedar/CM.h
@@ -5,8 +5,14 @@
// CM.h
// Header of CM.c
-#ifndef CM_H
-#define CM_H
+#ifdef OS_WIN32
+
+#ifndef CM_H
+#define CM_H
+
+#include "GlobalConst.h"
+
+#include "Mayaqua/MayaType.h"
// Constants
#define CM_REG_KEY "Software\\" GC_REG_COMPANY_NAME "\\" CEDAR_PRODUCT_STR " VPN\\Client Manager"
@@ -47,6 +53,6 @@ void CmStopUacHelper(void *p);
void *CmExecUiHelperMain();
UINT CmGetSecureBitmapId(char *dest_hostname);
-#endif // CM_H
-
+#endif // CM_H
+#endif // OS_WIN32
diff --git a/src/Cedar/CMInner.h b/src/Cedar/CMInner.h
index 90fec6d5..72ad0768 100644
--- a/src/Cedar/CMInner.h
+++ b/src/Cedar/CMInner.h
@@ -5,10 +5,21 @@
// CMInner.h
// Internal header for the CM.c
+#include "Client.h"
+#include "CM.h"
+#include "Command.h"
+#include "WinUi.h"
+
+#include "Mayaqua/Table.h"
+
+#include
+
#define STARTUP_MUTEX_NAME GC_SW_SOFTETHER_PREFIX "vpncmgr_startup_mutex"
#define NAME_OF_VPN_CLIENT_MANAGER "vpncmgr"
+typedef struct LVB LVB;
+
void CmVoice(char *name);
typedef struct CM_UAC_HELPER
@@ -379,7 +390,7 @@ void CmPolicyDlg(HWND hWnd, CM_STATUS *st);
UINT CmPolicyDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);
void CmPolicyDlgPrint(HWND hWnd, CM_POLICY *p);
void CmPolicyDlgPrintEx(HWND hWnd, CM_POLICY *p, bool cascade_mode);
-void CmPolicyDlgPrintEx2(HWND hWnd, CM_POLICY *p, bool cascade_mode, bool ver);
+void CmPolicyDlgPrintEx2(HWND hWnd, CM_POLICY *p, bool cascade_mode, UINT ver);
void CmNewAccount(HWND hWnd);
void CmEditAccount(HWND hWnd, wchar_t *account_name);
void CmGenerateNewAccountName(HWND hWnd, wchar_t *name, UINT size);
diff --git a/src/Cedar/CMakeLists.txt b/src/Cedar/CMakeLists.txt
index 4eefc034..2e5c99f9 100644
--- a/src/Cedar/CMakeLists.txt
+++ b/src/Cedar/CMakeLists.txt
@@ -19,6 +19,29 @@ set_target_properties(cedar
RUNTIME_OUTPUT_DIRECTORY "${BUILD_DIRECTORY}"
)
+cmake_host_system_information(RESULT HAS_SSE2 QUERY HAS_SSE2)
+
+set(BLAKE2_SRC_PATH $,${TOP_DIRECTORY}/3rdparty/BLAKE2/sse,${TOP_DIRECTORY}/3rdparty/BLAKE2/ref>)
+set(BLAKE2_SRC $,${BLAKE2_SRC_PATH}/blake2s.c,${BLAKE2_SRC_PATH}/blake2s-ref.c>)
+
+target_include_directories(cedar PUBLIC ${BLAKE2_SRC_PATH})
+target_sources(cedar PRIVATE ${BLAKE2_SRC})
+
+if(VCPKG_TARGET_TRIPLET)
+ find_package(unofficial-sodium CONFIG REQUIRED)
+ target_link_libraries(cedar PUBLIC unofficial-sodium::sodium)
+else()
+ find_package(PkgConfig REQUIRED)
+ pkg_search_module(SODIUM libsodium REQUIRED)
+ target_include_directories(cedar PUBLIC ${SODIUM_INCLUDE_DIRS})
+ if(NOT ("$ENV{TRAVIS_CPU_ARCH}" STREQUAL ppc64le))
+ target_link_libraries(cedar PUBLIC $,${SODIUM_LINK_LIBRARIES},${SODIUM_LIBRARIES}>)
+ else()
+ # TODO: investigate why on ppc64le the use of SODIUM_LINK_LIBRARIES causes undefined references to libsodium functions.
+ target_link_libraries(cedar PUBLIC ${SODIUM_LIBRARIES})
+ endif()
+endif()
+
if(WIN32)
set_target_properties(cedar
PROPERTIES
@@ -31,10 +54,10 @@ if(WIN32)
endif()
if(UNIX)
- find_library(LIB_READLINE readline)
find_package(Curses REQUIRED)
+ find_library(LIB_READLINE readline)
- target_link_libraries(cedar PRIVATE ${LIB_READLINE} ${CURSES_LIBRARIES})
+ target_link_libraries(cedar PRIVATE ${CURSES_LIBRARIES} ${LIB_READLINE})
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
target_link_libraries(cedar PRIVATE mayaqua pcap)
diff --git a/src/Cedar/Cedar.c b/src/Cedar/Cedar.c
index a1d23ecd..b12fb3ba 100644
--- a/src/Cedar/Cedar.c
+++ b/src/Cedar/Cedar.c
@@ -5,8 +5,35 @@
// Cedar.c
// Cedar Communication Module
+#include "Cedar.h"
-#include "CedarPch.h"
+#include "Admin.h"
+#include "Bridge.h"
+#include "Connection.h"
+#include "Layer3.h"
+#include "Link.h"
+#include "Listener.h"
+#include "Protocol.h"
+#include "Sam.h"
+#include "Server.h"
+#include "Session.h"
+#include "VLanWin32.h"
+#include "WebUI.h"
+
+#include "Mayaqua/Cfg.h"
+#include "Mayaqua/Encrypt.h"
+#include "Mayaqua/FileIO.h"
+#include "Mayaqua/HTTP.h"
+#include "Mayaqua/Mayaqua.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Microsoft.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Table.h"
+#include "Mayaqua/Tick64.h"
+#include "Mayaqua/Win32.h"
+
+#include
static UINT init_cedar_counter = 0;
static REF *cedar_log_ref = NULL;
@@ -1094,12 +1121,13 @@ void CleanupCedar(CEDAR *c)
WuFreeWebUI(c->WebUI);
FreeCedarLayer3(c);
-/*
- for (i = 0;i < LIST_NUM(c->HubList);i++)
+ for (i = 0; i < LIST_NUM(c->WgkList); ++i)
{
- HUB *h = LIST_DATA(c->HubList, i);
+ WGK *wgk = LIST_DATA(c->WgkList, i);
+ Free(wgk);
}
-*/
+ ReleaseList(c->WgkList);
+
for (i = 0;i < LIST_NUM(c->CaList);i++)
{
X *x = LIST_DATA(c->CaList, i);
@@ -1491,6 +1519,7 @@ CEDAR *NewCedar(X *server_x, K *server_k)
c->Traffic = NewTraffic();
c->TrafficLock = NewLock();
c->CaList = NewList(CompareCert);
+ c->WgkList = NewList(CompareWgk);
c->TrafficDiffList = NewList(NULL);
@@ -1600,6 +1629,12 @@ void InitCedar()
return;
}
+ if (sodium_init() == -1)
+ {
+ Debug("InitCedar(): sodium_init() failed!\n");
+ return;
+ }
+
// Initialize protocol module
InitProtocol();
}
diff --git a/src/Cedar/Cedar.h b/src/Cedar/Cedar.h
index 6d2f6b23..88440c09 100644
--- a/src/Cedar/Cedar.h
+++ b/src/Cedar/Cedar.h
@@ -8,6 +8,10 @@
#ifndef CEDAR_H
#define CEDAR_H
+#include "CedarType.h"
+#include "GlobalConst.h"
+
+#include "Mayaqua/Network.h"
//////////////////////////////////////////////////////////////////////
//
@@ -24,10 +28,6 @@
#endif // VPN_SPEED
-#define bool UINT
-#define BOOL UINT
-
-
// Version number
#ifndef CEDAR_VERSION_MAJOR
#define CEDAR_VERSION_MAJOR 0
@@ -122,7 +122,6 @@
#define MAX_SESSION_NAME_LEN 255 // Session name maximum length
#define MAX_CONNECTION_NAME_LEN 255 // Maximum length of connection name
#define MAX_DEVICE_NAME_LEN 31 // Device name maximum length
-#define MAX_DEVICE_NAME_LEN_9X 4 // Maximum length of Virtual LAN card name in Win9x
#define MAX_ACCESSLIST_NOTE_LEN 255 // Maximum length of the note of access list entry
#define MAX_SECURE_DEVICE_FILE_LEN 255 // Secure device file name maximum length
#define MAX_ADMIN_OPTION_NAME_LEN 63 // Management option name
@@ -367,6 +366,7 @@
#define AUTHTYPE_ROOTCERT 3 // Root certificate which is issued by trusted Certificate Authority
#define AUTHTYPE_RADIUS 4 // Radius authentication
#define AUTHTYPE_NT 5 // Windows NT authentication
+#define AUTHTYPE_WIREGUARD_KEY 97 // WireGuard public key authentication
#define AUTHTYPE_OPENVPN_CERT 98 // TLS client certificate authentication
#define AUTHTYPE_TICKET 99 // Ticket authentication
@@ -892,11 +892,11 @@ typedef struct TRAFFIC_ENTRY
} TRAFFIC_ENTRY;
// Traffic data
-typedef struct TRAFFIC
+struct TRAFFIC
{
TRAFFIC_ENTRY Send; // Transmitted data
TRAFFIC_ENTRY Recv; // Received data
-} TRAFFIC;
+};
// Non-SSL connection source
typedef struct NON_SSL
@@ -915,7 +915,7 @@ typedef struct TINY_LOG
} TINY_LOG;
// CEDAR structure
-typedef struct CEDAR
+struct CEDAR
{
LOCK *lock; // Lock
REF *ref; // Reference counter
@@ -923,6 +923,7 @@ typedef struct CEDAR
UINT Type; // Type
LIST *ListenerList; // Listener list
LIST *HubList; // HUB list
+ LIST *WgkList; // WireGuard key list
LIST *ConnectionList; // Negotiating connection list
LIST *CaList; // List of CA
volatile bool Halt; // Halt flag
@@ -982,7 +983,7 @@ typedef struct CEDAR
UINT FifoBudget; // Fifo budget
SSL_ACCEPT_SETTINGS SslAcceptSettings; // SSL Accept Settings
UINT DhParamBits; // Bits of Diffie-Hellman parameters
-} CEDAR;
+};
// Type of CEDAR
#define CEDAR_CLIENT 0 // Client
@@ -990,131 +991,6 @@ typedef struct CEDAR
#define CEDAR_FARM_CONTROLLER 2 // Server farm controller
#define CEDAR_FARM_MEMBER 3 // Server farm member
-
-////////////////////////////
-// Read the header file
-
-// Type
-#include
-// Account Manager
-#include
-// Listener module
-#include
-// Log storage module
-#include
-// Connection management
-#include
-// Session Management
-#include
-// RPC
-#include
-// HUB management
-#include
-// Security Accounts Manager
-#include
-// Radius authentication module
-#include
-// Native protocol
-#include
-// Inter-HUB link
-#include
-// User-mode virtual host
-#include
-// SecureNAT
-#include
-// Digital watermark
-#include
-// Secure data
-#include
-// Console service
-#include
-// Vpncmd utility
-#include
-// RPC over HTTP
-#include
-// Layer-2/Layer-3 converter
-#include
-// Third party protocols
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-// UDP Acceleration
-#include
-// DDNS Client
-#include
-// VPN Azure Client
-#include
-// VPN Azure Server
-#include
-// Native IP Stack
-#include
-
-#ifdef OS_WIN32
-// Neo device driver
-#include
-// SeLow User-mode
-#include
-#endif // OS_WIN32
-
-// Neo device driver manipulation library
-#include
-// Bridge
-#include
-// Layer-3 switch
-#include
-// Virtual LAN card for test
-#include
-// Client
-#include
-// Server
-#include
-// License database
-#include
-// EtherLogger
-#include
-// Management RPC
-#include
-// User-mode Router
-#include
-
-// Web UI
-#include
-
-// VPN Gate Main Implementation
-#include
-
-
-#ifdef OS_WIN32
-
-// Win32 user interface
-#include
-// Win32 Client Connection Manager
-#include
-// Win32 Server Manager
-#include
-// Win32 User-mode Router Manager
-#include
-// Win32 EtherLogger Manager
-#include
-// Win32 Network Utility
-#include
-// Win32 Setup Wizard
-#include
-// Win32 COM calling module
-#include
-
-#endif
-
-
-
-
////////////////////////////
// Function prototype
diff --git a/src/Cedar/CedarPch.c b/src/Cedar/CedarPch.c
deleted file mode 100644
index 722c7afa..00000000
--- a/src/Cedar/CedarPch.c
+++ /dev/null
@@ -1,9 +0,0 @@
-// SoftEther VPN Source Code - Developer Edition Master Branch
-// Cedar Communication Module
-
-
-// CedarPch.c
-// Cedar Pre-compile Header Generating Code
-
-#include "CedarPch.h"
-
diff --git a/src/Cedar/CedarPch.h b/src/Cedar/CedarPch.h
deleted file mode 100644
index a3eac0f6..00000000
--- a/src/Cedar/CedarPch.h
+++ /dev/null
@@ -1,20 +0,0 @@
-// SoftEther VPN Source Code - Developer Edition Master Branch
-// Cedar Communication Module
-
-
-// CedarPch.h
-// Header file for grecompile header generation for Cedar
-
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-#include
-
diff --git a/src/Cedar/CedarType.h b/src/Cedar/CedarType.h
index 74fa5798..b95dd9a1 100644
--- a/src/Cedar/CedarType.h
+++ b/src/Cedar/CedarType.h
@@ -8,6 +8,9 @@
#ifndef CEDARTYPE_H
#define CEDARTYPE_H
+typedef struct CEDAR CEDAR;
+typedef struct TRAFFIC TRAFFIC;
+
// ==============================================================
// Remote Procedure Call
@@ -277,6 +280,7 @@ typedef struct HUB_SNAPSHOT HUB_SNAPSHOT;
typedef struct SERVER_SNAPSHOT SERVER_SNAPSHOT;
typedef struct SERVER_HUB_CREATE_HISTORY SERVER_HUB_CREATE_HISTORY;
typedef struct OPENVPN_SSTP_CONFIG OPENVPN_SSTP_CONFIG;
+typedef struct WGK WGK;
// ==============================================================
// Server Admin Tool
@@ -299,6 +303,7 @@ typedef struct RPC_ENUM_FARM_ITEM RPC_ENUM_FARM_ITEM;
typedef struct RPC_ENUM_FARM RPC_ENUM_FARM;
typedef struct RPC_FARM_CONNECTION_STATUS RPC_FARM_CONNECTION_STATUS;
typedef struct RPC_KEY_PAIR RPC_KEY_PAIR;
+typedef struct RPC_WGK RPC_WGK;
typedef struct RPC_HUB_OPTION RPC_HUB_OPTION;
typedef struct RPC_RADIUS RPC_RADIUS;
typedef struct RPC_HUB RPC_HUB;
@@ -469,6 +474,13 @@ typedef struct WIDE_MACHINE_ID WIDE_MACHINE_ID;
typedef struct TRIAL_INFO TRIAL_INFO;
+// ==============================================================
+// Proto
+// ==============================================================
+
+typedef struct PROTO_OPTION PROTO_OPTION;
+
+
// ==============================================================
// IPsec
// ==============================================================
diff --git a/src/Cedar/Client.c b/src/Cedar/Client.c
index 3acf9423..1ce3fe83 100644
--- a/src/Cedar/Client.c
+++ b/src/Cedar/Client.c
@@ -5,7 +5,43 @@
// Client.c
// Client Manager
-#include "CedarPch.h"
+#include "Client.h"
+
+#include "Account.h"
+#include "Admin.h"
+#include "Cedar.h"
+#include "CM.h"
+#include "Connection.h"
+#include "IPC.h"
+#include "Listener.h"
+#include "Logging.h"
+#include "Protocol.h"
+#include "Remote.h"
+#include "Virtual.h"
+#include "VLanUnix.h"
+#include "VLanWin32.h"
+#include "Win32Com.h"
+#include "WinUi.h"
+
+#include "Mayaqua/Cfg.h"
+#include "Mayaqua/Encrypt.h"
+#include "Mayaqua/FileIO.h"
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Kernel.h"
+#include "Mayaqua/MayaType.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Microsoft.h"
+#include "Mayaqua/Network.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/OS.h"
+#include "Mayaqua/Pack.h"
+#include "Mayaqua/Secure.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Table.h"
+#include "Mayaqua/Tick64.h"
+#include "Mayaqua/Win32.h"
+
+#include
static CLIENT *client = NULL;
static LISTENER *cn_listener = NULL;
@@ -1108,11 +1144,7 @@ void Win32CnNicInfoThreadProc(THREAD *thread, void *param)
return;
}
- if (MsIsNt())
- {
- // Do not show a dialog on Windows 9x system
- NicInfo(info);
- }
+ NicInfo(info);
Disconnect(info->Sock);
}
@@ -1370,10 +1402,7 @@ void Win32CnExecDriverInstaller(SOCK *s, PACK *p)
return;
}
- if (MsIsVista())
- {
- helper = CmStartUacHelper();
- }
+ helper = CmStartUacHelper();
ret = MsExecDriverInstaller(arg);
@@ -1506,7 +1535,7 @@ void CnListenerProc(THREAD *thread, void *param)
AddRef(s->ref);
NoticeThreadInit(thread);
- if (s->LocalIP.addr[0] == 127)
+ if (IsLocalHostIP(&s->LocalIP))
{
p = RecvPack(s);
@@ -5081,7 +5110,7 @@ void CiRpcAccepted(CLIENT *c, SOCK *s)
retcode = 1;
}
- if (c->PasswordRemoteOnly && s->RemoteIP.addr[0] == 127)
+ if (c->PasswordRemoteOnly && IsLocalHostIP(&s->RemoteIP))
{
// If in a mode that requires a password only remote,
// the password sent from localhost is considered to be always correct
@@ -5094,7 +5123,7 @@ void CiRpcAccepted(CLIENT *c, SOCK *s)
{
// If the remote control is prohibited,
// identify whether this connection is from remote
- if (s->RemoteIP.addr[0] != 127)
+ if (IsLocalHostIP(&s->RemoteIP) == false)
{
retcode = 2;
}
@@ -5725,7 +5754,6 @@ L_TRY:
CcGetClientVersion(ret, &t);
ret->OsType = t.OsType;
ret->Unix = OS_IS_UNIX(ret->OsType);
- ret->Win9x = OS_IS_WINDOWS_9X(ret->OsType);
ret->IsVgcSupported = t.IsVgcSupported;
ret->ShowVgcLink = t.ShowVgcLink;
StrCpy(ret->ClientId, sizeof(ret->ClientId), t.ClientId);
@@ -6282,17 +6310,12 @@ bool CtConnect(CLIENT *c, RPC_CLIENT_CONNECT *connect)
{
if (t.NumItem == 0)
{
- // There are no virtual LAN cards in the system
- if (OS_IS_WINDOWS_NT(GetOsInfo()->OsType) || OS_IS_UNIX(GetOsInfo()->OsType))
- {
- // Only in Linux system or Windows NT system,
- // create a new virtual LAN card which named as "VPN" automatically
+ // Create a new virtual LAN card named "VPN" automatically
RPC_CLIENT_CREATE_VLAN t;
Zero(&t, sizeof(t));
StrCpy(t.DeviceName, sizeof(t.DeviceName), "VPN");
CtCreateVLan(c, &t);
- }
}
CiFreeClientEnumVLan(&t);
@@ -7641,13 +7664,6 @@ bool CtDeleteVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *d)
#else // OS_WIN32
- if (MsIsNt() == false)
- {
- // Not available in Win9x
- CiSetError(c, ERR_NOT_SUPPORTED);
- return false;
- }
-
// Check whether the virtual LAN card are present
if (MsIsVLanExists(VLAN_ADAPTER_NAME_TAG, d->DeviceName) == false &&
MsIsVLanExists(VLAN_ADAPTER_NAME_TAG_OLD, d->DeviceName) == false)
@@ -8021,8 +8037,7 @@ bool CtUpgradeVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *create)
{
bool use_old_name = false;
-#ifdef OS_WIN32
- KAKUSHI *k = NULL;
+#ifdef OS_WIN32
MS_DRIVER_VER ver;
#endif // OS_WIN32
@@ -8042,13 +8057,6 @@ bool CtUpgradeVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *create)
CiInitDriverVerStruct(&ver);
- if (MsIsNt() == false)
- {
- // Not available in Win9x
- CiSetError(c, ERR_NOT_SUPPORTED);
- return false;
- }
-
// Check whether the LAN card with the specified name already exists
if (MsIsVLanExists(VLAN_ADAPTER_NAME_TAG, create->DeviceName) == false &&
MsIsVLanExists(VLAN_ADAPTER_NAME_TAG_OLD, create->DeviceName) == false)
@@ -8065,47 +8073,19 @@ bool CtUpgradeVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *create)
use_old_name = true;
}
- if (MsIsVista() == false)
+ // Perform the installation
+ char tmp[MAX_SIZE];
+ Format(tmp, sizeof(tmp), "upgradevlan %s", create->DeviceName);
+
+ if (CncExecDriverInstaller(tmp) == false)
{
- k = InitKakushi();
+ // Installation Failed
+ CiSetError(c, ERR_VLAN_INSTALL_ERROR);
+ CiNotify(c);
+ CiSendGlobalPulse(c);
+ return false;
}
-
- if (MsIsVista() == false)
- {
- // Perform the installation (other than Windows Vista)
- if (MsUpgradeVLan(use_old_name ? VLAN_ADAPTER_NAME_TAG_OLD : VLAN_ADAPTER_NAME_TAG,
- use_old_name ? VLAN_CONNECTION_NAME_OLD : VLAN_CONNECTION_NAME,
- create->DeviceName, &ver) == false)
- {
- // Installation Failed
- FreeKakushi(k);
- CiSetError(c, ERR_VLAN_INSTALL_ERROR);
- CiNotify(c);
- CiSendGlobalPulse(c);
- return false;
- }
- }
- else
- {
- // Perform the installation (Windows Vista)
- char tmp[MAX_SIZE];
-
- Format(tmp, sizeof(tmp), "upgradevlan %s", create->DeviceName);
-
- if (CncExecDriverInstaller(tmp) == false)
- {
- // Installation Failed
- FreeKakushi(k);
- CiSetError(c, ERR_VLAN_INSTALL_ERROR);
- CiNotify(c);
- CiSendGlobalPulse(c);
- return false;
- }
- }
-
- FreeKakushi(k);
-
CLog(c, "LC_UPDATE_VLAN", create->DeviceName);
CiNotify(c);
@@ -8122,10 +8102,6 @@ bool CtCreateVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *create)
TOKEN_LIST *t;
UINT max_len;
-#ifdef OS_WIN32
- KAKUSHI *k = NULL;
-#endif // OS_WIN32
-
// Validate arguments
if (c == NULL || create == NULL)
{
@@ -8206,25 +8182,6 @@ bool CtCreateVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *create)
return true;
#else // OS_WIN32
-
- if (OS_IS_WINDOWS_9X(GetOsInfo()->OsType))
- {
- // Only one LAN card is available in the Win9x
- TOKEN_LIST *t;
-
- t = MsEnumNetworkAdapters(VLAN_ADAPTER_NAME, VLAN_ADAPTER_NAME_OLD);
- if (t != NULL)
- {
- if (t->NumTokens >= 1)
- {
- FreeToken(t);
- CiSetError(c, ERR_NOT_SUPPORTED);
- return false;
- }
- FreeToken(t);
- }
- }
-
// Check whether the specified name is valid or not
if (IsSafeStr(create->DeviceName) == false)
{
@@ -8233,7 +8190,7 @@ bool CtCreateVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *create)
return false;
}
- max_len = MsIsNt() ? MAX_DEVICE_NAME_LEN : MAX_DEVICE_NAME_LEN_9X;
+ max_len = MAX_DEVICE_NAME_LEN;
if (StrLen(create->DeviceName) > max_len)
{
// Name is too long
@@ -8261,51 +8218,18 @@ bool CtCreateVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *create)
return false;
}
- if (MsIsNt())
+ // Perform the installation (Windows Vista)
+ char tmp[MAX_SIZE];
+ Format(tmp, sizeof(tmp), "instvlan %s", create->DeviceName);
+
+ if (CncExecDriverInstaller(tmp) == false)
{
- if (MsIsVista() == false)
- {
- k = InitKakushi();
- }
+ CiSetError(c, ERR_VLAN_INSTALL_ERROR);
+ CiNotify(c);
+ CiSendGlobalPulse(c);
+ return false;
}
- if (MsIsVista() == false)
- {
- MS_DRIVER_VER ver;
-
- CiInitDriverVerStruct(&ver);
-
- // Perform the installation (other than Windows Vista)
- if (MsInstallVLan(VLAN_ADAPTER_NAME_TAG, VLAN_CONNECTION_NAME, create->DeviceName, &ver) == false)
- {
- // Installation Failed
- FreeKakushi(k);
- CiSetError(c, ERR_VLAN_INSTALL_ERROR);
- CiNotify(c);
- CiSendGlobalPulse(c);
- return false;
- }
- }
- else
- {
- // Perform the installation (Windows Vista)
- char tmp[MAX_SIZE];
-
- Format(tmp, sizeof(tmp), "instvlan %s", create->DeviceName);
-
- if (CncExecDriverInstaller(tmp) == false)
- {
- // Installation Failed
- FreeKakushi(k);
- CiSetError(c, ERR_VLAN_INSTALL_ERROR);
- CiNotify(c);
- CiSendGlobalPulse(c);
- return false;
- }
- }
-
- FreeKakushi(k);
-
t = MsEnumNetworkAdapters(VLAN_ADAPTER_NAME, VLAN_ADAPTER_NAME_OLD);
if (t->NumTokens == 1)
{
@@ -8340,17 +8264,6 @@ bool CtCreateVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *create)
CiSaveConfigurationFile(c);
- if (MsIsNt() == false)
- {
- if (GetOsInfo()->OsType == OSTYPE_WINDOWS_ME)
- {
- // Show the warning in the case of Windows Me
- MsgBox(NULL, 0x00000040L, _UU("CM_9X_VLAN_ME_MESSAGE"));
- }
-
- ReleaseThread(NewThread(Win9xRebootThread, NULL));
- }
-
return true;
#endif // OS_WIN32
@@ -9741,12 +9654,7 @@ bool CiReadSettingFromCfg(CLIENT *c, FOLDER *root)
UINT ostype = GetOsInfo()->OsType;
// CM_SETTING
CM_SETTING *s = c->CmSetting;
-
- if (OS_IS_UNIX(ostype) || OS_IS_WINDOWS_NT(ostype))
- {
- s->EasyMode = CfgGetBool(cmsetting, "EasyMode");
- }
-
+ s->EasyMode = CfgGetBool(cmsetting, "EasyMode");
s->LockMode = CfgGetBool(cmsetting, "LockMode");
CfgGetByte(cmsetting, "HashedPassword", s->HashedPassword, sizeof(s->HashedPassword));
}
@@ -10432,16 +10340,6 @@ CLIENT *CiNewClient()
// Raise the priority
OSSetHighPriority();
-
-
-#ifdef OS_WIN32
- // For Win9x, release the DHCP address of all the virtual LAN card
- if (MsIsNt() == false)
- {
- Win32ReleaseAllDhcp9x(true);
- }
-#endif // OS_WIN32
-
CiChangeAllVLanMacAddressIfMachineChanged(c);
CiChangeAllVLanMacAddressIfCleared(c);
@@ -10564,14 +10462,6 @@ void CiCleanupClient(CLIENT *c)
Free(c);
-#ifdef OS_WIN32
- // For Win9x, release the DHCP address of all the virtual LAN card
- if (MsIsNt() == false)
- {
- Win32ReleaseAllDhcp9x(true);
- }
-#endif // OS_WIN32
-
StopCedarLog();
if (ci_active_sessions_lock != NULL)
@@ -10632,9 +10522,6 @@ void CtStartClient()
return;
}
- // OS check
- CiCheckOs();
-
#ifdef OS_WIN32
RegistWindowsFirewallAll();
#endif
@@ -10754,27 +10641,6 @@ void CtStopClient()
client = NULL;
}
-// OS check
-void CiCheckOs()
-{
- // Get the OS type
- OS_INFO *info = GetOsInfo();
-
- if (OS_IS_WINDOWS(info->OsType))
- {
- bool ok = IS_CLIENT_SUPPORTED_OS(info->OsType);
-
- if (ok == false)
- {
- Alert(
- CEDAR_PRODUCT_STR " VPN Client doesn't support this Windows Operating System.\n"
- CEDAR_PRODUCT_STR " VPN Client requires Windows 98, Windows Me, Windows 2000, Windows XP, Windows Server 2003 or Greater.\n\n"
- "Please contact your system administrator.", CEDAR_PRODUCT_STR " VPN Client");
- exit(0);
- }
- }
-}
-
// Client status indicator
void CiClientStatusPrinter(SESSION *s, wchar_t *status)
{
diff --git a/src/Cedar/Client.h b/src/Cedar/Client.h
index 96b5fe07..b7198ac5 100644
--- a/src/Cedar/Client.h
+++ b/src/Cedar/Client.h
@@ -8,16 +8,14 @@
#ifndef CLIENT_H
#define CLIENT_H
+#include "Account.h"
+#include "Session.h"
+#include "Wpc.h"
+
#define CLIENT_CONFIG_PORT GC_CLIENT_CONFIG_PORT // Client port number
#define CLIENT_NOTIFY_PORT GC_CLIENT_NOTIFY_PORT // Client notification port number
#define CLIENT_WAIT_CN_READY_TIMEOUT (10 * 1000) // Standby time to start the client notification service
-
-// Check whether the client can run on the specified OS_TYPE
-#define IS_CLIENT_SUPPORTED_OS(t) \
- ((OS_IS_WINDOWS_NT(t) && GET_KETA(t, 100) >= 2) || (OS_IS_WINDOWS_9X(t)))
-
-
// Constants
#define CLIENT_CONFIG_FILE_NAME "$vpn_client.config"
#define CLIENT_DEFAULT_KEEPALIVE_HOST "keepalive.softether.org"
@@ -420,7 +418,6 @@ struct REMOTE_CLIENT
RPC *Rpc;
UINT OsType;
bool Unix;
- bool Win9x;
UINT ProcessId;
UINT ClientBuildInt;
bool IsVgcSupported;
@@ -643,7 +640,6 @@ void CiFreeGetCa(RPC_GET_CA *a);
void CiFreeGetIssuer(RPC_GET_ISSUER *a);
void CiFreeClientEnumAccount(RPC_CLIENT_ENUM_ACCOUNT *a);
void CiSetError(CLIENT *c, UINT err);
-void CiCheckOs();
CLIENT *CiNewClient();
void CiCleanupClient(CLIENT *c);
bool CiLoadConfigurationFile(CLIENT *c);
@@ -750,11 +746,9 @@ void OutRpcTrafficEx(TRAFFIC *t, PACK *p, UINT i, UINT num);
void OutRpcCmSetting(PACK *p, CM_SETTING *c);
void InRpcCmSetting(CM_SETTING *c, PACK *p);
-
-#ifdef OS_WIN32
+#ifdef OS_WIN32
+typedef struct MS_DRIVER_VER MS_DRIVER_VER;
void CiInitDriverVerStruct(MS_DRIVER_VER *ver);
#endif // OS_EIN32
#endif // CLIENT_H
-
-
diff --git a/src/Cedar/Command.c b/src/Cedar/Command.c
index c11455cc..a4e1c429 100644
--- a/src/Cedar/Command.c
+++ b/src/Cedar/Command.c
@@ -5,7 +5,45 @@
// Command.c
// vpncmd Command Line Management Utility
-#include "CedarPch.h"
+#include "Command.h"
+
+#include "Admin.h"
+#include "AzureClient.h"
+#include "Connection.h"
+#include "Console.h"
+#include "Database.h"
+#include "DDNS.h"
+#include "Layer3.h"
+#include "Nat.h"
+#include "Proto_IPsec.h"
+#include "Proto_WireGuard.h"
+#include "Radius.h"
+#include "Server.h"
+#include "Virtual.h"
+#include "WinUi.h"
+
+#include "Mayaqua/Cfg.h"
+#include "Mayaqua/FileIO.h"
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Kernel.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Microsoft.h"
+#include "Mayaqua/Network.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/OS.h"
+#include "Mayaqua/Pack.h"
+#include "Mayaqua/Secure.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Table.h"
+#include "Mayaqua/Tick64.h"
+#include "Mayaqua/Unix.h"
+
+#include
+
+#ifdef OS_UNIX
+#include
+#include
+#endif
// System checker definition
typedef bool (CHECKER_PROC_DEF)();
@@ -916,14 +954,7 @@ void VpnCmdInitBootPath()
{
bool b = false;
// Copy the vpncmdsys.exe to system32
- if (MsIsNt())
- {
- Format(tmp, sizeof(tmp), "%s\\vpncmd.exe", MsGetSystem32Dir());
- }
- else
- {
- Format(tmp, sizeof(tmp), "%s\\vpncmd.exe", MsGetWindowsDir());
- }
+ Format(tmp, sizeof(tmp), "%s\\vpncmd.exe", MsGetSystem32Dir());
if (MsIs64BitWindows() == false || Is64())
{
@@ -7483,6 +7514,9 @@ void PsMain(PS *ps)
{"RouterTableDel", PsRouterTableDel},
{"LogFileList", PsLogFileList},
{"LogFileGet", PsLogFileGet},
+ {"WgkAdd", PsWgkAdd},
+ {"WgkDelete", PsWgkDelete},
+ {"WgkEnum", PsWgkEnum},
{"HubCreate", PsHubCreate},
{"HubCreateDynamic", PsHubCreateDynamic},
{"HubCreateStatic", PsHubCreateStatic},
@@ -7493,6 +7527,7 @@ void PsMain(PS *ps)
{"Hub", PsHub},
{"Online", PsOnline},
{"Offline", PsOffline},
+ {"SetStaticNetwork", PsSetStaticNetwork},
{"SetMaxSession", PsSetMaxSession},
{"SetHubPassword", PsSetHubPassword},
{"SetEnumAllow", PsSetEnumAllow},
@@ -10561,6 +10596,137 @@ UINT PsLogFileGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
return ret;
}
+// Add a WireGuard key (TODO: ability add multiple keys in a single call)
+UINT PsWgkAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
+{
+ PS *ps = (PS *)param;
+ RPC_WGK t;
+ UINT ret;
+ LIST *o;
+ PARAM args[] =
+ {
+ {"[key]", CmdPrompt, _UU("CMD_WgkAdd_Prompt_[key]"), CmdEvalNotEmpty, NULL},
+ {"HUB", CmdPrompt, _UU("CMD_WgkAdd_Prompt_HUB"), NULL, NULL},
+ {"USER", CmdPrompt, _UU("CMD_WgkAdd_Prompt_USER"), NULL, NULL}
+ };
+
+ o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
+ if (o == NULL)
+ {
+ return ERR_INVALID_PARAMETER;
+ }
+
+ Zero(&t, sizeof(t));
+ t.Num = 1;
+ t.Wgks = ZeroMalloc(sizeof(WGK));
+
+ StrCpy(t.Wgks[0].Key, sizeof(t.Wgks[0].Key), GetParamStr(o, "[key]"));
+ StrCpy(t.Wgks[0].Hub, sizeof(t.Wgks[0].Hub), GetParamStr(o, "HUB"));
+ StrCpy(t.Wgks[0].User, sizeof(t.Wgks[0].User), GetParamStr(o, "USER"));
+
+ FreeParamValueList(o);
+
+ ret = ScAddWgk(ps->Rpc, &t);
+ if (ret != ERR_NO_ERROR)
+ {
+ CmdPrintError(c, ret);
+ }
+
+ FreeRpcWgk(&t);
+
+ return ret;
+}
+
+// Delete a WireGuard key (TODO: ability to delete multiple keys in a single call)
+UINT PsWgkDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
+{
+ PS *ps = (PS *)param;
+ RPC_WGK t;
+ UINT ret;
+ LIST *o;
+ PARAM args[] =
+ {
+ {"[key]", CmdPrompt, _UU("CMD_WgkDelete_Prompt_[key]"), CmdEvalNotEmpty, NULL},
+ };
+
+ o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
+ if (o == NULL)
+ {
+ return ERR_INVALID_PARAMETER;
+ }
+
+ Zero(&t, sizeof(t));
+ t.Num = 1;
+ t.Wgks = ZeroMalloc(sizeof(WGK));
+
+ StrCpy(t.Wgks[0].Key, sizeof(t.Wgks[0].Key), GetParamStr(o, "[key]"));
+
+ FreeParamValueList(o);
+
+ ret = ScDeleteWgk(ps->Rpc, &t);
+ if (ret != ERR_NO_ERROR)
+ {
+ CmdPrintError(c, ret);
+ }
+
+ FreeRpcWgk(&t);
+
+ return ret;
+}
+
+// List the WireGuard keys
+UINT PsWgkEnum(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
+{
+ UINT ret = ERR_NO_ERROR;
+ PS *ps = (PS *)param;
+ RPC_WGK t;
+ LIST *o;
+
+ o = ParseCommandList(c, cmd_name, str, NULL, 0);
+ if (o == NULL)
+ {
+ return ERR_INVALID_PARAMETER;
+ }
+
+ Zero(&t, sizeof(t));
+
+ ret = ScEnumWgk(ps->Rpc, &t);
+ if (ret == ERR_NO_ERROR)
+ {
+ UINT i;
+ CT *ct = CtNew();
+ CtInsertColumn(ct, _UU("CMD_WgkEnum_Column_Key"), false);
+ CtInsertColumn(ct, _UU("CMD_WgkEnum_Column_Hub"), false);
+ CtInsertColumn(ct, _UU("CMD_WgkEnum_Column_User"), false);
+
+ for (i = 0; i < t.Num; ++i)
+ {
+ const WGK *wgk = &t.Wgks[i];
+ wchar_t *key, *hub, *user;
+
+ key = CopyStrToUni(wgk->Key);
+ hub = CopyStrToUni(wgk->Hub);
+ user = CopyStrToUni(wgk->User);
+
+ CtInsert(ct, key, hub, user);
+
+ Free(key);
+ Free(hub);
+ Free(user);
+ }
+
+ CtFree(ct, c);
+ }
+ else
+ {
+ CmdPrintError(c, ret);
+ }
+
+ FreeRpcWgk(&t);
+
+ return ret;
+}
+
// Create a New Virtual HUB
UINT PsHubCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
{
@@ -11143,6 +11309,53 @@ UINT PsOffline(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
return 0;
}
+// Set the static IPv4 network parameters for the Virtual HUB
+UINT PsSetStaticNetwork(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
+{
+ LIST *o;
+ PS *ps = (PS *)param;
+ UINT ret = 0;
+ RPC_CREATE_HUB t;
+ PARAM args[] =
+ {
+ {"GATEWAY", CmdPrompt, _UU("CMD_SetStaticNetwork_Prompt_GATEWAY"), CmdEvalIp, NULL},
+ {"SUBNET", CmdPrompt, _UU("CMD_SetStaticNetwork_Prompt_SUBNET"), CmdEvalIp, NULL}
+ };
+
+ if (ps->HubName == NULL)
+ {
+ c->Write(c, _UU("CMD_Hub_Not_Selected"));
+ return ERR_INVALID_PARAMETER;
+ }
+
+ o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
+ if (o == NULL)
+ {
+ return ERR_INVALID_PARAMETER;
+ }
+
+ Zero(&t, sizeof(t));
+ StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
+ ret = ScGetHub(ps->Rpc, &t);
+ if (ret != ERR_NO_ERROR)
+ {
+ goto FINAL;
+ }
+
+ t.HubOption.DefaultGateway = StrToIP32(GetParamStr(o, "GATEWAY"));
+ t.HubOption.DefaultSubnet = StrToIP32(GetParamStr(o, "SUBNET"));
+
+ ret = ScSetHub(ps->Rpc, &t);
+FINAL:
+ if (ret != ERR_NO_ERROR)
+ {
+ CmdPrintError(c, ret);
+ }
+
+ FreeParamValueList(o);
+ return ret;
+}
+
// Set the maximum number of concurrent connecting sessions of the Virtual HUB
UINT PsSetMaxSession(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
{
@@ -11420,6 +11633,12 @@ UINT PsOptionsGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
CtInsert(ct, _UU("CMD_OptionsGet_TYPE"), GetHubTypeStr(t.HubType));
+ IPToUniStr32(tmp, sizeof(tmp), t.HubOption.DefaultGateway);
+ CtInsert(ct, _UU("CMD_OptionsGet_GATEWAY"), tmp);
+
+ IPToUniStr32(tmp, sizeof(tmp), t.HubOption.DefaultSubnet);
+ CtInsert(ct, _UU("CMD_OptionsGet_SUBNET"), tmp);
+
CtFree(ct, c);
}
@@ -23025,7 +23244,7 @@ void CtEscapeCsv(wchar_t *dst, UINT size, wchar_t *src){
UINT i;
UINT len = UniStrLen(src);
UINT idx;
- BOOL need_to_escape = false;
+ bool need_to_escape = false;
wchar_t tmp[2]=L"*";
// Check the input value
@@ -24512,19 +24731,13 @@ void Win32CmdDebug(bool is_uac)
UniPrint(_UU("CMD_DEBUG_PRINT"));
- if (MsIsWin2000OrGreater() == false)
- {
- MsgBox(NULL, 0x00000040L, _UU("CMD_DEBUG_NOT_2000"));
- goto LABEL_CLEANUP;
- }
-
- if ((MsIsVista() == false || is_uac) && MsIsAdmin() == false)
+ if (is_uac && MsIsAdmin() == false)
{
MsgBox(NULL, 0x00000040L, _UU("CMD_DEBUG_NOT_ADMIN"));
goto LABEL_CLEANUP;
}
- if (MsIsVista() && MsIsAdmin() == false)
+ if (MsIsAdmin() == false)
{
void *process_handle = NULL;
diff --git a/src/Cedar/Command.h b/src/Cedar/Command.h
index 8e0b4943..5a91c37c 100644
--- a/src/Cedar/Command.h
+++ b/src/Cedar/Command.h
@@ -8,6 +8,12 @@
#ifndef COMMAND_H
#define COMMAND_H
+#include "CedarType.h"
+
+#include "Mayaqua/Network.h"
+
+#include
+
// Constants
#define TRAFFIC_DEFAULT_PORT 9821
#define TRAFFIC_NUMTCP_MAX 32
@@ -446,6 +452,9 @@ UINT PsRouterTableAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsRouterTableDel(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsLogFileList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsLogFileGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
+UINT PsWgkAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
+UINT PsWgkDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
+UINT PsWgkEnum(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsHubCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsHubCreateDynamic(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsHubCreateStatic(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
@@ -456,6 +465,7 @@ UINT PsHubList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsHub(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsOnline(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsOffline(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
+UINT PsSetStaticNetwork(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsSetMaxSession(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsSetHubPassword(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsSetEnumAllow(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
diff --git a/src/Cedar/Connection.c b/src/Cedar/Connection.c
index 64d0e01a..700c718f 100644
--- a/src/Cedar/Connection.c
+++ b/src/Cedar/Connection.c
@@ -5,7 +5,31 @@
// Connection.c
// Connection Manager
-#include "CedarPch.h"
+#include "Connection.h"
+
+#include "BridgeUnix.h"
+#include "BridgeWin32.h"
+#include "Hub.h"
+#include "Layer3.h"
+#include "Link.h"
+#include "Listener.h"
+#include "Nat.h"
+#include "Protocol.h"
+#include "Server.h"
+#include "SecureNAT.h"
+#include "Session.h"
+#include "UdpAccel.h"
+#include "Virtual.h"
+
+#include "Mayaqua/Kernel.h"
+#include "Mayaqua/Mayaqua.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Pack.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Tick64.h"
+
+#include
// Determine whether the socket is to use to send
#define IS_SEND_TCP_SOCK(ts) \
@@ -862,8 +886,9 @@ void SendKeepAlive(CONNECTION *c, TCPSOCK *ts)
UINT size, i, num;
UINT size_be;
SESSION *s;
+ UDP_ACCEL *udp_accel;
UCHAR *buf;
- bool insert_natt_port = false;
+ bool insert_natt_port = false, insert_natt_ip = false;
// Validate arguments
if (c == NULL || ts == NULL)
{
@@ -871,33 +896,61 @@ void SendKeepAlive(CONNECTION *c, TCPSOCK *ts)
}
s = c->Session;
+ if (s == NULL)
+ {
+ return;
+ }
+
+ udp_accel = s->UdpAccel;
size = rand() % MAX_KEEPALIVE_SIZE;
num = KEEP_ALIVE_MAGIC;
- if (s != NULL && s->UseUdpAcceleration && s->UdpAccel != NULL)
+ if (s->UseUdpAcceleration && udp_accel != NULL)
{
- if (s->UdpAccel->MyPortByNatTServer != 0)
+ if (udp_accel->MyPortNatT != 0)
{
size = MAX(size, (StrLen(UDP_NAT_T_PORT_SIGNATURE_IN_KEEP_ALIVE) + sizeof(USHORT)));
insert_natt_port = true;
}
+
+ if (IsZeroIP(&udp_accel->MyIpNatT) == false)
+ {
+ size = MAX(size, (StrLen(UDP_NAT_T_IP_SIGNATURE_IN_KEEP_ALIVE) + sizeof(udp_accel->MyIpNatT.address)));
+
+ insert_natt_ip = true;
+ }
+
}
buf = MallocFast(size);
- for (i = 0;i < size;i++)
+ for (i = 0; i < size; ++i)
{
buf[i] = rand();
}
+ UCHAR *seek = buf;
+
if (insert_natt_port)
{
- USHORT myport = Endian16((USHORT)s->UdpAccel->MyPortByNatTServer);
+ const UINT nat_t_port_sig_size = StrLen(UDP_NAT_T_PORT_SIGNATURE_IN_KEEP_ALIVE);
+ const USHORT port = Endian16(udp_accel->MyPortNatT);
- Copy(buf, UDP_NAT_T_PORT_SIGNATURE_IN_KEEP_ALIVE, StrLen(UDP_NAT_T_PORT_SIGNATURE_IN_KEEP_ALIVE));
- Copy(buf + StrLen(UDP_NAT_T_PORT_SIGNATURE_IN_KEEP_ALIVE), &myport, sizeof(USHORT));
+ Copy(buf, UDP_NAT_T_PORT_SIGNATURE_IN_KEEP_ALIVE, nat_t_port_sig_size);
+ seek += nat_t_port_sig_size;
+ Copy(seek, &port, sizeof(port));
+ seek += sizeof(port);
+ }
+
+ if (insert_natt_ip)
+ {
+ const UINT nat_t_ip_sig_size = StrLen(UDP_NAT_T_IP_SIGNATURE_IN_KEEP_ALIVE);
+
+ Copy(seek, UDP_NAT_T_IP_SIGNATURE_IN_KEEP_ALIVE, nat_t_ip_sig_size);
+ seek += nat_t_ip_sig_size;
+ Copy(seek, udp_accel->MyIpNatT.address, sizeof(udp_accel->MyIpNatT.address));
}
num = Endian32(num);
@@ -979,7 +1032,7 @@ void ConnectionSend(CONNECTION *c, UINT64 now)
{
// Processing of KeepAlive
if (now >= tcpsock->NextKeepAliveTime || tcpsock->NextKeepAliveTime == 0 ||
- (s->UseUdpAcceleration && s->UdpAccel != NULL && s->UdpAccel->MyPortByNatTServerChanged))
+ (s->UseUdpAcceleration && s->UdpAccel != NULL && s->UdpAccel->MyIpOrPortNatTChanged))
{
// Send the KeepAlive
SendKeepAlive(c, tcpsock);
@@ -987,7 +1040,7 @@ void ConnectionSend(CONNECTION *c, UINT64 now)
if (s->UseUdpAcceleration && s->UdpAccel != NULL)
{
- s->UdpAccel->MyPortByNatTServerChanged = false;
+ s->UdpAccel->MyIpOrPortNatTChanged = false;
}
}
@@ -2161,28 +2214,48 @@ DISCONNECT_THIS_TCP:
ts->Mode = 0;
sz = ts->NextBlockSize;
- if (sz >= (StrLen(UDP_NAT_T_PORT_SIGNATURE_IN_KEEP_ALIVE) + sizeof(USHORT)))
+ if (s->UseUdpAcceleration && s->UdpAccel != NULL)
{
- UCHAR *keep_alive_buffer = FifoPtr(ts->RecvFifo);
+ const UCHAR *keep_alive_buffer = FifoPtr(ts->RecvFifo);
+ const UINT nat_t_ip_sig_size = StrLen(UDP_NAT_T_IP_SIGNATURE_IN_KEEP_ALIVE);
+ const UINT nat_t_port_sig_size = StrLen(UDP_NAT_T_PORT_SIGNATURE_IN_KEEP_ALIVE);
+ UINT cur_size = sz;
- if (Cmp(keep_alive_buffer, UDP_NAT_T_PORT_SIGNATURE_IN_KEEP_ALIVE, StrLen(UDP_NAT_T_PORT_SIGNATURE_IN_KEEP_ALIVE)) == 0)
+ if (cur_size >= nat_t_port_sig_size + sizeof(USHORT))
{
- USHORT us = READ_USHORT(keep_alive_buffer + StrLen(UDP_NAT_T_PORT_SIGNATURE_IN_KEEP_ALIVE));
-
- if (us != 0)
+ if (Cmp(keep_alive_buffer, UDP_NAT_T_PORT_SIGNATURE_IN_KEEP_ALIVE, nat_t_port_sig_size) == 0)
{
- if (s->UseUdpAcceleration && s->UdpAccel != NULL)
+ cur_size -= nat_t_port_sig_size;
+ keep_alive_buffer += nat_t_port_sig_size;
+
+ const USHORT port = READ_USHORT(keep_alive_buffer);
+ cur_size -= sizeof(USHORT);
+ keep_alive_buffer += sizeof(USHORT);
+
+ if (port && s->UdpAccel->YourPortNatT != port)
{
- UINT port = (UINT)us;
+ s->UdpAccel->YourPortNatT = port;
+ s->UdpAccel->YourIpOrPortNatTChanged = true;
- if (s->UdpAccel->YourPortByNatTServer != port)
- {
- s->UdpAccel->YourPortByNatTServer = port;
- s->UdpAccel->YourPortByNatTServerChanged = true;
+ Debug("ConnectionReceive(): New peer NAT-T port: %u\n", port);
+ }
+ }
+ }
- Debug("s->UdpAccel->YourPortByNatTServer: %u\n",
- s->UdpAccel->YourPortByNatTServer);
- }
+ if (cur_size >= nat_t_ip_sig_size + sizeof(s->UdpAccel->YourIpNatT.address))
+ {
+ if (Cmp(keep_alive_buffer, UDP_NAT_T_IP_SIGNATURE_IN_KEEP_ALIVE, nat_t_ip_sig_size) == 0)
+ {
+ keep_alive_buffer += nat_t_ip_sig_size;
+
+ IP ip;
+ SetIP6(&ip, keep_alive_buffer);
+ if (IsZeroIP(&ip) == false && CmpIpAddr(&s->UdpAccel->YourIpNatT, &ip) != 0)
+ {
+ Copy(&s->UdpAccel->YourIpNatT, &ip, sizeof(s->UdpAccel->YourIpNatT));
+ s->UdpAccel->YourIpOrPortNatTChanged = true;
+
+ Debug("ConnectionReceive(): New peer NAT-T IP: %r\n", &ip);
}
}
}
diff --git a/src/Cedar/Connection.h b/src/Cedar/Connection.h
index c846ddeb..8f47a71f 100644
--- a/src/Cedar/Connection.h
+++ b/src/Cedar/Connection.h
@@ -8,6 +8,11 @@
#ifndef CONNECTION_H
#define CONNECTION_H
+#include "Cedar.h"
+
+#include "Mayaqua/Encrypt.h"
+#include "Mayaqua/Proxy.h"
+
// Magic number indicating that the packet is compressed
#define CONNECTION_BULK_COMPRESS_SIGNATURE 0xDEADBEEFCAFEFACEULL
@@ -149,7 +154,7 @@ struct UDP
// Data block
struct BLOCK
{
- BOOL Compressed; // Compression flag
+ bool Compressed; // Compression flag
UINT Size; // Block size
UINT SizeofData; // Data size
UCHAR *Buf; // Buffer
diff --git a/src/Cedar/Console.c b/src/Cedar/Console.c
index 28d4bc57..45bab426 100644
--- a/src/Cedar/Console.c
+++ b/src/Cedar/Console.c
@@ -5,8 +5,32 @@
// Console.c
// Console Service
-#include "CedarPch.h"
+#include "Console.h"
+#include "Cedar.h"
+
+#include "Mayaqua/Cfg.h"
+#include "Mayaqua/FileIO.h"
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Mayaqua.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Microsoft.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Table.h"
+
+#include
+#include
+
+#ifdef OS_WIN32
+#include
+#else
+#include
+#include
+
+#include
+#include
+#endif
// Display the help for the command
void PrintCmdHelp(CONSOLE *c, char *cmd_name, TOKEN_LIST *param_list)
@@ -1911,7 +1935,7 @@ bool PasswordPrompt(char *password, UINT size)
int c;
#ifdef OS_WIN32
- c = getch();
+ c = _getch();
#else // OS_WIN32
c = getc(stdin);
#endif // OS_WIN32
@@ -1943,7 +1967,7 @@ bool PasswordPrompt(char *password, UINT size)
{
// Read one more character
#ifdef OS_WIN32
- c = getch();
+ c = _getch();
#else // OS_WIN32
c = getc(stdin);
#endif // OS_WIN32
diff --git a/src/Cedar/Console.h b/src/Cedar/Console.h
index 0e9c2b35..a4b7e9dc 100644
--- a/src/Cedar/Console.h
+++ b/src/Cedar/Console.h
@@ -8,6 +8,10 @@
#ifndef CONSOLE_H
#define CONSOLE_H
+#include "CedarType.h"
+
+#include "Mayaqua/MayaType.h"
+
// Constant
#define MAX_PROMPT_STRSIZE 65536
#define WIN32_DEFAULT_CONSOLE_WIDTH 100
diff --git a/src/Cedar/DDNS.c b/src/Cedar/DDNS.c
index 5a2fec7b..87cd49f1 100644
--- a/src/Cedar/DDNS.c
+++ b/src/Cedar/DDNS.c
@@ -5,7 +5,21 @@
// DDNS.c
// Dynamic DNS Client
-#include "CedarPch.h"
+#include "DDNS.h"
+
+#include "AzureClient.h"
+#include "Server.h"
+#include "Virtual.h"
+
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Mayaqua.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Microsoft.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Pack.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Table.h"
+#include "Mayaqua/Tick64.h"
// Get the current status of the DDNS client
void DCGetStatus(DDNS_CLIENT *c, DDNS_CLIENT_STATUS *st)
diff --git a/src/Cedar/DDNS.h b/src/Cedar/DDNS.h
index bd6a6fc1..0775766f 100644
--- a/src/Cedar/DDNS.h
+++ b/src/Cedar/DDNS.h
@@ -8,6 +8,11 @@
#ifndef DDNS_H
#define DDNS_H
+#include "CedarType.h"
+#include "Wpc.h"
+
+#include
+
// Certificate hash
#define DDNS_CERT_HASH "78BF0499A99396907C9F49DD13571C81FE26E6F5" \
"439BAFA75A6EE5671FC9F9A02D34FF29881761A0" \
diff --git a/src/Cedar/Database.c b/src/Cedar/Database.c
index 321d64b0..3f638878 100644
--- a/src/Cedar/Database.c
+++ b/src/Cedar/Database.c
@@ -5,7 +5,13 @@
// Database.c
// License database
-#include "CedarPch.h"
+#include "Database.h"
+
+#include "Cedar.h"
+
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Table.h"
+#include "Mayaqua/Str.h"
// Get the License status string
wchar_t *LiGetLicenseStatusStr(UINT i)
diff --git a/src/Cedar/Database.h b/src/Cedar/Database.h
index a413a5d5..4985fb5e 100644
--- a/src/Cedar/Database.h
+++ b/src/Cedar/Database.h
@@ -8,6 +8,8 @@
#ifndef DATABASE_H
#define DATABASE_H
+#include "Mayaqua/MayaType.h"
+
wchar_t *LiGetLicenseStatusStr(UINT i);
bool LiIsLicenseKey(char *str);
bool LiStrToKeyBit(UCHAR *keybit, char *keystr);
diff --git a/src/Cedar/EM.c b/src/Cedar/EM.c
index ee529211..17c5c1f3 100644
--- a/src/Cedar/EM.c
+++ b/src/Cedar/EM.c
@@ -5,39 +5,31 @@
// EM.c
// EtherLogger Manager for Win32
-#include
+#ifdef OS_WIN32
-#ifdef WIN32
+#define WINUI_C
-#define SM_C
-#define CM_C
-#define NM_C
-#define EM_C
-
-#define _WIN32_WINNT 0x0502
-#define WINVER 0x0502
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include "CMInner.h"
-#include "SMInner.h"
-#include "NMInner.h"
+#include "EM.h"
#include "EMInner.h"
+
+#include "CMInner.h"
+#include "Database.h"
+#include "EtherLog.h"
+#include "Remote.h"
+#include "SMInner.h"
+#include "WinUi.h"
+
+#include "Mayaqua/FileIO.h"
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Microsoft.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Table.h"
+
#include "../PenCore/resource.h"
+#include
+#include
// License registration process
void EmLicenseAddDlgOnOk(HWND hWnd, RPC *s)
@@ -1120,32 +1112,23 @@ RES_ERROR:
return;
}
- // Message after the end
- if (OS_IS_WINDOWS_NT(GetOsInfo()->OsType) == false)
+ // Need to restart the service
+ if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO, _UU("EM_WPCAP_REBOOT2")) == IDNO)
{
- // Need to restart the computer
- MsgBox(hWnd, MB_ICONINFORMATION, _UU("EM_WPCAP_REBOOT1"));
+ // Not restart
}
else
{
- // Need to restart the service
- if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO, _UU("EM_WPCAP_REBOOT2")) == IDNO)
- {
- // Not restart
- }
- else
- {
- // Restart
- RPC_TEST t;
- RPC_BRIDGE_SUPPORT t2;
- Zero(&t, sizeof(t));
- EcRebootServer(r, &t);
+ // Restart
+ RPC_TEST t;
+ RPC_BRIDGE_SUPPORT t2;
+ Zero(&t, sizeof(t));
+ EcRebootServer(r, &t);
- SleepThread(500);
+ SleepThread(500);
- Zero(&t2, sizeof(t2));
- CALL(hWnd, EcGetBridgeSupport(r, &t2));
- }
+ Zero(&t2, sizeof(t2));
+ CALL(hWnd, EcGetBridgeSupport(r, &t2));
}
}
@@ -1173,7 +1156,7 @@ void EMMain(RPC *r)
if (t.IsWinPcapNeeded)
{
- if (r->Sock->RemoteIP.addr[0] != 127)
+ if (IsLocalHostIP(&r->Sock->RemoteIP) == false)
{
// WinPcap is required, but can not do anything because it is in remote management mode
MsgBox(NULL, MB_ICONINFORMATION, _UU("EM_WPCAP_REMOTE"));
diff --git a/src/Cedar/EMInner.h b/src/Cedar/EMInner.h
index c4327aee..d13ebadc 100644
--- a/src/Cedar/EMInner.h
+++ b/src/Cedar/EMInner.h
@@ -5,6 +5,10 @@
// EMInner.h
// Inner header of EM.c
+#include "CedarType.h"
+
+#include "Mayaqua/MayaType.h"
+
// Constants
#define EM_REG_KEY "Software\\" GC_REG_COMPANY_NAME "\\EtherLogger\\Manager"
diff --git a/src/Cedar/EtherLog.c b/src/Cedar/EtherLog.c
index dc057a97..f29cf74e 100644
--- a/src/Cedar/EtherLog.c
+++ b/src/Cedar/EtherLog.c
@@ -5,7 +5,24 @@
// EtherLog.c
// EtherLogger program
-#include "CedarPch.h"
+#include "EtherLog.h"
+
+#include "Admin.h"
+#include "BridgeUnix.h"
+#include "BridgeWin32.h"
+#include "Listener.h"
+#include "Remote.h"
+#include "Sam.h"
+#include "Server.h"
+#include "WinUi.h"
+
+#include "Mayaqua/Cfg.h"
+#include "Mayaqua/Encrypt.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/OS.h"
+#include "Mayaqua/Pack.h"
+#include "Mayaqua/Str.h"
static LOCK *el_lock = NULL;
static EL *el = NULL;
diff --git a/src/Cedar/EtherLog.h b/src/Cedar/EtherLog.h
index 15800b41..2ade72e9 100644
--- a/src/Cedar/EtherLog.h
+++ b/src/Cedar/EtherLog.h
@@ -8,6 +8,8 @@
#ifndef ETHERLOG_H
#define ETHERLOG_H
+#include "Hub.h"
+
// Whether this is a beta version
#define ELOG_IS_BETA true
@@ -51,7 +53,7 @@ struct RPC_ENUM_DEVICE
// License status of the service
struct RPC_EL_LICENSE_STATUS
{
- BOOL Valid; // Enable flag
+ bool Valid; // Enable flag
UINT64 SystemId; // System ID
UINT64 SystemExpires; // System expiration date
};
@@ -74,7 +76,7 @@ struct EL_DEVICE
// License status
struct EL_LICENSE_STATUS
{
- BOOL Valid; // Enable flag
+ bool Valid; // Enable flag
UINT64 SystemId; // System ID
UINT64 Expires; // Expiration date
};
diff --git a/src/Cedar/Hub.c b/src/Cedar/Hub.c
index 184f3312..17d0b40e 100644
--- a/src/Cedar/Hub.c
+++ b/src/Cedar/Hub.c
@@ -5,7 +5,35 @@
// Hub.c
// Virtual HUB module
-#include "CedarPch.h"
+#include "Hub.h"
+
+#include "Admin.h"
+#include "Bridge.h"
+#include "Connection.h"
+#include "Link.h"
+#include "Nat.h"
+#include "NativeStack.h"
+#include "Protocol.h"
+#include "Radius.h"
+#include "SecureNAT.h"
+#include "Server.h"
+
+#include "Mayaqua/Cfg.h"
+#include "Mayaqua/FileIO.h"
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Table.h"
+#include "Mayaqua/TcpIp.h"
+#include "Mayaqua/Tick64.h"
+
+#define GetHubAdminOptionDataAndSet(ao, name, dest) \
+ value = GetHubAdminOptionData(ao, name); \
+ if (value != INFINITE) \
+ { \
+ dest = value; \
+ }
static UCHAR broadcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
static char vgs_ua_str[9] = {0};
@@ -516,23 +544,6 @@ UINT GetHubAdminOptionData(RPC_ADMIN_OPTION *ao, char *name)
return INFINITE;
}
-void GetHubAdminOptionDataAndSet(RPC_ADMIN_OPTION *ao, char *name, UINT *dest)
-{
- UINT value;
- // Validate arguments
- if (ao == NULL || name == NULL || dest == NULL)
- {
- return;
- }
-
- value = GetHubAdminOptionData(ao, name);
- if (value == INFINITE)
- {
- return;
- }
-
- *dest = value;
-}
// Set the contents of the HUB_OPTION based on the data
void DataToHubOptionStruct(HUB_OPTION *o, RPC_ADMIN_OPTION *ao)
@@ -543,64 +554,66 @@ void DataToHubOptionStruct(HUB_OPTION *o, RPC_ADMIN_OPTION *ao)
return;
}
- GetHubAdminOptionDataAndSet(ao, "NoAddressPollingIPv4", &o->NoArpPolling);
- GetHubAdminOptionDataAndSet(ao, "NoAddressPollingIPv6", &o->NoIPv6AddrPolling);
- GetHubAdminOptionDataAndSet(ao, "NoIpTable", &o->NoIpTable);
- GetHubAdminOptionDataAndSet(ao, "NoMacAddressLog", &o->NoMacAddressLog);
- GetHubAdminOptionDataAndSet(ao, "ManageOnlyPrivateIP", &o->ManageOnlyPrivateIP);
- GetHubAdminOptionDataAndSet(ao, "ManageOnlyLocalUnicastIPv6", &o->ManageOnlyLocalUnicastIPv6);
- GetHubAdminOptionDataAndSet(ao, "DisableIPParsing", &o->DisableIPParsing);
- GetHubAdminOptionDataAndSet(ao, "YieldAfterStorePacket", &o->YieldAfterStorePacket);
- GetHubAdminOptionDataAndSet(ao, "NoSpinLockForPacketDelay", &o->NoSpinLockForPacketDelay);
- GetHubAdminOptionDataAndSet(ao, "BroadcastStormDetectionThreshold", &o->BroadcastStormDetectionThreshold);
- GetHubAdminOptionDataAndSet(ao, "ClientMinimumRequiredBuild", &o->ClientMinimumRequiredBuild);
- GetHubAdminOptionDataAndSet(ao, "FilterPPPoE", &o->FilterPPPoE);
- GetHubAdminOptionDataAndSet(ao, "FilterOSPF", &o->FilterOSPF);
- GetHubAdminOptionDataAndSet(ao, "FilterIPv4", &o->FilterIPv4);
- GetHubAdminOptionDataAndSet(ao, "FilterIPv6", &o->FilterIPv6);
- GetHubAdminOptionDataAndSet(ao, "FilterNonIP", &o->FilterNonIP);
- GetHubAdminOptionDataAndSet(ao, "NoIPv4PacketLog", &o->NoIPv4PacketLog);
- GetHubAdminOptionDataAndSet(ao, "NoIPv6PacketLog", &o->NoIPv6PacketLog);
- GetHubAdminOptionDataAndSet(ao, "FilterBPDU", &o->FilterBPDU);
- GetHubAdminOptionDataAndSet(ao, "NoIPv6DefaultRouterInRAWhenIPv6", &o->NoIPv6DefaultRouterInRAWhenIPv6);
- GetHubAdminOptionDataAndSet(ao, "NoLookBPDUBridgeId", &o->NoLookBPDUBridgeId);
- GetHubAdminOptionDataAndSet(ao, "NoManageVlanId", &o->NoManageVlanId);
- GetHubAdminOptionDataAndSet(ao, "VlanTypeId", &o->VlanTypeId);
- GetHubAdminOptionDataAndSet(ao, "FixForDLinkBPDU", &o->FixForDLinkBPDU);
- GetHubAdminOptionDataAndSet(ao, "RequiredClientId", &o->RequiredClientId);
- GetHubAdminOptionDataAndSet(ao, "AdjustTcpMssValue", &o->AdjustTcpMssValue);
- GetHubAdminOptionDataAndSet(ao, "DisableAdjustTcpMss", &o->DisableAdjustTcpMss);
- GetHubAdminOptionDataAndSet(ao, "NoDhcpPacketLogOutsideHub", &o->NoDhcpPacketLogOutsideHub);
- GetHubAdminOptionDataAndSet(ao, "DisableHttpParsing", &o->DisableHttpParsing);
- GetHubAdminOptionDataAndSet(ao, "DisableUdpAcceleration", &o->DisableUdpAcceleration);
- GetHubAdminOptionDataAndSet(ao, "DisableUdpFilterForLocalBridgeNic", &o->DisableUdpFilterForLocalBridgeNic);
- GetHubAdminOptionDataAndSet(ao, "ApplyIPv4AccessListOnArpPacket", &o->ApplyIPv4AccessListOnArpPacket);
- GetHubAdminOptionDataAndSet(ao, "RemoveDefGwOnDhcpForLocalhost", &o->RemoveDefGwOnDhcpForLocalhost);
- GetHubAdminOptionDataAndSet(ao, "SecureNAT_MaxTcpSessionsPerIp", &o->SecureNAT_MaxTcpSessionsPerIp);
- GetHubAdminOptionDataAndSet(ao, "SecureNAT_MaxTcpSynSentPerIp", &o->SecureNAT_MaxTcpSynSentPerIp);
- GetHubAdminOptionDataAndSet(ao, "SecureNAT_MaxUdpSessionsPerIp", &o->SecureNAT_MaxUdpSessionsPerIp);
- GetHubAdminOptionDataAndSet(ao, "SecureNAT_MaxDnsSessionsPerIp", &o->SecureNAT_MaxDnsSessionsPerIp);
- GetHubAdminOptionDataAndSet(ao, "SecureNAT_MaxIcmpSessionsPerIp", &o->SecureNAT_MaxIcmpSessionsPerIp);
- GetHubAdminOptionDataAndSet(ao, "AccessListIncludeFileCacheLifetime", &o->AccessListIncludeFileCacheLifetime);
- GetHubAdminOptionDataAndSet(ao, "DisableKernelModeSecureNAT", &o->DisableKernelModeSecureNAT);
- GetHubAdminOptionDataAndSet(ao, "DisableIpRawModeSecureNAT", &o->DisableIpRawModeSecureNAT);
- GetHubAdminOptionDataAndSet(ao, "DisableUserModeSecureNAT", &o->DisableUserModeSecureNAT);
- GetHubAdminOptionDataAndSet(ao, "DisableCheckMacOnLocalBridge", &o->DisableCheckMacOnLocalBridge);
- GetHubAdminOptionDataAndSet(ao, "DisableCorrectIpOffloadChecksum", &o->DisableCorrectIpOffloadChecksum);
- GetHubAdminOptionDataAndSet(ao, "BroadcastLimiterStrictMode", &o->BroadcastLimiterStrictMode);
- GetHubAdminOptionDataAndSet(ao, "MaxLoggedPacketsPerMinute", &o->MaxLoggedPacketsPerMinute);
- GetHubAdminOptionDataAndSet(ao, "DoNotSaveHeavySecurityLogs", &o->DoNotSaveHeavySecurityLogs);
- GetHubAdminOptionDataAndSet(ao, "DropBroadcastsInPrivacyFilterMode", &o->DropBroadcastsInPrivacyFilterMode);
- GetHubAdminOptionDataAndSet(ao, "DropArpInPrivacyFilterMode", &o->DropArpInPrivacyFilterMode);
- GetHubAdminOptionDataAndSet(ao, "SuppressClientUpdateNotification", &o->SuppressClientUpdateNotification);
- GetHubAdminOptionDataAndSet(ao, "FloodingSendQueueBufferQuota", &o->FloodingSendQueueBufferQuota);
- GetHubAdminOptionDataAndSet(ao, "AssignVLanIdByRadiusAttribute", &o->AssignVLanIdByRadiusAttribute);
- GetHubAdminOptionDataAndSet(ao, "DenyAllRadiusLoginWithNoVlanAssign", &o->DenyAllRadiusLoginWithNoVlanAssign);
- GetHubAdminOptionDataAndSet(ao, "SecureNAT_RandomizeAssignIp", &o->SecureNAT_RandomizeAssignIp);
- GetHubAdminOptionDataAndSet(ao, "DetectDormantSessionInterval", &o->DetectDormantSessionInterval);
- GetHubAdminOptionDataAndSet(ao, "NoPhysicalIPOnPacketLog", &o->NoPhysicalIPOnPacketLog);
- GetHubAdminOptionDataAndSet(ao, "UseHubNameAsDhcpUserClassOption", &o->UseHubNameAsDhcpUserClassOption);
- GetHubAdminOptionDataAndSet(ao, "UseHubNameAsRadiusNasId", &o->UseHubNameAsRadiusNasId);
+ UINT value;
+
+ GetHubAdminOptionDataAndSet(ao, "NoAddressPollingIPv4", o->NoArpPolling);
+ GetHubAdminOptionDataAndSet(ao, "NoAddressPollingIPv6", o->NoIPv6AddrPolling);
+ GetHubAdminOptionDataAndSet(ao, "NoIpTable", o->NoIpTable);
+ GetHubAdminOptionDataAndSet(ao, "NoMacAddressLog", o->NoMacAddressLog);
+ GetHubAdminOptionDataAndSet(ao, "ManageOnlyPrivateIP", o->ManageOnlyPrivateIP);
+ GetHubAdminOptionDataAndSet(ao, "ManageOnlyLocalUnicastIPv6", o->ManageOnlyLocalUnicastIPv6);
+ GetHubAdminOptionDataAndSet(ao, "DisableIPParsing", o->DisableIPParsing);
+ GetHubAdminOptionDataAndSet(ao, "YieldAfterStorePacket", o->YieldAfterStorePacket);
+ GetHubAdminOptionDataAndSet(ao, "NoSpinLockForPacketDelay", o->NoSpinLockForPacketDelay);
+ GetHubAdminOptionDataAndSet(ao, "BroadcastStormDetectionThreshold", o->BroadcastStormDetectionThreshold);
+ GetHubAdminOptionDataAndSet(ao, "ClientMinimumRequiredBuild", o->ClientMinimumRequiredBuild);
+ GetHubAdminOptionDataAndSet(ao, "FilterPPPoE", o->FilterPPPoE);
+ GetHubAdminOptionDataAndSet(ao, "FilterOSPF", o->FilterOSPF);
+ GetHubAdminOptionDataAndSet(ao, "FilterIPv4", o->FilterIPv4);
+ GetHubAdminOptionDataAndSet(ao, "FilterIPv6", o->FilterIPv6);
+ GetHubAdminOptionDataAndSet(ao, "FilterNonIP", o->FilterNonIP);
+ GetHubAdminOptionDataAndSet(ao, "NoIPv4PacketLog", o->NoIPv4PacketLog);
+ GetHubAdminOptionDataAndSet(ao, "NoIPv6PacketLog", o->NoIPv6PacketLog);
+ GetHubAdminOptionDataAndSet(ao, "FilterBPDU", o->FilterBPDU);
+ GetHubAdminOptionDataAndSet(ao, "NoIPv6DefaultRouterInRAWhenIPv6", o->NoIPv6DefaultRouterInRAWhenIPv6);
+ GetHubAdminOptionDataAndSet(ao, "NoLookBPDUBridgeId", o->NoLookBPDUBridgeId);
+ GetHubAdminOptionDataAndSet(ao, "NoManageVlanId", o->NoManageVlanId);
+ GetHubAdminOptionDataAndSet(ao, "VlanTypeId", o->VlanTypeId);
+ GetHubAdminOptionDataAndSet(ao, "FixForDLinkBPDU", o->FixForDLinkBPDU);
+ GetHubAdminOptionDataAndSet(ao, "RequiredClientId", o->RequiredClientId);
+ GetHubAdminOptionDataAndSet(ao, "AdjustTcpMssValue", o->AdjustTcpMssValue);
+ GetHubAdminOptionDataAndSet(ao, "DisableAdjustTcpMss", o->DisableAdjustTcpMss);
+ GetHubAdminOptionDataAndSet(ao, "NoDhcpPacketLogOutsideHub", o->NoDhcpPacketLogOutsideHub);
+ GetHubAdminOptionDataAndSet(ao, "DisableHttpParsing", o->DisableHttpParsing);
+ GetHubAdminOptionDataAndSet(ao, "DisableUdpAcceleration", o->DisableUdpAcceleration);
+ GetHubAdminOptionDataAndSet(ao, "DisableUdpFilterForLocalBridgeNic", o->DisableUdpFilterForLocalBridgeNic);
+ GetHubAdminOptionDataAndSet(ao, "ApplyIPv4AccessListOnArpPacket", o->ApplyIPv4AccessListOnArpPacket);
+ GetHubAdminOptionDataAndSet(ao, "RemoveDefGwOnDhcpForLocalhost", o->RemoveDefGwOnDhcpForLocalhost);
+ GetHubAdminOptionDataAndSet(ao, "SecureNAT_MaxTcpSessionsPerIp", o->SecureNAT_MaxTcpSessionsPerIp);
+ GetHubAdminOptionDataAndSet(ao, "SecureNAT_MaxTcpSynSentPerIp", o->SecureNAT_MaxTcpSynSentPerIp);
+ GetHubAdminOptionDataAndSet(ao, "SecureNAT_MaxUdpSessionsPerIp", o->SecureNAT_MaxUdpSessionsPerIp);
+ GetHubAdminOptionDataAndSet(ao, "SecureNAT_MaxDnsSessionsPerIp", o->SecureNAT_MaxDnsSessionsPerIp);
+ GetHubAdminOptionDataAndSet(ao, "SecureNAT_MaxIcmpSessionsPerIp", o->SecureNAT_MaxIcmpSessionsPerIp);
+ GetHubAdminOptionDataAndSet(ao, "AccessListIncludeFileCacheLifetime", o->AccessListIncludeFileCacheLifetime);
+ GetHubAdminOptionDataAndSet(ao, "DisableKernelModeSecureNAT", o->DisableKernelModeSecureNAT);
+ GetHubAdminOptionDataAndSet(ao, "DisableIpRawModeSecureNAT", o->DisableIpRawModeSecureNAT);
+ GetHubAdminOptionDataAndSet(ao, "DisableUserModeSecureNAT", o->DisableUserModeSecureNAT);
+ GetHubAdminOptionDataAndSet(ao, "DisableCheckMacOnLocalBridge", o->DisableCheckMacOnLocalBridge);
+ GetHubAdminOptionDataAndSet(ao, "DisableCorrectIpOffloadChecksum", o->DisableCorrectIpOffloadChecksum);
+ GetHubAdminOptionDataAndSet(ao, "BroadcastLimiterStrictMode", o->BroadcastLimiterStrictMode);
+ GetHubAdminOptionDataAndSet(ao, "MaxLoggedPacketsPerMinute", o->MaxLoggedPacketsPerMinute);
+ GetHubAdminOptionDataAndSet(ao, "DoNotSaveHeavySecurityLogs", o->DoNotSaveHeavySecurityLogs);
+ GetHubAdminOptionDataAndSet(ao, "DropBroadcastsInPrivacyFilterMode", o->DropBroadcastsInPrivacyFilterMode);
+ GetHubAdminOptionDataAndSet(ao, "DropArpInPrivacyFilterMode", o->DropArpInPrivacyFilterMode);
+ GetHubAdminOptionDataAndSet(ao, "SuppressClientUpdateNotification", o->SuppressClientUpdateNotification);
+ GetHubAdminOptionDataAndSet(ao, "FloodingSendQueueBufferQuota", o->FloodingSendQueueBufferQuota);
+ GetHubAdminOptionDataAndSet(ao, "AssignVLanIdByRadiusAttribute", o->AssignVLanIdByRadiusAttribute);
+ GetHubAdminOptionDataAndSet(ao, "DenyAllRadiusLoginWithNoVlanAssign", o->DenyAllRadiusLoginWithNoVlanAssign);
+ GetHubAdminOptionDataAndSet(ao, "SecureNAT_RandomizeAssignIp", o->SecureNAT_RandomizeAssignIp);
+ GetHubAdminOptionDataAndSet(ao, "DetectDormantSessionInterval", o->DetectDormantSessionInterval);
+ GetHubAdminOptionDataAndSet(ao, "NoPhysicalIPOnPacketLog", o->NoPhysicalIPOnPacketLog);
+ GetHubAdminOptionDataAndSet(ao, "UseHubNameAsDhcpUserClassOption", o->UseHubNameAsDhcpUserClassOption);
+ GetHubAdminOptionDataAndSet(ao, "UseHubNameAsRadiusNasId", o->UseHubNameAsRadiusNasId);
}
// Convert the contents of the HUB_OPTION to data
@@ -4008,7 +4021,7 @@ DISCARD_PACKET:
if (forward_now)
{
- if (memcmp(packet->MacAddressSrc, hub->HubMacAddr, 6) == 0)
+ if (Cmp(packet->MacAddressSrc, hub->HubMacAddr, 6) == 0)
{
if (s != NULL)
{
@@ -4016,7 +4029,7 @@ DISCARD_PACKET:
goto DISCARD_PACKET;
}
}
- if (s != NULL && (memcmp(packet->MacAddressSrc, hub->HubMacAddr, 6) != 0))
+ if (s != NULL && (Cmp(packet->MacAddressSrc, hub->HubMacAddr, 6) != 0))
{
// Check whether the source MAC address is registered in the table
Copy(t.MacAddress, packet->MacAddressSrc, 6);
@@ -4175,7 +4188,7 @@ DISCARD_PACKET:
}
// It's already registered and it's in another session
- if (check_mac && (memcmp(packet->MacAddressSrc, hub->HubMacAddr, 6) != 0) &&
+ if (check_mac && (Cmp(packet->MacAddressSrc, hub->HubMacAddr, 6) != 0) &&
((entry->UpdatedTime + MAC_TABLE_EXCLUSIVE_TIME) >= now))
{
UCHAR *mac = packet->MacAddressSrc;
@@ -4192,7 +4205,7 @@ DISCARD_PACKET:
if ((s->LastDLinkSTPPacketSendTick != 0) &&
(tick_diff < 750ULL) &&
- (memcmp(hash, s->LastDLinkSTPPacketDataHash, MD5_SIZE) == 0))
+ (Cmp(hash, s->LastDLinkSTPPacketDataHash, MD5_SIZE) == 0))
{
// Discard if the same packet sent before 750ms ago
Debug("D-Link Discard %u\n", (UINT)tick_diff);
@@ -4832,8 +4845,8 @@ UPDATE_FDB:
if (s != NULL)
{
- if (memcmp(packet->MacAddressSrc, s->Hub->HubMacAddr, 6) == 0 ||
- memcmp(packet->MacAddressDest, s->Hub->HubMacAddr, 6) == 0)
+ if (Cmp(packet->MacAddressSrc, s->Hub->HubMacAddr, 6) == 0 ||
+ Cmp(packet->MacAddressDest, s->Hub->HubMacAddr, 6) == 0)
{
goto DISCARD_UNICAST_PACKET;
}
@@ -5049,8 +5062,8 @@ DISCARD_UNICAST_PACKET:
if (s != NULL)
{
- if (memcmp(packet->MacAddressSrc, s->Hub->HubMacAddr, 6) == 0 ||
- memcmp(packet->MacAddressDest, s->Hub->HubMacAddr, 6) == 0)
+ if (Cmp(packet->MacAddressSrc, s->Hub->HubMacAddr, 6) == 0 ||
+ Cmp(packet->MacAddressDest, s->Hub->HubMacAddr, 6) == 0)
{
discard = true;
}
@@ -6672,7 +6685,7 @@ int CompareMacTable(void *p1, void *p2)
{
return 0;
}
- r = memcmp(e1->MacAddress, e2->MacAddress, 6);
+ r = Cmp(e1->MacAddress, e2->MacAddress, 6);
if (r != 0)
{
return r;
@@ -6739,11 +6752,13 @@ bool IsHubIpAddress(IP *ip)
return false;
}
- if (ip->addr[0] == 172 && ip->addr[1] == 31)
+ const BYTE *ipv4 = IPV4(ip->address);
+
+ if (ipv4[0] == 172 && ipv4[1] == 31)
{
- if (ip->addr[2] >= 1 && ip->addr[2] <= 254)
+ if (ipv4[2] >= 1 && ipv4[2] <= 254)
{
- if (ip->addr[3] >= 1 && ip->addr[3] <= 254)
+ if (ipv4[3] >= 1 && ipv4[3] <= 254)
{
return true;
}
@@ -6797,11 +6812,7 @@ void GenHubIpAddress(IP *ip, char *name)
Sha0(hash, tmp2, StrLen(tmp2));
- Zero(ip, sizeof(IP));
- ip->addr[0] = 172;
- ip->addr[1] = 31;
- ip->addr[2] = hash[0] % 254 + 1;
- ip->addr[3] = hash[1] % 254 + 1;
+ SetIP(ip, 172, 31, hash[0] % 254 + 1, hash[0] % 254 + 1);
}
// Generate a MAC address for the Virtual HUB
diff --git a/src/Cedar/Hub.h b/src/Cedar/Hub.h
index 2c2dc66a..3942c69a 100644
--- a/src/Cedar/Hub.h
+++ b/src/Cedar/Hub.h
@@ -8,6 +8,8 @@
#ifndef HUB_H
#define HUB_H
+#include "Account.h"
+#include "Logging.h"
// Prefix in the access list for investigating whether the user name which is contained in a particular file
#define ACCESS_LIST_INCLUDED_PREFIX "include:" // Included
@@ -116,6 +118,8 @@ struct HUB_PA
struct HUB_OPTION
{
// Standard options
+ UINT DefaultGateway; // Used in IPC when DHCP cannot be used (e.g. WireGuard sessions)
+ UINT DefaultSubnet; // Used in IPC when DHCP cannot be used (e.g. WireGuard sessions)
UINT MaxSession; // Maximum number of simultaneous connections
bool NoEnum; // Excluded from the enumeration
// Advanced options
@@ -519,7 +523,6 @@ void HubOptionStructToData(RPC_ADMIN_OPTION *ao, HUB_OPTION *o, char *hub_name);
ADMIN_OPTION *NewAdminOption(char *name, UINT value);
void DataToHubOptionStruct(HUB_OPTION *o, RPC_ADMIN_OPTION *ao);
UINT GetHubAdminOptionData(RPC_ADMIN_OPTION *ao, char *name);
-void GetHubAdminOptionDataAndSet(RPC_ADMIN_OPTION *ao, char *name, UINT *dest);
bool IsURLMsg(wchar_t *str, char *url, UINT url_size);
LIST *NewUserList();
void DeleteAllUserListCache(LIST *o);
diff --git a/src/Cedar/IPC.c b/src/Cedar/IPC.c
index f8a5f081..162f7f00 100644
--- a/src/Cedar/IPC.c
+++ b/src/Cedar/IPC.c
@@ -5,7 +5,22 @@
// IPC.c
// In-process VPN client module
-#include "CedarPch.h"
+#include "IPC.h"
+
+#include "Admin.h"
+#include "Cedar.h"
+#include "Client.h"
+#include "Connection.h"
+#include "Hub.h"
+#include "Protocol.h"
+#include "Radius.h"
+#include "Virtual.h"
+
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Pack.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Tick64.h"
// Extract the MS-CHAP v2 authentication information by parsing the password string
bool ParseAndExtractMsChapV2InfoFromPassword(IPC_MSCHAP_V2_AUTHINFO *d, char *password)
@@ -226,8 +241,8 @@ IPC *NewIPCByParam(CEDAR *cedar, IPC_PARAM *param, UINT *error_code)
}
ipc = NewIPC(cedar, param->ClientName, param->Postfix, param->HubName,
- param->UserName, param->Password, error_code, ¶m->ClientIp,
- param->ClientPort, ¶m->ServerIp, param->ServerPort,
+ param->UserName, param->Password, param->WgKey, error_code,
+ ¶m->ClientIp, param->ClientPort, ¶m->ServerIp, param->ServerPort,
param->ClientHostname, param->CryptName,
param->BridgeMode, param->Mss, NULL, param->ClientCertificate, param->Layer);
@@ -235,13 +250,14 @@ IPC *NewIPCByParam(CEDAR *cedar, IPC_PARAM *param, UINT *error_code)
}
// Start a new IPC connection
-IPC *NewIPC(CEDAR *cedar, char *client_name, char *postfix, char *hubname, char *username, char *password,
+IPC *NewIPC(CEDAR *cedar, char *client_name, char *postfix, char *hubname, char *username, char *password, char *wg_key,
UINT *error_code, IP *client_ip, UINT client_port, IP *server_ip, UINT server_port,
char *client_hostname, char *crypt_name,
bool bridge_mode, UINT mss, EAP_CLIENT *eap_client, X *client_certificate,
UINT layer)
{
IPC *ipc;
+ HUB *hub;
UINT dummy_int = 0;
SOCK *a;
SOCK *s;
@@ -297,9 +313,6 @@ IPC *NewIPC(CEDAR *cedar, char *client_name, char *postfix, char *hubname, char
ipc->FlushList = NewTubeFlushList();
StrCpy(ipc->ClientHostname, sizeof(ipc->ClientHostname), client_hostname);
- StrCpy(ipc->HubName, sizeof(ipc->HubName), hubname);
- StrCpy(ipc->UserName, sizeof(ipc->UserName), username);
- StrCpy(ipc->Password, sizeof(ipc->Password), password);
// Connect the in-process socket
s = ConnectInProc(a, client_ip, client_port, server_ip, server_port);
@@ -339,7 +352,11 @@ IPC *NewIPC(CEDAR *cedar, char *client_name, char *postfix, char *hubname, char
FreePack(p);
// Upload the authentication data
- if (client_certificate != NULL)
+ if (IsEmptyStr(wg_key) == false)
+ {
+ p = PackLoginWithWireGuardKey(wg_key);
+ }
+ else if (client_certificate != NULL)
{
p = PackLoginWithOpenVPNCertificate(hubname, username, client_certificate);
}
@@ -408,14 +425,14 @@ IPC *NewIPC(CEDAR *cedar, char *client_name, char *postfix, char *hubname, char
info.ServerIpAddress = IPToUINT(&s->RemoteIP);
info.ServerPort = Endian32(s->RemotePort);
StrCpy(info.HubName, sizeof(info.HubName), hubname);
- Copy(info.UniqueId, unique, 16);
+ Copy(info.UniqueId, unique, sizeof(info.UniqueId));
if (IsIP6(&s->LocalIP))
{
- Copy(info.ClientIpAddress6, s->LocalIP.ipv6_addr, 16);
+ Copy(info.ClientIpAddress6, s->LocalIP.address, sizeof(info.ClientIpAddress6));
}
if (IsIP6(&s->RemoteIP))
{
- Copy(info.ServerIpAddress6, s->RemoteIP.ipv6_addr, 16);
+ Copy(info.ServerIpAddress6, s->RemoteIP.address, sizeof(info.ServerIpAddress6));
}
OutRpcNodeInfo(p, &info);
@@ -466,6 +483,22 @@ IPC *NewIPC(CEDAR *cedar, char *client_name, char *postfix, char *hubname, char
PackGetStr(p, "IpcHubName", ipc->HubName, sizeof(ipc->HubName));
Debug("IPC Hub Name: %s\n", ipc->HubName);
+ hub = GetHub(cedar, ipc->HubName);
+ if (hub != NULL)
+ {
+ UINTToIP(&ipc->DefaultGateway, hub->Option->DefaultGateway);
+ UINTToIP(&ipc->SubnetMask, hub->Option->DefaultSubnet);
+ GetBroadcastAddress4(&ipc->BroadcastAddress, &ipc->DefaultGateway, &ipc->SubnetMask);
+ }
+ else
+ {
+ ZeroIP4(&ipc->DefaultGateway);
+ ZeroIP4(&ipc->SubnetMask);
+ ZeroIP4(&ipc->BroadcastAddress);
+ }
+
+ ZeroIP4(&ipc->ClientIPAddress);
+
MacToStr(macstr, sizeof(macstr), ipc->MacAddress);
Debug("IPC: Session = %s, Connection = %s, Mac = %s\n", ipc->SessionName, ipc->ConnectionName, macstr);
@@ -1377,23 +1410,23 @@ void IPCProcessL3EventsEx(IPC *ipc, UINT64 now)
{
ok = true;
}
- else if (ip_dst.addr[0] == 255 && ip_dst.addr[1] == 255 &&
- ip_dst.addr[2] == 255 && ip_dst.addr[3] == 255)
- {
- ok = true;
- }
- else if (ip_dst.addr[0] >= 224 && ip_dst.addr[0] <= 239)
- {
- ok = true;
- }
else
{
- if (CmpIpAddr(&ipc->BroadcastAddress, &ip_dst) == 0)
+ const BYTE *ipv4 = IPV4(ip_dst.address);
+
+ if (ipv4[0] == 255 && ipv4[1] == 255 && ipv4[2] == 255 && ipv4[3] == 255)
{
ok = true;
}
-
- if (IsZeroIP(&ipc->ClientIPAddress))
+ else if (ipv4[0] >= 224 && ipv4[1] <= 239)
+ {
+ ok = true;
+ }
+ else if (CmpIpAddr(&ipc->BroadcastAddress, &ip_dst) == 0)
+ {
+ ok = true;
+ }
+ else if (IsZeroIP(&ipc->ClientIPAddress))
{
// Client IP address is undetermined
ok = true;
@@ -1639,17 +1672,20 @@ void IPCSendIPv4(IPC *ipc, void *data, UINT size)
// Local Broadcast
is_broadcast = true;
}
-
- if (ip_dst.addr[0] == 255 && ip_dst.addr[1] == 255 && ip_dst.addr[2] == 255 && ip_dst.addr[3] == 255)
+ else
{
- // Global Broadcast
- is_broadcast = true;
- }
+ const BYTE *ipv4 = IPV4(ip_dst.address);
- if (ip_dst.addr[0] >= 224 && ip_dst.addr[0] <= 239)
- {
- // IPv4 Multicast
- is_broadcast = true;
+ if (ipv4[0] == 255 && ipv4[1] == 255 && ipv4[2] == 255 && ipv4[3] == 255)
+ {
+ // Global Broadcast
+ is_broadcast = true;
+ }
+ else if (ipv4[0] >= 224 && ipv4[0] <= 239)
+ {
+ // IPv4 Multicast
+ is_broadcast = true;
+ }
}
if (is_broadcast)
@@ -2180,10 +2216,10 @@ bool IPCIPv6CheckExistingLinkLocal(IPC *ipc, UINT64 eui)
t.Name = ipc->HubName;
// Construct link local from eui
- ZeroIP6(&i.Ip);
- i.Ip.ipv6_addr[0] = 0xFE;
- i.Ip.ipv6_addr[1] = 0x80;
- Copy(&i.Ip.ipv6_addr[8], &eui, sizeof(UINT64));
+ Zero(&i.Ip, sizeof(i.Ip));
+ i.Ip.address[0] = 0xfe;
+ i.Ip.address[1] = 0x80;
+ Copy(&i.Ip.address[8], &eui, sizeof(eui));
h = Search(ipc->Cedar->HubList, &t);
@@ -2211,7 +2247,7 @@ void IPCIPv6AddRouterPrefixes(IPC *ipc, ICMPV6_OPTION_LIST *recvPrefix, UCHAR *m
for (j = 0; j < LIST_NUM(ipc->IPv6RouterAdvs); j++)
{
IPC_IPV6_ROUTER_ADVERTISEMENT *existingRA = LIST_DATA(ipc->IPv6RouterAdvs, j);
- if (Cmp(&recvPrefix->Prefix[i]->Prefix, &existingRA->RoutedPrefix.ipv6_addr, sizeof(IPV6_ADDR)) == 0)
+ if (Cmp(&recvPrefix->Prefix[i]->Prefix, &existingRA->RoutedPrefix.address, sizeof(IPV6_ADDR)) == 0)
{
foundPrefix = true;
break;
@@ -2297,7 +2333,7 @@ UINT64 IPCIPv6GetServerEui(IPC *ipc)
// Generate the MAC address from the multicast address
destMacAddress[0] = 0x33;
destMacAddress[1] = 0x33;
- Copy(&destMacAddress[2], &destIP.ipv6_addr[12], sizeof(UINT));
+ Copy(&destMacAddress[2], &destIP.address[12], sizeof(UINT));
IPToIPv6Addr(&destV6, &destIP);
@@ -2331,7 +2367,7 @@ UINT64 IPCIPv6GetServerEui(IPC *ipc)
if (LIST_NUM(ipc->IPv6RouterAdvs) > 0)
{
IPC_IPV6_ROUTER_ADVERTISEMENT *ra = LIST_DATA(ipc->IPv6RouterAdvs, 0);
- Copy(&ipc->IPv6ServerEUI, &ra->RouterAddress.ipv6_addr[8], sizeof(UINT64));
+ Copy(&ipc->IPv6ServerEUI, &ra->RouterAddress.address[8], sizeof(ipc->IPv6ServerEUI));
}
// If it is still not defined, let's just generate something random
@@ -2384,10 +2420,10 @@ void IPCIPv6Send(IPC *ipc, void *data, UINT size)
// Constructing multicast MAC address based on destination IP address, then just fire and forget
destMac[0] = 0x33;
destMac[1] = 0x33;
- destMac[2] = destAddr.ipv6_addr[12];
- destMac[3] = destAddr.ipv6_addr[13];
- destMac[4] = destAddr.ipv6_addr[14];
- destMac[5] = destAddr.ipv6_addr[15];
+ destMac[2] = destAddr.address[12];
+ destMac[3] = destAddr.address[13];
+ destMac[4] = destAddr.address[14];
+ destMac[5] = destAddr.address[15];
IPCIPv6SendWithDestMacAddr(ipc, data, size, destMac);
return;
}
diff --git a/src/Cedar/IPC.h b/src/Cedar/IPC.h
index bd68c176..ed9ae24d 100644
--- a/src/Cedar/IPC.h
+++ b/src/Cedar/IPC.h
@@ -8,6 +8,11 @@
#ifndef IPC_H
#define IPC_H
+#include "Cedar.h"
+#include "Proto_WireGuard.h"
+
+#include "Mayaqua/TcpIp.h"
+
// Constants
#define IPC_ARP_LIFETIME (3 * 60 * 1000)
#define IPC_ARP_GIVEUPTIME (1 * 1000)
@@ -75,6 +80,7 @@ struct IPC_PARAM
char HubName[MAX_HUBNAME_LEN + 1];
char UserName[MAX_USERNAME_LEN + 1];
char Password[MAX_PASSWORD_LEN + 1];
+ char WgKey[WG_KEY_BASE64_SIZE];
IP ClientIp;
UINT ClientPort;
IP ServerIp;
@@ -119,8 +125,6 @@ struct IPC
{
CEDAR *Cedar;
char HubName[MAX_HUBNAME_LEN + 1];
- char UserName[MAX_USERNAME_LEN + 1];
- char Password[MAX_PASSWORD_LEN + 1];
char ClientHostname[MAX_SIZE];
UCHAR random[SHA1_SIZE];
char SessionName[MAX_SESSION_NAME_LEN + 1];
@@ -173,7 +177,7 @@ struct IPC_IPV6_ROUTER_ADVERTISEMENT
UCHAR RouterLinkLayerAddress[6];
};
-IPC *NewIPC(CEDAR *cedar, char *client_name, char *postfix, char *hubname, char *username, char *password,
+IPC *NewIPC(CEDAR *cedar, char *client_name, char *postfix, char *hubname, char *username, char *password, char *wg_key,
UINT *error_code, IP *client_ip, UINT client_port, IP *server_ip, UINT server_port,
char *client_hostname, char *crypt_name,
bool bridge_mode, UINT mss, EAP_CLIENT *eap_client, X *client_certificate,
diff --git a/src/Cedar/Layer3.c b/src/Cedar/Layer3.c
index 96c5c216..6838bc9d 100644
--- a/src/Cedar/Layer3.c
+++ b/src/Cedar/Layer3.c
@@ -5,7 +5,21 @@
// Layer3.c
// Layer-3 switch module
-#include "CedarPch.h"
+#include "Layer3.h"
+
+#include "Connection.h"
+#include "Hub.h"
+#include "Server.h"
+#include "Session.h"
+#include "Virtual.h"
+
+#include "Mayaqua/FileIO.h"
+#include "Mayaqua/Kernel.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/TcpIp.h"
+#include "Mayaqua/Tick64.h"
static UCHAR broadcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
diff --git a/src/Cedar/Layer3.h b/src/Cedar/Layer3.h
index 5e91d3a3..2c1c409c 100644
--- a/src/Cedar/Layer3.h
+++ b/src/Cedar/Layer3.h
@@ -8,6 +8,8 @@
#ifndef LAYER3_H
#define LAYER3_H
+#include "Cedar.h"
+
// Constants
#define L3_USERNAME "L3SW_"
diff --git a/src/Cedar/Link.c b/src/Cedar/Link.c
index ec25023c..001fd19d 100644
--- a/src/Cedar/Link.c
+++ b/src/Cedar/Link.c
@@ -5,7 +5,21 @@
// Link.c
// Inter-HUB Link
-#include "CedarPch.h"
+#include "Link.h"
+
+#include "Account.h"
+#include "Client.h"
+#include "Connection.h"
+#include "Hub.h"
+#include "Logging.h"
+#include "Server.h"
+#include "Session.h"
+
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Kernel.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
// Link server thread
void LinkServerSessionThread(THREAD *t, void *param)
diff --git a/src/Cedar/Link.h b/src/Cedar/Link.h
index 22b42999..817d0bbb 100644
--- a/src/Cedar/Link.h
+++ b/src/Cedar/Link.h
@@ -8,6 +8,10 @@
#ifndef LINK_H
#define LINK_H
+#include "CedarType.h"
+
+#include "Mayaqua/MayaType.h"
+
struct LINK
{
bool Started; // Running flag
diff --git a/src/Cedar/Listener.c b/src/Cedar/Listener.c
index f365ddc8..1eb876f5 100644
--- a/src/Cedar/Listener.c
+++ b/src/Cedar/Listener.c
@@ -5,7 +5,18 @@
// Listener.c
// Listener module
-#include "CedarPch.h"
+#include "Listener.h"
+
+#include "Cedar.h"
+#include "Connection.h"
+#include "Logging.h"
+#include "Server.h"
+#include "Session.h"
+
+#include "Mayaqua/Mayaqua.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
static bool disable_dos = false;
static UINT max_connections_per_ip = DEFAULT_MAX_CONNECTIONS_PER_IP;
diff --git a/src/Cedar/Listener.h b/src/Cedar/Listener.h
index 9ef8a1d8..40b816f1 100644
--- a/src/Cedar/Listener.h
+++ b/src/Cedar/Listener.h
@@ -8,6 +8,9 @@
#ifndef LISTENER_H
#define LISTENER_H
+#include "CedarType.h"
+
+#include "Mayaqua/Kernel.h"
// Function to call when receiving a new connection
typedef void (NEW_CONNECTION_PROC)(CONNECTION *c);
diff --git a/src/Cedar/Logging.c b/src/Cedar/Logging.c
index ff79ef48..b8e0198d 100644
--- a/src/Cedar/Logging.c
+++ b/src/Cedar/Logging.c
@@ -5,7 +5,28 @@
// Logging.c
// Log storaging module
-#include "CedarPch.h"
+#include "Logging.h"
+
+#include "Admin.h"
+#include "Client.h"
+#include "Nat.h"
+#include "Proto_EtherIP.h"
+#include "Proto_IKE.h"
+#include "Proto_PPP.h"
+#include "Remote.h"
+#include "SecureNAT.h"
+#include "Server.h"
+
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/FileIO.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Microsoft.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Tick64.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Table.h"
+#include "Mayaqua/Unix.h"
+#include "Mayaqua/Win32.h"
static char *delete_targets[] =
{
@@ -832,8 +853,8 @@ bool PacketLog(HUB *hub, SESSION *src_session, SESSION *dest_session, PKT *packe
return true;
}
- if (memcmp(hub->HubMacAddr, packet->MacAddressSrc, 6) == 0 ||
- memcmp(hub->HubMacAddr, packet->MacAddressDest, 6) == 0)
+ if (Cmp(hub->HubMacAddr, packet->MacAddressSrc, 6) == 0 ||
+ Cmp(hub->HubMacAddr, packet->MacAddressDest, 6) == 0)
{
return true;
}
@@ -2272,7 +2293,7 @@ bool MakeLogFileName(LOG *g, char *name, UINT size, char *dir, char *prefix, UIN
}
}
- if (strcmp(old_datestr, tmp) != 0)
+ if (StrCmp(old_datestr, tmp) != 0)
{
ret = true;
StrCpy(old_datestr, MAX_SIZE, tmp);
diff --git a/src/Cedar/Logging.h b/src/Cedar/Logging.h
index b59be053..b4c05941 100644
--- a/src/Cedar/Logging.h
+++ b/src/Cedar/Logging.h
@@ -8,6 +8,9 @@
#ifndef LOGGING_H
#define LOGGING_H
+#include "Cedar.h"
+
+#include "Mayaqua/Network.h"
// Port number for HTTP monitoring
#define LOG_HTTP_PORT 80
diff --git a/src/Cedar/NM.c b/src/Cedar/NM.c
index 61c98f0e..3e80b5da 100644
--- a/src/Cedar/NM.c
+++ b/src/Cedar/NM.c
@@ -5,36 +5,20 @@
// NM.c
// VPN User-mode Router Manager for Win32
-#include
+#ifdef OS_WIN32
-#ifdef WIN32
-
-#define SM_C
-#define CM_C
-#define NM_C
-
-#define _WIN32_WINNT 0x0502
-#define WINVER 0x0502
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include "CMInner.h"
-#include "SMInner.h"
+#include "NM.h"
#include "NMInner.h"
-#include "EMInner.h"
+
+#include "CMInner.h"
+#include "Nat.h"
+#include "Remote.h"
+#include "Server.h"
+
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Str.h"
+
#include "../PenCore/resource.h"
// Global variable
diff --git a/src/Cedar/NMInner.h b/src/Cedar/NMInner.h
index ab9b6a22..14531be6 100644
--- a/src/Cedar/NMInner.h
+++ b/src/Cedar/NMInner.h
@@ -5,6 +5,9 @@
// NMInner.h
// The internal header of NM.c
+#include "SMInner.h"
+
+#include "Mayaqua/Encrypt.h"
// Constants
#define NM_REG_KEY "Software\\" GC_REG_COMPANY_NAME "\\PacketiX VPN\\User-mode Router Manager"
diff --git a/src/Cedar/Nat.c b/src/Cedar/Nat.c
index 63852fb5..69ab1e6c 100644
--- a/src/Cedar/Nat.c
+++ b/src/Cedar/Nat.c
@@ -5,7 +5,18 @@
// Nat.c
// User-mode Router
-#include "CedarPch.h"
+#include "Nat.h"
+
+#include "Admin.h"
+#include "Remote.h"
+#include "Sam.h"
+
+#include "Mayaqua/Cfg.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Pack.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Tick64.h"
static LOCK *nat_lock = NULL;
static NAT *nat = NULL;
diff --git a/src/Cedar/Nat.h b/src/Cedar/Nat.h
index 70cf601e..7cdb5d3b 100644
--- a/src/Cedar/Nat.h
+++ b/src/Cedar/Nat.h
@@ -8,6 +8,11 @@
#ifndef NAT_H
#define NAT_H
+#include "Cedar.h"
+#include "Virtual.h"
+
+#include "Mayaqua/Kernel.h"
+
// Constants
#define NAT_CONFIG_FILE_NAME "$vpn_router.config" // NAT configuration file
#define DEFAULT_NAT_ADMIN_PORT 2828 // Default port number for management
diff --git a/src/Cedar/NativeStack.c b/src/Cedar/NativeStack.c
index afd01afe..0a1eabaa 100644
--- a/src/Cedar/NativeStack.c
+++ b/src/Cedar/NativeStack.c
@@ -5,7 +5,21 @@
// NativeStack.c
// Native IP stack
-#include "CedarPch.h"
+#include "NativeStack.h"
+
+#include "BridgeUnix.h"
+#include "BridgeWin32.h"
+#include "IPC.h"
+#include "Virtual.h"
+
+#include "Mayaqua/FileIO.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
+
+#ifdef OS_UNIX
+#include "Mayaqua/Unix.h"
+#endif
// Stack main thread
void NsMainThread(THREAD *thread, void *param)
@@ -669,30 +683,26 @@ UINT GenerateDummyMark(PRAND *p)
// Generate a dummy IP
void GenerateDummyIp(PRAND *p, IP *ip)
{
- UINT i;
if (p == NULL || ip == NULL)
{
return;
}
- Zero(ip, sizeof(IP));
+ ZeroIP4(ip);
+ BYTE *ipv4 = IPV4(ip->address);
- for (i = 1;i < 4;i++)
+ for (BYTE i = 1; i < IPV4_SIZE; ++i)
{
- UINT v = 0;
- while (true)
+ BYTE v = 0;
+ while (v == 0 || v > 254)
{
v = PRandInt(p) % 256;
- if (v >= 1 && v <= 254)
- {
- break;
- }
}
- ip->addr[i] = (UCHAR)v;
+ IPV4(ip->address)[i] = v;
}
- ip->addr[0] = 127;
+ IPV4(ip->address)[0] = 127;
}
// Search an entry
diff --git a/src/Cedar/NativeStack.h b/src/Cedar/NativeStack.h
index 23142d8a..e96ba173 100644
--- a/src/Cedar/NativeStack.h
+++ b/src/Cedar/NativeStack.h
@@ -8,6 +8,10 @@
#ifndef NATIVESTACK_H
#define NATIVESTACK_H
+#include "CedarType.h"
+
+#include "Mayaqua/TcpIp.h"
+
//// Constants
#define NS_MAC_ADDRESS_BYTE_1 0xDA // First byte of the MAC address
diff --git a/src/Cedar/NullLan.c b/src/Cedar/NullLan.c
index 1e2606a0..0b953415 100644
--- a/src/Cedar/NullLan.c
+++ b/src/Cedar/NullLan.c
@@ -5,7 +5,17 @@
// NullLan.c
// Virtual LAN card device driver for testing
-#include "CedarPch.h"
+#include "NullLan.h"
+
+#include "Connection.h"
+#include "Session.h"
+
+#include "Mayaqua/Kernel.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Microsoft.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Tick64.h"
static UCHAR null_lan_broadcast_address[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
diff --git a/src/Cedar/NullLan.h b/src/Cedar/NullLan.h
index 16267f55..f703cecd 100644
--- a/src/Cedar/NullLan.h
+++ b/src/Cedar/NullLan.h
@@ -8,6 +8,9 @@
#ifndef NULLLAN_H
#define NULLLAN_H
+#include "CedarType.h"
+
+#include "Mayaqua/MayaType.h"
#define NULL_PACKET_GENERATE_INTERVAL 100000000 // Packet generation interval
diff --git a/src/Cedar/Proto.c b/src/Cedar/Proto.c
index 7023e4c7..182cc183 100644
--- a/src/Cedar/Proto.c
+++ b/src/Cedar/Proto.c
@@ -1,6 +1,18 @@
-#include "CedarPch.h"
+#include "Proto.h"
+#include "Cedar.h"
+#include "Logging.h"
#include "Proto_OpenVPN.h"
+#include "Proto_SSTP.h"
+#include "Proto_WireGuard.h"
+#include "Server.h"
+
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Kernel.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Table.h"
void ProtoLog(const PROTO *proto, const PROTO_SESSION *session, const char *name, ...)
{
@@ -122,47 +134,21 @@ UINT ProtoSessionHash(void *p)
}
ip = &session->SrcIp;
- if (IsIP6(ip))
+ for (BYTE i = 0; i < sizeof(ip->address); ++i)
{
- UINT i;
- for (i = 0; i < sizeof(ip->ipv6_addr); ++i)
- {
- ret += ip->ipv6_addr[i];
- }
-
- ret += ip->ipv6_scope_id;
- }
- else
- {
- UINT i;
- for (i = 0; i < sizeof(ip->addr); ++i)
- {
- ret += ip->addr[i];
- }
+ ret += ip->address[i];
}
+ ret += ip->ipv6_scope_id;
ret += session->SrcPort;
ip = &session->DstIp;
- if (IsIP6(ip))
+ for (BYTE i = 0; i < sizeof(ip->address); ++i)
{
- UINT i;
- for (i = 0; i < sizeof(ip->ipv6_addr); ++i)
- {
- ret += ip->ipv6_addr[i];
- }
-
- ret += ip->ipv6_scope_id;
- }
- else
- {
- UINT i;
- for (i = 0; i < sizeof(ip->addr); ++i)
- {
- ret += ip->addr[i];
- }
+ ret += ip->address[i];
}
+ ret += ip->ipv6_scope_id;
ret += session->DstPort;
return ret;
@@ -213,6 +199,8 @@ PROTO *ProtoNew(CEDAR *cedar)
AddRef(cedar->ref);
+ // WireGuard
+ Add(proto->Containers, ProtoContainerNew(WgsGetProtoImpl()));
// OpenVPN
Add(proto->Containers, ProtoContainerNew(OvsGetProtoImpl()));
// SSTP
@@ -291,7 +279,7 @@ PROTO_CONTAINER *ProtoContainerNew(const PROTO_IMPL *impl)
option->Bool = impl_option->Bool;
break;
case PROTO_OPTION_STRING:
- option->String = CopyStr(impl_option->String);
+ option->String = impl_option->String != NULL ? CopyStr(impl_option->String) : impl->OptionStringValue(option->Name);
break;
default:
Debug("ProtoContainerNew(): unhandled option type %u!\n", impl_option->Type);
diff --git a/src/Cedar/Proto.h b/src/Cedar/Proto.h
index 63f1b360..909e3d5a 100644
--- a/src/Cedar/Proto.h
+++ b/src/Cedar/Proto.h
@@ -1,6 +1,11 @@
#ifndef PROTO_H
#define PROTO_H
+#include "CedarType.h"
+
+#include "Mayaqua/MayaType.h"
+#include "Mayaqua/Network.h"
+
#define PROTO_OPTION_TOGGLE_NAME "Enabled"
// OpenVPN sends 2 bytes, thus this is the buffer size.
@@ -31,7 +36,7 @@ typedef struct PROTO
UDPLISTENER *UdpListener;
} PROTO;
-typedef struct PROTO_OPTION
+struct PROTO_OPTION
{
char *Name;
PROTO_OPTION_VALUE Type;
@@ -40,15 +45,16 @@ typedef struct PROTO_OPTION
bool Bool;
char *String;
};
-} PROTO_OPTION;
+};
typedef struct PROTO_IMPL
{
const char *(*Name)();
const PROTO_OPTION *(*Options)();
+ char *(*OptionStringValue)(const char *name);
bool (*Init)(void **param, const LIST *options, CEDAR *cedar, INTERRUPT_MANAGER *im, SOCK_EVENT *se, const char *cipher, const char *hostname);
void (*Free)(void *param);
- bool (*IsPacketForMe)(const PROTO_MODE mode, const UCHAR *data, const UINT size);
+ bool (*IsPacketForMe)(const PROTO_MODE mode, const void *data, const UINT size);
bool (*ProcessData)(void *param, TCP_RAW_DATA *in, FIFO *out);
bool (*ProcessDatagrams)(void *param, LIST *in, LIST *out);
} PROTO_IMPL;
diff --git a/src/Cedar/Proto_EtherIP.c b/src/Cedar/Proto_EtherIP.c
index 60d4616e..3e457774 100644
--- a/src/Cedar/Proto_EtherIP.c
+++ b/src/Cedar/Proto_EtherIP.c
@@ -5,7 +5,18 @@
// Proto_EtherIP.c
// EtherIP protocol stack
-#include "CedarPch.h"
+#include "Proto_EtherIP.h"
+
+#include "Connection.h"
+#include "IPC.h"
+#include "Logging.h"
+#include "Proto_IKE.h"
+
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Table.h"
+#include "Mayaqua/Tick64.h"
// IPC connection processing thread
void EtherIPIpcConnectThread(THREAD *t, void *p)
@@ -59,7 +70,7 @@ void EtherIPIpcConnectThread(THREAD *t, void *p)
EtherIPLog(s, "LE_START_IPC", id.HubName, id.UserName, mss);
ipc = NewIPC(s->Cedar, client_name,
(s->L2TPv3 ? ETHERIP_L2TPV3_POSTFIX : ETHERIP_POSTFIX),
- id.HubName, id.UserName, id.Password,
+ id.HubName, id.UserName, id.Password, NULL,
&error_code,
&s->ClientIP, s->ClientPort,
&s->ServerIP, s->ServerPort,
diff --git a/src/Cedar/Proto_EtherIP.h b/src/Cedar/Proto_EtherIP.h
index c540bc68..0df44990 100644
--- a/src/Cedar/Proto_EtherIP.h
+++ b/src/Cedar/Proto_EtherIP.h
@@ -8,8 +8,7 @@
#ifndef PROTO_ETHERIP_H
#define PROTO_ETHERIP_H
-//// Macro
-
+#include "Proto_IPsec.h"
//// Constants
#define ETHERIP_VPN_CONNECT_RETRY_INTERVAL (15 * 1000) // VPN connection retry interval
diff --git a/src/Cedar/Proto_IKE.c b/src/Cedar/Proto_IKE.c
index c35468c2..beaf09ab 100644
--- a/src/Cedar/Proto_IKE.c
+++ b/src/Cedar/Proto_IKE.c
@@ -5,7 +5,22 @@
// Proto_IKE.c
// IKE (ISAKMP) and ESP protocol stack
-#include "CedarPch.h"
+#include "Proto_IKE.h"
+
+#include "Cedar.h"
+#include "Connection.h"
+#include "Logging.h"
+#include "Proto_EtherIP.h"
+#include "Proto_IPsec.h"
+#include "Proto_L2TP.h"
+#include "Server.h"
+
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Table.h"
+#include "Mayaqua/TcpIp.h"
+#include "Mayaqua/Tick64.h"
//#define RAW_DEBUG
@@ -128,8 +143,8 @@ void IPsecSendPacketByIPsecSa(IKE_SERVER *ike, IPSECSA *sa, UCHAR *data, UINT da
h.PayloadLength = Endian16(data_size);
h.NextHeader = protocol_id;
h.HopLimit = 64;
- Copy(h.SrcAddress.Value, c->TunnelModeServerIP.ipv6_addr, 16);
- Copy(h.DestAddress.Value, c->TunnelModeClientIP.ipv6_addr, 16);
+ Copy(h.SrcAddress.Value, c->TunnelModeServerIP.address, sizeof(h.SrcAddress.Value));
+ Copy(h.DestAddress.Value, c->TunnelModeClientIP.address, sizeof(h.DestAddress.Value));
WriteBuf(b, &h, sizeof(IPV6_HEADER));
@@ -344,16 +359,16 @@ void IPsecSendUdpPacket(IKE_SERVER *ike, IKE_CLIENT *c, UINT src_port, UINT dst_
{
if (IsIPsecSaTunnelMode(c->CurrentIpSecSaSend) == false)
{
- u->Checksum = CalcChecksumForIPv6((IPV6_ADDR *)c->TransportModeServerIP.ipv6_addr,
- (IPV6_ADDR *)c->TransportModeClientIP.ipv6_addr,
+ u->Checksum = CalcChecksumForIPv6((IPV6_ADDR *)c->TransportModeServerIP.address,
+ (IPV6_ADDR *)c->TransportModeClientIP.address,
IP_PROTO_UDP,
u,
udp_size, 0);
}
else
{
- u->Checksum = CalcChecksumForIPv6((IPV6_ADDR *)c->TunnelModeServerIP.ipv6_addr,
- (IPV6_ADDR *)c->TunnelModeClientIP.ipv6_addr,
+ u->Checksum = CalcChecksumForIPv6((IPV6_ADDR *)c->TunnelModeServerIP.address,
+ (IPV6_ADDR *)c->TunnelModeClientIP.address,
IP_PROTO_UDP,
u,
udp_size, 0);
@@ -2892,12 +2907,12 @@ void ProcIkeAggressiveModePacketRecv(IKE_SERVER *ike, UDPPACKET *p, IKE_PACKET *
if (IsIP6(&sa->IkeClient->ServerIP))
{
// IPv6 address
- my_id_payload = IkeNewIdPayload(IKE_ID_IPV6_ADDR, 0, 0, sa->IkeClient->ServerIP.ipv6_addr, 16);
+ my_id_payload = IkeNewIdPayload(IKE_ID_IPV6_ADDR, 0, 0, sa->IkeClient->ServerIP.address, 16);
}
else
{
// IPv4 address
- my_id_payload = IkeNewIdPayload(IKE_ID_IPV4_ADDR, 0, 0, sa->IkeClient->ServerIP.addr, 4);
+ my_id_payload = IkeNewIdPayload(IKE_ID_IPV4_ADDR, 0, 0, IPV4(sa->IkeClient->ServerIP.address), IPV4_SIZE);
}
// Build the ID payload tentatively
@@ -3396,12 +3411,12 @@ void ProcIkeMainModePacketRecv(IKE_SERVER *ike, UDPPACKET *p, IKE_PACKET *header
if (IsIP6(&sa->IkeClient->ServerIP))
{
// IPv6 address
- my_id_payload = IkeNewIdPayload(IKE_ID_IPV6_ADDR, 0, 0, sa->IkeClient->ServerIP.ipv6_addr, 16);
+ my_id_payload = IkeNewIdPayload(IKE_ID_IPV6_ADDR, 0, 0, sa->IkeClient->ServerIP.address, 16);
}
else
{
// IPv4 address
- my_id_payload = IkeNewIdPayload(IKE_ID_IPV4_ADDR, 0, 0, sa->IkeClient->ServerIP.addr, 4);
+ my_id_payload = IkeNewIdPayload(IKE_ID_IPV4_ADDR, 0, 0, IPV4(sa->IkeClient->ServerIP.address), IPV4_SIZE);
}
// Build the ID payload tentatively
@@ -3672,11 +3687,11 @@ BUF *IkeCalcNatDetectHash(IKE_SERVER *ike, IKE_HASH *hash, UINT64 initiator_cook
if (IsIP6(ip))
{
- WriteBuf(b, ip->ipv6_addr, sizeof(ip->ipv6_addr));
+ WriteBuf(b, ip->address, sizeof(ip->address));
}
else
{
- WriteBuf(b, ip->addr, sizeof(ip->addr));
+ WriteBuf(b, IPV4(ip->address), IPV4_SIZE);
}
us = Endian16((USHORT)port);
diff --git a/src/Cedar/Proto_IKE.h b/src/Cedar/Proto_IKE.h
index c32b55fc..26ec8f2e 100644
--- a/src/Cedar/Proto_IKE.h
+++ b/src/Cedar/Proto_IKE.h
@@ -8,7 +8,7 @@
#ifndef PROTO_IKE_H
#define PROTO_IKE_H
-//// Macro
+#include "Proto_IkePacket.h"
//// Constants
diff --git a/src/Cedar/Proto_IPsec.c b/src/Cedar/Proto_IPsec.c
index 3128ffff..c6c5f575 100644
--- a/src/Cedar/Proto_IPsec.c
+++ b/src/Cedar/Proto_IPsec.c
@@ -5,8 +5,21 @@
// Proto_IPsec.c
// IPsec module
-#include "CedarPch.h"
+#include "Proto_IPsec.h"
+#include "Hub.h"
+#include "Proto_IKE.h"
+#include "Proto_L2TP.h"
+#include "Proto_Win7.h"
+#include "Server.h"
+
+#include "Mayaqua/Kernel.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Microsoft.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Tick64.h"
+#include "Mayaqua/Unix.h"
static bool ipsec_disable = false;
diff --git a/src/Cedar/Proto_IPsec.h b/src/Cedar/Proto_IPsec.h
index 7be62430..bfc6ce49 100644
--- a/src/Cedar/Proto_IPsec.h
+++ b/src/Cedar/Proto_IPsec.h
@@ -8,6 +8,8 @@
#ifndef PROTO_IPSEC_H
#define PROTO_IPSEC_H
+#include "Cedar.h"
+
//// Constants
// UDP port number
diff --git a/src/Cedar/Proto_IkePacket.c b/src/Cedar/Proto_IkePacket.c
index f3e837af..2b160dc7 100644
--- a/src/Cedar/Proto_IkePacket.c
+++ b/src/Cedar/Proto_IkePacket.c
@@ -5,7 +5,11 @@
// Proto_IkePacket.c
// IKE (ISAKMP) packet processing
-#include "CedarPch.h"
+#include "Proto_IkePacket.h"
+
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/TcpIp.h"
// Convert the string to a password
BUF *IkeStrToPassword(char *str)
@@ -378,11 +382,11 @@ BUF *IkeBuildNatOaPayload(IKE_PACKET_NAT_OA_PAYLOAD *t)
if (IsIP6(&t->IpAddress))
{
- WriteBuf(ret, t->IpAddress.ipv6_addr, 16);
+ WriteBuf(ret, t->IpAddress.address, sizeof(t->IpAddress.address));
}
else
{
- WriteBuf(ret, t->IpAddress.addr, 4);
+ WriteBuf(ret, IPV4(t->IpAddress.address), IPV4_SIZE);
}
return ret;
@@ -1229,8 +1233,8 @@ bool IkeParseIdPayload(IKE_PACKET_ID_PAYLOAD *t, BUF *b)
return false;
}
- Zero(&ip, sizeof(ip));
- Zero(&subnet, sizeof(subnet));
+ ZeroIP4(&ip);
+ ZeroIP4(&subnet);
// Convert to string
Zero(t->StrData, sizeof(t->StrData));
@@ -1243,9 +1247,9 @@ bool IkeParseIdPayload(IKE_PACKET_ID_PAYLOAD *t, BUF *b)
break;
case IKE_ID_IPV4_ADDR:
- if (t->IdData->Size == 4)
+ if (t->IdData->Size == IPV4_SIZE)
{
- Copy(ip.addr, t->IdData->Buf, 4);
+ Copy(IPV4(ip.address), t->IdData->Buf, IPV4_SIZE);
IPToStr(t->StrData, sizeof(t->StrData), &ip);
}
@@ -1261,12 +1265,12 @@ bool IkeParseIdPayload(IKE_PACKET_ID_PAYLOAD *t, BUF *b)
break;
case IKE_ID_IPV4_ADDR_SUBNET:
- if (t->IdData->Size == 8)
+ if (t->IdData->Size == IPV4_SIZE * 2)
{
char ipstr[MAX_SIZE];
char subnetstr[MAX_SIZE];
- Copy(ip.addr, t->IdData->Buf, 4);
- Copy(subnet.addr, ((UCHAR *)t->IdData->Buf) + 4, 4);
+ Copy(IPV4(ip.address), t->IdData->Buf, IPV4_SIZE);
+ Copy(IPV4(subnet.address), ((BYTE *)t->IdData->Buf) + IPV4_SIZE, IPV4_SIZE);
IPToStr(ipstr, sizeof(ipstr), &ip);
MaskToStr(subnetstr, sizeof(subnetstr), &subnet);
diff --git a/src/Cedar/Proto_IkePacket.h b/src/Cedar/Proto_IkePacket.h
index c02bba32..193d32ec 100644
--- a/src/Cedar/Proto_IkePacket.h
+++ b/src/Cedar/Proto_IkePacket.h
@@ -8,6 +8,11 @@
#ifndef PROTO_IKEPACKET_H
#define PROTO_IKEPACKET_H
+#include "CedarType.h"
+
+#include "Mayaqua/Mayaqua.h"
+#include "Mayaqua/Network.h"
+
// Constants
#ifdef OS_WIN32
#pragma pack(push, 1)
diff --git a/src/Cedar/Proto_L2TP.c b/src/Cedar/Proto_L2TP.c
index 6994777c..45eac6a2 100644
--- a/src/Cedar/Proto_L2TP.c
+++ b/src/Cedar/Proto_L2TP.c
@@ -5,7 +5,20 @@
// Proto_L2TP.c
// L2TP protocol stack
-#include "CedarPch.h"
+#include "Proto_L2TP.h"
+
+#include "Connection.h"
+#include "Logging.h"
+#include "Proto_EtherIP.h"
+#include "Proto_IKE.h"
+#include "Proto_IPsec.h"
+#include "Proto_PPP.h"
+
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Network.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/TcpIp.h"
// Release the L2TP AVP value
void FreeL2TPAVP(L2TP_AVP *a)
diff --git a/src/Cedar/Proto_L2TP.h b/src/Cedar/Proto_L2TP.h
index 9d83f66b..cf1d055c 100644
--- a/src/Cedar/Proto_L2TP.h
+++ b/src/Cedar/Proto_L2TP.h
@@ -8,7 +8,9 @@
#ifndef PROTO_L2TP_H
#define PROTO_L2TP_H
-//// Macro
+#include "CedarType.h"
+
+#include "Mayaqua/Network.h"
// Check the sequence number
#define L2TP_SEQ_LT(a, b) (((USHORT)(((USHORT)(a)) - ((USHORT)(b)))) & 0x8000)
diff --git a/src/Cedar/Proto_OpenVPN.c b/src/Cedar/Proto_OpenVPN.c
index a466a9c1..a1779710 100644
--- a/src/Cedar/Proto_OpenVPN.c
+++ b/src/Cedar/Proto_OpenVPN.c
@@ -5,7 +5,22 @@
// Proto_OpenVPN.c
// OpenVPN protocol stack
-#include "CedarPch.h"
+#include "Proto_OpenVPN.h"
+
+#include "Cedar.h"
+#include "Connection.h"
+#include "IPC.h"
+#include "Logging.h"
+#include "Proto_EtherIP.h"
+#include "Proto_PPP.h"
+#include "Server.h"
+
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Table.h"
+#include "Mayaqua/Tick64.h"
// Ping signature of the OpenVPN protocol
static UCHAR ping_signature[] =
@@ -20,6 +35,7 @@ const PROTO_IMPL *OvsGetProtoImpl()
{
OvsName,
OvsOptions,
+ NULL,
OvsInit,
OvsFree,
OvsIsPacketForMe,
@@ -69,16 +85,17 @@ void OvsFree(void *param)
}
// Check whether it's an OpenVPN packet
-bool OvsIsPacketForMe(const PROTO_MODE mode, const UCHAR *data, const UINT size)
+bool OvsIsPacketForMe(const PROTO_MODE mode, const void *data, const UINT size)
{
+ if (data == NULL || size < 2)
+ {
+ return false;
+ }
+
if (mode == PROTO_MODE_TCP)
{
- if (data == NULL || size < 2)
- {
- return false;
- }
-
- if (data[0] == 0x00 && data[1] == 0x0E)
+ const UCHAR *raw = data;
+ if (raw[0] == 0x00 && raw[1] == 0x0E)
{
return true;
}
@@ -2899,7 +2916,7 @@ int OvsCompareSessionList(void *p1, void *p2)
return 0;
}
- i = CmpIpAddr(&s1->Protocol, &s2->Protocol);
+ i = Cmp(&s1->Protocol, &s2->Protocol, sizeof(s1->Protocol));
if (i != 0)
{
return i;
diff --git a/src/Cedar/Proto_OpenVPN.h b/src/Cedar/Proto_OpenVPN.h
index 8a5c111d..dd851cc9 100644
--- a/src/Cedar/Proto_OpenVPN.h
+++ b/src/Cedar/Proto_OpenVPN.h
@@ -8,6 +8,7 @@
#ifndef PROTO_OPENVPN_H
#define PROTO_OPENVPN_H
+#include "Proto.h"
//// Constants
#define OPENVPN_UDP_PORT 1194 // OpenVPN default UDP port number
@@ -215,11 +216,9 @@ const char *OvsName();
const PROTO_OPTION *OvsOptions();
bool OvsInit(void **param, const LIST *options, CEDAR *cedar, INTERRUPT_MANAGER *im, SOCK_EVENT *se, const char *cipher, const char *hostname);
void OvsFree(void *param);
-bool OvsIsPacketForMe(const PROTO_MODE mode, const UCHAR *data, const UINT size);
+bool OvsIsPacketForMe(const PROTO_MODE mode, const void *data, const UINT size);
bool OvsProcessData(void *param, TCP_RAW_DATA *in, FIFO *out);
bool OvsProcessDatagrams(void *param, LIST *in, LIST *out);
-bool OvsIsOk(void *param);
-UINT OvsEstablishedSessions(void *param);
OPENVPN_SERVER *NewOpenVpnServer(const LIST *options, CEDAR *cedar, INTERRUPT_MANAGER *interrupt, SOCK_EVENT *sock_event);
void FreeOpenVpnServer(OPENVPN_SERVER *s);
diff --git a/src/Cedar/Proto_PPP.c b/src/Cedar/Proto_PPP.c
index 9542cf09..b99c0775 100644
--- a/src/Cedar/Proto_PPP.c
+++ b/src/Cedar/Proto_PPP.c
@@ -5,7 +5,22 @@
// Proto_PPP.c
// PPP protocol stack
-#include "CedarPch.h"
+#include "Proto_PPP.h"
+
+#include "Account.h"
+#include "Cedar.h"
+#include "Connection.h"
+#include "Hub.h"
+#include "IPC.h"
+#include "Logging.h"
+#include "Proto_IPsec.h"
+#include "Radius.h"
+#include "Server.h"
+
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Tick64.h"
// PPP main thread
void PPPThread(THREAD *thread, void *param)
@@ -1519,7 +1534,7 @@ bool PPPProcessPAPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
// Attempt to connect with IPC
UINT error_code;
- ipc = NewIPC(p->Cedar, p->ClientSoftwareName, p->Postfix, hub, id, password,
+ ipc = NewIPC(p->Cedar, p->ClientSoftwareName, p->Postfix, hub, id, password, NULL,
&error_code, &p->ClientIP, p->ClientPort, &p->ServerIP, p->ServerPort,
p->ClientHostname, p->CryptName, false, p->AdjustMss, NULL, NULL,
IPC_LAYER_3);
@@ -2844,7 +2859,7 @@ bool PPPParseMSCHAP2ResponsePacket(PPP_SESSION *p, PPP_PACKET *pp)
else if (p->Ipc == NULL)
{
Debug("MSCHAPv2 creating IPC\n");
- ipc = NewIPC(p->Cedar, p->ClientSoftwareName, p->Postfix, hub, id, password,
+ ipc = NewIPC(p->Cedar, p->ClientSoftwareName, p->Postfix, hub, id, password, NULL,
&error_code, &p->ClientIP, p->ClientPort, &p->ServerIP, p->ServerPort,
p->ClientHostname, p->CryptName, false, p->AdjustMss, p->EapClient, NULL,
+ IPC_LAYER_3);
@@ -3252,7 +3267,7 @@ bool PPPProcessEAPTlsResponse(PPP_SESSION *p, PPP_EAP *eap_packet, UINT eapTlsSi
PPPParseUsername(p->Cedar, p->Eap_Identity, &d);
- ipc = NewIPC(p->Cedar, p->ClientSoftwareName, p->Postfix, d.HubName, d.UserName, "",
+ ipc = NewIPC(p->Cedar, p->ClientSoftwareName, p->Postfix, d.HubName, d.UserName, "", NULL,
&error_code, &p->ClientIP, p->ClientPort, &p->ServerIP, p->ServerPort,
p->ClientHostname, p->CryptName, false, p->AdjustMss, NULL, p->Eap_TlsCtx.ClientCert.X,
IPC_LAYER_3);
diff --git a/src/Cedar/Proto_PPP.h b/src/Cedar/Proto_PPP.h
index 8414fec9..47ac9ebb 100644
--- a/src/Cedar/Proto_PPP.h
+++ b/src/Cedar/Proto_PPP.h
@@ -8,6 +8,9 @@
#ifndef PROTO_PPP_H
#define PROTO_PPP_H
+#include "CedarType.h"
+
+#include "Mayaqua/TcpIp.h"
//// Macro
#define PPP_LCP_CODE_IS_NEGATIVE(c) ((c) == PPP_LCP_CODE_NAK || (c) == PPP_LCP_CODE_REJECT || (c) == PPP_LCP_CODE_CODE_REJECT || (c) == PPP_LCP_CODE_PROTOCOL_REJECT)
diff --git a/src/Cedar/Proto_SSTP.c b/src/Cedar/Proto_SSTP.c
index 514ddeda..64664f53 100644
--- a/src/Cedar/Proto_SSTP.c
+++ b/src/Cedar/Proto_SSTP.c
@@ -5,7 +5,17 @@
// Proto_SSTP.c
// SSTP (Microsoft Secure Socket Tunneling Protocol) protocol stack
-#include "CedarPch.h"
+#include "Proto_SSTP.h"
+
+#include "Connection.h"
+#include "Proto_PPP.h"
+#include "Server.h"
+
+#include "Mayaqua/HTTP.h"
+#include "Mayaqua/Kernel.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Tick64.h"
const PROTO_IMPL *SstpGetProtoImpl()
{
@@ -13,6 +23,7 @@ const PROTO_IMPL *SstpGetProtoImpl()
{
SstpName,
SstpOptions,
+ NULL,
SstpInit,
SstpFree,
NULL,
diff --git a/src/Cedar/Proto_SSTP.h b/src/Cedar/Proto_SSTP.h
index adb0347a..ca341ee4 100644
--- a/src/Cedar/Proto_SSTP.h
+++ b/src/Cedar/Proto_SSTP.h
@@ -8,6 +8,8 @@
#ifndef PROTO_SSTP_H
#define PROTO_SSTP_H
+#include "Proto.h"
+
//// Constants
#define SSTP_URI "/sra_{BA195980-CD49-458b-9E23-C84EE0ADCD75}/" // SSTP HTTPS URI
#define SSTP_VERSION_1 0x10 // SSTP Version 1.0
diff --git a/src/Cedar/Proto_Win7.c b/src/Cedar/Proto_Win7.c
index 48b23aee..98397503 100644
--- a/src/Cedar/Proto_Win7.c
+++ b/src/Cedar/Proto_Win7.c
@@ -5,39 +5,26 @@
// Proto_Win7.c
// Initialize the helper module for Windows 7 / Windows 8 / Windows Vista / Windows Server 2008 / Windows Server 2008 R2 / Windows Server 2012 / Windows 10
-#include
+#ifdef OS_WIN32
-#ifdef WIN32
+#include "Proto_Win7.h"
+
+#include "Mayaqua/Cfg.h"
+#include "Mayaqua/FileIO.h"
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Microsoft.h"
+#include "Mayaqua/Str.h"
-#define _WIN32_WINNT 0x0600
-#define WINVER 0x0600
-#define INITGUID
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include "Proto_Win7Inner.h"
#include
+#include
+
+#include
+
static IPSEC_WIN7_FUNCTIONS *api = NULL;
static HINSTANCE hDll = NULL;
-
// Initialize the IPsec helper module for Windows 7
IPSEC_WIN7 *IPsecWin7Init()
{
@@ -49,11 +36,6 @@ IPSEC_WIN7 *IPsecWin7Init()
Debug("IPsecWin7Init()\n");
- if (MsIsVista() == false)
- {
- return NULL;
- }
-
if (MsIsAdmin() == false)
{
return NULL;
@@ -173,12 +155,12 @@ void IPsecWin7UpdateHostIPAddressList(IPSEC_WIN7 *w)
if (IsIP4(ip))
{
a.IpVersion = 4;
- Copy(a.IpAddress.IPv4Address, ip->addr, 4);
+ Copy(a.IpAddress.IPv4Address, IPV4(ip->address), sizeof(a.IpAddress.IPv4Address));
}
else
{
a.IpVersion = 6;
- Copy(a.IpAddress.IPv6Address, ip->ipv6_addr, 16);
+ Copy(a.IpAddress.IPv6Address, ip->address, sizeof(a.IpAddress.IPv6Address));
}
WriteBuf(buf, &a, sizeof(WFP_LOCAL_IP));
diff --git a/src/Cedar/Proto_Win7.h b/src/Cedar/Proto_Win7.h
index 33d585b1..0c7bf9d1 100644
--- a/src/Cedar/Proto_Win7.h
+++ b/src/Cedar/Proto_Win7.h
@@ -8,6 +8,9 @@
#ifndef PROTO_WIN7_H
#define PROTO_WIN7_H
+#include "Proto_IPsec.h"
+#include "Proto_Win7Inner.h"
+
// Constants
#define IPSEC_WIN7_SRC_SYS_X86 "|pxwfp_x86.sys"
#define IPSEC_WIN7_SRC_SYS_X64 "|pxwfp_x64.sys"
diff --git a/src/Cedar/Proto_Win7Inner.h b/src/Cedar/Proto_Win7Inner.h
index 7a8767be..615a6786 100644
--- a/src/Cedar/Proto_Win7Inner.h
+++ b/src/Cedar/Proto_Win7Inner.h
@@ -5,8 +5,15 @@
// Proto_Win7Inner.h
// Internal header of Proto_Win7.c
-#ifndef PROTO_WIN7_INNER_H
-#define PROTO_WIN7_INNER_H
+#ifdef OS_WIN32
+
+#ifndef PROTO_WIN7_INNER_H
+#define PROTO_WIN7_INNER_H
+
+#include "Mayaqua/MayaType.h"
+
+#include
+#include
// API function
typedef struct IPSEC_WIN7_FUNCTIONS
@@ -74,4 +81,6 @@ struct IPSEC_WIN7
};
-#endif // PROTO_WIN7_INNER_H
+#endif // PROTO_WIN7_INNER_H
+
+#endif // OS_WIN32
diff --git a/src/Cedar/Proto_WireGuard.c b/src/Cedar/Proto_WireGuard.c
new file mode 100644
index 00000000..dfb40779
--- /dev/null
+++ b/src/Cedar/Proto_WireGuard.c
@@ -0,0 +1,1098 @@
+#include "Proto_WireGuard.h"
+
+#include "Connection.h"
+#include "IPC.h"
+#include "Logging.h"
+
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Table.h"
+#include "Mayaqua/Tick64.h"
+
+#include
+
+const PROTO_IMPL *WgsGetProtoImpl()
+{
+ static const PROTO_IMPL impl =
+ {
+ WgsName,
+ WgsOptions,
+ WgsOptionStringValue,
+ WgsInit,
+ WgsFree,
+ WgsIsPacketForMe,
+ NULL,
+ WgsProcessDatagrams
+ };
+
+ return &impl;
+}
+
+const char *WgsName()
+{
+ return "WireGuard";
+}
+
+const PROTO_OPTION *WgsOptions()
+{
+ static const PROTO_OPTION options[] =
+ {
+ { .Name = "PresharedKey", .Type = PROTO_OPTION_STRING, .String = NULL},
+ { .Name = "PrivateKey", .Type = PROTO_OPTION_STRING, .String = NULL },
+ { .Name = NULL, .Type = PROTO_OPTION_UNKNOWN }
+ };
+
+ return options;
+}
+
+char *WgsOptionStringValue(const char *name)
+{
+ if (name == NULL)
+ {
+ return NULL;
+ }
+
+ if (StrCmp(name, "PresharedKey") == 0 || StrCmp(name, "PrivateKey") == 0)
+ {
+ unsigned char buf[WG_KEY_SIZE];
+ const UINT size = sodium_base64_ENCODED_LEN(sizeof(buf), sodium_base64_VARIANT_ORIGINAL);
+ char *str = Malloc(size);
+ Rand(buf, sizeof(buf));
+ sodium_bin2base64(str, size, buf, sizeof(buf), sodium_base64_VARIANT_ORIGINAL);
+ Zero(buf, sizeof(buf));
+ return str;
+ }
+
+ return NULL;
+}
+
+bool WgsInit(void **param, const LIST *options, CEDAR *cedar, INTERRUPT_MANAGER *im, SOCK_EVENT *se, const char *cipher, const char *hostname)
+{
+ UINT i;
+ WG_SERVER *server;
+
+ if (param == NULL || options == NULL || cedar == NULL || im == NULL || se == NULL)
+ {
+ return false;
+ }
+
+ Debug("WgsInit(): cipher: %s, hostname: %s\n", cipher, hostname);
+
+ server = ZeroMalloc(sizeof(WG_SERVER));
+
+ for (i = 0; i < LIST_NUM(options); ++i)
+ {
+ const PROTO_OPTION *option = LIST_DATA(options, i);
+ if (StrCmp(option->Name, "PresharedKey") == 0)
+ {
+ if (IsEmptyStr(option->String) == false)
+ {
+ sodium_base642bin(server->PresharedKey, sizeof(server->PresharedKey), option->String, StrLen(option->String), NULL, NULL, NULL, sodium_base64_VARIANT_ORIGINAL);
+ }
+ }
+ else if (StrCmp(option->Name, "PrivateKey") == 0)
+ {
+ sodium_base642bin(server->StaticPrivate, sizeof(server->StaticPrivate), option->String, StrLen(option->String), NULL, NULL, NULL, sodium_base64_VARIANT_ORIGINAL);
+ crypto_scalarmult_curve25519_base(server->StaticPublic, server->StaticPrivate);
+ }
+ }
+
+ server->Cedar = cedar;
+ server->SockEvent = se;
+ server->InterruptManager = im;
+
+ blake2s(server->HandshakeInitChainingKey, sizeof(server->HandshakeInitChainingKey), WG_CONSTRUCTION, StrLen(WG_CONSTRUCTION), NULL, 0);
+
+ blake2s_state b2s_state;
+ blake2s_init(&b2s_state, sizeof(server->HandshakeInitHash));
+ blake2s_update(&b2s_state, server->HandshakeInitChainingKey, sizeof(server->HandshakeInitChainingKey));
+ blake2s_update(&b2s_state, WG_IDENTIFIER, StrLen(WG_IDENTIFIER));
+ blake2s_final(&b2s_state, server->HandshakeInitHash, sizeof(server->HandshakeInitHash));
+
+ server->CreationTime = Tick64();
+ AddInterrupt(im, server->CreationTime + WG_INITIATION_GIVEUP);
+
+ *param = server;
+
+ return true;
+}
+
+void WgsFree(void *param)
+{
+ WG_SERVER *server = param;
+ WG_SESSION *session;
+ WG_KEYPAIRS *keypairs;
+
+ if (server == NULL)
+ {
+ return;
+ }
+
+ session = &server->Session;
+ keypairs = &session->Keypairs;
+
+ FreeIPC(session->IPC);
+
+ Zero(keypairs->Current, sizeof(WG_KEYPAIR));
+ Free(keypairs->Current);
+
+ Zero(keypairs->Next, sizeof(WG_KEYPAIR));
+ Free(keypairs->Next);
+
+ Zero(keypairs->Previous, sizeof(WG_KEYPAIR));
+ Free(keypairs->Previous);
+
+ Zero(server, sizeof(WG_SERVER));
+ Free(server);
+}
+
+bool WgsIsPacketForMe(const PROTO_MODE mode, const void *data, const UINT size)
+{
+ if (mode != PROTO_MODE_UDP)
+ {
+ return false;
+ }
+
+ return WgsDetectMessageType(data, size);
+}
+
+bool WgsProcessDatagrams(void *param, LIST *in, LIST *out)
+{
+ UINT i;
+ WG_SERVER *server = param;
+ WG_SESSION *session;
+ WG_KEYPAIRS *keypairs;
+
+ if (server == NULL || in == NULL || out == NULL)
+ {
+ return false;
+ }
+
+ server->Now = Tick64();
+
+ session = &server->Session;
+ keypairs = &session->Keypairs;
+
+ if (keypairs->Current != NULL)
+ {
+ const WG_KEYPAIR *current = keypairs->Current;
+ if (server->Now - current->CreationTime >= WG_REJECT_AFTER_TIME)
+ {
+ WgsLog(server, "LW_KEYPAIR_EXPIRED", current->IndexRemote, current->IndexLocal);
+ return false;
+ }
+ }
+ else if (server->Now - server->CreationTime >= WG_INITIATION_GIVEUP)
+ {
+ Debug("WgsProcessDatagrams(): current keypair not present, giving up!\n");
+ return false;
+ }
+
+ if (keypairs->Previous != NULL)
+ {
+ WG_KEYPAIR *previous = keypairs->Previous;
+ if (server->Now - previous->CreationTime >= WG_REJECT_AFTER_TIME)
+ {
+ Debug("WgsProcessDatagrams(): deleting keypair: %x -> %x\n", previous->IndexRemote, previous->IndexLocal);
+ Zero(previous, sizeof(WG_KEYPAIR));
+ Free(previous);
+ keypairs->Previous = NULL;
+ }
+ }
+
+ for (i = 0; i < LIST_NUM(in); ++i)
+ {
+ const UDPPACKET *packet = LIST_DATA(in, i);
+ const UINT size = packet->Size;
+ void *data = packet->Data;
+
+ const WG_MSG_TYPE message_type = WgsDetectMessageType(data, size);
+ switch (message_type)
+ {
+ case WG_MSG_HANDSHAKE_INIT:
+ {
+ WG_KEYPAIR *keypair;
+ UDPPACKET *udp_reply;
+ WG_HANDSHAKE_REPLY *reply;
+ BYTE ephemeral_remote[WG_KEY_SIZE];
+
+ if (session->LastInitiationReceived + 1000 / WG_MAX_INITIATIONS_PER_SECOND > server->Now)
+ {
+ WgsLog(server, "LW_FLOOD_ATTACK");
+ return false;
+ }
+
+ session->LastInitiationReceived = server->Now;
+
+ keypair = WgsProcessHandshakeInit(server, data, ephemeral_remote);
+ if (keypair == NULL)
+ {
+ Debug("WgsProcessDatagrams(): WgsProcessHandshakeInit() failed!\n");
+ Zero(ephemeral_remote, sizeof(ephemeral_remote));
+ return false;
+ }
+
+ reply = WgsCreateHandshakeReply(server, keypair, ephemeral_remote);
+
+ Zero(ephemeral_remote, sizeof(ephemeral_remote));
+
+ if (reply == NULL)
+ {
+ Debug("WgsProcessDatagrams(): WgsCreateHandshakeReply() failed!\n");
+ Zero(keypair, sizeof(WG_KEYPAIR));
+ Free(keypair);
+ return false;
+ }
+
+ Copy(&session->IPLocal, &packet->DstIP, sizeof(session->IPLocal));
+ Copy(&session->IPRemote, &packet->SrcIP, sizeof(session->IPRemote));
+ session->PortLocal = packet->DestPort;
+ session->PortRemote = packet->SrcPort;
+
+ udp_reply = NewUdpPacket(&session->IPLocal, session->PortLocal, &session->IPRemote, session->PortRemote, reply, sizeof(WG_HANDSHAKE_REPLY));
+ Add(out, udp_reply);
+
+ AddInterrupt(server->InterruptManager, keypair->CreationTime + WG_REJECT_AFTER_TIME);
+ break;
+ }
+ case WG_MSG_HANDSHAKE_COOKIE:
+ // TODO: reply to message.
+ continue;
+ case WG_MSG_TRANSPORT_DATA:
+ if (keypairs->Current == NULL)
+ {
+ continue;
+ }
+
+ if (WgsProcessTransportData(server, data, size) == false)
+ {
+ Debug("WgsProcessDatagrams(): WgsProcessTransportData() failed!\n");
+ return false;
+ }
+
+ session->LastDataReceived = server->Now;
+ break;
+ default:
+ Debug("WgsProcessDatagrams(): unrecognized packet type %u\n", message_type);
+ return false;
+ }
+ }
+
+ if (session->IPC == NULL)
+ {
+ return true;
+ }
+
+ if (IsIPCConnected(session->IPC) == false)
+ {
+ WgsLog(server, "LW_HUB_DISCONNECT");
+ return false;
+ }
+
+ IPCProcessL3Events(session->IPC);
+
+ while (true)
+ {
+ UDPPACKET *udp;
+ UINT final_size = 0;
+ WG_TRANSPORT_DATA *data;
+ BLOCK *block = IPCRecvIPv4(session->IPC);
+ if (block == NULL)
+ {
+ break;
+ }
+
+ data = WgsCreateTransportData(server, block->Buf, block->Size, &final_size);
+
+ FreeBlock(block);
+
+ if (data == NULL)
+ {
+ continue;
+ }
+
+ udp = NewUdpPacket(&session->IPLocal, session->PortLocal, &session->IPRemote, session->PortRemote, data, final_size);
+ Add(out, udp);
+ }
+
+ if (LIST_NUM(out) > 0)
+ {
+ session->LastDataSent = server->Now;
+ }
+ else if (session->LastDataReceived >= session->LastDataSent)
+ {
+ if (server->Now - session->LastDataSent >= WG_KEEPALIVE_TIMEOUT)
+ {
+ UINT final_size = 0;
+ WG_TRANSPORT_DATA *data = WgsCreateTransportData(server, NULL, 0, &final_size);
+ UDPPACKET *udp = NewUdpPacket(&session->IPLocal, session->PortLocal, &session->IPRemote, session->PortRemote, data, final_size);
+ Add(out, udp);
+
+ Debug("WgsProcessDatagrams(): sending keepalive packet\n");
+
+ session->LastDataSent = server->Now;
+
+ // Schedule next keepalive.
+ AddInterrupt(server->InterruptManager, server->Now + WG_KEEPALIVE_TIMEOUT);
+ }
+ }
+
+ return true;
+}
+
+void WgsLog(const WG_SERVER *server, const char *name, ...)
+{
+ wchar_t message[MAX_SIZE * 2];
+ const WG_SESSION *session;
+ UINT current_len;
+ va_list args;
+
+ if (server == NULL)
+ {
+ return;
+ }
+
+ session = &server->Session;
+
+ UniFormat(message, sizeof(message), _UU("LW_PREFIX_SESSION"), &session->IPRemote, session->PortRemote, &session->IPLocal, session->PortLocal);
+
+ current_len = UniStrLen(message);
+
+ va_start(args, name);
+ UniFormatArgs(message + current_len, sizeof(message) - current_len, _UU(name), args);
+ va_end(args);
+
+ WriteServerLog(server->Cedar, message);
+}
+
+WG_MSG_TYPE WgsDetectMessageType(const void *data, const UINT size)
+{
+ const WG_COMMON *packet = data;
+
+ if (packet == NULL || size < sizeof(WG_COMMON))
+ {
+ return WG_MSG_INVALID;
+ }
+
+ switch (packet->Header.Type)
+ {
+ case WG_MSG_HANDSHAKE_INIT:
+ if (size != sizeof(WG_HANDSHAKE_INIT))
+ {
+ return WG_MSG_INVALID;
+ }
+
+ break;
+ case WG_MSG_HANDSHAKE_REPLY:
+ if (size != sizeof(WG_HANDSHAKE_REPLY))
+ {
+ return WG_MSG_INVALID;
+ }
+
+ break;
+ case WG_MSG_HANDSHAKE_COOKIE:
+ if (size != sizeof(WG_COOKIE_REPLY))
+ {
+ return WG_MSG_INVALID;
+ }
+
+ break;
+ case WG_MSG_TRANSPORT_DATA:
+ if (size < sizeof(WG_TRANSPORT_DATA) + WG_AEAD_SIZE(0))
+ {
+ return WG_MSG_INVALID;
+ }
+
+ break;
+ default:
+ return WG_MSG_INVALID;
+ }
+
+ if (IsZero(packet->Header.Reserved, sizeof(packet->Header.Reserved)) == false)
+ {
+ return WG_MSG_INVALID;
+ }
+
+ if (packet->Index == 0)
+ {
+ return WG_MSG_INVALID;
+ }
+
+ return packet->Header.Type;
+}
+
+UINT WgsMSS(const WG_SESSION *session)
+{
+ UINT ret = MTU_FOR_PPPOE;
+
+ if (session == NULL)
+ {
+ return 0;
+ }
+
+ // IPv4 / IPv6
+ if (IsIP4(&session->IPRemote))
+ {
+ ret -= 20;
+ }
+ else
+ {
+ ret -= 40;
+ }
+
+ // UDP
+ ret -= 8;
+
+ // WireGuard packet
+ ret -= sizeof(WG_TRANSPORT_DATA);
+
+ // Inner IPv4
+ ret -= 20;
+
+ // Inner TCP
+ ret -= 20;
+
+ return ret;
+}
+
+IPC *WgsIPCNew(WG_SERVER *server)
+{
+ UINT err;
+ IPC *ipc;
+ IPC_PARAM param;
+ WG_SESSION *session;
+
+ if (server == NULL)
+ {
+ return NULL;
+ }
+
+ session = &server->Session;
+
+ Zero(¶m, sizeof(param));
+
+ StrCpy(param.ClientName, sizeof(param.ClientName), WgsName());
+ StrCpy(param.Postfix, sizeof(param.Postfix), WG_IPC_POSTFIX);
+
+ sodium_bin2base64(param.WgKey, sizeof(param.WgKey), session->StaticRemote, sizeof(session->StaticRemote), sodium_base64_VARIANT_ORIGINAL);
+
+ Copy(¶m.ServerIp, &session->IPLocal, sizeof(param.ServerIp));
+ Copy(¶m.ClientIp, &session->IPRemote, sizeof(param.ClientIp));
+ param.ServerPort = session->PortLocal;
+ param.ClientPort = session->PortRemote;
+
+ StrCpy(param.CryptName, sizeof(param.CryptName), WG_CIPHER);
+
+ param.Layer = IPC_LAYER_3;
+ param.Mss = WgsMSS(session);
+
+ ipc = NewIPCByParam(server->Cedar, ¶m, &err);
+ if (ipc == NULL)
+ {
+ Debug("WgsIPCNew(): NewIPCByParam() failed with error %u!\n", err);
+ }
+
+ return ipc;
+}
+
+WG_KEYPAIR *WgsProcessHandshakeInit(WG_SERVER *server, const WG_HANDSHAKE_INIT *init, BYTE *ephemeral_remote)
+{
+ WG_SESSION *session;
+ WG_KEYPAIR *keypair = NULL;
+ BYTE hash[WG_HASH_SIZE];
+ BYTE key[WG_KEY_SIZE];
+ BYTE chaining_key[WG_HASH_SIZE];
+ BYTE timestamp[WG_TIMESTAMP_SIZE];
+ BYTE static_remote[WG_KEY_SIZE];
+
+ if (server == NULL || init == NULL || ephemeral_remote == NULL)
+ {
+ return NULL;
+ }
+
+ session = &server->Session;
+
+ Copy(hash, server->HandshakeInitHash, sizeof(server->HandshakeInitHash));
+ Copy(chaining_key, server->HandshakeInitChainingKey, sizeof(server->HandshakeInitChainingKey));
+ WgsMixHash(hash, server->StaticPublic, sizeof(server->StaticPublic));
+
+ WgsEphemeral(ephemeral_remote, init->UnencryptedEphemeral, chaining_key, hash);
+
+ if (WgsMixDh(chaining_key, key, server->StaticPrivate, ephemeral_remote) == 0)
+ {
+ Debug("WgsProcessHandshakeInit(): WgsMixDh() failed!\n");
+ goto FINAL;
+ }
+
+ if (WgsDecryptWithHash(static_remote, init->EncryptedStatic, sizeof(init->EncryptedStatic), hash, key) == false)
+ {
+ Debug("WgsProcessHandshakeInit(): WgsDecryptWithHash() failed to decrypt the static key!\n");
+ goto FINAL;
+ }
+
+ if (IsZero(session->StaticRemote, sizeof(session->StaticRemote)) == false)
+ {
+ if (Cmp(static_remote, session->StaticRemote, sizeof(static_remote)) != 0)
+ {
+ Debug("WgsProcessHandshakeInit(): static remote key doesn't match!\n");
+ goto FINAL;
+ }
+ }
+
+ if (IsZero(session->PrecomputedStaticStatic, sizeof(session->PrecomputedStaticStatic)))
+ {
+ Debug("WgsProcessHandshakeInit(): precomputing static static...\n");
+ if (crypto_scalarmult_curve25519(session->PrecomputedStaticStatic, server->StaticPrivate, static_remote) != 0)
+ {
+ Debug("WgsProcessHandshakeInit(): crypto_scalarmult_curve25519() failed!\n");
+ goto FINAL;
+ }
+ }
+
+ WgsHKDF(chaining_key, key, NULL, session->PrecomputedStaticStatic, sizeof(session->PrecomputedStaticStatic), chaining_key);
+
+ if (WgsDecryptWithHash(×tamp, init->EncryptedTimestamp, sizeof(init->EncryptedTimestamp), hash, key) == false)
+ {
+ Debug("WgsProcessHandshakeInit(): WgsDecrypt() failed to decrypt the timestamp!\n");
+ goto FINAL;
+ }
+
+ if (Cmp(×tamp, session->LastTimestamp, sizeof(timestamp) <= 0))
+ {
+ WgsLog(server, "LW_REPLAY_ATTACK");
+ goto FINAL;
+ }
+
+ Copy(session->LastTimestamp, ×tamp, sizeof(session->LastTimestamp));
+
+ Copy(session->Hash, hash, sizeof(session->Hash));
+ Copy(session->ChainingKey, chaining_key, sizeof(session->ChainingKey));
+ Copy(session->StaticRemote, static_remote, sizeof(session->StaticRemote));
+
+ keypair = ZeroMalloc(sizeof(WG_KEYPAIR));
+ keypair->State = WG_KEYPAIR_INITIATED;
+ keypair->CreationTime = server->Now;
+ keypair->IndexLocal = Rand32();
+ keypair->IndexRemote = init->SenderIndex;
+FINAL:
+ Zero(key, sizeof(key));
+ Zero(hash, sizeof(hash));
+ Zero(chaining_key, sizeof(chaining_key));
+ Zero(static_remote, sizeof(static_remote));
+
+ return keypair;
+}
+
+WG_HANDSHAKE_REPLY *WgsCreateHandshakeReply(WG_SERVER *server, WG_KEYPAIR *keypair, const BYTE *ephemeral_remote)
+{
+ bool ok = false;
+ WG_SESSION *session;
+ WG_HANDSHAKE_REPLY *ret;
+ BYTE hash[WG_HASH_SIZE];
+ BYTE key[WG_KEY_SIZE];
+ BYTE ephemeral[WG_KEY_SIZE];
+
+ if (server == NULL || keypair == NULL || ephemeral_remote == NULL)
+ {
+ return NULL;
+ }
+
+ if (keypair->State != WG_KEYPAIR_INITIATED)
+ {
+ Debug("WgsCreateHandshakeReply(): unexpected keypair state %u!\n", keypair->State);
+ return NULL;
+ }
+
+ session = &server->Session;
+
+ ret = ZeroMalloc(sizeof(WG_HANDSHAKE_REPLY));
+ ret->Header.Type = WG_MSG_HANDSHAKE_REPLY;
+ ret->SenderIndex = keypair->IndexLocal;
+ ret->ReceiverIndex = keypair->IndexRemote;
+
+ crypto_box_curve25519xsalsa20poly1305_keypair(ret->UnencryptedEphemeral, ephemeral);
+
+ WgsEphemeral(ret->UnencryptedEphemeral, ret->UnencryptedEphemeral, session->ChainingKey, session->Hash);
+
+ if (WgsMixDh(session->ChainingKey, NULL, ephemeral, ephemeral_remote) == 0)
+ {
+ Debug("WgsCreateHandshakeReply(): WgsMixDh() failed to mix ephemeral public!\n");
+ goto FINAL;
+ }
+
+ if (WgsMixDh(session->ChainingKey, NULL, ephemeral, session->StaticRemote) == 0)
+ {
+ Debug("WgsCreateHandshakeReply(): WgsMixDh() failed to mix static public!\n");
+ goto FINAL;
+ }
+
+ WgsHKDF(session->ChainingKey, hash, key, server->PresharedKey, sizeof(server->PresharedKey), session->ChainingKey);
+ WgsMixHash(session->Hash, hash, sizeof(hash));
+
+ if (WgsEncryptWithHash(ret->EncryptedNothing, NULL, 0, session->Hash, key) == false)
+ {
+ Debug("WgsCreateHandshakeReply(): WgsEncryptWithHash() failed!\n");
+ goto FINAL;
+ }
+
+ WgsMixHash(session->Hash, ret->EncryptedNothing, sizeof(ret->EncryptedNothing));
+
+ blake2s_state blake;
+ blake2s_init(&blake, sizeof(key));
+ blake2s_update(&blake, WG_LABEL_MAC1, StrLen(WG_LABEL_MAC1));
+ blake2s_update(&blake, session->StaticRemote, sizeof(session->StaticRemote));
+ blake2s_final(&blake, key, sizeof(key));
+
+ blake2s(ret->Macs.Mac1, sizeof(ret->Macs.Mac1), ret, sizeof(WG_HANDSHAKE_REPLY) - sizeof(WG_MACS), key, sizeof(key));
+
+ ok = true;
+FINAL:
+ Zero(key, sizeof(key));
+ Zero(hash, sizeof(hash));
+ Zero(ephemeral, sizeof(ephemeral));
+
+ if (ok)
+ {
+ WG_KEYPAIRS *keypairs = &session->Keypairs;
+
+ WgsHKDF(keypair->KeyRemote, keypair->KeyLocal, NULL, NULL, 0, session->ChainingKey);
+ keypair->State = WG_KEYPAIR_CONFIRMED;
+
+ Debug("WgsCreateHandshakeReply(): new keypair available: %x -> %x\n", keypair->IndexRemote, keypair->IndexLocal);
+
+ if (keypairs->Next != NULL)
+ {
+ WG_KEYPAIR *next = keypairs->Next;
+ Debug("WgsCreateHandshakeReply(): deleting keypair: %x -> %x\n", next->IndexRemote, next->IndexLocal);
+ Zero(next, sizeof(WG_KEYPAIR));
+ Free(next);
+ }
+
+ if (keypairs->Current == NULL)
+ {
+ Debug("WgsCreateHandshakeReply(): switched to keypair: %x -> %x\n", keypair->IndexRemote, keypair->IndexLocal);
+ keypairs->Current = keypair;
+ keypairs->Next = NULL;
+ return ret;
+ }
+
+ keypairs->Next = keypair;
+ return ret;
+ }
+
+ Zero(ret, sizeof(WG_HANDSHAKE_REPLY));
+ Free(ret);
+
+ return NULL;
+}
+
+bool WgsProcessTransportData(WG_SERVER *server, WG_TRANSPORT_DATA *data, const UINT size)
+{
+ UINT written;
+ UINT encrypted_size;
+ WG_KEYPAIR *keypair;
+ WG_KEYPAIRS *keypairs;
+
+ if (server == NULL || data == NULL || size < sizeof(WG_TRANSPORT_DATA))
+ {
+ return false;
+ }
+
+ encrypted_size = size - sizeof(WG_TRANSPORT_DATA);
+ if (encrypted_size < WG_TAG_SIZE)
+ {
+ return false;
+ }
+
+ keypairs = &server->Session.Keypairs;
+ keypair = keypairs->Current;
+
+ if (data->ReceiverIndex != keypair->IndexLocal)
+ {
+ WG_KEYPAIR *previous = keypairs->Previous;
+
+ if (keypairs->Next != NULL && data->ReceiverIndex == keypairs->Next->IndexLocal)
+ {
+ if (previous != NULL)
+ {
+ Debug("WgsProcessTransportData(): deleting keypair: %x -> %x\n", previous->IndexRemote, previous->IndexLocal);
+ Zero(previous, sizeof(WG_KEYPAIR));
+ Free(previous);
+ }
+
+ keypairs->Previous = keypair;
+ keypairs->Current = keypair = keypairs->Next;
+ keypairs->Next = NULL;
+ Debug("WgsProcessTransportData(): switched to keypair: %x -> %x\n", keypair->IndexRemote, keypair->IndexLocal);
+ }
+ else if (previous != NULL && data->ReceiverIndex == previous->IndexLocal)
+ {
+ keypair = previous;
+ }
+ else
+ {
+ WgsLog(server, "LW_KEYPAIR_UNKNOWN");
+ return false;
+ }
+ }
+
+ if (WgsIsInReplayWindow(keypair, data->Counter))
+ {
+ WgsLog(server, "LW_REPLAY_ATTACK");
+ return false;
+ }
+
+ written = WgsDecryptData(keypair->KeyRemote, data->Counter, data->EncapsulatedPacket, data->EncapsulatedPacket, encrypted_size);
+ if (written == INFINITE)
+ {
+ WgsLog(server, "LW_DECRYPT_FAIL");
+ return false;
+ }
+
+ if (data->Counter > WG_REJECT_AFTER_MESSAGES)
+ {
+ WgsLog(server, "LW_KEYPAIR_EXPIRED", keypair->IndexRemote, keypair->IndexLocal);
+ return false;
+ }
+
+ WgsUpdateReplayWindow(keypair, data->Counter);
+
+ if (written > 0)
+ {
+ WG_SESSION *session = &server->Session;
+ if (session->IPC == NULL)
+ {
+ IP ip;
+ PKT pkt;
+ IPC *ipc;
+
+ ipc = WgsIPCNew(server);
+ if (ipc == NULL)
+ {
+ Debug("WgsProcessTransportData(): WgsCreateIPC() returned NULL!\n");
+ return false;
+ }
+
+ if (ParsePacketIPv4(&pkt, data->EncapsulatedPacket, written) == false)
+ {
+ Debug("WgsProcessTransportData(): ParsePacketIPv4() failed!\n");
+ return false;
+ }
+
+ UINTToIP(&ip, pkt.L3.IPv4Header->SrcIP);
+ IPCSetIPv4Parameters(ipc, &ip, &ipc->SubnetMask, &ipc->DefaultGateway, NULL);
+
+ IPCSetSockEventWhenRecvL2Packet(ipc, server->SockEvent);
+
+ IPC_PROTO_SET_STATUS(ipc, IPv4State, IPC_PROTO_STATUS_OPENED);
+
+ session->IPC = ipc;
+ }
+
+ IPCSendIPv4(session->IPC, data->EncapsulatedPacket, written);
+ }
+
+ return true;
+}
+
+WG_TRANSPORT_DATA *WgsCreateTransportData(WG_SERVER *server, const void *data, const UINT size, UINT *final_size)
+{
+ UINT pad_size;
+ UINT encrypted_size;
+ WG_KEYPAIR *keypair;
+ WG_TRANSPORT_DATA *ret;
+
+ if (server == NULL || (data == NULL && size > 0) || final_size == NULL)
+ {
+ return NULL;
+ }
+
+ keypair = server->Session.Keypairs.Current;
+ if (keypair == NULL)
+ {
+ Debug("WgsCreateTransportData(): no keypair!\n");
+ return NULL;
+ }
+
+ if (keypair->CounterLocal > WG_REJECT_AFTER_MESSAGES)
+ {
+ WgsLog(server, "LW_KEYPAIR_EXPIRED", keypair->IndexRemote, keypair->IndexLocal);
+ return false;
+ }
+
+ pad_size = (WG_BLOCK_SIZE - (size % WG_BLOCK_SIZE)) % WG_BLOCK_SIZE;
+ encrypted_size = WG_AEAD_SIZE(size + pad_size);
+
+ *final_size = sizeof(WG_TRANSPORT_DATA) + encrypted_size;
+
+ ret = ZeroMalloc(*final_size);
+ ret->Header.Type = WG_MSG_TRANSPORT_DATA;
+ ret->ReceiverIndex = keypair->IndexRemote;
+ ret->Counter = keypair->CounterLocal;
+
+ Copy(ret->EncapsulatedPacket, data, size);
+
+ if (WgsEncryptData(keypair->KeyLocal, ret->Counter, ret->EncapsulatedPacket, ret->EncapsulatedPacket, size + pad_size) != encrypted_size)
+ {
+ Debug("WgsCreateTransportData(): WgsEncryptData() didn't write the expected number of bytes!\n");
+ Free(ret);
+ return NULL;
+ }
+
+ ++keypair->CounterLocal;
+
+ return ret;
+}
+
+// RFC 6479: ipsec_check_replay_window()
+bool WgsIsInReplayWindow(const WG_KEYPAIR *keypair, const UINT64 counter)
+{
+ int bit_location;
+ int index;
+
+ if (keypair == NULL || counter == 0)
+ {
+ return false;
+ }
+
+ if (counter > keypair->CounterRemote)
+ {
+ return false;
+ }
+
+ if (counter + sizeof(keypair->ReplayWindow) < keypair->CounterRemote)
+ {
+ return false;
+ }
+
+ bit_location = counter & WG_REPLAY_BITMAP_LOC_MASK;
+ index = counter >> WG_REPLAY_REDUNDANT_BIT_SHIFTS & WG_REPLAY_BITMAP_INDEX_MASK;
+
+ if (keypair->ReplayWindow[index] & (1 << bit_location))
+ {
+ return true;
+ }
+
+ return false;
+}
+
+// RFC 6479: ipsec_update_replay_window()
+void WgsUpdateReplayWindow(WG_KEYPAIR *keypair, const UINT64 counter)
+{
+ int bit_location;
+ int index;
+
+ if (keypair == NULL || counter == 0)
+ {
+ return;
+ }
+
+ if (counter + sizeof(keypair->ReplayWindow) < keypair->CounterRemote)
+ {
+ return;
+ }
+
+ index = counter >> WG_REPLAY_REDUNDANT_BIT_SHIFTS;
+
+ if (counter > keypair->CounterRemote)
+ {
+ const int index_cur = keypair->CounterRemote >> WG_REPLAY_REDUNDANT_BIT_SHIFTS;
+ int diff = index - index_cur;
+ int id;
+
+ if (diff > WG_REPLAY_BITMAP_SIZE)
+ {
+ diff = WG_REPLAY_BITMAP_SIZE;
+ }
+
+ for (id = 0; id < diff; ++id)
+ {
+ keypair->ReplayWindow[(id + index_cur + 1) & WG_REPLAY_BITMAP_INDEX_MASK] = 0;
+ }
+
+ keypair->CounterRemote = counter;
+ }
+
+ index &= WG_REPLAY_BITMAP_INDEX_MASK;
+ bit_location = counter & WG_REPLAY_BITMAP_LOC_MASK;
+
+ if (keypair->ReplayWindow[index] & 1 << bit_location)
+ {
+ return;
+ }
+
+ keypair->ReplayWindow[index] |= 1 << bit_location;
+}
+
+UINT WgsEncryptData(void *key, const UINT64 counter, void *dst, const void *src, const UINT src_size)
+{
+ unsigned long long written;
+ BYTE iv[WG_IV_SIZE];
+
+ if (key == NULL || dst == NULL || (src == NULL && src_size > 0))
+ {
+ return INFINITE;
+ }
+
+ Zero(iv, sizeof(iv) - sizeof(counter));
+ Copy(iv + sizeof(iv) - sizeof(counter), &counter, sizeof(counter));
+
+ crypto_aead_chacha20poly1305_ietf_encrypt(dst, &written, src, src_size, NULL, 0, NULL, iv, key);
+
+ return written;
+}
+
+UINT WgsDecryptData(void *key, const UINT64 counter, void *dst, const void *src, const UINT src_size)
+{
+ unsigned long long written;
+ BYTE iv[WG_IV_SIZE];
+
+ if (key == NULL || src == NULL || src_size == 0)
+ {
+ return INFINITE;
+ }
+
+ Zero(iv, sizeof(iv) - sizeof(counter));
+ Copy(iv + sizeof(iv) - sizeof(counter), &counter, sizeof(counter));
+
+ if (crypto_aead_chacha20poly1305_ietf_decrypt(dst, &written, NULL, src, src_size, NULL, 0, iv, key) != 0)
+ {
+ return INFINITE;
+ }
+
+ return written;
+}
+
+bool WgsEncryptWithHash(void *dst, const void *src, const UINT src_size, BYTE *hash, const BYTE *key)
+{
+ unsigned long long written;
+ BYTE iv[WG_IV_SIZE];
+
+ if (dst == NULL || (src == NULL && src_size > 0) || hash == NULL || key == NULL)
+ {
+ return false;
+ }
+
+ Zero(iv, sizeof(iv));
+
+ crypto_aead_chacha20poly1305_ietf_encrypt(dst, &written, src, src_size, hash, WG_HASH_SIZE, NULL, iv, key);
+
+ WgsMixHash(hash, dst, WG_AEAD_SIZE(src_size));
+
+ return (written > 0);
+}
+
+bool WgsDecryptWithHash(void *dst, const void *src, const UINT src_size, BYTE *hash, const BYTE *key)
+{
+ unsigned long long written;
+ BYTE iv[WG_IV_SIZE];
+
+ if ((src == NULL && src_size > 0) || hash == NULL || key == NULL)
+ {
+ return false;
+ }
+
+ Zero(iv, sizeof(iv));
+
+ if (crypto_aead_chacha20poly1305_ietf_decrypt(dst, &written, NULL, src, src_size, hash, WG_HASH_SIZE, iv, key) != 0)
+ {
+ return false;
+ }
+
+ WgsMixHash(hash, src, src_size);
+
+ return (written > 0);
+}
+
+void WgsEphemeral(BYTE *ephemeral_dst, const BYTE *ephemeral_src, BYTE *chaining_key, BYTE *hash)
+{
+ Copy(ephemeral_dst, ephemeral_src, WG_KEY_SIZE);
+ WgsMixHash(hash, ephemeral_src, WG_HASH_SIZE);
+ WgsHKDF(chaining_key, NULL, NULL, ephemeral_src, WG_KEY_SIZE, chaining_key);
+}
+
+void WgsHKDF(BYTE *dst_1, BYTE *dst_2, BYTE *dst_3, const BYTE *data, const UINT data_size, const BYTE *chaining_key)
+{
+ BYTE output[WG_HASH_SIZE + 1];
+ BYTE secret[WG_HASH_SIZE];
+
+ MD *md = NewMd("BLAKE2s256");
+ SetMdKey(md, chaining_key, WG_HASH_SIZE);
+
+ // Extract entropy from data into secret.
+ MdProcess(md, secret, data, data_size);
+
+ if (dst_1 == NULL)
+ {
+ goto FINAL;
+ }
+
+ SetMdKey(md, secret, sizeof(secret));
+
+ // Expand first key
+ output[0] = 1;
+ MdProcess(md, output, output, 1);
+ Copy(dst_1, output, WG_KEY_SIZE);
+
+ if (dst_2 == NULL)
+ {
+ goto FINAL;
+ }
+
+ // Expand second key
+ output[sizeof(output) - 1] = 2;
+ MdProcess(md, output, output, sizeof(output));
+ Copy(dst_2, output, WG_KEY_SIZE);
+
+ if (dst_3 == NULL)
+ {
+ goto FINAL;
+ }
+
+ // Expand third key
+ output[sizeof(output) - 1] = 3;
+ MdProcess(md, output, output, sizeof(output));
+ Copy(dst_3, output, WG_KEY_SIZE);
+FINAL:
+ FreeMd(md);
+ Zero(secret, sizeof(secret));
+ Zero(output, sizeof(output));
+}
+
+void WgsMixHash(void *dst, const void *src, const UINT size)
+{
+ blake2s_state b2s_state;
+
+ if (dst == NULL || (src == NULL && size > 0))
+ {
+ return;
+ }
+
+ blake2s_init(&b2s_state, WG_HASH_SIZE);
+ blake2s_update(&b2s_state, dst, WG_HASH_SIZE);
+ blake2s_update(&b2s_state, src, size);
+ blake2s_final(&b2s_state, dst, WG_HASH_SIZE);
+}
+
+bool WgsMixDh(BYTE *chaining_key, BYTE *key, const BYTE *priv, const BYTE *pub)
+{
+ BYTE dh[WG_HASH_SIZE];
+
+ if (chaining_key == NULL || priv == NULL || pub == NULL)
+ {
+ return false;
+ }
+
+ if (crypto_scalarmult_curve25519(dh, priv, pub) != 0)
+ {
+ Debug("WgsMixDh(): crypto_scalarmult_curve25519() failed!\n");
+ return false;
+ }
+
+ WgsHKDF(chaining_key, key, NULL, dh, sizeof(dh), chaining_key);
+
+ Zero(dh, sizeof(dh));
+
+ return true;
+}
diff --git a/src/Cedar/Proto_WireGuard.h b/src/Cedar/Proto_WireGuard.h
new file mode 100644
index 00000000..6816c84a
--- /dev/null
+++ b/src/Cedar/Proto_WireGuard.h
@@ -0,0 +1,211 @@
+#ifndef PROTO_WIREGUARD_H
+#define PROTO_WIREGUARD_H
+
+#include "Proto.h"
+
+#include
+
+#define WG_IPC_POSTFIX "WIREGUARD"
+
+#define WG_CIPHER "ChaCha20-Poly1305"
+
+#define WG_CONSTRUCTION "Noise_IKpsk2_25519_ChaChaPoly_BLAKE2s"
+#define WG_IDENTIFIER "WireGuard v1 zx2c4 Jason@zx2c4.com"
+#define WG_LABEL_COOKIE "cookie--"
+#define WG_LABEL_MAC1 "mac1----"
+
+#define WG_MAX_INITIATIONS_PER_SECOND 50
+
+#define WG_KEEPALIVE_TIMEOUT 10000 // 10 seconds
+#define WG_INITIATION_GIVEUP 30000 // 30 seconds
+
+#define WG_REJECT_AFTER_TIME 180000 // 180 seconds
+#define WG_REJECT_AFTER_MESSAGES (UINT64_MAX - 16 - 1)
+
+#define WG_KEY_SIZE crypto_aead_chacha20poly1305_ietf_KEYBYTES
+#define WG_IV_SIZE crypto_aead_chacha20poly1305_ietf_NPUBBYTES
+#define WG_TAG_SIZE crypto_aead_chacha20poly1305_ietf_ABYTES
+
+#define WG_COOKIE_IV_SIZE crypto_aead_xchacha20poly1305_ietf_NPUBBYTES
+#define WG_COOKIE_TAG_SIZE crypto_aead_xchacha20poly1305_ietf_ABYTES
+
+#define WG_HASH_SIZE 32
+#define WG_BLOCK_SIZE 16
+#define WG_COOKIE_SIZE 16
+#define WG_TIMESTAMP_SIZE (sizeof(UINT64) + sizeof(UINT))
+
+#define WG_KEY_BASE64_SIZE (sodium_base64_ENCODED_LEN(WG_KEY_SIZE, sodium_base64_VARIANT_ORIGINAL))
+
+#define WG_AEAD_SIZE(plain_size) (plain_size + WG_TAG_SIZE)
+#define WG_PLAIN_SIZE(aead_size) (aead_size - WG_TAG_SIZE)
+
+// RFC 6479
+#define WG_REPLAY_WINDOW_SIZE 1024
+#define WG_REPLAY_BITMAP_SIZE (WG_REPLAY_WINDOW_SIZE / (sizeof(int) * 8))
+#define WG_REPLAY_BITMAP_INDEX_MASK (WG_REPLAY_BITMAP_SIZE - 1)
+#define WG_REPLAY_REDUNDANT_BIT_SHIFTS 5
+#define WG_REPLAY_REDUNDANT_BITS (1 << WG_REPLAY_REDUNDANT_BIT_SHIFTS)
+#define WG_REPLAY_BITMAP_LOC_MASK (WG_REPLAY_REDUNDANT_BITS - 1)
+
+typedef enum WG_MSG_TYPE
+{
+ WG_MSG_INVALID = 0,
+ WG_MSG_HANDSHAKE_INIT,
+ WG_MSG_HANDSHAKE_REPLY,
+ WG_MSG_HANDSHAKE_COOKIE,
+ WG_MSG_TRANSPORT_DATA
+} WG_MSG_TYPE;
+
+typedef enum WG_KEYPAIR_STATE
+{
+ WG_KEYPAIR_INVALID = 0,
+ WG_KEYPAIR_INITIATED,
+ WG_KEYPAIR_CONFIRMED
+} WG_KEYPAIR_STATE;
+
+typedef struct WG_HEADER
+{
+ BYTE Type;
+ BYTE Reserved[3];
+} WG_HEADER;
+
+typedef struct WG_COMMON
+{
+ WG_HEADER Header;
+ UINT Index;
+} WG_COMMON;
+
+typedef struct WG_MACS
+{
+ BYTE Mac1[WG_COOKIE_SIZE];
+ BYTE Mac2[WG_COOKIE_SIZE];
+} WG_MACS;
+
+typedef struct WG_HANDSHAKE_INIT
+{
+ WG_HEADER Header;
+ UINT SenderIndex;
+ BYTE UnencryptedEphemeral[WG_KEY_SIZE];
+ BYTE EncryptedStatic[WG_AEAD_SIZE(WG_KEY_SIZE)];
+ BYTE EncryptedTimestamp[WG_AEAD_SIZE(WG_TIMESTAMP_SIZE)];
+ WG_MACS Macs;
+} WG_HANDSHAKE_INIT;
+
+typedef struct WG_HANDSHAKE_REPLY
+{
+ WG_HEADER Header;
+ UINT SenderIndex;
+ UINT ReceiverIndex;
+ BYTE UnencryptedEphemeral[WG_KEY_SIZE];
+ BYTE EncryptedNothing[WG_AEAD_SIZE(0)];
+ WG_MACS Macs;
+} WG_HANDSHAKE_REPLY;
+
+typedef struct WG_COOKIE_REPLY
+{
+ WG_HEADER Header;
+ UINT ReceiverIndex;
+ BYTE Nonce[WG_COOKIE_IV_SIZE];
+ BYTE EncryptedCookie[WG_COOKIE_SIZE + WG_COOKIE_TAG_SIZE];
+} WG_COOKIE_REPLY;
+
+typedef struct WG_TRANSPORT_DATA
+{
+ WG_HEADER Header;
+ UINT ReceiverIndex;
+ UINT64 Counter;
+ BYTE EncapsulatedPacket[];
+} WG_TRANSPORT_DATA;
+
+typedef struct WG_KEYPAIR
+{
+ WG_KEYPAIR_STATE State;
+ UINT64 CreationTime;
+ UINT IndexLocal;
+ UINT IndexRemote;
+ UINT64 CounterLocal;
+ UINT64 CounterRemote;
+ BYTE KeyLocal[WG_KEY_SIZE];
+ BYTE KeyRemote[WG_KEY_SIZE];
+ UINT64 ReplayWindow[WG_REPLAY_WINDOW_SIZE];
+} WG_KEYPAIR;
+
+typedef struct WG_KEYPAIRS
+{
+ WG_KEYPAIR *Current;
+ WG_KEYPAIR *Next;
+ WG_KEYPAIR *Previous;
+} WG_KEYPAIRS;
+
+typedef struct WG_SESSION
+{
+ WG_KEYPAIRS Keypairs;
+ IPC *IPC;
+ IP IPLocal;
+ IP IPRemote;
+ USHORT PortLocal;
+ USHORT PortRemote;
+ UINT64 LastInitiationReceived;
+ UINT64 LastDataReceived;
+ UINT64 LastDataSent;
+ BYTE StaticRemote[WG_KEY_SIZE];
+ BYTE LastTimestamp[WG_TIMESTAMP_SIZE];
+ BYTE Hash[WG_HASH_SIZE];
+ BYTE ChainingKey[WG_HASH_SIZE];
+ BYTE PrecomputedStaticStatic[WG_KEY_SIZE];
+} WG_SESSION;
+
+typedef struct WG_SERVER
+{
+ UINT64 Now;
+ UINT64 CreationTime;
+ WG_SESSION Session;
+ CEDAR *Cedar;
+ SOCK_EVENT *SockEvent;
+ INTERRUPT_MANAGER *InterruptManager;
+ BYTE PresharedKey[WG_KEY_SIZE];
+ BYTE StaticPublic[WG_KEY_SIZE];
+ BYTE StaticPrivate[WG_KEY_SIZE];
+ BYTE HandshakeInitHash[WG_HASH_SIZE];
+ BYTE HandshakeInitChainingKey[WG_HASH_SIZE];
+} WG_SERVER;
+
+const PROTO_IMPL *WgsGetProtoImpl();
+const char *WgsName();
+const PROTO_OPTION *WgsOptions();
+char *WgsOptionStringValue(const char *name);
+bool WgsInit(void **param, const LIST *options, CEDAR *cedar, INTERRUPT_MANAGER *im, SOCK_EVENT *se, const char *cipher, const char *hostname);
+void WgsFree(void *param);
+bool WgsIsPacketForMe(const PROTO_MODE mode, const void *data, const UINT size);
+bool WgsProcessDatagrams(void *param, LIST *in, LIST *out);
+
+void WgsLog(const WG_SERVER *server, const char *name, ...);
+
+WG_MSG_TYPE WgsDetectMessageType(const void *data, const UINT size);
+
+UINT WgsMSS(const WG_SESSION *session);
+
+IPC *WgsIPCNew(WG_SERVER *server);
+
+WG_KEYPAIR *WgsProcessHandshakeInit(WG_SERVER *server, const WG_HANDSHAKE_INIT *init, BYTE *ephemeral_remote);
+WG_HANDSHAKE_REPLY *WgsCreateHandshakeReply(WG_SERVER *server, WG_KEYPAIR *keypair, const BYTE *ephemeral_remote);
+
+bool WgsProcessTransportData(WG_SERVER *server, WG_TRANSPORT_DATA *data, const UINT size);
+WG_TRANSPORT_DATA *WgsCreateTransportData(WG_SERVER *server, const void *data, const UINT size, UINT *final_size);
+
+bool WgsIsInReplayWindow(const WG_KEYPAIR *keypair, const UINT64 counter);
+void WgsUpdateReplayWindow(WG_KEYPAIR *keypair, const UINT64 counter);
+
+UINT WgsEncryptData(void *key, const UINT64 counter, void *dst, const void *src, const UINT src_size);
+UINT WgsDecryptData(void *key, const UINT64 counter, void *dst, const void *src, const UINT src_size);
+
+bool WgsEncryptWithHash(void *dst, const void *src, const UINT src_size, BYTE *hash, const BYTE *key);
+bool WgsDecryptWithHash(void *dst, const void *src, const UINT src_size, BYTE *hash, const BYTE *key);
+
+void WgsEphemeral(BYTE *ephemeral_dst, const BYTE *ephemeral_src, BYTE *chaining_key, BYTE *hash);
+void WgsHKDF(BYTE *dst_1, BYTE *dst_2, BYTE *dst_3, const BYTE *data, const UINT data_size, const BYTE *chaining_key);
+
+void WgsMixHash(void *dst, const void *src, const UINT size);
+bool WgsMixDh(BYTE *chaining_key, BYTE *key, const BYTE *priv, const BYTE *pub);
+
+#endif
diff --git a/src/Cedar/Protocol.c b/src/Cedar/Protocol.c
index f515d593..ecf9f5c8 100644
--- a/src/Cedar/Protocol.c
+++ b/src/Cedar/Protocol.c
@@ -5,9 +5,42 @@
// Protocol.c
// SoftEther protocol related routines
-#include "CedarPch.h"
+#include "Protocol.h"
-static UCHAR ssl_packet_start[3] = {0x17, 0x03, 0x00};
+#include "Admin.h"
+#include "Client.h"
+#include "CM.h"
+#include "DDNS.h"
+#include "Hub.h"
+#include "IPC.h"
+#include "Link.h"
+#include "Logging.h"
+#include "Proto_IPsec.h"
+#include "Proto_OpenVPN.h"
+#include "Proto_PPP.h"
+#include "Proto_SSTP.h"
+#include "Radius.h"
+#include "Sam.h"
+#include "Server.h"
+#include "UdpAccel.h"
+#include "VLanUnix.h"
+#include "WaterMark.h"
+#include "WebUI.h"
+#include "WinUi.h"
+#include "Wpc.h"
+
+#include "Mayaqua/Cfg.h"
+#include "Mayaqua/FileIO.h"
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Microsoft.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/OS.h"
+#include "Mayaqua/Pack.h"
+#include "Mayaqua/Secure.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Table.h"
+#include "Mayaqua/Tick64.h"
// Download and save intermediate certificates if necessary
bool DownloadAndSaveIntermediateCertificatesIfNecessary(X *x)
@@ -1330,12 +1363,45 @@ bool ServerAccept(CONNECTION *c)
goto CLEANUP;
}
-
-
- // Login
- if (GetHubnameAndUsernameFromPack(p, username, sizeof(username), hubname, sizeof(hubname)) == false)
+ // Get authentication method and initiate login process
+ authtype = GetAuthTypeFromPack(p);
+ if (authtype == AUTHTYPE_WIREGUARD_KEY)
+ {
+ WGK *wgk, tmp;
+ bool ok = false;
+
+ if (PackGetStr(p, "key", tmp.Key, sizeof(tmp.Key)) == false)
+ {
+ FreePack(p);
+ c->Err = ERR_PROTOCOL_ERROR;
+ error_detail = "GetWireGuardKeyFromPack";
+ goto CLEANUP;
+ }
+
+ LockList(c->Cedar->WgkList);
+ {
+ wgk = Search(c->Cedar->WgkList, &tmp);
+ if (wgk != NULL)
+ {
+ ok = true;
+ StrCpy(hubname, sizeof(hubname), wgk->Hub);
+ StrCpy(username, sizeof(username), wgk->User);
+ StrCpy(node.HubName, sizeof(node.HubName), hubname);
+ }
+ }
+ UnlockList(c->Cedar->WgkList);
+
+ if (ok == false)
+ {
+ FreePack(p);
+ c->Err = ERR_AUTH_FAILED;
+ SLog(c->Cedar, "LS_WG_KEY_NOT_FOUND", c->Name, hubname);
+ error_detail = "ERR_AUTH_FAILED";
+ goto CLEANUP;
+ }
+ }
+ else if (GetHubnameAndUsernameFromPack(p, username, sizeof(username), hubname, sizeof(hubname)) == false)
{
- // Protocol error
FreePack(p);
c->Err = ERR_PROTOCOL_ERROR;
error_detail = "GetHubnameAndUsernameFromPack";
@@ -1345,9 +1411,7 @@ bool ServerAccept(CONNECTION *c)
if (farm_member)
{
bool ok = false;
- UINT authtype;
- authtype = GetAuthTypeFromPack(p);
if (StrCmpi(username, ADMINISTRATOR_USERNAME) == 0 &&
authtype == AUTHTYPE_PASSWORD)
{
@@ -1600,9 +1664,6 @@ bool ServerAccept(CONNECTION *c)
PackGetData(p, "unique_id", unique);
}
- // Get the authentication method
- authtype = GetAuthTypeFromPack(p);
-
if (1)
{
// Log
@@ -1622,12 +1683,15 @@ bool ServerAccept(CONNECTION *c)
case CLIENT_AUTHTYPE_CERT:
authtype_str = _UU("LH_AUTH_CERT");
break;
- case AUTHTYPE_TICKET:
- authtype_str = _UU("LH_AUTH_TICKET");
+ case AUTHTYPE_WIREGUARD_KEY:
+ authtype_str = _UU("LH_AUTH_WIREGUARD_KEY");
break;
case AUTHTYPE_OPENVPN_CERT:
authtype_str = _UU("LH_AUTH_OPENVPN_CERT");
break;
+ case AUTHTYPE_TICKET:
+ authtype_str = _UU("LH_AUTH_TICKET");
+ break;
}
IPToStr(ip1, sizeof(ip1), &c->FirstSock->RemoteIP);
IPToStr(ip2, sizeof(ip2), &c->FirstSock->LocalIP);
@@ -1640,7 +1704,6 @@ bool ServerAccept(CONNECTION *c)
// Attempt an anonymous authentication first
auth_ret = SamAuthUserByAnonymous(hub, username);
-
if (auth_ret)
{
if (c->IsInProc)
@@ -1734,8 +1797,6 @@ bool ServerAccept(CONNECTION *c)
if (auth_ret)
{
- // User authentication success by anonymous authentication
- HLog(hub, "LH_AUTH_OK", c->Name, username);
is_empty_password = true;
}
}
@@ -1961,6 +2022,24 @@ bool ServerAccept(CONNECTION *c)
}
break;
+ case AUTHTYPE_WIREGUARD_KEY:
+ // We already retrieved the hubname and username associated with the key.
+ // Now we only have to verify that the user effectively exists.
+ if (c->IsInProc)
+ {
+ auth_ret = SamIsUser(hub, username);
+ }
+ else
+ {
+ // WireGuard public key authentication cannot be used directly by external clients.
+ Unlock(hub->lock);
+ ReleaseHub(hub);
+ FreePack(p);
+ c->Err = ERR_AUTHTYPE_NOT_SUPPORTED;
+ goto CLEANUP;
+ }
+ break;
+
case AUTHTYPE_OPENVPN_CERT:
// For OpenVPN; mostly same as CLIENT_AUTHTYPE_CERT, but without
// signature verification, because it was already performed during TLS handshake.
@@ -2014,25 +2093,14 @@ bool ServerAccept(CONNECTION *c)
error_detail = "ERR_AUTHTYPE_NOT_SUPPORTED";
goto CLEANUP;
}
-
- if (auth_ret == false)
- {
- // Get client IP to feed tools such as Fail2Ban
- char ip[64];
- IPToStr(ip, sizeof(ip), &c->FirstSock->RemoteIP);
- // Authentication failure
- HLog(hub, "LH_AUTH_NG", c->Name, username, ip);
- }
- else
- {
- // Authentication success
- HLog(hub, "LH_AUTH_OK", c->Name, username);
- }
}
if (auth_ret == false)
{
- // Authentication failure
+ char ip[64];
+ IPToStr(ip, sizeof(ip), &c->FirstSock->RemoteIP);
+ HLog(hub, "LH_AUTH_NG", c->Name, username, ip);
+
Unlock(hub->lock);
ReleaseHub(hub);
FreePack(p);
@@ -2046,13 +2114,12 @@ bool ServerAccept(CONNECTION *c)
}
else
{
- if(is_empty_password)
+ if (is_empty_password)
{
- SOCK *s = c->FirstSock;
- if (s != NULL && s->RemoteIP.addr[0] != 127)
+ const SOCK *s = c->FirstSock;
+ if (s != NULL && IsLocalHostIP(&s->RemoteIP) == false)
{
- if(StrCmpi(username, ADMINISTRATOR_USERNAME) == 0 ||
- GetHubAdminOption(hub, "deny_empty_password") != 0)
+ if (StrCmpi(username, ADMINISTRATOR_USERNAME) == 0 || GetHubAdminOption(hub, "deny_empty_password") != 0)
{
// When the password is empty, remote connection is not acceptable
HLog(hub, "LH_LOCAL_ONLY", c->Name, username);
@@ -2066,6 +2133,8 @@ bool ServerAccept(CONNECTION *c)
}
}
}
+
+ HLog(hub, "LH_AUTH_OK", c->Name, username);
}
policy = NULL;
@@ -2932,7 +3001,7 @@ bool ServerAccept(CONNECTION *c)
if (UdpAccelInitServer(s->UdpAccel,
s->UdpAccel->Version == 2 ? udp_acceleration_client_key_v2 : udp_acceleration_client_key,
- &udp_acceleration_client_ip, udp_acceleration_client_port, &c->FirstSock->RemoteIP) == false)
+ &c->FirstSock->RemoteIP, &udp_acceleration_client_ip, udp_acceleration_client_port) == false)
{
Debug("UdpAccelInitServer Failed.\n");
s->UseUdpAcceleration = false;
@@ -3120,7 +3189,7 @@ bool ServerAccept(CONNECTION *c)
if (IsURLMsg(msg, NULL, 0) == false)
{
- if (s != NULL && s->IsRUDPSession && c != NULL && StrCmpi(hub->Name, VG_HUBNAME) != 0)
+ if (s != NULL && s->IsRUDPSession && c != NULL)
{
// Show the warning message if the connection is made by NAT-T
wchar_t *tmp2;
@@ -3765,7 +3834,7 @@ void CreateNodeInfo(NODE_INFO *info, CONNECTION *c)
}
else
{
- Copy(info->ClientIpAddress6, c->FirstSock->LocalIP.ipv6_addr, sizeof(info->ClientIpAddress6));
+ Copy(info->ClientIpAddress6, c->FirstSock->LocalIP.address, sizeof(info->ClientIpAddress6));
}
// Client port number
info->ClientPort = Endian32(c->FirstSock->LocalPort);
@@ -3781,7 +3850,7 @@ void CreateNodeInfo(NODE_INFO *info, CONNECTION *c)
}
else
{
- Copy(info->ServerIpAddress6, ip.ipv6_addr, sizeof(info->ServerIpAddress6));
+ Copy(info->ServerIpAddress6, ip.address, sizeof(info->ServerIpAddress6));
}
}
// Server port number
@@ -3799,7 +3868,7 @@ void CreateNodeInfo(NODE_INFO *info, CONNECTION *c)
}
else
{
- Copy(&info->ProxyIpAddress6, c->FirstSock->RemoteIP.ipv6_addr, sizeof(info->ProxyIpAddress6));
+ Copy(&info->ProxyIpAddress6, c->FirstSock->RemoteIP.address, sizeof(info->ProxyIpAddress6));
}
info->ProxyPort = Endian32(c->FirstSock->RemotePort);
@@ -4918,8 +4987,8 @@ REDIRECTED:
if (UdpAccelInitClient(sess->UdpAccel,
sess->UdpAccel->Version == 2 ? udp_acceleration_server_key_v2 : udp_acceleration_server_key,
- &udp_acceleration_server_ip, udp_acceleration_server_port,
- server_cookie, client_cookie, &remote_ip) == false)
+ &remote_ip, &udp_acceleration_server_ip, udp_acceleration_server_port,
+ server_cookie, client_cookie) == false)
{
Debug("UdpAccelInitClient failed.\n");
}
@@ -5605,25 +5674,18 @@ bool ClientUploadAuth(CONNECTION *c)
// UDP acceleration function using flag
if (o->NoUdpAcceleration == false && c->Session->UdpAccel != NULL)
{
- IP my_ip;
-
- Zero(&my_ip, sizeof(my_ip));
-
PackAddBool(p, "use_udp_acceleration", true);
PackAddInt(p, "udp_acceleration_version", c->Session->UdpAccel->Version);
- Copy(&my_ip, &c->Session->UdpAccel->MyIp, sizeof(IP));
- if (IsLocalHostIP(&my_ip))
+ IP my_ip;
+ if (IsLocalHostIP(&c->Session->UdpAccel->MyIp) == false)
{
- if (IsIP4(&my_ip))
- {
- ZeroIP4(&my_ip);
- }
- else
- {
- ZeroIP6(&my_ip);
- }
+ Copy(&my_ip, &c->Session->UdpAccel->MyIp, sizeof(my_ip));
+ }
+ else
+ {
+ Zero(&my_ip, sizeof(my_ip));
}
PackAddIp(p, "udp_acceleration_client_ip", &my_ip);
@@ -5989,7 +6051,7 @@ bool ServerDownloadSignature(CONNECTION *c, char **error_detail_str)
}
- if (c->FirstSock->RemoteIP.addr[0] == 127)
+ if (IsLocalHostIP(&c->FirstSock->RemoteIP))
{
if (StrCmpi(h->Target, HTTP_SAITAMA) == 0)
{
@@ -6592,6 +6654,24 @@ PACK *PackLoginWithPlainPassword(char *hubname, char *username, void *plain_pass
return p;
}
+// Generate a packet of WireGuard key login
+PACK *PackLoginWithWireGuardKey(char *key)
+{
+ PACK *p;
+ // Validate arguments
+ if (key == NULL)
+ {
+ return NULL;
+ }
+
+ p = NewPack();
+ PackAddStr(p, "method", "login");
+ PackAddInt(p, "authtype", AUTHTYPE_WIREGUARD_KEY);
+ PackAddStr(p, "key", key);
+
+ return p;
+}
+
// Generate a packet of OpenVPN certificate login
PACK *PackLoginWithOpenVPNCertificate(char *hubname, char *username, X *x)
{
diff --git a/src/Cedar/Protocol.h b/src/Cedar/Protocol.h
index 260a6b4e..8e3db267 100644
--- a/src/Cedar/Protocol.h
+++ b/src/Cedar/Protocol.h
@@ -8,6 +8,8 @@
#ifndef PROTOCOL_H
#define PROTOCOL_H
+#include "Connection.h"
+
// The parameters that will be passed to the certificate confirmation thread
struct CHECK_CERT_THREAD_PROC
{
@@ -134,6 +136,7 @@ PACK *PackLoginWithAnonymous(char *hubname, char *username);
PACK *PackLoginWithPassword(char *hubname, char *username, void *secure_password);
PACK *PackLoginWithPlainPassword(char *hubname, char *username, void *plain_password);
PACK *PackLoginWithCert(char *hubname, char *username, X *x, void *sign, UINT sign_size);
+PACK *PackLoginWithWireGuardKey(char *key);
PACK *PackLoginWithOpenVPNCertificate(char *hubname, char *username, X *x);
bool GetMethodFromPack(PACK *p, char *method, UINT size);
bool GetHubnameAndUsernameFromPack(PACK *p, char *username, UINT username_size,
diff --git a/src/Cedar/Radius.c b/src/Cedar/Radius.c
index 58c4edbf..34d646aa 100644
--- a/src/Cedar/Radius.c
+++ b/src/Cedar/Radius.c
@@ -5,10 +5,17 @@
// Radius.c
// Radius authentication module
-#include "CedarPch.h"
+#include "Radius.h"
-////////// Modern implementation
+#include "Connection.h"
+#include "IPC.h"
+#include "Server.h"
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Tick64.h"
// send PEAP-MSCHAPv2 auth client response
bool PeapClientSendMsChapv2AuthClientResponse(EAP_CLIENT *e, UCHAR *client_response, UCHAR *client_challenge)
@@ -1785,7 +1792,7 @@ bool RadiusLogin(CONNECTION *c, char *server, UINT port, UCHAR *secret, UINT sec
SOCK *sock;
USHORT sz = 0;
UINT pos = 0;
- BOOL *finish = ZeroMallocEx(sizeof(BOOL) * LIST_NUM(ip_list), true);
+ bool *finish = ZeroMallocEx(sizeof(bool) * LIST_NUM(ip_list), true);
Zero(tmp, sizeof(tmp));
diff --git a/src/Cedar/Radius.h b/src/Cedar/Radius.h
index dbe46051..8c422368 100644
--- a/src/Cedar/Radius.h
+++ b/src/Cedar/Radius.h
@@ -8,6 +8,10 @@
#ifndef RADIUS_H
#define RADIUS_H
+#include "Cedar.h"
+
+#include "Mayaqua/Mayaqua.h"
+
#define RADIUS_DEFAULT_PORT 1812 // The default port number
#define RADIUS_RETRY_INTERVAL 1000 // Retransmission interval
#define RADIUS_RETRY_TIMEOUT (15 * 1000) // Time-out period, keep it 2FA friendly
diff --git a/src/Cedar/Remote.c b/src/Cedar/Remote.c
index 742c83c3..982c2442 100644
--- a/src/Cedar/Remote.c
+++ b/src/Cedar/Remote.c
@@ -5,7 +5,14 @@
// Remote.c
// Remote Procedure Call
-#include "CedarPch.h"
+#include "Remote.h"
+
+#include "Admin.h"
+
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Pack.h"
+#include "Mayaqua/Str.h"
// End of RPC
void EndRpc(RPC *rpc)
diff --git a/src/Cedar/Remote.h b/src/Cedar/Remote.h
index 49de5056..0032c89f 100644
--- a/src/Cedar/Remote.h
+++ b/src/Cedar/Remote.h
@@ -8,6 +8,8 @@
#ifndef REMOTE_H
#define REMOTE_H
+#include "Connection.h"
+
// RPC execution function
typedef PACK *(RPC_DISPATCHER)(RPC *r, char *function_name, PACK *p);
diff --git a/src/Cedar/SM.c b/src/Cedar/SM.c
index c5716b4c..13f89797 100644
--- a/src/Cedar/SM.c
+++ b/src/Cedar/SM.c
@@ -5,38 +5,35 @@
// SM.c
// VPN Server Manager for Win32
-#include
+#ifdef OS_WIN32
-#ifdef WIN32
-
-#define SM_C
-#define CM_C
-#define NM_C
-
-#define _WIN32_WINNT 0x0502
-#define WINVER 0x0502
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include "CMInner.h"
+#include "SM.h"
#include "SMInner.h"
+
+#include "AzureClient.h"
+#include "CMInner.h"
+#include "Console.h"
+#include "Database.h"
+#include "Layer3.h"
#include "NMInner.h"
-#include "EMInner.h"
+#include "Proto_PPP.h"
+#include "Radius.h"
+#include "Remote.h"
+#include "Server.h"
+
+#include "Mayaqua/Cfg.h"
+#include "Mayaqua/FileIO.h"
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Microsoft.h"
+#include "Mayaqua/Secure.h"
+#include "Mayaqua/Str.h"
+
#include "../PenCore/resource.h"
+#include
+#include
+
// Global variable
static SM *sm = NULL;
static bool link_create_now = false;
@@ -834,10 +831,10 @@ void SmDDnsDlgInit(HWND hWnd, SM_DDNS *d)
SetFont(hWnd, S_SUFFIX, GetFont("Verdana", 10, false, false, false, false));
SetFont(hWnd, E_NEWHOST, GetFont("Verdana", 10, false, false, false, false));
- SetFont(hWnd, E_HOST, GetFont((MsIsWinXPOrGreater() ? "Verdana" : NULL), 10, false, false, false, false));
- SetFont(hWnd, E_IPV4, GetFont((MsIsWinXPOrGreater() ? "Verdana" : NULL), 10, false, false, false, false));
- SetFont(hWnd, E_IPV6, GetFont((MsIsWinXPOrGreater() ? "Verdana" : NULL), 10, false, false, false, false));
- SetFont(hWnd, E_KEY, GetFont((MsIsWinXPOrGreater() ? "Verdana" : NULL), 8, false, false, false, false));
+ SetFont(hWnd, E_HOST, GetFont("Verdana", 10, false, false, false, false));
+ SetFont(hWnd, E_IPV4, GetFont("Verdana", 10, false, false, false, false));
+ SetFont(hWnd, E_IPV6, GetFont("Verdana", 10, false, false, false, false));
+ SetFont(hWnd, E_KEY, GetFont("Verdana", 8, false, false, false, false));
DlgFont(hWnd, IDOK, 0, true);
@@ -1056,7 +1053,6 @@ void SmOpenVpn(HWND hWnd, SM_SERVER *s)
UINT SmOpenVpnDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)
{
SM_SERVER *s = (SM_SERVER *)param;
- char tmp[MAX_SIZE];
// Validate arguments
if (hWnd == NULL)
{
@@ -1993,14 +1989,7 @@ void SmHubMsgDlgInit(HWND hWnd, SM_EDIT_HUB *s)
return;
}
- if (MsIsVista())
- {
- SetFont(hWnd, E_TEXT, GetMeiryoFont());
- }
- else
- {
- DlgFont(hWnd, E_TEXT, 11, false);
- }
+ SetFont(hWnd, E_TEXT, GetMeiryoFont());
FormatText(hWnd, S_MSG_2, s->HubName);
@@ -8195,7 +8184,7 @@ void SmInstallWinPcap(HWND hWnd, SM_SERVER *s)
UniFormat(temp_name, sizeof(temp_name), L"%s\\winpcap_installer.exe", MsGetTempDirW());
// Read from hamcore
- buf = ReadDump(MsIsNt() ? "|winpcap_installer.exe" : "|winpcap_installer_win9x.exe");
+ buf = ReadDump("|winpcap_installer.exe");
if (buf == NULL)
{
RES_ERROR:
@@ -8231,31 +8220,22 @@ RES_ERROR:
return;
}
- // Message after completed
- if (OS_IS_WINDOWS_NT(GetOsInfo()->OsType) == false)
+ // Need to restart the service
+ if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO, _UU("SM_BRIDGE_WPCAP_REBOOT2")) == IDNO)
{
- // Need to restart the computer
- MsgBox(hWnd, MB_ICONINFORMATION, _UU("SM_BRIDGE_WPCAP_REBOOT1"));
+ // Not restart
}
else
{
- // Need to restart the service
- if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO, _UU("SM_BRIDGE_WPCAP_REBOOT2")) == IDNO)
- {
- // Not restart
- }
- else
- {
- // Restart
- RPC_TEST t;
- Zero(&t, sizeof(t));
- ScRebootServer(s->Rpc, &t);
+ // Restart
+ RPC_TEST t;
+ Zero(&t, sizeof(t));
+ ScRebootServer(s->Rpc, &t);
- SleepThread(500);
+ SleepThread(500);
- Zero(&t, sizeof(t));
- CALL(hWnd, ScTest(s->Rpc, &t));
- }
+ Zero(&t, sizeof(t));
+ CALL(hWnd, ScTest(s->Rpc, &t));
}
}
@@ -8287,7 +8267,7 @@ void SmBridgeDlg(HWND hWnd, SM_SERVER *s)
if (t.IsWinPcapNeeded)
{
- if (s->Rpc->Sock->RemoteIP.addr[0] != 127)
+ if (IsLocalHostIP(&s->Rpc->Sock->RemoteIP) == false)
{
// WinPcap is required, but can not do anything because it is in remote control mode
MsgBox(hWnd, MB_ICONINFORMATION, _UU("SM_BRIDGE_WPCAP_REMOTE"));
@@ -8517,14 +8497,14 @@ void SmCreateCertDlgInit(HWND hWnd, SM_CERT *s)
}
// Font
- SetFont(hWnd, E_CN, GetFont((MsIsWinXPOrGreater() ? "Verdana" : NULL), 0, false, false, false, false));
- SetFont(hWnd, E_O, GetFont((MsIsWinXPOrGreater() ? "Verdana" : NULL), 0, false, false, false, false));
- SetFont(hWnd, E_OU, GetFont((MsIsWinXPOrGreater() ? "Verdana" : NULL), 0, false, false, false, false));
- SetFont(hWnd, E_C, GetFont((MsIsWinXPOrGreater() ? "Verdana" : NULL), 0, false, false, false, false));
- SetFont(hWnd, E_ST, GetFont((MsIsWinXPOrGreater() ? "Verdana" : NULL), 0, false, false, false, false));
- SetFont(hWnd, E_L, GetFont((MsIsWinXPOrGreater() ? "Verdana" : NULL), 0, false, false, false, false));
- SetFont(hWnd, E_SERIAL, GetFont((MsIsWinXPOrGreater() ? "Verdana" : NULL), 0, false, false, false, false));
- SetFont(hWnd, E_EXPIRE, GetFont((MsIsWinXPOrGreater() ? "Verdana" : NULL), 0, false, false, false, false));
+ SetFont(hWnd, E_CN, GetFont("Verdana", 0, false, false, false, false));
+ SetFont(hWnd, E_O, GetFont("Verdana", 0, false, false, false, false));
+ SetFont(hWnd, E_OU, GetFont("Verdana", 0, false, false, false, false));
+ SetFont(hWnd, E_C, GetFont("Verdana", 0, false, false, false, false));
+ SetFont(hWnd, E_ST, GetFont("Verdana", 0, false, false, false, false));
+ SetFont(hWnd, E_L, GetFont("Verdana", 0, false, false, false, false));
+ SetFont(hWnd, E_SERIAL, GetFont("Verdana", 0, false, false, false, false));
+ SetFont(hWnd, E_EXPIRE, GetFont("Verdana", 0, false, false, false, false));
SetFont(hWnd, C_BITS, GetFont("Verdana", 0, false, false, false, false));
FocusEx(hWnd, E_CN);
@@ -18681,7 +18661,6 @@ UINT SmServerDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *pa
case B_APPLY:
{
// Apply UDP ports
- bool ret;
LIST* ports;
RPC_PORTS t;
char tmp[MAX_SIZE];
diff --git a/src/Cedar/SMInner.h b/src/Cedar/SMInner.h
index b41d2b34..b1cd699c 100644
--- a/src/Cedar/SMInner.h
+++ b/src/Cedar/SMInner.h
@@ -5,6 +5,17 @@
// SMInner.h
// The internal header of SM.c
+#ifndef SMINNER_H
+#define SMINNER_H
+
+#include "Admin.h"
+#include "Connection.h"
+#include "DDNS.h"
+#include "Proto_EtherIP.h"
+#include "WinUi.h"
+
+#include "Mayaqua/TcpIp.h"
+
// Constants
#define SM_REG_KEY "Software\\SoftEther VPN Developer Edition\\SoftEther VPN\\Server Manager"
#define SM_CERT_REG_KEY "Software\\SoftEther VPN Developer Edition\\SoftEther VPN\\Server Manager\\Cert Tool"
@@ -720,4 +731,4 @@ UINT SmProxyDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);
void SmProxyDlgInit(HWND hWnd, INTERNET_SETTING *t);
void SmProxyDlgUpdate(HWND hWnd, INTERNET_SETTING *t);
-
+#endif
diff --git a/src/Cedar/SW.c b/src/Cedar/SW.c
index ae3ebae7..4a0eb9e3 100644
--- a/src/Cedar/SW.c
+++ b/src/Cedar/SW.c
@@ -5,40 +5,29 @@
// SW.c
// Setup Wizard for Win32
-#include
+#ifdef OS_WIN32
-#ifdef WIN32
-
-#define SM_C
-#define CM_C
-#define NM_C
-#define SW_C
-
-#define _WIN32_WINNT 0x0502
-#define WINVER 0x0502
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include "CMInner.h"
-#include "SMInner.h"
-#include "NMInner.h"
-#include "EMInner.h"
+#include "SW.h"
#include "SWInner.h"
+
+#include "CMInner.h"
+#include "Console.h"
+#include "SeLowUser.h"
+#include "Win32Com.h"
+
+#include "Mayaqua/Cfg.h"
+#include "Mayaqua/FileIO.h"
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Microsoft.h"
+#include "Mayaqua/Str.h"
+#include "Mayaqua/Tick64.h"
+#include "Mayaqua/Win32.h"
+
#include "../PenCore/resource.h"
+#include
+
//// Old MSI product information
// VPN Server
static SW_OLD_MSI old_msi_vpnserver[] =
@@ -1188,15 +1177,7 @@ void SwLang1Init(HWND hWnd, SW *sw)
UniFormat(tmp, sizeof(tmp), L"%s (%s)", t.TitleEnglish, t.TitleLocal);
SetText(hWnd, E_CURRENT, tmp);
-
- if (MsIsVista())
- {
- SetFont(hWnd, E_CURRENT, GetMeiryoFontEx(11));
- }
- else
- {
- DlgFont(hWnd, E_CURRENT, 11, false);
- }
+ SetFont(hWnd, E_CURRENT, GetMeiryoFontEx(11));
}
}
@@ -1239,14 +1220,7 @@ UINT SwLang1(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard,
case WM_INITDIALOG:
LvInitEx2(hWnd, L_LIST, false, true);
- if (MsIsVista())
- {
- SetFont(hWnd, L_LIST, GetMeiryoFontEx(12));
- }
- else
- {
- DlgFont(hWnd, L_LIST, 12, false);
- }
+ SetFont(hWnd, L_LIST, GetMeiryoFontEx(12));
LvInsertColumn(hWnd, L_LIST, 0, L"English Name", 250);
LvInsertColumn(hWnd, L_LIST, 1, L"Local Name", 250);
@@ -1276,14 +1250,6 @@ UINT SwLang1(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard,
break;
}
- if (MsIsNt() == false)
- {
- // Win9x
- MsgBox(hWnd, MB_ICONSTOP,
- L"Windows 9x / Me doesn't support multi-language switcing.\r\n\r\nIf you want to switch to another language, please use Windows NT 4.0, 2000 or greater.");
- break;
- }
-
// Get the current selection
id = (UINT)LvGetSelectedParam(hWnd, L_LIST);
if (id != 0)
@@ -1375,35 +1341,27 @@ LABEL_RUN_CHILD_PROCESS:
// In the case of system mode
if (MsIsAdmin() == false)
{
- if (MsIsVista())
+ if (sw->IsReExecForUac == false)
{
- if (sw->IsReExecForUac == false)
- {
- // If there is no Admin privileges in Vista or later, attempt to acquire Admin rights by UAC first during the first run
- UniStrCat(add_param, sizeof(add_param), L" /SETLANGANDREBOOT:true");
+ // If there is no Admin privileges in Vista or later, attempt to acquire Admin rights by UAC first during the first run
+ UniStrCat(add_param, sizeof(add_param), L" /SETLANGANDREBOOT:true");
- if (SwReExecMyself(sw, add_param, true))
- {
- // Terminate itself if it succeeds to start the child process
- CloseWizard(wizard_page);
- break;
- }
- else
- {
- // Do nothing if it fails to start in the UAC
- sw->DoubleClickBlocker = false;
- break;
- }
+ if (SwReExecMyself(sw, add_param, true))
+ {
+ // Terminate itself if it succeeds to start the child process
+ CloseWizard(wizard_page);
+ break;
}
else
{
- // If no Admin privileges after being started by the UAC, jump to the guidance screen indicating it is not Admin
- return D_SW_NOT_ADMIN;
+ // Do nothing if it fails to start in the UAC
+ sw->DoubleClickBlocker = false;
+ break;
}
}
else
{
- // Jump to guide screen indicating that it is not the Admin in the case of XP or earlier
+ // If no Admin privileges after being started by the UAC, jump to the guidance screen indicating it is not Admin
return D_SW_NOT_ADMIN;
}
}
@@ -1507,32 +1465,24 @@ UINT SwUninst1(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard
// In the case of system mode
if (MsIsAdmin() == false)
{
- if (MsIsVista())
+ if (sw->IsReExecForUac == false)
{
- if (sw->IsReExecForUac == false)
+ // If there is no Admin privileges in Vista or later, attempt to acquire Admin rights by UAC first during the first run
+ if (SwReExecMyself(sw, NULL, true))
{
- // If there is no Admin privileges in Vista or later, attempt to acquire Admin rights by UAC first during the first run
- if (SwReExecMyself(sw, NULL, true))
- {
- // Terminate itself if it succeeds to start the child process
- CloseWizard(wizard_page);
- break;
- }
- else
- {
- // If fail to run in UAC, jump to guide screen indicating that it is not Admin
- return D_SW_NOT_ADMIN;
- }
+ // Terminate itself if it succeeds to start the child process
+ CloseWizard(wizard_page);
+ break;
}
else
{
- // If no Admin privileges after being started by the UAC, jump to the guidance screen indicating it is not Admin
+ // If fail to run in UAC, jump to guide screen indicating that it is not Admin
return D_SW_NOT_ADMIN;
}
}
else
{
- // Jump to guide screen indicating that it is not the Admin in the case of XP or earlier
+ // If no Admin privileges after being started by the UAC, jump to the guidance screen indicating it is not Admin
return D_SW_NOT_ADMIN;
}
}
@@ -1987,7 +1937,7 @@ bool SwUninstallMain(SW *sw, WIZARD_PAGE *wp, SW_COMPONENT *c)
if (UniIsEmptyStr(svc_title) == false)
{
- if (sw->IsSystemMode && MsIsNt())
+ if (sw->IsSystemMode)
{
// WinNT and system mode
if (MsIsServiceRunning(c->SvcName))
@@ -2157,17 +2107,7 @@ LABEL_RETRY_1:
if (UniIsEmptyStr(svc_title) == false)
{
- if (sw->IsSystemMode == false || MsIsNt() == false)
- {
- // Win9x or user mode
- if (MsIsNt() == false)
- {
- // Remove the Run key from the registry for Win9x
- MsRegDeleteValue(REG_LOCAL_MACHINE, WIN9X_SVC_REGKEY_1, c->SvcName);
- MsRegDeleteValue(REG_LOCAL_MACHINE, WIN9X_SVC_REGKEY_2, c->SvcName);
- }
- }
- else
+ if (sw->IsSystemMode)
{
// System mode
UniFormat(tmp, sizeof(tmp), _UU("SW_PERFORM_MSG_UNINSTALL_SVC"), svc_title);
@@ -2437,19 +2377,17 @@ void SwDefineTasks(SW *sw, SW_TASK *t, SW_COMPONENT *c)
_UU("SW_LINK_NAME_TCP"),
_UU("SW_LINK_NAME_TCP_COMMENT"), false));
- if (MsIsWin2000OrGreater())
- {
- Add(t->LinkTasks, SwNewLinkTask(MsGetSystem32DirW(), L"services.msc", NULL, L"filemgmt.dll", 0, dir_config_program,
- _UU("SW_LINK_NAME_SERVICES"),
- _UU("SW_LINK_NAME_SERVICES_COMMENT"), false));
- if (sw->IsSystemMode)
- {
- // Debugging information collecting tool
- Add(t->LinkTasks, SwNewLinkTask(sw->InstallDir, vpncmd->DstFileName, L"/debug", L"vpnsetup.exe", 4, dir_admin_tools,
- _UU("SW_LINK_NAME_DEBUG"),
- _UU("SW_LINK_NAME_DEBUG_COMMENT"), false));
- }
+ Add(t->LinkTasks, SwNewLinkTask(MsGetSystem32DirW(), L"services.msc", NULL, L"filemgmt.dll", 0, dir_config_program,
+ _UU("SW_LINK_NAME_SERVICES"),
+ _UU("SW_LINK_NAME_SERVICES_COMMENT"), false));
+
+ if (sw->IsSystemMode)
+ {
+ // Debugging information collecting tool
+ Add(t->LinkTasks, SwNewLinkTask(sw->InstallDir, vpncmd->DstFileName, L"/debug", L"vpnsetup.exe", 4, dir_admin_tools,
+ _UU("SW_LINK_NAME_DEBUG"),
+ _UU("SW_LINK_NAME_DEBUG_COMMENT"), false));
}
if (sw->IsSystemMode == false)
@@ -2508,19 +2446,16 @@ void SwDefineTasks(SW *sw, SW_TASK *t, SW_COMPONENT *c)
_UU("SW_LINK_NAME_TCP"),
_UU("SW_LINK_NAME_TCP_COMMENT"), false));
- if (MsIsWin2000OrGreater())
- {
- Add(t->LinkTasks, SwNewLinkTask(MsGetSystem32DirW(), L"services.msc", NULL, L"filemgmt.dll", 0, dir_config_program,
- _UU("SW_LINK_NAME_SERVICES"),
- _UU("SW_LINK_NAME_SERVICES_COMMENT"), false));
+ Add(t->LinkTasks, SwNewLinkTask(MsGetSystem32DirW(), L"services.msc", NULL, L"filemgmt.dll", 0, dir_config_program,
+ _UU("SW_LINK_NAME_SERVICES"),
+ _UU("SW_LINK_NAME_SERVICES_COMMENT"), false));
- if (sw->IsSystemMode)
- {
- // Debugging information collecting tool
- Add(t->LinkTasks, SwNewLinkTask(sw->InstallDir, vpncmd->DstFileName, L"/debug", L"vpnsetup.exe", 4, dir_admin_tools,
- _UU("SW_LINK_NAME_DEBUG"),
- _UU("SW_LINK_NAME_DEBUG_COMMENT"), false));
- }
+ if (sw->IsSystemMode)
+ {
+ // Debugging information collecting tool
+ Add(t->LinkTasks, SwNewLinkTask(sw->InstallDir, vpncmd->DstFileName, L"/debug", L"vpnsetup.exe", 4, dir_admin_tools,
+ _UU("SW_LINK_NAME_DEBUG"),
+ _UU("SW_LINK_NAME_DEBUG_COMMENT"), false));
}
if (sw->IsSystemMode == false)
@@ -2621,32 +2556,26 @@ void SwDefineTasks(SW *sw, SW_TASK *t, SW_COMPONENT *c)
_UU("SW_LINK_NAME_TCP"),
_UU("SW_LINK_NAME_TCP_COMMENT"), false));
- if (MsIsWin2000OrGreater())
- {
- Add(t->LinkTasks, SwNewLinkTask(MsGetSystem32DirW(), L"services.msc", NULL, L"filemgmt.dll", 0, dir_config_program,
- _UU("SW_LINK_NAME_SERVICES"),
- _UU("SW_LINK_NAME_SERVICES_COMMENT"), false));
+ Add(t->LinkTasks, SwNewLinkTask(MsGetSystem32DirW(), L"services.msc", NULL, L"filemgmt.dll", 0, dir_config_program,
+ _UU("SW_LINK_NAME_SERVICES"),
+ _UU("SW_LINK_NAME_SERVICES_COMMENT"), false));
- if (sw->IsSystemMode)
- {
- // Debugging information collecting tool
- Add(t->LinkTasks, SwNewLinkTask(sw->InstallDir, vpncmd->DstFileName, L"/debug", L"vpnsetup.exe", 4, dir_admin_tools,
- _UU("SW_LINK_NAME_DEBUG"),
- _UU("SW_LINK_NAME_DEBUG_COMMENT"), false));
- }
+ if (sw->IsSystemMode)
+ {
+ // Debugging information collecting tool
+ Add(t->LinkTasks, SwNewLinkTask(sw->InstallDir, vpncmd->DstFileName, L"/debug", L"vpnsetup.exe", 4, dir_admin_tools,
+ _UU("SW_LINK_NAME_DEBUG"),
+ _UU("SW_LINK_NAME_DEBUG_COMMENT"), false));
}
// Programs\PacketiX VPN Client\System administrators tool
- if (MsIsNt())
- {
- Add(t->LinkTasks, SwNewLinkTask(sw->InstallDir, L"vpnsetup.exe", L"/easy:true", L"vpnsetup.exe", 12, dir_admin_tools,
- _UU("SW_LINK_NAME_EASYINSTALLER"),
- _UU("SW_LINK_NAME_EASYINSTALLER_COMMENT"), false));
+ Add(t->LinkTasks, SwNewLinkTask(sw->InstallDir, L"vpnsetup.exe", L"/easy:true", L"vpnsetup.exe", 12, dir_admin_tools,
+ _UU("SW_LINK_NAME_EASYINSTALLER"),
+ _UU("SW_LINK_NAME_EASYINSTALLER_COMMENT"), false));
- Add(t->LinkTasks, SwNewLinkTask(sw->InstallDir, L"vpnsetup.exe", L"/web:true", L"vpnsetup.exe", 1, dir_admin_tools,
- _UU("SW_LINK_NAME_WEBINSTALLER"),
- _UU("SW_LINK_NAME_WEBINSTALLER_COMMENT"), false));
- }
+ Add(t->LinkTasks, SwNewLinkTask(sw->InstallDir, L"vpnsetup.exe", L"/web:true", L"vpnsetup.exe", 1, dir_admin_tools,
+ _UU("SW_LINK_NAME_WEBINSTALLER"),
+ _UU("SW_LINK_NAME_WEBINSTALLER_COMMENT"), false));
// Startup
Add(t->LinkTasks, SwNewLinkTask(sw->InstallDir, vpncmgr->DstFileName, L"/startup", NULL, 0, dir_startup,
@@ -2717,16 +2646,13 @@ void SwDefineTasks(SW *sw, SW_TASK *t, SW_COMPONENT *c)
tmp1,
tmp2, false));
- // Language settings (except for Win9x)
- if (MsIsNt())
- {
- UniFormat(tmp1, sizeof(tmp1), _UU("SW_LINK_NAME_LANGUAGE"), c->Title);
- UniFormat(tmp2, sizeof(tmp2), _UU("SW_LINK_NAME_LANGUAGE_COMMENT"), c->Title);
- Add(t->LinkTasks, SwNewLinkTask(setup_exe->DstDir, setup_exe->DstFileName, L"/language:yes",
- L"vpnsetup.exe", 10, dir_config_language,
- tmp1,
- tmp2, false));
- }
+ // Language settings
+ UniFormat(tmp1, sizeof(tmp1), _UU("SW_LINK_NAME_LANGUAGE"), c->Title);
+ UniFormat(tmp2, sizeof(tmp2), _UU("SW_LINK_NAME_LANGUAGE_COMMENT"), c->Title);
+ Add(t->LinkTasks, SwNewLinkTask(setup_exe->DstDir, setup_exe->DstFileName, L"/language:yes",
+ L"vpnsetup.exe", 10, dir_config_language,
+ tmp1,
+ tmp2, false));
// Hamcore!
Add(t->CopyTasks, SwNewCopyTask(L"hamcore.se2", NULL, sw->InstallSrc, sw->InstallDir, true, true));
@@ -3082,7 +3008,7 @@ bool SwInstallMain(SW *sw, WIZARD_PAGE *wp, SW_COMPONENT *c)
if (UniIsEmptyStr(svc_title) == false)
{
- if (sw->IsSystemMode && MsIsNt())
+ if (sw->IsSystemMode)
{
// WinNT and system mode
if (MsIsServiceRunning(c->SvcName))
@@ -3337,7 +3263,7 @@ LABEL_RETRY_2:
}
- if (sw->IsSystemMode && MsIsNt())
+ if (sw->IsSystemMode)
{
// ACL settings only in the system mode
for (i = 0;i < LIST_NUM(t->SetSecurityPaths);i++)
@@ -3398,7 +3324,7 @@ LABEL_RETRY_2:
if (UniIsEmptyStr(svc_title) == false)
{
- if (sw->IsSystemMode == false || MsIsNt() == false)
+ if (sw->IsSystemMode == false)
{
// Just simply start in user mode or Win9x mode
wchar_t fullpath[MAX_SIZE];
@@ -3407,7 +3333,7 @@ LABEL_RETRY_USERMODE_EXEC:
CombinePathW(fullpath, sizeof(fullpath), sw->InstallDir, c->SvcFileName);
- if (MsExecuteW(fullpath, (MsIsNt() ? L"/usermode" : L"/win9x_service")) == false)
+ if (MsExecuteW(fullpath, L"/usermode") == false)
{
UniFormat(tmp, sizeof(tmp), _UU("SW_PERFORM_MSG_SVC_USERMODE_EXEC_FAILED"), fullpath);
@@ -3422,19 +3348,6 @@ LABEL_RETRY_USERMODE_EXEC:
goto LABEL_RETRY_USERMODE_EXEC;
}
}
- else
- {
- if (MsIsNt() == false)
- {
- // Register into the registry as a background service in the case of Win9x
- wchar_t fullpath2[MAX_SIZE];
-
- UniFormat(fullpath2, sizeof(fullpath2), L"\"%s\" /win9x_service", fullpath);
-
- MsRegWriteStrW(REG_LOCAL_MACHINE, WIN9X_SVC_REGKEY_1, c->SvcName, fullpath2);
- MsRegWriteStrW(REG_LOCAL_MACHINE, WIN9X_SVC_REGKEY_2, c->SvcName, fullpath2);
- }
- }
}
else
{
@@ -3565,7 +3478,7 @@ LABEL_CREATE_SHORTCUT:
if (UniIsEmptyStr(svc_description) == false)
{
- if (sw->IsSystemMode && MsIsNt())
+ if (sw->IsSystemMode)
{
MsSetServiceDescription(c->SvcName, svc_description);
}
@@ -4306,17 +4219,9 @@ void SwPerformInit(HWND hWnd, SW *sw, WIZARD_PAGE *wp)
SetTextA(hWnd, S_STATUS, "");
- if (MsIsWinXPOrWinVista())
- {
- // Display the progress bar for Windows XP or later
- SendMsg(hWnd, IDC_PROGRESS1, PBM_SETMARQUEE, TRUE, 100);
- SetStyle(hWnd, IDC_PROGRESS1, PBS_MARQUEE);
- }
- else
- {
- // Hide the progress bar in the case of Windows 2000 or earlier
- Hide(hWnd, IDC_PROGRESS1);
- }
+ // Display the progress bar
+ SendMsg(hWnd, IDC_PROGRESS1, PBM_SETMARQUEE, TRUE, 100);
+ SetStyle(hWnd, IDC_PROGRESS1, PBS_MARQUEE);
}
// Do the set-up process
@@ -4572,22 +4477,11 @@ void SwInitDefaultInstallDir(SW *sw)
UniStrCpy(sw->DefaultInstallDir_User, sizeof(sw->DefaultInstallDir_User), reg_dir_user);
}
- if (MsIsNt() == false)
- {
- // Set to system mode for Win9x
- sw->IsSystemMode = true;
- }
-
if (MsIsAdmin() == false)
{
sw->IsAvailableSystemMode = false;
sw->IsAvailableUserMode = true;
}
- else if (MsIsNt() == false)
- {
- sw->IsAvailableSystemMode = true;
- sw->IsAvailableUserMode = false;
- }
else
{
sw->IsAvailableSystemMode = true;
@@ -5272,16 +5166,8 @@ UINT SwComponents(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wiz
case WM_INITDIALOG:
LvInitEx2(hWnd, L_LIST, false, true);
- if (MsIsVista())
- {
- SetFont(hWnd, L_LIST, GetMeiryoFontEx(12));
- SetFont(hWnd, S_TITLE, GetMeiryoFontEx(11));
- }
- else
- {
- DlgFont(hWnd, L_LIST, 12, false);
- DlgFont(hWnd, S_TITLE, 11, false);
- }
+ SetFont(hWnd, L_LIST, GetMeiryoFontEx(12));
+ SetFont(hWnd, S_TITLE, GetMeiryoFontEx(11));
LvInsertColumn(hWnd, L_LIST, 0, L"Component", 515);
break;
@@ -5306,13 +5192,6 @@ UINT SwComponents(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wiz
if (c != NULL)
{
- if (SwCheckOs(sw, c) == false)
- {
- // OS Check Failed
- MsgBoxEx(hWnd, MB_ICONEXCLAMATION, _UU("SW_OS_FAILED"), c->Title);
- break;
- }
-
sw->CurrentComponent = c;
if (sw->CurrentComponent->SystemModeOnly == false || MsIsAdmin())
@@ -5480,7 +5359,7 @@ UINT SwModeDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard
if (sw->IsSystemMode)
{
- if (MsIsVista() && MsIsAdmin() == false && sw->IsReExecForUac == false)
+ if (MsIsAdmin() == false && sw->IsReExecForUac == false)
{
// If UAC is available and this isn't invoked via UAC,
// give the user a chance to get administrator privileges on UAC start again
@@ -5579,33 +5458,25 @@ UINT SwWelcomeDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wiz
if (MsIsAdmin() == false)
{
- if (MsIsVista())
+ if (sw->IsReExecForUac == false)
{
- if (sw->IsReExecForUac == false)
+ // If there is no Admin privileges in Vista or later, attempt to acquire Admin rights by UAC first during the first run
+ if (SwReExecMyself(sw, NULL, true))
{
- // If there is no Admin privileges in Vista or later, attempt to acquire Admin rights by UAC first during the first run
- if (SwReExecMyself(sw, NULL, true))
- {
- // Terminate itself if it succeeds to start the child process
- CloseWizard(wizard_page);
- break;
- }
- else
- {
- // Jump to mode selection screen if it fails to start the
- // child process (including user presses the cancel of UAC)
- return D_SW_MODE;
- }
+ // Terminate itself if it succeeds to start the child process
+ CloseWizard(wizard_page);
+ break;
}
else
{
- // Jump to mode selection screen when the user don't have Admin rights after being activated by UAC
+ // Jump to mode selection screen if it fails to start the
+ // child process (including user presses the cancel of UAC)
return D_SW_MODE;
}
}
else
{
- // Jump to the mode selection screen in the case of older than Vista
+ // Jump to mode selection screen when the user don't have Admin rights after being activated by UAC
return D_SW_MODE;
}
}
@@ -5710,10 +5581,7 @@ void SwUiMain(SW *sw)
AddWizardPage(w, NewWizardPage(D_SW_WEB1, SwWeb1, _UU("SW_WEB1_TITLE")));
AddWizardPage(w, NewWizardPage(D_SW_WEB2, SwWeb2, _UU("SW_WEB2_TITLE")));
- if (MsIsVista())
- {
- w->IsAreoStyle = true;
- }
+ w->IsAreoStyle = true;
if (sw->UninstallMode)
{
@@ -5984,48 +5852,6 @@ SW_COMPONENT *SwNewComponent(char *name, char *svc_name, UINT id, UINT icon, UIN
return c;
}
-// Examine the OS requirements
-bool SwCheckOs(SW *sw, SW_COMPONENT *c)
-{
- // Validate arguments
- if (sw == NULL || c == NULL)
- {
- return false;
- }
-
- if (c->Id == SW_CMP_VPN_CLIENT)
- {
- OS_INFO *info = GetOsInfo();
-
- if (OS_IS_WINDOWS_NT(info->OsType))
- {
- if (MsIsWin2000OrGreater() == false)
- {
- // It doesn't work with WinNT 4.0
- return false;
- }
- }
- else
- {
- if (GET_KETA(info->OsType, 100) <= 1)
- {
- // It doesn't work with Win95
- return false;
- }
- else if (info->OsType == OSTYPE_WINDOWS_98)
- {
- if (EndWith(info->OsVersion, "A") == false)
- {
- // It doesn't work in Win98 First Edition
- return false;
- }
- }
- }
- }
-
- return true;
-}
-
// Define the component
void SwDefineComponents(SW *sw)
{
diff --git a/src/Cedar/SW.h b/src/Cedar/SW.h
index 718ee3f2..cd3488f0 100644
--- a/src/Cedar/SW.h
+++ b/src/Cedar/SW.h
@@ -8,6 +8,8 @@
#ifndef SW_H
#define SW_H
+#include "Mayaqua/MayaType.h"
+
#define SW_REG_KEY "Software\\" GC_REG_COMPANY_NAME "\\Setup Wizard Settings"
diff --git a/src/Cedar/SWInner.h b/src/Cedar/SWInner.h
index a1617ddf..8b41a21a 100644
--- a/src/Cedar/SWInner.h
+++ b/src/Cedar/SWInner.h
@@ -8,6 +8,8 @@
#ifndef SW_INNER_H
#define SW_INNER_H
+#include "WinUi.h"
+
// Component string
#define SW_NAME_VPNSERVER "vpnserver"
#define SW_LONG_VPNSERVER _UU("SW_LONG_VPNSERVER")
@@ -287,8 +289,6 @@ void SwFreeLogFile(SW_LOGFILE *logfile);
void SwInstallShortcuts(SW *sw, WIZARD_PAGE *wp, SW_COMPONENT *c, SW_TASK *t);
void SwDeleteShortcuts(SW_LOGFILE *logfile);
-bool SwCheckOs(SW *sw, SW_COMPONENT *c);
-
bool SwEnterSingle(SW *sw);
void SwLeaveSingle(SW *sw);
diff --git a/src/Cedar/Sam.c b/src/Cedar/Sam.c
index 3836dc5e..e9a72b64 100644
--- a/src/Cedar/Sam.c
+++ b/src/Cedar/Sam.c
@@ -5,8 +5,31 @@
// Sam.c
// Security Accounts Manager
-#include "CedarPch.h"
+#include "Sam.h"
+#include "Account.h"
+#include "Cedar.h"
+#include "Hub.h"
+#include "IPC.h"
+#include "Proto_PPP.h"
+#include "Radius.h"
+#include "Server.h"
+
+#include "Mayaqua/Internat.h"
+#include "Mayaqua/Memory.h"
+#include "Mayaqua/Microsoft.h"
+#include "Mayaqua/Object.h"
+#include "Mayaqua/Str.h"
+
+#include