Skip to content

Commit

Permalink
Better UI rendering of DESFire/SAM key types enums
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxhy committed May 23, 2024
1 parent b12aecd commit 43d6ce8
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Globalization;
using System.Windows.Data;

namespace Leosac.KeyManager.Library.KeyStore.NXP_SAM.UI.Domain
{
public class DESFireKeyTypeConverter : IValueConverter
{
public static string GetKeyTypeName(LibLogicalAccess.Card.DESFireKeyType keyType)
{
return keyType switch
{
LibLogicalAccess.Card.DESFireKeyType.DF_KEY_DES => "DES",
LibLogicalAccess.Card.DESFireKeyType.DF_KEY_3K3DES => "TK3DES",
_ => "AES128",
};
}

object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is LibLogicalAccess.Card.DESFireKeyType kt)
{
return GetKeyTypeName(kt);
}
return string.Empty;
}

object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return string.Empty;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Globalization;
using System.Windows.Data;

namespace Leosac.KeyManager.Library.KeyStore.NXP_SAM.UI.Domain
{
public class SAMKeyTypeConverter : IValueConverter
{
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is LibLogicalAccess.Card.SAMKeyType kt)
{
return SAMKeyStore.GetVariantName(kt);
}
return string.Empty;
}

object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return string.Empty;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
mc:Ignorable="d"
d:DataContext="{d:DesignInstance domain:SAMKeyStorePropertiesControlViewModel}"
d:DesignHeight="200" d:DesignWidth="500">
<UserControl.Resources>
<domain:DESFireKeyTypeConverter x:Key="DESFireKeyTypeConverter" />
</UserControl.Resources>
<StackPanel>
<local:LLAReaderControl ReaderProvider="{Binding SAMProperties.ReaderProvider, Mode=TwoWay}" ReaderUnit="{Binding SAMProperties.ReaderUnit, Mode=TwoWay}" />
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="5">
Expand All @@ -25,7 +28,13 @@
Hint="{x:Static properties:Resources.KeyEntryIdentifier}" Margin="5"/>
<ComboBox ItemsSource="{Binding KeyTypes}" SelectedItem="{Binding SAMProperties.AuthenticateKeyType}"
materialDesign:HintAssist.HelperText="{x:Static properties:Resources.KeyTypeHelper}"
materialDesign:HintAssist.Hint="{x:Static properties:Resources.KeyType}" Margin="5" />
materialDesign:HintAssist.Hint="{x:Static properties:Resources.KeyType}" Margin="5,5,5,15">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource DESFireKeyTypeConverter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<wpfappctrls:NumericUpDownControl MinValue="0" MaxValue="255" CurrentValue="{Binding SAMProperties.AuthenticateKeyVersion, Mode=TwoWay}"
HelperText="{x:Static properties:Resources.KeyVersionHelper}"
Hint="{x:Static properties:Resources.KeyVersion}" Margin="5"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<wpfappdomain:ByteArrayToStringConverter x:Key="ByteArrayToStringConverter" />
<domain:SAMKeyTypeConverter x:Key="SAMKeyTypeConverter" />
</UserControl.Resources>
<StackPanel Orientation="Vertical">
<materialDesign:Card Margin="5">
Expand All @@ -41,7 +42,13 @@
<libui:KeyContainerControl Grid.Row="1" DataContext="{Binding SAMAuthKey}" ShowKCV="False" ShowKeyLink="False" />
<ComboBox ItemsSource="{Binding KeyTypes}" SelectedItem="{Binding SAMAuthKeyType}" Grid.Row="2" Margin="0,10,0,0"
materialDesign:HintAssist.HelperText="{x:Static properties:Resources.KeyTypeHelper}"
materialDesign:HintAssist.Hint="{x:Static properties:Resources.KeyType}"/>
materialDesign:HintAssist.Hint="{x:Static properties:Resources.KeyType}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource SAMKeyTypeConverter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Button Content="{x:Static properties:Resources.Authenticate}" Command="{Binding SAMAuthCommand}" Grid.Row="3" Margin="0,30,0,0" Width="200" />
</Grid>
</StackPanel>
Expand Down
40 changes: 15 additions & 25 deletions KeyManager.Library.KeyStore.NXP_SAM/SAMKeyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,37 +322,27 @@ internal static void ParseKeyEntryProperties(LibLogicalAccess.Card.KeyEntryAV2In
private static SAMSymmetricKeyEntry CreateKeyEntryFromKeyType(LibLogicalAccess.Card.SAMKeyType keyType)
{
var keyEntry = new SAMSymmetricKeyEntry();
if (keyType == LibLogicalAccess.Card.SAMKeyType.SAM_KEY_DES)
{
keyEntry.SetVariant("DES");
}
else if (keyType == LibLogicalAccess.Card.SAMKeyType.SAM_KEY_AES128)
{
keyEntry.SetVariant("AES128");
}
else if (keyType == LibLogicalAccess.Card.SAMKeyType.SAM_KEY_AES192)
{
keyEntry.SetVariant("AES192");
}
else if (keyType == LibLogicalAccess.Card.SAMKeyType.SAM_KEY_AES256)
{
keyEntry.SetVariant("AES256");
}
else if (keyType == LibLogicalAccess.Card.SAMKeyType.SAM_KEY_MIFARE)
{
keyEntry.SetVariant("MIFARE");
}
else
{
keyEntry.SetVariant("TK3DES");
}
keyEntry.SetVariant(GetVariantName(keyType));
return keyEntry;
}

public static string GetVariantName(LibLogicalAccess.Card.SAMKeyType keyType)
{
return keyType switch
{
LibLogicalAccess.Card.SAMKeyType.SAM_KEY_DES => "DES",
LibLogicalAccess.Card.SAMKeyType.SAM_KEY_AES128 => "AES128",
LibLogicalAccess.Card.SAMKeyType.SAM_KEY_AES192 => "AES192",
LibLogicalAccess.Card.SAMKeyType.SAM_KEY_AES256 => "AES256",
LibLogicalAccess.Card.SAMKeyType.SAM_KEY_MIFARE => "MIFARE",
_ => "TK3DES",
};
}

public override Task<IList<KeyEntryId>> GetAll(KeyEntryClass? keClass)
{
log.Info(string.Format("Getting all key entries (class: `{0}`)...", keClass));
IList<KeyEntryId> entries = new List<KeyEntryId>();
IList<KeyEntryId> entries = [];
if (keClass == null || keClass == KeyEntryClass.Symmetric)
{
for (uint i = 0; i < SAM_AV2_MAX_SYMMETRIC_ENTRIES; ++i)
Expand Down
4 changes: 2 additions & 2 deletions latestversion
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"VersionString": "1.15.0",
"Uri": "https://download.leosac.com/lkm/KeyManager.Setup-1.15.0.msi"
"VersionString": "1.16.1",
"Uri": "https://download.leosac.com/lkm/KeyManager.Setup-1.16.1.msi"
}

0 comments on commit 43d6ce8

Please sign in to comment.