1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-25 12:45:18 +01:00

pub/priv keys and share updates

This commit is contained in:
Kyle Spearrin 2017-02-21 00:27:32 -05:00
parent 47da65be5f
commit 9ca2baba74
10 changed files with 13 additions and 49 deletions

View File

@ -123,7 +123,7 @@ namespace Bit.Api.IdentityServer
claims: claims.Count > 0 ? claims : null, claims: claims.Count > 0 ? claims : null,
customResponse: new Dictionary<string, object> customResponse: new Dictionary<string, object>
{ {
{ "PrivateKey", user.PrivateKey } { "EncryptedPrivateKey", user.PrivateKey }
}); });
} }

View File

@ -7,7 +7,7 @@ namespace Bit.Api.Models
{ {
public string PublicKey { get; set; } public string PublicKey { get; set; }
[Required] [Required]
public string PrivateKey { get; set; } public string EncryptedPrivateKey { get; set; }
public User ToUser(User existingUser) public User ToUser(User existingUser)
{ {
@ -16,7 +16,7 @@ namespace Bit.Api.Models
existingUser.PublicKey = PublicKey; existingUser.PublicKey = PublicKey;
} }
existingUser.PrivateKey = PrivateKey; existingUser.PrivateKey = EncryptedPrivateKey;
return existingUser; return existingUser;
} }
} }

View File

@ -12,19 +12,27 @@ namespace Bit.Api.Models
[StringLength(50)] [StringLength(50)]
public string Email { get; set; } public string Email { get; set; }
[Required] [Required]
[StringLength(300)] [StringLength(1000)]
public string MasterPasswordHash { get; set; } public string MasterPasswordHash { get; set; }
[StringLength(50)] [StringLength(50)]
public string MasterPasswordHint { get; set; } public string MasterPasswordHint { get; set; }
public KeysRequestModel Keys { get; set; }
public User ToUser() public User ToUser()
{ {
return new User var user = new User
{ {
Name = Name, Name = Name,
Email = Email, Email = Email,
MasterPasswordHint = MasterPasswordHint MasterPasswordHint = MasterPasswordHint
}; };
if(Keys != null)
{
Keys.ToUser(user);
}
return user;
} }
} }
} }

View File

@ -33,16 +33,6 @@ namespace Bit.Api.Models
default: default:
throw new ArgumentException("Unsupported " + nameof(Type) + "."); throw new ArgumentException("Unsupported " + nameof(Type) + ".");
} }
if(!string.IsNullOrWhiteSpace(cipher.Shares))
{
var shares = JsonConvert.DeserializeObject<IEnumerable<Cipher.Share>>(cipher.Shares);
var userShare = shares.FirstOrDefault(s => s.UserId == userId);
if(userShare != null)
{
Key = userShare.Key;
}
}
} }
public string Id { get; set; } public string Id { get; set; }

View File

@ -26,16 +26,6 @@ namespace Bit.Api.Models
Id = cipher.Id.ToString(); Id = cipher.Id.ToString();
Name = data.Name; Name = data.Name;
RevisionDate = cipher.RevisionDate; RevisionDate = cipher.RevisionDate;
if(!string.IsNullOrWhiteSpace(cipher.Shares))
{
var shares = JsonConvert.DeserializeObject<IEnumerable<Cipher.Share>>(cipher.Shares);
var userShare = shares.FirstOrDefault(s => s.UserId == userId);
if(userShare != null)
{
Key = userShare.Key;
}
}
} }
public string Id { get; set; } public string Id { get; set; }

View File

@ -32,16 +32,6 @@ namespace Bit.Api.Models
Password = data.Password; Password = data.Password;
Notes = data.Notes; Notes = data.Notes;
RevisionDate = cipher.RevisionDate; RevisionDate = cipher.RevisionDate;
if(!string.IsNullOrWhiteSpace(cipher.Shares))
{
var shares = JsonConvert.DeserializeObject<IEnumerable<Cipher.Share>>(cipher.Shares);
var userShare = shares.FirstOrDefault(s => s.UserId == userId);
if(userShare != null)
{
Key = userShare.Key;
}
}
} }
public string Id { get; set; } public string Id { get; set; }

View File

@ -11,7 +11,6 @@ namespace Bit.Core.Domains
public Enums.CipherType Type { get; set; } public Enums.CipherType Type { get; set; }
public bool Favorite { get; set; } public bool Favorite { get; set; }
public string Data { get; set; } public string Data { get; set; }
public string Shares { get; set; }
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow; public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow; public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
@ -19,12 +18,5 @@ namespace Bit.Core.Domains
{ {
Id = CoreHelpers.GenerateComb(); Id = CoreHelpers.GenerateComb();
} }
public class Share
{
public Guid UserId { get; set; }
public string Key { get; set; }
// TODO: permission flags?
}
} }
} }

View File

@ -5,7 +5,6 @@
@Type TINYINT, @Type TINYINT,
@Favorite BIT, @Favorite BIT,
@Data NVARCHAR(MAX), @Data NVARCHAR(MAX),
@Shares NVARCHAR(MAX),
@CreationDate DATETIME2(7), @CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7) @RevisionDate DATETIME2(7)
AS AS
@ -20,7 +19,6 @@ BEGIN
[Type], [Type],
[Favorite], [Favorite],
[Data], [Data],
[Shares],
[CreationDate], [CreationDate],
[RevisionDate] [RevisionDate]
) )
@ -32,7 +30,6 @@ BEGIN
@Type, @Type,
@Favorite, @Favorite,
@Data, @Data,
@Shares,
@CreationDate, @CreationDate,
@RevisionDate @RevisionDate
) )

View File

@ -5,7 +5,6 @@
@Type TINYINT, @Type TINYINT,
@Favorite BIT, @Favorite BIT,
@Data NVARCHAR(MAX), @Data NVARCHAR(MAX),
@Shares NVARCHAR(MAX),
@CreationDate DATETIME2(7), @CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7) @RevisionDate DATETIME2(7)
AS AS
@ -20,7 +19,6 @@ BEGIN
[Type] = @Type, [Type] = @Type,
[Favorite] = @Favorite, [Favorite] = @Favorite,
[Data] = @Data, [Data] = @Data,
[Shares] = @Shares,
[CreationDate] = @CreationDate, [CreationDate] = @CreationDate,
[RevisionDate] = @RevisionDate [RevisionDate] = @RevisionDate
WHERE WHERE

View File

@ -5,7 +5,6 @@
[Type] TINYINT NOT NULL, [Type] TINYINT NOT NULL,
[Favorite] BIT NOT NULL, [Favorite] BIT NOT NULL,
[Data] NVARCHAR (MAX) NOT NULL, [Data] NVARCHAR (MAX) NOT NULL,
[Shares] NVARCHAR (MAX) NULL,
[CreationDate] DATETIME2 (7) NOT NULL, [CreationDate] DATETIME2 (7) NOT NULL,
[RevisionDate] DATETIME2 (7) NOT NULL, [RevisionDate] DATETIME2 (7) NOT NULL,
CONSTRAINT [PK_Cipher] PRIMARY KEY CLUSTERED ([Id] ASC), CONSTRAINT [PK_Cipher] PRIMARY KEY CLUSTERED ([Id] ASC),