mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-12 14:51:44 +01:00
Added: NTAG scan on Android
This commit is contained in:
parent
c6d6153932
commit
092081e82d
@ -1,16 +1,33 @@
|
||||
|
||||
using Android.App;
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.Content.PM;
|
||||
using Android.OS;
|
||||
using AndroidX.AppCompat.App;
|
||||
using Java.Interop;
|
||||
|
||||
namespace Borepin.Droid
|
||||
{
|
||||
[Activity(Theme = "@style/MainTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
|
||||
[Activity(MainLauncher = true, Exported = true, Theme = "@style/MainTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
|
||||
[IntentFilter(
|
||||
new[]
|
||||
{
|
||||
"android.nfc.action.NDEF_DISCOVERED"
|
||||
},
|
||||
Categories = new[]
|
||||
{
|
||||
Intent.CategoryDefault
|
||||
},
|
||||
DataScheme = "fabaccess",
|
||||
DataHost = "innovisionlab.de"
|
||||
)]
|
||||
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
|
||||
{
|
||||
protected override void OnCreate(Bundle savedInstanceState)
|
||||
{
|
||||
Android.Net.Uri test = Intent.Data;
|
||||
string text = Intent.GetStringExtra("MyData") ?? "Data not available";
|
||||
|
||||
|
||||
AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo;
|
||||
|
||||
TabLayoutResource = Resource.Layout.Tabbar;
|
||||
@ -24,6 +41,10 @@ namespace Borepin.Droid
|
||||
Xamarin.Forms.Forms.Init(this, savedInstanceState);
|
||||
LoadApplication(new App(new PlatformInitializer()));
|
||||
}
|
||||
protected override void OnNewIntent(Intent intent)
|
||||
{
|
||||
base.OnNewIntent(intent);
|
||||
}
|
||||
|
||||
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
|
||||
{
|
||||
|
@ -1,9 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="org.fab_infra.fabaccess" android:installLocation="auto">
|
||||
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="33" />
|
||||
<application android:theme="@style/MainTheme" android:label="FabAccess" android:networkSecurityConfig="@xml/network_security_config"></application>
|
||||
<application android:theme="@style/MainTheme" android:label="FabAccess" android:networkSecurityConfig="@xml/network_security_config">
|
||||
|
||||
</application>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.FLASHLIGHT" />
|
||||
<uses-permission android:name="android.permission.NFC" />
|
||||
<uses-permission android:name="android.permission.BIND_NFC_SERVICE" />
|
||||
</manifest>
|
@ -27,6 +27,7 @@ using Android.App;
|
||||
// Add some common permissions, these can be removed if not needed
|
||||
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
|
||||
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
|
||||
[assembly: UsesPermission(Android.Manifest.Permission.Nfc)]
|
||||
|
||||
//#if DEBUG
|
||||
//[assembly: Application(Debuggable=true)]
|
||||
|
@ -13,8 +13,8 @@ namespace Borepin.Model
|
||||
public class FabFireCard
|
||||
{
|
||||
#region Private Fields
|
||||
INFCService _NFCService;
|
||||
IErrorMessageService _ErrorMessageService;
|
||||
readonly INFCService _NFCService;
|
||||
readonly IErrorMessageService _ErrorMessageService;
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@ -85,20 +85,32 @@ namespace Borepin.Model
|
||||
card.AuthenticateISO_AES(0x00, MasterKey._Key);
|
||||
card.ChangeOtherKey_AES(0x01, AuthKey._Key, _Default_AESKey._Key, AuthKey._KeyVersion);
|
||||
|
||||
UInt16 accesRights = card.GenerateFileAccessRights((byte)FileAccessRights.FREE, 0x00, 0x00, 0x00);
|
||||
UInt16 accessRights = card.GenerateFileAccessRights((byte)FileAccessRights.FREE, 0x00, 0x00, 0x00);
|
||||
|
||||
card.CreateFile_Standard(0x01, FileCommunication.PLAIN, accesRights, (uint)cardConfig.MetaInfo.Length);
|
||||
card.CreateFile_Standard(0x02, FileCommunication.PLAIN, accesRights, (uint)cardConfig.SpaceInfo.Length);
|
||||
card.CreateFile_Standard(0x03, FileCommunication.PLAIN, accesRights, (uint)cardConfig.CardToken.Length);
|
||||
card.CreateFile_Standard(0x01, FileCommunication.PLAIN, accessRights, (uint)cardConfig.MetaInfo.Length);
|
||||
card.CreateFile_Standard(0x02, FileCommunication.PLAIN, accessRights, (uint)cardConfig.SpaceInfo.Length);
|
||||
card.CreateFile_Standard(0x03, FileCommunication.PLAIN, accessRights, (uint)47);// TODO (uint)cardConfig.CardToken.Length);
|
||||
|
||||
card.WriteData(0x01, 0x00, cardConfig.MetaInfo);
|
||||
card.WriteData(0x02, 0x00, cardConfig.SpaceInfo);
|
||||
card.WriteData(0x03, 0x00, cardConfig.CardToken);
|
||||
card.WriteData(0x03, 0x00, _TODOFixDataFileSize(cardConfig.CardToken));
|
||||
|
||||
_NFCService.Disconnect();
|
||||
|
||||
return AuthKey._Key;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO implement GetFileInfo in DESFire
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
private byte[] _TODOFixDataFileSize(byte[] data)
|
||||
{
|
||||
byte[] array = ByteOperation.GenerateEmptyArray(47);
|
||||
data.CopyTo(array, 0);
|
||||
return array;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ namespace Borepin.PageModel
|
||||
private CardConfig _CardConfig;
|
||||
private User _User;
|
||||
private INFCService _NFCService;
|
||||
private User.ICardDESFireInterface _CardDESFireInterface;
|
||||
private IErrorMessageService _ErrorMessageService;
|
||||
|
||||
private KeyTypes _ScanKeyType = KeyTypes.NONE;
|
||||
@ -44,9 +43,6 @@ namespace Borepin.PageModel
|
||||
RandomAPPKeyCommand = new DelegateCommand(RandomAPPKeyCommandExecute);
|
||||
|
||||
RefreshCommand = new DelegateCommand(async () => await RefreshCommandExecute().ConfigureAwait(true));
|
||||
|
||||
// TODO Use Server Interface
|
||||
_CardDESFireInterface = new DESFireInterfaceDummy();
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -281,9 +277,9 @@ namespace Borepin.PageModel
|
||||
|
||||
_CardConfig.DoFormat = FormatCard;
|
||||
|
||||
_CardConfig.CardToken = (await _CardDESFireInterface.GenCardToken().ConfigureAwait(false)).ToArray();
|
||||
_CardConfig.SpaceInfo = (await _CardDESFireInterface.GetSpaceInfo().ConfigureAwait(false)).ToArray();
|
||||
_CardConfig.MetaInfo = (await _CardDESFireInterface.GetMetaInfo().ConfigureAwait(false)).ToArray();
|
||||
_CardConfig.CardToken = (await _User.CardDESFireEV2.GenCardToken().ConfigureAwait(false)).ToArray();
|
||||
_CardConfig.SpaceInfo = (await _User.CardDESFireEV2.GetSpaceInfo().ConfigureAwait(false)).ToArray();
|
||||
_CardConfig.MetaInfo = (await _User.CardDESFireEV2.GetMetaInfo().ConfigureAwait(false)).ToArray();
|
||||
|
||||
FabFireCard fabFireCard = new FabFireCard(_NFCService, _ErrorMessageService);
|
||||
|
||||
@ -294,7 +290,7 @@ namespace Borepin.PageModel
|
||||
fabFireCard.FormatCard(ReaderID, _CardConfig);
|
||||
}
|
||||
}
|
||||
catch
|
||||
catch(Exception exception)
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
@ -302,14 +298,17 @@ namespace Borepin.PageModel
|
||||
|
||||
IsBusy = false;
|
||||
});
|
||||
|
||||
_NFCService.Disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
byte[] key = fabFireCard.CreateCard(ReaderID, _CardConfig);
|
||||
await _CardDESFireInterface.Bind(_CardConfig.CardToken, new List<byte>(key)).ConfigureAwait(false);
|
||||
await _User.CardDESFireEV2.Bind(_CardConfig.CardToken, new List<byte>(key)).ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
catch(Exception excpetion)
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
@ -317,8 +316,14 @@ namespace Borepin.PageModel
|
||||
|
||||
IsBusy = false;
|
||||
});
|
||||
_NFCService.Disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
INavigationResult result = await _NavigationService.GoBackAsync().ConfigureAwait(false);
|
||||
});
|
||||
IsBusy = false;
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,8 @@ namespace Borepin.PageModel
|
||||
CanCreateCard = !((User.CardDESFireInterface_Proxy)_User.CardDESFireEV2).IsNull;
|
||||
if(CanCreateCard)
|
||||
{
|
||||
HasCardBinded = (await _User.CardDESFireEV2.GetTokenList().ConfigureAwait(false)).Count > 0;
|
||||
IReadOnlyList<IReadOnlyList<byte>> list = await _User.CardDESFireEV2.GetTokenList().ConfigureAwait(false);
|
||||
HasCardBinded = list != null && list.Count > 0;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
Loading…
x
Reference in New Issue
Block a user