1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-26 12:16:07 +01:00

[PM-3811] Passkeys unification (#2774)

* PM-3811 Unified passkeys view and moved both inside Login as an array of FIdo2Key

* PM-3811 Passkeys unification => updated cipher details view an helpers

* PM-3811 Updated passkeys creation date time format
This commit is contained in:
Federico Maccaroni 2023-09-22 11:55:35 -03:00 committed by GitHub
parent 6ef6cf5d84
commit a4a0d31fc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 7367 additions and 5018 deletions

View File

@ -37,7 +37,7 @@ namespace Bit.App.Pages
set => SetProperty(ref _cipher, value, additionalPropertyNames: AdditionalPropertiesToRaiseOnCipherChanged);
}
public string CreationDate => string.Format(AppResources.CreatedX, Cipher.CreationDate.ToShortDateString());
public string CreationDate => string.Format(AppResources.CreatedXY, Cipher.CreationDate.ToShortDateString(), Cipher.CreationDate.ToShortTimeString());
public AsyncCommand CheckPasswordCommand { get; }

View File

@ -229,9 +229,9 @@
Margin="0,10,0,0"
IsVisible="{Binding ShowPasskeyInfo}"/>
<Entry
Text="{u:I18n AvailableForTwoStepLogin}"
Text="{Binding CreationDate}"
IsEnabled="False"
StyleClass="box-value,text-muted"
StyleClass="box-value,text-muted"
IsVisible="{Binding ShowPasskeyInfo}" />
<Grid StyleClass="box-row, box-row-input">
@ -650,38 +650,6 @@
AutomationId="IdentityCountryEntry" />
</StackLayout>
</StackLayout>
<StackLayout IsVisible="{Binding IsFido2Key}" Spacing="0" Padding="0">
<Label
Text="{u:I18n Username}"
StyleClass="box-label"
Margin="0,10,0,0"/>
<Entry
x:Name="_fido2KeyUsernameEntry"
Text="{Binding Cipher.Fido2Key.UserName}"
StyleClass="box-value"
Grid.Row="1"/>
<Label
Text="{u:I18n Passkey}"
StyleClass="box-label"
Margin="0,10,0,0"/>
<Entry
Text="{Binding CreationDate}"
IsEnabled="False"
StyleClass="box-value,text-muted" />
<Label
Text="{u:I18n Application}"
StyleClass="box-label"
Margin="0,10,0,0"/>
<Entry
Text="{Binding Cipher.Fido2Key.LaunchUri}"
IsEnabled="False"
StyleClass="box-value,text-muted" />
<Label
Text="{u:I18n YouCannotEditPasskeyApplicationBecauseItWouldInvalidateThePasskey}"
StyleClass="box-sub-label" />
</StackLayout>
</StackLayout>
<StackLayout StyleClass="box" IsVisible="{Binding IsLogin}">
<StackLayout StyleClass="box-row-header">

View File

@ -296,7 +296,6 @@ namespace Bit.App.Pages
public bool IsIdentity => Cipher?.Type == CipherType.Identity;
public bool IsCard => Cipher?.Type == CipherType.Card;
public bool IsSecureNote => Cipher?.Type == CipherType.SecureNote;
public bool IsFido2Key => Cipher?.Type == CipherType.Fido2Key;
public bool ShowUris => IsLogin && Cipher.Login.HasUris;
public bool ShowAttachments => Cipher.HasAttachments;
public string ShowPasswordIcon => ShowPassword ? BitwardenIcons.EyeSlash : BitwardenIcons.Eye;
@ -309,7 +308,7 @@ namespace Bit.App.Pages
public string PasswordVisibilityAccessibilityText => ShowPassword ? AppResources.PasswordIsVisibleTapToHide : AppResources.PasswordIsNotVisibleTapToShow;
public bool HasTotpValue => IsLogin && !string.IsNullOrEmpty(Cipher?.Login?.Totp);
public string SetupTotpText => $"{BitwardenIcons.Camera} {AppResources.SetupTotp}";
public bool ShowPasskeyInfo => Cipher?.Login?.Fido2Key != null && !CloneMode;
public bool ShowPasskeyInfo => Cipher?.HasFido2Key == true && !CloneMode;
public void Init()
{
@ -371,7 +370,7 @@ namespace Bit.App.Pages
if (Cipher.Type == CipherType.Login)
{
// passkeys can't be cloned
Cipher.Login.Fido2Key = null;
Cipher.Login.Fido2Keys = null;
}
}
if (appOptions?.OtpData != null && Cipher.Type == CipherType.Login)

