Added: Card Actions in Test

This commit is contained in:
TheJoKlLa
2020-09-26 18:02:44 +02:00
parent 04a41322e6
commit b9708da234
12 changed files with 377 additions and 126 deletions

View File

@ -0,0 +1,8 @@
namespace NFC.Mifare_DESFire.Enums
{
public enum AccessRights : byte
{
FREE = 0x0E,
NEVER = 0x0F
}
}

View File

@ -0,0 +1,21 @@
namespace NFC.Mifare_DESFire.Enums
{
/// <summary>
/// hold the Access Rights for changing application keys (Change Key command)
/// </summary>
public enum ChangeApplicationKey : byte
{
/// <summary>
/// Application master key authentication is necessary to change any key (default)
/// </summary>
MASTERKEY = 0x00,
/// <summary>
/// Authentication with the key to be changed (same Key#) is necessary to change a key
/// </summary>
SAMEKEY = 0x0E,
/// <summary>
/// All keys (except application master key, see Bit 0) within this application are frozen
/// </summary>
ALLKEYS = 0x0F
}
}

View File

@ -0,0 +1,18 @@
namespace NFC.Mifare_DESFire.Enums
{
/// <summary>
/// codes whether the application master key is changeable
/// </summary>
public enum ChangeMasterKey : byte
{
/// <summary>
/// Application master key is not changeable anymore (frozen)
/// </summary>
FROZEN = 0x00,
/// <summary>
/// Application master key is changeable (authentication with the current application master key necessary, default)
/// </summary>
CHANGEABLE = 0x01,
}
}

View File

@ -0,0 +1,19 @@
namespace NFC.Mifare_DESFire.Enums
{
/// <summary>
/// codes whether a change of the application master key settings is allowed
/// </summary>
public enum ChangeMasterKeySettings : byte
{
/// <summary>
/// configuration not changeable anymore (frozen)
/// </summary>
FROZEN = 0x00,
/// <summary>
/// this configuration is changeable if authenticated with the application master key (default)
/// </summary>
WITHMASTERKEY = 0x08
}
}

View File

@ -0,0 +1,18 @@
namespace NFC.Mifare_DESFire.Enums
{
/// <summary>
/// codes whether application master key authentication is needed before “Create File” / “Delete File”
/// </summary>
public enum CreateDeleteFile : byte
{
/// <summary>
/// “Create File”/ “Delete File”is permitted only with application master key authentication
/// </summary>
ONLYMASTERKEY = 0x00,
/// <summary>
/// “Create File”/ “Delete File”is permitted also without application master key authentication (default)
/// </summary>
NOKEY = 0x04,
}
}

View File

@ -0,0 +1,12 @@
namespace NFC.Mifare_DESFire.Enums
{
/// <summary>
/// Crypto method of the application
/// </summary>
public enum CryptoOperationsType : byte
{
TDES = 0x00,
TKTDES = 0x40,
AES = 0x80,
}
}

View File

