Example #1
0
        public Cipher(CipherView obj)
        {
            OrganizationId = obj.OrganizationId;
            FolderId       = obj.FolderId;
            Type           = obj.Type;
            Name           = obj.Name;
            Notes          = obj.Notes;
            Favorite       = obj.Favorite;

            Fields = obj.Fields?.Select(f => new Field(f)).ToList();

            switch (obj.Type)
            {
            case CipherType.Login:
                Login = new Login(obj.Login);
                break;

            case CipherType.SecureNote:
                SecureNote = new SecureNote(obj.SecureNote);
                break;

            case CipherType.Card:
                Card = new Card(obj.Card);
                break;

            case CipherType.Identity:
                Identity = new Identity(obj.Identity);
                break;
            }
        }
        private string GetIcon(CipherView cipher)
        {
            string icon = null;

            switch (cipher.Type)
            {
            case CipherType.Login:
                icon = GetLoginIconGlyph(cipher);
                break;

            case CipherType.SecureNote:
                icon = "\uf24a";     // fa-sticky-note-o
                break;

            case CipherType.Card:
                icon = "\uf09d";     // fa-credit-card
                break;

            case CipherType.Identity:
                icon = "\uf2c3";     // fa-id-card-o
                break;

            default:
                break;
            }
            return(icon);
        }
Example #3
0
        public static string GetLoginIconImage(CipherView cipher)
        {
            string image = null;

            if (cipher.Login.HasUris)
            {
                foreach (var uri in cipher.Login.Uris)
                {
                    var hostnameUri = uri.Uri;
                    var isWebsite   = false;
                    if (!hostnameUri.Contains("."))
                    {
                        continue;
                    }
                    if (!hostnameUri.Contains("://"))
                    {
                        hostnameUri = string.Concat("http://", hostnameUri);
                    }
                    isWebsite = hostnameUri.StartsWith("http");

                    if (isWebsite)
                    {
                        image = GetIconUrl(hostnameUri);
                        break;
                    }
                }
            }
            return(image);
        }
 public ViewPageFieldViewModel(ViewPageViewModel vm, CipherView cipher, FieldView field)
 {
     _vm     = vm;
     _cipher = cipher;
     Field   = field;
     ToggleHiddenValueCommand = new Command(ToggleHiddenValue);
 }
Example #5
0
        private string GetIcon(CipherView cipher)
        {
            string icon = null;

            switch (cipher.Type)
            {
            case CipherType.Login:
                icon = GetLoginIconGlyph(cipher);
                break;

            case CipherType.SecureNote:
                icon = BitwardenIcons.StickyNote;
                break;

            case CipherType.Card:
                icon = BitwardenIcons.CreditCard;
                break;

            case CipherType.Identity:
                icon = BitwardenIcons.IdCard;
                break;

            default:
                break;
            }
            return(icon);
        }
Example #6
0
 public ViewPageFieldViewModel(ViewPageViewModel vm, CipherView cipher, FieldView field)
 {
     _i18nService             = ServiceContainer.Resolve <II18nService>("i18nService");
     _vm                      = vm;
     _cipher                  = cipher;
     Field                    = field;
     ToggleHiddenValueCommand = new Command(ToggleHiddenValue);
 }
Example #7
0
 public CipherViewModel(CipherView cipher)
 {
     Id       = cipher.Id;
     Name     = cipher.Name;
     Username = cipher.Login?.Username;
     Password = cipher.Login?.Password;
     Totp     = cipher.Login?.Totp;
     Uris     = cipher.Login?.Uris?.Select(u => new LoginUriModel(u)).ToList();
     Fields   = cipher.Fields?.Select(f => new Tuple <string, string>(f.Name, f.Value)).ToList();
 }
        private string GetIcon(CipherView cipher)
        {
            string icon = null;

            switch (cipher.Type)
            {
            case CipherType.Login:
                icon = GetLoginIconImage(cipher);
                break;

            default:
                break;
            }
            return(icon);
        }