View File

@ -199,12 +199,12 @@
Text="{u:I18n Passkey}"
StyleClass="box-label"
Margin="0,10,0,0"
IsVisible="{Binding Cipher.Login.Fido2Key, Converter={StaticResource notNull}}"/>
IsVisible="{Binding Cipher.Login.MainFido2Key, Converter={StaticResource notNull}}"/>
<Entry
Text="{u:I18n AvailableForTwoStepLogin}"
Text="{Binding CreationDate}"
IsEnabled="False"
StyleClass="box-value,text-muted"
IsVisible="{Binding Cipher.Login.Fido2Key, Converter={StaticResource notNull}}" />
IsVisible="{Binding Cipher.Login.MainFido2Key, Converter={StaticResource notNull}}" />
<Grid StyleClass="box-row"
IsVisible="{Binding ShowTotp}"
AutomationId="ItemRow">
@ -579,64 +579,6 @@
</StackLayout>
<BoxView StyleClass="box-row-separator" IsVisible="{Binding ShowIdentityAddress}" />
</StackLayout>
<StackLayout
IsVisible="{Binding IsFido2Key}"
Spacing="0"
Padding="0"
Margin="0,10,0,0">
<Label
Text="{u:I18n Username}"
StyleClass="box-label" />
<Label
Text="{Binding Cipher.Fido2Key.UserName, Mode=OneWay}"
StyleClass="box-value" />
<BoxView StyleClass="box-row-separator" Margin="0,10,0,0" />
<Label
Text="{u:I18n Passkey}"
StyleClass="box-label"
Margin="0,10,0,0" />
<Label
Text="{Binding CreationDate, Mode=OneWay}"
StyleClass="box-value" />
<BoxView StyleClass="box-row-separator" Margin="0,10,0,0" />
<Grid
StyleClass="box-row"
RowDefinitions="Auto,*,Auto"
ColumnDefinitions="*,Auto,Auto">
<Label
Text="{u:I18n Application}"
StyleClass="box-label" />
<Label
Grid.Row="1"
Text="{Binding Cipher.Fido2Key.LaunchUri, Mode=OneWay}"
StyleClass="box-value" />
<controls:IconButton
StyleClass="box-row-button, box-row-button-platform"
Text="{Binding Source={x:Static core:BitwardenIcons.ShareSquare}}"
Command="{Binding LaunchUriCommand}"
CommandParameter="{Binding Cipher.Fido2Key}"
Grid.Column="1"
Grid.RowSpan="2"
VerticalOptions="End"
IsVisible="{Binding Cipher.Fido2Key.CanLaunch, Mode=OneWay}"
AutomationProperties.IsInAccessibleTree="True"
AutomationProperties.Name="{u:I18n Launch}" />
<controls:IconButton
StyleClass="box-row-button, box-row-button-platform"
Text="{Binding Source={x:Static core:BitwardenIcons.Clone}}"
Command="{Binding CopyCommand}"
CommandParameter="Fido2KeyApplication"
Grid.Column="2"
Grid.RowSpan="2"
AutomationProperties.IsInAccessibleTree="True"
AutomationProperties.Name="{u:I18n CopyApplication}" />
<BoxView
StyleClass="box-row-separator"
Margin="0,3,0,0"
Grid.Row="2"
Grid.ColumnSpan="3" />
</Grid>
</StackLayout>
</StackLayout>
<StackLayout StyleClass="box" IsVisible="{Binding ShowUris}">
<StackLayout StyleClass="box-row-header">

