From 9aa492d86eeb3dfb1772400cb6233a1a45f790fc Mon Sep 17 00:00:00 2001 From: C3rebro Date: Tue, 16 Mar 2021 20:18:19 +0100 Subject: [PATCH] add "Encryption Type" to rfiddevice + add: show encryption settings when available --- RFiDGear/DataAccessLayer/RFiDDevice.cs | 60 +++++++++++++++++++++----- RFiDGear/RFiDGear.csproj | 36 ++++++++++++++++ RFiDGear/app.config | 8 ++-- RFiDGear/packages.config | 5 +++ 4 files changed, 94 insertions(+), 15 deletions(-) diff --git a/RFiDGear/DataAccessLayer/RFiDDevice.cs b/RFiDGear/DataAccessLayer/RFiDDevice.cs index c7d66d4..05114a9 100644 --- a/RFiDGear/DataAccessLayer/RFiDDevice.cs +++ b/RFiDGear/DataAccessLayer/RFiDDevice.cs @@ -52,6 +52,8 @@ public class RFiDDevice : IDisposable public byte MaxNumberOfAppKeys { get; private set; } + public byte EncryptionType { get; private set; } + public uint FreeMemory { get; private set; } public FileSetting DesfireFileSetting { get; private set; } @@ -963,8 +965,34 @@ public ERROR CreateMifareDesfireFile(string _appMasterKey, DESFireKeyType _keyTy cmd.CreateLinearRecordFile((byte)_fileNo, _encMode, accessRights, (uint)_fileSize, (uint)_maxNbOfRecords); break; } + + return ERROR.NoError; } + switch (_fileType) + { + case FileType_MifareDesfireFileType.StdDataFile: + cmd.CreateStdDataFile((byte)_fileNo, _encMode, accessRights, (uint)_fileSize); + break; + + case FileType_MifareDesfireFileType.BackupFile: + cmd.CreateBackupFile((byte)_fileNo, _encMode, accessRights, (uint)_fileSize); + break; + + case FileType_MifareDesfireFileType.ValueFile: + cmd.CreateValueFile((byte)_fileNo, _encMode, accessRights, (uint)_minValue, (uint)_maxValue, (uint)_initValue, _isValueLimited); + break; + + case FileType_MifareDesfireFileType.CyclicRecordFile: + cmd.CreateCyclicRecordFile((byte)_fileNo, _encMode, accessRights, (uint)_fileSize, (uint)_maxNbOfRecords); + break; + + case FileType_MifareDesfireFileType.LinearRecordFile: + cmd.CreateLinearRecordFile((byte)_fileNo, _encMode, accessRights, (uint)_fileSize, (uint)_maxNbOfRecords); + break; + } + + return ERROR.NoError; } catch @@ -1239,7 +1267,7 @@ public ERROR GetMifareDesfireAppSettings(string _applicationMasterKey, DESFireKe if (card.Type == "DESFire" || card.Type == "DESFireEV1" || - card.Type == "DESFireEV2") + card.Type == "DESFireEV2" || card.Type == "GENERIC_T_CL_A") { var cmd = card.Commands as IDESFireCommands; @@ -1255,7 +1283,8 @@ public ERROR GetMifareDesfireAppSettings(string _applicationMasterKey, DESFireKe try { cmd.GetKeySettings(out keySettings, out maxNbrOfKeys); - MaxNumberOfAppKeys = maxNbrOfKeys; + MaxNumberOfAppKeys = (byte)(maxNbrOfKeys & 0x0F); + EncryptionType = (byte)(maxNbrOfKeys & 0xF0); DesfireAppKeySetting = keySettings; return ERROR.NoError; @@ -1266,7 +1295,8 @@ public ERROR GetMifareDesfireAppSettings(string _applicationMasterKey, DESFireKe } } cmd.GetKeySettings(out keySettings, out maxNbrOfKeys); - MaxNumberOfAppKeys = maxNbrOfKeys; + MaxNumberOfAppKeys = (byte)(maxNbrOfKeys & 0x0F); + EncryptionType = (byte)(maxNbrOfKeys & 0xF0); DesfireAppKeySetting = keySettings; return ERROR.NoError; @@ -1472,15 +1502,23 @@ public ERROR ChangeMifareDesfireApplicationKey(string _applicationMasterKeyCurre return ERROR.NoError; } - catch (Exception e) + catch { - if (e.Message != "" && e.Message.Contains("status does not allow the requested command")) - { - return ERROR.NotAllowed; - } - else - return ERROR.AuthenticationError; - } + try + { + cmd.Authenticate((byte)_keyNumberCurrent, aiToUse.MasterApplicationKey); + cmd.ChangeKey((byte)_keyNumberTarget, applicationMasterKeyTarget); + } + catch (Exception e) + { + if (e.Message != "" && e.Message.Contains("status does not allow the requested command")) + { + return ERROR.NotAllowed; + } + else + return ERROR.AuthenticationError; + } + } } } diff --git a/RFiDGear/RFiDGear.csproj b/RFiDGear/RFiDGear.csproj index b4fc737..c8f3a1c 100644 --- a/RFiDGear/RFiDGear.csproj +++ b/RFiDGear/RFiDGear.csproj @@ -54,6 +54,15 @@ Project + + ..\packages\Portable.BouncyCastle.1.8.9\lib\net40\BouncyCastle.Crypto.dll + + + ..\packages\Common.Logging.3.4.1\lib\net40\Common.Logging.dll + + + ..\packages\Common.Logging.Core.3.4.1\lib\net40\Common.Logging.Core.dll + ..\packages\CommonServiceLocator.2.0.2\lib\net45\CommonServiceLocator.dll @@ -64,6 +73,33 @@ ..\packages\DotNetZip.Reduced.1.9.1.8\lib\net20\Ionic.Zip.Reduced.dll True + + ..\packages\itext7.7.1.14\lib\net40\itext.barcodes.dll + + + ..\packages\itext7.7.1.14\lib\net40\itext.forms.dll + + + ..\packages\itext7.7.1.14\lib\net40\itext.io.dll + + + ..\packages\itext7.7.1.14\lib\net40\itext.kernel.dll + + + ..\packages\itext7.7.1.14\lib\net40\itext.layout.dll + + + ..\packages\itext7.7.1.14\lib\net40\itext.pdfa.dll + + + ..\packages\itext7.7.1.14\lib\net40\itext.sign.dll + + + ..\packages\itext7.7.1.14\lib\net40\itext.styledxmlparser.dll + + + ..\packages\itext7.7.1.14\lib\net40\itext.svg.dll + 4.0 diff --git a/RFiDGear/app.config b/RFiDGear/app.config index a26fe11..89168e0 100644 --- a/RFiDGear/app.config +++ b/RFiDGear/app.config @@ -1,8 +1,8 @@ - - - + + + @@ -11,4 +11,4 @@ - + \ No newline at end of file diff --git a/RFiDGear/packages.config b/RFiDGear/packages.config index 804b35f..d0d6b9c 100644 --- a/RFiDGear/packages.config +++ b/RFiDGear/packages.config @@ -1,6 +1,11 @@  + + + + + \ No newline at end of file