From f2936c95fa7af8540d8d1bc5e40df58a097b3f70 Mon Sep 17 00:00:00 2001 From: Federico Maccaroni Date: Thu, 12 Oct 2023 16:51:19 -0300 Subject: [PATCH] [PM-4054] Rename Fido2Key to Fido2Credential (#2821) * PM-4054 Renamed Fido2Key to Fido2Credential on the entire codebase * PM-4054 Renamed file Fido2KeyApi to Fido2CredentialApi --- .../Pages/Vault/CipherAddEditPageViewModel.cs | 4 ++-- src/App/Pages/Vault/CipherDetailsPage.xaml | 4 ++-- .../Pages/Vault/CipherDetailsPageViewModel.cs | 2 +- src/Core/Constants.cs | 6 +++--- .../{Fido2KeyApi.cs => Fido2CredentialApi.cs} | 12 ++++++------ src/Core/Models/Api/LoginApi.cs | 2 +- .../{Fido2KeyData.cs => Fido2CredentialData.cs} | 12 ++++++------ src/Core/Models/Data/LoginData.cs | 4 ++-- .../Domain/{Fido2Key.cs => Fido2Credential.cs} | 14 +++++++------- src/Core/Models/Domain/Login.cs | 16 ++++++++-------- src/Core/Models/Request/CipherRequest.cs | 2 +- src/Core/Models/View/CipherView.cs | 2 +- .../{Fido2KeyView.cs => Fido2CredentialView.cs} | 10 +++++----- src/Core/Models/View/LoginView.cs | 6 +++--- src/Core/Services/CipherService.cs | 16 ++++++++-------- 15 files changed, 56 insertions(+), 56 deletions(-) rename src/Core/Models/Api/{Fido2KeyApi.cs => Fido2CredentialApi.cs} (86%) rename src/Core/Models/Data/{Fido2KeyData.cs => Fido2CredentialData.cs} (83%) rename src/Core/Models/Domain/{Fido2Key.cs => Fido2Credential.cs} (73%) rename src/Core/Models/View/{Fido2KeyView.cs => Fido2CredentialView.cs} (79%) diff --git a/src/App/Pages/Vault/CipherAddEditPageViewModel.cs b/src/App/Pages/Vault/CipherAddEditPageViewModel.cs index f5bfd0c64..a80cb8fb7 100644 --- a/src/App/Pages/Vault/CipherAddEditPageViewModel.cs +++ b/src/App/Pages/Vault/CipherAddEditPageViewModel.cs @@ -308,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?.HasFido2Key == true && !CloneMode; + public bool ShowPasskeyInfo => Cipher?.HasFido2Credential == true && !CloneMode; public void Init() { @@ -370,7 +370,7 @@ namespace Bit.App.Pages if (Cipher.Type == CipherType.Login) { // passkeys can't be cloned - Cipher.Login.Fido2Keys = null; + Cipher.Login.Fido2Credentials = null; } } if (appOptions?.OtpData != null && Cipher.Type == CipherType.Login) diff --git a/src/App/Pages/Vault/CipherDetailsPage.xaml b/src/App/Pages/Vault/CipherDetailsPage.xaml index 9c97500a1..e95c2add4 100644 --- a/src/App/Pages/Vault/CipherDetailsPage.xaml +++ b/src/App/Pages/Vault/CipherDetailsPage.xaml @@ -199,12 +199,12 @@ Text="{u:I18n Passkey}" StyleClass="box-label" Margin="0,10,0,0" - IsVisible="{Binding Cipher.Login.MainFido2Key, Converter={StaticResource notNull}}"/> + IsVisible="{Binding Cipher.Login.MainFido2Credential, Converter={StaticResource notNull}}"/> + IsVisible="{Binding Cipher.Login.MainFido2Credential, Converter={StaticResource notNull}}" /> diff --git a/src/App/Pages/Vault/CipherDetailsPageViewModel.cs b/src/App/Pages/Vault/CipherDetailsPageViewModel.cs index f12348c10..0b1da5f56 100644 --- a/src/App/Pages/Vault/CipherDetailsPageViewModel.cs +++ b/src/App/Pages/Vault/CipherDetailsPageViewModel.cs @@ -702,7 +702,7 @@ namespace Bit.App.Pages private async Task CanCloneAsync() { - if (!Cipher.HasFido2Key) + if (!Cipher.HasFido2Credential) { return true; } diff --git a/src/Core/Constants.cs b/src/Core/Constants.cs index 7fe9fe8f5..04641a6b0 100644 --- a/src/Core/Constants.cs +++ b/src/Core/Constants.cs @@ -69,9 +69,9 @@ namespace Bit.Core public const int MasterPasswordMinimumChars = 12; public const int CipherKeyRandomBytesLength = 64; public const string CipherKeyEncryptionMinServerVersion = "2023.9.1"; - public const string DefaultFido2KeyType = "public-key"; - public const string DefaultFido2KeyAlgorithm = "ECDSA"; - public const string DefaultFido2KeyCurve = "P-256"; + public const string DefaultFido2CredentialType = "public-key"; + public const string DefaultFido2CredentialAlgorithm = "ECDSA"; + public const string DefaultFido2CredentialCurve = "P-256"; public static readonly string[] AndroidAllClearCipherCacheKeys = { diff --git a/src/Core/Models/Api/Fido2KeyApi.cs b/src/Core/Models/Api/Fido2CredentialApi.cs similarity index 86% rename from src/Core/Models/Api/Fido2KeyApi.cs rename to src/Core/Models/Api/Fido2CredentialApi.cs index 40c5595d0..8ebc63dbf 100644 --- a/src/Core/Models/Api/Fido2KeyApi.cs +++ b/src/Core/Models/Api/Fido2CredentialApi.cs @@ -2,13 +2,13 @@ namespace Bit.Core.Models.Api { - public class Fido2KeyApi + public class Fido2CredentialApi { - public Fido2KeyApi() + public Fido2CredentialApi() { } - public Fido2KeyApi(Fido2Key fido2Key) + public Fido2CredentialApi(Fido2Credential fido2Key) { CredentialId = fido2Key.CredentialId?.EncryptedString; Discoverable = fido2Key.Discoverable?.EncryptedString; @@ -25,9 +25,9 @@ namespace Bit.Core.Models.Api 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; + public string KeyType { get; set; } = Constants.DefaultFido2CredentialType; + public string KeyAlgorithm { get; set; } = Constants.DefaultFido2CredentialAlgorithm; + public string KeyCurve { get; set; } = Constants.DefaultFido2CredentialCurve; public string KeyValue { get; set; } public string RpId { get; set; } public string RpName { get; set; } diff --git a/src/Core/Models/Api/LoginApi.cs b/src/Core/Models/Api/LoginApi.cs index 2ebefc0c3..2d4c1d851 100644 --- a/src/Core/Models/Api/LoginApi.cs +++ b/src/Core/Models/Api/LoginApi.cs @@ -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 List Fido2Keys { get; set; } + public List Fido2Credentials { get; set; } } } diff --git a/src/Core/Models/Data/Fido2KeyData.cs b/src/Core/Models/Data/Fido2CredentialData.cs similarity index 83% rename from src/Core/Models/Data/Fido2KeyData.cs rename to src/Core/Models/Data/Fido2CredentialData.cs index aa1fd8e39..2e63e7aa5 100644 --- a/src/Core/Models/Data/Fido2KeyData.cs +++ b/src/Core/Models/Data/Fido2CredentialData.cs @@ -2,11 +2,11 @@ namespace Bit.Core.Models.Data { - public class Fido2KeyData : Data + public class Fido2CredentialData : Data { - public Fido2KeyData() { } + public Fido2CredentialData() { } - public Fido2KeyData(Fido2KeyApi apiData) + public Fido2CredentialData(Fido2CredentialApi apiData) { CredentialId = apiData.CredentialId; Discoverable = apiData.Discoverable; @@ -23,9 +23,9 @@ namespace Bit.Core.Models.Data 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; + public string KeyType { get; set; } = Constants.DefaultFido2CredentialType; + public string KeyAlgorithm { get; set; } = Constants.DefaultFido2CredentialAlgorithm; + public string KeyCurve { get; set; } = Constants.DefaultFido2CredentialCurve; public string KeyValue { get; set; } public string RpId { get; set; } public string RpName { get; set; } diff --git a/src/Core/Models/Data/LoginData.cs b/src/Core/Models/Data/LoginData.cs index bc71df1af..ede56065f 100644 --- a/src/Core/Models/Data/LoginData.cs +++ b/src/Core/Models/Data/LoginData.cs @@ -16,7 +16,7 @@ namespace Bit.Core.Models.Data PasswordRevisionDate = data.PasswordRevisionDate; Totp = data.Totp; Uris = data.Uris?.Select(u => new LoginUriData(u)).ToList(); - Fido2Keys = data.Fido2Keys?.Select(f => new Fido2KeyData(f)).ToList(); + Fido2Credentials = data.Fido2Credentials?.Select(f => new Fido2CredentialData(f)).ToList(); } public List 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 List Fido2Keys { get; set; } + public List Fido2Credentials { get; set; } } } diff --git a/src/Core/Models/Domain/Fido2Key.cs b/src/Core/Models/Domain/Fido2Credential.cs similarity index 73% rename from src/Core/Models/Domain/Fido2Key.cs rename to src/Core/Models/Domain/Fido2Credential.cs index 504830fd7..b606aa0dd 100644 --- a/src/Core/Models/Domain/Fido2Key.cs +++ b/src/Core/Models/Domain/Fido2Credential.cs @@ -5,7 +5,7 @@ using Bit.Core.Models.View; namespace Bit.Core.Models.Domain { - public class Fido2Key : Domain + public class Fido2Credential : Domain { public static HashSet EncryptableProperties => new HashSet { @@ -22,9 +22,9 @@ namespace Bit.Core.Models.Domain nameof(Counter) }; - public Fido2Key() { } + public Fido2Credential() { } - public Fido2Key(Fido2KeyData data, bool alreadyEncrypted = false) + public Fido2Credential(Fido2CredentialData data, bool alreadyEncrypted = false) { BuildDomainModel(this, data, EncryptableProperties, alreadyEncrypted); } @@ -41,14 +41,14 @@ namespace Bit.Core.Models.Domain public EncString UserName { get; set; } public EncString Counter { get; set; } - public async Task DecryptAsync(string orgId, SymmetricCryptoKey key = null) + public async Task DecryptAsync(string orgId, SymmetricCryptoKey key = null) { - return await DecryptObjAsync(new Fido2KeyView(), this, EncryptableProperties, orgId, key); + return await DecryptObjAsync(new Fido2CredentialView(), this, EncryptableProperties, orgId, key); } - public Fido2KeyData ToFido2KeyData() + public Fido2CredentialData ToFido2CredentialData() { - var data = new Fido2KeyData(); + var data = new Fido2CredentialData(); BuildDataModel(this, data, EncryptableProperties); return data; } diff --git a/src/Core/Models/Domain/Login.cs b/src/Core/Models/Domain/Login.cs index 43900b179..ed1822c13 100644 --- a/src/Core/Models/Domain/Login.cs +++ b/src/Core/Models/Domain/Login.cs @@ -15,7 +15,7 @@ namespace Bit.Core.Models.Domain { PasswordRevisionDate = obj.PasswordRevisionDate; Uris = obj.Uris?.Select(u => new LoginUri(u, alreadyEncrypted)).ToList(); - Fido2Keys = obj.Fido2Keys?.Select(f => new Fido2Key(f, alreadyEncrypted)).ToList(); + Fido2Credentials = obj.Fido2Credentials?.Select(f => new Fido2Credential(f, alreadyEncrypted)).ToList(); BuildDomainModel(this, obj, new HashSet { "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 List Fido2Keys { get; set; } + public List Fido2Credentials { get; set; } public async Task DecryptAsync(string orgId, SymmetricCryptoKey key = null) { @@ -47,12 +47,12 @@ namespace Bit.Core.Models.Domain view.Uris.Add(await uri.DecryptAsync(orgId, key)); } } - if (Fido2Keys != null) + if (Fido2Credentials != null) { - view.Fido2Keys = new List(); - foreach (var fido2Key in Fido2Keys) + view.Fido2Credentials = new List(); + foreach (var fido2Credential in Fido2Credentials) { - view.Fido2Keys.Add(await fido2Key.DecryptAsync(orgId, key)); + view.Fido2Credentials.Add(await fido2Credential.DecryptAsync(orgId, key)); } } return view; @@ -72,9 +72,9 @@ namespace Bit.Core.Models.Domain { l.Uris = Uris.Select(u => u.ToLoginUriData()).ToList(); } - if (Fido2Keys != null) + if (Fido2Credentials != null) { - l.Fido2Keys = Fido2Keys.Select(f => f.ToFido2KeyData()).ToList(); + l.Fido2Credentials = Fido2Credentials.Select(f => f.ToFido2CredentialData()).ToList(); } return l; } diff --git a/src/Core/Models/Request/CipherRequest.cs b/src/Core/Models/Request/CipherRequest.cs index bef11566c..f0b44d402 100644 --- a/src/Core/Models/Request/CipherRequest.cs +++ b/src/Core/Models/Request/CipherRequest.cs @@ -32,7 +32,7 @@ namespace Bit.Core.Models.Request Password = cipher.Login.Password?.EncryptedString, PasswordRevisionDate = cipher.Login.PasswordRevisionDate, Totp = cipher.Login.Totp?.EncryptedString, - Fido2Keys = cipher.Login.Fido2Keys?.Select(f => new Fido2KeyApi(f)).ToList() + Fido2Credentials = cipher.Login.Fido2Credentials?.Select(f => new Fido2CredentialApi(f)).ToList() }; break; case CipherType.Card: diff --git a/src/Core/Models/View/CipherView.cs b/src/Core/Models/View/CipherView.cs index 01c86f450..df8a47eb4 100644 --- a/src/Core/Models/View/CipherView.cs +++ b/src/Core/Models/View/CipherView.cs @@ -121,6 +121,6 @@ namespace Bit.Core.Models.View public bool IsClonable => OrganizationId is null; - public bool HasFido2Key => Type == CipherType.Login && Login?.HasFido2Keys == true; + public bool HasFido2Credential => Type == CipherType.Login && Login?.HasFido2Credentials == true; } } diff --git a/src/Core/Models/View/Fido2KeyView.cs b/src/Core/Models/View/Fido2CredentialView.cs similarity index 79% rename from src/Core/Models/View/Fido2KeyView.cs rename to src/Core/Models/View/Fido2CredentialView.cs index 20a4d0ee1..390a3bf7d 100644 --- a/src/Core/Models/View/Fido2KeyView.cs +++ b/src/Core/Models/View/Fido2CredentialView.cs @@ -3,13 +3,13 @@ using Bit.Core.Enums; namespace Bit.Core.Models.View { - public class Fido2KeyView : ItemView, ILaunchableView + public class Fido2CredentialView : ItemView, ILaunchableView { 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; + public string KeyType { get; set; } = Constants.DefaultFido2CredentialType; + public string KeyAlgorithm { get; set; } = Constants.DefaultFido2CredentialAlgorithm; + public string KeyCurve { get; set; } = Constants.DefaultFido2CredentialCurve; public string KeyValue { get; set; } public string RpId { get; set; } public string RpName { get; set; } @@ -23,6 +23,6 @@ namespace Bit.Core.Models.View public bool CanLaunch => !string.IsNullOrEmpty(RpId); public string LaunchUri => $"https://{RpId}"; - public bool IsUniqueAgainst(Fido2KeyView fido2View) => fido2View?.RpId != RpId || fido2View?.UserName != UserName; + public bool IsUniqueAgainst(Fido2CredentialView fido2View) => fido2View?.RpId != RpId || fido2View?.UserName != UserName; } } diff --git a/src/Core/Models/View/LoginView.cs b/src/Core/Models/View/LoginView.cs index bece3a9ce..9993c2f11 100644 --- a/src/Core/Models/View/LoginView.cs +++ b/src/Core/Models/View/LoginView.cs @@ -20,7 +20,7 @@ namespace Bit.Core.Models.View public DateTime? PasswordRevisionDate { get; set; } public string Totp { get; set; } public List Uris { get; set; } - public List Fido2Keys { get; set; } + public List Fido2Credentials { get; set; } public string Uri => HasUris ? Uris[0].Uri : null; public string MaskedPassword => Password != null ? "••••••••" : null; @@ -28,8 +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 bool HasFido2Credentials => Fido2Credentials?.Any() == true; + public Fido2CredentialView MainFido2Credential => HasFido2Credentials ? Fido2Credentials[0] : null; public override List> LinkedFieldOptions { diff --git a/src/Core/Services/CipherService.cs b/src/Core/Services/CipherService.cs index cdbc4aa46..8b490d12d 100644 --- a/src/Core/Services/CipherService.cs +++ b/src/Core/Services/CipherService.cs @@ -597,7 +597,7 @@ namespace Bit.Core.Services private async Task ValidateCanBeSharedWithOrgAsync(CipherView cipher, string organizationId) { - if (!cipher.HasFido2Key) + if (!cipher.HasFido2Credential) { return true; } @@ -605,7 +605,7 @@ namespace Bit.Core.Services var decCiphers = await GetAllDecryptedAsync(); return !decCiphers .Where(c => c.OrganizationId == organizationId) - .Any(c => !cipher.Login.MainFido2Key.IsUniqueAgainst(c.Login?.MainFido2Key)); + .Any(c => !cipher.Login.MainFido2Credential.IsUniqueAgainst(c.Login?.MainFido2Credential)); } public async Task SaveAttachmentRawWithServerAsync(Cipher cipher, CipherView cipherView, string filename, byte[] data) @@ -1176,14 +1176,14 @@ namespace Bit.Core.Services cipher.Login.Uris.Add(loginUri); } } - if (model.Login.HasFido2Keys) + if (model.Login.HasFido2Credentials) { - cipher.Login.Fido2Keys = new List(); - foreach (var fido2Key in model.Login.Fido2Keys) + cipher.Login.Fido2Credentials = new List(); + foreach (var fido2Credential in model.Login.Fido2Credentials) { - var fido2KeyDomain = new Fido2Key(); - await EncryptObjPropertyAsync(fido2Key, fido2KeyDomain, Fido2Key.EncryptableProperties, key); - cipher.Login.Fido2Keys.Add(fido2KeyDomain); + var fido2CredentialDomain = new Fido2Credential(); + await EncryptObjPropertyAsync(fido2Credential, fido2CredentialDomain, Fido2Credential.EncryptableProperties, key); + cipher.Login.Fido2Credentials.Add(fido2CredentialDomain); } } break;