View File

@ -148,7 +148,6 @@ namespace Bit.App.Pages
public bool IsIdentity => Cipher?.Type == Core.Enums.CipherType.Identity;
public bool IsCard => Cipher?.Type == Core.Enums.CipherType.Card;
public bool IsSecureNote => Cipher?.Type == Core.Enums.CipherType.SecureNote;
public bool IsFido2Key => Cipher?.Type == Core.Enums.CipherType.Fido2Key;
public FormattedString ColoredPassword => GeneratedValueFormatter.Format(Cipher.Login.Password);
public FormattedString UpdatedText
{
@ -649,11 +648,6 @@ namespace Bit.App.Pages
text = Cipher.Card.Code;
name = AppResources.SecurityCode;
}
else if (id == "Fido2KeyApplication")
{
text = Cipher.Fido2Key?.LaunchUri;
name = AppResources.Application;
}
if (text != null)
{
@ -708,18 +702,12 @@ namespace Bit.App.Pages
private async Task<bool> CanCloneAsync()
{
if (Cipher.Type == CipherType.Fido2Key)
if (!Cipher.HasFido2Key)
{
await _platformUtilsService.ShowDialogAsync(AppResources.PasskeyWillNotBeCopied);
return false;
return true;
}
if (Cipher.Type == CipherType.Login && Cipher.Login?.Fido2Key != null)
{
return await _platformUtilsService.ShowDialogAsync(AppResources.ThePasskeyWillNotBeCopiedToTheClonedItemDoYouWantToContinueCloningThisItem, AppResources.PasskeyWillNotBeCopied, AppResources.Yes, AppResources.No);
}
return true;
return await _platformUtilsService.ShowDialogAsync(AppResources.ThePasskeyWillNotBeCopiedToTheClonedItemDoYouWantToContinueCloningThisItem, AppResources.PasskeyWillNotBeCopied, AppResources.Yes, AppResources.No);
}
}
}

View File

@ -60,9 +60,6 @@ namespace Bit.App.Pages
case CipherType.Identity:
_name = AppResources.TypeIdentity;
break;
case CipherType.Fido2Key:
_name = AppResources.Passkey;
break;
default:
break;
}
@ -111,9 +108,6 @@ namespace Bit.App.Pages
case CipherType.Identity:
_icon = BitwardenIcons.IdCard;
break;
case CipherType.Fido2Key:
_icon = BitwardenIcons.Passkey;
break;
default:
_icon = BitwardenIcons.Globe;
break;

View File

@ -569,7 +569,7 @@ namespace Bit.App.Pages
{
Filter = c => !c.IsDeleted
&&
Type.Value.IsEqualToOrCanSignIn(c.Type);
Type.Value == c.Type;
}
else if (FolderId != null)
{
@ -636,9 +636,7 @@ namespace Bit.App.Pages
NoFolderCiphers.Add(c);
}
// Fido2Key ciphers should be counted as Login ciphers
var countType = c.Type == CipherType.Fido2Key ? CipherType.Login : c.Type;
_typeCounts[countType] = _typeCounts.TryGetValue(countType, out var currentTypeCount)
_typeCounts[c.Type] = _typeCounts.TryGetValue(c.Type, out var currentTypeCount)
? currentTypeCount + 1
: 1;
}

File diff suppressed because it is too large Load Diff

View File

@ -2657,7 +2657,7 @@ Do you want to switch to this account?</value>
</data>
<data name="CreatedX" xml:space="preserve">
<value>Created {0}</value>
<comment>To state the date in which the cipher was created: Created 03/21/2023</comment>
<comment>DEPRECATED To state the date in which the cipher was created: Created 03/21/2023</comment>
</data>
<data name="Application" xml:space="preserve">
<value>Application</value>
@ -2765,6 +2765,10 @@ Do you want to switch to this account?</value>
<data name="LoggingInOn" xml:space="preserve">
<value>Logging in on</value>
</data>
<data name="CreatedXY" xml:space="preserve">
<value>Created {0}, {1}</value>
<comment>To state the date/time in which the cipher was created: Created 03/21/2023, 09:25 AM. First parameter is the date and the second parameter is the time.</comment>
</data>
<data name="TooManyAttempts" xml:space="preserve">
<value>Too many attempts</value>
</data>

