瀏覽代碼

Add custom tls cert

bdbai 4 年之前
父節點
當前提交
db759a3c67

+ 16 - 0
Maple.App/CertPage.cpp

@@ -0,0 +1,16 @@
+#include "pch.h"
+#include "CertPage.h"
+#if __has_include("CertPage.g.cpp")
+#include "CertPage.g.cpp"
+#endif
+
+using namespace winrt;
+using namespace Windows::UI::Xaml;
+
+namespace winrt::Maple_App::implementation
+{
+    CertPage::CertPage()
+    {
+        InitializeComponent();
+    }
+}

+ 18 - 0
Maple.App/CertPage.h

@@ -0,0 +1,18 @@
+#pragma once
+
+#include "CertPage.g.h"
+
+namespace winrt::Maple_App::implementation
+{
+    struct CertPage : CertPageT<CertPage>
+    {
+        CertPage();
+   };
+}
+
+namespace winrt::Maple_App::factory_implementation
+{
+    struct CertPage : CertPageT<CertPage, implementation::CertPage>
+    {
+    };
+}

+ 8 - 0
Maple.App/CertPage.idl

@@ -0,0 +1,8 @@
+namespace Maple_App
+{
+    [default_interface]
+    runtimeclass CertPage : Windows.UI.Xaml.Controls.Page
+    {
+        CertPage();
+    }
+}

+ 21 - 0
Maple.App/CertPage.xaml

@@ -0,0 +1,21 @@
+<Page
+    x:Class="Maple_App.CertPage"
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:local="using:Maple_App"
+    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+    mc:Ignorable="d">
+
+    <StackPanel Orientation="Vertical" Padding="16, 16, 0, 0">
+        <TextBlock TextWrapping="Wrap">
+            <Run>Set</Run>
+            <Run FontFamily="Consolas">tls-cert</Run>
+            <Run>attribute in an outbound configuration to make use of a custom TLS certificate. For more information, see</Run>
+            <Hyperlink NavigateUri="https://github.com/eycorsican/leaf/blob/master/README.zh.md">
+                https://github.com/eycorsican/leaf/blob/master/README.zh.md
+            </Hyperlink>
+            <Run>.</Run>
+        </TextBlock>
+    </StackPanel>
+</Page>

+ 4 - 1
Maple.App/MainPage.cpp

@@ -250,7 +250,7 @@ namespace winrt::Maple_App::implementation
             co_await NotifyUser(L"Cannot unsnap the app.");
             co_return;
         }
-        ImportFilePicker().FileTypeFilter().ReplaceAll({ L".conf", L".json", L".mmdb", L".dat" });
+        ImportFilePicker().FileTypeFilter().ReplaceAll({ L".conf", L".json", L".mmdb", L".dat", L".cer", L".crt" });
         const auto& files = co_await ImportFilePicker().PickMultipleFilesAsync();
         co_await ImportFiles(files);
     }
@@ -317,6 +317,9 @@ namespace winrt::Maple_App::implementation
             else if (ext == ".dat") {
                 targetPage = xaml_typename<DatPage>();
             }
+            else if (ext == ".cer" || ext == ".crt") {
+                targetPage = xaml_typename<CertPage>();
+            }
         }
         MainContentFrame().BackStack().Clear();
         MainContentFrame().Navigate(targetPage, item);

+ 1 - 1
Maple.App/MainPage.h

@@ -89,7 +89,7 @@ namespace winrt::Maple_App::implementation
                     continue;
                 }
                 auto ext = getNormalizedExtentionFromPath(file.Path());
-                if (ext != ".json" && ext != ".conf" && ext != ".mmdb" && ext != ".dat") {
+                if (ext != ".json" && ext != ".conf" && ext != ".mmdb" && ext != ".dat" && ext != ".cer" && ext != ".crt") {
                     continue;
                 }
                 const auto& newFile = co_await file.CopyAsync(targetDir, file.Name(), NameCollisionOption::GenerateUniqueName);

+ 15 - 0
Maple.App/Maple.App.vcxproj

@@ -148,6 +148,10 @@
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClInclude Include="CertPage.h">
+      <DependentUpon>CertPage.xaml</DependentUpon>
+      <SubType>Code</SubType>
+    </ClInclude>
     <ClInclude Include="Converter\DateTimeConverter.h">
       <DependentUpon>Converter\DateTimeConverter.idl</DependentUpon>
       <SubType>Code</SubType>
@@ -185,6 +189,9 @@
     <ApplicationDefinition Include="App.xaml">
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Page Include="CertPage.xaml">
+      <SubType>Designer</SubType>
+    </Page>
     <Page Include="DatPage.xaml">
       <SubType>Designer</SubType>
     </Page>
@@ -257,6 +264,10 @@
     <Image Include="Assets\Wide310x150Logo.scale-400.png" />
   </ItemGroup>
   <ItemGroup>
+    <ClCompile Include="CertPage.cpp">
+      <DependentUpon>CertPage.xaml</DependentUpon>
+      <SubType>Code</SubType>
+    </ClCompile>
     <ClCompile Include="Converter\DateTimeConverter.cpp">
       <DependentUpon>Converter\DateTimeConverter.idl</DependentUpon>
       <SubType>Code</SubType>
@@ -296,6 +307,10 @@
     <Midl Include="App.idl">
       <DependentUpon>App.xaml</DependentUpon>
     </Midl>
+    <Midl Include="CertPage.idl">
+      <DependentUpon>CertPage.xaml</DependentUpon>
+      <SubType>Code</SubType>
+    </Midl>
     <Midl Include="Converter\DateTimeConverter.idl">
       <SubType>Designer</SubType>
     </Midl>

+ 1 - 0
Maple.App/Maple.App.vcxproj.filters

@@ -175,6 +175,7 @@
     <Page Include="MainPage.xaml" />
     <Page Include="MmdbPage.xaml" />
     <Page Include="DatPage.xaml" />
+    <Page Include="CertPage.xaml" />
   </ItemGroup>
   <ItemGroup>
     <Filter Include="Assets">

+ 1 - 1
Maple.Task/VpnPlugin.cpp

@@ -98,7 +98,7 @@ namespace winrt::Maple_Task::implementation
             dnsHosts.push_back(HostName{ to_hstring(dns) });
             });
         if (m_leaf == nullptr) {
-            channel.TerminateConnection(L"Error initializing Leaf runtime.\r\nPlease check your configuration file and default interface.");
+            channel.TerminateConnection(L"Error initializing Leaf runtime.\r\nPlease check your configuration file and default interface.\r\nPlease make sure all associated files (.dat, .mmdb, .cer) exist.");
             StopLeaf();
             return;
         }

+ 1 - 1
leaf

@@ -1 +1 @@
-Subproject commit a7a16741e32e395823897b2d2c8c9bcfc4223f5e
+Subproject commit 3f1018ba4f1499cce91b15cc3f0e3bf60be988e5