From 9879f074b4068b7f25b122f88a2b32c834e9b51d Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 13 Jul 2017 12:08:48 -0400 Subject: [PATCH] decrypt with org id --- src/Android/Services/DeviceActionService.cs | 8 ++++---- src/App/Abstractions/Services/ILoginService.cs | 2 +- src/App/Pages/Vault/VaultViewLoginPage.cs | 7 ++++--- src/App/Resources/AppResources.Designer.cs | 2 +- src/App/Resources/AppResources.resx | 2 +- src/App/Services/LoginService.cs | 13 ++++++++++--- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/Android/Services/DeviceActionService.cs b/src/Android/Services/DeviceActionService.cs index 3ed9392b1..114ec28f2 100644 --- a/src/Android/Services/DeviceActionService.cs +++ b/src/Android/Services/DeviceActionService.cs @@ -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; diff --git a/src/App/Abstractions/Services/ILoginService.cs b/src/App/Abstractions/Services/ILoginService.cs index 0e6167b9a..0eb48ead6 100644 --- a/src/App/Abstractions/Services/ILoginService.cs +++ b/src/App/Abstractions/Services/ILoginService.cs @@ -14,6 +14,6 @@ namespace Bit.App.Abstractions Task, IEnumerable>> GetAllAsync(string uriString); Task> SaveAsync(Login login); Task DeleteAsync(string id); - Task DownloadAndDecryptAttachmentAsync(SymmetricCryptoKey key, string url); + Task DownloadAndDecryptAttachmentAsync(string url, string orgId = null); } } diff --git a/src/App/Pages/Vault/VaultViewLoginPage.cs b/src/App/Pages/Vault/VaultViewLoginPage.cs index 89fde7eb6..48363e258 100644 --- a/src/App/Pages/Vault/VaultViewLoginPage.cs +++ b/src/App/Pages/Vault/VaultViewLoginPage.cs @@ -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) { diff --git a/src/App/Resources/AppResources.Designer.cs b/src/App/Resources/AppResources.Designer.cs index d9c1a58d7..801124198 100644 --- a/src/App/Resources/AppResources.Designer.cs +++ b/src/App/Resources/AppResources.Designer.cs @@ -2024,7 +2024,7 @@ namespace Bit.App.Resources { } /// - /// 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.. /// public static string UnableToOpenFile { get { diff --git a/src/App/Resources/AppResources.resx b/src/App/Resources/AppResources.resx index 628be1fca..27350e1a8 100644 --- a/src/App/Resources/AppResources.resx +++ b/src/App/Resources/AppResources.resx @@ -912,7 +912,7 @@ Unable to download file. - Your device cannot open this type of tile. + Your device cannot open this type of file. Downloading... diff --git a/src/App/Services/LoginService.cs b/src/App/Services/LoginService.cs index 8f890d597..c439e556b 100644 --- a/src/App/Services/LoginService.cs +++ b/src/App/Services/LoginService.cs @@ -221,7 +221,7 @@ namespace Bit.App.Services return response; } - public async Task DownloadAndDecryptAttachmentAsync(SymmetricCryptoKey key, string url) + public async Task 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 {