mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 23:25:45 +03:00
Fixed potential broadcast leak & policy value parsing (#756)
This commit is contained in:
parent
b9c134654f
commit
b65b01fe3d
2 changed files with 45 additions and 21 deletions
|
@ -24,7 +24,7 @@ namespace Bit.App.Pages
|
|||
{
|
||||
base.OnAppearing();
|
||||
await _vm.InitAsync();
|
||||
_broadcasterService.Subscribe(nameof(AttachmentsPage), (message) =>
|
||||
_broadcasterService.Subscribe(nameof(ExportVaultPage), (message) =>
|
||||
{
|
||||
if(message.Command == "selectSaveFileResult")
|
||||
{
|
||||
|
@ -45,6 +45,7 @@ namespace Bit.App.Pages
|
|||
protected async override void OnDisappearing()
|
||||
{
|
||||
base.OnDisappearing();
|
||||
_broadcasterService.Unsubscribe(nameof(ExportVaultPage));
|
||||
}
|
||||
|
||||
public Entry MasterPasswordEntry { get; set; }
|
||||
|
|
|
@ -344,55 +344,78 @@ namespace Bit.Core.Services
|
|||
enforcedOptions = new PasswordGeneratorPolicyOptions();
|
||||
}
|
||||
|
||||
var currentPolicyMinLength = currentPolicy.Data["minLength"];
|
||||
if(currentPolicyMinLength != null &&
|
||||
(int)(long)currentPolicyMinLength > enforcedOptions.MinLength)
|
||||
var minLength = GetPolicyInt(currentPolicy, "minLength");
|
||||
if(minLength != null && (int)(long)minLength > enforcedOptions.MinLength)
|
||||
{
|
||||
enforcedOptions.MinLength = (int)(long)currentPolicyMinLength;
|
||||
enforcedOptions.MinLength = (int)(long)minLength;
|
||||
}
|
||||
|
||||
var currentPolicyUseUpper = currentPolicy.Data["useUpper"];
|
||||
if(currentPolicyUseUpper != null && (bool)currentPolicyUseUpper)
|
||||
var useUpper = GetPolicyBool(currentPolicy, "useUpper");
|
||||
if(useUpper != null && (bool)useUpper)
|
||||
{
|
||||
enforcedOptions.UseUppercase = true;
|
||||
}
|
||||
|
||||
var currentPolicyUseLower = currentPolicy.Data["useLower"];
|
||||
if(currentPolicyUseLower != null && (bool)currentPolicyUseLower)
|
||||
var useLower = GetPolicyBool(currentPolicy, "useLower");
|
||||
if(useLower != null && (bool)useLower)
|
||||
{
|
||||
enforcedOptions.UseLowercase = true;
|
||||
}
|
||||
|
||||
var currentPolicyUseNumbers = currentPolicy.Data["useNumbers"];
|
||||
if(currentPolicyUseNumbers != null && (bool)currentPolicyUseNumbers)
|
||||
var useNumbers = GetPolicyBool(currentPolicy, "useNumbers");
|
||||
if(useNumbers != null && (bool)useNumbers)
|
||||
{
|
||||
enforcedOptions.UseNumbers = true;
|
||||
}
|
||||
|
||||
var currentPolicyMinNumbers = currentPolicy.Data["minNumbers"];
|
||||
if(currentPolicyMinNumbers != null &&
|
||||
(int)(long)currentPolicyMinNumbers > enforcedOptions.NumberCount)
|
||||
var minNumbers = GetPolicyInt(currentPolicy, "minNumbers");
|
||||
if(minNumbers != null && (int)(long)minNumbers > enforcedOptions.NumberCount)
|
||||
{
|
||||
enforcedOptions.NumberCount = (int)(long)currentPolicyMinNumbers;
|
||||
enforcedOptions.NumberCount = (int)(long)minNumbers;
|
||||
}
|
||||
|
||||
var currentPolicyUseSpecial = currentPolicy.Data["useSpecial"];
|
||||
if(currentPolicyUseSpecial != null && (bool)currentPolicyUseSpecial)
|
||||
var useSpecial = GetPolicyBool(currentPolicy, "useSpecial");
|
||||
if(useSpecial != null && (bool)useSpecial)
|
||||
{
|
||||
enforcedOptions.UseSpecial = true;
|
||||
}
|
||||
|
||||
var currentPolicyMinSpecial = currentPolicy.Data["minSpecial"];
|
||||
if(currentPolicyMinSpecial != null &&
|
||||
(int)(long)currentPolicyMinSpecial > enforcedOptions.SpecialCount)
|
||||
var minSpecial = GetPolicyInt(currentPolicy, "minSpecial");
|
||||
if(minSpecial != null && (int)(long)minSpecial > enforcedOptions.SpecialCount)
|
||||
{
|
||||
enforcedOptions.SpecialCount = (int)(long)currentPolicyMinSpecial;
|
||||
enforcedOptions.SpecialCount = (int)(long)minSpecial;
|
||||
}
|
||||
}
|
||||
|
||||
return enforcedOptions;
|
||||
}
|
||||
|
||||
private int? GetPolicyInt(Policy policy, string key)
|
||||
{
|
||||
if(policy.Data.ContainsKey(key))
|
||||
{
|
||||
var value = policy.Data[key];
|
||||
if(value != null)
|
||||
{
|
||||
return (int)(long)value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool? GetPolicyBool(Policy policy, string key)
|
||||
{
|
||||
if(policy.Data.ContainsKey(key))
|
||||
{
|
||||
var value = policy.Data[key];
|
||||
if(value != null)
|
||||
{
|
||||
return (bool)value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task SaveOptionsAsync(PasswordGenerationOptions options)
|
||||
{
|
||||
await _storageService.SaveAsync(Keys_Options, options);
|
||||
|
|
Loading…
Reference in a new issue