View File

@ -79,17 +79,6 @@ namespace Bit.App.Utilities
options.Add(AppResources.CopyNotes);
}
}
if (cipher.Type == Core.Enums.CipherType.Fido2Key)
{
if (!string.IsNullOrWhiteSpace(cipher.Fido2Key.UserName))
{
options.Add(AppResources.CopyUsername);
}
if (cipher.Fido2Key.CanLaunch)
{
options.Add(AppResources.Launch);
}
}
var selection = await page.DisplayActionSheet(cipher.Name, AppResources.Cancel, null, options.ToArray());
if (await vaultTimeoutService.IsLockedAsync())
@ -108,7 +97,7 @@ namespace Bit.App.Utilities
}
else if (selection == AppResources.CopyUsername)
{
await clipboardService.CopyTextAsync(cipher.Type == CipherType.Login ? cipher.Login.Username : cipher.Fido2Key.UserName);
await clipboardService.CopyTextAsync(cipher.Login.Username);
platformUtilsService.ShowToastForCopiedValue(AppResources.Username);
}
else if (selection == AppResources.CopyPassword

View File

@ -18,8 +18,6 @@ namespace Bit.App.Utilities
return BitwardenIcons.CreditCard;
case CipherType.Identity:
return BitwardenIcons.IdCard;
case CipherType.Fido2Key:
return BitwardenIcons.Passkey;
}
return null;
}

View File

@ -26,14 +26,12 @@ namespace Bit.App.Utilities
{
public static string GetIconImage(CipherView cipher)
{
switch (cipher.Type)
if (cipher.Type != CipherType.Login)
{
case CipherType.Login:
return IconImageHelper.GetLoginIconImage(cipher);
case CipherType.Fido2Key:
return IconImageHelper.GetFido2KeyIconImage(cipher);
return null;
}
return null;
return GetLoginIconImage(cipher);
}
public static string GetLoginIconImage(CipherView cipher)
@ -65,26 +63,6 @@ namespace Bit.App.Utilities
return image;
}
public static string GetFido2KeyIconImage(CipherView cipher)
{
var hostnameUri = cipher.Fido2Key.LaunchUri;
if (!hostnameUri.Contains("."))
{
return null;
}
if (!hostnameUri.Contains("://"))
{
hostnameUri = string.Concat("https://", hostnameUri);
}
if (hostnameUri.StartsWith("http"))
{
return GetIconUrl(hostnameUri);
}
return null;
}
private static string GetIconUrl(string hostnameUri)
{
IEnvironmentService _environmentService = ServiceContainer.Resolve<IEnvironmentService>("environmentService");

View File

@ -7,7 +7,6 @@
Login = 1,
SecureNote = 2,
Card = 3,
Identity = 4,
Fido2Key = 5
Identity = 4
}
}

View File

@ -1,5 +1,4 @@
using Bit.Core.Models.Domain;
using Bit.Core.Models.Export;
namespace Bit.Core.Models.Api
{
@ -11,7 +10,8 @@ namespace Bit.Core.Models.Api
public Fido2KeyApi(Fido2Key fido2Key)
{
NonDiscoverableId = fido2Key.NonDiscoverableId?.EncryptedString;
CredentialId = fido2Key.CredentialId?.EncryptedString;
Discoverable = fido2Key.Discoverable?.EncryptedString;
KeyType = fido2Key.KeyType?.EncryptedString;
KeyAlgorithm = fido2Key.KeyAlgorithm?.EncryptedString;
KeyCurve = fido2Key.KeyCurve?.EncryptedString;
@ -23,7 +23,8 @@ namespace Bit.Core.Models.Api
Counter = fido2Key.Counter?.EncryptedString;
}
public string NonDiscoverableId { get; set; }
public string CredentialId { get; set; }
public string Discoverable { get; set; }
public string KeyType { get; set; } = Constants.DefaultFido2KeyType;
public string KeyAlgorithm { get; set; } = Constants.DefaultFido2KeyAlgorithm;
public string KeyCurve { get; set; } = Constants.DefaultFido2KeyCurve;

View File

@ -10,6 +10,6 @@ namespace Bit.Core.Models.Api
public string Password { get; set; }
public DateTime? PasswordRevisionDate { get; set; }
public string Totp { get; set; }
public Fido2KeyApi Fido2Key { get; set; }
public List<Fido2KeyApi> Fido2Keys { get; set; }
}
}

