Skip to content

Commit

Permalink
Implements ISLOG SAM Manager Template as a new read-only Key Store
Browse files Browse the repository at this point in the history
Add new option on Key Store to inform about Key Entries Update capability (default set to true)
  • Loading branch information
Maxhy committed Oct 17, 2023
1 parent 733f93b commit ef39b55
Show file tree
Hide file tree
Showing 22 changed files with 608 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Leosac.KeyManager.Library.Plugin.UI.Domain;
using CommunityToolkit.Mvvm.Input;
using Leosac.KeyManager.Library.Plugin.UI.Domain;
using Microsoft.Win32;
using Net.Pkcs11Interop.Common;
using System.Collections.ObjectModel;

Expand All @@ -11,6 +13,17 @@ public PKCS11KeyStorePropertiesControlViewModel()
_properties = new PKCS11KeyStoreProperties();
FilterTypes = new ObservableCollection<SlotFilterType>(Enum.GetValues<SlotFilterType>());
UserTypes = new ObservableCollection<CKU>(Enum.GetValues<CKU>());
BrowseCommand = new RelayCommand(() =>
{
var ofd = new OpenFileDialog();
ofd.Filter = "Dll files (*.dll)|*.dll";
ofd.FileName = PKCS11Properties!.LibraryPath;
ofd.CheckPathExists = true;
if (ofd.ShowDialog() == true)
{
PKCS11Properties.LibraryPath = ofd.FileName;
}
});
}

public PKCS11KeyStoreProperties? PKCS11Properties
Expand All @@ -21,5 +34,7 @@ public PKCS11KeyStorePropertiesControlViewModel()
public ObservableCollection<SlotFilterType> FilterTypes { get; private set; }

public ObservableCollection<CKU> UserTypes { get; private set; }

public RelayCommand BrowseCommand;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</Binding>
</TextBox.Text>
</TextBox>
<Button Grid.Row="0" Grid.Column="1" x:Name="btnBrowse" Content="{x:Static properties:Resources.Browse}" HorizontalAlignment="Left" Margin="5,5,5,5" VerticalAlignment="Top" Click="btnBrowse_Click"/>
<Button Grid.Row="0" Grid.Column="1" x:Name="btnBrowse" Content="{x:Static properties:Resources.Browse}" HorizontalAlignment="Left" Margin="5,5,5,5" VerticalAlignment="Top" Command="{Binding BrowseCommand}"/>
<ComboBox Grid.Row="1" Grid.ColumnSpan="2" ItemsSource="{Binding FilterTypes}" SelectedItem="{Binding PKCS11Properties.SlotFilterType}"
materialDesign:HintAssist.HelperText="{x:Static properties:Resources.SlotFilterTypeHelper}"
materialDesign:HintAssist.Hint="{x:Static properties:Resources.SlotFilterType}" Margin="5,5,5,10" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
using Leosac.KeyManager.Library.KeyStore.HSM_PKCS11.UI.Domain;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls;

