private void ProvideCredential()
        {
            var cipherService = Resolver.Resolve <ICipherService>();
            var cipher        = cipherService.GetByIdAsync(_context.CredentialIdentity.RecordIdentifier).GetAwaiter().GetResult();

            if (cipher == null || cipher.Type != App.Enums.CipherType.Login)
            {
                var err = new NSError(new NSString("ASExtensionErrorDomain"),
                                      Convert.ToInt32(ASExtensionErrorCode.CredentialIdentityNotFound), null);
                ExtensionContext.CancelRequest(err);
                return;
            }

            string totpCode = null;

            if (!_settings.GetValueOrDefault(App.Constants.SettingDisableTotpCopy, false))
            {
                var totpKey = cipher.Login.Totp?.Decrypt(cipher.OrganizationId);
                if (!string.IsNullOrWhiteSpace(totpKey))
                {
                    totpCode = Crypto.Totp(totpKey);
                }
            }

            CompleteRequest(cipher.Login.Username?.Decrypt(cipher.OrganizationId),
                            cipher.Login.Password?.Decrypt(cipher.OrganizationId), totpCode);
        }
        private async Task ProvideCredentialAsync()
        {
            var cipherService = ServiceContainer.Resolve <ICipherService>("cipherService", true);
            var cipher        = await cipherService?.GetAsync(_context.CredentialIdentity.RecordIdentifier);

            if (cipher == null || cipher.Type != Bit.Core.Enums.CipherType.Login)
            {
                var err = new NSError(new NSString("ASExtensionErrorDomain"),
                                      Convert.ToInt32(ASExtensionErrorCode.CredentialIdentityNotFound), null);
                ExtensionContext.CancelRequest(err);
                return;
            }

            var storageService = ServiceContainer.Resolve <IStorageService>("storageService");
            var decCipher      = await cipher.DecryptAsync();

            string totpCode        = null;
            var    disableTotpCopy = await storageService.GetAsync <bool?>(Bit.Core.Constants.DisableAutoTotpCopyKey);

            if (!disableTotpCopy.GetValueOrDefault(false))
            {
                var userService           = ServiceContainer.Resolve <IUserService>("userService");
                var canAccessPremiumAsync = await userService.CanAccessPremiumAsync();

                if (!string.IsNullOrWhiteSpace(decCipher.Login.Totp) &&
                    (canAccessPremiumAsync || cipher.OrganizationUseTotp))
                {
                    var totpService = ServiceContainer.Resolve <ITotpService>("totpService");
                    totpCode = await totpService.GetCodeAsync(decCipher.Login.Totp);
                }
            }

            CompleteRequest(decCipher.Id, decCipher.Login.Username, decCipher.Login.Password, totpCode);
        }
Esempio n. 3
0
 public override void ProvideCredentialWithoutUserInteraction(ASPasswordCredentialIdentity credentialIdentity)
 {
     if (!IsAuthed() || IsLocked())
     {
         var err = new NSError(new NSString("ASExtensionErrorDomain"),
                               Convert.ToInt32(ASExtensionErrorCode.UserInteractionRequired), null);
         ExtensionContext.CancelRequest(err);
         return;
     }
     _context.CredentialIdentity = credentialIdentity;
     ProvideCredentialAsync().GetAwaiter().GetResult();
 }
 public override async void ProvideCredentialWithoutUserInteraction(ASPasswordCredentialIdentity credentialIdentity)
 {
     InitAppIfNeeded();
     if (!await IsAuthed() || await IsLocked())
     {
         var err = new NSError(new NSString("ASExtensionErrorDomain"),
                               Convert.ToInt32(ASExtensionErrorCode.UserInteractionRequired), null);
         ExtensionContext.CancelRequest(err);
         return;
     }
     _context.CredentialIdentity = credentialIdentity;
     await ProvideCredentialAsync();
 }
