From 9ca2baba74deb5a4e6bf9d8008714bda54f13806 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 21 Feb 2017 00:27:32 -0500 Subject: [PATCH] pub/priv keys and share updates --- .../IdentityServer/ResourceOwnerPasswordValidator.cs | 2 +- src/Api/Models/Request/Accounts/KeysRequestModel.cs | 4 ++-- .../Models/Request/Accounts/RegisterRequestModel.cs | 12 ++++++++++-- src/Api/Models/Response/CipherResponseModel.cs | 10 ---------- src/Api/Models/Response/FolderResponseModel.cs | 10 ---------- src/Api/Models/Response/LoginResponseModel.cs | 10 ---------- src/Core/Domains/Cipher.cs | 8 -------- src/Sql/dbo/Stored Procedures/Cipher_Create.sql | 3 --- src/Sql/dbo/Stored Procedures/Cipher_Update.sql | 2 -- src/Sql/dbo/Tables/Cipher.sql | 1 - 10 files changed, 13 insertions(+), 49 deletions(-) diff --git a/src/Api/IdentityServer/ResourceOwnerPasswordValidator.cs b/src/Api/IdentityServer/ResourceOwnerPasswordValidator.cs index 0d475d440..46b3bf843 100644 --- a/src/Api/IdentityServer/ResourceOwnerPasswordValidator.cs +++ b/src/Api/IdentityServer/ResourceOwnerPasswordValidator.cs @@ -123,7 +123,7 @@ namespace Bit.Api.IdentityServer claims: claims.Count > 0 ? claims : null, customResponse: new Dictionary { - { "PrivateKey", user.PrivateKey } + { "EncryptedPrivateKey", user.PrivateKey } }); } diff --git a/src/Api/Models/Request/Accounts/KeysRequestModel.cs b/src/Api/Models/Request/Accounts/KeysRequestModel.cs index b59545b9d..2ab8a5a78 100644 --- a/src/Api/Models/Request/Accounts/KeysRequestModel.cs +++ b/src/Api/Models/Request/Accounts/KeysRequestModel.cs @@ -7,7 +7,7 @@ namespace Bit.Api.Models { public string PublicKey { get; set; } [Required] - public string PrivateKey { get; set; } + public string EncryptedPrivateKey { get; set; } public User ToUser(User existingUser) { @@ -16,7 +16,7 @@ namespace Bit.Api.Models existingUser.PublicKey = PublicKey; } - existingUser.PrivateKey = PrivateKey; + existingUser.PrivateKey = EncryptedPrivateKey; return existingUser; } } diff --git a/src/Api/Models/Request/Accounts/RegisterRequestModel.cs b/src/Api/Models/Request/Accounts/RegisterRequestModel.cs index 4efae52c5..8b5dc3fce 100644 --- a/src/Api/Models/Request/Accounts/RegisterRequestModel.cs +++ b/src/Api/Models/Request/Accounts/RegisterRequestModel.cs @@ -12,19 +12,27 @@ namespace Bit.Api.Models [StringLength(50)] public string Email { get; set; } [Required] - [StringLength(300)] + [StringLength(1000)] public string MasterPasswordHash { get; set; } [StringLength(50)] public string MasterPasswordHint { get; set; } + public KeysRequestModel Keys { get; set; } public User ToUser() { - return new User + var user = new User { Name = Name, Email = Email, MasterPasswordHint = MasterPasswordHint }; + + if(Keys != null) + { + Keys.ToUser(user); + } + + return user; } } } diff --git a/src/Api/Models/Response/CipherResponseModel.cs b/src/Api/Models/Response/CipherResponseModel.cs index 05208686c..b9ce73bfb 100644 --- a/src/Api/Models/Response/CipherResponseModel.cs +++ b/src/Api/Models/Response/CipherResponseModel.cs @@ -33,16 +33,6 @@ namespace Bit.Api.Models default: throw new ArgumentException("Unsupported " + nameof(Type) + "."); } - - if(!string.IsNullOrWhiteSpace(cipher.Shares)) - { - var shares = JsonConvert.DeserializeObject>(cipher.Shares); - var userShare = shares.FirstOrDefault(s => s.UserId == userId); - if(userShare != null) - { - Key = userShare.Key; - } - } } public string Id { get; set; } diff --git a/src/Api/Models/Response/FolderResponseModel.cs b/src/Api/Models/Response/FolderResponseModel.cs index d6a46bba6..ccc988610 100644 --- a/src/Api/Models/Response/FolderResponseModel.cs +++ b/src/Api/Models/Response/FolderResponseModel.cs @@ -26,16 +26,6 @@ namespace Bit.Api.Models Id = cipher.Id.ToString(); Name = data.Name; RevisionDate = cipher.RevisionDate; - - if(!string.IsNullOrWhiteSpace(cipher.Shares)) - { - var shares = JsonConvert.DeserializeObject>(cipher.Shares); - var userShare = shares.FirstOrDefault(s => s.UserId == userId); - if(userShare != null) - { - Key = userShare.Key; - } - } } public string Id { get; set; } diff --git a/src/Api/Models/Response/LoginResponseModel.cs b/src/Api/Models/Response/LoginResponseModel.cs index 97f25c0c4..2f097a923 100644 --- a/src/Api/Models/Response/LoginResponseModel.cs +++ b/src/Api/Models/Response/LoginResponseModel.cs @@ -32,16 +32,6 @@ namespace Bit.Api.Models Password = data.Password; Notes = data.Notes; RevisionDate = cipher.RevisionDate; - - if(!string.IsNullOrWhiteSpace(cipher.Shares)) - { - var shares = JsonConvert.DeserializeObject>(cipher.Shares); - var userShare = shares.FirstOrDefault(s => s.UserId == userId); - if(userShare != null) - { - Key = userShare.Key; - } - } } public string Id { get; set; } diff --git a/src/Core/Domains/Cipher.cs b/src/Core/Domains/Cipher.cs index 03130c285..46accfb29 100644 --- a/src/Core/Domains/Cipher.cs +++ b/src/Core/Domains/Cipher.cs @@ -11,7 +11,6 @@ namespace Bit.Core.Domains public Enums.CipherType Type { get; set; } public bool Favorite { get; set; } public string Data { get; set; } - public string Shares { get; set; } public DateTime CreationDate { get; internal set; } = DateTime.UtcNow; public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow; @@ -19,12 +18,5 @@ namespace Bit.Core.Domains { Id = CoreHelpers.GenerateComb(); } - - public class Share - { - public Guid UserId { get; set; } - public string Key { get; set; } - // TODO: permission flags? - } } } diff --git a/src/Sql/dbo/Stored Procedures/Cipher_Create.sql b/src/Sql/dbo/Stored Procedures/Cipher_Create.sql index b51f33659..4c7894909 100644 --- a/src/Sql/dbo/Stored Procedures/Cipher_Create.sql +++ b/src/Sql/dbo/Stored Procedures/Cipher_Create.sql @@ -5,7 +5,6 @@ @Type TINYINT, @Favorite BIT, @Data NVARCHAR(MAX), - @Shares NVARCHAR(MAX), @CreationDate DATETIME2(7), @RevisionDate DATETIME2(7) AS @@ -20,7 +19,6 @@ BEGIN [Type], [Favorite], [Data], - [Shares], [CreationDate], [RevisionDate] ) @@ -32,7 +30,6 @@ BEGIN @Type, @Favorite, @Data, - @Shares, @CreationDate, @RevisionDate ) diff --git a/src/Sql/dbo/Stored Procedures/Cipher_Update.sql b/src/Sql/dbo/Stored Procedures/Cipher_Update.sql index 8421ca20b..19190a73c 100644 --- a/src/Sql/dbo/Stored Procedures/Cipher_Update.sql +++ b/src/Sql/dbo/Stored Procedures/Cipher_Update.sql @@ -5,7 +5,6 @@ @Type TINYINT, @Favorite BIT, @Data NVARCHAR(MAX), - @Shares NVARCHAR(MAX), @CreationDate DATETIME2(7), @RevisionDate DATETIME2(7) AS @@ -20,7 +19,6 @@ BEGIN [Type] = @Type, [Favorite] = @Favorite, [Data] = @Data, - [Shares] = @Shares, [CreationDate] = @CreationDate, [RevisionDate] = @RevisionDate WHERE diff --git a/src/Sql/dbo/Tables/Cipher.sql b/src/Sql/dbo/Tables/Cipher.sql index 0f8b2f204..719e147b0 100644 --- a/src/Sql/dbo/Tables/Cipher.sql +++ b/src/Sql/dbo/Tables/Cipher.sql @@ -5,7 +5,6 @@ [Type] TINYINT NOT NULL, [Favorite] BIT NOT NULL, [Data] NVARCHAR (MAX) NOT NULL, - [Shares] NVARCHAR (MAX) NULL, [CreationDate] DATETIME2 (7) NOT NULL, [RevisionDate] DATETIME2 (7) NOT NULL, CONSTRAINT [PK_Cipher] PRIMARY KEY CLUSTERED ([Id] ASC),