mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-12 06:41:54 +01:00
Implement Scan Keys
This commit is contained in:
parent
2f80a17c79
commit
d737faa989
@ -1,6 +1,7 @@
|
||||
using NFC.Helper;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Borepin.Model
|
||||
{
|
||||
@ -9,8 +10,8 @@ namespace Borepin.Model
|
||||
#region Constructors
|
||||
public CardConfig()
|
||||
{
|
||||
PICCKey = ByteOperation.GenerateEmptyArray(16);
|
||||
APPKey = ByteOperation.GenerateEmptyArray(16);
|
||||
PICCKey = GenerateEmptyKey();
|
||||
APPKey = GenerateEmptyKey();
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -53,11 +54,15 @@ namespace Borepin.Model
|
||||
public byte[] GenerateRandomKey()
|
||||
{
|
||||
byte[] key = ByteOperation.GenerateEmptyArray(16);
|
||||
Random random= new Random();
|
||||
|
||||
random.NextBytes(key);
|
||||
RNGCryptoServiceProvider cryptoProvider = new RNGCryptoServiceProvider();
|
||||
cryptoProvider.GetBytes(key);
|
||||
return key;
|
||||
}
|
||||
|
||||
public byte[] GenerateEmptyKey()
|
||||
{
|
||||
return ByteOperation.GenerateEmptyArray(16);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
14
Borepin/Borepin/Model/KeyScan.cs
Normal file
14
Borepin/Borepin/Model/KeyScan.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace Borepin.Model
|
||||
{
|
||||
public class KeyScan
|
||||
{
|
||||
public KeyScan(CardConfig cardConfig, KeyTypes keyType)
|
||||
{
|
||||
CardConfig = cardConfig;
|
||||
KeyType = keyType;
|
||||
}
|
||||
|
||||
public CardConfig CardConfig;
|
||||
public KeyTypes KeyType;
|
||||
}
|
||||
}
|
9
Borepin/Borepin/Model/KeyTypes.cs
Normal file
9
Borepin/Borepin/Model/KeyTypes.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace Borepin.Model
|
||||
{
|
||||
public enum KeyTypes
|
||||
{
|
||||
NONE,
|
||||
PICC,
|
||||
APP
|
||||
};
|
||||
}
|
@ -37,7 +37,6 @@
|
||||
<ColumnDefinition Width="1*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Entry Grid.Column="0" Text="{Binding PICCKey}" IsSpellCheckEnabled="false"/>
|
||||
<Button Grid.Column="1" Text="Random" Command="{Binding RandomPICCKeyCommand}" Style="{StaticResource Style_Button_Primary}"/>
|
||||
<Button Grid.Column="2" Text="Scan QR-Code" Command="{Binding ScanPICCKeyCommand}" Style="{StaticResource Style_Button_Primary}"/>
|
||||
</Grid>
|
||||
|
||||
|
@ -10,6 +10,8 @@ using Borepin.Base.Exceptions;
|
||||
using NFC.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using Borepin.Model;
|
||||
using Xamarin.Forms;
|
||||
using System;
|
||||
|
||||
namespace Borepin.PageModel
|
||||
{
|
||||
@ -19,6 +21,9 @@ namespace Borepin.PageModel
|
||||
private CardConfig _CardConfig;
|
||||
private User _User;
|
||||
private INFCService _NFCService;
|
||||
|
||||
private KeyTypes _ScanKeyType = KeyTypes.NONE;
|
||||
private KeyTypes _ScanedKeyType = KeyTypes.NONE;
|
||||
#endregion
|
||||
|
||||
#region Contructors
|
||||
@ -30,8 +35,6 @@ namespace Borepin.PageModel
|
||||
CreateCardCommand = new DelegateCommand(CreateCardCommandExecute);
|
||||
|
||||
ScanPICCKeyCommand = new DelegateCommand(ScanPICCKeyCommandExecute);
|
||||
RandomPICCKeyCommand = new DelegateCommand(RandomPICCKeyCommandExecute);
|
||||
|
||||
ScanAPPKeyCommand = new DelegateCommand(ScanAPPKeyCommandExecute);
|
||||
RandomAPPKeyCommand = new DelegateCommand(RandomAPPKeyCommandExecute);
|
||||
|
||||
@ -46,6 +49,17 @@ namespace Borepin.PageModel
|
||||
{
|
||||
_CardConfig.UserID = instance as string;
|
||||
}
|
||||
else if (instance is CardConfig)
|
||||
{
|
||||
_CardConfig = instance as CardConfig;
|
||||
}
|
||||
else if (instance is KeyScan)
|
||||
{
|
||||
KeyScan keyScan = instance as KeyScan;
|
||||
_CardConfig = keyScan.CardConfig;
|
||||
_ScanedKeyType = keyScan.KeyType;
|
||||
_ScanKeyType = KeyTypes.NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InstanceIncorrectException();
|
||||
@ -54,15 +68,52 @@ namespace Borepin.PageModel
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override Task LoadFromParameters(INavigationParameters parameters)
|
||||
{
|
||||
if (parameters.ContainsKey("result") && string.Equals((string)parameters["result"], "scanned", StringComparison.Ordinal) && parameters.ContainsKey("value"))
|
||||
{
|
||||
switch(_ScanedKeyType)
|
||||
{
|
||||
case (KeyTypes.PICC):
|
||||
try
|
||||
{
|
||||
_CardConfig.PICCKey = _CardConfig.ConvertFromString(PICCKey);
|
||||
}
|
||||
catch
|
||||
{
|
||||
_CardConfig.PICCKey = _CardConfig.GenerateEmptyKey();
|
||||
}
|
||||
_CardConfig.PICCKey = _CardConfig.ConvertFromString((string)parameters["value"]);
|
||||
PICCKey = _CardConfig.ConvertToString(_CardConfig.PICCKey);
|
||||
break;
|
||||
case (KeyTypes.APP):
|
||||
try
|
||||
{
|
||||
_CardConfig.APPKey = _CardConfig.ConvertFromString((string)parameters["value"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
_CardConfig.APPKey = _CardConfig.GenerateEmptyKey();
|
||||
}
|
||||
APPKey = _CardConfig.ConvertToString(_CardConfig.APPKey);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override async Task LoadAPIData()
|
||||
{
|
||||
_User = (await _API.Session.UserSystem.Search.GetUserByName(_CardConfig.UserID).ConfigureAwait(false)).Just;
|
||||
|
||||
ReaderIDs = await Task.Run(() =>
|
||||
ReaderIDs = await Task.Run(() =>
|
||||
{
|
||||
return _NFCService.GetReaderIDs();
|
||||
}).ConfigureAwait(false);
|
||||
|
||||
// Delay to sync with XAML Picker Item Source
|
||||
await Task.Delay(100).ConfigureAwait(false);
|
||||
if (ReaderIDs.Count > 0)
|
||||
{
|
||||
ReaderID = ReaderIDs[0];
|
||||
@ -70,11 +121,41 @@ namespace Borepin.PageModel
|
||||
|
||||
PICCKey = _CardConfig.ConvertToString(_CardConfig.PICCKey);
|
||||
APPKey = _CardConfig.ConvertToString(_CardConfig.APPKey);
|
||||
FormatCard = _CardConfig.DoFormat;
|
||||
}
|
||||
|
||||
public override Task<object> CreateInstance()
|
||||
{
|
||||
return Task.FromResult<object>(_CardConfig);
|
||||
try
|
||||
{
|
||||
_CardConfig.PICCKey = _CardConfig.ConvertFromString(PICCKey);
|
||||
}
|
||||
catch
|
||||
{
|
||||
_CardConfig.PICCKey = _CardConfig.GenerateEmptyKey();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_CardConfig.APPKey = _CardConfig.ConvertFromString(APPKey);
|
||||
}
|
||||
catch
|
||||
{
|
||||
_CardConfig.APPKey = _CardConfig.GenerateEmptyKey();
|
||||
}
|
||||
|
||||
_CardConfig.DoFormat = FormatCard;
|
||||
|
||||
switch(_ScanKeyType)
|
||||
{
|
||||
case (KeyTypes.PICC):
|
||||
return Task.FromResult<object>(new KeyScan(_CardConfig, KeyTypes.PICC));
|
||||
case (KeyTypes.APP):
|
||||
return Task.FromResult<object>(new KeyScan(_CardConfig, KeyTypes.APP));
|
||||
case (KeyTypes.NONE):
|
||||
default:
|
||||
return Task.FromResult<object>(_CardConfig);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -107,8 +188,8 @@ namespace Borepin.PageModel
|
||||
set => SetProperty(ref _APPKey, value);
|
||||
}
|
||||
|
||||
private string _FormatCard;
|
||||
public string FormatCard
|
||||
private bool _FormatCard;
|
||||
public bool FormatCard
|
||||
{
|
||||
get => _FormatCard;
|
||||
set => SetProperty(ref _FormatCard, value);
|
||||
@ -163,13 +244,18 @@ namespace Borepin.PageModel
|
||||
set => SetProperty(ref _ScanPICCKeyCommand, value);
|
||||
}
|
||||
|
||||
public async void ScanPICCKeyCommandExecute()
|
||||
public void ScanPICCKeyCommandExecute()
|
||||
{
|
||||
IsBusy = true;
|
||||
_ScanKeyType = KeyTypes.PICC;
|
||||
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
|
||||
IsBusy = false;
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
INavigationResult result = await _NavigationService.NavigateAsync("ScanPage").ConfigureAwait(false);
|
||||
if (result.Exception != null)
|
||||
{
|
||||
Log.Fatal(result.Exception, "Navigating failed");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private ICommand _RandomPICCKeyCommand;
|
||||
@ -213,13 +299,18 @@ namespace Borepin.PageModel
|
||||
set => SetProperty(ref _ScanAPPKeyCommand, value);
|
||||
}
|
||||
|
||||
public async void ScanAPPKeyCommandExecute()
|
||||
public void ScanAPPKeyCommandExecute()
|
||||
{
|
||||
IsBusy = true;
|
||||
_ScanKeyType = KeyTypes.APP;
|
||||
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
|
||||
IsBusy = false;
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
INavigationResult result = await _NavigationService.NavigateAsync("ScanPage").ConfigureAwait(false);
|
||||
if (result.Exception != null)
|
||||
{
|
||||
Log.Fatal(result.Exception, "Navigating failed");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private ICommand _RandomAPPKeyCommand;
|
||||
|
@ -346,7 +346,7 @@ namespace FabAccessAPI
|
||||
SslStream sslStream = new SslStream(tcpstream, false, new RemoteCertificateValidationCallback(_RemoteCertificateValidationCallback));
|
||||
try
|
||||
{
|
||||
sslStream.ReadTimeout = 2000;
|
||||
sslStream.ReadTimeout = 5000;
|
||||
sslStream.AuthenticateAsClient("bffhd");
|
||||
sslStream.ReadTimeout = -1;
|
||||
|
||||
@ -376,7 +376,7 @@ namespace FabAccessAPI
|
||||
|
||||
try
|
||||
{
|
||||
Task timeoutTask = Task.Delay(3000);
|
||||
Task timeoutTask = Task.Delay(5000);
|
||||
tcprpcClient.Connect(connectionData.Host.Host, connectionData.Host.Port);
|
||||
await await Task.WhenAny(tcprpcClient.WhenConnected, timeoutTask);
|
||||
|
||||
|
2
external/capnproto-dotnetcore
vendored
2
external/capnproto-dotnetcore
vendored
@ -1 +1 @@
|
||||
Subproject commit a70eecd99112b16902128b8b4b2c95b2721fdf0e
|
||||
Subproject commit 1be9ffbf8acbc9770f2d5b67c961fb60e49e5ec5
|
Loading…
x
Reference in New Issue
Block a user