Esempio n. 5
0
        public override async void ProvideCredentialWithoutUserInteraction(ASPasswordCredentialIdentity credentialIdentity)
        {
            InitAppIfNeeded();
            var storageService = ServiceContainer.Resolve <IStorageService>("storageService");
            await storageService.SaveAsync(Bit.Core.Constants.PasswordRepromptAutofillKey, false);

            await storageService.SaveAsync(Bit.Core.Constants.PasswordVerifiedAutofillKey, false);

            if (!await IsAuthed() || await IsLocked())
            {
                var err = new NSError(new NSString("ASExtensionErrorDomain"),
                                      Convert.ToInt32(ASExtensionErrorCode.UserInteractionRequired), null);
                ExtensionContext.CancelRequest(err);
                return;
            }
            _context.CredentialIdentity = credentialIdentity;
            await ProvideCredentialAsync(false);
        }
        public override void ProvideCredentialWithoutUserInteraction(ASPasswordCredentialIdentity credentialIdentity)
        {
            bool canGetCredentials = false;
            var  authService       = Resolver.Resolve <IAuthService>();

            if (authService.IsAuthenticated)
            {
                var lockService = Resolver.Resolve <ILockService>();
                var lockType    = lockService.GetLockTypeAsync(false).GetAwaiter().GetResult();
                canGetCredentials = lockType == App.Enums.LockType.Fingerprint || lockType == App.Enums.LockType.None;
            }

            if (!canGetCredentials)
            {
                var err = new NSError(new NSString("ASExtensionErrorDomain"),
                                      Convert.ToInt32(ASExtensionErrorCode.UserInteractionRequired), null);
                ExtensionContext.CancelRequest(err);
                return;
            }
            _context.CredentialIdentity = credentialIdentity;
            ProvideCredential();
        }
        public void CompleteRequest(string username = null, string password = null, string totp = null)
        {
            if (_context.Configuring)
            {
                ExtensionContext.CompleteExtensionConfigurationRequest();
                return;
            }

            if (string.IsNullOrWhiteSpace(username) && string.IsNullOrWhiteSpace(password))
            {
                _googleAnalyticsService.TrackAutofillExtensionEvent("Canceled");
                var err = new NSError(new NSString("ASExtensionErrorDomain"),
                                      Convert.ToInt32(ASExtensionErrorCode.UserCanceled), null);
                _googleAnalyticsService.Dispatch(() =>
                {
                    NSRunLoop.Main.BeginInvokeOnMainThread(() =>
                    {
                        ExtensionContext.CancelRequest(err);
                    });
                });
                return;
            }

            if (!string.IsNullOrWhiteSpace(totp))
            {
                UIPasteboard.General.String = totp;
            }

            _googleAnalyticsService.TrackAutofillExtensionEvent("AutoFilled");
            var cred = new ASPasswordCredential(username, password);

            _googleAnalyticsService.Dispatch(() =>
            {
                NSRunLoop.Main.BeginInvokeOnMainThread(() =>
                {
                    ExtensionContext.CompleteRequest(cred, null);
                });
            });
        }
 public override async void ProvideCredentialWithoutUserInteraction(ASPasswordCredentialIdentity credentialIdentity)
 {
     try
     {
         InitAppIfNeeded();
         await _stateService.Value.SetPasswordRepromptAutofillAsync(false);
         await _stateService.Value.SetPasswordVerifiedAutofillAsync(false);
         if (!await IsAuthed() || await IsLocked())
         {
             var err = new NSError(new NSString("ASExtensionErrorDomain"),
                 Convert.ToInt32(ASExtensionErrorCode.UserInteractionRequired), null);
             ExtensionContext.CancelRequest(err);
             return;
         }
         _context.CredentialIdentity = credentialIdentity;
         await ProvideCredentialAsync(false);
     }
     catch (Exception ex)
     {
         LoggerHelper.LogEvenIfCantBeResolved(ex);
         throw;
     }
 }
        public void CompleteRequest(string id       = null, string username = null,
                                    string password = null, string totp     = null)
        {
            if ((_context?.Configuring ?? true) && string.IsNullOrWhiteSpace(password))
            {
                ServiceContainer.Reset();
                ExtensionContext?.CompleteExtensionConfigurationRequest();
                return;
            }

            if (_context == null || string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
            {
                ServiceContainer.Reset();
                var err = new NSError(new NSString("ASExtensionErrorDomain"),
                                      Convert.ToInt32(ASExtensionErrorCode.UserCanceled), null);
                NSRunLoop.Main.BeginInvokeOnMainThread(() => ExtensionContext?.CancelRequest(err));
                return;
            }

            if (!string.IsNullOrWhiteSpace(totp))
            {
                UIPasteboard.General.String = totp;
            }

            var cred = new ASPasswordCredential(username, password);

            NSRunLoop.Main.BeginInvokeOnMainThread(async() =>
            {
                if (!string.IsNullOrWhiteSpace(id))
                {
                    var eventService = ServiceContainer.Resolve <IEventService>("eventService");
                    await eventService.CollectAsync(Bit.Core.Enums.EventType.Cipher_ClientAutofilled, id);
                }
                ServiceContainer.Reset();
                ExtensionContext?.CompleteRequest(cred, null);
            });
        }
Esempio n. 10
0
        private async Task ProvideCredentialAsync(bool userInteraction = true)
        {
            var cipherService = ServiceContainer.Resolve <ICipherService>("cipherService", true);

            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)
            {
                var err = new NSError(new NSString("ASExtensionErrorDomain"),
                                      Convert.ToInt32(ASExtensionErrorCode.CredentialIdentityNotFound), null);
                ExtensionContext?.CancelRequest(err);
                return;
            }

            var storageService = ServiceContainer.Resolve <IStorageService>("storageService");
            var decCipher      = await cipher.DecryptAsync();

            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)
                {
                    await storageService.SaveAsync(Bit.Core.Constants.PasswordRepromptAutofillKey, true);

                    var err = new NSError(new NSString("ASExtensionErrorDomain"),
                                          Convert.ToInt32(ASExtensionErrorCode.UserInteractionRequired), null);
                    ExtensionContext?.CancelRequest(err);
                    return;
                }
                else if (!await storageService.GetAsync <bool>(Bit.Core.Constants.PasswordVerifiedAutofillKey))
                {
                    // Add a timeout to resolve keyboard not always showing up.
                    await Task.Delay(250);

                    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;
                    }
                }
            }
            string totpCode        = null;
            var    disableTotpCopy = await storageService.GetAsync <bool?>(Bit.Core.Constants.DisableAutoTotpCopyKey);

            if (!disableTotpCopy.GetValueOrDefault(false))
            {
                var userService           = ServiceContainer.Resolve <IUserService>("userService");
                var canAccessPremiumAsync = await userService.CanAccessPremiumAsync();

                if (!string.IsNullOrWhiteSpace(decCipher.Login.Totp) &&
                    (canAccessPremiumAsync || cipher.OrganizationUseTotp))
                {
                    var totpService = ServiceContainer.Resolve <ITotpService>("totpService");
                    totpCode = await totpService.GetCodeAsync(decCipher.Login.Totp);
                }
            }

            CompleteRequest(decCipher.Id, decCipher.Login.Username, decCipher.Login.Password, totpCode);
        }
        partial void Send(Foundation.NSObject sender)
        {
            NSError cancelError = NSError.FromDomain(NSError.CocoaErrorDomain, 3072, null);

            ExtensionContext.CancelRequest(cancelError);
        }
Esempio n. 12
0
 public void UserDidCancelSetup()
 {
     ExtensionContext.CancelRequest(new NSError(new NSString("YourAppDomain"), -1, null));
 }
Esempio n. 13
0
 private void UserDidCancelSetup()
 {
     // Tell ReplayKit that the extension was cancelled by the user
     ExtensionContext.CancelRequest(new NSError(new NSString("com.google.AppRTCMobile"), -1));
 }
 partial void OnCancelClicked(UIButton sender)
 {
     // Cancel the request
     ExtensionContext.CancelRequest(new NSError((NSString)"ImageInverterErrorDomain", 0));
 }