Skip to content

Commit

Permalink
add "Encryption Type" to rfiddevice
Browse files Browse the repository at this point in the history
+ add: show encryption settings when available
  • Loading branch information
c3rebro committed Mar 16, 2021
1 parent 8ce2e57 commit 9aa492d
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 15 deletions.
60 changes: 49 additions & 11 deletions RFiDGear/DataAccessLayer/RFiDDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
}

Expand Down
36 changes: 36 additions & 0 deletions RFiDGear/RFiDGear.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
<StartAction>Project</StartAction>
</PropertyGroup>
<ItemGroup>
<Reference Include="BouncyCastle.Crypto, Version=1.8.9.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
<HintPath>..\packages\Portable.BouncyCastle.1.8.9\lib\net40\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="Common.Logging, Version=3.4.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<HintPath>..\packages\Common.Logging.3.4.1\lib\net40\Common.Logging.dll</HintPath>
</Reference>
<Reference Include="Common.Logging.Core, Version=3.4.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<HintPath>..\packages\Common.Logging.Core.3.4.1\lib\net40\Common.Logging.Core.dll</HintPath>
</Reference>
<Reference Include="CommonServiceLocator">
<HintPath>..\packages\CommonServiceLocator.2.0.2\lib\net45\CommonServiceLocator.dll</HintPath>
</Reference>
Expand All @@ -64,6 +73,33 @@
<HintPath>..\packages\DotNetZip.Reduced.1.9.1.8\lib\net20\Ionic.Zip.Reduced.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="itext.barcodes, Version=7.1.14.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca, processorArchitecture=MSIL">
<HintPath>..\packages\itext7.7.1.14\lib\net40\itext.barcodes.dll</HintPath>
</Reference>
<Reference Include="itext.forms, Version=7.1.14.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca, processorArchitecture=MSIL">
<HintPath>..\packages\itext7.7.1.14\lib\net40\itext.forms.dll</HintPath>
</Reference>
<Reference Include="itext.io, Version=7.1.14.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca, processorArchitecture=MSIL">
<HintPath>..\packages\itext7.7.1.14\lib\net40\itext.io.dll</HintPath>
</Reference>
<Reference Include="itext.kernel, Version=7.1.14.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca, processorArchitecture=MSIL">
<HintPath>..\packages\itext7.7.1.14\lib\net40\itext.kernel.dll</HintPath>
</Reference>
<Reference Include="itext.layout, Version=7.1.14.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca, processorArchitecture=MSIL">
<HintPath>..\packages\itext7.7.1.14\lib\net40\itext.layout.dll</HintPath>
</Reference>
<Reference Include="itext.pdfa, Version=7.1.14.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca, processorArchitecture=MSIL">
<HintPath>..\packages\itext7.7.1.14\lib\net40\itext.pdfa.dll</HintPath>
</Reference>
<Reference Include="itext.sign, Version=7.1.14.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca, processorArchitecture=MSIL">
<HintPath>..\packages\itext7.7.1.14\lib\net40\itext.sign.dll</HintPath>
</Reference>
<Reference Include="itext.styledxmlparser, Version=7.1.14.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca, processorArchitecture=MSIL">
<HintPath>..\packages\itext7.7.1.14\lib\net40\itext.styledxmlparser.dll</HintPath>
</Reference>
<Reference Include="itext.svg, Version=7.1.14.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca, processorArchitecture=MSIL">
<HintPath>..\packages\itext7.7.1.14\lib\net40\itext.svg.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
Expand Down
8 changes: 4 additions & 4 deletions RFiDGear/app.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
Expand All @@ -11,4 +11,4 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
</configuration>
5 changes: 5 additions & 0 deletions RFiDGear/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Common.Logging" version="3.4.1" targetFramework="net461" />
<package id="Common.Logging.Core" version="3.4.1" targetFramework="net461" />
<package id="CommonServiceLocator" version="2.0.2" targetFramework="net452" />
<package id="DotNetZip.Reduced" version="1.9.1.8" targetFramework="net452" />
<package id="itext7" version="7.1.14" targetFramework="net461" />
<package id="Microsoft.CSharp" version="4.0.1" targetFramework="net461" />
<package id="MvvmLightLibs" version="5.4.1" targetFramework="net452" />
<package id="Portable.BouncyCastle" version="1.8.9" targetFramework="net461" />
</packages>

0 comments on commit 9aa492d

Please sign in to comment.