namespace Leosac.KeyManager.Library.KeyStore.HSM_PKCS11.UI
{
Expand All @@ -26,20 +11,5 @@ public PKCS11KeyStorePropertiesControl()
{
InitializeComponent();
}

private void btnBrowse_Click(object sender, RoutedEventArgs e)
{
if (DataContext is PKCS11KeyStorePropertiesControlViewModel model)
{
var ofd = new OpenFileDialog();
ofd.Filter = "Dll files (*.dll)|*.dll";
ofd.FileName = model.PKCS11Properties!.LibraryPath;
ofd.CheckPathExists = true;
if (ofd.ShowDialog() == true)
{
model.PKCS11Properties.LibraryPath = ofd.FileName;
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using CommunityToolkit.Mvvm.Input;
using Leosac.KeyManager.Library.KeyStore.NXP_SAM.ISLOG;
using Leosac.KeyManager.Library.Plugin.UI.Domain;
using Microsoft.Win32;

namespace Leosac.KeyManager.Library.KeyStore.NXP_SAM.UI.ISLOG.Domain
{
public class ISLOGKeyStorePropertiesControlViewModel : KeyStorePropertiesControlViewModel
{
public ISLOGKeyStorePropertiesControlViewModel()
{
_properties = new ISLOGKeyStoreProperties();
BrowseCommand = new RelayCommand(() =>
{
var ofd = new OpenFileDialog();
ofd.Filter = "Xml files (*.xml)|*.xml";
ofd.FileName = ISLOGProperties!.TemplateFile;
ofd.CheckPathExists = true;
if (ofd.ShowDialog() == true)
{
ISLOGProperties.TemplateFile = ofd.FileName;
}
});
}

public ISLOGKeyStoreProperties? ISLOGProperties
{
get { return Properties as ISLOGKeyStoreProperties; }
}

public RelayCommand BrowseCommand { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<UserControl x:Class="Leosac.KeyManager.Library.KeyStore.NXP_SAM.UI.ISLOG.ISLOGKeyStorePropertiesControl"
xmlns="http:https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http:https://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http:https://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http:https://schemas.microsoft.com/expression/blend/2008"
xmlns:domain="clr-namespace:Leosac.KeyManager.Library.KeyStore.NXP_SAM.UI.ISLOG.Domain"
xmlns:kslibDomain="clr-namespace:Leosac.KeyManager.Library.UI.Domain;assembly=KeyManager.Library.UI"
xmlns:libui="clr-namespace:Leosac.KeyManager.Library.UI;assembly=KeyManager.Library.UI"
xmlns:local="clr-namespace:Leosac.KeyManager.Library.KeyStore.NXP_SAM.UI.ISLOG"
xmlns:materialDesign="http:https://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:properties="clr-namespace:Leosac.KeyManager.Library.KeyStore.NXP_SAM.UI.Properties"
xmlns:wpfappctrls="clr-namespace:Leosac.WpfApp.Controls;assembly=WpfApp"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance domain:ISLOGKeyStorePropertiesControlViewModel}"
d:DesignHeight="200" d:DesignWidth="500">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<TextBox Grid.Row="0" Grid.Column="0" x:Name="tbxTemplateFile" HorizontalAlignment="Left" Margin="5,5,5,5" TextWrapping="Wrap" VerticalAlignment="Top" Width="300" IsReadOnly="True"
materialDesign:HintAssist.HelperText="{x:Static properties:Resources.ISLOGTemplateFileHelper}"
materialDesign:HintAssist.Hint="{x:Static properties:Resources.ISLOGTemplateFile}"
Style="{StaticResource MaterialDesignFloatingHintTextBox}">
<TextBox.Text>
<Binding Path="ISLOGProperties.TemplateFile">
<Binding.ValidationRules>
<kslibDomain:NotEmptyValidationRule />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<Button Grid.Row="0" Grid.Column="1" x:Name="btnBrowse" Content="{x:Static properties:Resources.Browse}" HorizontalAlignment="Left" Margin="5,5,5,5" VerticalAlignment="Top" Command="{Binding BrowseCommand}"/>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Windows.Controls;

namespace Leosac.KeyManager.Library.KeyStore.NXP_SAM.UI.ISLOG
{
/// <summary>
/// Interaction logic for ISLOGKeyStorePropertiesControl.xaml
/// </summary>
public partial class ISLOGKeyStorePropertiesControl : UserControl
{
public ISLOGKeyStorePropertiesControl()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Leosac.KeyManager.Library.KeyStore.NXP_SAM.ISLOG;
using Leosac.KeyManager.Library.KeyStore.NXP_SAM.UI.ISLOG.Domain;
using Leosac.KeyManager.Library.Plugin;
using Leosac.KeyManager.Library.Plugin.UI.Domain;
using System.Windows.Controls;

namespace Leosac.KeyManager.Library.KeyStore.NXP_SAM.UI.ISLOG
{
public class ISLOGKeyStoreUIFactory : KeyStoreUIFactory
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod()?.DeclaringType);

public ISLOGKeyStoreUIFactory()
{
targetFactory = new ISLOGKeyStoreFactory();
}

public override string Name => "ISLOG SAM Manager Template";

public override Type GetPropertiesType()
{
return typeof(ISLOGKeyStoreProperties);
}

public override UserControl CreateKeyStorePropertiesControl()
{
return new ISLOGKeyStorePropertiesControl();
}

public override KeyStorePropertiesControlViewModel? CreateKeyStorePropertiesControlViewModel()
{
try
{
return new ISLOGKeyStorePropertiesControlViewModel();
}
catch (Exception ex)
{
log.Error("Error when initializing the key store view model", ex);
return null;
}
}

public override IDictionary<string, UserControl> CreateKeyStoreAdditionalControls()
{
return new Dictionary<string, UserControl>();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
<data name="AutoSwitchToAV2" xml:space="preserve">
<value>Basculer automatiquement la SAM vers le mode AV2 si nécessaire lors de modifications</value>
</data>
<data name="Browse" xml:space="preserve">
<value>Parcourir</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>Annuler</value>
</data>
Expand Down Expand Up @@ -210,6 +213,12 @@
<data name="GetSAMVersion" xml:space="preserve">
<value>Afficher la version de la SAM</value>
</data>
<data name="ISLOGTemplateFile" xml:space="preserve">
<value>Fichier Modèle</value>
</data>
<data name="ISLOGTemplateFileHelper" xml:space="preserve">
<value>Fichier Modèle XML créé avec ISLOG SAM Manager</value>
</data>
<data name="KeepIV" xml:space="preserve">
<value>Conserver l'IV</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
<data name="AutoSwitchToAV2" xml:space="preserve">
<value>Automatically switch the SAM to AV2 mode if required when performing updates</value>
</data>
<data name="Browse" xml:space="preserve">
<value>Browse</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>Cancel</value>
</data>
Expand Down Expand Up @@ -210,6 +213,12 @@
<data name="GetSAMVersion" xml:space="preserve">
<value>Show SAM Version</value>
</data>
<data name="ISLOGTemplateFile" xml:space="preserve">
<value>Template File</value>
</data>
<data name="ISLOGTemplateFileHelper" xml:space="preserve">
<value>XML Template File created with ISLOG SAM Manager</value>
</data>
<data name="KeepIV" xml:space="preserve">
<value>Keep IV</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ public override UserControl CreateKeyStorePropertiesControl()

public override IDictionary<string, UserControl> CreateKeyStoreAdditionalControls()
{
var controls = new Dictionary<string, UserControl>();
controls.Add("Key Usage Counters", new SAMKeyStoreKeyCounterControl());
controls.Add("Tools", new SAMKeyStoreToolsControl());
var controls = new Dictionary<string, UserControl>
{
{ "Key Usage Counters", new SAMKeyStoreKeyCounterControl() },
{ "Tools", new SAMKeyStoreToolsControl() }
};
return controls;
}
}
Expand Down
Loading

0 comments on commit ef39b55

Please sign in to comment.