2019-08-27 20:55:15 +02:00
|
|
|
|
using AuthenticationServices;
|
2019-09-04 17:52:32 +02:00
|
|
|
|
using Bit.App.Abstractions;
|
2019-06-28 14:21:44 +02:00
|
|
|
|
using Bit.Core.Abstractions;
|
|
|
|
|
using Bit.Core.Utilities;
|
|
|
|
|
using Bit.iOS.Autofill.Models;
|
|
|
|
|
using Bit.iOS.Core.Utilities;
|
|
|
|
|
using Foundation;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-05-29 18:26:36 +02:00
|
|
|
|
using Bit.App.Pages;
|
2019-06-28 14:21:44 +02:00
|
|
|
|
using UIKit;
|
2020-05-29 18:26:36 +02:00
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
using Bit.App.Utilities;
|
|
|
|
|
using Bit.App.Models;
|
2020-10-15 20:34:31 +02:00
|
|
|
|
using Bit.iOS.Core.Views;
|
2020-05-29 18:26:36 +02:00
|
|
|
|
using CoreNFC;
|
2019-06-28 14:21:44 +02:00
|
|
|
|
|
|
|
|
|
namespace Bit.iOS.Autofill
|
|
|
|
|
{
|
|
|
|
|
public partial class CredentialProviderViewController : ASCredentialProviderViewController
|
|
|
|
|
{
|
|
|
|
|
private Context _context;
|
2020-04-02 15:02:38 +02:00
|
|
|
|
private bool _initedAppCenter;
|
2020-05-29 18:26:36 +02:00
|
|
|
|
private NFCNdefReaderSession _nfcSession = null;
|
|
|
|
|
private Core.NFCReaderDelegate _nfcDelegate = null;
|
2019-06-28 14:21:44 +02:00
|
|
|
|
|
|
|
|
|
public CredentialProviderViewController(IntPtr handle)
|
|
|
|
|
: base(handle)
|
2019-10-01 03:17:53 +02:00
|
|
|
|
{
|
|
|
|
|
ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
|
|
|
|
|
}
|
2019-06-28 14:21:44 +02:00
|
|
|
|
|
|
|
|
|
public override void ViewDidLoad()
|
|
|
|
|
{
|
|
|
|
|
InitApp();
|
|
|
|
|
base.ViewDidLoad();
|
2019-06-28 18:30:48 +02:00
|
|
|
|
Logo.Image = new UIImage(ThemeHelpers.LightTheme ? "logo.png" : "logo_white.png");
|
|
|
|
|
View.BackgroundColor = ThemeHelpers.SplashBackgroundColor;
|
2019-06-28 14:21:44 +02:00
|
|
|
|
_context = new Context
|
|
|
|
|
{
|
|
|
|
|
ExtContext = ExtensionContext
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 06:15:51 +02:00
|
|
|
|
public override async void PrepareCredentialList(ASCredentialServiceIdentifier[] serviceIdentifiers)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2019-07-22 14:22:02 +02:00
|
|
|
|
InitAppIfNeeded();
|
2019-06-28 14:21:44 +02:00
|
|
|
|
_context.ServiceIdentifiers = serviceIdentifiers;
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (serviceIdentifiers.Length > 0)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
|
|
|
|
var uri = serviceIdentifiers[0].Identifier;
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (serviceIdentifiers[0].Type == ASCredentialServiceIdentifierType.Domain)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
|
|
|
|
uri = string.Concat("https://", uri);
|
|
|
|
|
}
|
|
|
|
|
_context.UrlString = uri;
|
|
|
|
|
}
|
2020-06-07 17:54:14 +02:00
|
|
|
|
if (!await IsAuthed())
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2020-09-03 18:30:40 +02:00
|
|
|
|
LaunchHomePage();
|
2019-06-28 14:21:44 +02:00
|
|
|
|
}
|
2020-06-07 06:15:51 +02:00
|
|
|
|
else if (await IsLocked())
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
|
|
|
|
PerformSegue("lockPasswordSegue", this);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (_context.ServiceIdentifiers == null || _context.ServiceIdentifiers.Length == 0)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
|
|
|
|
PerformSegue("loginSearchSegue", this);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PerformSegue("loginListSegue", this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 06:15:51 +02:00
|
|
|
|
public override async void ProvideCredentialWithoutUserInteraction(ASPasswordCredentialIdentity credentialIdentity)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2019-07-22 14:22:02 +02:00
|
|
|
|
InitAppIfNeeded();
|
2022-02-23 18:40:17 +01:00
|
|
|
|
var stateService = ServiceContainer.Resolve<IStateService>("stateService");
|
|
|
|
|
await stateService.SetPasswordRepromptAutofillAsync(false);
|
|
|
|
|
await stateService.SetPasswordVerifiedAutofillAsync(false);
|
2020-06-07 17:54:14 +02:00
|
|
|
|
if (!await IsAuthed() || await IsLocked())
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
|
|
|
|
var err = new NSError(new NSString("ASExtensionErrorDomain"),
|
|
|
|
|
Convert.ToInt32(ASExtensionErrorCode.UserInteractionRequired), null);
|
|
|
|
|
ExtensionContext.CancelRequest(err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_context.CredentialIdentity = credentialIdentity;
|
2021-06-10 17:57:18 +02:00
|
|
|
|
await ProvideCredentialAsync(false);
|
2019-06-28 14:21:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 06:15:51 +02:00
|
|
|
|
public override async void PrepareInterfaceToProvideCredential(ASPasswordCredentialIdentity credentialIdentity)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2019-07-22 14:22:02 +02:00
|
|
|
|
InitAppIfNeeded();
|
2020-06-07 17:54:14 +02:00
|
|
|
|
if (!await IsAuthed())
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2020-09-03 18:30:40 +02:00
|
|
|
|
LaunchHomePage();
|
2019-06-28 14:21:44 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_context.CredentialIdentity = credentialIdentity;
|
|
|
|
|
CheckLock(async () => await ProvideCredentialAsync());
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 06:15:51 +02:00
|
|
|
|
public override async void PrepareInterfaceForExtensionConfiguration()
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2019-07-22 14:22:02 +02:00
|
|
|
|
InitAppIfNeeded();
|
2019-06-28 14:21:44 +02:00
|
|
|
|
_context.Configuring = true;
|
2020-06-07 17:54:14 +02:00
|
|
|
|
if (!await IsAuthed())
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2020-09-03 18:30:40 +02:00
|
|
|
|
LaunchHomePage();
|
2019-06-28 14:21:44 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
CheckLock(() => PerformSegue("setupSegue", this));
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-22 21:50:59 +02:00
|
|
|
|
public void CompleteRequest(string id = null, string username = null,
|
|
|
|
|
string password = null, string totp = null)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if ((_context?.Configuring ?? true) && string.IsNullOrWhiteSpace(password))
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2019-07-23 03:35:05 +02:00
|
|
|
|
ServiceContainer.Reset();
|
2019-06-28 14:21:44 +02:00
|
|
|
|
ExtensionContext?.CompleteExtensionConfigurationRequest();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (_context == null || string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2019-07-23 03:35:05 +02:00
|
|
|
|
ServiceContainer.Reset();
|
2019-06-28 14:21:44 +02:00
|
|
|
|
var err = new NSError(new NSString("ASExtensionErrorDomain"),
|
|
|
|
|
Convert.ToInt32(ASExtensionErrorCode.UserCanceled), null);
|
|
|
|
|
NSRunLoop.Main.BeginInvokeOnMainThread(() => ExtensionContext?.CancelRequest(err));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(totp))
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
|
|
|
|
UIPasteboard.General.String = totp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var cred = new ASPasswordCredential(username, password);
|
2019-07-23 03:35:05 +02:00
|
|
|
|
NSRunLoop.Main.BeginInvokeOnMainThread(async () =>
|
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(id))
|
2019-07-24 16:42:13 +02:00
|
|
|
|
{
|
|
|
|
|
var eventService = ServiceContainer.Resolve<IEventService>("eventService");
|
|
|
|
|
await eventService.CollectAsync(Bit.Core.Enums.EventType.Cipher_ClientAutofilled, id);
|
|
|
|
|
}
|
2019-07-23 03:35:05 +02:00
|
|
|
|
ServiceContainer.Reset();
|
|
|
|
|
ExtensionContext?.CompleteRequest(cred, null);
|
|
|
|
|
});
|
2019-06-28 14:21:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender)
|
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (segue.DestinationViewController is UINavigationController navController)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (navController.TopViewController is LoginListViewController listLoginController)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
|
|
|
|
listLoginController.Context = _context;
|
|
|
|
|
listLoginController.CPViewController = this;
|
2020-10-15 20:34:31 +02:00
|
|
|
|
segue.DestinationViewController.PresentationController.Delegate =
|
|
|
|
|
new CustomPresentationControllerDelegate(listLoginController.DismissModalAction);
|
2019-06-28 14:21:44 +02:00
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (navController.TopViewController is LoginSearchViewController listSearchController)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
|
|
|
|
listSearchController.Context = _context;
|
|
|
|
|
listSearchController.CPViewController = this;
|
2020-10-15 20:34:31 +02:00
|
|
|
|
segue.DestinationViewController.PresentationController.Delegate =
|
|
|
|
|
new CustomPresentationControllerDelegate(listSearchController.DismissModalAction);
|
2019-06-28 14:21:44 +02:00
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (navController.TopViewController is LockPasswordViewController passwordViewController)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
|
|
|
|
passwordViewController.CPViewController = this;
|
2020-10-15 20:34:31 +02:00
|
|
|
|
segue.DestinationViewController.PresentationController.Delegate =
|
|
|
|
|
new CustomPresentationControllerDelegate(passwordViewController.DismissModalAction);
|
2019-06-28 14:21:44 +02:00
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
else if (navController.TopViewController is SetupViewController setupViewController)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
|
|
|
|
setupViewController.CPViewController = this;
|
2020-10-15 20:34:31 +02:00
|
|
|
|
segue.DestinationViewController.PresentationController.Delegate =
|
|
|
|
|
new CustomPresentationControllerDelegate(setupViewController.DismissModalAction);
|
2019-06-28 14:21:44 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DismissLockAndContinue()
|
|
|
|
|
{
|
|
|
|
|
DismissViewController(false, async () =>
|
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (_context.CredentialIdentity != null)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
|
|
|
|
await ProvideCredentialAsync();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (_context.Configuring)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
|
|
|
|
PerformSegue("setupSegue", this);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (_context.ServiceIdentifiers == null || _context.ServiceIdentifiers.Length == 0)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
|
|
|
|
PerformSegue("loginSearchSegue", this);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PerformSegue("loginListSegue", this);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-10 17:57:18 +02:00
|
|
|
|
private async Task ProvideCredentialAsync(bool userInteraction = true)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2019-08-27 20:55:15 +02:00
|
|
|
|
var cipherService = ServiceContainer.Resolve<ICipherService>("cipherService", true);
|
2020-06-05 19:30:53 +02:00
|
|
|
|
Bit.Core.Models.Domain.Cipher cipher = null;
|
|
|
|
|
var cancel = cipherService == null || _context.CredentialIdentity?.RecordIdentifier == null;
|
|
|
|
|
if (!cancel)
|
|
|
|
|
{
|
|
|
|
|
cipher = await cipherService.GetAsync(_context.CredentialIdentity.RecordIdentifier);
|
|
|
|
|
cancel = cipher == null || cipher.Type != Bit.Core.Enums.CipherType.Login || cipher.Login == null;
|
|
|
|
|
}
|
|
|
|
|
if (cancel)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
|
|
|
|
var err = new NSError(new NSString("ASExtensionErrorDomain"),
|
|
|
|
|
Convert.ToInt32(ASExtensionErrorCode.CredentialIdentityNotFound), null);
|
2020-06-05 19:30:53 +02:00
|
|
|
|
ExtensionContext?.CancelRequest(err);
|
2019-06-28 14:21:44 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-23 18:40:17 +01:00
|
|
|
|
var stateService = ServiceContainer.Resolve<IStateService>("stateService");
|
2019-06-28 14:21:44 +02:00
|
|
|
|
var decCipher = await cipher.DecryptAsync();
|
2021-06-10 17:57:18 +02:00
|
|
|
|
if (decCipher.Reprompt != Bit.Core.Enums.CipherRepromptType.None)
|
|
|
|
|
{
|
|
|
|
|
// Prompt for password using either the lock screen or dialog unless
|
|
|
|
|
// already verified the password.
|
|
|
|
|
if (!userInteraction)
|
|
|
|
|
{
|
2022-02-23 18:40:17 +01:00
|
|
|
|
await stateService.SetPasswordRepromptAutofillAsync(true);
|
2021-06-10 17:57:18 +02:00
|
|
|
|
var err = new NSError(new NSString("ASExtensionErrorDomain"),
|
|
|
|
|
Convert.ToInt32(ASExtensionErrorCode.UserInteractionRequired), null);
|
|
|
|
|
ExtensionContext?.CancelRequest(err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-02-23 18:40:17 +01:00
|
|
|
|
else if (!await stateService.GetPasswordVerifiedAutofillAsync())
|
2021-06-10 17:57:18 +02:00
|
|
|
|
{
|
2021-06-15 20:29:11 +02:00
|
|
|
|
// Add a timeout to resolve keyboard not always showing up.
|
|
|
|
|
await Task.Delay(250);
|
2021-06-10 17:57:18 +02:00
|
|
|
|
var passwordRepromptService = ServiceContainer.Resolve<IPasswordRepromptService>("passwordRepromptService");
|
|
|
|
|
if (!await passwordRepromptService.ShowPasswordPromptAsync())
|
|
|
|
|
{
|
|
|
|
|
var err = new NSError(new NSString("ASExtensionErrorDomain"),
|
|
|
|
|
Convert.ToInt32(ASExtensionErrorCode.UserCanceled), null);
|
|
|
|
|
ExtensionContext?.CancelRequest(err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-28 14:21:44 +02:00
|
|
|
|
string totpCode = null;
|
2022-02-23 18:40:17 +01:00
|
|
|
|
var disableTotpCopy = await stateService.GetDisableAutoTotpCopyAsync();
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (!disableTotpCopy.GetValueOrDefault(false))
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2022-02-23 18:40:17 +01:00
|
|
|
|
var canAccessPremiumAsync = await stateService.CanAccessPremiumAsync();
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(decCipher.Login.Totp) &&
|
2019-06-28 14:21:44 +02:00
|
|
|
|
(canAccessPremiumAsync || cipher.OrganizationUseTotp))
|
|
|
|
|
{
|
|
|
|
|
var totpService = ServiceContainer.Resolve<ITotpService>("totpService");
|
|
|
|
|
totpCode = await totpService.GetCodeAsync(decCipher.Login.Totp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-22 21:50:59 +02:00
|
|
|
|
CompleteRequest(decCipher.Id, decCipher.Login.Username, decCipher.Login.Password, totpCode);
|
2019-06-28 14:21:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 06:15:51 +02:00
|
|
|
|
private async void CheckLock(Action notLockedAction)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2022-02-23 18:40:17 +01:00
|
|
|
|
var stateService = ServiceContainer.Resolve<IStateService>("stateService");
|
|
|
|
|
if (await IsLocked() || await stateService.GetPasswordRepromptAutofillAsync())
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
|
|
|
|
PerformSegue("lockPasswordSegue", this);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
notLockedAction();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 06:15:51 +02:00
|
|
|
|
private Task<bool> IsLocked()
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2020-05-29 18:26:36 +02:00
|
|
|
|
var vaultTimeoutService = ServiceContainer.Resolve<IVaultTimeoutService>("vaultTimeoutService");
|
2020-06-07 06:15:51 +02:00
|
|
|
|
return vaultTimeoutService.IsLockedAsync();
|
2019-06-28 14:21:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 06:15:51 +02:00
|
|
|
|
private Task<bool> IsAuthed()
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2022-02-23 18:40:17 +01:00
|
|
|
|
var stateService = ServiceContainer.Resolve<IStateService>("stateService");
|
|
|
|
|
return stateService.IsAuthenticatedAsync();
|
2019-06-28 14:21:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-24 20:14:26 +02:00
|
|
|
|
private void LogoutIfAuthed()
|
|
|
|
|
{
|
|
|
|
|
NSRunLoop.Main.BeginInvokeOnMainThread(async () =>
|
|
|
|
|
{
|
|
|
|
|
if (await IsAuthed())
|
|
|
|
|
{
|
2022-02-23 18:40:17 +01:00
|
|
|
|
var stateService = ServiceContainer.Resolve<IStateService>("stateService");
|
|
|
|
|
await AppHelpers.LogOutAsync(await stateService.GetActiveUserIdAsync());
|
2021-09-24 20:14:26 +02:00
|
|
|
|
var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
|
|
|
|
if (deviceActionService.SystemMajorVersion() >= 12)
|
|
|
|
|
{
|
|
|
|
|
await ASCredentialIdentityStore.SharedStore?.RemoveAllCredentialIdentitiesAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-28 14:21:44 +02:00
|
|
|
|
private void InitApp()
|
|
|
|
|
{
|
2020-05-29 18:26:36 +02:00
|
|
|
|
// Init Xamarin Forms
|
|
|
|
|
Forms.Init();
|
|
|
|
|
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (ServiceContainer.RegisteredServices.Count > 0)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2019-07-03 02:45:54 +02:00
|
|
|
|
ServiceContainer.Reset();
|
2019-06-28 14:21:44 +02:00
|
|
|
|
}
|
|
|
|
|
iOSCoreHelpers.RegisterLocalServices();
|
2019-09-04 17:52:32 +02:00
|
|
|
|
var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
2020-05-29 18:26:36 +02:00
|
|
|
|
var messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
|
2020-10-13 21:39:36 +02:00
|
|
|
|
ServiceContainer.Init(deviceActionService.DeviceUserAgent,
|
|
|
|
|
Bit.Core.Constants.iOSAutoFillClearCiphersCacheKey, Bit.Core.Constants.iOSAllClearCipherCacheKeys);
|
2020-04-02 15:02:38 +02:00
|
|
|
|
if (!_initedAppCenter)
|
2019-07-03 22:49:47 +02:00
|
|
|
|
{
|
2020-04-02 15:02:38 +02:00
|
|
|
|
iOSCoreHelpers.RegisterAppCenter();
|
|
|
|
|
_initedAppCenter = true;
|
2019-07-03 22:49:47 +02:00
|
|
|
|
}
|
2019-06-28 14:21:44 +02:00
|
|
|
|
iOSCoreHelpers.Bootstrap();
|
2021-10-08 14:47:40 +02:00
|
|
|
|
var app = new App.App(new AppOptions { IosExtension = true });
|
2022-02-23 18:40:17 +01:00
|
|
|
|
ThemeManager.SetTheme(app.Resources);
|
2021-10-08 14:47:40 +02:00
|
|
|
|
iOSCoreHelpers.AppearanceAdjustments();
|
2020-05-29 18:26:36 +02:00
|
|
|
|
_nfcDelegate = new Core.NFCReaderDelegate((success, message) =>
|
|
|
|
|
messagingService.Send("gotYubiKeyOTP", message));
|
|
|
|
|
iOSCoreHelpers.SubscribeBroadcastReceiver(this, _nfcSession, _nfcDelegate);
|
2019-06-28 14:21:44 +02:00
|
|
|
|
}
|
2019-07-22 14:22:02 +02:00
|
|
|
|
|
|
|
|
|
private void InitAppIfNeeded()
|
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (ServiceContainer.RegisteredServices == null || ServiceContainer.RegisteredServices.Count == 0)
|
2019-07-22 14:22:02 +02:00
|
|
|
|
{
|
|
|
|
|
InitApp();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-29 18:26:36 +02:00
|
|
|
|
|
2020-09-03 18:30:40 +02:00
|
|
|
|
private void LaunchHomePage()
|
2020-05-29 18:26:36 +02:00
|
|
|
|
{
|
2020-09-03 18:30:40 +02:00
|
|
|
|
var homePage = new HomePage();
|
|
|
|
|
var app = new App.App(new AppOptions { IosExtension = true });
|
2022-02-23 18:40:17 +01:00
|
|
|
|
ThemeManager.SetTheme(app.Resources);
|
2020-09-03 18:30:40 +02:00
|
|
|
|
ThemeManager.ApplyResourcesToPage(homePage);
|
|
|
|
|
if (homePage.BindingContext is HomeViewModel vm)
|
|
|
|
|
{
|
|
|
|
|
vm.StartLoginAction = () => DismissViewController(false, () => LaunchLoginFlow());
|
|
|
|
|
vm.StartRegisterAction = () => DismissViewController(false, () => LaunchRegisterFlow());
|
|
|
|
|
vm.StartSsoLoginAction = () => DismissViewController(false, () => LaunchLoginSsoFlow());
|
|
|
|
|
vm.StartEnvironmentAction = () => DismissViewController(false, () => LaunchEnvironmentFlow());
|
|
|
|
|
vm.CloseAction = () => CompleteRequest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var navigationPage = new NavigationPage(homePage);
|
|
|
|
|
var loginController = navigationPage.CreateViewController();
|
|
|
|
|
loginController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
|
|
|
|
|
PresentViewController(loginController, true, null);
|
2021-09-24 20:14:26 +02:00
|
|
|
|
|
|
|
|
|
LogoutIfAuthed();
|
2020-09-03 18:30:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LaunchEnvironmentFlow()
|
|
|
|
|
{
|
|
|
|
|
var environmentPage = new EnvironmentPage();
|
|
|
|
|
var app = new App.App(new AppOptions { IosExtension = true });
|
2022-02-23 18:40:17 +01:00
|
|
|
|
ThemeManager.SetTheme(app.Resources);
|
2020-09-03 18:30:40 +02:00
|
|
|
|
ThemeManager.ApplyResourcesToPage(environmentPage);
|
|
|
|
|
if (environmentPage.BindingContext is EnvironmentPageViewModel vm)
|
|
|
|
|
{
|
|
|
|
|
vm.SubmitSuccessAction = () => DismissViewController(false, () => LaunchHomePage());
|
|
|
|
|
vm.CloseAction = () => DismissViewController(false, () => LaunchHomePage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var navigationPage = new NavigationPage(environmentPage);
|
|
|
|
|
var loginController = navigationPage.CreateViewController();
|
|
|
|
|
loginController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
|
|
|
|
|
PresentViewController(loginController, true, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LaunchRegisterFlow()
|
|
|
|
|
{
|
|
|
|
|
var registerPage = new RegisterPage(null);
|
|
|
|
|
var app = new App.App(new AppOptions { IosExtension = true });
|
2022-02-23 18:40:17 +01:00
|
|
|
|
ThemeManager.SetTheme(app.Resources);
|
2020-09-03 18:30:40 +02:00
|
|
|
|
ThemeManager.ApplyResourcesToPage(registerPage);
|
|
|
|
|
if (registerPage.BindingContext is RegisterPageViewModel vm)
|
|
|
|
|
{
|
|
|
|
|
vm.RegistrationSuccess = () => DismissViewController(false, () => LaunchLoginFlow(vm.Email));
|
|
|
|
|
vm.CloseAction = () => DismissViewController(false, () => LaunchHomePage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var navigationPage = new NavigationPage(registerPage);
|
|
|
|
|
var loginController = navigationPage.CreateViewController();
|
|
|
|
|
loginController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
|
|
|
|
|
PresentViewController(loginController, true, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LaunchLoginFlow(string email = null)
|
|
|
|
|
{
|
|
|
|
|
var loginPage = new LoginPage(email);
|
2020-05-29 21:25:06 +02:00
|
|
|
|
var app = new App.App(new AppOptions { IosExtension = true });
|
2022-02-23 18:40:17 +01:00
|
|
|
|
ThemeManager.SetTheme(app.Resources);
|
2020-05-29 18:26:36 +02:00
|
|
|
|
ThemeManager.ApplyResourcesToPage(loginPage);
|
|
|
|
|
if (loginPage.BindingContext is LoginPageViewModel vm)
|
|
|
|
|
{
|
2020-09-03 18:30:40 +02:00
|
|
|
|
vm.StartTwoFactorAction = () => DismissViewController(false, () => LaunchTwoFactorFlow(false));
|
2021-09-24 20:14:26 +02:00
|
|
|
|
vm.UpdateTempPasswordAction = () => DismissViewController(false, () => LaunchUpdateTempPasswordFlow());
|
2020-09-03 18:30:40 +02:00
|
|
|
|
vm.LogInSuccessAction = () => DismissLockAndContinue();
|
|
|
|
|
vm.CloseAction = () => DismissViewController(false, () => LaunchHomePage());
|
2020-05-29 18:26:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var navigationPage = new NavigationPage(loginPage);
|
|
|
|
|
var loginController = navigationPage.CreateViewController();
|
|
|
|
|
loginController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
|
|
|
|
|
PresentViewController(loginController, true, null);
|
2021-09-24 20:14:26 +02:00
|
|
|
|
|
|
|
|
|
LogoutIfAuthed();
|
2020-05-29 18:26:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-03 18:30:40 +02:00
|
|
|
|
private void LaunchLoginSsoFlow()
|
|
|
|
|
{
|
|
|
|
|
var loginPage = new LoginSsoPage();
|
|
|
|
|
var app = new App.App(new AppOptions { IosExtension = true });
|
2022-02-23 18:40:17 +01:00
|
|
|
|
ThemeManager.SetTheme(app.Resources);
|
2020-09-03 18:30:40 +02:00
|
|
|
|
ThemeManager.ApplyResourcesToPage(loginPage);
|
|
|
|
|
if (loginPage.BindingContext is LoginSsoPageViewModel vm)
|
|
|
|
|
{
|
|
|
|
|
vm.StartTwoFactorAction = () => DismissViewController(false, () => LaunchTwoFactorFlow(true));
|
|
|
|
|
vm.StartSetPasswordAction = () => DismissViewController(false, () => LaunchSetPasswordFlow());
|
2021-09-24 20:14:26 +02:00
|
|
|
|
vm.UpdateTempPasswordAction = () => DismissViewController(false, () => LaunchUpdateTempPasswordFlow());
|
2020-09-03 18:30:40 +02:00
|
|
|
|
vm.SsoAuthSuccessAction = () => DismissLockAndContinue();
|
|
|
|
|
vm.CloseAction = () => DismissViewController(false, () => LaunchHomePage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var navigationPage = new NavigationPage(loginPage);
|
|
|
|
|
var loginController = navigationPage.CreateViewController();
|
|
|
|
|
loginController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
|
|
|
|
|
PresentViewController(loginController, true, null);
|
2021-09-24 20:14:26 +02:00
|
|
|
|
|
|
|
|
|
LogoutIfAuthed();
|
2020-09-03 18:30:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LaunchTwoFactorFlow(bool authingWithSso)
|
2020-05-29 18:26:36 +02:00
|
|
|
|
{
|
2020-09-03 18:30:40 +02:00
|
|
|
|
var twoFactorPage = new TwoFactorPage(authingWithSso);
|
2020-05-29 21:25:06 +02:00
|
|
|
|
var app = new App.App(new AppOptions { IosExtension = true });
|
2022-02-23 18:40:17 +01:00
|
|
|
|
ThemeManager.SetTheme(app.Resources);
|
2020-05-29 18:26:36 +02:00
|
|
|
|
ThemeManager.ApplyResourcesToPage(twoFactorPage);
|
|
|
|
|
if (twoFactorPage.BindingContext is TwoFactorPageViewModel vm)
|
|
|
|
|
{
|
2020-09-03 18:30:40 +02:00
|
|
|
|
vm.TwoFactorAuthSuccessAction = () => DismissLockAndContinue();
|
|
|
|
|
vm.StartSetPasswordAction = () => DismissViewController(false, () => LaunchSetPasswordFlow());
|
|
|
|
|
if (authingWithSso)
|
|
|
|
|
{
|
|
|
|
|
vm.CloseAction = () => DismissViewController(false, () => LaunchLoginSsoFlow());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vm.CloseAction = () => DismissViewController(false, () => LaunchLoginFlow());
|
|
|
|
|
}
|
2021-09-24 20:14:26 +02:00
|
|
|
|
vm.UpdateTempPasswordAction = () => DismissViewController(false, () => LaunchUpdateTempPasswordFlow());
|
2020-05-29 18:26:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var navigationPage = new NavigationPage(twoFactorPage);
|
|
|
|
|
var twoFactorController = navigationPage.CreateViewController();
|
|
|
|
|
twoFactorController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
|
|
|
|
|
PresentViewController(twoFactorController, true, null);
|
|
|
|
|
}
|
2020-09-03 18:30:40 +02:00
|
|
|
|
|
|
|
|
|
private void LaunchSetPasswordFlow()
|
|
|
|
|
{
|
|
|
|
|
var setPasswordPage = new SetPasswordPage();
|
|
|
|
|
var app = new App.App(new AppOptions { IosExtension = true });
|
2022-02-23 18:40:17 +01:00
|
|
|
|
ThemeManager.SetTheme(app.Resources);
|
2020-09-03 18:30:40 +02:00
|
|
|
|
ThemeManager.ApplyResourcesToPage(setPasswordPage);
|
|
|
|
|
if (setPasswordPage.BindingContext is SetPasswordPageViewModel vm)
|
|
|
|
|
{
|
2021-09-24 20:14:26 +02:00
|
|
|
|
vm.UpdateTempPasswordAction = () => DismissViewController(false, () => LaunchUpdateTempPasswordFlow());
|
2020-09-03 18:30:40 +02:00
|
|
|
|
vm.SetPasswordSuccessAction = () => DismissLockAndContinue();
|
|
|
|
|
vm.CloseAction = () => DismissViewController(false, () => LaunchHomePage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var navigationPage = new NavigationPage(setPasswordPage);
|
|
|
|
|
var setPasswordController = navigationPage.CreateViewController();
|
|
|
|
|
setPasswordController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
|
|
|
|
|
PresentViewController(setPasswordController, true, null);
|
|
|
|
|
}
|
2021-09-24 20:14:26 +02:00
|
|
|
|
|
|
|
|
|
private void LaunchUpdateTempPasswordFlow()
|
|
|
|
|
{
|
|
|
|
|
var updateTempPasswordPage = new UpdateTempPasswordPage();
|
|
|
|
|
var app = new App.App(new AppOptions { IosExtension = true });
|
2022-02-23 18:40:17 +01:00
|
|
|
|
ThemeManager.SetTheme(app.Resources);
|
2021-09-24 20:14:26 +02:00
|
|
|
|
ThemeManager.ApplyResourcesToPage(updateTempPasswordPage);
|
|
|
|
|
if (updateTempPasswordPage.BindingContext is UpdateTempPasswordPageViewModel vm)
|
|
|
|
|
{
|
|
|
|
|
vm.UpdateTempPasswordSuccessAction = () => DismissViewController(false, () => LaunchHomePage());
|
|
|
|
|
vm.LogOutAction = () => DismissViewController(false, () => LaunchHomePage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var navigationPage = new NavigationPage(updateTempPasswordPage);
|
|
|
|
|
var updateTempPasswordController = navigationPage.CreateViewController();
|
|
|
|
|
updateTempPasswordController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
|
|
|
|
|
PresentViewController(updateTempPasswordController, true, null);
|
|
|
|
|
}
|
2019-06-28 14:21:44 +02:00
|
|
|
|
}
|
2019-08-27 20:55:15 +02:00
|
|
|
|
}
|