View File

@ -45,9 +45,6 @@ namespace Bit.Core.Models.Data
case Enums.CipherType.Identity:
Identity = new IdentityData(response.Identity);
break;
case Enums.CipherType.Fido2Key:
Fido2Key = new Fido2KeyData(response.Fido2Key);
break;
default:
break;
}
@ -86,7 +83,6 @@ namespace Bit.Core.Models.Data
public SecureNoteData SecureNote { get; set; }
public CardData Card { get; set; }
public IdentityData Identity { get; set; }
public Fido2KeyData Fido2Key { get; set; }
public List<FieldData> Fields { get; set; }
public List<AttachmentData> Attachments { get; set; }
public List<PasswordHistoryData> PasswordHistory { get; set; }

View File

@ -8,7 +8,8 @@ namespace Bit.Core.Models.Data
public Fido2KeyData(Fido2KeyApi apiData)
{
NonDiscoverableId = apiData.NonDiscoverableId;
CredentialId = apiData.CredentialId;
Discoverable = apiData.Discoverable;
KeyType = apiData.KeyType;
KeyAlgorithm = apiData.KeyAlgorithm;
KeyCurve = apiData.KeyCurve;
@ -20,7 +21,8 @@ namespace Bit.Core.Models.Data
Counter = apiData.Counter;
}
public string NonDiscoverableId { get; set; }
public string CredentialId { get; set; }
public string Discoverable { get; set; }
public string KeyType { get; set; } = Constants.DefaultFido2KeyType;
public string KeyAlgorithm { get; set; } = Constants.DefaultFido2KeyAlgorithm;
public string KeyCurve { get; set; } = Constants.DefaultFido2KeyCurve;

View File

@ -16,7 +16,7 @@ namespace Bit.Core.Models.Data
PasswordRevisionDate = data.PasswordRevisionDate;
Totp = data.Totp;
Uris = data.Uris?.Select(u => new LoginUriData(u)).ToList();
Fido2Key = data.Fido2Key != null ? new Fido2KeyData(data.Fido2Key) : null;
Fido2Keys = data.Fido2Keys?.Select(f => new Fido2KeyData(f)).ToList();
}
public List<LoginUriData> Uris { get; set; }
@ -24,6 +24,6 @@ namespace Bit.Core.Models.Data
public string Password { get; set; }
public DateTime? PasswordRevisionDate { get; set; }
public string Totp { get; set; }
public Fido2KeyData Fido2Key { get; set; }
public List<Fido2KeyData> Fido2Keys { get; set; }
}
}

View File

