Skip to content

Commit

Permalink
Add custom tls cert
Browse files Browse the repository at this point in the history
  • Loading branch information
bdbai committed Aug 30, 2021
1 parent abdd11f commit db759a3
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 4 deletions.
16 changes: 16 additions & 0 deletions Maple.App/CertPage.cpp
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 0 deletions Maple.App/CertPage.h
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions Maple.App/CertPage.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Maple_App
{
[default_interface]
runtimeclass CertPage : Windows.UI.Xaml.Controls.Page
{
CertPage();
}
}
21 changes: 21 additions & 0 deletions Maple.App/CertPage.xaml
Original file line number Diff line number Diff line change
@@ -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>
5 changes: 4 additions & 1 deletion Maple.App/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Maple.App/MainPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions Maple.App/Maple.App.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions Maple.App/Maple.App.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
2 changes: 1 addition & 1 deletion Maple.Task/VpnPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit db759a3

Please sign in to comment.