mirror of
https://github.com/bitwarden/android.git
synced 2024-11-01 07:35:52 +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();
|
base.OnAppearing();
|
||||||
await _vm.InitAsync();
|
await _vm.InitAsync();
|
||||||
_broadcasterService.Subscribe(nameof(AttachmentsPage), (message) =>
|
_broadcasterService.Subscribe(nameof(ExportVaultPage), (message) =>
|
||||||
{
|
{
|
||||||
if(message.Command == "selectSaveFileResult")
|
if(message.Command == "selectSaveFileResult")
|
||||||
{
|
{
|
||||||
|
@ -45,6 +45,7 @@ namespace Bit.App.Pages
|
||||||
protected async override void OnDisappearing()
|
protected async override void OnDisappearing()
|
||||||
{
|
{
|
||||||
base.OnDisappearing();
|
base.OnDisappearing();
|
||||||
|
_broadcasterService.Unsubscribe(nameof(ExportVaultPage));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entry MasterPasswordEntry { get; set; }
|
public Entry MasterPasswordEntry { get; set; }
|
||||||
|
|
|
@ -344,55 +344,78 @@ namespace Bit.Core.Services
|
||||||
enforcedOptions = new PasswordGeneratorPolicyOptions();
|
enforcedOptions = new PasswordGeneratorPolicyOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentPolicyMinLength = currentPolicy.Data["minLength"];
|
var minLength = GetPolicyInt(currentPolicy, "minLength");
|
||||||
if(currentPolicyMinLength != null &&
|
if(minLength != null && (int)(long)minLength > enforcedOptions.MinLength)
|
||||||
(int)(long)currentPolicyMinLength > enforcedOptions.MinLength)
|
|
||||||
{
|
{
|
||||||
enforcedOptions.MinLength = (int)(long)currentPolicyMinLength;
|
enforcedOptions.MinLength = (int)(long)minLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentPolicyUseUpper = currentPolicy.Data["useUpper"];
|
var useUpper = GetPolicyBool(currentPolicy, "useUpper");
|
||||||
if(currentPolicyUseUpper != null && (bool)currentPolicyUseUpper)
|
if(useUpper != null && (bool)useUpper)
|
||||||
{
|
{
|
||||||
enforcedOptions.UseUppercase = true;
|
enforcedOptions.UseUppercase = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentPolicyUseLower = currentPolicy.Data["useLower"];
|
var useLower = GetPolicyBool(currentPolicy, "useLower");
|
||||||
if(currentPolicyUseLower != null && (bool)currentPolicyUseLower)
|
if(useLower != null && (bool)useLower)
|
||||||
{
|
{
|
||||||
enforcedOptions.UseLowercase = true;
|
enforcedOptions.UseLowercase = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentPolicyUseNumbers = currentPolicy.Data["useNumbers"];
|
var useNumbers = GetPolicyBool(currentPolicy, "useNumbers");
|
||||||
if(currentPolicyUseNumbers != null && (bool)currentPolicyUseNumbers)
|
if(useNumbers != null && (bool)useNumbers)
|
||||||
{
|
{
|
||||||
enforcedOptions.UseNumbers = true;
|
enforcedOptions.UseNumbers = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentPolicyMinNumbers = currentPolicy.Data["minNumbers"];
|
var minNumbers = GetPolicyInt(currentPolicy, "minNumbers");
|
||||||
if(currentPolicyMinNumbers != null &&
|
if(minNumbers != null && (int)(long)minNumbers > enforcedOptions.NumberCount)
|
||||||
(int)(long)currentPolicyMinNumbers > enforcedOptions.NumberCount)
|
|
||||||
{
|
{
|
||||||
enforcedOptions.NumberCount = (int)(long)currentPolicyMinNumbers;
|
enforcedOptions.NumberCount = (int)(long)minNumbers;
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentPolicyUseSpecial = currentPolicy.Data["useSpecial"];
|
var useSpecial = GetPolicyBool(currentPolicy, "useSpecial");
|
||||||
if(currentPolicyUseSpecial != null && (bool)currentPolicyUseSpecial)
|
if(useSpecial != null && (bool)useSpecial)
|
||||||
{
|
{
|
||||||
enforcedOptions.UseSpecial = true;
|
enforcedOptions.UseSpecial = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentPolicyMinSpecial = currentPolicy.Data["minSpecial"];
|
var minSpecial = GetPolicyInt(currentPolicy, "minSpecial");
|
||||||
if(currentPolicyMinSpecial != null &&
|
if(minSpecial != null && (int)(long)minSpecial > enforcedOptions.SpecialCount)
|
||||||
(int)(long)currentPolicyMinSpecial > enforcedOptions.SpecialCount)
|
|
||||||
{
|
{
|
||||||
enforcedOptions.SpecialCount = (int)(long)currentPolicyMinSpecial;
|
enforcedOptions.SpecialCount = (int)(long)minSpecial;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return enforcedOptions;
|
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)
|
public async Task SaveOptionsAsync(PasswordGenerationOptions options)
|
||||||
{
|
{
|
||||||
await _storageService.SaveAsync(Keys_Options, options);
|
await _storageService.SaveAsync(Keys_Options, options);
|
||||||
|
|
Loading…
Reference in a new issue