@ -48,9 +48,6 @@ namespace Bit.Core.Models.Domain
case Enums.CipherType.Identity:
Identity = new Identity(obj.Identity, alreadyEncrypted);
break;
case CipherType.Fido2Key:
Fido2Key = new Fido2Key(obj.Fido2Key, alreadyEncrypted);
break;
default:
break;
}
@ -66,7 +63,7 @@ namespace Bit.Core.Models.Domain
public string FolderId { get; set; }
public EncString Name { get; set; }
public EncString Notes { get; set; }
public Enums.CipherType Type { get; set; }
public CipherType Type { get; set; }
public bool Favorite { get; set; }
public bool OrganizationUseTotp { get; set; }
public bool Edit { get; set; }
@ -79,7 +76,6 @@ namespace Bit.Core.Models.Domain
public Identity Identity { get; set; }
public Card Card { get; set; }
public SecureNote SecureNote { get; set; }
public Fido2Key Fido2Key { get; set; }
public List<Attachment> Attachments { get; set; }
public List<Field> Fields { get; set; }
public List<PasswordHistory> PasswordHistory { get; set; }
@ -109,9 +105,6 @@ namespace Bit.Core.Models.Domain
case Enums.CipherType.Identity:
model.Identity = await Identity.DecryptAsync(OrganizationId);
break;
case Enums.CipherType.Fido2Key:
model.Fido2Key = await Fido2Key.DecryptAsync(OrganizationId);
break;
default:
break;
}
@ -201,9 +194,6 @@ namespace Bit.Core.Models.Domain
case Enums.CipherType.Identity:
c.Identity = Identity.ToIdentityData();
break;
case Enums.CipherType.Fido2Key:
c.Fido2Key = Fido2Key.ToFido2KeyData();
break;
default:
break;
}

View File

@ -9,7 +9,8 @@ namespace Bit.Core.Models.Domain
{
public static HashSet<string> EncryptableProperties => new HashSet<string>
{
nameof(NonDiscoverableId),
nameof(CredentialId),
nameof(Discoverable),
nameof(KeyType),
nameof(KeyAlgorithm),
nameof(KeyCurve),
@ -28,7 +29,8 @@ namespace Bit.Core.Models.Domain
BuildDomainModel(this, data, EncryptableProperties, alreadyEncrypted);
}
public EncString NonDiscoverableId { get; set; }
public EncString CredentialId { get; set; }
public EncString Discoverable { get; set; }
public EncString KeyType { get; set; }
public EncString KeyAlgorithm { get; set; }
public EncString KeyCurve { get; set; }

View File

@ -15,7 +15,7 @@ namespace Bit.Core.Models.Domain
{
PasswordRevisionDate = obj.PasswordRevisionDate;
Uris = obj.Uris?.Select(u => new LoginUri(u, alreadyEncrypted)).ToList();
Fido2Key = obj.Fido2Key != null ? new Fido2Key(obj.Fido2Key, alreadyEncrypted) : null;
Fido2Keys = obj.Fido2Keys?.Select(f => new Fido2Key(f, alreadyEncrypted)).ToList();
BuildDomainModel(this, obj, new HashSet<string>
{
"Username",
@ -29,7 +29,7 @@ namespace Bit.Core.Models.Domain
public EncString Password { get; set; }
public DateTime? PasswordRevisionDate { get; set; }
public EncString Totp { get; set; }
public Fido2Key Fido2Key { get; set; }
public List<Fido2Key> Fido2Keys { get; set; }
public async Task<LoginView> DecryptAsync(string orgId)
{
@ -47,9 +47,13 @@ namespace Bit.Core.Models.Domain
view.Uris.Add(await uri.DecryptAsync(orgId));
}
}
if (Fido2Key != null)
if (Fido2Keys != null)
{
view.Fido2Key = await Fido2Key.DecryptAsync(orgId);
view.Fido2Keys = new List<Fido2KeyView>();
foreach (var fido2Key in Fido2Keys)
{
view.Fido2Keys.Add(await fido2Key.DecryptAsync(orgId));
}
}
return view;
}
@ -68,9 +72,9 @@ namespace Bit.Core.Models.Domain
{
l.Uris = Uris.Select(u => u.ToLoginUriData()).ToList();
}
if (Fido2Key != null)
if (Fido2Keys != null)
{
l.Fido2Key = Fido2Key.ToFido2KeyData();
l.Fido2Keys = Fido2Keys.Select(f => f.ToFido2KeyData()).ToList();
}
return l;
}

View File

@ -31,7 +31,7 @@ namespace Bit.Core.Models.Request
Password = cipher.Login.Password?.EncryptedString,
PasswordRevisionDate = cipher.Login.PasswordRevisionDate,
Totp = cipher.Login.Totp?.EncryptedString,
Fido2Key = cipher.Login.Fido2Key != null ? new Fido2KeyApi(cipher.Login.Fido2Key) : null
Fido2Keys = cipher.Login.Fido2Keys?.Select(f => new Fido2KeyApi(f)).ToList()
};
break;
case CipherType.Card:
@ -74,9 +74,6 @@ namespace Bit.Core.Models.Request
Type = cipher.SecureNote.Type
};
break;
case CipherType.Fido2Key:
Fido2Key = new Fido2KeyApi(cipher.Fido2Key);
break;
default:
break;
}
@ -122,7 +119,6 @@ namespace Bit.Core.Models.Request
public SecureNoteApi SecureNote { get; set; }
public CardApi Card { get; set; }
public IdentityApi Identity { get; set; }
public Fido2KeyApi Fido2Key { get; set; }
public List<FieldApi> Fields { get; set; }
public List<PasswordHistoryRequest> PasswordHistory { get; set; }
public Dictionary<string, string> Attachments { get; set; }