Example #9
0
        private async Task CopyTotpAsync(CipherView cipher)
        {
            var autoCopyDisabled = await _storageService.GetAsync <bool?>(Constants.DisableAutoTotpCopyKey);

            var canAccessPremium = await ServiceContainer.Resolve <IUserService>("userService").CanAccessPremiumAsync();

            if ((canAccessPremium || cipher.OrganizationUseTotp) && !autoCopyDisabled.GetValueOrDefault() &&
                !string.IsNullOrWhiteSpace(cipher?.Login?.Totp))
            {
                var totp = await ServiceContainer.Resolve <ITotpService>("totpService").GetCodeAsync(cipher.Login.Totp);

                if (totp != null)
                {
                    CopyToClipboard(totp);
                }
            }
        }
Example #10
0
        string GetLoginIconGlyph(CipherView cipher)
        {
            var icon = BitwardenIcons.Globe;

            if (cipher.Login.Uri != null)
            {
                var hostnameUri = cipher.Login.Uri;
                if (hostnameUri.StartsWith(Constants.AndroidAppProtocol))
                {
                    icon = BitwardenIcons.Android;
                }
                else if (hostnameUri.StartsWith(Constants.iOSAppProtocol))
                {
                    icon = BitwardenIcons.Apple;
                }
            }
            return(icon);
        }
        string GetLoginIconGlyph(CipherView cipher)
        {
            var icon = "\uf0ac"; // fa-globe

            if (cipher.Login.Uri != null)
            {
                var hostnameUri = cipher.Login.Uri;
                if (hostnameUri.StartsWith(Constants.AndroidAppProtocol))
                {
                    icon = "\uf17b"; // fa-android
                }
                else if (hostnameUri.StartsWith(Constants.iOSAppProtocol))
                {
                    icon = "\uf179"; // fa-apple
                }
            }
            return(icon);
        }
Example #12
0
        private async Task CopyTotpAsync(CipherView cipher)
        {
            if (!string.IsNullOrWhiteSpace(cipher?.Login?.Totp))
            {
                var autoCopyDisabled = await _stateService.GetDisableAutoTotpCopyAsync();

                var canAccessPremium = await _stateService.CanAccessPremiumAsync();

                if ((canAccessPremium || cipher.OrganizationUseTotp) && !autoCopyDisabled.GetValueOrDefault())
                {
                    var totpService = ServiceContainer.Resolve <ITotpService>("totpService");
                    var totp        = await totpService.GetCodeAsync(cipher.Login.Totp);

                    if (totp != null)
                    {
                        await _clipboardService.CopyTextAsync(totp);
                    }
                }
            }
        }
Example #13
0
        public CipherView ToView(Cipher req, CipherView view = null)
        {
            if (view == null)
            {
                view = new CipherView();
            }

            view.Type     = req.Type;
            view.FolderId = req.FolderId;
            if (view.OrganizationId == null)
            {
                view.OrganizationId = req.OrganizationId;
            }

            view.Name     = req.Name;
            view.Notes    = req.Notes;
            view.Favorite = req.Favorite;

            view.Fields = req.Fields?.Select(f => Field.ToView(f)).ToList();

            switch (req.Type)
            {
            case CipherType.Login:
                view.Login = Login.ToView(req.Login);
                break;

            case CipherType.SecureNote:
                view.SecureNote = SecureNote.ToView(req.SecureNote);
                break;

            case CipherType.Card:
                view.Card = Card.ToView(req.Card);
                break;

            case CipherType.Identity:
                view.Identity = Identity.ToView(req.Identity);
                break;
            }

            return(view);
        }
        string GetLoginIconImage(CipherView cipher)
        {
            string image = null;

            if (cipher.Login.Uri != null)
            {
                var hostnameUri = cipher.Login.Uri;
                var isWebsite   = false;

                if (!hostnameUri.Contains("://") && hostnameUri.Contains("."))
                {
                    hostnameUri = string.Concat("http://", hostnameUri);
                    isWebsite   = true;
                }
                else
                {
                    isWebsite = hostnameUri.StartsWith("http") && hostnameUri.Contains(".");
                }

                if (isWebsite)
                {
                    var hostname = CoreHelpers.GetHostname(hostnameUri);
                    var iconsUrl = _environmentService.IconsUrl;
                    if (string.IsNullOrWhiteSpace(iconsUrl))
                    {
                        if (!string.IsNullOrWhiteSpace(_environmentService.BaseUrl))
                        {
                            iconsUrl = string.Format("{0}/icons", _environmentService.BaseUrl);
                        }
                        else
                        {
                            iconsUrl = "https://icons.bitwarden.net";
                        }
                    }
                    image = string.Format("{0}/{1}/icon.png", iconsUrl, hostname);
                }
            }
            return(image);
        }
