From b54775bbcd2f4dd108e50b3c96794aed0a8351af Mon Sep 17 00:00:00 2001 From: Rans4ckeR Date: Tue, 26 Dec 2023 20:00:08 +0100 Subject: [PATCH] Cleanup --- .editorconfig | 1 + .github/workflows/dotnet.yml | 16 ++++------- .../CipherPunk.CipherSuiteInfoApi.csproj | 5 ++-- CipherPunk.UI/App.xaml.cs | 4 +-- CipherPunk.UI/CipherPunk.UI.csproj | 8 +++--- CipherPunk.UI/Infrastructure/BaseViewModel.cs | 15 ++-------- .../Infrastructure/ExceptionMessageBuilder.cs | 5 +--- .../Infrastructure/NoScrollDataGrid.cs | 5 +--- CipherPunk.UI/MainWindowViewModel.cs | 21 ++++---------- .../ActiveViewValueChangedMessage.cs | 2 +- .../Messaging/UserInterfaceLogService.cs | 2 +- CipherPunk.UI/Messaging/UserMessage.cs | 2 +- .../UserMessageValueChangedMessage.cs | 2 +- CipherPunk.UI/Properties/AssemblyInfo.cs | 2 +- CipherPunk.UI/Properties/GlobalUsings.cs | 2 +- ...ipherSuitesGroupPolicySettingsView.xaml.cs | 5 +--- ...ipherSuitesGroupPolicySettingsViewModel.cs | 12 ++++---- .../CipherSuitesOsSettingsView.xaml.cs | 5 +--- .../CipherSuitesOsSettingsViewModel.cs | 7 ++--- .../CipherSuites/CipherSuitesView.xaml.cs | 5 +--- .../CipherSuites/CipherSuitesViewModel.cs | 2 +- ...ipticCurvesGroupPolicySettingsView.xaml.cs | 5 +--- ...ipticCurvesGroupPolicySettingsViewModel.cs | 7 ++--- .../EllipticCurvesOsSettingsView.xaml.cs | 5 +--- .../EllipticCurvesOsSettingsViewModel.cs | 5 +--- .../EllipticCurves/EllipticCurvesView.xaml.cs | 5 +--- .../UserControls/Logging/LoggingView.xaml.cs | 5 +--- .../UserControls/Logging/LoggingViewModel.cs | 2 +- .../Overview/OverviewView.xaml.cs | 5 +--- .../Overview/OverviewViewModel.cs | 2 +- .../RemoteServerTestView.xaml.cs | 5 +--- .../RemoteServerTestViewModel.cs | 13 +++------ CipherPunk/CipherPunk.csproj | 13 ++++----- ...cs => SchannelCertificateMappingMethod.cs} | 2 +- .../Entities/Schannel/SchannelSettings.cs | 2 +- .../CompressCertificateHandshakeExtension.cs | 6 ++-- ...ticCurvesPointFormatsHandshakeExtension.cs | 11 +++----- .../EncryptThenMacExtension.cs | 2 +- .../ExtendedMasterSecretExtension.cs | 2 +- .../Tls/HandshakeExtensions/KeyShare.cs | 2 +- .../HandshakeExtensions/KeyShareExtension.cs | 2 +- .../PaddingHandshakeExtension.cs | 9 ++---- .../PreSharedKeysKeyExchangeModesExtension.cs | 6 ++-- .../RenegotiationInfoHandshakeExtension.cs | 4 +-- .../ServerNameHandshakeExtension.cs | 13 ++++----- .../SessionTicketExtension.cs | 2 +- .../SignatureAlgorithmsHandshakeExtension.cs | 10 +++---- ...dCertificateTimestampHandshakeExtension.cs | 4 +-- .../StatusRequestHandshakeExtension.cs | 5 ++-- .../SupportedGroupsHandshakeExtension.cs | 10 +++---- .../SupportedVersionsExtension.cs | 7 ++--- .../Entities/Tls/Records/AlertTlsRecord.cs | 7 ++--- .../Tls/Records/ClientHelloTlsRecord.cs | 14 ++++------ .../Tls/Records/ServerHelloTlsRecord.cs | 8 ++---- .../Tls/Records/Ssl2ClientHelloRecord.cs | 4 +-- .../Tls/Records/Ssl2ServerHelloRecord.cs | 2 +- CipherPunk/Entities/Tls/Records/TlsRecord.cs | 16 +++++------ .../Entities/Tls/Records/TlsRecordHeader.cs | 2 +- ...wsDocumentationCipherSuiteConfiguration.cs | 11 ++------ .../ReadOnlySpanOfBytesExtensions.cs | 5 +--- .../Extensions/ServiceCollectionExtensions.cs | 4 +-- CipherPunk/Services/CipherSuiteService.cs | 18 ++++-------- ...s10V1507CipherSuiteDocumentationService.cs | 2 -- ...s10V1511CipherSuiteDocumentationService.cs | 2 -- ...s10V1607CipherSuiteDocumentationService.cs | 2 -- ...s10V1703CipherSuiteDocumentationService.cs | 2 -- ...s10V1709CipherSuiteDocumentationService.cs | 2 -- ...s10V1903CipherSuiteDocumentationService.cs | 2 -- ...s10V22H2CipherSuiteDocumentationService.cs | 2 -- ...indows11CipherSuiteDocumentationService.cs | 2 -- ...s11V22H2CipherSuiteDocumentationService.cs | 2 -- ...Windows7CipherSuiteDocumentationService.cs | 2 -- ...indows81CipherSuiteDocumentationService.cs | 2 -- ...Windows8CipherSuiteDocumentationService.cs | 2 -- ...indowsEllipticCurveDocumentationService.cs | 2 +- ...rver2022CipherSuiteDocumentationService.cs | 2 -- ...owsVistaCipherSuiteDocumentationService.cs | 2 -- .../EllipticCurveIdentifierService.cs | 14 ++-------- CipherPunk/Services/EllipticCurveService.cs | 11 +++----- CipherPunk/Services/GroupPolicyService.cs | 10 ++----- CipherPunk/Services/SchannelLogService.cs | 13 ++++++++- CipherPunk/Services/SchannelService.cs | 28 ++++++------------- CipherPunk/Services/TlsService.cs | 11 ++------ README.md | 6 ++-- 84 files changed, 171 insertions(+), 342 deletions(-) rename CipherPunk/Entities/Schannel/{CertificateMappingMethod.cs => SchannelCertificateMappingMethod.cs} (93%) diff --git a/.editorconfig b/.editorconfig index 731a3ee..0a1abe1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1380,3 +1380,4 @@ csharp_style_prefer_switch_expression = true:warning csharp_style_prefer_pattern_matching = true:warning csharp_style_prefer_not_pattern = true:warning csharp_style_prefer_extended_property_pattern = true:warning +dotnet_diagnostic.SA1010.severity = warning diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index d80ac64..f2f5fde 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -18,7 +18,7 @@ jobs: - name: Setup .NET Core SDK uses: actions/setup-dotnet@main with: - dotnet-version: '7.x.x' + dotnet-version: '8.x.x' - name: Install GitVersion uses: gittools/actions/gitversion/setup@main with: @@ -32,17 +32,11 @@ jobs: dotnet publish CipherPunk.UI/CipherPunk.UI.csproj --configuration Release --no-self-contained --framework net7.0-windows --runtime win-arm64 -p:PublishReadyToRun=true -p:PublishReadyToRunComposite=true -p:PublishSingleFile=true -p:DebugType=embedded -p:AssemblyVersion=$env:GitVersion_AssemblySemVer -p:FileVersion=$env:GitVersion_AssemblySemFileVer -p:InformationalVersion=$env:GitVersion_InformationalVersion - name: Zip run: | - 7z a -r ${{ format('CipherPunk-v{0}-net7.0-windows-x86.zip', env.GitVersion_SemVer) }} ./CipherPunk.UI/bin/Release/net7.0-windows/win-x86/publish/*.* - 7z a -r ${{ format('CipherPunk-v{0}-net7.0-windows-x64.zip', env.GitVersion_SemVer) }} ./CipherPunk.UI/bin/Release/net7.0-windows/win-x64/publish/*.* - 7z a -r ${{ format('CipherPunk-v{0}-net7.0-windows-ARM64.zip', env.GitVersion_SemVer) }} ./CipherPunk.UI/bin/Release/net7.0-windows/win-arm64/publish/*.* - - name: Prerelease - if: ${{ env.GitVersion_PreReleaseTag != '' }} - run: gh release create ${{ format('v{0}', env.GitVersion_SemVer) }} (get-item *.zip) --generate-notes --target ${{ github.sha }} --prerelease - env: - GH_TOKEN: ${{ github.token }} + 7z a -r "${{ format('CipherPunk-v{0}-net7.0-windows-x86.zip', env.GitVersion_SemVer) }}" "./CipherPunk.UI/bin/Release/net7.0-windows/win-x86/publish/*.*" "-x!*.xml" + 7z a -r "${{ format('CipherPunk-v{0}-net7.0-windows-x64.zip', env.GitVersion_SemVer) }}" "./CipherPunk.UI/bin/Release/net7.0-windows/win-x64/publish" "-x!*.xml" + 7z a -r "${{ format('CipherPunk-v{0}-net7.0-windows-ARM64.zip', env.GitVersion_SemVer) }}" "./CipherPunk.UI/bin/Release/net7.0-windows/win-arm64/publish/*.*" "-x!*.xml" - name: Release - if: ${{ env.GitVersion_PreReleaseTag == '' }} - run: gh release create ${{ format('v{0}', env.GitVersion_SemVer) }} (get-item *.zip) --generate-notes --target ${{ github.sha }} + run: gh release create v${{ env.GitVersion_SemVer }} (get-item *.zip) --generate-notes --target ${{ github.sha }} ${{ env.PreReleaseTag != '' && '--prerelease' || '' }} env: GH_TOKEN: ${{ github.token }} - name: Package diff --git a/CipherPunk.CipherSuiteInfoApi/CipherPunk.CipherSuiteInfoApi.csproj b/CipherPunk.CipherSuiteInfoApi/CipherPunk.CipherSuiteInfoApi.csproj index 6569fe9..7810a75 100644 --- a/CipherPunk.CipherSuiteInfoApi/CipherPunk.CipherSuiteInfoApi.csproj +++ b/CipherPunk.CipherSuiteInfoApi/CipherPunk.CipherSuiteInfoApi.csproj @@ -16,6 +16,7 @@ preview-all preview true + true enable enable 0.0.0.1 @@ -24,10 +25,10 @@ AnyCPU - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + \ No newline at end of file diff --git a/CipherPunk.UI/App.xaml.cs b/CipherPunk.UI/App.xaml.cs index f07de89..6cd657c 100644 --- a/CipherPunk.UI/App.xaml.cs +++ b/CipherPunk.UI/App.xaml.cs @@ -78,11 +78,9 @@ private static void PreventWpfFlashBang(Window window) } private static void SetUiCulture() - { - FrameworkElement.LanguageProperty.OverrideMetadata( + => FrameworkElement.LanguageProperty.OverrideMetadata( typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag))); - } private void AppDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { diff --git a/CipherPunk.UI/CipherPunk.UI.csproj b/CipherPunk.UI/CipherPunk.UI.csproj index d8270ca..30adf2a 100644 --- a/CipherPunk.UI/CipherPunk.UI.csproj +++ b/CipherPunk.UI/CipherPunk.UI.csproj @@ -17,19 +17,19 @@ preview-all preview true + true enable enable true 0.0.0.1 0.0.0.1 0.0.0.1 - true win-x86;win-x64;win-arm64 x86;x64;ARM64 app.manifest - + all @@ -38,7 +38,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -46,7 +46,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/CipherPunk.UI/Infrastructure/BaseViewModel.cs b/CipherPunk.UI/Infrastructure/BaseViewModel.cs index 3b3c42f..8009048 100644 --- a/CipherPunk.UI/Infrastructure/BaseViewModel.cs +++ b/CipherPunk.UI/Infrastructure/BaseViewModel.cs @@ -19,10 +19,7 @@ protected BaseViewModel(ILogger logger) DefaultCommand = new AsyncRelayCommand(ExecuteDefaultCommandAsync, _ => CanExecuteDefaultCommand); PropertyChanged += BaseViewModelPropertyChanged; - StrongReferenceMessenger.Default.Register>(this, (r, m) => - { - ((BaseViewModel)r).Receive(m); - }); + StrongReferenceMessenger.Default.Register>(this, (r, m) => ((BaseViewModel)r).Receive(m)); } public IAsyncRelayCommand DefaultCommand { get; } @@ -67,15 +64,9 @@ protected virtual void BaseViewModelPropertyChanged(object? sender, PropertyChan } } - protected virtual bool GetCanExecuteDefaultCommand() - { - return !DefaultCommandActive; - } + protected virtual bool GetCanExecuteDefaultCommand() => !DefaultCommandActive; - protected void UpdateCanExecuteDefaultCommand() - { - CanExecuteDefaultCommand = GetCanExecuteDefaultCommand(); - } + protected void UpdateCanExecuteDefaultCommand() => CanExecuteDefaultCommand = GetCanExecuteDefaultCommand(); private async Task ExecuteDefaultCommandAsync(bool? showView, CancellationToken cancellationToken) { diff --git a/CipherPunk.UI/Infrastructure/ExceptionMessageBuilder.cs b/CipherPunk.UI/Infrastructure/ExceptionMessageBuilder.cs index f170269..60b62b4 100644 --- a/CipherPunk.UI/Infrastructure/ExceptionMessageBuilder.cs +++ b/CipherPunk.UI/Infrastructure/ExceptionMessageBuilder.cs @@ -4,10 +4,7 @@ public static class ExceptionMessageBuilder { - public static string GetDetailedExceptionInfo(this Exception ex) - { - return new StringBuilder().GetExceptionInfo(ex).ToString(); - } + public static string GetDetailedExceptionInfo(this Exception ex) => new StringBuilder().GetExceptionInfo(ex).ToString(); private static StringBuilder GetExceptionInfo(this StringBuilder sb, Exception ex) { diff --git a/CipherPunk.UI/Infrastructure/NoScrollDataGrid.cs b/CipherPunk.UI/Infrastructure/NoScrollDataGrid.cs index ca18812..f0d9648 100644 --- a/CipherPunk.UI/Infrastructure/NoScrollDataGrid.cs +++ b/CipherPunk.UI/Infrastructure/NoScrollDataGrid.cs @@ -6,10 +6,7 @@ internal sealed class NoScrollDataGrid : DataGrid { - public NoScrollDataGrid() - { - PreviewMouseWheel += OnPreviewMouseWheel; - } + public NoScrollDataGrid() => PreviewMouseWheel += OnPreviewMouseWheel; private static void OnPreviewMouseWheel(object sender, MouseWheelEventArgs e) { diff --git a/CipherPunk.UI/MainWindowViewModel.cs b/CipherPunk.UI/MainWindowViewModel.cs index 3deb69d..3aa5ce4 100644 --- a/CipherPunk.UI/MainWindowViewModel.cs +++ b/CipherPunk.UI/MainWindowViewModel.cs @@ -44,14 +44,8 @@ public MainWindowViewModel( CopyMessageCommand = new RelayCommand(ExecuteCopyMessageCommand); CloseMessageCommand = new RelayCommand(ExecuteCloseMessageCommand); - StrongReferenceMessenger.Default.Register(this, (r, m) => - { - ((MainWindowViewModel)r).UserMessage = m.Value.Message; - }); - StrongReferenceMessenger.Default.Register(this, (r, m) => - { - ((MainWindowViewModel)r).ActiveView = m.Value; - }); + StrongReferenceMessenger.Default.Register(this, (r, m) => ((MainWindowViewModel)r).UserMessage = m.Value.Message); + StrongReferenceMessenger.Default.Register(this, (r, m) => ((MainWindowViewModel)r).ActiveView = m.Value); UpdateCanExecuteDefaultCommand(); } @@ -81,17 +75,17 @@ public MainWindowViewModel( public double MainContentOpacity { - get => mainContentOpacity; set { _ = SetProperty(ref mainContentOpacity, value); } + get => mainContentOpacity; set => _ = SetProperty(ref mainContentOpacity, value); } public bool MainContentIsHitTestVisible { - get => mainContentIsHitTestVisible; set { _ = SetProperty(ref mainContentIsHitTestVisible, value); } + get => mainContentIsHitTestVisible; set => _ = SetProperty(ref mainContentIsHitTestVisible, value); } public int MessageZIndex { - get => messageZIndex; set { _ = SetProperty(ref messageZIndex, value); } + get => messageZIndex; set => _ = SetProperty(ref messageZIndex, value); } public string? UserMessage @@ -138,8 +132,5 @@ private void ExecuteCopyMessageCommand() Clipboard.Clear(); } - private void ExecuteCloseMessageCommand() - { - UserMessage = null; - } + private void ExecuteCloseMessageCommand() => UserMessage = null; } \ No newline at end of file diff --git a/CipherPunk.UI/Messaging/ActiveViewValueChangedMessage.cs b/CipherPunk.UI/Messaging/ActiveViewValueChangedMessage.cs index d31ccbb..9112e4b 100644 --- a/CipherPunk.UI/Messaging/ActiveViewValueChangedMessage.cs +++ b/CipherPunk.UI/Messaging/ActiveViewValueChangedMessage.cs @@ -1,4 +1,4 @@ -namespace CipherPunk.UI; +namespace CipherPunk.UI; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Messaging.Messages; diff --git a/CipherPunk.UI/Messaging/UserInterfaceLogService.cs b/CipherPunk.UI/Messaging/UserInterfaceLogService.cs index 216cb02..d1e0f1d 100644 --- a/CipherPunk.UI/Messaging/UserInterfaceLogService.cs +++ b/CipherPunk.UI/Messaging/UserInterfaceLogService.cs @@ -1,4 +1,4 @@ -namespace CipherPunk.UI; +namespace CipherPunk.UI; using CommunityToolkit.Mvvm.Messaging; diff --git a/CipherPunk.UI/Messaging/UserMessage.cs b/CipherPunk.UI/Messaging/UserMessage.cs index a2e6596..90960bf 100644 --- a/CipherPunk.UI/Messaging/UserMessage.cs +++ b/CipherPunk.UI/Messaging/UserMessage.cs @@ -1,3 +1,3 @@ -namespace CipherPunk.UI; +namespace CipherPunk.UI; internal readonly record struct UserMessage(string Message); \ No newline at end of file diff --git a/CipherPunk.UI/Messaging/UserMessageValueChangedMessage.cs b/CipherPunk.UI/Messaging/UserMessageValueChangedMessage.cs index 4241a8c..16d1dc2 100644 --- a/CipherPunk.UI/Messaging/UserMessageValueChangedMessage.cs +++ b/CipherPunk.UI/Messaging/UserMessageValueChangedMessage.cs @@ -1,4 +1,4 @@ -namespace CipherPunk.UI; +namespace CipherPunk.UI; using CommunityToolkit.Mvvm.Messaging.Messages; diff --git a/CipherPunk.UI/Properties/AssemblyInfo.cs b/CipherPunk.UI/Properties/AssemblyInfo.cs index c0ea722..f2ac31a 100644 --- a/CipherPunk.UI/Properties/AssemblyInfo.cs +++ b/CipherPunk.UI/Properties/AssemblyInfo.cs @@ -1,3 +1,3 @@ -using System.Windows; +using System.Windows; [assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)] \ No newline at end of file diff --git a/CipherPunk.UI/Properties/GlobalUsings.cs b/CipherPunk.UI/Properties/GlobalUsings.cs index 31f0e85..1237bba 100644 --- a/CipherPunk.UI/Properties/GlobalUsings.cs +++ b/CipherPunk.UI/Properties/GlobalUsings.cs @@ -1,4 +1,4 @@ -#pragma warning disable IDE0065 // Misplaced using directive +#pragma warning disable IDE0065 // Misplaced using directive #pragma warning disable SA1200 // Using directives should be placed correctly global using CipherPunk; global using Microsoft.Extensions.Logging; diff --git a/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesGroupPolicySettingsView.xaml.cs b/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesGroupPolicySettingsView.xaml.cs index 7980394..d9e7cde 100644 --- a/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesGroupPolicySettingsView.xaml.cs +++ b/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesGroupPolicySettingsView.xaml.cs @@ -2,8 +2,5 @@ internal sealed partial class CipherSuitesGroupPolicySettingsView { - public CipherSuitesGroupPolicySettingsView() - { - InitializeComponent(); - } + public CipherSuitesGroupPolicySettingsView() => InitializeComponent(); } \ No newline at end of file diff --git a/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesGroupPolicySettingsViewModel.cs b/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesGroupPolicySettingsViewModel.cs index 76a060a..1a57a5b 100644 --- a/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesGroupPolicySettingsViewModel.cs +++ b/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesGroupPolicySettingsViewModel.cs @@ -11,14 +11,15 @@ internal sealed class CipherSuitesGroupPolicySettingsViewModel : BaseViewModel private readonly IUacIconService uacIconService; private readonly ICipherSuiteInfoApiService cipherSuiteInfoApiService; private readonly IGroupPolicyService groupPolicyService; - private readonly List onlineCipherSuiteInfos = new(); + private readonly List onlineCipherSuiteInfos = []; private ObservableCollection? activeGroupPolicyCipherSuiteConfigurations; private ObservableCollection? defaultGroupPolicyCipherSuiteConfigurations; private BitmapSource? uacIcon; private bool fetchOnlineInfo = true; private string? adminMessage; - public CipherSuitesGroupPolicySettingsViewModel(ILogger logger, ICipherSuiteService cipherSuiteService, IUacIconService uacIconService, ICipherSuiteInfoApiService cipherSuiteInfoApiService, IGroupPolicyService groupPolicyService) + public CipherSuitesGroupPolicySettingsViewModel( + ILogger logger, ICipherSuiteService cipherSuiteService, IUacIconService uacIconService, ICipherSuiteInfoApiService cipherSuiteInfoApiService, IGroupPolicyService groupPolicyService) : base(logger) { this.cipherSuiteService = cipherSuiteService; @@ -35,10 +36,7 @@ public string? AdminMessage private set => _ = SetProperty(ref adminMessage, value); } - public BitmapSource UacIcon - { - get => uacIcon ??= uacIconService.GetUacShieldIcon(); - } + public BitmapSource UacIcon => uacIcon ??= uacIconService.GetUacShieldIcon(); public bool FetchOnlineInfo { @@ -61,7 +59,7 @@ public ObservableCollection? Def protected override async Task DoExecuteDefaultCommandAsync(CancellationToken cancellationToken) { string[] windowsDefaultGroupPolicyCipherSuiteConfigurationsStrings = await groupPolicyService.GetSslCipherSuiteOrderPolicyWindowsDefaultsAsync(cancellationToken); - string[] windowsActiveGroupPolicyCipherSuiteConfigurationsStrings = Array.Empty(); + string[] windowsActiveGroupPolicyCipherSuiteConfigurationsStrings = []; AdminMessage = null; diff --git a/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesOsSettingsView.xaml.cs b/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesOsSettingsView.xaml.cs index 05c5042..e68dfad 100644 --- a/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesOsSettingsView.xaml.cs +++ b/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesOsSettingsView.xaml.cs @@ -2,8 +2,5 @@ internal sealed partial class CipherSuitesOsSettingsView { - public CipherSuitesOsSettingsView() - { - InitializeComponent(); - } + public CipherSuitesOsSettingsView() => InitializeComponent(); } \ No newline at end of file diff --git a/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesOsSettingsViewModel.cs b/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesOsSettingsViewModel.cs index 8728264..3154872 100644 --- a/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesOsSettingsViewModel.cs +++ b/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesOsSettingsViewModel.cs @@ -10,7 +10,7 @@ internal sealed class CipherSuitesOsSettingsViewModel : BaseViewModel private readonly ICipherSuiteService cipherSuiteService; private readonly IUacIconService uacIconService; private readonly ICipherSuiteInfoApiService cipherSuiteInfoApiService; - private readonly List onlineCipherSuiteInfos = new(); + private readonly List onlineCipherSuiteInfos = []; private ObservableCollection? activeCipherSuiteConfigurations; private ObservableCollection? osDefaultCipherSuiteConfigurations; private BitmapSource? uacIcon; @@ -26,10 +26,7 @@ public CipherSuitesOsSettingsViewModel(ILogger logger, ICipherSuiteService ciphe UpdateCanExecuteDefaultCommand(); } - public BitmapSource UacIcon - { - get => uacIcon ??= uacIconService.GetUacShieldIcon(); - } + public BitmapSource UacIcon => uacIcon ??= uacIconService.GetUacShieldIcon(); public bool FetchOnlineInfo { diff --git a/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesView.xaml.cs b/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesView.xaml.cs index 86aed77..3f363d6 100644 --- a/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesView.xaml.cs +++ b/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesView.xaml.cs @@ -2,8 +2,5 @@ internal sealed partial class CipherSuitesView { - public CipherSuitesView() - { - InitializeComponent(); - } + public CipherSuitesView() => InitializeComponent(); } \ No newline at end of file diff --git a/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesViewModel.cs b/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesViewModel.cs index ccf2930..805067e 100644 --- a/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesViewModel.cs +++ b/CipherPunk.UI/UserControls/CipherSuites/CipherSuitesViewModel.cs @@ -8,7 +8,7 @@ internal sealed class CipherSuitesViewModel : BaseViewModel { private readonly ICipherSuiteService cipherSuiteService; private readonly ICipherSuiteInfoApiService cipherSuiteInfoApiService; - private readonly List onlineCipherSuiteInfos = new(); + private readonly List onlineCipherSuiteInfos = []; private ObservableCollection? activeCipherSuiteConfigurations; private bool fetchOnlineInfo = true; diff --git a/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesGroupPolicySettingsView.xaml.cs b/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesGroupPolicySettingsView.xaml.cs index 12d2ce3..68518c0 100644 --- a/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesGroupPolicySettingsView.xaml.cs +++ b/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesGroupPolicySettingsView.xaml.cs @@ -2,8 +2,5 @@ internal sealed partial class EllipticCurvesGroupPolicySettingsView { - public EllipticCurvesGroupPolicySettingsView() - { - InitializeComponent(); - } + public EllipticCurvesGroupPolicySettingsView() => InitializeComponent(); } \ No newline at end of file diff --git a/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesGroupPolicySettingsViewModel.cs b/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesGroupPolicySettingsViewModel.cs index a5cc389..bf0b882 100644 --- a/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesGroupPolicySettingsViewModel.cs +++ b/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesGroupPolicySettingsViewModel.cs @@ -30,10 +30,7 @@ public string? AdminMessage private set => _ = SetProperty(ref adminMessage, value); } - public BitmapSource UacIcon - { - get => uacIcon ??= uacIconService.GetUacShieldIcon(); - } + public BitmapSource UacIcon => uacIcon ??= uacIconService.GetUacShieldIcon(); public ObservableCollection? ActiveEllipticCurveConfigurations { @@ -57,7 +54,7 @@ protected override async Task DoExecuteDefaultCommandAsync(CancellationToken can { await Task.CompletedTask; - string[] activeGroupPolicyEllipticCurveConfigurationsStrings = Array.Empty(); + string[] activeGroupPolicyEllipticCurveConfigurationsStrings = []; AdminMessage = null; diff --git a/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesOsSettingsView.xaml.cs b/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesOsSettingsView.xaml.cs index ee4185d..fdc8ca7 100644 --- a/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesOsSettingsView.xaml.cs +++ b/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesOsSettingsView.xaml.cs @@ -2,8 +2,5 @@ internal sealed partial class EllipticCurvesOsSettingsView { - public EllipticCurvesOsSettingsView() - { - InitializeComponent(); - } + public EllipticCurvesOsSettingsView() => InitializeComponent(); } \ No newline at end of file diff --git a/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesOsSettingsViewModel.cs b/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesOsSettingsViewModel.cs index ac82845..dcc7ec9 100644 --- a/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesOsSettingsViewModel.cs +++ b/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesOsSettingsViewModel.cs @@ -21,10 +21,7 @@ public EllipticCurvesOsSettingsViewModel(ILogger logger, IUacIconService uacIcon UpdateCanExecuteDefaultCommand(); } - public BitmapSource UacIcon - { - get => uacIcon ??= uacIconService.GetUacShieldIcon(); - } + public BitmapSource UacIcon => uacIcon ??= uacIconService.GetUacShieldIcon(); public ObservableCollection? ActiveEllipticCurveConfigurations { diff --git a/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesView.xaml.cs b/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesView.xaml.cs index 008135b..2a8cbbe 100644 --- a/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesView.xaml.cs +++ b/CipherPunk.UI/UserControls/EllipticCurves/EllipticCurvesView.xaml.cs @@ -2,8 +2,5 @@ internal sealed partial class EllipticCurvesView { - public EllipticCurvesView() - { - InitializeComponent(); - } + public EllipticCurvesView() => InitializeComponent(); } \ No newline at end of file diff --git a/CipherPunk.UI/UserControls/Logging/LoggingView.xaml.cs b/CipherPunk.UI/UserControls/Logging/LoggingView.xaml.cs index e1818e7..473c987 100644 --- a/CipherPunk.UI/UserControls/Logging/LoggingView.xaml.cs +++ b/CipherPunk.UI/UserControls/Logging/LoggingView.xaml.cs @@ -2,8 +2,5 @@ internal sealed partial class LoggingView { - public LoggingView() - { - InitializeComponent(); - } + public LoggingView() => InitializeComponent(); } \ No newline at end of file diff --git a/CipherPunk.UI/UserControls/Logging/LoggingViewModel.cs b/CipherPunk.UI/UserControls/Logging/LoggingViewModel.cs index 11c8338..8256065 100644 --- a/CipherPunk.UI/UserControls/Logging/LoggingViewModel.cs +++ b/CipherPunk.UI/UserControls/Logging/LoggingViewModel.cs @@ -33,7 +33,7 @@ protected override Task DoExecuteDefaultCommandAsync(CancellationToken cancellat { AdminMessage = null; - List schannelLogs = new(); + List schannelLogs = []; try { diff --git a/CipherPunk.UI/UserControls/Overview/OverviewView.xaml.cs b/CipherPunk.UI/UserControls/Overview/OverviewView.xaml.cs index 18a258b..062565e 100644 --- a/CipherPunk.UI/UserControls/Overview/OverviewView.xaml.cs +++ b/CipherPunk.UI/UserControls/Overview/OverviewView.xaml.cs @@ -2,8 +2,5 @@ internal sealed partial class OverviewView { - public OverviewView() - { - InitializeComponent(); - } + public OverviewView() => InitializeComponent(); } \ No newline at end of file diff --git a/CipherPunk.UI/UserControls/Overview/OverviewViewModel.cs b/CipherPunk.UI/UserControls/Overview/OverviewViewModel.cs index 3745420..24ec0d1 100644 --- a/CipherPunk.UI/UserControls/Overview/OverviewViewModel.cs +++ b/CipherPunk.UI/UserControls/Overview/OverviewViewModel.cs @@ -11,7 +11,7 @@ internal sealed class OverviewViewModel : BaseViewModel private readonly ICipherSuiteInfoApiService cipherSuiteInfoApiService; private readonly IGroupPolicyService groupPolicyService; private readonly ISchannelService schannelService; - private readonly List onlineCipherSuiteInfos = new(); + private readonly List onlineCipherSuiteInfos = []; private ObservableCollection? protocolSettings; private ObservableCollection? keyExchangeAlgorithmSettings; private ObservableCollection? cipherSettings; diff --git a/CipherPunk.UI/UserControls/RemoteServerTest/RemoteServerTestView.xaml.cs b/CipherPunk.UI/UserControls/RemoteServerTest/RemoteServerTestView.xaml.cs index 8a7ded4..805ac18 100644 --- a/CipherPunk.UI/UserControls/RemoteServerTest/RemoteServerTestView.xaml.cs +++ b/CipherPunk.UI/UserControls/RemoteServerTest/RemoteServerTestView.xaml.cs @@ -2,8 +2,5 @@ internal sealed partial class RemoteServerTestView { - public RemoteServerTestView() - { - InitializeComponent(); - } + public RemoteServerTestView() => InitializeComponent(); } \ No newline at end of file diff --git a/CipherPunk.UI/UserControls/RemoteServerTest/RemoteServerTestViewModel.cs b/CipherPunk.UI/UserControls/RemoteServerTest/RemoteServerTestViewModel.cs index a6d48a5..37862b6 100644 --- a/CipherPunk.UI/UserControls/RemoteServerTest/RemoteServerTestViewModel.cs +++ b/CipherPunk.UI/UserControls/RemoteServerTest/RemoteServerTestViewModel.cs @@ -50,10 +50,7 @@ public ObservableCollection? RemoteServerTestResults private set => _ = SetProperty(ref remoteServerTestResults, value); } - protected override Task DoExecuteDefaultCommandAsync(CancellationToken cancellationToken) - { - return Task.CompletedTask; - } + protected override Task DoExecuteDefaultCommandAsync(CancellationToken cancellationToken) => Task.CompletedTask; protected override void BaseViewModelPropertyChanged(object? sender, PropertyChangedEventArgs e) { @@ -71,7 +68,8 @@ protected override void BaseViewModelPropertyChanged(object? sender, PropertyCha private async Task ExecuteRunTestCommandAsync(CancellationToken cancellationToken) { - List<(TlsVersion TlsVersion, List<(uint CipherSuiteId, bool Supported, string? ErrorReason)>? Results)> remoteServerCipherSuites = await tlsService.GetRemoteServerCipherSuitesAsync(HostName!, Port!.Value, cancellationToken); + List<(TlsVersion TlsVersion, List<(uint CipherSuiteId, bool Supported, string? ErrorReason)>? Results)> remoteServerCipherSuites = + await tlsService.GetRemoteServerCipherSuitesAsync(HostName!, Port!.Value, cancellationToken); var uiRemoteServerTestResults = remoteServerCipherSuites.SelectMany(q => q.Results!.Select(r => new UiRemoteServerTestResult( q.TlsVersion, q.TlsVersion is TlsVersion.SSL2_PROTOCOL_VERSION ? ((SslCipherSuite)r.CipherSuiteId).ToString() : ((TlsCipherSuite)r.CipherSuiteId).ToString(), @@ -81,8 +79,5 @@ private async Task ExecuteRunTestCommandAsync(CancellationToken cancellationToke RemoteServerTestResults = new(uiRemoteServerTestResults); } - private bool CanExecuteRunTestCommand() - { - return !string.IsNullOrWhiteSpace(HostName) && Port.HasValue; - } + private bool CanExecuteRunTestCommand() => !string.IsNullOrWhiteSpace(HostName) && Port.HasValue; } \ No newline at end of file diff --git a/CipherPunk/CipherPunk.csproj b/CipherPunk/CipherPunk.csproj index 51af306..c0510f2 100644 --- a/CipherPunk/CipherPunk.csproj +++ b/CipherPunk/CipherPunk.csproj @@ -16,6 +16,7 @@ preview-all preview true + true enable enable 0.0.0.1 @@ -30,7 +31,6 @@ true true LGPL-3.0-or-later - true README.md true AnyCPU @@ -52,7 +52,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -60,13 +60,12 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + \ No newline at end of file diff --git a/CipherPunk/Entities/Schannel/CertificateMappingMethod.cs b/CipherPunk/Entities/Schannel/SchannelCertificateMappingMethod.cs similarity index 93% rename from CipherPunk/Entities/Schannel/CertificateMappingMethod.cs rename to CipherPunk/Entities/Schannel/SchannelCertificateMappingMethod.cs index 19cfbf7..bbd07d1 100644 --- a/CipherPunk/Entities/Schannel/CertificateMappingMethod.cs +++ b/CipherPunk/Entities/Schannel/SchannelCertificateMappingMethod.cs @@ -11,7 +11,7 @@ namespace CipherPunk; [Flags] -public enum CertificateMappingMethod +public enum SchannelCertificateMappingMethod { Subject_Issuer = 0x0001, IssuerCertificate = 0x0002, diff --git a/CipherPunk/Entities/Schannel/SchannelSettings.cs b/CipherPunk/Entities/Schannel/SchannelSettings.cs index 0908fdd..b6ea24d 100644 --- a/CipherPunk/Entities/Schannel/SchannelSettings.cs +++ b/CipherPunk/Entities/Schannel/SchannelSettings.cs @@ -2,7 +2,7 @@ public readonly record struct SchannelSettings( SchannelLogLevel? LogLevel, - CertificateMappingMethod? CertificateMappingMethods, + SchannelCertificateMappingMethod? CertificateMappingMethods, int? ClientCacheTime, bool? EnableOcspStaplingForSni, bool? FipsAlgorithmPolicy, diff --git a/CipherPunk/Entities/Tls/HandshakeExtensions/CompressCertificateHandshakeExtension.cs b/CipherPunk/Entities/Tls/HandshakeExtensions/CompressCertificateHandshakeExtension.cs index 5281918..221ff4c 100644 --- a/CipherPunk/Entities/Tls/HandshakeExtensions/CompressCertificateHandshakeExtension.cs +++ b/CipherPunk/Entities/Tls/HandshakeExtensions/CompressCertificateHandshakeExtension.cs @@ -5,9 +5,7 @@ public sealed record CompressCertificateHandshakeExtension : HandshakeExtension { public CompressCertificateHandshakeExtension(TlsCertificateCompressionAlgorithm[] tlsCertificateCompressionAlgorithms) - { - CertificateCompressionAlgorithms = tlsCertificateCompressionAlgorithms.SelectMany(q => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)q))).ToArray(); - } + => CertificateCompressionAlgorithms = tlsCertificateCompressionAlgorithms.SelectMany(q => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)q))).ToArray(); // 2 bytes public override byte[] ExtensionType => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)TlsExtensionType.compress_certificate)); @@ -29,6 +27,6 @@ public override byte[] GetBytes() result.Add(CertificateCompressionAlgorithmsLength); result.AddRange(CertificateCompressionAlgorithms); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/HandshakeExtensions/EllipticCurvesPointFormatsHandshakeExtension.cs b/CipherPunk/Entities/Tls/HandshakeExtensions/EllipticCurvesPointFormatsHandshakeExtension.cs index e8a1eac..6666d53 100644 --- a/CipherPunk/Entities/Tls/HandshakeExtensions/EllipticCurvesPointFormatsHandshakeExtension.cs +++ b/CipherPunk/Entities/Tls/HandshakeExtensions/EllipticCurvesPointFormatsHandshakeExtension.cs @@ -4,18 +4,15 @@ public sealed record EllipticCurvesPointFormatsHandshakeExtension : HandshakeExtension { - public EllipticCurvesPointFormatsHandshakeExtension(TlsEllipticCurvesPointFormat[] tlsEllipticCurvesPointFormats) - { - ExtensionTypeEcPointFormats = tlsEllipticCurvesPointFormats.Cast().ToArray(); - } + public EllipticCurvesPointFormatsHandshakeExtension(TlsEllipticCurvesPointFormat[] tlsEllipticCurvesPointFormats) => ExtensionTypeEcPointFormats = tlsEllipticCurvesPointFormats.Cast().ToArray(); // 2 bytes public override byte[] ExtensionType => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)TlsExtensionType.ec_point_formats)); // 2 bytes - public override byte[] ExtensionTypeLength { get => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)(ExtensionTypeEcPointFormats.Length + 1))); } // + 1 for size of ExtensionTypeEcPointFormatsLength + public override byte[] ExtensionTypeLength => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)(ExtensionTypeEcPointFormats.Length + 1))); // + 1 for size of ExtensionTypeEcPointFormatsLength - public byte ExtensionTypeEcPointFormatsLength { get => (byte)ExtensionTypeEcPointFormats.Length; } + public byte ExtensionTypeEcPointFormatsLength => (byte)ExtensionTypeEcPointFormats.Length; // 1 byte per item public byte[] ExtensionTypeEcPointFormats { get; } @@ -29,6 +26,6 @@ public override byte[] GetBytes() result.Add(ExtensionTypeEcPointFormatsLength); result.AddRange(ExtensionTypeEcPointFormats); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/HandshakeExtensions/EncryptThenMacExtension.cs b/CipherPunk/Entities/Tls/HandshakeExtensions/EncryptThenMacExtension.cs index 8c34cc2..bb68a19 100644 --- a/CipherPunk/Entities/Tls/HandshakeExtensions/EncryptThenMacExtension.cs +++ b/CipherPunk/Entities/Tls/HandshakeExtensions/EncryptThenMacExtension.cs @@ -17,6 +17,6 @@ public override byte[] GetBytes() result.AddRange(ExtensionType); result.AddRange(ExtensionTypeLength); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/HandshakeExtensions/ExtendedMasterSecretExtension.cs b/CipherPunk/Entities/Tls/HandshakeExtensions/ExtendedMasterSecretExtension.cs index ac8df1e..6f5c41d 100644 --- a/CipherPunk/Entities/Tls/HandshakeExtensions/ExtendedMasterSecretExtension.cs +++ b/CipherPunk/Entities/Tls/HandshakeExtensions/ExtendedMasterSecretExtension.cs @@ -17,6 +17,6 @@ public override byte[] GetBytes() result.AddRange(ExtensionType); result.AddRange(ExtensionTypeLength); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/HandshakeExtensions/KeyShare.cs b/CipherPunk/Entities/Tls/HandshakeExtensions/KeyShare.cs index 4318a4a..6556bea 100644 --- a/CipherPunk/Entities/Tls/HandshakeExtensions/KeyShare.cs +++ b/CipherPunk/Entities/Tls/HandshakeExtensions/KeyShare.cs @@ -26,6 +26,6 @@ public byte[] GetBytes() result.AddRange(PublicKeyLength); result.AddRange(PublicKey); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/HandshakeExtensions/KeyShareExtension.cs b/CipherPunk/Entities/Tls/HandshakeExtensions/KeyShareExtension.cs index 8b9518f..6bd055f 100644 --- a/CipherPunk/Entities/Tls/HandshakeExtensions/KeyShareExtension.cs +++ b/CipherPunk/Entities/Tls/HandshakeExtensions/KeyShareExtension.cs @@ -22,6 +22,6 @@ public override byte[] GetBytes() result.AddRange(KeyShareLength); result.AddRange(KeyShares.SelectMany(q => q.GetBytes())); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/HandshakeExtensions/PaddingHandshakeExtension.cs b/CipherPunk/Entities/Tls/HandshakeExtensions/PaddingHandshakeExtension.cs index 362fe92..5edbdcd 100644 --- a/CipherPunk/Entities/Tls/HandshakeExtensions/PaddingHandshakeExtension.cs +++ b/CipherPunk/Entities/Tls/HandshakeExtensions/PaddingHandshakeExtension.cs @@ -4,16 +4,13 @@ public sealed record PaddingHandshakeExtension : HandshakeExtension { - public PaddingHandshakeExtension(int paddingLength) - { - ExtensionTypePadding = new byte[paddingLength - ExtensionType.Length - 2]; // - 2 for ExtensionTypeLength - } + public PaddingHandshakeExtension(int paddingLength) => ExtensionTypePadding = new byte[paddingLength - ExtensionType.Length - 2]; // - 2 for ExtensionTypeLength // 2 bytes public override byte[] ExtensionType => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)TlsExtensionType.padding)); // 2 bytes - public override byte[] ExtensionTypeLength { get => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)ExtensionTypePadding.Length)); } + public override byte[] ExtensionTypeLength => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)ExtensionTypePadding.Length)); // must contain all zeros public byte[] ExtensionTypePadding { get; } @@ -26,6 +23,6 @@ public override byte[] GetBytes() result.AddRange(ExtensionTypeLength); result.AddRange(ExtensionTypePadding); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/HandshakeExtensions/PreSharedKeysKeyExchangeModesExtension.cs b/CipherPunk/Entities/Tls/HandshakeExtensions/PreSharedKeysKeyExchangeModesExtension.cs index 39f7238..023fca3 100644 --- a/CipherPunk/Entities/Tls/HandshakeExtensions/PreSharedKeysKeyExchangeModesExtension.cs +++ b/CipherPunk/Entities/Tls/HandshakeExtensions/PreSharedKeysKeyExchangeModesExtension.cs @@ -5,9 +5,7 @@ public sealed record PreSharedKeysKeyExchangeModesExtension : HandshakeExtension { public PreSharedKeysKeyExchangeModesExtension(TlsPreSharedKeysKeyExchangeMode[] tlsPreSharedKeysKeyExchangeModes) - { - PreSharedKeysKeyExchangeModes = tlsPreSharedKeysKeyExchangeModes.Cast().ToArray(); - } + => PreSharedKeysKeyExchangeModes = tlsPreSharedKeysKeyExchangeModes.Cast().ToArray(); // 2 bytes public override byte[] ExtensionType => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)TlsExtensionType.psk_key_exchange_modes)); @@ -29,6 +27,6 @@ public override byte[] GetBytes() result.Add(PreSharedKeysKeyExchangeModesLength); result.AddRange(PreSharedKeysKeyExchangeModes); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/HandshakeExtensions/RenegotiationInfoHandshakeExtension.cs b/CipherPunk/Entities/Tls/HandshakeExtensions/RenegotiationInfoHandshakeExtension.cs index 984aea3..b74d2ff 100644 --- a/CipherPunk/Entities/Tls/HandshakeExtensions/RenegotiationInfoHandshakeExtension.cs +++ b/CipherPunk/Entities/Tls/HandshakeExtensions/RenegotiationInfoHandshakeExtension.cs @@ -8,7 +8,7 @@ public sealed record RenegotiationInfoHandshakeExtension : HandshakeExtension public override byte[] ExtensionType => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)TlsExtensionType.renegotiation_info)); // 2 bytes - public override byte[] ExtensionTypeLength { get => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)1)); } + public override byte[] ExtensionTypeLength => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)1)); public static byte ExtensionTypeRenegotiationInfoLength => 0x00; // length 0, because of new connection @@ -20,6 +20,6 @@ public override byte[] GetBytes() result.AddRange(ExtensionTypeLength); result.Add(ExtensionTypeRenegotiationInfoLength); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/HandshakeExtensions/ServerNameHandshakeExtension.cs b/CipherPunk/Entities/Tls/HandshakeExtensions/ServerNameHandshakeExtension.cs index 53fb09b..e227504 100644 --- a/CipherPunk/Entities/Tls/HandshakeExtensions/ServerNameHandshakeExtension.cs +++ b/CipherPunk/Entities/Tls/HandshakeExtensions/ServerNameHandshakeExtension.cs @@ -5,24 +5,21 @@ public sealed record ServerNameHandshakeExtension : HandshakeExtension { - public ServerNameHandshakeExtension(string serverName) - { - ExtensionTypeServerName = Encoding.Default.GetBytes(serverName); - } + public ServerNameHandshakeExtension(string serverName) => ExtensionTypeServerName = Encoding.Default.GetBytes(serverName); // 2 bytes public override byte[] ExtensionType => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)TlsExtensionType.server_name)); // 2 bytes - public override byte[] ExtensionTypeLength { get => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)(ExtensionTypeServerName.Length + ExtensionTypeEntryLength.Length + 1 + 2))); } // + 1 for size of ExtensionTypeServerNameEntryType, + 2 for size of ExtensionTypeLength + public override byte[] ExtensionTypeLength => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)(ExtensionTypeServerName.Length + ExtensionTypeEntryLength.Length + 1 + 2))); // + 1 for size of ExtensionTypeServerNameEntryType, + 2 for size of ExtensionTypeLength // 2 bytes - public byte[] ExtensionTypeEntryLength { get => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)(ExtensionTypeServerName.Length + ExtensionTypeServerNameLength.Length + 1))); } // + 1 for size of ExtensionTypeServerNameEntryType + public byte[] ExtensionTypeEntryLength => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)(ExtensionTypeServerName.Length + ExtensionTypeServerNameLength.Length + 1))); // + 1 for size of ExtensionTypeServerNameEntryType public static byte ExtensionTypeServerNameEntryType => 0x00; // 0x00: DNS hostname // 2 bytes - public byte[] ExtensionTypeServerNameLength { get => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)ExtensionTypeServerName.Length)); } + public byte[] ExtensionTypeServerNameLength => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)ExtensionTypeServerName.Length)); public byte[] ExtensionTypeServerName { get; } @@ -37,6 +34,6 @@ public override byte[] GetBytes() result.AddRange(ExtensionTypeServerNameLength); result.AddRange(ExtensionTypeServerName); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/HandshakeExtensions/SessionTicketExtension.cs b/CipherPunk/Entities/Tls/HandshakeExtensions/SessionTicketExtension.cs index 62570f0..15d5ed2 100644 --- a/CipherPunk/Entities/Tls/HandshakeExtensions/SessionTicketExtension.cs +++ b/CipherPunk/Entities/Tls/HandshakeExtensions/SessionTicketExtension.cs @@ -17,6 +17,6 @@ public override byte[] GetBytes() result.AddRange(ExtensionType); result.AddRange(ExtensionTypeLength); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/HandshakeExtensions/SignatureAlgorithmsHandshakeExtension.cs b/CipherPunk/Entities/Tls/HandshakeExtensions/SignatureAlgorithmsHandshakeExtension.cs index 57f4541..81f2ee5 100644 --- a/CipherPunk/Entities/Tls/HandshakeExtensions/SignatureAlgorithmsHandshakeExtension.cs +++ b/CipherPunk/Entities/Tls/HandshakeExtensions/SignatureAlgorithmsHandshakeExtension.cs @@ -5,18 +5,16 @@ public sealed record SignatureAlgorithmsHandshakeExtension : HandshakeExtension { public SignatureAlgorithmsHandshakeExtension(TlsSignatureScheme[] tlsSignatureSchemes) - { - ExtensionTypeSignatureAlgorithms = tlsSignatureSchemes.SelectMany(q => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)q))).ToArray(); - } + => ExtensionTypeSignatureAlgorithms = tlsSignatureSchemes.SelectMany(q => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)q))).ToArray(); // 2 bytes public override byte[] ExtensionType => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)TlsExtensionType.signature_algorithms)); // 2 bytes - public override byte[] ExtensionTypeLength { get => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)(ExtensionTypeSignatureAlgorithmsLength.Length + ExtensionTypeSignatureAlgorithms.Length))); } + public override byte[] ExtensionTypeLength => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)(ExtensionTypeSignatureAlgorithmsLength.Length + ExtensionTypeSignatureAlgorithms.Length))); // 2 bytes - public byte[] ExtensionTypeSignatureAlgorithmsLength { get => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)ExtensionTypeSignatureAlgorithms.Length)); } + public byte[] ExtensionTypeSignatureAlgorithmsLength => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)ExtensionTypeSignatureAlgorithms.Length)); // 2 bytes per item public byte[] ExtensionTypeSignatureAlgorithms { get; } @@ -30,6 +28,6 @@ public override byte[] GetBytes() result.AddRange(ExtensionTypeSignatureAlgorithmsLength); result.AddRange(ExtensionTypeSignatureAlgorithms); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/HandshakeExtensions/SignedCertificateTimestampHandshakeExtension.cs b/CipherPunk/Entities/Tls/HandshakeExtensions/SignedCertificateTimestampHandshakeExtension.cs index a0a59e8..77e061e 100644 --- a/CipherPunk/Entities/Tls/HandshakeExtensions/SignedCertificateTimestampHandshakeExtension.cs +++ b/CipherPunk/Entities/Tls/HandshakeExtensions/SignedCertificateTimestampHandshakeExtension.cs @@ -8,7 +8,7 @@ public sealed record SignedCertificateTimestampHandshakeExtension : HandshakeExt public override byte[] ExtensionType => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)TlsExtensionType.signed_certificate_timestamp)); // 2 bytes - public override byte[] ExtensionTypeLength { get => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)0)); } // length 0 + public override byte[] ExtensionTypeLength => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)0)); // length 0 public override byte[] GetBytes() { @@ -17,6 +17,6 @@ public override byte[] GetBytes() result.AddRange(ExtensionType); result.AddRange(ExtensionTypeLength); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/HandshakeExtensions/StatusRequestHandshakeExtension.cs b/CipherPunk/Entities/Tls/HandshakeExtensions/StatusRequestHandshakeExtension.cs index e85ea43..1c9030b 100644 --- a/CipherPunk/Entities/Tls/HandshakeExtensions/StatusRequestHandshakeExtension.cs +++ b/CipherPunk/Entities/Tls/HandshakeExtensions/StatusRequestHandshakeExtension.cs @@ -8,7 +8,8 @@ public sealed record StatusRequestHandshakeExtension : HandshakeExtension public override byte[] ExtensionType => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)TlsExtensionType.status_request)); // 2 bytes - public override byte[] ExtensionTypeLength { get => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)(ExtensionTypeStatusRequestResponderIdLength.Length + ExtensionTypeStatusRequestRequestExtensionLength.Length + 1))); } // + 1 for size of ExtensionTypeStatusRequestType + public override byte[] ExtensionTypeLength + => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)(ExtensionTypeStatusRequestResponderIdLength.Length + ExtensionTypeStatusRequestRequestExtensionLength.Length + 1))); // + 1 for size of ExtensionTypeStatusRequestType public static byte ExtensionTypeStatusRequestType => 0x01; // 0x00: certificate status type OCSP @@ -28,6 +29,6 @@ public override byte[] GetBytes() result.AddRange(ExtensionTypeStatusRequestResponderIdLength); result.AddRange(ExtensionTypeStatusRequestRequestExtensionLength); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/HandshakeExtensions/SupportedGroupsHandshakeExtension.cs b/CipherPunk/Entities/Tls/HandshakeExtensions/SupportedGroupsHandshakeExtension.cs index e1476a6..c91ca59 100644 --- a/CipherPunk/Entities/Tls/HandshakeExtensions/SupportedGroupsHandshakeExtension.cs +++ b/CipherPunk/Entities/Tls/HandshakeExtensions/SupportedGroupsHandshakeExtension.cs @@ -5,18 +5,16 @@ public sealed record SupportedGroupsHandshakeExtension : HandshakeExtension { public SupportedGroupsHandshakeExtension(TlsSupportedGroup[] tlsSupportedGroups) - { - ExtensionTypeSupportedGroups = tlsSupportedGroups.SelectMany(q => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)q))).ToArray(); - } + => ExtensionTypeSupportedGroups = tlsSupportedGroups.SelectMany(q => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)q))).ToArray(); // 2 bytes public override byte[] ExtensionType => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)TlsExtensionType.supported_groups)); // 2 bytes - public override byte[] ExtensionTypeLength { get => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)(ExtensionTypeSupportedGroupsLength.Length + ExtensionTypeSupportedGroups.Length))); } + public override byte[] ExtensionTypeLength => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)(ExtensionTypeSupportedGroupsLength.Length + ExtensionTypeSupportedGroups.Length))); // 2 bytes - public byte[] ExtensionTypeSupportedGroupsLength { get => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)ExtensionTypeSupportedGroups.Length)); } + public byte[] ExtensionTypeSupportedGroupsLength => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)ExtensionTypeSupportedGroups.Length)); // 2 bytes per item public byte[] ExtensionTypeSupportedGroups { get; } @@ -30,6 +28,6 @@ public override byte[] GetBytes() result.AddRange(ExtensionTypeSupportedGroupsLength); result.AddRange(ExtensionTypeSupportedGroups); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/HandshakeExtensions/SupportedVersionsExtension.cs b/CipherPunk/Entities/Tls/HandshakeExtensions/SupportedVersionsExtension.cs index 5ef95c6..4cb6be6 100644 --- a/CipherPunk/Entities/Tls/HandshakeExtensions/SupportedVersionsExtension.cs +++ b/CipherPunk/Entities/Tls/HandshakeExtensions/SupportedVersionsExtension.cs @@ -4,10 +4,7 @@ public sealed record SupportedVersionsExtension : HandshakeExtension { - public SupportedVersionsExtension(TlsVersion[] tlsVersions) - { - SupportedVersions = tlsVersions.SelectMany(q => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)q))).ToArray(); - } + public SupportedVersionsExtension(TlsVersion[] tlsVersions) => SupportedVersions = tlsVersions.SelectMany(q => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)q))).ToArray(); // 2 bytes public override byte[] ExtensionType => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)TlsExtensionType.supported_versions)); @@ -29,6 +26,6 @@ public override byte[] GetBytes() result.Add(SupportedVersionsLength); result.AddRange(SupportedVersions); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/Records/AlertTlsRecord.cs b/CipherPunk/Entities/Tls/Records/AlertTlsRecord.cs index 2f463f0..be7a525 100644 --- a/CipherPunk/Entities/Tls/Records/AlertTlsRecord.cs +++ b/CipherPunk/Entities/Tls/Records/AlertTlsRecord.cs @@ -15,10 +15,7 @@ public AlertTlsRecord(ReadOnlySpan data) public byte Description { get; } - public static implicit operator TlsAlert(AlertTlsRecord alertTlsRecord) - { - return new((TlsAlertLevel)alertTlsRecord.Level, (TlsAlertDescription)alertTlsRecord.Description); - } + public static implicit operator TlsAlert(AlertTlsRecord alertTlsRecord) => new((TlsAlertLevel)alertTlsRecord.Level, (TlsAlertDescription)alertTlsRecord.Description); protected override byte[] GetRecordTypeBytes() { @@ -28,6 +25,6 @@ protected override byte[] GetRecordTypeBytes() Description }; - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/Records/ClientHelloTlsRecord.cs b/CipherPunk/Entities/Tls/Records/ClientHelloTlsRecord.cs index f2a5b72..53d8451 100644 --- a/CipherPunk/Entities/Tls/Records/ClientHelloTlsRecord.cs +++ b/CipherPunk/Entities/Tls/Records/ClientHelloTlsRecord.cs @@ -7,8 +7,8 @@ public sealed record ClientHelloTlsRecord : TlsRecord public ClientHelloTlsRecord(ReadOnlySpan data) : base(data) { - HandshakeCipherSuites = Array.Empty(); - HandshakeCompressionMethods = Array.Empty(); + HandshakeCipherSuites = []; + HandshakeCompressionMethods = []; int index = TlsRecordHeader.Size + 1 + HandshakeMessageLength.Length + HandshakeClientVersion.Length + HandshakeClientRandom.Length + 1 + HandshakeSessionId.Length; // + 1 for TlsHandshakeHeaderMessageType, HandshakeSessionIdLength ushort handshakeCipherSuitesLength = BinaryPrimitives.ReverseEndianness(BitConverter.ToUInt16(data.TakeBytes(ref index, 2))); @@ -35,13 +35,9 @@ public ClientHelloTlsRecord( TlsCertificateCompressionAlgorithm[]? tlsCertificateCompressionAlgorithms) : base(tlsVersion, TlsContentType.handshake, TlsHandshakeType.client_hello) { - HandshakeCipherSuites = sslProviderCipherSuiteIds?.Length > 0 - ? sslProviderCipherSuiteIds.SelectMany(q => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)q))).ToArray() - : Array.Empty(); + HandshakeCipherSuites = sslProviderCipherSuiteIds?.Length > 0 ? sslProviderCipherSuiteIds.SelectMany(q => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)q))).ToArray() : []; - HandshakeCompressionMethods = tlsCompressionMethodIdentifiers?.Length > 0 - ? tlsCompressionMethodIdentifiers.Cast().ToArray() - : Array.Empty(); + HandshakeCompressionMethods = tlsCompressionMethodIdentifiers?.Length > 0 ? tlsCompressionMethodIdentifiers.Cast().ToArray() : []; HandshakeExtensions.AddRange(new HandshakeExtension[] { @@ -104,6 +100,6 @@ protected override byte[] GetRecordTypeBytes() result.Add(HandshakeCompressionMethodsLength); result.AddRange(HandshakeCompressionMethods); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/Records/ServerHelloTlsRecord.cs b/CipherPunk/Entities/Tls/Records/ServerHelloTlsRecord.cs index 28e4ced..b59c9d5 100644 --- a/CipherPunk/Entities/Tls/Records/ServerHelloTlsRecord.cs +++ b/CipherPunk/Entities/Tls/Records/ServerHelloTlsRecord.cs @@ -8,7 +8,7 @@ public sealed record ServerHelloTlsRecord : TlsRecord public ServerHelloTlsRecord(ReadOnlySpan data) : base(data) { - HandshakeCipherSuite = Array.Empty(); + HandshakeCipherSuite = []; int index = TlsRecordHeader.Size + 1 + HandshakeMessageLength.Length + HandshakeClientVersion.Length + HandshakeClientRandom.Length + 1 + HandshakeSessionId.Length; // + 1 for TlsHandshakeHeaderMessageType, HandshakeSessionIdLength HandshakeCipherSuite = data.TakeBytes(ref index, 2); @@ -67,9 +67,7 @@ public ServerHelloTlsRecord(ReadOnlySpan data) public byte HandshakeCompressionMethod { get; } public static implicit operator TlsServerHello(ServerHelloTlsRecord serverHelloTlsRecord) - { - return new((SslProviderCipherSuiteId)BitConverter.ToUInt16(serverHelloTlsRecord.HandshakeCipherSuite), (TlsCompressionMethodIdentifier)serverHelloTlsRecord.HandshakeCompressionMethod); - } + => new((SslProviderCipherSuiteId)BitConverter.ToUInt16(serverHelloTlsRecord.HandshakeCipherSuite), (TlsCompressionMethodIdentifier)serverHelloTlsRecord.HandshakeCompressionMethod); protected override byte[] GetRecordTypeBytes() { @@ -78,6 +76,6 @@ protected override byte[] GetRecordTypeBytes() result.AddRange(HandshakeCipherSuite); result.Add(HandshakeCompressionMethod); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/Records/Ssl2ClientHelloRecord.cs b/CipherPunk/Entities/Tls/Records/Ssl2ClientHelloRecord.cs index a11a1a7..310721d 100644 --- a/CipherPunk/Entities/Tls/Records/Ssl2ClientHelloRecord.cs +++ b/CipherPunk/Entities/Tls/Records/Ssl2ClientHelloRecord.cs @@ -9,7 +9,7 @@ public Ssl2ClientHelloRecord(SslCipherSuite[] sslProviderCipherSuiteIds) MessageType = (byte)TlsHandshakeType.client_hello; Version = BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((ushort)TlsVersion.SSL2_PROTOCOL_VERSION)); CipherSpecs = sslProviderCipherSuiteIds.SelectMany(q => BitConverter.GetBytes(BinaryPrimitives.ReverseEndianness((uint)q)).Skip(1)).ToArray(); - SessionId = Array.Empty(); + SessionId = []; Challenge = new byte[16]; new Random().NextBytes(Challenge); @@ -82,6 +82,6 @@ public byte[] GetBytes() result.AddRange(SessionId); result.AddRange(Challenge); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/Records/Ssl2ServerHelloRecord.cs b/CipherPunk/Entities/Tls/Records/Ssl2ServerHelloRecord.cs index e6164f3..421c56d 100644 --- a/CipherPunk/Entities/Tls/Records/Ssl2ServerHelloRecord.cs +++ b/CipherPunk/Entities/Tls/Records/Ssl2ServerHelloRecord.cs @@ -61,6 +61,6 @@ public byte[] GetBytes() result.AddRange(CipherSpecs); result.AddRange(ConnectionId); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/Records/TlsRecord.cs b/CipherPunk/Entities/Tls/Records/TlsRecord.cs index fcc2c10..3806743 100644 --- a/CipherPunk/Entities/Tls/Records/TlsRecord.cs +++ b/CipherPunk/Entities/Tls/Records/TlsRecord.cs @@ -14,10 +14,10 @@ protected TlsRecord(ReadOnlySpan data) { case TlsContentType.alert: TlsHandshakeHeaderMessageType = byte.MinValue; - HandshakeClientVersion = Array.Empty(); - HandshakeClientRandom = Array.Empty(); - HandshakeSessionId = Array.Empty(); - HandshakeExtensions = new(); + HandshakeClientVersion = []; + HandshakeClientRandom = []; + HandshakeSessionId = []; + HandshakeExtensions = []; return; } @@ -27,7 +27,7 @@ protected TlsRecord(ReadOnlySpan data) HandshakeClientRandom = data.TakeBytes(ref index, 32); byte handshakeSessionIdLength = data.TakeByte(ref index); HandshakeSessionId = data.TakeBytes(ref index, handshakeSessionIdLength); - HandshakeExtensions = new(); + HandshakeExtensions = []; } protected TlsRecord(TlsVersion tlsVersion, TlsContentType tlsContentType, TlsHandshakeType tlsHandshakeType) @@ -47,7 +47,7 @@ protected TlsRecord(TlsVersion tlsVersion, TlsContentType tlsContentType, TlsHan new Random().NextBytes(HandshakeSessionId); - HandshakeExtensions = new(); + HandshakeExtensions = []; } public int HandshakeMessageNumberOfBytes => HandshakeClientVersion.Length + HandshakeClientRandom.Length + 1 + HandshakeSessionId.Length + GetRecordTypeBytes().Length + HandshakeExtensionsLength.Length + HandshakeExtensions.Sum(q => q.GetBytes().Length); // + 1 for HandshakeSessionIdLength @@ -119,7 +119,7 @@ public byte[] GetBytes() result.AddRange(handshakeExtension.GetBytes()); } - return result.ToArray(); + return [.. result]; } public byte[] GetMessageBytes() @@ -142,6 +142,6 @@ public byte[] GetMessageBytes() result.AddRange(handshakeExtension.GetBytes()); } - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/Tls/Records/TlsRecordHeader.cs b/CipherPunk/Entities/Tls/Records/TlsRecordHeader.cs index 1a2e3fa..2f6f8a6 100644 --- a/CipherPunk/Entities/Tls/Records/TlsRecordHeader.cs +++ b/CipherPunk/Entities/Tls/Records/TlsRecordHeader.cs @@ -49,6 +49,6 @@ public byte[] GetBytes() result.AddRange(TlsRecordVersion); result.AddRange(TlsRecordLength); - return result.ToArray(); + return [.. result]; } } \ No newline at end of file diff --git a/CipherPunk/Entities/WindowsDocumentationCipherSuiteConfiguration.cs b/CipherPunk/Entities/WindowsDocumentationCipherSuiteConfiguration.cs index 529e7ea..1615771 100644 --- a/CipherPunk/Entities/WindowsDocumentationCipherSuiteConfiguration.cs +++ b/CipherPunk/Entities/WindowsDocumentationCipherSuiteConfiguration.cs @@ -10,14 +10,10 @@ public readonly record struct WindowsDocumentationCipherSuiteConfiguration( bool ExplicitApplicationRequestOnly = false, SslProviderKeyTypeId? PreWindows10EllipticCurve = null) { - public string GetName() - { - return FormattableString.Invariant($"{CipherSuite}{PreWindows10EllipticCurveName(PreWindows10EllipticCurve)}"); - } + public string GetName() => FormattableString.Invariant($"{CipherSuite}{PreWindows10EllipticCurveName(PreWindows10EllipticCurve)}"); - private static string? PreWindows10EllipticCurveName(SslProviderKeyTypeId? preWindows10EllipticCurve) - { - return preWindows10EllipticCurve switch + private static string? PreWindows10EllipticCurveName(SslProviderKeyTypeId? preWindows10EllipticCurve) => + preWindows10EllipticCurve switch { SslProviderKeyTypeId.TLS_ECC_P256_CURVE_KEY_TYPE => "_P256", SslProviderKeyTypeId.TLS_ECC_P384_CURVE_KEY_TYPE => "_P384", @@ -25,5 +21,4 @@ public string GetName() null => null, _ => throw new ArgumentOutOfRangeException(nameof(preWindows10EllipticCurve), preWindows10EllipticCurve, null) }; - } } \ No newline at end of file diff --git a/CipherPunk/Extensions/ReadOnlySpanOfBytesExtensions.cs b/CipherPunk/Extensions/ReadOnlySpanOfBytesExtensions.cs index 8fde186..b8bb04f 100644 --- a/CipherPunk/Extensions/ReadOnlySpanOfBytesExtensions.cs +++ b/CipherPunk/Extensions/ReadOnlySpanOfBytesExtensions.cs @@ -2,10 +2,7 @@ public static class ReadOnlySpanOfBytesExtensions { - public static byte TakeByte(this ReadOnlySpan data, ref int index) - { - return data[index..++index][0]; - } + public static byte TakeByte(this ReadOnlySpan data, ref int index) => data[index..++index][0]; public static byte[] TakeBytes(this ReadOnlySpan data, ref int index, int size) { diff --git a/CipherPunk/Extensions/ServiceCollectionExtensions.cs b/CipherPunk/Extensions/ServiceCollectionExtensions.cs index c10ed8d..4db28b5 100644 --- a/CipherPunk/Extensions/ServiceCollectionExtensions.cs +++ b/CipherPunk/Extensions/ServiceCollectionExtensions.cs @@ -10,8 +10,7 @@ public static class ServiceCollectionExtensions /// The to add the service to. /// A reference to this instance after the operation has completed. public static IServiceCollection AddCipherPunk(this IServiceCollection services) - { - return services + => services .AddSingleton() .AddSingleton() .AddSingleton() @@ -21,5 +20,4 @@ public static IServiceCollection AddCipherPunk(this IServiceCollection services) .AddSingleton() .AddSingleton() .AddSingleton(); - } } \ No newline at end of file diff --git a/CipherPunk/Services/CipherSuiteService.cs b/CipherPunk/Services/CipherSuiteService.cs index fb8f81e..076a59e 100644 --- a/CipherPunk/Services/CipherSuiteService.cs +++ b/CipherPunk/Services/CipherSuiteService.cs @@ -303,25 +303,20 @@ public void RemoveCipherSuite(string cipherSuite) } [SupportedOSPlatform("windows6.0.6000")] - public void RemoveCipherSuite(SslProviderCipherSuiteId cipherSuite) - { - RemoveCipherSuite(cipherSuite.ToString()); - } + public void RemoveCipherSuite(SslProviderCipherSuiteId cipherSuite) => RemoveCipherSuite(cipherSuite.ToString()); [SupportedOSPlatform("windows6.0.6000")] public void AddCipherSuite(string cipherSuite, bool top = true) { - NTSTATUS status = PInvoke.BCryptAddContextFunction(BCRYPT_TABLE.CRYPT_LOCAL, LocalCngSslContextName, BCRYPT_INTERFACE.NCRYPT_SCHANNEL_INTERFACE, cipherSuite, (uint)(top ? PriorityListPosition.CRYPT_PRIORITY_TOP : PriorityListPosition.CRYPT_PRIORITY_BOTTOM)); + NTSTATUS status = PInvoke.BCryptAddContextFunction( + BCRYPT_TABLE.CRYPT_LOCAL, LocalCngSslContextName, BCRYPT_INTERFACE.NCRYPT_SCHANNEL_INTERFACE, cipherSuite, (uint)(top ? PriorityListPosition.CRYPT_PRIORITY_TOP : PriorityListPosition.CRYPT_PRIORITY_BOTTOM)); if (status.SeverityCode is not NTSTATUS.Severity.Success) throw new Win32Exception(status); } [SupportedOSPlatform("windows6.0.6000")] - public void AddCipherSuite(SslProviderCipherSuiteId cipherSuite) - { - AddCipherSuite(cipherSuite.ToString()); - } + public void AddCipherSuite(SslProviderCipherSuiteId cipherSuite) => AddCipherSuite(cipherSuite.ToString()); [SupportedOSPlatform("windows6.0.6000")] public void UpdateCipherSuiteOrder(string[] cipherSuites) @@ -340,8 +335,5 @@ public void UpdateCipherSuiteOrder(string[] cipherSuites) } [SupportedOSPlatform("windows6.0.6000")] - public void UpdateCipherSuiteOrder(SslProviderCipherSuiteId[] cipherSuites) - { - UpdateCipherSuiteOrder(cipherSuites.Select(q => q.ToString()).ToArray()); - } + public void UpdateCipherSuiteOrder(SslProviderCipherSuiteId[] cipherSuites) => UpdateCipherSuiteOrder(cipherSuites.Select(q => q.ToString()).ToArray()); } \ No newline at end of file diff --git a/CipherPunk/Services/Documentation/Windows10V1507CipherSuiteDocumentationService.cs b/CipherPunk/Services/Documentation/Windows10V1507CipherSuiteDocumentationService.cs index d86e647..e516a86 100644 --- a/CipherPunk/Services/Documentation/Windows10V1507CipherSuiteDocumentationService.cs +++ b/CipherPunk/Services/Documentation/Windows10V1507CipherSuiteDocumentationService.cs @@ -4,7 +4,6 @@ internal static class Windows10V1507CipherSuiteDocumentationService { -#pragma warning disable SA1010 // Opening square brackets should be spaced correctly public static (WindowsSchannelVersion Version, List Configurations) GetConfiguration() => (WindowsSchannelVersion.Windows10V1507, [.. GetDefaultEnabledConfiguration(), .. GetDefaultDisabledConfiguration()]); @@ -60,5 +59,4 @@ private static List GetDefaultDisa new(SslProviderCipherSuiteId.SSL_CK_DES_64_CBC_WITH_MD5, true, false, [SslProviderProtocolId.SSL2_PROTOCOL_VERSION]), new(SslProviderCipherSuiteId.SSL_CK_RC4_128_EXPORT40_WITH_MD5, false, false, [SslProviderProtocolId.SSL2_PROTOCOL_VERSION]) }; -#pragma warning restore SA1010 // Opening square brackets should be spaced correctly } \ No newline at end of file diff --git a/CipherPunk/Services/Documentation/Windows10V1511CipherSuiteDocumentationService.cs b/CipherPunk/Services/Documentation/Windows10V1511CipherSuiteDocumentationService.cs index 6cc05bd..0897eba 100644 --- a/CipherPunk/Services/Documentation/Windows10V1511CipherSuiteDocumentationService.cs +++ b/CipherPunk/Services/Documentation/Windows10V1511CipherSuiteDocumentationService.cs @@ -4,7 +4,6 @@ internal static class Windows10V1511CipherSuiteDocumentationService { -#pragma warning disable SA1010 // Opening square brackets should be spaced correctly public static (WindowsSchannelVersion Version, List Configurations) GetConfiguration() => (WindowsSchannelVersion.Windows10V1511, [.. GetDefaultEnabledConfiguration(), .. GetDefaultDisabledConfiguration()]); @@ -60,5 +59,4 @@ private static List GetDefaultDisa new(SslProviderCipherSuiteId.SSL_CK_DES_64_CBC_WITH_MD5, false, false, [SslProviderProtocolId.SSL2_PROTOCOL_VERSION]), new(SslProviderCipherSuiteId.SSL_CK_RC4_128_EXPORT40_WITH_MD5, false, false, [SslProviderProtocolId.SSL2_PROTOCOL_VERSION]) }; -#pragma warning restore SA1010 // Opening square brackets should be spaced correctly } \ No newline at end of file diff --git a/CipherPunk/Services/Documentation/Windows10V1607CipherSuiteDocumentationService.cs b/CipherPunk/Services/Documentation/Windows10V1607CipherSuiteDocumentationService.cs index 4e6e375..49d671b 100644 --- a/CipherPunk/Services/Documentation/Windows10V1607CipherSuiteDocumentationService.cs +++ b/CipherPunk/Services/Documentation/Windows10V1607CipherSuiteDocumentationService.cs @@ -4,7 +4,6 @@ internal static class Windows10V1607CipherSuiteDocumentationService { -#pragma warning disable SA1010 // Opening square brackets should be spaced correctly public static (WindowsSchannelVersion Version, List Configurations) GetConfiguration() => (WindowsSchannelVersion.Windows10V1607OrServer2016, [.. GetDefaultEnabledConfiguration(), .. GetDefaultDisabledConfiguration(), .. GetPreSharedKeyConfiguration()]); @@ -67,5 +66,4 @@ private static List GetPreSharedKe new(SslProviderCipherSuiteId.TLS_PSK_WITH_NULL_SHA384, false, false, [SslProviderProtocolId.TLS1_2_PROTOCOL_VERSION], true), new(SslProviderCipherSuiteId.TLS_PSK_WITH_NULL_SHA256, false, false, [SslProviderProtocolId.TLS1_2_PROTOCOL_VERSION], true) }; -#pragma warning restore SA1010 // Opening square brackets should be spaced correctly } \ No newline at end of file diff --git a/CipherPunk/Services/Documentation/Windows10V1703CipherSuiteDocumentationService.cs b/CipherPunk/Services/Documentation/Windows10V1703CipherSuiteDocumentationService.cs index 412b4a3..476d8a1 100644 --- a/CipherPunk/Services/Documentation/Windows10V1703CipherSuiteDocumentationService.cs +++ b/CipherPunk/Services/Documentation/Windows10V1703CipherSuiteDocumentationService.cs @@ -4,7 +4,6 @@ internal static class Windows10V1703CipherSuiteDocumentationService { -#pragma warning disable SA1010 // Opening square brackets should be spaced correctly public static (WindowsSchannelVersion Version, List Configurations) GetConfiguration() => (WindowsSchannelVersion.Windows10V1703, [.. GetDefaultEnabledConfiguration(), .. GetDefaultDisabledConfiguration(), .. GetPreSharedKeyConfiguration()]); @@ -67,5 +66,4 @@ private static List GetPreSharedKe new(SslProviderCipherSuiteId.TLS_PSK_WITH_NULL_SHA384, false, false, [SslProviderProtocolId.TLS1_2_PROTOCOL_VERSION], true), new(SslProviderCipherSuiteId.TLS_PSK_WITH_NULL_SHA256, false, false, [SslProviderProtocolId.TLS1_2_PROTOCOL_VERSION], true) }; -#pragma warning restore SA1010 // Opening square brackets should be spaced correctly } \ No newline at end of file diff --git a/CipherPunk/Services/Documentation/Windows10V1709CipherSuiteDocumentationService.cs b/CipherPunk/Services/Documentation/Windows10V1709CipherSuiteDocumentationService.cs index addc046..52d4d94 100644 --- a/CipherPunk/Services/Documentation/Windows10V1709CipherSuiteDocumentationService.cs +++ b/CipherPunk/Services/Documentation/Windows10V1709CipherSuiteDocumentationService.cs @@ -4,7 +4,6 @@ internal static class Windows10V1709CipherSuiteDocumentationService { -#pragma warning disable SA1010 // Opening square brackets should be spaced correctly public static (WindowsSchannelVersion Version, List Configurations) GetConfiguration() => (WindowsSchannelVersion.Windows10V1709, [.. GetDefaultEnabledConfiguration(), .. GetDefaultDisabledConfiguration(), .. GetPreSharedKeyConfiguration()]); @@ -67,5 +66,4 @@ private static List GetPreSharedKe new(SslProviderCipherSuiteId.TLS_PSK_WITH_NULL_SHA384, false, false, [SslProviderProtocolId.TLS1_2_PROTOCOL_VERSION], true), new(SslProviderCipherSuiteId.TLS_PSK_WITH_NULL_SHA256, false, false, [SslProviderProtocolId.TLS1_2_PROTOCOL_VERSION], true) }; -#pragma warning restore SA1010 // Opening square brackets should be spaced correctly } \ No newline at end of file diff --git a/CipherPunk/Services/Documentation/Windows10V1903CipherSuiteDocumentationService.cs b/CipherPunk/Services/Documentation/Windows10V1903CipherSuiteDocumentationService.cs index e70f579..5628dc5 100644 --- a/CipherPunk/Services/Documentation/Windows10V1903CipherSuiteDocumentationService.cs +++ b/CipherPunk/Services/Documentation/Windows10V1903CipherSuiteDocumentationService.cs @@ -4,7 +4,6 @@ internal static class Windows10V1903CipherSuiteDocumentationService { -#pragma warning disable SA1010 // Opening square brackets should be spaced correctly public static (WindowsSchannelVersion Version, List Configurations) GetConfiguration() => (WindowsSchannelVersion.Windows10V1903, [.. GetDefaultEnabledConfiguration(), .. GetDefaultDisabledConfiguration(), .. GetPreSharedKeyConfiguration()]); @@ -67,5 +66,4 @@ private static List GetPreSharedKe new(SslProviderCipherSuiteId.TLS_PSK_WITH_NULL_SHA384, false, false, [SslProviderProtocolId.TLS1_2_PROTOCOL_VERSION], true), new(SslProviderCipherSuiteId.TLS_PSK_WITH_NULL_SHA256, false, false, [SslProviderProtocolId.TLS1_2_PROTOCOL_VERSION], true) }; -#pragma warning restore SA1010 // Opening square brackets should be spaced correctly } \ No newline at end of file diff --git a/CipherPunk/Services/Documentation/Windows10V22H2CipherSuiteDocumentationService.cs b/CipherPunk/Services/Documentation/Windows10V22H2CipherSuiteDocumentationService.cs index eed5cf5..66ba689 100644 --- a/CipherPunk/Services/Documentation/Windows10V22H2CipherSuiteDocumentationService.cs +++ b/CipherPunk/Services/Documentation/Windows10V22H2CipherSuiteDocumentationService.cs @@ -4,7 +4,6 @@ internal static class Windows10V22H2CipherSuiteDocumentationService { -#pragma warning disable SA1010 // Opening square brackets should be spaced correctly public static (WindowsSchannelVersion Version, List Configurations) GetConfiguration() => (WindowsSchannelVersion.Windows10V22H2, [.. GetDefaultEnabledConfiguration(), .. GetDefaultDisabledConfiguration(), .. GetPreSharedKeyConfiguration()]); @@ -67,5 +66,4 @@ private static List GetPreSharedKe new(SslProviderCipherSuiteId.TLS_PSK_WITH_NULL_SHA384, false, false, [SslProviderProtocolId.TLS1_2_PROTOCOL_VERSION], true), new(SslProviderCipherSuiteId.TLS_PSK_WITH_NULL_SHA256, false, false, [SslProviderProtocolId.TLS1_2_PROTOCOL_VERSION], true) }; -#pragma warning restore SA1010 // Opening square brackets should be spaced correctly } \ No newline at end of file diff --git a/CipherPunk/Services/Documentation/Windows11CipherSuiteDocumentationService.cs b/CipherPunk/Services/Documentation/Windows11CipherSuiteDocumentationService.cs index 36d354c..fe354eb 100644 --- a/CipherPunk/Services/Documentation/Windows11CipherSuiteDocumentationService.cs +++ b/CipherPunk/Services/Documentation/Windows11CipherSuiteDocumentationService.cs @@ -4,7 +4,6 @@ internal static class Windows11CipherSuiteDocumentationService { -#pragma warning disable SA1010 // Opening square brackets should be spaced correctly public static (WindowsSchannelVersion Version, List Configurations) GetConfiguration() => (WindowsSchannelVersion.Windows11, [.. GetDefaultEnabledConfiguration(), .. GetDefaultDisabledConfiguration(), .. GetPreSharedKeyConfiguration()]); @@ -70,5 +69,4 @@ private static List GetPreSharedKe new(SslProviderCipherSuiteId.TLS_PSK_WITH_NULL_SHA384, false, false, [SslProviderProtocolId.TLS1_2_PROTOCOL_VERSION], true), new(SslProviderCipherSuiteId.TLS_PSK_WITH_NULL_SHA256, false, false, [SslProviderProtocolId.TLS1_2_PROTOCOL_VERSION], true) }; -#pragma warning restore SA1010 // Opening square brackets should be spaced correctly } \ No newline at end of file diff --git a/CipherPunk/Services/Documentation/Windows11V22H2CipherSuiteDocumentationService.cs b/CipherPunk/Services/Documentation/Windows11V22H2CipherSuiteDocumentationService.cs index 1d7b51b..73cb71c 100644 --- a/CipherPunk/Services/Documentation/Windows11V22H2CipherSuiteDocumentationService.cs +++ b/CipherPunk/Services/Documentation/Windows11V22H2CipherSuiteDocumentationService.cs @@ -4,7 +4,6 @@ internal static class Windows11V22H2CipherSuiteDocumentationService { -#pragma warning disable SA1010 // Opening square brackets should be spaced correctly public static (WindowsSchannelVersion Version, List Configurations) GetConfiguration() => (WindowsSchannelVersion.Windows11V22H2, [.. GetDefaultEnabledConfiguration(), .. GetDefaultDisabledConfiguration(), .. GetPreSharedKeyConfiguration()]); @@ -70,5 +69,4 @@ private static List GetPreSharedKe new(SslProviderCipherSuiteId.TLS_PSK_WITH_NULL_SHA384, false, false, [SslProviderProtocolId.TLS1_2_PROTOCOL_VERSION], true), new(SslProviderCipherSuiteId.TLS_PSK_WITH_NULL_SHA256, false, false, [SslProviderProtocolId.TLS1_2_PROTOCOL_VERSION], true) }; -#pragma warning restore SA1010 // Opening square brackets should be spaced correctly } \ No newline at end of file diff --git a/CipherPunk/Services/Documentation/Windows7CipherSuiteDocumentationService.cs b/CipherPunk/Services/Documentation/Windows7CipherSuiteDocumentationService.cs index b0a3a4f..79fdbec 100644 --- a/CipherPunk/Services/Documentation/Windows7CipherSuiteDocumentationService.cs +++ b/CipherPunk/Services/Documentation/Windows7CipherSuiteDocumentationService.cs @@ -4,7 +4,6 @@ internal static class Windows7CipherSuiteDocumentationService { -#pragma warning disable SA1010 // Opening square brackets should be spaced correctly public static (WindowsSchannelVersion Version, List Configurations) GetConfiguration() => (WindowsSchannelVersion.Windows7OrServer2008R2, [.. GetDefaultEnabledConfiguration(), .. GetDefaultDisabledConfiguration()]); @@ -76,5 +75,4 @@ private static List GetDefaultDisa new(SslProviderCipherSuiteId.SSL_CK_DES_64_CBC_WITH_MD5, true, false, [SslProviderProtocolId.SSL2_PROTOCOL_VERSION]), new(SslProviderCipherSuiteId.SSL_CK_RC4_128_EXPORT40_WITH_MD5, false, false, [SslProviderProtocolId.SSL2_PROTOCOL_VERSION]) }; -#pragma warning restore SA1010 // Opening square brackets should be spaced correctly } \ No newline at end of file diff --git a/CipherPunk/Services/Documentation/Windows81CipherSuiteDocumentationService.cs b/CipherPunk/Services/Documentation/Windows81CipherSuiteDocumentationService.cs index 97f194d..f2bed60 100644 --- a/CipherPunk/Services/Documentation/Windows81CipherSuiteDocumentationService.cs +++ b/CipherPunk/Services/Documentation/Windows81CipherSuiteDocumentationService.cs @@ -4,7 +4,6 @@ internal static class Windows81CipherSuiteDocumentationService { -#pragma warning disable SA1010 // Opening square brackets should be spaced correctly public static (WindowsSchannelVersion Version, List Configurations) GetConfiguration() => (WindowsSchannelVersion.Windows81OrServer2012R2, [.. GetDefaultEnabledConfiguration(), .. GetDefaultDisabledConfiguration()]); @@ -76,5 +75,4 @@ private static List GetDefaultDisa new(SslProviderCipherSuiteId.SSL_CK_DES_64_CBC_WITH_MD5, true, false, [SslProviderProtocolId.SSL2_PROTOCOL_VERSION]), new(SslProviderCipherSuiteId.SSL_CK_RC4_128_EXPORT40_WITH_MD5, false, false, [SslProviderProtocolId.SSL2_PROTOCOL_VERSION]) }; -#pragma warning restore SA1010 // Opening square brackets should be spaced correctly } \ No newline at end of file diff --git a/CipherPunk/Services/Documentation/Windows8CipherSuiteDocumentationService.cs b/CipherPunk/Services/Documentation/Windows8CipherSuiteDocumentationService.cs index 6ecafbf..b17ebad 100644 --- a/CipherPunk/Services/Documentation/Windows8CipherSuiteDocumentationService.cs +++ b/CipherPunk/Services/Documentation/Windows8CipherSuiteDocumentationService.cs @@ -4,7 +4,6 @@ internal static class Windows8CipherSuiteDocumentationService { -#pragma warning disable SA1010 // Opening square brackets should be spaced correctly public static (WindowsSchannelVersion Version, List Configurations) GetConfiguration() => (WindowsSchannelVersion.Windows8OrServer2012, [.. GetDefaultEnabledConfiguration(), .. GetDefaultDisabledConfiguration()]); @@ -74,5 +73,4 @@ private static List GetDefaultDisa new(SslProviderCipherSuiteId.SSL_CK_DES_64_CBC_WITH_MD5, true, false, [SslProviderProtocolId.SSL2_PROTOCOL_VERSION]), new(SslProviderCipherSuiteId.SSL_CK_RC4_128_EXPORT40_WITH_MD5, false, false, [SslProviderProtocolId.SSL2_PROTOCOL_VERSION]) }; -#pragma warning restore SA1010 // Opening square brackets should be spaced correctly } \ No newline at end of file diff --git a/CipherPunk/Services/Documentation/WindowsEllipticCurveDocumentationService.cs b/CipherPunk/Services/Documentation/WindowsEllipticCurveDocumentationService.cs index 4d7f2cb..1ab64ef 100644 --- a/CipherPunk/Services/Documentation/WindowsEllipticCurveDocumentationService.cs +++ b/CipherPunk/Services/Documentation/WindowsEllipticCurveDocumentationService.cs @@ -10,7 +10,7 @@ public Dictionary windowsDocumentationEllipticCurveConfigurations ??= BuildWindowsDocumentationEllipticCurveConfigurations(); public List GetWindowsDocumentationEllipticCurveConfigurations(WindowsSchannelVersion windowsSchannelVersion) - => GetWindowsDocumentationEllipticCurveConfigurations().Any(q => q.Key >= windowsSchannelVersion) ? GetWindowsDocumentationEllipticCurveConfigurations().FirstOrDefault(q => q.Key >= windowsSchannelVersion).Value : new(); + => GetWindowsDocumentationEllipticCurveConfigurations().Any(q => q.Key >= windowsSchannelVersion) ? GetWindowsDocumentationEllipticCurveConfigurations().FirstOrDefault(q => q.Key >= windowsSchannelVersion).Value : []; private Dictionary> BuildWindowsDocumentationEllipticCurveConfigurations() { diff --git a/CipherPunk/Services/Documentation/WindowsServer2022CipherSuiteDocumentationService.cs b/CipherPunk/Services/Documentation/WindowsServer2022CipherSuiteDocumentationService.cs index 9f5a713..7660491 100644 --- a/CipherPunk/Services/Documentation/WindowsServer2022CipherSuiteDocumentationService.cs +++ b/CipherPunk/Services/Documentation/WindowsServer2022CipherSuiteDocumentationService.cs @@ -4,7 +4,6 @@ internal static class WindowsServer2022CipherSuiteDocumentationService { -#pragma warning disable SA1010 // Opening square brackets should be spaced correctly public static (WindowsSchannelVersion Version, List Configurations) GetConfiguration() => (WindowsSchannelVersion.WindowsServer2022, [.. GetDefaultEnabledConfiguration(), .. GetDefaultDisabledConfiguration(), .. GetPreSharedKeyConfiguration()]); @@ -70,5 +69,4 @@ private static List GetPreSharedKe new(SslProviderCipherSuiteId.TLS_PSK_WITH_NULL_SHA384, false, false, [SslProviderProtocolId.TLS1_2_PROTOCOL_VERSION], true), new(SslProviderCipherSuiteId.TLS_PSK_WITH_NULL_SHA256, false, false, [SslProviderProtocolId.TLS1_2_PROTOCOL_VERSION], true) }; -#pragma warning restore SA1010 // Opening square brackets should be spaced correctly } \ No newline at end of file diff --git a/CipherPunk/Services/Documentation/WindowsVistaCipherSuiteDocumentationService.cs b/CipherPunk/Services/Documentation/WindowsVistaCipherSuiteDocumentationService.cs index 6c56d5c..ef310f3 100644 --- a/CipherPunk/Services/Documentation/WindowsVistaCipherSuiteDocumentationService.cs +++ b/CipherPunk/Services/Documentation/WindowsVistaCipherSuiteDocumentationService.cs @@ -4,7 +4,6 @@ internal static class WindowsVistaCipherSuiteDocumentationService { -#pragma warning disable SA1010 // Opening square brackets should be spaced correctly public static (WindowsSchannelVersion Version, List Configurations) GetConfiguration() => (WindowsSchannelVersion.WindowsVistaOrServer2008, [.. GetDefaultEnabledConfiguration(), .. GetDefaultDisabledConfiguration()]); @@ -49,5 +48,4 @@ private static List GetDefaultDisa new(SslProviderCipherSuiteId.TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA, true, false, [SslProviderProtocolId.TLS1_2_PROTOCOL_VERSION, SslProviderProtocolId.TLS1_1_PROTOCOL_VERSION, SslProviderProtocolId.TLS1_0_PROTOCOL_VERSION, SslProviderProtocolId.SSL3_PROTOCOL_VERSION]), new(SslProviderCipherSuiteId.TLS_DHE_DSS_WITH_DES_CBC_SHA, true, false, [SslProviderProtocolId.TLS1_2_PROTOCOL_VERSION, SslProviderProtocolId.TLS1_1_PROTOCOL_VERSION, SslProviderProtocolId.TLS1_0_PROTOCOL_VERSION, SslProviderProtocolId.SSL3_PROTOCOL_VERSION]) }; -#pragma warning restore SA1010 // Opening square brackets should be spaced correctly } \ No newline at end of file diff --git a/CipherPunk/Services/EllipticCurveIdentifierService.cs b/CipherPunk/Services/EllipticCurveIdentifierService.cs index 61e9477..a9c3a5a 100644 --- a/CipherPunk/Services/EllipticCurveIdentifierService.cs +++ b/CipherPunk/Services/EllipticCurveIdentifierService.cs @@ -9,19 +9,12 @@ internal sealed class EllipticCurveIdentifierService : IEllipticCurveIdentifierS public Dictionary GetEllipticCurveIdentifiers() => ellipticCurveIdentifiers ??= BuildEllipticCurveIdentifiers(); - public string? GetIdentifier(string code) - { - return GetIdentifier(Enum.Parse(code, true)); - } + public string? GetIdentifier(string code) => GetIdentifier(Enum.Parse(code, true)); - public string? GetIdentifier(BCRYPT_ECC_CURVE code) - { - return GetEllipticCurveIdentifiers()[code]; - } + public string? GetIdentifier(BCRYPT_ECC_CURVE code) => GetEllipticCurveIdentifiers()[code]; private static Dictionary BuildEllipticCurveIdentifiers() - { - return new() + => new() { { BCRYPT_ECC_CURVE.BCRYPT_ECC_CURVE_25519, null }, { BCRYPT_ECC_CURVE.BCRYPT_ECC_CURVE_BRAINPOOLP160R1, PInvoke.szOID_ECC_CURVE_BRAINPOOLP160R1 }, @@ -66,5 +59,4 @@ internal sealed class EllipticCurveIdentifierService : IEllipticCurveIdentifierS { BCRYPT_ECC_CURVE.BCRYPT_ECC_CURVE_X962P239V3, PInvoke.szOID_ECC_CURVE_X962P239V3 }, { BCRYPT_ECC_CURVE.BCRYPT_ECC_CURVE_X962P256V1, PInvoke.szOID_ECC_CURVE_X962P256V1 } }; - } } \ No newline at end of file diff --git a/CipherPunk/Services/EllipticCurveService.cs b/CipherPunk/Services/EllipticCurveService.cs index 18c68fd..d798ffb 100644 --- a/CipherPunk/Services/EllipticCurveService.cs +++ b/CipherPunk/Services/EllipticCurveService.cs @@ -189,7 +189,7 @@ public List GetOperatingSystemAvailableEll } // todo search strings in certutil.exe: CurveType, EccCurveFlags - var windowsEllipticCurveInfo = new WindowsApiEllipticCurveConfiguration(null, eccCurveNameString, null, null, null, dwBitLength, null, null, new(), null); + var windowsEllipticCurveInfo = new WindowsApiEllipticCurveConfiguration(null, eccCurveNameString, null, null, null, dwBitLength, null, null, [], null); curveConfigurations.Add(windowsEllipticCurveInfo); } @@ -239,7 +239,7 @@ public List GetOperatingSystemAvailableEll if (string.IsNullOrWhiteSpace(pwszCNGExtraAlgid)) pwszCNGExtraAlgid = null; - var windowsEllipticCurveInfo = new WindowsApiEllipticCurveConfiguration(pszOid, pwszName, dwGroupId, dwMagic, algId, dwBitLength, bcryptMagic, flags, new() { pwszCNGAlgid! }, pwszCNGExtraAlgid); + var windowsEllipticCurveInfo = new WindowsApiEllipticCurveConfiguration(pszOid, pwszName, dwGroupId, dwMagic, algId, dwBitLength, bcryptMagic, flags, [pwszCNGAlgid!], pwszCNGExtraAlgid); curveConfigurations.Add(windowsEllipticCurveInfo); } @@ -276,7 +276,7 @@ public List GetOperatingSystemDe public List GetOperatingSystemActiveEllipticCurveList() { using RegistryKey? registryKey = Registry.LocalMachine.OpenSubKey(NcryptSchannelInterfaceSslKey); - string[] activeEllipticCurves = (string[]?)registryKey?.GetValue(CurveOrderValueName, null, RegistryValueOptions.DoNotExpandEnvironmentNames) ?? Array.Empty(); + string[] activeEllipticCurves = (string[]?)registryKey?.GetValue(CurveOrderValueName, null, RegistryValueOptions.DoNotExpandEnvironmentNames) ?? []; List availableWindowsApiActiveEllipticCurveConfigurations = GetOperatingSystemAvailableEllipticCurveList(); return availableWindowsApiActiveEllipticCurveConfigurations.Where(q => activeEllipticCurves.Contains(q.pwszName, StringComparer.OrdinalIgnoreCase)).ToList(); @@ -318,8 +318,5 @@ public void UpdateEllipticCurveOrder(string[] ellipticCurves) } [SupportedOSPlatform("windows6.0.6000")] - public void UpdateEllipticCurveOrder(BCRYPT_ECC_CURVE[] ellipticCurves) - { - UpdateEllipticCurveOrder(ellipticCurves.Select(q => q.ToString()).ToArray()); - } + public void UpdateEllipticCurveOrder(BCRYPT_ECC_CURVE[] ellipticCurves) => UpdateEllipticCurveOrder(ellipticCurves.Select(q => q.ToString()).ToArray()); } \ No newline at end of file diff --git a/CipherPunk/Services/GroupPolicyService.cs b/CipherPunk/Services/GroupPolicyService.cs index f87b919..d7ca8ed 100644 --- a/CipherPunk/Services/GroupPolicyService.cs +++ b/CipherPunk/Services/GroupPolicyService.cs @@ -83,16 +83,10 @@ public void UpdateEccCurveOrderPolicy(string[] ellipticCurves) } [SupportedOSPlatform("windows6.0.6000")] - public string[] GetSslCipherSuiteOrderPolicy() - { - return GetOrderPolicy(SslCipherSuiteOrderValueName, REG_ROUTINE_FLAGS.RRF_RT_REG_SZ)?.Split(',') ?? Array.Empty(); - } + public string[] GetSslCipherSuiteOrderPolicy() => GetOrderPolicy(SslCipherSuiteOrderValueName, REG_ROUTINE_FLAGS.RRF_RT_REG_SZ)?.Split(',') ?? []; [SupportedOSPlatform("windows6.0.6000")] - public string[] GetEccCurveOrderPolicy() - { - return GetOrderPolicy(SslCurveOrderValueName, REG_ROUTINE_FLAGS.RRF_RT_REG_MULTI_SZ)?.Split('\0', StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty(); - } + public string[] GetEccCurveOrderPolicy() => GetOrderPolicy(SslCurveOrderValueName, REG_ROUTINE_FLAGS.RRF_RT_REG_MULTI_SZ)?.Split('\0', StringSplitOptions.RemoveEmptyEntries) ?? []; [SupportedOSPlatform("windows6.0.6000")] private static void UpdateOrderPolicy(string valueData, string valueName, REG_VALUE_TYPE valueType) diff --git a/CipherPunk/Services/SchannelLogService.cs b/CipherPunk/Services/SchannelLogService.cs index 7ac10c3..9d23a6f 100644 --- a/CipherPunk/Services/SchannelLogService.cs +++ b/CipherPunk/Services/SchannelLogService.cs @@ -1,8 +1,10 @@ namespace CipherPunk; +using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.Runtime.Versioning; +using Windows.Win32.Foundation; internal sealed class SchannelLogService : ISchannelLogService { @@ -64,7 +66,16 @@ public List GetSchannelLogs() { string processCurrentName = process.ProcessName; string processMainWindowTitle = process.MainWindowTitle; - string? processMainModuleFileName = process.MainModule?.FileName; + string? processMainModuleFileName; + + try + { + processMainModuleFileName = process.MainModule?.FileName; + } + catch (Win32Exception ex) when (ex.NativeErrorCode is (int)WIN32_ERROR.ERROR_ACCESS_DENIED) + { + processMainModuleFileName = FormattableString.CurrentCulture($"Error: {ex.Message}"); + } result.AddRange(schannelEventLogEntries.Where(q => q.ProcessId == processId).Select(q => q.SchannelLog with { diff --git a/CipherPunk/Services/SchannelService.cs b/CipherPunk/Services/SchannelService.cs index f5ecd8f..a23bd54 100644 --- a/CipherPunk/Services/SchannelService.cs +++ b/CipherPunk/Services/SchannelService.cs @@ -72,17 +72,14 @@ public List GetProtocolSettings() } [SupportedOSPlatform("windows")] - public void UpdateProtocolSettings(List schannelProtocolSettings) - { - throw new NotImplementedException(); - } + public void UpdateProtocolSettings(List schannelProtocolSettings) => throw new NotImplementedException(); [SupportedOSPlatform("windows")] public List GetKeyExchangeAlgorithmSettings() { var result = new List(); using RegistryKey? key = Registry.LocalMachine.OpenSubKey(SchannelKeyExchangeAlgorithmsPath); - string[] subKeyNames = key?.GetSubKeyNames() ?? Array.Empty(); + string[] subKeyNames = key?.GetSubKeyNames() ?? []; foreach (string subKeyName in subKeyNames) { @@ -106,17 +103,14 @@ public List GetKeyExchangeAlgorithmSetting } [SupportedOSPlatform("windows")] - public void UpdateKeyExchangeAlgorithmSettings(List schannelKeyExchangeAlgorithmSettings) - { - throw new NotImplementedException(); - } + public void UpdateKeyExchangeAlgorithmSettings(List schannelKeyExchangeAlgorithmSettings) => throw new NotImplementedException(); [SupportedOSPlatform("windows")] public List GetSchannelHashSettings() { var result = new List(); using RegistryKey? key = Registry.LocalMachine.OpenSubKey(SchannelHashesPath); - string[] subKeyNames = key?.GetSubKeyNames() ?? Array.Empty(); + string[] subKeyNames = key?.GetSubKeyNames() ?? []; foreach (string subKeyName in subKeyNames) { @@ -146,17 +140,14 @@ public List GetSchannelHashSettings() } [SupportedOSPlatform("windows")] - public void UpdateSchannelHashSettings(List schannelHashSettings) - { - throw new NotImplementedException(); - } + public void UpdateSchannelHashSettings(List schannelHashSettings) => throw new NotImplementedException(); [SupportedOSPlatform("windows")] public List GetSchannelCipherSettings() { var result = new List(); using RegistryKey? key = Registry.LocalMachine.OpenSubKey(SchannelCiphersPath); - string[] subKeyNames = key?.GetSubKeyNames() ?? Array.Empty(); + string[] subKeyNames = key?.GetSubKeyNames() ?? []; foreach (string subKeyName in subKeyNames) { @@ -186,17 +177,14 @@ public List GetSchannelCipherSettings() } [SupportedOSPlatform("windows")] - public void UpdateSchannelCipherSettings(List schannelCipherSettings) - { - throw new NotImplementedException(); - } + public void UpdateSchannelCipherSettings(List schannelCipherSettings) => throw new NotImplementedException(); [SupportedOSPlatform("windows")] public SchannelSettings GetSchannelSettings() { using RegistryKey? key = Registry.LocalMachine.OpenSubKey(SchannelPath); var logLevel = (SchannelLogLevel?)(int?)key?.GetValue(EventLogging); - var certificateMappingMethods = (CertificateMappingMethod?)(int?)key?.GetValue(CertificateMappingMethods); + var certificateMappingMethods = (SchannelCertificateMappingMethod?)(int?)key?.GetValue(CertificateMappingMethods); int? clientCacheTime = (int?)key?.GetValue(ClientCacheTime); // in milliseconds int? enableOcspStaplingForSni = (int?)key?.GetValue(EnableOcspStaplingForSni); int? fipsAlgorithmPolicy = (int?)key?.GetValue(FipsAlgorithmPolicy); diff --git a/CipherPunk/Services/TlsService.cs b/CipherPunk/Services/TlsService.cs index 6d7743c..275153c 100644 --- a/CipherPunk/Services/TlsService.cs +++ b/CipherPunk/Services/TlsService.cs @@ -114,9 +114,7 @@ private static async ValueTask GetIpEndPointAsync(string hostName, C private static async ValueTask> GetRemoteServerCipherSuitesAsync(EndPoint endpoint, string hostName, TlsVersion tlsVersion, CancellationToken cancellationToken) { -#pragma warning disable SA1010 // Opening square brackets should be spaced correctly TlsCompressionMethodIdentifier[] tlsCompressionMethodIdentifiers = [TlsCompressionMethodIdentifier.NULL]; -#pragma warning restore SA1010 // Opening square brackets should be spaced correctly TlsEllipticCurvesPointFormat[] tlsEllipticCurvesPointFormats = Enum.GetValues(); TlsSignatureScheme[] tlsSignatureSchemes = Enum.GetValues(); TlsSupportedGroup[] tlsSupportedGroups = Enum.GetValues(); @@ -248,12 +246,9 @@ private static async ValueTask GetIpEndPointAsync(string hostName, C } } - private static bool IsSsl2Response(Memory responseBytes) - { - // https://www.rfc-editor.org/rfc/rfc2246#appendix-E - // E.1. Version 2 client hello - return (responseBytes.Span[0] & 0x80) is 0x80; - } + // https://www.rfc-editor.org/rfc/rfc2246#appendix-E + // E.1. Version 2 client hello + private static bool IsSsl2Response(Memory responseBytes) => (responseBytes.Span[0] & 0x80) is 0x80; private static async ValueTask> SendClientHelloAsync(Memory clientHelloBytes, EndPoint endPoint, CancellationToken cancellationToken) { diff --git a/README.md b/README.md index a9571ec..e12639f 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # CipherPunk -Allows Windows Schannel CipherSuite and Elliptic Curve configuration. +Library & UI for Windows Schannel CipherSuite and Elliptic Curve configuration and remote server probing. Inspired by [IISCrypto](https://www.nartac.com/Products/IISCrypto/) Features -* Supports SSL/TLS protocols from SSL2.0 to TLS1.3 +* Supports SSL2.0, SSL3.0, TLS1.0, TLS1.1, TLS1.2 & TLS1.3 * Remote server probing * Cipher Suite configuration * Elliptic Curve configuration @@ -13,7 +13,7 @@ Features Available as a standalone Windows application ([UI](#cipherpunkui)) and as a NuGet package ([API](#cipherpunk-1)). -Note: not all applications use Schannel, most browsers for example require seperate configuration. +Note: not all applications use Schannel, most browsers for example require separate configuration. ## CipherPunk.UI A Windows .NET WPF application for x86, x64 and ARM64.