borepin/NFC_Test/REAL_Windows_CardSetUp.cs

192 lines
6.0 KiB
C#
Raw Normal View History

2020-09-26 18:02:44 +02:00
using NFC;
using NFC.Mifare_DESFire;
using NFC.Mifare_DESFire.Enums;
using NFC.Readers.PCSC;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
namespace NFC_Test
{
//[TestFixture]
//public class REAL_Windows_CardSetUp
//{
// public static UInt32 FabAccessAID = 0x001100;
// public static string CardReaderID = "ACS ACR122U PICC Interface 0";
// public static byte[] PICC_MasterKey = new byte[]
// {
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
// };
2020-09-26 18:02:44 +02:00
// public static byte[] APP_MasterKey = new byte[]
// {
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
// };
2020-09-26 18:02:44 +02:00
// public static byte[] APP_Key_1 = new byte[]
// {
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
// };
2020-09-26 18:02:44 +02:00
// public static byte[] APP_Key_2 = new byte[]
// {
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
// };
2020-09-26 18:02:44 +02:00
// public static byte[] Empty_Key = new byte[]
// {
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
// };
2020-09-26 18:02:44 +02:00
// public static byte FabAccessIdentFileID = 0x01;
// public static string UserDomain = "user1@fabaccess.org";
2020-09-26 18:02:44 +02:00
// [Test]
// public void ResetCard()
// {
// IHardware hardware = new Hardware();
// IReader reader = hardware.OpenReader(CardReaderID);
2020-09-26 18:02:44 +02:00
// bool connected_successfully = false;
2020-09-26 18:02:44 +02:00
// ReaderEventHandler handler = (sender, card) =>
// {
// card.Connect();
2020-09-26 18:02:44 +02:00
// MIFARE_DESFire mifareDESFire = new MIFARE_DESFire(card);
2020-09-26 18:02:44 +02:00
// mifareDESFire.AuthenticateISO_DES(0x01, PICC_MasterKey);
2020-09-26 18:02:44 +02:00
// mifareDESFire.Format();
2020-09-26 18:02:44 +02:00
// connected_successfully = true;
2020-09-26 18:02:44 +02:00
// card.Disconnect();
// };
2020-09-26 18:02:44 +02:00
// reader.CardDiscovered += handler;
// reader.Start();
2020-09-26 18:02:44 +02:00
// Assert.AreEqual(true, connected_successfully);
2020-09-26 18:02:44 +02:00
// reader.Stop();
// reader.CardDiscovered -= handler;
// }
2020-09-26 18:02:44 +02:00
// [Test]
// public void ProvisionCard()
// {
// IHardware hardware = new Hardware();
// IReader reader = hardware.OpenReader(CardReaderID);
2020-09-26 18:02:44 +02:00
// bool connected_successfully = false;
2020-09-26 18:02:44 +02:00
// ReaderEventHandler handler = (sender, card) =>
// {
// card.Connect();
2020-09-26 18:02:44 +02:00
// MIFARE_DESFire mifareDESFire = new MIFARE_DESFire(card);
2020-09-26 18:02:44 +02:00
// mifareDESFire.AuthenticateISO_DES(0x01, APP_MasterKey);
// mifareDESFire.CreateApplication(FabAccessAID);
// mifareDESFire.SelectApplication(FabAccessAID);
2020-09-26 18:02:44 +02:00
// mifareDESFire.AuthenticateDES(0x00, Empty_Key);
// mifareDESFire.ChangeApplicationMasterKey(APP_MasterKey);
2020-09-26 18:02:44 +02:00
// mifareDESFire.AuthenticateDES(0x00, APP_MasterKey);
// mifareDESFire.ChangeApplicationKey(0x01, APP_Key_1);
2020-09-26 18:02:44 +02:00
// connected_successfully = true;
2020-09-26 18:02:44 +02:00
// card.Disconnect();
// };
2020-09-26 18:02:44 +02:00
// reader.CardDiscovered += handler;
// reader.Start();
2020-09-26 18:02:44 +02:00
// Assert.AreEqual(true, connected_successfully);
2020-09-26 18:02:44 +02:00
// reader.Stop();
// reader.CardDiscovered -= handler;
// }
2020-09-26 18:02:44 +02:00
// [Test]
// public void SetUpUserCard()
// {
// IHardware hardware = new Hardware();
// IReader reader = hardware.OpenReader(CardReaderID);
2020-09-26 18:02:44 +02:00
// bool connected_successfully = false;
2020-09-26 18:02:44 +02:00
// ReaderEventHandler handler = (sender, card) =>
// {
// card.Connect();
2020-09-26 18:02:44 +02:00
// MIFARE_DESFire mifareDESFire = new MIFARE_DESFire(card);
2020-09-26 18:02:44 +02:00
// mifareDESFire.SelectApplication(FabAccessAID);
// mifareDESFire.AuthenticateDES(0x00, Empty_Key);
// UInt16 fileAccessRight = mifareDESFire.GenerateFileAccessRight(AccessRights.FREE, 0x00, 0x00, 0x00);
// mifareDESFire.CreateFile(FabAccessIdentFileID, FileCommunication.PLAIN, fileAccessRight, (UInt32)0x90);
2020-09-26 18:02:44 +02:00
// System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
2020-09-26 18:02:44 +02:00
// mifareDESFire.WirteData(FabAccessIdentFileID, 0x00000000, 0x00000000, enc.GetBytes(UserDomain));
2020-09-26 18:02:44 +02:00
// connected_successfully = true;
2020-09-26 18:02:44 +02:00
// card.Disconnect();
// };
2020-09-26 18:02:44 +02:00
// reader.CardDiscovered += handler;
// reader.Start();
2020-09-26 18:02:44 +02:00
// Assert.AreEqual(true, connected_successfully);
2020-09-26 18:02:44 +02:00
// reader.Stop();
// reader.CardDiscovered -= handler;
// }
2020-09-26 18:02:44 +02:00
// [Test]
// public void AuthenticateCard()
// {
// IHardware hardware = new Hardware();
// IReader reader = hardware.OpenReader(CardReaderID);
2020-09-26 18:02:44 +02:00
// bool connected_successfully = false;
2020-09-26 18:02:44 +02:00
// ReaderEventHandler handler = (sender, card) =>
// {
// card.Connect();
2020-09-26 18:02:44 +02:00
// MIFARE_DESFire mifareDESFire = new MIFARE_DESFire(card);
2020-09-26 18:02:44 +02:00
// mifareDESFire.SelectApplication(FabAccessAID);
// byte[] filedata = mifareDESFire.ReadData(FabAccessIdentFileID, 0x00000000, 0x00000000);
2020-09-26 18:02:44 +02:00
// System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
// string userdomain = enc.GetString(filedata);
2020-09-26 18:02:44 +02:00
// Console.WriteLine(userdomain);
2020-09-26 18:02:44 +02:00
// mifareDESFire.AuthenticateDES(0x01, APP_Key_1);
2020-09-26 18:02:44 +02:00
// connected_successfully = true;
2020-09-26 18:02:44 +02:00
// card.Disconnect();
// };
2020-09-26 18:02:44 +02:00
// reader.CardDiscovered += handler;
// reader.Start();
2020-09-26 18:02:44 +02:00
// Assert.AreEqual(true, connected_successfully);
2020-09-26 18:02:44 +02:00
// reader.Stop();
// reader.CardDiscovered -= handler;
// }
//}
2020-09-26 18:02:44 +02:00
}