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

Implement Disable SSL Certificate Verification #165

Closed
wants to merge 3 commits into from
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
2 changes: 1 addition & 1 deletion Photino.NET/Photino.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</Target>

<ItemGroup>
<PackageReference Include="Photino.Native" Version="0.9.0-20231228.2" />
<PackageReference Include="Photino.Native" Version="0.9.0-20240104.1" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion Photino.NET/PhotinoDllImports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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
Expand Down Expand Up @@ -74,7 +75,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);
Expand Down
2 changes: 2 additions & 0 deletions Photino.NET/PhotinoNativeParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ internal struct PhotinoNativeParameters
[MarshalAs(UnmanagedType.I1)] internal bool SmoothScrollingEnabled;
[MarshalAs(UnmanagedType.I1)] internal bool IgnoreCertificateErrorsEnabled;

[MarshalAs(UnmanagedType.I1)] internal bool DisableSslCertificateVerification;

///<summary>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.</summary>
[MarshalAs(UnmanagedType.I4)] internal int Size;

Expand Down
38 changes: 27 additions & 11 deletions Photino.NET/PhotinoWindow.NET.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public partial class PhotinoWindow
/// <param name="UseOsDefaultLocation">Specifies whether the window should use the OS default location.</param>
/// <param name="UseOsDefaultSize">Indicates whether the window should use the OS default size.</param>
/// <param name="Zoom">Sets the zoom level for the window.</param>
/// <param name="DisableSslCertificateVerification">Disables SSL Certificate Verification. This allows the window to ignore SSL certificate errors. Should not be used in production.</param>
private PhotinoNativeParameters _startupParameters = new()
{
Resizable = true, //These values can't be initialized within the struct itself. Set required defaults.
Expand All @@ -42,7 +43,6 @@ public partial class PhotinoWindow
JavascriptClipboardAccessEnabled = true,
MediaStreamEnabled = true,
SmoothScrollingEnabled = true,
IgnoreCertificateErrorsEnabled = false,
TemporaryFilesPathWide = IsWindowsPlatform
? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Photino")
: null,
Expand All @@ -53,6 +53,7 @@ public partial class PhotinoWindow
Zoom = 100,
MaxHeight = int.MaxValue,
MaxWidth = int.MaxValue,
DisableSslCertificateVerification = false,
};

//Pointers to the type and instance.
Expand Down Expand Up @@ -481,31 +482,29 @@ public bool SmoothScrollingEnabled
}
}
}

public bool IgnoreCertificateErrorsEnabled
public bool SslCertificateVerificationDisabled
{
get
{
if (_nativeInstance == IntPtr.Zero)
return _startupParameters.IgnoreCertificateErrorsEnabled;
return _startupParameters.DisableSslCertificateVerification;

var enabled = false;
Invoke(() => Photino_GetIgnoreCertificateErrorsEnabled(_nativeInstance, out enabled));
var enabled = true;
Invoke(() => Photino_GetSslCertificateVerificationDisabled(_nativeInstance, out enabled));
return enabled;
}
set
{
if (IgnoreCertificateErrorsEnabled != value)
if (SslCertificateVerificationDisabled != value)
{
if (_nativeInstance == IntPtr.Zero)
_startupParameters.IgnoreCertificateErrorsEnabled = value;
else
throw new ApplicationException("IgnoreCertificateErrorsEnabled can only be set before the native window is instantiated.");
_startupParameters.DisableSslCertificateVerification = value;
else if (IsWindowsPlatform)
throw new ApplicationException("SSLCertificateVerificationDisabled can only be set before the native window is instantiated.");
}
}
}


/// <summary>
/// This property returns or sets the fullscreen status of the window.
/// When set to true, the native window will cover the entire screen, similar to kiosk mode.
Expand Down Expand Up @@ -2244,6 +2243,23 @@ public PhotinoWindow SetUseOsDefaultSize(bool useOsDefault)
return this;
}

/// <summary>
/// Disable SSL Certificate Verification to bypass SSL certificate warnings. This should not be used in production environments or should be strictly controlled.
/// </summary>
/// <remarks>
/// This is only available on startup in windows
/// </remarks>
/// <returns>
/// Returns the current <see cref="PhotinoWindow"/> instance.
/// </returns>
/// <param name="disabled">Indicates if ssl certificate verification should be disabled.</param>
public PhotinoWindow SetSslCertificateVerificationDisabled(bool disabled)
{
Log($".SetSslCertificateVerificationDisabled({disabled})");
SslCertificateVerificationDisabled = disabled;
return this;
}

/// <summary>
/// Set runtime path for WebView2 so that developers can use Photino on Windows using the "Fixed Version" deployment module of the WebView2 runtime.
/// </summary>
Expand Down