Example #15
0
        public static ASPasswordCredentialIdentity ToCredentialIdentity(CipherView cipher)
        {
            if (!cipher?.Login?.Uris?.Any() ?? true)
            {
                return(null);
            }
            var uri = cipher.Login.Uris.FirstOrDefault(u => u.Match != Bit.Core.Enums.UriMatchType.Never)?.Uri;

            if (string.IsNullOrWhiteSpace(uri))
            {
                return(null);
            }
            var username = cipher.Login.Username;

            if (string.IsNullOrWhiteSpace(username))
            {
                return(null);
            }
            var serviceId = new ASCredentialServiceIdentifier(uri, ASCredentialServiceIdentifierType.Url);

            return(new ASPasswordCredentialIdentity(serviceId, username, cipher.Id));
        }
Example #16
0
        public FilledItem(CipherView cipher)
        {
            Name     = cipher.Name;
            Type     = cipher.Type;
            Subtitle = cipher.SubTitle;

            switch (Type)
            {
            case CipherType.Login:
                Icon      = Resource.Drawable.login;
                _password = cipher.Login.Password;
                break;

            case CipherType.Card:
                _cardNumber   = cipher.Card.Number;
                Icon          = Resource.Drawable.card;
                _cardName     = cipher.Card.CardholderName;
                _cardCode     = cipher.Card.Code;
                _cardExpMonth = cipher.Card.ExpMonth;
                _cardExpYear  = cipher.Card.ExpYear;
                break;

            case CipherType.Identity:
                Icon          = Resource.Drawable.id;
                _idPhone      = cipher.Identity.Phone;
                _idEmail      = cipher.Identity.Email;
                _idUsername   = cipher.Identity.Username;
                _idAddress    = cipher.Identity.FullAddress;
                _idPostalCode = cipher.Identity.PostalCode;
                break;

            default:
                Icon = Resource.Drawable.login;
                break;
            }
        }
Example #17
0
 public void Autofill(CipherView cipher)
 {
     throw new NotImplementedException();
 }
Example #18
0
        public async Task <CipherView> DecryptAsync()
        {
            var model = new CipherView(this);

            await DecryptObjAsync(model, this, new HashSet <string>
            {
                "Name",
                "Notes"
            }, OrganizationId);

            switch (Type)
            {
            case Enums.CipherType.Login:
                model.Login = await Login.DecryptAsync(OrganizationId);

                break;

            case Enums.CipherType.SecureNote:
                model.SecureNote = await SecureNote.DecryptAsync(OrganizationId);

                break;

            case Enums.CipherType.Card:
                model.Card = await Card.DecryptAsync(OrganizationId);

                break;

            case Enums.CipherType.Identity:
                model.Identity = await Identity.DecryptAsync(OrganizationId);

                break;

            default:
                break;
            }

            if (Attachments?.Any() ?? false)
            {
                model.Attachments = new List <AttachmentView>();
                var tasks = new List <Task>();
                async Task decryptAndAddAttachmentAsync(Attachment attachment)
                {
                    var decAttachment = await attachment.DecryptAsync(OrganizationId);

                    model.Attachments.Add(decAttachment);
                }

                foreach (var attachment in Attachments)
                {
                    tasks.Add(decryptAndAddAttachmentAsync(attachment));
                }
                await Task.WhenAll(tasks);
            }
            if (Fields?.Any() ?? false)
            {
                model.Fields = new List <FieldView>();
                var tasks = new List <Task>();
                async Task decryptAndAddFieldAsync(Field field)
                {
                    var decField = await field.DecryptAsync(OrganizationId);

                    model.Fields.Add(decField);
                }

                foreach (var field in Fields)
                {
                    tasks.Add(decryptAndAddFieldAsync(field));
                }
                await Task.WhenAll(tasks);
            }
            if (PasswordHistory?.Any() ?? false)
            {
                model.PasswordHistory = new List <PasswordHistoryView>();
                var tasks = new List <Task>();
                async Task decryptAndAddHistoryAsync(PasswordHistory ph)
                {
                    var decPh = await ph.DecryptAsync(OrganizationId);

                    model.PasswordHistory.Add(decPh);
                }

                foreach (var ph in PasswordHistory)
                {
                    tasks.Add(decryptAndAddHistoryAsync(ph));
                }
                await Task.WhenAll(tasks);
            }
            return(model);
        }
