1
0
mirror of https://github.com/bitwarden/mobile synced 2026-01-04 17:43:17 +00:00

attachments on view page abd device actions

This commit is contained in:
Kyle Spearrin
2019-04-29 16:09:27 -04:00
parent a5bf16a415
commit 1f4bdb04ee
10 changed files with 264 additions and 4 deletions

View File

@@ -35,5 +35,6 @@ namespace Bit.Core.Abstractions
Task UpdateLastUsedDateAsync(string id);
Task UpsertAsync(CipherData cipher);
Task UpsertAsync(List<CipherData> cipher);
Task<byte[]> DownloadAndDecryptAttachmentAsync(AttachmentView attachment, string organizationId);
}
}

View File

@@ -9,5 +9,6 @@
public static string DefaultUriMatch = "defaultUriMatch";
public static string DisableAutoTotpCopyKey = "disableAutoTotpCopy";
public static string EnvironmentUrlsKey = "environmentUrls";
public static string LastFileCacheClearKey = "lastFileCacheClear";
}
}

View File

@@ -20,5 +20,17 @@ namespace Bit.Core.Models.View
public string SizeName { get; set; }
public string FileName { get; set; }
public SymmetricCryptoKey Key { get; set; }
public long FileSize
{
get
{
if(!string.IsNullOrWhiteSpace(Size) && long.TryParse(Size, out var s))
{
return s;
}
return 0;
}
}
}
}

View File

@@ -678,6 +678,27 @@ namespace Bit.Core.Services
await DeleteAttachmentAsync(id, attachmentId);
}
public async Task<byte[]> DownloadAndDecryptAttachmentAsync(AttachmentView attachment, string organizationId)
{
try
{
var response = await _httpClient.GetAsync(new Uri(attachment.Url));
if(!response.IsSuccessStatusCode)
{
return null;
}
var data = await response.Content.ReadAsByteArrayAsync();
if(data == null)
{
return null;
}
var key = attachment.Key ?? await _cryptoService.GetOrgKeyAsync(organizationId);
return await _cryptoService.DecryptFromBytesAsync(data, key);
}
catch { }
return null;
}
// Helpers
private async Task ShareAttachmentWithServerAsync(AttachmentView attachmentView, string cipherId,