1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-18 01:03:24 +00: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
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); 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; } public AsyncCommand CheckPasswordCommand { get; }

View File

@@ -229,7 +229,7 @@
Margin="0,10,0,0" Margin="0,10,0,0"
IsVisible="{Binding ShowPasskeyInfo}"/> IsVisible="{Binding ShowPasskeyInfo}"/>
<Entry <Entry
Text="{u:I18n AvailableForTwoStepLogin}" Text="{Binding CreationDate}"
IsEnabled="False" IsEnabled="False"
StyleClass="box-value,text-muted" StyleClass="box-value,text-muted"
IsVisible="{Binding ShowPasskeyInfo}" /> IsVisible="{Binding ShowPasskeyInfo}" />
@@ -650,38 +650,6 @@
AutomationId="IdentityCountryEntry" /> AutomationId="IdentityCountryEntry" />
</StackLayout> </StackLayout>
</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>
<StackLayout StyleClass="box" IsVisible="{Binding IsLogin}"> <StackLayout StyleClass="box" IsVisible="{Binding IsLogin}">
<StackLayout StyleClass="box-row-header"> <StackLayout StyleClass="box-row-header">

View File

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

View File

@@ -199,12 +199,12 @@
Text="{u:I18n Passkey}" Text="{u:I18n Passkey}"
StyleClass="box-label" StyleClass="box-label"
Margin="0,10,0,0" Margin="0,10,0,0"
IsVisible="{Binding Cipher.Login.Fido2Key, Converter={StaticResource notNull}}"/> IsVisible="{Binding Cipher.Login.MainFido2Key, Converter={StaticResource notNull}}"/>
<Entry <Entry
Text="{u:I18n AvailableForTwoStepLogin}" Text="{Binding CreationDate}"
IsEnabled="False" IsEnabled="False"
StyleClass="box-value,text-muted" 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" <Grid StyleClass="box-row"
IsVisible="{Binding ShowTotp}" IsVisible="{Binding ShowTotp}"
AutomationId="ItemRow"> AutomationId="ItemRow">
@@ -579,64 +579,6 @@
</StackLayout> </StackLayout>
<BoxView StyleClass="box-row-separator" IsVisible="{Binding ShowIdentityAddress}" /> <BoxView StyleClass="box-row-separator" IsVisible="{Binding ShowIdentityAddress}" />
</StackLayout> </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>
<StackLayout StyleClass="box" IsVisible="{Binding ShowUris}"> <StackLayout StyleClass="box" IsVisible="{Binding ShowUris}">
<StackLayout StyleClass="box-row-header"> <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 IsIdentity => Cipher?.Type == Core.Enums.CipherType.Identity;
public bool IsCard => Cipher?.Type == Core.Enums.CipherType.Card; public bool IsCard => Cipher?.Type == Core.Enums.CipherType.Card;
public bool IsSecureNote => Cipher?.Type == Core.Enums.CipherType.SecureNote; 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 ColoredPassword => GeneratedValueFormatter.Format(Cipher.Login.Password);
public FormattedString UpdatedText public FormattedString UpdatedText
{ {
@@ -649,11 +648,6 @@ namespace Bit.App.Pages
text = Cipher.Card.Code; text = Cipher.Card.Code;
name = AppResources.SecurityCode; name = AppResources.SecurityCode;
} }
else if (id == "Fido2KeyApplication")
{
text = Cipher.Fido2Key?.LaunchUri;
name = AppResources.Application;
}
if (text != null) if (text != null)
{ {
@@ -708,18 +702,12 @@ namespace Bit.App.Pages
private async Task<bool> CanCloneAsync() private async Task<bool> CanCloneAsync()
{ {
if (Cipher.Type == CipherType.Fido2Key) if (!Cipher.HasFido2Key)
{ {
await _platformUtilsService.ShowDialogAsync(AppResources.PasskeyWillNotBeCopied);
return false;
}
if (Cipher.Type == CipherType.Login && Cipher.Login?.Fido2Key != null)
{
return await _platformUtilsService.ShowDialogAsync(AppResources.ThePasskeyWillNotBeCopiedToTheClonedItemDoYouWantToContinueCloningThisItem, AppResources.PasskeyWillNotBeCopied, AppResources.Yes, AppResources.No);
}
return true; 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: case CipherType.Identity:
_name = AppResources.TypeIdentity; _name = AppResources.TypeIdentity;
break; break;
case CipherType.Fido2Key:
_name = AppResources.Passkey;
break;
default: default:
break; break;
} }
@@ -111,9 +108,6 @@ namespace Bit.App.Pages
case CipherType.Identity: case CipherType.Identity:
_icon = BitwardenIcons.IdCard; _icon = BitwardenIcons.IdCard;
break; break;
case CipherType.Fido2Key:
_icon = BitwardenIcons.Passkey;
break;
default: default:
_icon = BitwardenIcons.Globe; _icon = BitwardenIcons.Globe;
break; break;

View File

@@ -569,7 +569,7 @@ namespace Bit.App.Pages
{ {
Filter = c => !c.IsDeleted Filter = c => !c.IsDeleted
&& &&
Type.Value.IsEqualToOrCanSignIn(c.Type); Type.Value == c.Type;
} }
else if (FolderId != null) else if (FolderId != null)
{ {
@@ -636,9 +636,7 @@ namespace Bit.App.Pages
NoFolderCiphers.Add(c); NoFolderCiphers.Add(c);
} }
// Fido2Key ciphers should be counted as Login ciphers _typeCounts[c.Type] = _typeCounts.TryGetValue(c.Type, out var currentTypeCount)
var countType = c.Type == CipherType.Fido2Key ? CipherType.Login : c.Type;
_typeCounts[countType] = _typeCounts.TryGetValue(countType, out var currentTypeCount)
? currentTypeCount + 1 ? currentTypeCount + 1
: 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>
<data name="CreatedX" xml:space="preserve"> <data name="CreatedX" xml:space="preserve">
<value>Created {0}</value> <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>
<data name="Application" xml:space="preserve"> <data name="Application" xml:space="preserve">
<value>Application</value> <value>Application</value>
@@ -2765,6 +2765,10 @@ Do you want to switch to this account?</value>
<data name="LoggingInOn" xml:space="preserve"> <data name="LoggingInOn" xml:space="preserve">
<value>Logging in on</value> <value>Logging in on</value>
</data> </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"> <data name="TooManyAttempts" xml:space="preserve">
<value>Too many attempts</value> <value>Too many attempts</value>
</data> </data>

View File

@@ -79,17 +79,6 @@ namespace Bit.App.Utilities
options.Add(AppResources.CopyNotes); 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()); var selection = await page.DisplayActionSheet(cipher.Name, AppResources.Cancel, null, options.ToArray());
if (await vaultTimeoutService.IsLockedAsync()) if (await vaultTimeoutService.IsLockedAsync())
@@ -108,7 +97,7 @@ namespace Bit.App.Utilities
} }
else if (selection == AppResources.CopyUsername) 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); platformUtilsService.ShowToastForCopiedValue(AppResources.Username);
} }
else if (selection == AppResources.CopyPassword else if (selection == AppResources.CopyPassword

View File

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

View File

@@ -26,16 +26,14 @@ namespace Bit.App.Utilities
{ {
public static string GetIconImage(CipherView cipher) 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) public static string GetLoginIconImage(CipherView cipher)
{ {
string image = null; string image = null;
@@ -65,26 +63,6 @@ namespace Bit.App.Utilities
return image; 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) private static string GetIconUrl(string hostnameUri)
{ {
IEnvironmentService _environmentService = ServiceContainer.Resolve<IEnvironmentService>("environmentService"); IEnvironmentService _environmentService = ServiceContainer.Resolve<IEnvironmentService>("environmentService");

View File

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

View File

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

View File

@@ -10,6 +10,6 @@ namespace Bit.Core.Models.Api
public string Password { get; set; } public string Password { get; set; }
public DateTime? PasswordRevisionDate { get; set; } public DateTime? PasswordRevisionDate { get; set; }
public string Totp { 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: case Enums.CipherType.Identity:
Identity = new IdentityData(response.Identity); Identity = new IdentityData(response.Identity);
break; break;
case Enums.CipherType.Fido2Key:
Fido2Key = new Fido2KeyData(response.Fido2Key);
break;
default: default:
break; break;
} }
@@ -86,7 +83,6 @@ namespace Bit.Core.Models.Data
public SecureNoteData SecureNote { get; set; } public SecureNoteData SecureNote { get; set; }
public CardData Card { get; set; } public CardData Card { get; set; }
public IdentityData Identity { get; set; } public IdentityData Identity { get; set; }
public Fido2KeyData Fido2Key { get; set; }
public List<FieldData> Fields { get; set; } public List<FieldData> Fields { get; set; }
public List<AttachmentData> Attachments { get; set; } public List<AttachmentData> Attachments { get; set; }
public List<PasswordHistoryData> PasswordHistory { get; set; } public List<PasswordHistoryData> PasswordHistory { get; set; }

View File

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

View File

@@ -16,7 +16,7 @@ namespace Bit.Core.Models.Data
PasswordRevisionDate = data.PasswordRevisionDate; PasswordRevisionDate = data.PasswordRevisionDate;
Totp = data.Totp; Totp = data.Totp;
Uris = data.Uris?.Select(u => new LoginUriData(u)).ToList(); 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; } public List<LoginUriData> Uris { get; set; }
@@ -24,6 +24,6 @@ namespace Bit.Core.Models.Data
public string Password { get; set; } public string Password { get; set; }
public DateTime? PasswordRevisionDate { get; set; } public DateTime? PasswordRevisionDate { get; set; }
public string Totp { 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: case Enums.CipherType.Identity:
Identity = new Identity(obj.Identity, alreadyEncrypted); Identity = new Identity(obj.Identity, alreadyEncrypted);
break; break;
case CipherType.Fido2Key:
Fido2Key = new Fido2Key(obj.Fido2Key, alreadyEncrypted);
break;
default: default:
break; break;
} }
@@ -66,7 +63,7 @@ namespace Bit.Core.Models.Domain
public string FolderId { get; set; } public string FolderId { get; set; }
public EncString Name { get; set; } public EncString Name { get; set; }
public EncString Notes { 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 Favorite { get; set; }
public bool OrganizationUseTotp { get; set; } public bool OrganizationUseTotp { get; set; }
public bool Edit { get; set; } public bool Edit { get; set; }
@@ -79,7 +76,6 @@ namespace Bit.Core.Models.Domain
public Identity Identity { get; set; } public Identity Identity { get; set; }
public Card Card { get; set; } public Card Card { get; set; }
public SecureNote SecureNote { get; set; } public SecureNote SecureNote { get; set; }
public Fido2Key Fido2Key { get; set; }
public List<Attachment> Attachments { get; set; } public List<Attachment> Attachments { get; set; }
public List<Field> Fields { get; set; } public List<Field> Fields { get; set; }
public List<PasswordHistory> PasswordHistory { get; set; } public List<PasswordHistory> PasswordHistory { get; set; }
@@ -109,9 +105,6 @@ namespace Bit.Core.Models.Domain
case Enums.CipherType.Identity: case Enums.CipherType.Identity:
model.Identity = await Identity.DecryptAsync(OrganizationId); model.Identity = await Identity.DecryptAsync(OrganizationId);
break; break;
case Enums.CipherType.Fido2Key:
model.Fido2Key = await Fido2Key.DecryptAsync(OrganizationId);
break;
default: default:
break; break;
} }
@@ -201,9 +194,6 @@ namespace Bit.Core.Models.Domain
case Enums.CipherType.Identity: case Enums.CipherType.Identity:
c.Identity = Identity.ToIdentityData(); c.Identity = Identity.ToIdentityData();
break; break;
case Enums.CipherType.Fido2Key:
c.Fido2Key = Fido2Key.ToFido2KeyData();
break;
default: default:
break; break;
} }