Example #19
0
        public void Autofill(CipherView cipher)
        {
            var activity = (MainActivity)CrossCurrentActivity.Current.Activity;

            if (activity.Intent.GetBooleanExtra("autofillFramework", false))
            {
                if (cipher == null)
                {
                    activity.SetResult(Result.Canceled);
                    activity.Finish();
                    return;
                }
                var structure = activity.Intent.GetParcelableExtra(
                    AutofillManager.ExtraAssistStructure) as AssistStructure;
                if (structure == null)
                {
                    activity.SetResult(Result.Canceled);
                    activity.Finish();
                    return;
                }
                var parser = new Parser(structure, activity.ApplicationContext);
                parser.Parse();
                if (!parser.FieldCollection.Fields.Any() || string.IsNullOrWhiteSpace(parser.Uri))
                {
                    activity.SetResult(Result.Canceled);
                    activity.Finish();
                    return;
                }
                var task        = CopyTotpAsync(cipher);
                var dataset     = AutofillHelpers.BuildDataset(activity, parser.FieldCollection, new FilledItem(cipher));
                var replyIntent = new Intent();
                replyIntent.PutExtra(AutofillManager.ExtraAuthenticationResult, dataset);
                activity.SetResult(Result.Ok, replyIntent);
                activity.Finish();
            }
            else
            {
                var data = new Intent();
                if (cipher == null)
                {
                    data.PutExtra("canceled", "true");
                }
                else
                {
                    var task = CopyTotpAsync(cipher);
                    data.PutExtra("uri", cipher.Login.Uri);
                    data.PutExtra("username", cipher.Login.Username);
                    data.PutExtra("password", cipher.Login.Password);
                }
                if (activity.Parent == null)
                {
                    activity.SetResult(Result.Ok, data);
                }
                else
                {
                    activity.Parent.SetResult(Result.Ok, data);
                }
                activity.Finish();
                _messagingService.Send("finishMainActivity");
            }
        }
Example #20
0
 public CipherWithId(CipherView obj) : base(obj)
 {
     Id            = obj.Id;
     CollectionIds = obj.CollectionIds;
 }