@ -1,6 +1,6 @@
namespace NFC.Mifare_DESFire
namespace NFC.Mifare_DESFire.Enums
{
enum FileCommunication : byte
public enum FileCommunication : byte
{
/// <summary>
/// "Plain communication"

View File

@ -0,0 +1,18 @@
namespace NFC.Mifare_DESFire.Enums
{
/// <summary>
/// codes whether application master key authentication is needed for file directory access
/// </summary>
public enum FileDirectoryAccess : byte
{
/// <summary>
/// Successful application master key authentication is required for executing the “Get FID List”, “Get File Settings”and “Get Key Settings”commands
/// </summary>
ONLYMASTERKEY = 0x00,
/// <summary>
/// “Get FID List”, “Get File Settings” and “Get Key Settings” commands succeed independentlyof a preceding application master key authentication (default)
/// </summary>
NOKEY = 0x02,
}
}

View File

@ -0,0 +1,11 @@
namespace NFC.Mifare_DESFire.Enums
{
/// <summary>
/// Indicates use of 2 byte ISO/IEC 7816-4 File Identifies for files within the Application
/// </summary>
public enum FileIdentifies : byte
{
NOTUSED = 0x00,
USED = 0x20
}
}

View File

@ -1,4 +1,5 @@
using PCSC.Iso7816;
using NFC.Mifare_DESFire.Enums;
using PCSC.Iso7816;
using System;
using System.Collections.Generic;
using System.Text;
@ -7,6 +8,13 @@ namespace NFC.Mifare_DESFire
{
public class MifareDESFire
{
private ICard _Card;
public MifareDESFire(ICard card)
{
_Card = card;
}
/// <summary>
/// Create new Application with AID
/// </summary>
@ -46,6 +54,16 @@ namespace NFC.Mifare_DESFire
return applicationIDs.ToArray();
}
public void Format()
{
throw new NotImplementedException();
}
public void Authenticate(int v, byte[] aPP_MasterKey)
{
throw new NotImplementedException();
}
/// <summary>
/// Select Application by ID
/// </summary>
@ -70,20 +88,9 @@ namespace NFC.Mifare_DESFire
return cmd;
}
public APDUCommand Authenticate_GetChallenge(byte keyid)
public void ChangeApplicationMasterKey(byte[] aPP_MasterKey)
{
APDUCommand cmd = new APDUCommand(IsoCase.Case4Short)
{
CLA = 0x90,
INS = (byte)APDUInstructions.,
Data = new byte[]
{
id_byte[0],
id_byte[1],
id_byte[2]
},
Le = 0x00
};
throw new NotImplementedException();
}
/// <summary>
@ -110,6 +117,11 @@ namespace NFC.Mifare_DESFire
return cmd;
}
public void ChangeApplicationKey(int v, byte[] aPP_Key_1)
{
throw new NotImplementedException();
}
/// <summary>
/// Select Application by ID
/// </summary>
@ -136,6 +148,31 @@ namespace NFC.Mifare_DESFire
return cmd;
}
public void CreateFile(byte fabAccessIdentFileID, FileCommunication pLAIN, ushort fileAccessRight, int v)
{
throw new NotImplementedException();
}
public ushort GenerateFileAccessRight(AccessRights fREE, int v1, int v2, int v3)
{
throw new NotImplementedException();
}
public void WirteData(byte fabAccessIdentFileID, int v1, int v2, byte[] vs)
{
throw new NotImplementedException();
}
public void CreateFile(byte fabAccessIdentFileID, object plain, AccessRights fREE, int v1, int v2, int v3)
{
throw new NotImplementedException();
}
public byte[] ReadData(byte identFileID, int v1, int v2)
{
throw new NotImplementedException();
}
/// <summary>
/// Genearte KeySetting1 for Application Settings or PICC Setting
/// </summary>
@ -163,7 +200,7 @@ namespace NFC.Mifare_DESFire
/// </summary>
/// <param name="numberOfKeys">Number of keys that can be stored within the application (0x01-0x0D)</param>
/// <returns></returns>
public byte GenerateKeySetting2(CryptoOperations cryptoOperations, FileIdentifies fileIdentifies, byte numberOfKeys)
public byte GenerateKeySetting2(CryptoOperationsType cryptoOperations, FileIdentifies fileIdentifies, byte numberOfKeys)
{
if(numberOfKeys < 0x01 || numberOfKeys >= 0x0D)
{
@ -172,108 +209,5 @@ namespace NFC.Mifare_DESFire
return (byte)((byte)cryptoOperations | (byte)fileIdentifies | numberOfKeys);
}
/// <summary>
/// Crypto method of the application
/// </summary>
public enum CryptoOperations : byte
{
TDES = 0x00,
TKTDES = 0x40,
AES = 0x80,
}
/// <summary>
/// Indicates use of 2 byte ISO/IEC 7816-4 File Identifies for files within the Application
/// </summary>
public enum FileIdentifies : byte
{
NOTUSED = 0x00,
USED = 0x20
}
/// <summary>
/// hold the Access Rights for changing application keys (Change Key command)
/// </summary>
public enum ChangeApplicationKey : byte
{
/// <summary>
/// Application master key authentication is necessary to change any key (default)
/// </summary>
MASTERKEY = 0x00,
/// <summary>
/// Authentication with the key to be changed (same Key#) is necessary to change a key
/// </summary>
SAMEKEY = 0x0E,
/// <summary>
/// All keys (except application master key, see Bit 0) within this application are frozen
/// </summary>
ALLKEYS = 0x0F
}
/// <summary>
/// codes whether a change of the application master key settings is allowed
/// </summary>
public enum ChangeMasterKeySettings : byte
{
/// <summary>
/// configuration not changeable anymore (frozen)
/// </summary>
FROZEN = 0x00,
/// <summary>
/// this configuration is changeable if authenticated with the application master key (default)
/// </summary>
WITHMASTERKEY = 0x08
}
/// <summary>
/// codes whether application master key authentication is needed before “Create File” / “Delete File”
/// </summary>
public enum CreateDeleteFile : byte
{
/// <summary>
/// “Create File”/ “Delete File”is permitted only with application master key authentication
/// </summary>
ONLYMASTERKEY = 0x00,
/// <summary>
/// “Create File”/ “Delete File”is permitted also without application master key authentication (default)
/// </summary>
NOKEY = 0x04,
}
/// <summary>
/// codes whether application master key authentication is needed for file directory access
/// </summary>
public enum FileDirectoryAccess : byte
{
/// <summary>
/// Successful application master key authentication is required for executing the “Get FID List”, “Get File Settings”and “Get Key Settings”commands
/// </summary>
ONLYMASTERKEY = 0x00,
/// <summary>
/// “Get FID List”, “Get File Settings” and “Get Key Settings” commands succeed independentlyof a preceding application master key authentication (default)
/// </summary>
NOKEY = 0x02,
}
/// <summary>
/// codes whether the application master key is changeable
/// </summary>
public enum ChangeMasterKey : byte
{
/// <summary>
/// Application master key is not changeable anymore (frozen)
/// </summary>
FROZEN = 0x00,
/// <summary>
/// Application master key is changeable (authentication with the current application master key necessary, default)
/// </summary>
CHANGEABLE = 0x01,
}
}
}