View File

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

View File

@@ -15,7 +15,7 @@ namespace Bit.Core.Models.Domain
{ {
PasswordRevisionDate = obj.PasswordRevisionDate; PasswordRevisionDate = obj.PasswordRevisionDate;
Uris = obj.Uris?.Select(u => new LoginUri(u, alreadyEncrypted)).ToList(); 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> BuildDomainModel(this, obj, new HashSet<string>
{ {
"Username", "Username",
@@ -29,7 +29,7 @@ namespace Bit.Core.Models.Domain
public EncString Password { get; set; } public EncString Password { get; set; }
public DateTime? PasswordRevisionDate { get; set; } public DateTime? PasswordRevisionDate { get; set; }
public EncString Totp { 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) public async Task<LoginView> DecryptAsync(string orgId)
{ {
@@ -47,9 +47,13 @@ namespace Bit.Core.Models.Domain
view.Uris.Add(await uri.DecryptAsync(orgId)); 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; return view;
} }
@@ -68,9 +72,9 @@ namespace Bit.Core.Models.Domain
{ {
l.Uris = Uris.Select(u => u.ToLoginUriData()).ToList(); 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; return l;
} }

View File

@@ -31,7 +31,7 @@ namespace Bit.Core.Models.Request
Password = cipher.Login.Password?.EncryptedString, Password = cipher.Login.Password?.EncryptedString,
PasswordRevisionDate = cipher.Login.PasswordRevisionDate, PasswordRevisionDate = cipher.Login.PasswordRevisionDate,
Totp = cipher.Login.Totp?.EncryptedString, 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; break;
case CipherType.Card: case CipherType.Card:
@@ -74,9 +74,6 @@ namespace Bit.Core.Models.Request
Type = cipher.SecureNote.Type Type = cipher.SecureNote.Type
}; };
break; break;
case CipherType.Fido2Key:
Fido2Key = new Fido2KeyApi(cipher.Fido2Key);
break;
default: default:
break; break;
} }
@@ -122,7 +119,6 @@ namespace Bit.Core.Models.Request
public SecureNoteApi SecureNote { get; set; } public SecureNoteApi SecureNote { get; set; }
public CardApi Card { get; set; } public CardApi Card { get; set; }
public IdentityApi Identity { get; set; } public IdentityApi Identity { get; set; }
public Fido2KeyApi Fido2Key { get; set; }
public List<FieldApi> Fields { get; set; } public List<FieldApi> Fields { get; set; }
public List<PasswordHistoryRequest> PasswordHistory { get; set; } public List<PasswordHistoryRequest> PasswordHistory { get; set; }
public Dictionary<string, string> Attachments { 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 CardApi Card { get; set; }
public IdentityApi Identity { get; set; } public IdentityApi Identity { get; set; }
public SecureNoteApi SecureNote { get; set; } public SecureNoteApi SecureNote { get; set; }
public Fido2KeyApi Fido2Key { get; set; }
public bool Favorite { get; set; } public bool Favorite { get; set; }
public bool Edit { get; set; } public bool Edit { get; set; }
public bool ViewPassword { get; set; } = true; // Fallback for old server versions 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 IdentityView Identity { get; set; }
public CardView Card { get; set; } public CardView Card { get; set; }
public SecureNoteView SecureNote { get; set; } public SecureNoteView SecureNote { get; set; }
public Fido2KeyView Fido2Key { get; set; }
public List<AttachmentView> Attachments { get; set; } public List<AttachmentView> Attachments { get; set; }
public List<FieldView> Fields { get; set; } public List<FieldView> Fields { get; set; }
public List<PasswordHistoryView> PasswordHistory { get; set; } public List<PasswordHistoryView> PasswordHistory { get; set; }
@@ -67,8 +66,6 @@ namespace Bit.Core.Models.View
return Card; return Card;
case CipherType.Identity: case CipherType.Identity:
return Identity; return Identity;
case CipherType.Fido2Key:
return Fido2Key;
default: default:
break; break;
} }
@@ -115,12 +112,14 @@ namespace Bit.Core.Models.View
return LinkedFieldOptions.Find(lfo => lfo.Value == id).Key; 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 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 KeyType { get; set; } = Constants.DefaultFido2KeyType;
public string KeyAlgorithm { get; set; } = Constants.DefaultFido2KeyAlgorithm; public string KeyAlgorithm { get; set; } = Constants.DefaultFido2KeyAlgorithm;
public string KeyCurve { get; set; } = Constants.DefaultFido2KeyCurve; public string KeyCurve { get; set; } = Constants.DefaultFido2KeyCurve;
@@ -18,6 +19,7 @@ namespace Bit.Core.Models.View
public override string SubTitle => UserName; public override string SubTitle => UserName;
public override List<KeyValuePair<string, LinkedIdType>> LinkedFieldOptions => new List<KeyValuePair<string, LinkedIdType>>(); 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 bool CanLaunch => !string.IsNullOrEmpty(RpId);
public string LaunchUri => $"https://{RpId}"; public string LaunchUri => $"https://{RpId}";

