├── ToyVpn
├── pch.cpp
├── App.idl
├── Assets
│ ├── StoreLogo.png
│ ├── SplashScreen.scale-200.png
│ ├── LockScreenLogo.scale-200.png
│ ├── Square150x150Logo.scale-200.png
│ ├── Square44x44Logo.scale-200.png
│ ├── Wide310x150Logo.scale-200.png
│ └── Square44x44Logo.targetsize-24_altform-unplated.png
├── MainPage.idl
├── packages.config
├── App.xaml
├── App.h
├── pch.h
├── MainPage.h
├── readme.txt
├── MainPage.xaml
├── ToyVpn.vcxproj.filters
├── Package.appxmanifest
├── MainPage.cpp
├── App.cpp
└── ToyVpn.vcxproj
├── ToyVpnBG
├── pch.cpp
├── ToyVpnBG.def
├── packages.config
├── VpnBackgroundTask.idl
├── VpnBackgroundTask.h
├── pch.h
├── VpnBackgroundTask.cpp
├── readme.txt
├── ToyVpnBG.vcxproj.filters
├── VpnPlugin.h
├── VpnPlugin.cpp
└── ToyVpnBG.vcxproj
├── README.md
├── LICENSE
├── strutil.h
├── ToyVpn.sln
└── .gitignore
/ToyVpn/pch.cpp:
--------------------------------------------------------------------------------
1 | #include "pch.h"
2 |
--------------------------------------------------------------------------------
/ToyVpnBG/pch.cpp:
--------------------------------------------------------------------------------
1 | #include "pch.h"
2 |
--------------------------------------------------------------------------------
/ToyVpn/App.idl:
--------------------------------------------------------------------------------
1 | namespace ToyVpn
2 | {
3 | }
4 |
--------------------------------------------------------------------------------
/ToyVpn/Assets/StoreLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ysc3839/UWPToyVpn/HEAD/ToyVpn/Assets/StoreLogo.png
--------------------------------------------------------------------------------
/ToyVpn/Assets/SplashScreen.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ysc3839/UWPToyVpn/HEAD/ToyVpn/Assets/SplashScreen.scale-200.png
--------------------------------------------------------------------------------
/ToyVpn/Assets/LockScreenLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ysc3839/UWPToyVpn/HEAD/ToyVpn/Assets/LockScreenLogo.scale-200.png
--------------------------------------------------------------------------------
/ToyVpn/Assets/Square150x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ysc3839/UWPToyVpn/HEAD/ToyVpn/Assets/Square150x150Logo.scale-200.png
--------------------------------------------------------------------------------
/ToyVpn/Assets/Square44x44Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ysc3839/UWPToyVpn/HEAD/ToyVpn/Assets/Square44x44Logo.scale-200.png
--------------------------------------------------------------------------------
/ToyVpn/Assets/Wide310x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ysc3839/UWPToyVpn/HEAD/ToyVpn/Assets/Wide310x150Logo.scale-200.png
--------------------------------------------------------------------------------
/ToyVpnBG/ToyVpnBG.def:
--------------------------------------------------------------------------------
1 | EXPORTS
2 | DllCanUnloadNow = WINRT_CanUnloadNow PRIVATE
3 | DllGetActivationFactory = WINRT_GetActivationFactory PRIVATE
4 |
--------------------------------------------------------------------------------
/ToyVpn/Assets/Square44x44Logo.targetsize-24_altform-unplated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ysc3839/UWPToyVpn/HEAD/ToyVpn/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
--------------------------------------------------------------------------------
/ToyVpn/MainPage.idl:
--------------------------------------------------------------------------------
1 | namespace ToyVpn
2 | {
3 | [default_interface]
4 | runtimeclass MainPage : Windows.UI.Xaml.Controls.Page
5 | {
6 | MainPage();
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/ToyVpn/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/ToyVpnBG/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/ToyVpnBG/VpnBackgroundTask.idl:
--------------------------------------------------------------------------------
1 | namespace ToyVpnBG
2 | {
3 | [default_interface]
4 | runtimeclass VpnBackgroundTask : Windows.ApplicationModel.Background.IBackgroundTask
5 | {
6 | VpnBackgroundTask();
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/ToyVpn/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # UWPToyVpn
2 | UWPToyVpn is a sample application that shows how to build a VPN client using the [Windows.Networking.Vpn](https://docs.microsoft.com/en-us/uwp/api/Windows.Networking.Vpn) class.
3 |
4 | It was inspired by Android's [ToyVpn](https://android.googlesource.com/platform/development/+/master/samples/ToyVpn).
5 |
6 | The server-side implementation is compatible with [ToyVpn's](https://android.googlesource.com/platform/development/+/master/samples/ToyVpn/server/linux).
7 |
--------------------------------------------------------------------------------
/ToyVpn/App.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "App.xaml.g.h"
3 |
4 | namespace winrt::ToyVpn::implementation
5 | {
6 | struct App : AppT
7 | {
8 | App();
9 |
10 | void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs const&);
11 | void OnSuspending(IInspectable const&, Windows::ApplicationModel::SuspendingEventArgs const&);
12 | void OnNavigationFailed(IInspectable const&, Windows::UI::Xaml::Navigation::NavigationFailedEventArgs const&);
13 | };
14 | }
15 |
--------------------------------------------------------------------------------
/ToyVpnBG/VpnBackgroundTask.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "VpnBackgroundTask.g.h"
4 |
5 | namespace winrt::ToyVpnBG::implementation
6 | {
7 | struct VpnBackgroundTask : VpnBackgroundTaskT
8 | {
9 | VpnBackgroundTask() = default;
10 |
11 | void Run(Windows::ApplicationModel::Background::IBackgroundTaskInstance const& taskInstance);
12 | };
13 | }
14 |
15 | namespace winrt::ToyVpnBG::factory_implementation
16 | {
17 | struct VpnBackgroundTask : VpnBackgroundTaskT
18 | {
19 | };
20 | }
21 |
--------------------------------------------------------------------------------
/ToyVpnBG/pch.h:
--------------------------------------------------------------------------------
1 | //
2 | // pch.h
3 | // Header for platform projection include files
4 | //
5 |
6 | #pragma once
7 |
8 | #define WIN32_LEAN_AND_MEAN
9 | //#include
10 | #include
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 |
--------------------------------------------------------------------------------
/ToyVpn/pch.h:
--------------------------------------------------------------------------------
1 | //
2 | // pch.h
3 | // Header for platform projection include files
4 | //
5 |
6 | #pragma once
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
--------------------------------------------------------------------------------
/ToyVpnBG/VpnBackgroundTask.cpp:
--------------------------------------------------------------------------------
1 | #include "pch.h"
2 | #include "VpnBackgroundTask.h"
3 | #include "VpnPlugin.h"
4 |
5 | using namespace winrt;
6 | using namespace Windows::ApplicationModel::Core;
7 |
8 | namespace winrt::ToyVpnBG::implementation
9 | {
10 | void VpnBackgroundTask::Run(Windows::ApplicationModel::Background::IBackgroundTaskInstance const& taskInstance)
11 | {
12 | auto deferral = taskInstance.GetDeferral();
13 | try
14 | {
15 | hstring pluginId{ L"ToyVpnPlugin" };
16 |
17 | IInspectable plugin;
18 | if (CoreApplication::Properties().HasKey(pluginId))
19 | {
20 | plugin = CoreApplication::Properties().Lookup(pluginId);
21 | }
22 | else
23 | {
24 | plugin = make();
25 | CoreApplication::Properties().Insert(pluginId, plugin);
26 | }
27 |
28 | Windows::Networking::Vpn::VpnChannel::ProcessEventAsync(plugin, taskInstance.TriggerDetails());
29 | }
30 | catch (winrt::hresult_error const&)
31 | {
32 | }
33 | deferral.Complete();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/ToyVpn/MainPage.h:
--------------------------------------------------------------------------------
1 | //
2 | // Declaration of the MainPage class.
3 | //
4 |
5 | #pragma once
6 |
7 | #include "MainPage.g.h"
8 |
9 | namespace winrt::ToyVpn::implementation
10 | {
11 | struct MainPage : MainPageT
12 | {
13 | MainPage();
14 |
15 | void LaunchVPNSettings(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args);
16 | Windows::Foundation::IAsyncAction SaveVPN(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args);
17 | Windows::Foundation::IAsyncAction ConnectVPN(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args);
18 | Windows::Foundation::IAsyncAction DisconnectVPN(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args);
19 |
20 | private:
21 | void LoadSettings();
22 | void SaveSettings();
23 | };
24 | }
25 |
26 | namespace winrt::ToyVpn::factory_implementation
27 | {
28 | struct MainPage : MainPageT
29 | {
30 | };
31 | }
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 ysc3839
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/ToyVpn/readme.txt:
--------------------------------------------------------------------------------
1 | ========================================================================
2 | C++/WinRT ToyVpn Project Overview
3 | ========================================================================
4 |
5 | This project demonstrates how to get started writing XAML apps directly
6 | with standard C++, using the C++/WinRT SDK component and XAML compiler
7 | support to generate implementation headers from interface (IDL) files.
8 | These headers can then be used to implement the local Windows Runtime
9 | classes referenced in the app's XAML pages.
10 |
11 | Steps:
12 | 1. Create an interface (IDL) file to define any local Windows Runtime
13 | classes referenced in the app's XAML pages.
14 | 2. Build the project once to generate implementation templates under
15 | the "Generated Files" folder, as well as skeleton class definitions
16 | under "Generated Files\sources".
17 | 3. Use the skeleton class definitions for reference to implement your
18 | Windows Runtime classes.
19 |
20 | ========================================================================
21 | Learn more about C++/WinRT here:
22 | http://aka.ms/cppwinrt/
23 | ========================================================================
24 |
--------------------------------------------------------------------------------
/strutil.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | void rtrimwsv(std::wstring_view& sv)
4 | {
5 | size_t end = sv.find_last_not_of(L' ');
6 | if (end != std::wstring_view::npos)
7 | sv.remove_suffix(sv.size() - end - 1);
8 | }
9 |
10 | // https://www.bfilipek.com/2018/07/string-view-perf-followup.html
11 | std::vector splitwsv(std::wstring_view strv, wchar_t delim = L' ')
12 | {
13 | std::vector output;
14 | size_t first = 0;
15 |
16 | while (first < strv.size())
17 | {
18 | const auto second = strv.find_first_of(delim, first);
19 |
20 | if (first != second)
21 | output.emplace_back(strv.substr(first, second - first));
22 |
23 | if (second == std::string_view::npos)
24 | break;
25 |
26 | first = second + 1;
27 | }
28 |
29 | return output;
30 | }
31 |
32 | std::vector splitws(std::wstring_view strv, wchar_t delim = L' ')
33 | {
34 | std::vector output;
35 | size_t first = 0;
36 |
37 | while (first < strv.size())
38 | {
39 | const auto second = strv.find_first_of(delim, first);
40 |
41 | if (first != second)
42 | output.emplace_back(strv.substr(first, second - first));
43 |
44 | if (second == std::string_view::npos)
45 | break;
46 |
47 | first = second + 1;
48 | }
49 |
50 | return output;
51 | }
52 |
--------------------------------------------------------------------------------
/ToyVpnBG/readme.txt:
--------------------------------------------------------------------------------
1 | ========================================================================
2 | C++/WinRT ToyVpnBG Project Overview
3 | ========================================================================
4 |
5 | This project demonstrates how to get started authoring Windows Runtime
6 | classes directly with standard C++, using the C++/WinRT SDK component
7 | to generate implementation headers from interface (IDL) files. The
8 | generated Windows Runtime component binary and WinMD files should then
9 | be bundled with the Universal Windows Platform (UWP) app consuming them.
10 |
11 | Steps:
12 | 1. Create an interface (IDL) file to define your Windows Runtime class,
13 | its default interface, and any other interfaces it implements.
14 | 2. Build the project once to generate module.g.cpp, module.h.cpp, and
15 | implementation templates under the "Generated Files" folder, as
16 | well as skeleton class definitions under "Generated Files\sources".
17 | 3. Use the skeleton class definitions for reference to implement your
18 | Windows Runtime classes.
19 |
20 | ========================================================================
21 | Learn more about C++/WinRT here:
22 | http://aka.ms/cppwinrt/
23 | ========================================================================
24 |
--------------------------------------------------------------------------------
/ToyVpnBG/ToyVpnBG.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | accd3aa8-1ba0-4223-9bbe-0c431709210b
6 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms
7 |
8 |
9 | {926ab91d-31b4-48c3-b9a4-e681349f27f0}
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/ToyVpnBG/VpnPlugin.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | namespace winrt::ToyVpnBG::implementation
4 | {
5 | enum HandshakeState
6 | {
7 | Waiting,
8 | Received,
9 | Canceled
10 | };
11 |
12 | struct VpnPlugin : implements
13 | {
14 | VpnPlugin() = default;
15 |
16 | void Connect(Windows::Networking::Vpn::VpnChannel const& channel);
17 | void Disconnect(Windows::Networking::Vpn::VpnChannel const& channel);
18 | void GetKeepAlivePayload(Windows::Networking::Vpn::VpnChannel const& channel, Windows::Networking::Vpn::VpnPacketBuffer& keepAlivePacket);
19 | void Encapsulate(Windows::Networking::Vpn::VpnChannel const& channel, Windows::Networking::Vpn::VpnPacketBufferList const& packets, Windows::Networking::Vpn::VpnPacketBufferList const& encapulatedPackets);
20 | void Decapsulate(Windows::Networking::Vpn::VpnChannel const& channel, Windows::Networking::Vpn::VpnPacketBuffer const& encapBuffer, Windows::Networking::Vpn::VpnPacketBufferList const& decapsulatedPackets, Windows::Networking::Vpn::VpnPacketBufferList const& controlPacketsToSend);
21 |
22 | private:
23 | void Handshake(Windows::Networking::Sockets::DatagramSocket const& tunnel, std::atomic const& handshakeState, std::wstring const& secret);
24 | void Configure(Windows::Networking::Vpn::VpnChannel const& channel, hstring const& parametershs);
25 | };
26 |
27 | struct VpnPluginContext : implements
28 | {
29 | friend struct VpnPlugin;
30 |
31 | VpnPluginContext() = default;
32 |
33 | private:
34 | std::atomic handshakeState{ Waiting };
35 | };
36 | }
37 |
--------------------------------------------------------------------------------
/ToyVpn/MainPage.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/ToyVpn/ToyVpn.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | Assets
27 |
28 |
29 | Assets
30 |
31 |
32 | Assets
33 |
34 |
35 | Assets
36 |
37 |
38 | Assets
39 |
40 |
41 | Assets
42 |
43 |
44 | Assets
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | {e48dc53e-40b1-40cb-970a-f89935452892}
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/ToyVpn/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | ToyVpn
7 | Richard
8 | Assets\StoreLogo.png
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/ToyVpn.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.28307.329
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ToyVpn", "ToyVpn\ToyVpn.vcxproj", "{C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ToyVpnBG", "ToyVpnBG\ToyVpnBG.vcxproj", "{BE554DC8-B093-4EB7-8006-72717C6C3D63}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|ARM = Debug|ARM
13 | Debug|x64 = Debug|x64
14 | Debug|x86 = Debug|x86
15 | Release|ARM = Release|ARM
16 | Release|x64 = Release|x64
17 | Release|x86 = Release|x86
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}.Debug|ARM.ActiveCfg = Debug|ARM
21 | {C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}.Debug|ARM.Build.0 = Debug|ARM
22 | {C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}.Debug|ARM.Deploy.0 = Debug|ARM
23 | {C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}.Debug|x64.ActiveCfg = Debug|x64
24 | {C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}.Debug|x64.Build.0 = Debug|x64
25 | {C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}.Debug|x64.Deploy.0 = Debug|x64
26 | {C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}.Debug|x86.ActiveCfg = Debug|Win32
27 | {C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}.Debug|x86.Build.0 = Debug|Win32
28 | {C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}.Debug|x86.Deploy.0 = Debug|Win32
29 | {C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}.Release|ARM.ActiveCfg = Release|ARM
30 | {C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}.Release|ARM.Build.0 = Release|ARM
31 | {C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}.Release|ARM.Deploy.0 = Release|ARM
32 | {C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}.Release|x64.ActiveCfg = Release|x64
33 | {C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}.Release|x64.Build.0 = Release|x64
34 | {C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}.Release|x64.Deploy.0 = Release|x64
35 | {C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}.Release|x86.ActiveCfg = Release|Win32
36 | {C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}.Release|x86.Build.0 = Release|Win32
37 | {C612F6F5-70DA-43D3-9E59-1CC7DFE5C523}.Release|x86.Deploy.0 = Release|Win32
38 | {BE554DC8-B093-4EB7-8006-72717C6C3D63}.Debug|ARM.ActiveCfg = Debug|ARM
39 | {BE554DC8-B093-4EB7-8006-72717C6C3D63}.Debug|ARM.Build.0 = Debug|ARM
40 | {BE554DC8-B093-4EB7-8006-72717C6C3D63}.Debug|x64.ActiveCfg = Debug|x64
41 | {BE554DC8-B093-4EB7-8006-72717C6C3D63}.Debug|x64.Build.0 = Debug|x64
42 | {BE554DC8-B093-4EB7-8006-72717C6C3D63}.Debug|x86.ActiveCfg = Debug|Win32
43 | {BE554DC8-B093-4EB7-8006-72717C6C3D63}.Debug|x86.Build.0 = Debug|Win32
44 | {BE554DC8-B093-4EB7-8006-72717C6C3D63}.Release|ARM.ActiveCfg = Release|ARM
45 | {BE554DC8-B093-4EB7-8006-72717C6C3D63}.Release|ARM.Build.0 = Release|ARM
46 | {BE554DC8-B093-4EB7-8006-72717C6C3D63}.Release|x64.ActiveCfg = Release|x64
47 | {BE554DC8-B093-4EB7-8006-72717C6C3D63}.Release|x64.Build.0 = Release|x64
48 | {BE554DC8-B093-4EB7-8006-72717C6C3D63}.Release|x86.ActiveCfg = Release|Win32
49 | {BE554DC8-B093-4EB7-8006-72717C6C3D63}.Release|x86.Build.0 = Release|Win32
50 | EndGlobalSection
51 | GlobalSection(SolutionProperties) = preSolution
52 | HideSolutionNode = FALSE
53 | EndGlobalSection
54 | GlobalSection(ExtensibilityGlobals) = postSolution
55 | SolutionGuid = {CB878D72-0B43-4339-881C-29C453F972F8}
56 | EndGlobalSection
57 | EndGlobal
58 |
--------------------------------------------------------------------------------
/ToyVpn/MainPage.cpp:
--------------------------------------------------------------------------------
1 | #include "pch.h"
2 | #include "MainPage.h"
3 | #include "../strutil.h"
4 |
5 | using namespace winrt;
6 | using namespace Windows::Foundation;
7 | using namespace Windows::Networking::Vpn;
8 |
9 | namespace winrt::ToyVpn::implementation
10 | {
11 | constexpr auto vpnProfileName = L"ToyVpnProfile";
12 |
13 | struct VpnPlugInProfileWithName : VpnPlugInProfile
14 | {
15 | VpnPlugInProfileWithName(param::hstring const& value)
16 | {
17 | ProfileName(value);
18 | }
19 | };
20 |
21 | MainPage::MainPage()
22 | {
23 | InitializeComponent();
24 | LoadSettings();
25 | }
26 |
27 | void MainPage::LaunchVPNSettings(IInspectable const&, Windows::UI::Xaml::RoutedEventArgs const&)
28 | {
29 | Windows::System::Launcher::LaunchUriAsync({ L"ms-settings:network-vpn" });
30 | }
31 |
32 | IAsyncAction MainPage::SaveVPN(IInspectable const&, Windows::UI::Xaml::RoutedEventArgs const&)
33 | {
34 | SaveSettings();
35 |
36 | Windows::Data::Xml::Dom::XmlDocument doc;
37 | auto elemConfig = doc.CreateElement(L"toyvpn-config");
38 | doc.AppendChild(elemConfig);
39 |
40 | auto elemPort = doc.CreateElement(L"port");
41 | elemPort.InnerText(inputPort().Text());
42 | elemConfig.AppendChild(elemPort);
43 |
44 | auto elemSecret = doc.CreateElement(L"secret");
45 | elemSecret.InnerText(inputSecret().Text());
46 | elemConfig.AppendChild(elemSecret);
47 |
48 | VpnPlugInProfile profile;
49 | profile.AlwaysOn(chkAlwaysOn().IsChecked().Value());
50 | profile.CustomConfiguration(doc.GetXml());
51 | profile.ProfileName(vpnProfileName);
52 | profile.RememberCredentials(false);
53 | profile.RequireVpnClientAppUI(chkShowInSettings().IsChecked().Value());
54 | profile.VpnPluginPackageFamilyName(Windows::ApplicationModel::Package::Current().Id().FamilyName());
55 |
56 | std::wstring_view server{ inputServer().Text() };
57 | profile.ServerUris().Append({ server._Starts_with(L"http://") ? server : L"http://" + server });
58 |
59 | co_await VpnManagementAgent().UpdateProfileFromObjectAsync(profile);
60 | }
61 |
62 | IAsyncAction MainPage::ConnectVPN(IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args)
63 | {
64 | co_await SaveVPN(sender, args);
65 | co_await VpnManagementAgent().ConnectProfileAsync(VpnPlugInProfileWithName(vpnProfileName));
66 | }
67 |
68 | IAsyncAction MainPage::DisconnectVPN(IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args)
69 | {
70 | co_await VpnManagementAgent().DisconnectProfileAsync(VpnPlugInProfileWithName(vpnProfileName));
71 | }
72 |
73 | void MainPage::LoadSettings()
74 | {
75 | auto roamingSettingsValues = Windows::Storage::ApplicationData::Current().RoamingSettings().Values();
76 | inputServer().Text(unbox_value_or(roamingSettingsValues.Lookup(L"server"), {}));
77 | inputPort().Text(unbox_value_or(roamingSettingsValues.Lookup(L"port"), {}));
78 | inputSecret().Text(unbox_value_or(roamingSettingsValues.Lookup(L"secret"), {}));
79 | chkAlwaysOn().IsChecked(unbox_value_or(roamingSettingsValues.Lookup(L"alwaysOn"), false));
80 | chkShowInSettings().IsChecked(unbox_value_or(roamingSettingsValues.Lookup(L"showInSettings"), true));
81 | }
82 |
83 | void MainPage::SaveSettings()
84 | {
85 | auto roamingSettingsValues = Windows::Storage::ApplicationData::Current().RoamingSettings().Values();
86 | roamingSettingsValues.Insert(L"server", box_value(inputServer().Text()));
87 | roamingSettingsValues.Insert(L"port", box_value(inputPort().Text()));
88 | roamingSettingsValues.Insert(L"secret", box_value(inputSecret().Text()));
89 | roamingSettingsValues.Insert(L"alwaysOn", box_value(chkAlwaysOn().IsChecked()));
90 | roamingSettingsValues.Insert(L"showInSettings", box_value(chkShowInSettings().IsChecked()));
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/ToyVpn/App.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // App.xaml.cpp
3 | // Implementation of the App class.
4 | //
5 |
6 | #include "pch.h"
7 |
8 | #include "App.h"
9 | #include "MainPage.h"
10 |
11 | using namespace winrt;
12 | using namespace Windows::ApplicationModel;
13 | using namespace Windows::ApplicationModel::Activation;
14 | using namespace Windows::Foundation;
15 | using namespace Windows::UI::Xaml;
16 | using namespace Windows::UI::Xaml::Controls;
17 | using namespace Windows::UI::Xaml::Navigation;
18 | using namespace ToyVpn;
19 | using namespace ToyVpn::implementation;
20 |
21 | ///
22 | /// Initializes the singleton application object. This is the first line of authored code
23 | /// executed, and as such is the logical equivalent of main() or WinMain().
24 | ///
25 | App::App()
26 | {
27 | InitializeComponent();
28 | Suspending({ this, &App::OnSuspending });
29 |
30 | #if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
31 | UnhandledException([this](IInspectable const&, UnhandledExceptionEventArgs const& e)
32 | {
33 | if (IsDebuggerPresent())
34 | {
35 | auto errorMessage = e.Message();
36 | __debugbreak();
37 | }
38 | });
39 | #endif
40 | }
41 |
42 | ///
43 | /// Invoked when the application is launched normally by the end user. Other entry points
44 | /// will be used such as when the application is launched to open a specific file.
45 | ///
46 | /// Details about the launch request and process.
47 | void App::OnLaunched(LaunchActivatedEventArgs const& e)
48 | {
49 | Frame rootFrame{ nullptr };
50 | auto content = Window::Current().Content();
51 | if (content)
52 | {
53 | rootFrame = content.try_as();
54 | }
55 |
56 | // Do not repeat app initialization when the Window already has content,
57 | // just ensure that the window is active
58 | if (rootFrame == nullptr)
59 | {
60 | // Create a Frame to act as the navigation context and associate it with
61 | // a SuspensionManager key
62 | rootFrame = Frame();
63 |
64 | rootFrame.NavigationFailed({ this, &App::OnNavigationFailed });
65 |
66 | if (e.PreviousExecutionState() == ApplicationExecutionState::Terminated)
67 | {
68 | // Restore the saved session state only when appropriate, scheduling the
69 | // final launch steps after the restore is complete
70 | }
71 |
72 | if (e.PrelaunchActivated() == false)
73 | {
74 | if (rootFrame.Content() == nullptr)
75 | {
76 | // When the navigation stack isn't restored navigate to the first page,
77 | // configuring the new page by passing required information as a navigation
78 | // parameter
79 | rootFrame.Navigate(xaml_typename(), box_value(e.Arguments()));
80 | }
81 | // Place the frame in the current Window
82 | Window::Current().Content(rootFrame);
83 | // Ensure the current window is active
84 | Window::Current().Activate();
85 | }
86 | }
87 | else
88 | {
89 | if (e.PrelaunchActivated() == false)
90 | {
91 | if (rootFrame.Content() == nullptr)
92 | {
93 | // When the navigation stack isn't restored navigate to the first page,
94 | // configuring the new page by passing required information as a navigation
95 | // parameter
96 | rootFrame.Navigate(xaml_typename(), box_value(e.Arguments()));
97 | }
98 | // Ensure the current window is active
99 | Window::Current().Activate();
100 | }
101 | }
102 | }
103 |
104 | ///
105 | /// Invoked when application execution is being suspended. Application state is saved
106 | /// without knowing whether the application will be terminated or resumed with the contents
107 | /// of memory still intact.
108 | ///
109 | /// The source of the suspend request.
110 | /// Details about the suspend request.
111 | void App::OnSuspending([[maybe_unused]] IInspectable const& sender, [[maybe_unused]] SuspendingEventArgs const& e)
112 | {
113 | // Save application state and stop any background activity
114 | }
115 |
116 | ///
117 | /// Invoked when Navigation to a certain page fails
118 | ///
119 | /// The Frame which failed navigation
120 | /// Details about the navigation failure
121 | void App::OnNavigationFailed(IInspectable const&, NavigationFailedEventArgs const& e)
122 | {
123 | throw hresult_error(E_FAIL, hstring(L"Failed to load Page ") + e.SourcePageType().Name);
124 | }
125 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
262 |
263 | # C++/WinRT
264 | Generated Files/
265 |
--------------------------------------------------------------------------------
/ToyVpnBG/VpnPlugin.cpp:
--------------------------------------------------------------------------------
1 | #include "pch.h"
2 | #include "VpnPlugin.h"
3 | #include "../strutil.h"
4 |
5 | using namespace winrt;
6 | using namespace Windows::Networking;
7 | using namespace Windows::Networking::Vpn;
8 | using namespace Windows::Networking::Sockets;
9 | using namespace Windows::Storage::Streams;
10 |
11 | using namespace std::chrono_literals;
12 |
13 | namespace winrt::ToyVpnBG::implementation
14 | {
15 | constexpr int MAX_HANDSHAKE_ATTEMPTS = 50;
16 | constexpr auto IDLE_INTERVAL = 100ms;
17 |
18 | constexpr int MAX_PACKET_SIZE = UINT16_MAX;
19 |
20 | void VpnPlugin::Connect(VpnChannel const& channel)
21 | {
22 | try
23 | {
24 | auto context = channel.PlugInContext().as();
25 | if (!context)
26 | {
27 | context = make().as();
28 | channel.PlugInContext(context.as());
29 | }
30 |
31 | DatagramSocket tunnel;
32 | channel.AssociateTransport(tunnel, nullptr);
33 |
34 | hstring parametershs;
35 | winrt::event_token token = tunnel.MessageReceived([&](DatagramSocket const& /*sender*/, DatagramSocketMessageReceivedEventArgs const& args)
36 | {
37 | DataReader reader{ args.GetDataReader() };
38 | if (reader.UnconsumedBufferLength() > 0 && reader.ReadByte() == 0)
39 | {
40 | parametershs = reader.ReadString(reader.UnconsumedBufferLength());
41 |
42 | tunnel.MessageReceived(token);
43 | context->handshakeState.store(HandshakeState::Received);
44 | }
45 | });
46 |
47 | HostName serverHostname{ nullptr };
48 | try
49 | {
50 | serverHostname = channel.Configuration().ServerHostNameList().GetAt(0);
51 | }
52 | catch (hresult_error const&)
53 | {
54 | throw hresult_invalid_argument{ L"Invalid server host name" };
55 | }
56 |
57 | std::wstring port, secret;
58 |
59 | Windows::Data::Xml::Dom::XmlDocument doc;
60 | doc.LoadXml(channel.Configuration().CustomField());
61 | auto root = doc.FirstChild();
62 | if (root.NodeName() == L"toyvpn-config")
63 | {
64 | for (auto node : root.ChildNodes())
65 | {
66 | if (node.NodeName() == L"port")
67 | port = node.InnerText();
68 | else if (node.NodeName() == L"secret")
69 | secret = node.InnerText();
70 | }
71 | }
72 |
73 | tunnel.ConnectAsync(serverHostname, port).get();
74 |
75 | Handshake(tunnel, context->handshakeState, secret);
76 |
77 | Configure(channel, parametershs);
78 | }
79 | catch (hresult_error const& ex)
80 | {
81 | channel.TerminateConnection(ex.message());
82 | }
83 | }
84 |
85 | void VpnPlugin::Disconnect(VpnChannel const& channel)
86 | {
87 | try
88 | {
89 | auto context = channel.PlugInContext().as();
90 | if (!context)
91 | {
92 | }
93 | else
94 | {
95 | context->handshakeState.store(HandshakeState::Canceled);
96 | channel.Stop();
97 | }
98 | }
99 | catch (winrt::hresult_error const&)
100 | {
101 | }
102 | channel.PlugInContext(nullptr);
103 | }
104 |
105 | void VpnPlugin::GetKeepAlivePayload(VpnChannel const& /*channel*/, VpnPacketBuffer& /*keepAlivePacket*/)
106 | {
107 | }
108 |
109 | void VpnPlugin::Encapsulate(VpnChannel const& /*channel*/, VpnPacketBufferList const& packets, VpnPacketBufferList const& encapulatedPackets)
110 | {
111 | while (packets.Size() > 0)
112 | {
113 | encapulatedPackets.Append(packets.RemoveAtBegin());
114 | }
115 | }
116 |
117 | void VpnPlugin::Decapsulate(VpnChannel const& channel, VpnPacketBuffer const& encapBuffer, VpnPacketBufferList const& decapsulatedPackets, VpnPacketBufferList const& /*controlPacketsToSend*/)
118 | {
119 | auto buf = channel.GetVpnReceivePacketBuffer();
120 | auto len = encapBuffer.Buffer().Length();
121 | if (len > buf.Buffer().Capacity())
122 | {
123 | return;
124 | }
125 |
126 | memcpy(buf.Buffer().data(), encapBuffer.Buffer().data(), len);
127 | buf.Buffer().Length(len);
128 | decapsulatedPackets.Append(buf);
129 | }
130 |
131 | void VpnPlugin::Handshake(DatagramSocket const& tunnel, std::atomic const& handshakeState, std::wstring const& secret)
132 | {
133 | for (int i = 0; i < 3; ++i)
134 | {
135 | DataWriter writer{ tunnel.OutputStream() };
136 | writer.UnicodeEncoding(UnicodeEncoding::Utf8);
137 | writer.WriteByte(0);
138 | writer.WriteString(secret);
139 | writer.StoreAsync().get();
140 | writer.DetachStream();
141 | }
142 |
143 | for (int i = 0; i < MAX_HANDSHAKE_ATTEMPTS; ++i)
144 | {
145 | std::this_thread::sleep_for(IDLE_INTERVAL);
146 |
147 | switch (handshakeState.load())
148 | {
149 | case HandshakeState::Received:
150 | return;
151 | case HandshakeState::Canceled:
152 | throw hresult_canceled{};
153 | }
154 | }
155 |
156 | throw hresult_error{ E_FAIL, L"Operation timed out" };
157 | }
158 |
159 | void VpnPlugin::Configure(Windows::Networking::Vpn::VpnChannel const & channel, hstring const& parametershs)
160 | {
161 | std::wstring_view parameters{ parametershs };
162 | rtrimwsv(parameters);
163 |
164 | uint32_t mtuSize{};
165 | std::vector IPv4AddrList;
166 | VpnRouteAssignment route;
167 | auto IPv4Routes = route.Ipv4InclusionRoutes();
168 | std::vector dnsServerList;
169 |
170 | for (auto const& parameter : splitwsv(parameters))
171 | {
172 | auto fields = splitws(parameter, L',');
173 | try
174 | {
175 | switch (fields[0].at(0))
176 | {
177 | case 'm':
178 | mtuSize = stoul(fields.at(1));
179 | break;
180 | case 'a':
181 | IPv4AddrList.emplace_back(fields.at(1));
182 | break;
183 | case 'r':
184 | IPv4Routes.Append({ {fields.at(1)}, static_cast(stoul(fields.at(2))) });
185 | break;
186 | case 'd':
187 | dnsServerList.emplace_back(fields.at(1));
188 | break;
189 | }
190 | }
191 | catch (std::out_of_range const&)
192 | {
193 | throw hresult_invalid_argument{ L"Bad parameter: " + parameter };
194 | }
195 | }
196 |
197 | VpnDomainNameAssignment assignment;
198 | assignment.DomainNameList().Append({ L".", VpnDomainNameType::Suffix, dnsServerList, nullptr });
199 |
200 | channel.StartExistingTransports(
201 | IPv4AddrList,
202 | nullptr,
203 | nullptr,
204 | route,
205 | assignment,
206 | mtuSize,
207 | MAX_PACKET_SIZE,
208 | false
209 | );
210 | }
211 | }
212 |
--------------------------------------------------------------------------------
/ToyVpnBG/ToyVpnBG.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | true
6 | true
7 | {be554dc8-b093-4eb7-8006-72717c6c3d63}
8 | ToyVpnBG
9 | ToyVpnBG
10 | en-US
11 | 14.0
12 | true
13 | Windows Store
14 | 10.0
15 | 10.0.17763.0
16 | 10.0.17134.0
17 |
18 |
19 |
20 |
21 | Debug
22 | ARM
23 |
24 |
25 | Debug
26 | Win32
27 |
28 |
29 | Debug
30 | x64
31 |
32 |
33 | Release
34 | ARM
35 |
36 |
37 | Release
38 | Win32
39 |
40 |
41 | Release
42 | x64
43 |
44 |
45 |
46 | DynamicLibrary
47 | v141
48 | Unicode
49 | false
50 |
51 |
52 | true
53 | true
54 |
55 |
56 | false
57 | true
58 | false
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | Use
73 | pch.h
74 | $(IntDir)pch.pch
75 | Level4
76 | %(AdditionalOptions) /bigobj
77 | 28204
78 | _WINRT_DLL;%(PreprocessorDefinitions)
79 | $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)
80 |
81 |
82 | Console
83 | true
84 | ToyVpnBG.def
85 |
86 |
87 |
88 |
89 | _DEBUG;%(PreprocessorDefinitions)
90 |
91 |
92 |
93 |
94 | NDEBUG;%(PreprocessorDefinitions)
95 |
96 |
97 |
98 |
99 |
100 |
101 | VpnBackgroundTask.idl
102 |
103 |
104 |
105 |
106 |
107 | Create
108 |
109 |
110 | VpnBackgroundTask.idl
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 | false
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 | 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。
134 |
135 |
136 |
137 |
138 |
--------------------------------------------------------------------------------
/ToyVpn/ToyVpn.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | true
6 | true
7 | {c612f6f5-70da-43d3-9e59-1cc7dfe5c523}
8 | ToyVpn
9 | ToyVpn
10 | en-US
11 | 15.0
12 | true
13 | Windows Store
14 | 10.0
15 | 10.0.17763.0
16 | 10.0.17134.0
17 |
18 |
19 |
20 |
21 | Debug
22 | ARM
23 |
24 |
25 | Debug
26 | Win32
27 |
28 |
29 | Debug
30 | x64
31 |
32 |
33 | Release
34 | ARM
35 |
36 |
37 | Release
38 | Win32
39 |
40 |
41 | Release
42 | x64
43 |
44 |
45 |
46 | Application
47 | v141
48 | Unicode
49 |
50 |
51 | true
52 | true
53 |
54 |
55 | false
56 | true
57 | false
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | ToyVpn_TemporaryKey.pfx
68 | 1132EA939A7107B303D4D40ED6CE28778FC96409
69 |
70 |
71 |
72 | Use
73 | pch.h
74 | $(IntDir)pch.pch
75 | Level4
76 | %(AdditionalOptions) /bigobj
77 | 4453;28204
78 |
79 |
80 |
81 |
82 | _DEBUG;%(PreprocessorDefinitions)
83 |
84 |
85 |
86 |
87 | NDEBUG;%(PreprocessorDefinitions)
88 |
89 |
90 |
91 |
92 |
93 | App.xaml
94 |
95 |
96 | MainPage.xaml
97 |
98 |
99 |
100 |
101 | Designer
102 |
103 |
104 | Designer
105 |
106 |
107 |
108 |
109 | Designer
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 | Create
126 |
127 |
128 | App.xaml
129 |
130 |
131 | MainPage.xaml
132 |
133 |
134 |
135 |
136 |
137 | App.xaml
138 |
139 |
140 | MainPage.xaml
141 |
142 |
143 |
144 |
145 | false
146 |
147 |
148 |
149 |
150 | {be554dc8-b093-4eb7-8006-72717c6c3d63}
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 | 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。
160 |
161 |
162 |
163 |
164 |
--------------------------------------------------------------------------------