Example #21
0
        public static async Task <string> CipherListOptions(ContentPage page, CipherView cipher, IPasswordRepromptService passwordRepromptService)
        {
            var platformUtilsService = ServiceContainer.Resolve <IPlatformUtilsService>("platformUtilsService");
            var eventService         = ServiceContainer.Resolve <IEventService>("eventService");
            var vaultTimeoutService  = ServiceContainer.Resolve <IVaultTimeoutService>("vaultTimeoutService");
            var options = new List <string> {
                AppResources.View
            };

            if (!cipher.IsDeleted)
            {
                options.Add(AppResources.Edit);
            }
            if (cipher.Type == Core.Enums.CipherType.Login)
            {
                if (!string.IsNullOrWhiteSpace(cipher.Login.Username))
                {
                    options.Add(AppResources.CopyUsername);
                }
                if (!string.IsNullOrWhiteSpace(cipher.Login.Password) && cipher.ViewPassword)
                {
                    options.Add(AppResources.CopyPassword);
                }
                if (!string.IsNullOrWhiteSpace(cipher.Login.Totp))
                {
                    var userService      = ServiceContainer.Resolve <IUserService>("userService");
                    var canAccessPremium = await userService.CanAccessPremiumAsync();

                    if (canAccessPremium || cipher.OrganizationUseTotp)
                    {
                        options.Add(AppResources.CopyTotp);
                    }
                }
                if (cipher.Login.CanLaunch)
                {
                    options.Add(AppResources.Launch);
                }
            }
            else if (cipher.Type == Core.Enums.CipherType.Card)
            {
                if (!string.IsNullOrWhiteSpace(cipher.Card.Number))
                {
                    options.Add(AppResources.CopyNumber);
                }
                if (!string.IsNullOrWhiteSpace(cipher.Card.Code))
                {
                    options.Add(AppResources.CopySecurityCode);
                }
            }
            else if (cipher.Type == Core.Enums.CipherType.SecureNote)
            {
                if (!string.IsNullOrWhiteSpace(cipher.Notes))
                {
                    options.Add(AppResources.CopyNotes);
                }
            }
            var selection = await page.DisplayActionSheet(cipher.Name, AppResources.Cancel, null, options.ToArray());

            if (await vaultTimeoutService.IsLockedAsync())
            {
                platformUtilsService.ShowToast("info", null, AppResources.VaultIsLocked);
            }
            else if (selection == AppResources.View)
            {
                await page.Navigation.PushModalAsync(new NavigationPage(new ViewPage(cipher.Id)));
            }
            else if (selection == AppResources.Edit)
            {
                if (cipher.Reprompt == CipherRepromptType.None || await passwordRepromptService.ShowPasswordPromptAsync())
                {
                    await page.Navigation.PushModalAsync(new NavigationPage(new AddEditPage(cipher.Id)));
                }
            }
            else if (selection == AppResources.CopyUsername)
            {
                await platformUtilsService.CopyToClipboardAsync(cipher.Login.Username);

                platformUtilsService.ShowToast("info", null,
                                               string.Format(AppResources.ValueHasBeenCopied, AppResources.Username));
            }
            else if (selection == AppResources.CopyPassword)
            {
                if (cipher.Reprompt == CipherRepromptType.None || await passwordRepromptService.ShowPasswordPromptAsync())
                {
                    await platformUtilsService.CopyToClipboardAsync(cipher.Login.Password);

                    platformUtilsService.ShowToast("info", null,
                                                   string.Format(AppResources.ValueHasBeenCopied, AppResources.Password));
                    var task = eventService.CollectAsync(Core.Enums.EventType.Cipher_ClientCopiedPassword, cipher.Id);
                }
            }
            else if (selection == AppResources.CopyTotp)
            {
                if (cipher.Reprompt == CipherRepromptType.None || await passwordRepromptService.ShowPasswordPromptAsync())
                {
                    var totpService = ServiceContainer.Resolve <ITotpService>("totpService");
                    var totp        = await totpService.GetCodeAsync(cipher.Login.Totp);

                    if (!string.IsNullOrWhiteSpace(totp))
                    {
                        await platformUtilsService.CopyToClipboardAsync(totp);

                        platformUtilsService.ShowToast("info", null,
                                                       string.Format(AppResources.ValueHasBeenCopied, AppResources.VerificationCodeTotp));
                    }
                }
            }
            else if (selection == AppResources.Launch)
            {
                platformUtilsService.LaunchUri(cipher.Login.LaunchUri);
            }
            else if (selection == AppResources.CopyNumber)
            {
                if (cipher.Reprompt == CipherRepromptType.None || await passwordRepromptService.ShowPasswordPromptAsync())
                {
                    await platformUtilsService.CopyToClipboardAsync(cipher.Card.Number);

                    platformUtilsService.ShowToast("info", null,
                                                   string.Format(AppResources.ValueHasBeenCopied, AppResources.Number));
                }
            }
            else if (selection == AppResources.CopySecurityCode)
            {
                if (cipher.Reprompt == CipherRepromptType.None || await passwordRepromptService.ShowPasswordPromptAsync())
                {
                    await platformUtilsService.CopyToClipboardAsync(cipher.Card.Code);

                    platformUtilsService.ShowToast("info", null,
                                                   string.Format(AppResources.ValueHasBeenCopied, AppResources.SecurityCode));
                    var task = eventService.CollectAsync(Core.Enums.EventType.Cipher_ClientCopiedCardCode, cipher.Id);
                }
            }
            else if (selection == AppResources.CopyNotes)
            {
                await platformUtilsService.CopyToClipboardAsync(cipher.Notes);

                platformUtilsService.ShowToast("info", null,
                                               string.Format(AppResources.ValueHasBeenCopied, AppResources.Notes));
            }
            return(selection);
        }
