Skip to content

Commit 1f8db8a

Browse files
committed
Fix div input calculation during key link resolving
1 parent 566c080 commit 1f8db8a

13 files changed

+150
-197
lines changed

KeyManager.Library.KeyStore.NXP_SAM/SAMKeyStore.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using LibLogicalAccess;
1+
using Leosac.KeyManager.Library.Crypto;
2+
using LibLogicalAccess;
23

34
namespace Leosac.KeyManager.Library.KeyStore.NXP_SAM
45
{
@@ -669,26 +670,25 @@ public LibLogicalAccess.Card.DESFireKey GetAuthenticationKey()
669670
key.setKeyVersion(GetSAMProperties().AuthenticateKeyVersion);
670671
if (!string.IsNullOrEmpty(Properties?.Secret))
671672
{
672-
key.fromString(KeyMaterial.GetValueAsString(Properties.Secret, KeyValueStringFormat.HexStringWithSpace));
673+
var kv = Properties.Secret;
674+
if (GetSAMProperties().AuthenticationDivInput.Count > 0)
675+
{
676+
var divContext = new DivInput.DivInputContext
677+
{
678+
KeyStore = this
679+
};
680+
var input = ComputeDivInput(divContext, GetSAMProperties().AuthenticationDivInput);
681+
if (!string.IsNullOrEmpty(input))
682+
{
683+
kv = AN10922KeyDiversification.Diversify(kv, input);
684+
}
685+
}
686+
key.fromString(KeyMaterial.GetValueAsString(kv, KeyValueStringFormat.HexStringWithSpace));
673687
}
674688
else
675689
{
676690
key.fromString("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");
677691
}
678-
if (GetSAMProperties().AuthenticationDivInput.Count > 0)
679-
{
680-
var divContext = new DivInput.DivInputContext
681-
{
682-
KeyStore = this
683-
};
684-
var div = new LibLogicalAccess.Card.NXPAV2KeyDiversification();
685-
var input = ComputeDivInput(divContext, GetSAMProperties().AuthenticationDivInput);
686-
if (!string.IsNullOrEmpty(input))
687-
{
688-
div.setDivInput([.. Convert.FromHexString(input)]);
689-
key.setKeyDiversification(div);
690-
}
691-
}
692692
return key;
693693
}
694694

KeyManager.Library.UI/DivInputTestControl.xaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

KeyManager.Library.UI/DivInputTestControl.xaml.cs

Lines changed: 0 additions & 50 deletions
This file was deleted.

KeyManager.Library.UI/Domain/KeyEntriesControlViewModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ protected KeyEntryDialogViewModel CreateKeyEntryDialogViewModel()
234234
protected KeyEntryDialogViewModel CreateKeyEntryDialogViewModel(bool keClone)
235235
{
236236
var model = new KeyEntryDialogViewModel(KeyEntryClass);
237+
if (_keyStore != null)
238+
{
239+
LinkDialogViewModel.KeyStoreAttributes = _keyStore.Attributes;
240+
}
237241
model.SetKeyEntry(KeyStore?.GetDefaultKeyEntry(KeyEntryClass, keClone));
238242
model.ShowKeyEntryLabel = (KeyStore?.CanDefineKeyEntryLabel).GetValueOrDefault(true);
239243
return model;

KeyManager.Library.UI/Domain/KeyEntryLinkDialogViewModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ public override async Task RunLinkImpl(KeyStore.KeyStore ks)
1313
{
1414
if (KeyEntryLink != null)
1515
{
16-
LinkResult = await ks.ResolveKeyEntryLink(KeyEntryLink.KeyIdentifier, Class, DivInputResult, KeyEntryLink.WrappingKey, null);
16+
var divContext = new DivInput.DivInputContext
17+
{
18+
AdditionalKeyStoreAttributes = KeyStoreAttributes
19+
};
20+
LinkResult = await ks.ResolveKeyEntryLink(KeyEntryLink.KeyIdentifier, Class, KeyStore.KeyStore.ComputeDivInput(divContext, KeyEntryLink.DivInput), KeyEntryLink.WrappingKey, null);
1721
}
1822
}
1923
}

KeyManager.Library.UI/Domain/KeyLinkDialogViewModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ public override async Task RunLinkImpl(KeyStore.KeyStore ks)
2626
{
2727
if (KeyLink != null)
2828
{
29-
LinkResult = await ks.ResolveKeyLink(KeyLink.KeyIdentifier, Class, KeyLink.ContainerSelector, DivInputResult);
29+
var divContext = new DivInput.DivInputContext
30+
{
31+
AdditionalKeyStoreAttributes = KeyStoreAttributes
32+
};
33+
LinkResult = await ks.ResolveKeyLink(KeyLink.KeyIdentifier, Class, KeyLink.ContainerSelector, KeyStore.KeyStore.ComputeDivInput(divContext, KeyLink.DivInput));
3034
}
3135
}
3236
}

KeyManager.Library.UI/Domain/LinkDialogViewModel.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ protected LinkDialogViewModel()
2929
_class = KeyEntryClass.Symmetric;
3030
}
3131

32+
public static IDictionary<string, string>? KeyStoreAttributes { get; set; }
33+
3234
private Link? _link;
3335
public Link? Link
3436

@@ -59,13 +61,6 @@ public string? LinkError
5961
set => SetProperty(ref _linkError, value);
6062
}
6163

62-
private string? _divInputResult;
63-
public string? DivInputResult
64-
{
65-
get => _divInputResult;
66-
set => SetProperty(ref _divInputResult, value);
67-
}
68-
6964
private bool _allowImport;
7065

7166
public bool AllowImport

KeyManager.Library.UI/KeyEntryLinkDialog.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
<TextBlock Margin="5" VerticalAlignment="Center" Text="{x:Static properties:Resources.LinkError}" />
3030
<TextBlock Margin="5" VerticalAlignment="Center" Text="{Binding LinkError}" />
3131
</WrapPanel>
32-
<local:DivInputTestControl DivInput="{Binding Link.DivInput}" DivInputResult="{Binding DivInputResult}" />
3332
<StackPanel Margin="15" HorizontalAlignment="Center" Orientation="Horizontal">
3433
<Button Margin="5" VerticalAlignment="Center" Command="{x:Static materialDesign:DrawerHost.CloseDrawerCommand}" CommandParameter="{x:Static Dock.Bottom}" Content="{x:Static properties:Resources.CloseCaps}" Style="{StaticResource MaterialDesignFlatButton}" />
3534
</StackPanel>

KeyManager.Library.UI/KeyLinkDialog.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
<TextBlock Margin="5" VerticalAlignment="Center" Text="{x:Static properties:Resources.LinkError}" />
3535
<TextBlock Margin="5" VerticalAlignment="Center" Text="{Binding LinkError}" />
3636
</WrapPanel>
37-
<local:DivInputTestControl DivInput="{Binding Link.DivInput}" DivInputResult="{Binding DivInputResult}" />
3837
<StackPanel Margin="15" HorizontalAlignment="Center" Orientation="Horizontal">
3938
<Button Margin="5" VerticalAlignment="Center"
4039
Command="{Binding ImportResultCommand}"

KeyManager.Library/DivInput/DivInputContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public class DivInputContext
66

77
public KeyStore.KeyStore? KeyStore { get; set; }
88

9+
public IDictionary<string, string>? AdditionalKeyStoreAttributes { get; set; }
10+
911
public KeyStore.KeyEntry? KeyEntry { get; set; }
1012

1113
public KeyContainer? KeyContainer { get; set; }

0 commit comments

Comments
 (0)