1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-06-30 11:14:51 +02:00

decrypt with org id

This commit is contained in:
Kyle Spearrin 2017-07-13 12:08:48 -04:00
parent 65168c71c0
commit 9879f074b4
6 changed files with 21 additions and 13 deletions

View File

@ -31,13 +31,13 @@ namespace Bit.Android.Services
return false;
}
var extension = MimeTypeMap.GetFileExtensionFromUrl(fileName);
var extension = MimeTypeMap.GetFileExtensionFromUrl(fileName.Replace(' ', '_').ToLower());
if(extension == null)
{
return false;
}
var mimeType = MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension.ToLower());
var mimeType = MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension);
if(mimeType == null)
{
return false;
@ -69,13 +69,13 @@ namespace Bit.Android.Services
public bool CanOpenFile(string fileName)
{
var extension = MimeTypeMap.GetFileExtensionFromUrl(fileName);
var extension = MimeTypeMap.GetFileExtensionFromUrl(fileName.Replace(' ', '_').ToLower());
if(extension == null)
{
return false;
}
var mimeType = MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension.ToLower());
var mimeType = MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension);
if(mimeType == null)
{
return false;

View File

@ -14,6 +14,6 @@ namespace Bit.App.Abstractions
Task<Tuple<IEnumerable<Login>, IEnumerable<Login>>> GetAllAsync(string uriString);
Task<ApiResult<LoginResponse>> SaveAsync(Login login);
Task<ApiResult> DeleteAsync(string id);
Task<byte[]> DownloadAndDecryptAttachmentAsync(SymmetricCryptoKey key, string url);
Task<byte[]> DownloadAndDecryptAttachmentAsync(string url, string orgId = null);
}
}

View File

@ -9,6 +9,7 @@ using XLabs.Ioc;
using System.Threading.Tasks;
using Bit.App.Utilities;
using System.Collections.Generic;
using Bit.App.Models;
namespace Bit.App.Pages
{
@ -199,7 +200,7 @@ namespace Bit.App.Pages
{
var attachmentCell = new AttachmentViewCell(attachment, async () =>
{
await OpenAttachmentAsync(attachment);
await OpenAttachmentAsync(login, attachment);
});
AttachmentCells.Add(attachmentCell);
AttachmentsSection.Add(attachmentCell);
@ -229,7 +230,7 @@ namespace Bit.App.Pages
}
}
private async Task OpenAttachmentAsync(VaultViewLoginPageModel.Attachment attachment)
private async Task OpenAttachmentAsync(Login login, VaultViewLoginPageModel.Attachment attachment)
{
// 20 MB warning
if(attachment.Size >= 20971520 && !(await _userDialogs.ConfirmAsync(
@ -246,7 +247,7 @@ namespace Bit.App.Pages
}
_userDialogs.ShowLoading(AppResources.Downloading, MaskType.Black);
var data = await _loginService.DownloadAndDecryptAttachmentAsync(null, attachment.Url);
var data = await _loginService.DownloadAndDecryptAttachmentAsync(attachment.Url, login.OrganizationId);
_userDialogs.HideLoading();
if(data == null)
{

View File

@ -2024,7 +2024,7 @@ namespace Bit.App.Resources {
}
/// <summary>
/// Looks up a localized string similar to Your device cannot open this type of tile..
/// Looks up a localized string similar to Your device cannot open this type of file..
/// </summary>
public static string UnableToOpenFile {
get {

View File

@ -912,7 +912,7 @@
<value>Unable to download file.</value>
</data>
<data name="UnableToOpenFile" xml:space="preserve">
<value>Your device cannot open this type of tile.</value>
<value>Your device cannot open this type of file.</value>
</data>
<data name="Downloading" xml:space="preserve">
<value>Downloading...</value>

View File

@ -221,7 +221,7 @@ namespace Bit.App.Services
return response;
}
public async Task<byte[]> DownloadAndDecryptAttachmentAsync(SymmetricCryptoKey key, string url)
public async Task<byte[]> DownloadAndDecryptAttachmentAsync(string url, string orgId = null)
{
using(var client = new HttpClient())
{
@ -238,8 +238,15 @@ namespace Bit.App.Services
{
return null;
}
return _cryptoService.DecryptToBytes(data, key);
if(!string.IsNullOrWhiteSpace(orgId))
{
return _cryptoService.DecryptToBytes(data, _cryptoService.GetOrgKey(orgId));
}
else
{
return _cryptoService.DecryptToBytes(data, null);
}
}
catch
{