-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Arch/cipher scene #7241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Arch/cipher scene #7241
Changes from all commits
fccc71a
a7d282f
9c1a957
56c7428
0641593
234b79c
728090a
1807b46
221ae12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| using System.ComponentModel.DataAnnotations; | ||
| using Bit.Core.Repositories; | ||
| using Bit.Core.Vault.Repositories; | ||
| using Bit.Seeder.Factories; | ||
| using Bit.Seeder.Models; | ||
| using Bit.Seeder.Services; | ||
|
|
||
| namespace Bit.Seeder.Scenes; | ||
|
|
||
| public class UserCardCipherScene(IUserRepository userRepository, ICipherRepository cipherRepository, IManglerService manglerService) : IScene<UserCardCipherScene.Request, UserCardCipherScene.Result> | ||
| { | ||
| public class Request | ||
| { | ||
| [Required] | ||
| public required Guid UserId { get; set; } | ||
| [Required] | ||
| public required string UserKeyB64 { get; set; } | ||
| [Required] | ||
| public required string Name { get; set; } | ||
| public required string CardholderName { get; set; } | ||
| public required string Number { get; set; } | ||
| public required string ExpMonth { get; set; } | ||
| public required string ExpYear { get; set; } | ||
| public required string Code { get; set; } | ||
| public string? Notes { get; set; } | ||
| } | ||
|
|
||
| public class Result | ||
| { | ||
| public required Guid CipherId { get; set; } | ||
| } | ||
|
|
||
| public async Task<SceneResult<Result>> SeedAsync(Request request) | ||
| { | ||
| var user = await userRepository.GetByIdAsync(request.UserId); | ||
| if (user == null) | ||
| { | ||
| throw new Exception($"User with ID {request.UserId} not found."); | ||
| } | ||
|
|
||
| var card = new CardViewDto | ||
| { | ||
| CardholderName = request.CardholderName, | ||
| Number = request.Number, | ||
| ExpMonth = request.ExpMonth, | ||
| ExpYear = request.ExpYear, | ||
| Code = request.Code | ||
| }; | ||
| var cipher = CardCipherSeeder.Create(request.UserKeyB64, request.Name, card: card, userId: request.UserId, notes: request.Notes); | ||
|
|
||
| await cipherRepository.CreateAsync(cipher); | ||
|
|
||
| return new SceneResult<Result>( | ||
| result: new Result | ||
| { | ||
| CipherId = cipher.Id | ||
| }, | ||
| mangleMap: manglerService.GetMangleMap()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| using System.ComponentModel.DataAnnotations; | ||
| using Bit.Core.Repositories; | ||
| using Bit.Core.Vault.Repositories; | ||
| using Bit.Seeder.Factories; | ||
| using Bit.Seeder.Models; | ||
| using Bit.Seeder.Services; | ||
|
|
||
| namespace Bit.Seeder.Scenes; | ||
|
|
||
| public class UserIdentityCipherScene(IUserRepository userRepository, ICipherRepository cipherRepository, IManglerService manglerService) : IScene<UserIdentityCipherScene.Request, UserIdentityCipherScene.Result> | ||
| { | ||
| public class Request | ||
| { | ||
| [Required] | ||
| public required Guid UserId { get; set; } | ||
| [Required] | ||
| public required string UserKeyB64 { get; set; } | ||
| [Required] | ||
| public required string Name { get; set; } | ||
| public string? Title { get; set; } | ||
| public string? FirstName { get; set; } | ||
| public string? MiddleName { get; set; } | ||
| public string? LastName { get; set; } | ||
| public string? Notes { get; set; } | ||
| } | ||
|
|
||
| public class Result | ||
| { | ||
| public required Guid CipherId { get; set; } | ||
| } | ||
|
|
||
| public async Task<SceneResult<Result>> SeedAsync(Request request) | ||
| { | ||
| var user = await userRepository.GetByIdAsync(request.UserId); | ||
| if (user == null) | ||
| { | ||
| throw new Exception($"User with ID {request.UserId} not found."); | ||
| } | ||
|
|
||
| var identity = new IdentityViewDto | ||
| { | ||
| Title = request.Title, | ||
| FirstName = request.FirstName, | ||
| MiddleName = request.MiddleName, | ||
| LastName = request.LastName | ||
| }; | ||
| var cipher = IdentityCipherSeeder.Create(request.UserKeyB64, request.Name, userId: request.UserId, identity: identity, notes: request.Notes); | ||
|
|
||
| await cipherRepository.CreateAsync(cipher); | ||
|
|
||
| return new SceneResult<Result>( | ||
| result: new Result | ||
| { | ||
| CipherId = cipher.Id | ||
| }, | ||
| mangleMap: manglerService.GetMangleMap()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,52 @@ | ||||||
| using System.ComponentModel.DataAnnotations; | ||||||
| using Bit.Core.Repositories; | ||||||
| using Bit.Core.Vault.Repositories; | ||||||
| using Bit.Seeder.Factories; | ||||||
| using Bit.Seeder.Services; | ||||||
|
|
||||||
| namespace Bit.Seeder.Scenes; | ||||||
|
|
||||||
| public class UserLoginCipherScene(IUserRepository userRepository, ICipherRepository cipherRepository, IManglerService manglerService) : IScene<UserLoginCipherScene.Request, UserLoginCipherScene.Result> | ||||||
| { | ||||||
| public class Request | ||||||
| { | ||||||
| [Required] | ||||||
| public required Guid UserId { get; set; } | ||||||
| [Required] | ||||||
| public required string UserKeyB64 { get; set; } | ||||||
| [Required] | ||||||
| public required string Name { get; set; } | ||||||
| public string? Username { get; set; } | ||||||
| public string? Password { get; set; } | ||||||
| public string? Uri { get; set; } | ||||||
| public string? Notes { get; set; } | ||||||
| public bool Reprompt { get; set; } | ||||||
| public bool Deleted { get; set; } | ||||||
| public IEnumerable<(string name, string value, int type)>? Fields { get; set; } | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 [SUGGESTION] C# value tuples ( Consider using
Suggested change
This would require a small adapter in |
||||||
| } | ||||||
|
|
||||||
| public class Result | ||||||
| { | ||||||
| public required Guid CipherId { get; set; } | ||||||
| } | ||||||
|
|
||||||
| public async Task<SceneResult<Result>> SeedAsync(Request request) | ||||||
| { | ||||||
| var user = await userRepository.GetByIdAsync(request.UserId); | ||||||
| if (user == null) | ||||||
| { | ||||||
| throw new Exception($"User with ID {request.UserId} not found."); | ||||||
| } | ||||||
|
|
||||||
| var cipher = LoginCipherSeeder.Create(request.UserKeyB64, request.Name, userId: request.UserId, username: request.Username, password: request.Password, uri: request.Uri, notes: request.Notes, fields: request.Fields, reprompt: request.Reprompt, deleted: request.Deleted); | ||||||
|
|
||||||
| await cipherRepository.CreateAsync(cipher); | ||||||
|
|
||||||
| return new SceneResult<Result>( | ||||||
| result: new Result | ||||||
| { | ||||||
| CipherId = cipher.Id | ||||||
| }, | ||||||
| mangleMap: manglerService.GetMangleMap()); | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| using System.ComponentModel.DataAnnotations; | ||
| using Bit.Core.Repositories; | ||
| using Bit.Core.Vault.Repositories; | ||
| using Bit.Seeder.Factories; | ||
| using Bit.Seeder.Services; | ||
|
|
||
| namespace Bit.Seeder.Scenes; | ||
|
|
||
| public class UserSecureNoteCipherScene(IUserRepository userRepository, ICipherRepository cipherRepository, IManglerService manglerService) : IScene<UserSecureNoteCipherScene.Request, UserSecureNoteCipherScene.Result> | ||
| { | ||
| public class Request | ||
| { | ||
| [Required] | ||
| public required Guid UserId { get; set; } | ||
| [Required] | ||
| public required string UserKeyB64 { get; set; } | ||
| [Required] | ||
| public required string Name { get; set; } | ||
| public string? Notes { get; set; } | ||
| } | ||
|
|
||
| public class Result | ||
| { | ||
| public required Guid CipherId { get; set; } | ||
| } | ||
|
|
||
| public async Task<SceneResult<Result>> SeedAsync(Request request) | ||
| { | ||
| var user = await userRepository.GetByIdAsync(request.UserId); | ||
| if (user == null) | ||
| { | ||
| throw new Exception($"User with ID {request.UserId} not found."); | ||
| } | ||
|
|
||
| var cipher = SecureNoteCipherSeeder.Create(request.UserKeyB64, request.Name, userId: request.UserId, notes: request.Notes); | ||
|
|
||
| await cipherRepository.CreateAsync(cipher); | ||
|
|
||
| return new SceneResult<Result>( | ||
| result: new Result | ||
| { | ||
| CipherId = cipher.Id | ||
| }, | ||
| mangleMap: manglerService.GetMangleMap()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| using System.ComponentModel.DataAnnotations; | ||
| using Bit.Core.Repositories; | ||
| using Bit.Core.Vault.Repositories; | ||
| using Bit.Seeder.Factories; | ||
| using Bit.Seeder.Models; | ||
| using Bit.Seeder.Services; | ||
|
|
||
| namespace Bit.Seeder.Scenes; | ||
|
|
||
| public class UserSshKeyCipherScene(IUserRepository userRepository, ICipherRepository cipherRepository, IManglerService manglerService) : IScene<UserSshKeyCipherScene.Request, UserSshKeyCipherScene.Result> | ||
| { | ||
| public class Request | ||
| { | ||
| [Required] | ||
| public required Guid UserId { get; set; } | ||
| [Required] | ||
| public required string UserKeyB64 { get; set; } | ||
| [Required] | ||
| public required string Name { get; set; } | ||
| public string? PrivateKey { get; set; } | ||
| public string? PublicKey { get; set; } | ||
| public string? Fingerprint { get; set; } | ||
| public bool Reprompt { get; set; } | ||
| public string? Notes { get; set; } | ||
| } | ||
theMickster marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public class Result | ||
| { | ||
| public required Guid CipherId { get; set; } | ||
| } | ||
|
|
||
| public async Task<SceneResult<Result>> SeedAsync(Request request) | ||
| { | ||
| var user = await userRepository.GetByIdAsync(request.UserId); | ||
| if (user == null) | ||
| { | ||
| throw new Exception($"User with ID {request.UserId} not found."); | ||
| } | ||
|
|
||
| var sshKey = new SshKeyViewDto | ||
| { | ||
| PrivateKey = request.PrivateKey, | ||
| PublicKey = request.PublicKey, | ||
| Fingerprint = request.Fingerprint | ||
| }; | ||
| var cipher = SshKeyCipherSeeder.Create(request.UserKeyB64, request.Name, userId: request.UserId, sshKey: sshKey, notes: request.Notes, reprompt: request.Reprompt); | ||
|
|
||
| await cipherRepository.CreateAsync(cipher); | ||
|
|
||
| return new SceneResult<Result>( | ||
| result: new Result | ||
| { | ||
| CipherId = cipher.Id | ||
| }, | ||
| mangleMap: manglerService.GetMangleMap()); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DeletedDateis set onCipherViewDtobut never propagated to theCipherentity -- settingdeleted: truesilently has no effectDetails and fix
CipherEncryption.CreateEntity(inCipherEncryption.cslines 46-57) does not copyDeletedDatefromEncryptedCipherDtoto the returnedCipherentity. It only setsId,OrganizationId,UserId,Type,Data,Key,Reprompt,CreationDate, andRevisionDate.The
EncryptedCipherDtodoes carryDeletedDatethrough encryption, but it is discarded when building the final entity.Fix in
CipherEncryption.CreateEntity:This requires adding a
DeletedDateparameter toCreateEntityor reading it from theEncryptedCipherDtothat is already passed in.