Example #22
0
 public CipherViewCellViewModel(CipherView cipherView, bool websiteIconsEnabled)
 {
     Cipher = cipherView;
     WebsiteIconsEnabled = websiteIconsEnabled;
 }
        protected async Task SaveAsync()
        {
            /*
             * if (!_connectivity.IsConnected)
             * {
             *  AlertNoConnection();
             *  return;
             * }
             */

            if (string.IsNullOrWhiteSpace(PasswordCell?.TextField?.Text))
            {
                DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
                                                                            AppResources.Password), AppResources.Ok);
                return;
            }

            if (string.IsNullOrWhiteSpace(NameCell?.TextField?.Text))
            {
                DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
                                                                            AppResources.Name), AppResources.Ok);
                return;
            }

            var cipher = new CipherView
            {
                Name     = NameCell.TextField.Text,
                Notes    = string.IsNullOrWhiteSpace(NotesCell?.TextView?.Text) ? null : NotesCell.TextView.Text,
                Favorite = FavoriteCell.Switch.On,
                FolderId = FolderCell.SelectedIndex == 0 ?
                           null : _folders.ElementAtOrDefault(FolderCell.SelectedIndex - 1)?.Id,
                Type  = Bit.Core.Enums.CipherType.Login,
                Login = new LoginView
                {
                    Uris     = null,
                    Username = string.IsNullOrWhiteSpace(UsernameCell?.TextField?.Text) ?
                               null : UsernameCell.TextField.Text,
                    Password = string.IsNullOrWhiteSpace(PasswordCell.TextField.Text) ?
                               null : PasswordCell.TextField.Text,
                }
            };

            if (!string.IsNullOrWhiteSpace(UriCell?.TextField?.Text))
            {
                cipher.Login.Uris = new List <LoginUriView>
                {
                    new LoginUriView
                    {
                        Uri = UriCell.TextField.Text
                    }
                };
            }

            var loadingAlert = Dialogs.CreateLoadingAlert(AppResources.Saving);

            PresentViewController(loadingAlert, true, null);
            try
            {
                var cipherDomain = await _cipherService.EncryptAsync(cipher);

                await _cipherService.SaveWithServerAsync(cipherDomain);

                await loadingAlert.DismissViewControllerAsync(true);

                await _storageService.SaveAsync(Bit.Core.Constants.ClearCiphersCacheKey, true);

                if (await ASHelpers.IdentitiesCanIncremental())
                {
                    var identity = await ASHelpers.GetCipherIdentityAsync(cipherDomain.Id);

                    if (identity != null)
                    {
                        await ASCredentialIdentityStore.SharedStore.SaveCredentialIdentitiesAsync(
                            new ASPasswordCredentialIdentity[] { identity });
                    }
                }
                else
                {
                    await ASHelpers.ReplaceAllIdentities();
                }
                Success(cipherDomain.Id);
            }
            catch (ApiException e)
            {
                if (e?.Error != null)
                {
                    DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok);
                }
            }
        }