View File

@ -18,7 +18,6 @@ namespace Bit.Core.Models.Response
public CardApi Card { get; set; }
public IdentityApi Identity { get; set; }
public SecureNoteApi SecureNote { get; set; }
public Fido2KeyApi Fido2Key { get; set; }
public bool Favorite { get; set; }
public bool Edit { get; set; }
public bool ViewPassword { get; set; } = true; // Fallback for old server versions

View File

@ -43,7 +43,6 @@ namespace Bit.Core.Models.View
public IdentityView Identity { get; set; }
public CardView Card { get; set; }
public SecureNoteView SecureNote { get; set; }
public Fido2KeyView Fido2Key { get; set; }
public List<AttachmentView> Attachments { get; set; }
public List<FieldView> Fields { get; set; }
public List<PasswordHistoryView> PasswordHistory { get; set; }
@ -67,8 +66,6 @@ namespace Bit.Core.Models.View
return Card;
case CipherType.Identity:
return Identity;
case CipherType.Fido2Key:
return Fido2Key;
default:
break;
}
@ -115,12 +112,14 @@ namespace Bit.Core.Models.View
return LinkedFieldOptions.Find(lfo => lfo.Value == id).Key;
}
public string ComparableName => Name + Login?.Username + Fido2Key?.UserName;
public string ComparableName => Name + Login?.Username;
public bool CanLaunch => Login?.CanLaunch == true || Fido2Key?.CanLaunch == true;
public bool CanLaunch => Login?.CanLaunch == true;
public string LaunchUri => Login?.LaunchUri ?? Fido2Key?.LaunchUri;
public string LaunchUri => Login?.LaunchUri;
public bool IsClonable => OrganizationId is null && Type != CipherType.Fido2Key;
public bool IsClonable => OrganizationId is null;
public bool HasFido2Key => Type == CipherType.Login && Login?.HasFido2Keys == true;
}
}

View File

