From b71397d78f8f29927c8aba4da94b9c27c846d3c3 Mon Sep 17 00:00:00 2001 From: Andreas Coroiu Date: Mon, 11 Sep 2023 11:55:13 +0200 Subject: [PATCH 1/4] [PM-3807] feat: add discoverable property to fido2key --- src/Api/Vault/Models/CipherFido2KeyModel.cs | 6 ++++++ src/Core/Vault/Models/Data/CipherFido2KeyData.cs | 1 + src/Core/Vault/Models/Data/CipherLoginFido2KeyData.cs | 1 + 3 files changed, 8 insertions(+) diff --git a/src/Api/Vault/Models/CipherFido2KeyModel.cs b/src/Api/Vault/Models/CipherFido2KeyModel.cs index d40e9462e196..c36487239ba5 100644 --- a/src/Api/Vault/Models/CipherFido2KeyModel.cs +++ b/src/Api/Vault/Models/CipherFido2KeyModel.cs @@ -19,6 +19,7 @@ public CipherFido2KeyModel(CipherFido2KeyData data) UserHandle = data.UserHandle; UserDisplayName = data.UserDisplayName; Counter = data.Counter; + Discoverable = data.Discoverable; } public CipherFido2KeyModel(CipherLoginFido2KeyData data) @@ -33,6 +34,7 @@ public CipherFido2KeyModel(CipherLoginFido2KeyData data) UserHandle = data.UserHandle; UserDisplayName = data.UserDisplayName; Counter = data.Counter; + Discoverable = data.Discoverable; } [EncryptedString] @@ -65,6 +67,9 @@ public CipherFido2KeyModel(CipherLoginFido2KeyData data) [EncryptedString] [EncryptedStringLength(1000)] public string Counter { get; set; } + [EncryptedString] + [EncryptedStringLength(1000)] + public string Discoverable { get; set; } public CipherLoginFido2KeyData ToCipherLoginFido2KeyData() { @@ -80,6 +85,7 @@ public CipherLoginFido2KeyData ToCipherLoginFido2KeyData() UserHandle = UserHandle, UserDisplayName = UserDisplayName, Counter = Counter, + Discoverable = Discoverable }; } } diff --git a/src/Core/Vault/Models/Data/CipherFido2KeyData.cs b/src/Core/Vault/Models/Data/CipherFido2KeyData.cs index f4f15a5709f6..ab4296953bc0 100644 --- a/src/Core/Vault/Models/Data/CipherFido2KeyData.cs +++ b/src/Core/Vault/Models/Data/CipherFido2KeyData.cs @@ -14,4 +14,5 @@ public CipherFido2KeyData() { } public string UserHandle { get; set; } public string UserDisplayName { get; set; } public string Counter { get; set; } + public string Discoverable { get; set; } } diff --git a/src/Core/Vault/Models/Data/CipherLoginFido2KeyData.cs b/src/Core/Vault/Models/Data/CipherLoginFido2KeyData.cs index 459613ede3b0..e138c8a7cd4c 100644 --- a/src/Core/Vault/Models/Data/CipherLoginFido2KeyData.cs +++ b/src/Core/Vault/Models/Data/CipherLoginFido2KeyData.cs @@ -14,4 +14,5 @@ public CipherLoginFido2KeyData() { } public string UserHandle { get; set; } public string UserDisplayName { get; set; } public string Counter { get; set; } + public string Discoverable { get; set; } } From 29aa75bb113e9c8f7d2b647684ccff5c2a545d4e Mon Sep 17 00:00:00 2001 From: Andreas Coroiu Date: Mon, 11 Sep 2023 14:05:19 +0200 Subject: [PATCH 2/4] [PM-3807] feat: remove standalone Fido2Key --- src/Api/Vault/Controllers/SyncController.cs | 20 ++------------- src/Api/Vault/Models/CipherFido2KeyModel.cs | 15 ----------- .../Models/Request/CipherRequestModel.cs | 25 ------------------- .../Models/Response/CipherResponseModel.cs | 6 ----- src/Core/Vault/Enums/CipherType.cs | 1 - .../Vault/Models/Data/CipherFido2KeyData.cs | 18 ------------- 6 files changed, 2 insertions(+), 83 deletions(-) delete mode 100644 src/Core/Vault/Models/Data/CipherFido2KeyData.cs diff --git a/src/Api/Vault/Controllers/SyncController.cs b/src/Api/Vault/Controllers/SyncController.cs index 5b85d7f6a5e3..3df216ba9c6b 100644 --- a/src/Api/Vault/Controllers/SyncController.cs +++ b/src/Api/Vault/Controllers/SyncController.cs @@ -1,6 +1,4 @@ using Bit.Api.Vault.Models.Response; -using Bit.Core; -using Bit.Core.Context; using Bit.Core.Entities; using Bit.Core.Enums; using Bit.Core.Enums.Provider; @@ -10,7 +8,6 @@ using Bit.Core.Services; using Bit.Core.Settings; using Bit.Core.Tools.Repositories; -using Bit.Core.Vault.Models.Data; using Bit.Core.Vault.Repositories; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -31,8 +28,6 @@ public class SyncController : Controller private readonly IPolicyRepository _policyRepository; private readonly ISendRepository _sendRepository; private readonly GlobalSettings _globalSettings; - private readonly ICurrentContext _currentContext; - private readonly Version _fido2KeyCipherMinimumVersion = new Version(Constants.Fido2KeyCipherMinimumVersion); public SyncController( IUserService userService, @@ -44,8 +39,7 @@ public SyncController( IProviderUserRepository providerUserRepository, IPolicyRepository policyRepository, ISendRepository sendRepository, - GlobalSettings globalSettings, - ICurrentContext currentContext) + GlobalSettings globalSettings) { _userService = userService; _folderRepository = folderRepository; @@ -57,7 +51,6 @@ public SyncController( _policyRepository = policyRepository; _sendRepository = sendRepository; _globalSettings = globalSettings; - _currentContext = currentContext; } [HttpGet("")] @@ -79,7 +72,7 @@ await _providerUserRepository.GetManyOrganizationDetailsByUserAsync(user.Id, var hasEnabledOrgs = organizationUserDetails.Any(o => o.Enabled); var folders = await _folderRepository.GetManyByUserIdAsync(user.Id); var allCiphers = await _cipherRepository.GetManyByUserIdAsync(user.Id, hasEnabledOrgs); - var ciphers = FilterFidoKeys(allCiphers); + var ciphers = allCiphers; var sends = await _sendRepository.GetManyByUserIdAsync(user.Id); IEnumerable collections = null; @@ -100,13 +93,4 @@ await _providerUserRepository.GetManyOrganizationDetailsByUserAsync(user.Id, collectionCiphersGroupDict, excludeDomains, policies, sends); return response; } - - private ICollection FilterFidoKeys(ICollection ciphers) - { - if (_currentContext.ClientVersion >= _fido2KeyCipherMinimumVersion) - { - return ciphers; - } - return ciphers.Where(c => c.Type != Core.Vault.Enums.CipherType.Fido2Key).ToList(); - } } diff --git a/src/Api/Vault/Models/CipherFido2KeyModel.cs b/src/Api/Vault/Models/CipherFido2KeyModel.cs index c36487239ba5..86d05f89ec2b 100644 --- a/src/Api/Vault/Models/CipherFido2KeyModel.cs +++ b/src/Api/Vault/Models/CipherFido2KeyModel.cs @@ -7,21 +7,6 @@ public class CipherFido2KeyModel { public CipherFido2KeyModel() { } - public CipherFido2KeyModel(CipherFido2KeyData data) - { - CredentialId = data.CredentialId; - KeyType = data.KeyType; - KeyAlgorithm = data.KeyAlgorithm; - KeyCurve = data.KeyCurve; - KeyValue = data.KeyValue; - RpId = data.RpId; - RpName = data.RpName; - UserHandle = data.UserHandle; - UserDisplayName = data.UserDisplayName; - Counter = data.Counter; - Discoverable = data.Discoverable; - } - public CipherFido2KeyModel(CipherLoginFido2KeyData data) { CredentialId = data.CredentialId; diff --git a/src/Api/Vault/Models/Request/CipherRequestModel.cs b/src/Api/Vault/Models/Request/CipherRequestModel.cs index 1c42ab86c2b5..4ce5e8f4079e 100644 --- a/src/Api/Vault/Models/Request/CipherRequestModel.cs +++ b/src/Api/Vault/Models/Request/CipherRequestModel.cs @@ -82,9 +82,6 @@ public Cipher ToCipher(Cipher existingCipher) case CipherType.SecureNote: existingCipher.Data = JsonSerializer.Serialize(ToCipherSecureNoteData(), JsonHelpers.IgnoreWritingNull); break; - case CipherType.Fido2Key: - existingCipher.Data = JsonSerializer.Serialize(ToCipherFido2KeyData(), JsonHelpers.IgnoreWritingNull); - break; default: throw new ArgumentException("Unsupported type: " + nameof(Type) + "."); } @@ -232,28 +229,6 @@ private CipherSecureNoteData ToCipherSecureNoteData() Type = SecureNote.Type, }; } - - private CipherFido2KeyData ToCipherFido2KeyData() - { - return new CipherFido2KeyData - { - Name = Name, - Notes = Notes, - Fields = Fields?.Select(f => f.ToCipherFieldData()), - PasswordHistory = PasswordHistory?.Select(ph => ph.ToCipherPasswordHistoryData()), - - CredentialId = Fido2Key.CredentialId, - KeyAlgorithm = Fido2Key.KeyAlgorithm, - KeyType = Fido2Key.KeyType, - KeyCurve = Fido2Key.KeyCurve, - KeyValue = Fido2Key.KeyValue, - RpId = Fido2Key.RpId, - RpName = Fido2Key.RpName, - UserHandle = Fido2Key.UserHandle, - UserDisplayName = Fido2Key.UserDisplayName, - Counter = Fido2Key.Counter - }; - } } public class CipherWithIdRequestModel : CipherRequestModel diff --git a/src/Api/Vault/Models/Response/CipherResponseModel.cs b/src/Api/Vault/Models/Response/CipherResponseModel.cs index df73827456d6..90522926183e 100644 --- a/src/Api/Vault/Models/Response/CipherResponseModel.cs +++ b/src/Api/Vault/Models/Response/CipherResponseModel.cs @@ -48,12 +48,6 @@ public CipherMiniResponseModel(Cipher cipher, IGlobalSettings globalSettings, bo cipherData = identityData; Identity = new CipherIdentityModel(identityData); break; - case CipherType.Fido2Key: - var fido2KeyData = JsonSerializer.Deserialize(cipher.Data); - Data = fido2KeyData; - cipherData = fido2KeyData; - Fido2Key = new CipherFido2KeyModel(fido2KeyData); - break; default: throw new ArgumentException("Unsupported " + nameof(Type) + "."); } diff --git a/src/Core/Vault/Enums/CipherType.cs b/src/Core/Vault/Enums/CipherType.cs index 9abb6330dfe3..f3c7a90f454e 100644 --- a/src/Core/Vault/Enums/CipherType.cs +++ b/src/Core/Vault/Enums/CipherType.cs @@ -8,5 +8,4 @@ public enum CipherType : byte SecureNote = 2, Card = 3, Identity = 4, - Fido2Key = 5, } diff --git a/src/Core/Vault/Models/Data/CipherFido2KeyData.cs b/src/Core/Vault/Models/Data/CipherFido2KeyData.cs deleted file mode 100644 index ab4296953bc0..000000000000 --- a/src/Core/Vault/Models/Data/CipherFido2KeyData.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Bit.Core.Vault.Models.Data; - -public class CipherFido2KeyData : CipherData -{ - public CipherFido2KeyData() { } - - public string CredentialId { get; set; } - public string KeyType { get; set; } - public string KeyAlgorithm { get; set; } - public string KeyCurve { get; set; } - public string KeyValue { get; set; } - public string RpId { get; set; } - public string RpName { get; set; } - public string UserHandle { get; set; } - public string UserDisplayName { get; set; } - public string Counter { get; set; } - public string Discoverable { get; set; } -} From 938d38055947de4bb01790be664bb7563cc29b71 Mon Sep 17 00:00:00 2001 From: Andreas Coroiu Date: Mon, 11 Sep 2023 15:15:58 +0200 Subject: [PATCH 3/4] [PM-3807] chore: clean up unusued constant --- src/Core/Constants.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Core/Constants.cs b/src/Core/Constants.cs index 3f4362dc12cd..13273acdfbb9 100644 --- a/src/Core/Constants.cs +++ b/src/Core/Constants.cs @@ -19,7 +19,6 @@ public static class Constants /// their subscription has expired. /// public const int OrganizationSelfHostSubscriptionGracePeriodDays = 60; - public const string Fido2KeyCipherMinimumVersion = "2023.9.0"; } public static class TokenPurposes From f6b5530c2c9a350273f6582db13875bc64c9c910 Mon Sep 17 00:00:00 2001 From: Andreas Coroiu Date: Mon, 11 Sep 2023 16:39:34 +0200 Subject: [PATCH 4/4] [PM-3807] fix: remove standadlone Fido2Key property that I missed --- src/Api/Vault/Models/Request/CipherRequestModel.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Api/Vault/Models/Request/CipherRequestModel.cs b/src/Api/Vault/Models/Request/CipherRequestModel.cs index 4ce5e8f4079e..43b54fb386c3 100644 --- a/src/Api/Vault/Models/Request/CipherRequestModel.cs +++ b/src/Api/Vault/Models/Request/CipherRequestModel.cs @@ -36,7 +36,6 @@ public class CipherRequestModel public CipherCardModel Card { get; set; } public CipherIdentityModel Identity { get; set; } public CipherSecureNoteModel SecureNote { get; set; } - public CipherFido2KeyModel Fido2Key { get; set; } public DateTime? LastKnownRevisionDate { get; set; } = null; public CipherDetails ToCipherDetails(Guid userId, bool allowOrgIdSet = true)