mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 18:08:26 +03:00
decrypt with org id
This commit is contained in:
parent
65168c71c0
commit
9879f074b4
6 changed files with 21 additions and 13 deletions
|
@ -31,13 +31,13 @@ namespace Bit.Android.Services
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var extension = MimeTypeMap.GetFileExtensionFromUrl(fileName);
|
var extension = MimeTypeMap.GetFileExtensionFromUrl(fileName.Replace(' ', '_').ToLower());
|
||||||
if(extension == null)
|
if(extension == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var mimeType = MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension.ToLower());
|
var mimeType = MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension);
|
||||||
if(mimeType == null)
|
if(mimeType == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -69,13 +69,13 @@ namespace Bit.Android.Services
|
||||||
|
|
||||||
public bool CanOpenFile(string fileName)
|
public bool CanOpenFile(string fileName)
|
||||||
{
|
{
|
||||||
var extension = MimeTypeMap.GetFileExtensionFromUrl(fileName);
|
var extension = MimeTypeMap.GetFileExtensionFromUrl(fileName.Replace(' ', '_').ToLower());
|
||||||
if(extension == null)
|
if(extension == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var mimeType = MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension.ToLower());
|
var mimeType = MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension);
|
||||||
if(mimeType == null)
|
if(mimeType == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -14,6 +14,6 @@ namespace Bit.App.Abstractions
|
||||||
Task<Tuple<IEnumerable<Login>, IEnumerable<Login>>> GetAllAsync(string uriString);
|
Task<Tuple<IEnumerable<Login>, IEnumerable<Login>>> GetAllAsync(string uriString);
|
||||||
Task<ApiResult<LoginResponse>> SaveAsync(Login login);
|
Task<ApiResult<LoginResponse>> SaveAsync(Login login);
|
||||||
Task<ApiResult> DeleteAsync(string id);
|
Task<ApiResult> DeleteAsync(string id);
|
||||||
Task<byte[]> DownloadAndDecryptAttachmentAsync(SymmetricCryptoKey key, string url);
|
Task<byte[]> DownloadAndDecryptAttachmentAsync(string url, string orgId = null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ using XLabs.Ioc;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Bit.App.Utilities;
|
using Bit.App.Utilities;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Bit.App.Models;
|
||||||
|
|
||||||
namespace Bit.App.Pages
|
namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
|
@ -199,7 +200,7 @@ namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
var attachmentCell = new AttachmentViewCell(attachment, async () =>
|
var attachmentCell = new AttachmentViewCell(attachment, async () =>
|
||||||
{
|
{
|
||||||
await OpenAttachmentAsync(attachment);
|
await OpenAttachmentAsync(login, attachment);
|
||||||
});
|
});
|
||||||
AttachmentCells.Add(attachmentCell);
|
AttachmentCells.Add(attachmentCell);
|
||||||
AttachmentsSection.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
|
// 20 MB warning
|
||||||
if(attachment.Size >= 20971520 && !(await _userDialogs.ConfirmAsync(
|
if(attachment.Size >= 20971520 && !(await _userDialogs.ConfirmAsync(
|
||||||
|
@ -246,7 +247,7 @@ namespace Bit.App.Pages
|
||||||
}
|
}
|
||||||
|
|
||||||
_userDialogs.ShowLoading(AppResources.Downloading, MaskType.Black);
|
_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();
|
_userDialogs.HideLoading();
|
||||||
if(data == null)
|
if(data == null)
|
||||||
{
|
{
|
||||||
|
|
2
src/App/Resources/AppResources.Designer.cs
generated
2
src/App/Resources/AppResources.Designer.cs
generated
|
@ -2024,7 +2024,7 @@ namespace Bit.App.Resources {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public static string UnableToOpenFile {
|
public static string UnableToOpenFile {
|
||||||
get {
|
get {
|
||||||
|
|
|
@ -912,7 +912,7 @@
|
||||||
<value>Unable to download file.</value>
|
<value>Unable to download file.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="UnableToOpenFile" xml:space="preserve">
|
<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>
|
||||||
<data name="Downloading" xml:space="preserve">
|
<data name="Downloading" xml:space="preserve">
|
||||||
<value>Downloading...</value>
|
<value>Downloading...</value>
|
||||||
|
|
|
@ -221,7 +221,7 @@ namespace Bit.App.Services
|
||||||
return response;
|
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())
|
using(var client = new HttpClient())
|
||||||
{
|
{
|
||||||
|
@ -238,8 +238,15 @@ namespace Bit.App.Services
|
||||||
{
|
{
|
||||||
return null;
|
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
|
catch
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue