1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-05 23:53:33 +00:00

Compare commits

...

9 Commits

Author SHA1 Message Date
Carlos Gonçalves
485aca083b Merge branch 'main' into vault/pm-2572 2024-06-11 14:11:28 +01:00
Carlos Gonçalves
290266c262 PM-2572 Fix pr comment 2024-05-29 13:27:59 +01:00
Carlos Gonçalves
c40eb9d3db PM-2572 Fix pr comments 2024-05-28 21:31:28 +01:00
Carlos Gonçalves
df9fcd1aca Merge branch 'main' into vault/pm-2572 2024-05-28 18:35:02 +01:00
Carlos Gonçalves
890eff79a2 PM-2572 Fix pr comments 2024-05-28 18:34:41 +01:00
Carlos Gonçalves
265c95b494 PM-2572 Code refactor 2024-05-28 10:59:40 +01:00
Carlos Gonçalves
25e394eb5e Minor change 2024-05-13 18:12:41 +01:00
Carlos Gonçalves
354aec09d9 Minor refactor 2024-05-13 18:03:43 +01:00
Carlos Gonçalves
4332e7a498 PM-2572 Added cipherKey to Attachment and logic to use it 2024-05-13 16:59:39 +01:00

View File

@@ -571,28 +571,39 @@ namespace Bit.Core.Services
await UpsertAsync(data);
}
public async Task ShareWithServerAsync(CipherView cipher, string organizationId, HashSet<string> collectionIds)
public async Task ShareWithServerAsync(CipherView cipherView, string organizationId, HashSet<string> collectionIds)
{
var attachmentTasks = new List<Task>();
if (cipher.Attachments != null)
Cipher cipher = null;
//If the cipher doesn't have a key, we update it
if(cipherView.Key == null && await ShouldUseCipherKeyEncryptionAsync())
{
foreach (var attachment in cipher.Attachments)
await UpdateAndUpsertAsync(cipherView, cipher => _apiService.PutCipherAsync(cipherView.Id, new CipherRequest(cipher)));
cipher = await GetAsync(cipherView.Id);
cipherView = await cipher.DecryptAsync();
}
if (cipherView.Attachments != null)
{
foreach (var attachment in cipherView.Attachments)
{
if (attachment.Key == null)
{
attachmentTasks.Add(ShareAttachmentWithServerAsync(attachment, cipher.Id, organizationId));
attachmentTasks.Add(ShareAttachmentWithServerAsync(attachment, cipherView.Id, organizationId));
}
}
}
await Task.WhenAll(attachmentTasks);
cipher.OrganizationId = organizationId;
cipher.CollectionIds = collectionIds;
var encCipher = await EncryptAsync(cipher);
var request = new CipherShareRequest(encCipher);
var response = await _apiService.PutShareCipherAsync(cipher.Id, request);
var userId = await _stateService.GetActiveUserIdAsync();
var data = new CipherData(response, userId, collectionIds);
await UpsertAsync(data);
cipherView.OrganizationId = organizationId;
cipherView.CollectionIds = collectionIds;
await UpdateAndUpsertAsync(cipherView, cipher => _apiService.PutShareCipherAsync(cipherView.Id, new CipherShareRequest(cipher)), collectionIds);
async Task UpdateAndUpsertAsync(CipherView cipherView, Func<Cipher,Task<CipherResponse>> callPutCipherApi, HashSet<string> collectionIds = null)
{
var cipher = await EncryptAsync(cipherView);
var response = await callPutCipherApi(cipher);
var data = new CipherData(response, await _stateService.GetActiveUserIdAsync(), collectionIds);
await UpsertAsync(data);
}
}
public async Task<Cipher> SaveAttachmentRawWithServerAsync(Cipher cipher, CipherView cipherView, string filename, byte[] data)