Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
Add targetKeyIdentifier parameter to key store update
  • Loading branch information
Maxhy committed Aug 22, 2024
1 parent b821e9d commit 6f1ecd9
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 32 deletions.
2 changes: 1 addition & 1 deletion KeyManager.Library.KeyStore.HSM_PKCS11/PKCS11KeyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ public override Task Open()
return Task.CompletedTask;
}

public override async Task<string?> ResolveKeyEntryLink(KeyEntryId keyIdentifier, KeyEntryClass keClass, string? divInput, WrappingKey? wrappingKey)
public override async Task<string?> ResolveKeyEntryLink(KeyEntryId keyIdentifier, KeyEntryClass keClass, string? divInput, WrappingKey? wrappingKey, KeyEntryId? targetKeyIdentifier)
{
log.Info(string.Format("Resolving key entry link with Key Entry Identifier `{0}` and Wrapping Key Entry Identifier `{1}`...", keyIdentifier, wrappingKey?.KeyId));
if (wrappingKey == null || !wrappingKey.KeyId.IsConfigured())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Leosac.WpfApp" Version="1.21.1">
<PackageReference Include="Leosac.WpfApp" Version="1.22.0">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="MaterialDesignThemes" Version="4.9.0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Leosac.CredentialProvisioning.API" Version="1.9.0" />
<PackageReference Include="Leosac.CredentialProvisioning.API" Version="1.11.0" />
<PackageReference Include="log4net" Version="2.0.17">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="Refit" Version="7.1.1" />
<PackageReference Include="Refit.HttpClientFactory" Version="7.1.1" />
<PackageReference Include="Refit" Version="7.1.2" />
<PackageReference Include="Refit.HttpClientFactory" Version="7.1.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.2" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Leosac.WpfApp" Version="1.21.1">
<PackageReference Include="Leosac.WpfApp" Version="1.22.0">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="MaterialDesignThemes" Version="4.9.0">
Expand Down
54 changes: 40 additions & 14 deletions KeyManager.Library.KeyStore.NXP_SAM/SAMKeyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,23 +407,23 @@ public override Task Update(IChangeKeyEntry change, bool ignoreIfMissing)
{
log.Info(string.Format("Updating key entry `{0}`...", change.Identifier));

var key = new LibLogicalAccess.Card.DESFireKey();
key.setKeyType(LibLogicalAccess.Card.DESFireKeyType.DF_KEY_AES);
key.setKeyVersion(GetSAMProperties().AuthenticateKeyVersion);
if (!string.IsNullOrEmpty(Properties?.Secret))
{
key.fromString(KeyMaterial.GetValueAsString(Properties.Secret, KeyValueStringFormat.HexStringWithSpace));
}
else
{
key.fromString("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");
}

if (change is SAMSymmetricKeyEntry samkey)
{
var cmd = Chip?.getCommands();
if (cmd is LibLogicalAccess.Reader.SAMAV2ISO7816Commands av2cmd)
{
var key = new LibLogicalAccess.Card.DESFireKey();
key.setKeyType(LibLogicalAccess.Card.DESFireKeyType.DF_KEY_AES);
key.setKeyVersion(GetSAMProperties().AuthenticateKeyVersion);
if (!string.IsNullOrEmpty(Properties?.Secret))
{
key.fromString(KeyMaterial.GetValueAsString(Properties.Secret, KeyValueStringFormat.HexStringWithSpace));
}
else
{
key.fromString("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");
}

var natkey = new LibLogicalAccess.Card.AV2SAMKeyEntry();
var infoav2 = new LibLogicalAccess.Card.KeyEntryAV2Information();

Expand Down Expand Up @@ -561,6 +561,17 @@ public override Task Update(IChangeKeyEntry change, bool ignoreIfMissing)
throw new KeyStoreException("Inserted SAM is not in AV2 mode, AV1 support has been deprecated, please check to option to auto switch to AV2 or manually perform a Switch.");
}
}
else if (change is KeyEntryCryptogram cryptogram)
{
var cmd = Chip?.getCommands();
if (cmd is LibLogicalAccess.Reader.SAMAV2ISO7816Commands av2cmd)
{
av2cmd.authenticateHost(key, GetSAMProperties().AuthenticateKeyEntryIdentifier);
//av2cmd.activateOfflineKey();
//av2cmd.changeKeyEntryOffline();
throw new NotImplementedException();
}
}
else
{
log.Error("Unsupported Key Entry type for this Key Store.");
Expand Down Expand Up @@ -746,7 +757,7 @@ public void UpdateCounter(SAMKeyUsageCounter counter)
log.Info(string.Format("Key usage counter `{0}` updated.", counter.Identifier));
}

public override Task<string?> ResolveKeyEntryLink(KeyEntryId keyIdentifier, KeyEntryClass keClass, string? divInput, WrappingKey? wrappingKey)
public override Task<string?> ResolveKeyEntryLink(KeyEntryId keyIdentifier, KeyEntryClass keClass, string? divInput, WrappingKey? wrappingKey, KeyEntryId? targetKeyIdentifier)
{
log.Info(string.Format("Resolving key entry link with Key Entry Identifier `{0}` and Wrapping Key Entry Identifier `{1}`...", keyIdentifier, wrappingKey?.KeyId));
if (wrappingKey == null || !wrappingKey.KeyId.IsConfigured())
Expand All @@ -765,8 +776,23 @@ public void UpdateCounter(SAMKeyUsageCounter counter)
}

byte entry = byte.Parse(keyIdentifier.Id!);
byte targetEntry = entry;
if (targetKeyIdentifier != null)
{
targetEntry = byte.Parse(targetKeyIdentifier.Id!);
}

byte[] div;
if (!string.IsNullOrEmpty(divInput))
{
div = Convert.FromHexString(divInput);
}
else
{
div = Array.Empty<byte>();
}

var keyCipheredVector = av3cmd.encipherKeyEntry(entry, entry, wrappingKey.ChangeCounter ?? 0);
var keyCipheredVector = av3cmd.encipherKeyEntry(entry, targetEntry, wrappingKey.ChangeCounter ?? 0, 0x00, [], new ByteVector(div));
log.Info("Key link completed.");
return Task.FromResult<string?>(Convert.ToHexString(keyCipheredVector.ToArray()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Leosac.WpfApp" Version="1.21.1">
<PackageReference Include="Leosac.WpfApp" Version="1.22.0">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="MaterialDesignThemes" Version="4.9.0">
Expand Down
6 changes: 3 additions & 3 deletions KeyManager.Library.Tests/KeyManager.Library.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.2" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override async Task RunLinkImpl(KeyStore.KeyStore ks)
{
if (KeyEntryLink != null)
{
LinkResult = await ks.ResolveKeyEntryLink(KeyEntryLink.KeyIdentifier, Class, DivInputResult, KeyEntryLink.WrappingKey);
LinkResult = await ks.ResolveKeyEntryLink(KeyEntryLink.KeyIdentifier, Class, DivInputResult, KeyEntryLink.WrappingKey, null);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion KeyManager.Library.UI/KeyManager.Library.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Leosac.WpfApp" Version="1.21.1" />
<PackageReference Include="Leosac.WpfApp" Version="1.22.0" />
<PackageReference Include="MaterialDesignThemes" Version="4.9.0" />
<PackageReference Include="Net.Codecrete.QrCodeGenerator" Version="2.0.5" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down
5 changes: 3 additions & 2 deletions KeyManager.Library/KeyStore/KeyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ protected virtual async Task KeyEntriesAction(KeyStore store, Func<string, KeySt
KeyStore = ks,
KeyEntry = entry
};
cryptogram.Value = await ks.ResolveKeyEntryLink(entry.Link.KeyIdentifier.Clone(resolveVariables ? Attributes : null), keClass, ComputeDivInput(divContext, entry.Link.DivInput), entry.Link.WrappingKey);
cryptogram.Value = await ks.ResolveKeyEntryLink(entry.Link.KeyIdentifier.Clone(resolveVariables ? Attributes : null), keClass, ComputeDivInput(divContext, entry.Link.DivInput), entry.Link.WrappingKey, entry.Identifier);
}
finally
{
Expand Down Expand Up @@ -685,8 +685,9 @@ protected void OnUserMessageNotified(string message)
/// <param name="keClass">The key entry class</param>
/// <param name="divInput">The key div input (optional)</param>
/// <param name="wrappingKey">The wrapping key for cryptogram computation (optional)</param>
/// <param name="targetKeyIdentifier">The key identifier on targeted key store (optional)</param>
/// <returns>The change key entry cryptogram</returns>
public virtual async Task<string?> ResolveKeyEntryLink(KeyEntryId keyIdentifier, KeyEntryClass keClass, string? divInput, WrappingKey? wrappingKey)
public virtual async Task<string?> ResolveKeyEntryLink(KeyEntryId keyIdentifier, KeyEntryClass keClass, string? divInput, WrappingKey? wrappingKey, KeyEntryId? targetKeyIdentifier)
{
string? result = null;
log.Info(string.Format("Resolving key entry link with Key Entry Identifier `{0}`, Div Input `{1}`...", keyIdentifier, divInput));
Expand Down
2 changes: 1 addition & 1 deletion KeyManager/KeyManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Leosac.WpfApp" Version="1.21.1" />
<PackageReference Include="Leosac.WpfApp" Version="1.22.0" />
<PackageReference Include="log4net" Version="2.0.17" />
<PackageReference Include="MaterialDesignThemes" Version="4.9.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down

0 comments on commit 6f1ecd9

Please sign in to comment.