Example #24
0
        public static async Task <string> CipherListOptions(ContentPage page, CipherView cipher)
        {
            var platformUtilsService = ServiceContainer.Resolve <IPlatformUtilsService>("platformUtilsService");
            var options = new List <string> {
                AppResources.View, AppResources.Edit
            };

            if (cipher.Type == Core.Enums.CipherType.Login)
            {
                if (!string.IsNullOrWhiteSpace(cipher.Login.Username))
                {
                    options.Add(AppResources.CopyUsername);
                }
                if (!string.IsNullOrWhiteSpace(cipher.Login.Password))
                {
                    options.Add(AppResources.CopyPassword);
                }
                if (!string.IsNullOrWhiteSpace(cipher.Login.Totp))
                {
                    options.Add(AppResources.CopyTotp);
                }
                if (cipher.Login.CanLaunch)
                {
                    options.Add(AppResources.Launch);
                }
            }
            else if (cipher.Type == Core.Enums.CipherType.Card)
            {
                if (!string.IsNullOrWhiteSpace(cipher.Card.Number))
                {
                    options.Add(AppResources.CopyNumber);
                }
                if (!string.IsNullOrWhiteSpace(cipher.Card.Code))
                {
                    options.Add(AppResources.CopySecurityCode);
                }
            }
            else if (cipher.Type == Core.Enums.CipherType.SecureNote)
            {
                if (!string.IsNullOrWhiteSpace(cipher.Notes))
                {
                    options.Add(AppResources.CopyNotes);
                }
            }
            var selection = await page.DisplayActionSheet(cipher.Name, AppResources.Cancel, null, options.ToArray());

            if (selection == AppResources.View)
            {
                await page.Navigation.PushModalAsync(new NavigationPage(new ViewPage(cipher.Id)));
            }
            else if (selection == AppResources.Edit)
            {
                await page.Navigation.PushModalAsync(new NavigationPage(new AddEditPage(cipher.Id)));
            }
            else if (selection == AppResources.CopyUsername)
            {
                await platformUtilsService.CopyToClipboardAsync(cipher.Login.Username);

                platformUtilsService.ShowToast("info", null,
                                               string.Format(AppResources.ValueHasBeenCopied, AppResources.Username));
            }
            else if (selection == AppResources.CopyPassword)
            {
                await platformUtilsService.CopyToClipboardAsync(cipher.Login.Password);

                platformUtilsService.ShowToast("info", null,
                                               string.Format(AppResources.ValueHasBeenCopied, AppResources.Password));
            }
            else if (selection == AppResources.CopyTotp)
            {
                var totpService = ServiceContainer.Resolve <ITotpService>("totpService");
                var totp        = await totpService.GetCodeAsync(cipher.Login.Totp);

                if (!string.IsNullOrWhiteSpace(totp))
                {
                    await platformUtilsService.CopyToClipboardAsync(totp);

                    platformUtilsService.ShowToast("info", null,
                                                   string.Format(AppResources.ValueHasBeenCopied, AppResources.VerificationCodeTotp));
                }
            }
            else if (selection == AppResources.Launch)
            {
                platformUtilsService.LaunchUri(cipher.Login.LaunchUri);
            }
            else if (selection == AppResources.CopyNumber)
            {
                await platformUtilsService.CopyToClipboardAsync(cipher.Card.Number);

                platformUtilsService.ShowToast("info", null,
                                               string.Format(AppResources.ValueHasBeenCopied, AppResources.Number));
            }
            else if (selection == AppResources.CopySecurityCode)
            {
                await platformUtilsService.CopyToClipboardAsync(cipher.Card.Code);

                platformUtilsService.ShowToast("info", null,
                                               string.Format(AppResources.ValueHasBeenCopied, AppResources.SecurityCode));
            }
            else if (selection == AppResources.CopyNotes)
            {
                await platformUtilsService.CopyToClipboardAsync(cipher.Notes);

                platformUtilsService.ShowToast("info", null,
                                               string.Format(AppResources.ValueHasBeenCopied, AppResources.Notes));
            }
            return(selection);
        }
Example #25
0
        private void BuildCommonCipher(ExportCipher cipher, CipherView c)
        {
            cipher.Type   = null;
            cipher.Name   = c.Name;
            cipher.Notes  = c.Notes;
            cipher.Fields = null;
            // Login props
            cipher.LoginUris     = null;
            cipher.LoginUsername = null;
            cipher.LoginPassword = null;
            cipher.LoginTotp     = null;

            if (c.Fields != null)
            {
                foreach (var f in c.Fields)
                {
                    if (cipher.Fields == null)
                    {
                        cipher.Fields = "";
                    }
                    else
                    {
                        cipher.Fields += "\n";
                    }

                    cipher.Fields += (f.Name ?? "") + ": " + f.Value;
                }
            }

            switch (c.Type)
            {
            case CipherType.Login:
                cipher.Type          = "login";
                cipher.LoginUsername = c.Login.Username;
                cipher.LoginPassword = c.Login.Password;
                cipher.LoginTotp     = c.Login.Totp;

                if (c.Login.Uris != null)
                {
                    foreach (var u in c.Login.Uris)
                    {
                        if (cipher.LoginUris == null)
                        {
                            cipher.LoginUris = "";
                        }
                        else
                        {
                            cipher.LoginUris += ",";
                        }

                        cipher.LoginUris += u.Uri;
                    }
                }

                break;

            case CipherType.SecureNote:
                cipher.Type = "note";
                break;

            default:
                return;
            }
        }