View File

@@ -20,7 +20,7 @@ namespace Bit.Core.Models.View
public DateTime? PasswordRevisionDate { get; set; } public DateTime? PasswordRevisionDate { get; set; }
public string Totp { get; set; } public string Totp { get; set; }
public List<LoginUriView> Uris { 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 Uri => HasUris ? Uris[0].Uri : null;
public string MaskedPassword => Password != null ? "••••••••" : 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 bool CanLaunch => HasUris && Uris.Any(u => u.CanLaunch);
public string LaunchUri => HasUris ? Uris.FirstOrDefault(u => u.CanLaunch)?.LaunchUri : null; public string LaunchUri => HasUris ? Uris.FirstOrDefault(u => u.CanLaunch)?.LaunchUri : null;
public bool HasUris => (Uris?.Count ?? 0) > 0; 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 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) private async Task<bool> ValidateCanBeSharedWithOrgAsync(CipherView cipher, string organizationId)
{ {
if (cipher.Login?.Fido2Key is null && cipher.Fido2Key is null) if (!cipher.HasFido2Key)
{ {
return true; return true;
} }
var decCiphers = await GetAllDecryptedAsync(); var decCiphers = await GetAllDecryptedAsync();
var orgCiphers = decCiphers.Where(c => c.OrganizationId == organizationId); return !decCiphers
if (cipher.Login?.Fido2Key != null) .Where(c => c.OrganizationId == organizationId)
{ .Any(c => !cipher.Login.MainFido2Key.IsUniqueAgainst(c.Login?.MainFido2Key));
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;
} }
public async Task<Cipher> SaveAttachmentRawWithServerAsync(Cipher cipher, string filename, byte[] data) public async Task<Cipher> SaveAttachmentRawWithServerAsync(Cipher cipher, string filename, byte[] data)
@@ -1132,10 +1119,15 @@ namespace Bit.Core.Services
cipher.Login.Uris.Add(loginUri); cipher.Login.Uris.Add(loginUri);
} }
} }
if (model.Login.Fido2Key != null) if (model.Login.HasFido2Keys)
{ {
cipher.Login.Fido2Key = new Fido2Key(); cipher.Login.Fido2Keys = new List<Fido2Key>();
await EncryptObjPropertyAsync(model.Login.Fido2Key, cipher.Login.Fido2Key, Fido2Key.EncryptableProperties, key); foreach (var fido2Key in model.Login.Fido2Keys)
{
var fido2KeyDomain = new Fido2Key();
await EncryptObjPropertyAsync(fido2Key, fido2KeyDomain, Fido2Key.EncryptableProperties, key);
cipher.Login.Fido2Keys.Add(fido2KeyDomain);
}
} }
break; break;
case CipherType.SecureNote: case CipherType.SecureNote:
@@ -1180,10 +1172,6 @@ namespace Bit.Core.Services
"LicenseNumber" "LicenseNumber"
}, key); }, key);
break; break;
case CipherType.Fido2Key:
cipher.Fido2Key = new Fido2Key();
await EncryptObjPropertyAsync(model.Fido2Key, cipher.Fido2Key, Fido2Key.EncryptableProperties, key);
break;
default: default:
throw new Exception("Unknown cipher type."); 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);
}
}
}