From 1f75cbebf7ad96c457e7571b67fb32e467adf533 Mon Sep 17 00:00:00 2001
From: jammerxd <8965289+jammerxd@users.noreply.github.com>
Date: Thu, 4 Jan 2024 19:54:15 -0600
Subject: [PATCH 1/2] implements the disable ssl certificate verification flag
from https://github.com/tryphotino/photino.Native/pull/120
---
Photino.NET/Photino.NET.csproj | 2 +-
Photino.NET/PhotinoDllImports.cs | 3 +-
Photino.NET/PhotinoNativeParameters.cs | 2 ++
Photino.NET/PhotinoWindow.NET.cs | 40 ++++++++++++++++++++++++++
4 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/Photino.NET/Photino.NET.csproj b/Photino.NET/Photino.NET.csproj
index 5c1f902..8e0cca0 100644
--- a/Photino.NET/Photino.NET.csproj
+++ b/Photino.NET/Photino.NET.csproj
@@ -29,7 +29,7 @@
-
+
diff --git a/Photino.NET/PhotinoDllImports.cs b/Photino.NET/PhotinoDllImports.cs
index 32e94f1..84747b0 100644
--- a/Photino.NET/PhotinoDllImports.cs
+++ b/Photino.NET/PhotinoDllImports.cs
@@ -46,6 +46,7 @@ public partial class PhotinoWindow
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] static extern void Photino_GetZoom(IntPtr instance, out int zoom);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] static extern void Photino_GetMaximized(IntPtr instance, out bool maximized);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] static extern void Photino_GetMinimized(IntPtr instance, out bool minimized);
+ [DllImport(DllName, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] static extern void Photino_GetSslCertificateVerificationDisabled(IntPtr instance, out bool disabled);
//MARSHAL CALLS FROM Non-UI Thread to UI Thread
@@ -73,7 +74,7 @@ public partial class PhotinoWindow
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] static extern void Photino_SetTopmost(IntPtr instance, int topmost);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, SetLastError = true, CharSet = CharSet.Auto)] static extern void Photino_SetIconFile(IntPtr instance, string filename);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] static extern void Photino_SetZoom(IntPtr instance, int zoom);
-
+ [DllImport(DllName, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] static extern void Photino_SetSslCertificateVerificationDisabled(IntPtr instance, bool disabled);
//MISC
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] static extern void Photino_Center(IntPtr instance);
diff --git a/Photino.NET/PhotinoNativeParameters.cs b/Photino.NET/PhotinoNativeParameters.cs
index d51e87f..607ad4e 100644
--- a/Photino.NET/PhotinoNativeParameters.cs
+++ b/Photino.NET/PhotinoNativeParameters.cs
@@ -193,6 +193,8 @@ internal struct PhotinoNativeParameters
[MarshalAs(UnmanagedType.I1)] internal bool MediaStreamEnabled;
[MarshalAs(UnmanagedType.I1)] internal bool SmoothScrollingEnabled;
+ [MarshalAs(UnmanagedType.I1)] internal bool DisableSslCertificateVerification;
+
///Set when GetParamErrors() is called, prior to initializing the native window. It is a check to make sure the struct matches what C++ is expecting.
[MarshalAs(UnmanagedType.I4)] internal int Size;
diff --git a/Photino.NET/PhotinoWindow.NET.cs b/Photino.NET/PhotinoWindow.NET.cs
index 9be1a58..730995c 100644
--- a/Photino.NET/PhotinoWindow.NET.cs
+++ b/Photino.NET/PhotinoWindow.NET.cs
@@ -27,6 +27,7 @@ public partial class PhotinoWindow
/// Specifies whether the window should use the OS default location.
/// Indicates whether the window should use the OS default size.
/// Sets the zoom level for the window.
+ /// Disables SSL Certificate Verification. This allows the window to ignore SSL certificate errors. Should not be used in production.
private PhotinoNativeParameters _startupParameters = new()
{
Resizable = true, //These values can't be initialized within the struct itself. Set required defaults.
@@ -52,6 +53,7 @@ public partial class PhotinoWindow
Zoom = 100,
MaxHeight = int.MaxValue,
MaxWidth = int.MaxValue,
+ DisableSslCertificateVerification = false,
};
//Pointers to the type and instance.
@@ -480,7 +482,28 @@ public bool SmoothScrollingEnabled
}
}
}
+ public bool SslCertificateVerificationDisabled
+ {
+ get
+ {
+ if (_nativeInstance == IntPtr.Zero)
+ return _startupParameters.DisableSslCertificateVerification;
+ var enabled = true;
+ Invoke(() => Photino_GetSslCertificateVerificationDisabled(_nativeInstance, out enabled));
+ return enabled;
+ }
+ set
+ {
+ if (SslCertificateVerificationDisabled != value)
+ {
+ if (_nativeInstance == IntPtr.Zero)
+ _startupParameters.DisableSslCertificateVerification = value;
+ else if (IsWindowsPlatform)
+ throw new ApplicationException("SSLCertificateVerificationDisabled can only be set before the native window is instantiated.");
+ }
+ }
+ }
///
/// This property returns or sets the fullscreen status of the window.
@@ -2209,6 +2232,23 @@ public PhotinoWindow SetUseOsDefaultSize(bool useOsDefault)
return this;
}
+ ///
+ /// Disable SSL Certificate Verification to bypass SSL certificate warnings. This should not be used in production environments or should be strictly controlled.
+ ///
+ ///
+ /// This is only available on startup in windows
+ ///
+ ///
+ /// Returns the current instance.
+ ///
+ /// Indicates if ssl certificate verification should be disabled.
+ public PhotinoWindow SetSslCertificateVerificationDisabled(bool disabled)
+ {
+ Log($".SetSslCertificateVerificationDisabled({disabled})");
+ SslCertificateVerificationDisabled = disabled;
+ return this;
+ }
+
///
/// Set runtime path for WebView2 so that developers can use Photino on Windows using the "Fixed Version" deployment module of the WebView2 runtime.
///
From 2b93e7a50233908c8daf3da381e6776be023236a Mon Sep 17 00:00:00 2001
From: Mike Yeager
Date: Thu, 4 Jan 2024 10:58:18 -0700
Subject: [PATCH 2/2] Added IgnoreCertificateErrorsEnabled. Tested on Windows.
---
Photino.NET/PhotinoDllImports.cs | 1 +
Photino.NET/PhotinoNativeParameters.cs | 1 +
Photino.NET/PhotinoWindow.NET.cs | 11 +++++++++++
3 files changed, 13 insertions(+)
diff --git a/Photino.NET/PhotinoDllImports.cs b/Photino.NET/PhotinoDllImports.cs
index 84747b0..d517fb9 100644
--- a/Photino.NET/PhotinoDllImports.cs
+++ b/Photino.NET/PhotinoDllImports.cs
@@ -37,6 +37,7 @@ public partial class PhotinoWindow
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] static extern void Photino_GetJavascriptClipboardAccessEnabled(IntPtr instance, out bool enabled);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] static extern void Photino_GetMediaStreamEnabled(IntPtr instance, out bool enabled);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] static extern void Photino_GetSmoothScrollingEnabled(IntPtr instance, out bool enabled);
+ [DllImport(DllName, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] static extern void Photino_GetIgnoreCertificateErrorsEnabled(IntPtr instance, out bool enabled);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] static extern void Photino_GetPosition(IntPtr instance, out int x, out int y);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] static extern void Photino_GetResizable(IntPtr instance, out bool resizable);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] static extern uint Photino_GetScreenDpi(IntPtr instance);
diff --git a/Photino.NET/PhotinoNativeParameters.cs b/Photino.NET/PhotinoNativeParameters.cs
index 607ad4e..350abc9 100644
--- a/Photino.NET/PhotinoNativeParameters.cs
+++ b/Photino.NET/PhotinoNativeParameters.cs
@@ -192,6 +192,7 @@ internal struct PhotinoNativeParameters
[MarshalAs(UnmanagedType.I1)] internal bool JavascriptClipboardAccessEnabled;
[MarshalAs(UnmanagedType.I1)] internal bool MediaStreamEnabled;
[MarshalAs(UnmanagedType.I1)] internal bool SmoothScrollingEnabled;
+ [MarshalAs(UnmanagedType.I1)] internal bool IgnoreCertificateErrorsEnabled;
[MarshalAs(UnmanagedType.I1)] internal bool DisableSslCertificateVerification;
diff --git a/Photino.NET/PhotinoWindow.NET.cs b/Photino.NET/PhotinoWindow.NET.cs
index 730995c..471c560 100644
--- a/Photino.NET/PhotinoWindow.NET.cs
+++ b/Photino.NET/PhotinoWindow.NET.cs
@@ -1885,6 +1885,17 @@ public PhotinoWindow SetSmoothScrollingEnabled(bool enable)
return this;
}
+ ///
+ /// Sets on the browser control at initialization.
+ ///
+ ///
+ /// Returns the current instance.
+ public PhotinoWindow SetIgnoreCertificateErrorsEnabled(bool enable)
+ {
+ Log($".SetIgnoreCertificateErrorsEnabled({enable})");
+ IgnoreCertificateErrorsEnabled = enable;
+ return this;
+ }
///
/// Sets the native window in pixels.