Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TLS disable check helper #103

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Photino.Native/Exports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ extern "C"
instance->WaitForExit();
}

EXPORTED void Photino_DisableTLSCheck(Photino* instance)
{
instance->DisableTLSCheck();
}



//Callbacks
Expand Down
6 changes: 6 additions & 0 deletions Photino.Native/Photino.Linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,12 @@ void Photino::WaitForExit()
gtk_main();
}

void Photino::DisableTLSCheck()
{
auto web_context = webkit_web_context_get_default();
auto data_manager = webkit_web_context_get_website_data_manager(web_context);
webkit_website_data_manager_set_tls_errors_policy(data_manager, WEBKIT_TLS_ERRORS_POLICY_IGNORE);
}



Expand Down
6 changes: 6 additions & 0 deletions Photino.Native/Photino.Mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,12 @@ void EnsureInvoke(dispatch_block_t block)
[NSApp run];
}

void Photino::DisableTLSCheck()
{
// TODO
// See https://stackoverflow.com/questions/27100540/allow-unverified-ssl-certificates-in-wkwebview
}

//Callbacks
void Photino::GetAllMonitors(GetAllMonitorsCallback callback)
{
Expand Down
8 changes: 4 additions & 4 deletions Photino.Native/Photino.Native.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,14 @@ COPY .\$(OutDir)WebView2Loader.dll ..\Photino.Test\bin\ARM64\Debug\net6.0\</Comm
<ImportGroup Label="ExtensionTargets">
<Import Project="..\..\packages\Microsoft.Web.WebView2.1.0.664.37\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\..\packages\Microsoft.Web.WebView2.1.0.664.37\build\native\Microsoft.Web.WebView2.targets')" />
<Import Project="..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.201120.3\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.201120.3\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.1462.37\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.1462.37\build\native\Microsoft.Web.WebView2.targets')" />
<Import Project="..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220914.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220914.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.1518.46\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.1518.46\build\native\Microsoft.Web.WebView2.targets')" />
<Import Project="..\packages\Microsoft.Windows.ImplementationLibrary.1.0.230202.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.230202.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.1462.37\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.1462.37\build\native\Microsoft.Web.WebView2.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220914.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220914.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.1518.46\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.1518.46\build\native\Microsoft.Web.WebView2.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.230202.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.ImplementationLibrary.1.0.230202.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
</Target>
</Project>
3 changes: 3 additions & 0 deletions Photino.Native/Photino.Native.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Natvis Include="$(MSBuildThisFileDirectory)..\..\natvis\wil.natvis" />
</ItemGroup>
</Project>
35 changes: 34 additions & 1 deletion Photino.Native/Photino.Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ struct ShowMessageParams
};


static bool AlwaysValidateServerCertificate(ICoreWebView2Certificate* certificate)
{
return true;
}


void Photino::Register(HINSTANCE hInstance)
{
InitDarkModeSupport();
Expand Down Expand Up @@ -670,7 +676,34 @@ void Photino::WaitForExit()
}
}


void Photino::DisableTLSCheck()
{
// Only from webview 14 upwards - see:
// https://github.com/MicrosoftEdge/WebView2Samples/blob/1710d535e895ed9c24196c5482e990e10d7285c7/SampleApps/WebView2APISample/SettingsComponent.cpp#L1445
EventRegistrationToken m_ServerCertificateErrorToken = {};
auto webview14 = _webviewWindow.try_query<ICoreWebView2_14>();
if (webview14) {
webview14->add_ServerCertificateErrorDetected(
Callback<ICoreWebView2ServerCertificateErrorDetectedEventHandler>([this](ICoreWebView2* sender, ICoreWebView2ServerCertificateErrorDetectedEventArgs* args) {
COREWEBVIEW2_WEB_ERROR_STATUS errorStatus;
if (SUCCEEDED(args->get_ErrorStatus(&errorStatus))) {
wil::com_ptr<ICoreWebView2Certificate> certificate = nullptr;
if (SUCCEEDED(args->get_ServerCertificate(&certificate))) {
if (errorStatus == COREWEBVIEW2_WEB_ERROR_STATUS_CERTIFICATE_IS_INVALID && AlwaysValidateServerCertificate(certificate.get()))
{
args->put_Action(COREWEBVIEW2_SERVER_CERTIFICATE_ERROR_ACTION_ALWAYS_ALLOW);
}
else
{
args->put_Action(COREWEBVIEW2_SERVER_CERTIFICATE_ERROR_ACTION_CANCEL);
}
}
}
return S_OK;
}
).Get(), &m_ServerCertificateErrorToken);
}
}



Expand Down
2 changes: 2 additions & 0 deletions Photino.Native/Photino.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ class Photino
void ShowNotification(AutoString title, AutoString message);
void WaitForExit();

void DisableTLSCheck();

//Callbacks
void AddCustomSchemeName(AutoString scheme) { _customSchemeNames.push_back((AutoString)scheme); };
void GetAllMonitors(GetAllMonitorsCallback callback);
Expand Down
4 changes: 2 additions & 2 deletions Photino.Native/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Web.WebView2" version="1.0.1462.37" targetFramework="native" />
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.220914.1" targetFramework="native" />
<package id="Microsoft.Web.WebView2" version="1.0.1518.46" targetFramework="native" />
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.230202.1" targetFramework="native" />
</packages>