Skip to content

Commit

Permalink
Fix update of 3K3DES SAM Key Entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxhy committed Oct 23, 2023
1 parent 9069615 commit bfd3924
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions KeyManager.Library.KeyStore.NXP_SAM/SAMKeyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ public override Task Update(IChangeKeyEntry change, bool ignoreIfMissing)
}

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

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

if (samkey.SAMProperties != null)
Expand All @@ -410,8 +409,20 @@ public override Task Update(IChangeKeyEntry change, bool ignoreIfMissing)
infoav2.ExtSET |= (byte)(Convert.ToByte(samkey.SAMProperties.AllowDumpSecretKey) << 3);
infoav2.ExtSET |= (byte)(Convert.ToByte(samkey.SAMProperties.AllowDumpSecretKeyWithDiv) << 4);
}

var updateSettings = new LibLogicalAccess.Card.KeyEntryUpdateSettings();
updateSettings.df_aid_keyno = 1;
updateSettings.key_no_v_cek = 1;
updateSettings.refkeykuc = 1;
updateSettings.keyversionsentseparatly = 1;
updateSettings.updateset = 1;

if (samkey.Variant != null)
{
updateSettings.keyVa = 1;
updateSettings.keyVb = 1;
updateSettings.keyVc = 1;

var keyVersions = samkey.Variant.KeyContainers.OfType<KeyVersion>().ToArray();
var keys = new LibLogicalAccess.UCharCollectionCollection(keyVersions.Length);
foreach (var keyversion in samkey.Variant.KeyContainers)
Expand Down Expand Up @@ -450,6 +461,7 @@ public override Task Update(IChangeKeyEntry change, bool ignoreIfMissing)
else
{
natkey.setKeysData(keys, LibLogicalAccess.Card.SAMKeyType.SAM_KEY_3K3DES);
updateSettings.keyVc = 0;
}
}
}
Expand All @@ -476,7 +488,7 @@ public override Task Update(IChangeKeyEntry change, bool ignoreIfMissing)
natkey.setSETKeyTypeFromKeyType();

av2cmd.authenticateHost(key, GetSAMProperties().AuthenticateKeyEntryIdentifier);
natkey.setUpdateMask(0xFF);
natkey.setUpdateSettings(updateSettings); // Or call setUpdateMask
av2cmd.changeKeyEntry((byte)Convert.ToDecimal(samkey.Identifier.Id), natkey, key);
}
else
Expand Down

0 comments on commit bfd3924

Please sign in to comment.