From d07e6cb17e3cd3476cb667d9d823ec051babc265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=B6glinger-Stelzer?= Date: Fri, 7 Jun 2019 13:07:39 +0200 Subject: [PATCH] Fixed handling test mode when secure boot is enabled --- DerpingDrivers/DerpingDrivers.csproj | 1 + DerpingDrivers/MainWindow.xaml | 10 +++++-- DerpingDrivers/MainWindow.xaml.cs | 12 +++++++- .../Util/InverseBooleanConverter.cs | 29 +++++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 DerpingDrivers/Util/InverseBooleanConverter.cs diff --git a/DerpingDrivers/DerpingDrivers.csproj b/DerpingDrivers/DerpingDrivers.csproj index a5403c2..69311c4 100644 --- a/DerpingDrivers/DerpingDrivers.csproj +++ b/DerpingDrivers/DerpingDrivers.csproj @@ -113,6 +113,7 @@ + diff --git a/DerpingDrivers/MainWindow.xaml b/DerpingDrivers/MainWindow.xaml index af68f01..88cc331 100644 --- a/DerpingDrivers/MainWindow.xaml +++ b/DerpingDrivers/MainWindow.xaml @@ -3,7 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:local="clr-namespace:DerpingDrivers" + xmlns:util="clr-namespace:DerpingDrivers.Util" xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks" mc:Ignorable="d" @@ -15,6 +15,9 @@ BorderThickness="0" GlowBrush="{DynamicResource AccentColorBrush}" DataContext="{Binding RelativeSource={RelativeSource Self}}"> + + + @@ -100,7 +103,8 @@ Header="Allow Prerelease Signatures" OnLabel="TESTSINGING is on" OffLabel="TESTSINGING is off" - IsChecked="{Binding Path=AllowPrereleaseSignatures}" /> + IsChecked="{Binding Path=AllowPrereleaseSignatures}" + IsEnabled="{Binding Path=IsSecureBootEnabled, Converter={StaticResource InverseBooleanConverter}}"/> - + /// Gets test-mode status. /// - public string TestSigningStatus => CodeIntegrityHelper.IsTestSignEnabled ? "Enabled" : "Disabled"; + public string TestSigningStatus => UefiHelper.IsRunningInUefiMode && UefiHelper.IsSecureBootEnabled + ? + "Not available" + : CodeIntegrityHelper.IsTestSignEnabled + ? "Enabled" + : "Disabled"; + + /// + /// True if SecureBoot enabled, false otherwise. + /// + public bool IsSecureBootEnabled => UefiHelper.IsRunningInUefiMode && UefiHelper.IsSecureBootEnabled; /// /// Gets or sets whether prerelease signatures (a.k.a. TESTSIGNING) are accepted by the kernel. diff --git a/DerpingDrivers/Util/InverseBooleanConverter.cs b/DerpingDrivers/Util/InverseBooleanConverter.cs new file mode 100644 index 0000000..c203669 --- /dev/null +++ b/DerpingDrivers/Util/InverseBooleanConverter.cs @@ -0,0 +1,29 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace DerpingDrivers.Util +{ + [ValueConversion(typeof(bool), typeof(bool))] + public class InverseBooleanConverter : IValueConverter + { + #region IValueConverter Members + + public object Convert(object value, Type targetType, object parameter, + CultureInfo culture) + { + if (targetType != typeof(bool)) + throw new InvalidOperationException("The target must be a boolean"); + + return !(bool) value; + } + + public object ConvertBack(object value, Type targetType, object parameter, + CultureInfo culture) + { + throw new NotSupportedException(); + } + + #endregion + } +} \ No newline at end of file