@ -5,7 +5,8 @@ namespace Bit.Core.Models.View
{
public class Fido2KeyView : ItemView, ILaunchableView
{
public string NonDiscoverableId { get; set; }
public string CredentialId { get; set; }
public string Discoverable { get; set; }
public string KeyType { get; set; } = Constants.DefaultFido2KeyType;
public string KeyAlgorithm { get; set; } = Constants.DefaultFido2KeyAlgorithm;
public string KeyCurve { get; set; } = Constants.DefaultFido2KeyCurve;
@ -18,6 +19,7 @@ namespace Bit.Core.Models.View
public override string SubTitle => UserName;
public override List<KeyValuePair<string, LinkedIdType>> LinkedFieldOptions => new List<KeyValuePair<string, LinkedIdType>>();
public bool IsDiscoverable => !string.IsNullOrWhiteSpace(Discoverable);
public bool CanLaunch => !string.IsNullOrEmpty(RpId);
public string LaunchUri => $"https://{RpId}";

View File

@ -20,7 +20,7 @@ namespace Bit.Core.Models.View
public DateTime? PasswordRevisionDate { get; set; }
public string Totp { get; set; }
public List<LoginUriView> Uris { get; set; }
public Fido2KeyView Fido2Key { get; set; }
public List<Fido2KeyView> Fido2Keys { get; set; }
public string Uri => HasUris ? Uris[0].Uri : null;
public string MaskedPassword => Password != null ? "••••••••" : null;
@ -28,6 +28,8 @@ namespace Bit.Core.Models.View
public bool CanLaunch => HasUris && Uris.Any(u => u.CanLaunch);
public string LaunchUri => HasUris ? Uris.FirstOrDefault(u => u.CanLaunch)?.LaunchUri : null;
public bool HasUris => (Uris?.Count ?? 0) > 0;
public bool HasFido2Keys => Fido2Keys?.Any() == true;
public Fido2KeyView MainFido2Key => HasFido2Keys ? Fido2Keys[0] : null;
public override List<KeyValuePair<string, LinkedIdType>> LinkedFieldOptions
{

View File

@ -549,28 +549,15 @@ namespace Bit.Core.Services
private async Task<bool> ValidateCanBeSharedWithOrgAsync(CipherView cipher, string organizationId)
{
if (cipher.Login?.Fido2Key is null && cipher.Fido2Key is null)
if (!cipher.HasFido2Key)
{
return true;
}
var decCiphers = await GetAllDecryptedAsync();
var orgCiphers = decCiphers.Where(c => c.OrganizationId == organizationId);
if (cipher.Login?.Fido2Key != null)
{
return !orgCiphers.Any(c => !cipher.Login.Fido2Key.IsUniqueAgainst(c.Login?.Fido2Key)
||
!cipher.Login.Fido2Key.IsUniqueAgainst(c.Fido2Key));
}
if (cipher.Fido2Key != null)
{
return !orgCiphers.Any(c => !cipher.Fido2Key.IsUniqueAgainst(c.Login?.Fido2Key)
||
!cipher.Fido2Key.IsUniqueAgainst(c.Fido2Key));
}
return true;
return !decCiphers
.Where(c => c.OrganizationId == organizationId)
.Any(c => !cipher.Login.MainFido2Key.IsUniqueAgainst(c.Login?.MainFido2Key));
}
public async Task<Cipher> SaveAttachmentRawWithServerAsync(Cipher cipher, string filename, byte[] data)
@ -1132,10 +1119,15 @@ namespace Bit.Core.Services
cipher.Login.Uris.Add(loginUri);
}
}
if (model.Login.Fido2Key != null)
if (model.Login.HasFido2Keys)
{
cipher.Login.Fido2Key = new Fido2Key();
await EncryptObjPropertyAsync(model.Login.Fido2Key, cipher.Login.Fido2Key, Fido2Key.EncryptableProperties, key);
cipher.Login.Fido2Keys = new List<Fido2Key>();
foreach (var fido2Key in model.Login.Fido2Keys)
{
var fido2KeyDomain = new Fido2Key();
await EncryptObjPropertyAsync(fido2Key, fido2KeyDomain, Fido2Key.EncryptableProperties, key);
cipher.Login.Fido2Keys.Add(fido2KeyDomain);
}
}
break;
case CipherType.SecureNote:
@ -1180,10 +1172,6 @@ namespace Bit.Core.Services
"LicenseNumber"
}, key);
break;
case CipherType.Fido2Key:
cipher.Fido2Key = new Fido2Key();
await EncryptObjPropertyAsync(model.Fido2Key, cipher.Fido2Key, Fido2Key.EncryptableProperties, key);
break;
default:
throw new Exception("Unknown cipher type.");
}

View File

@ -1,14 +0,0 @@
using Bit.Core.Enums;
namespace Bit.Core.Utilities
{
public static class CipherTypeExtensions
{
public static bool IsEqualToOrCanSignIn(this CipherType type, CipherType type2)
{
return type == type2
||
(type == CipherType.Login && type2 == CipherType.Fido2Key);
}
}
}