2021-05-21 15:13:54 +02:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.App.Resources;
|
2021-11-24 20:09:39 +01:00
|
|
|
|
using Bit.Core.Abstractions;
|
2021-05-21 15:13:54 +02:00
|
|
|
|
using System;
|
2021-11-11 02:46:48 +01:00
|
|
|
|
using Bit.Core.Utilities;
|
2021-05-21 15:13:54 +02:00
|
|
|
|
|
|
|
|
|
namespace Bit.App.Services
|
|
|
|
|
{
|
|
|
|
|
public class MobilePasswordRepromptService : IPasswordRepromptService
|
|
|
|
|
{
|
|
|
|
|
private readonly IPlatformUtilsService _platformUtilsService;
|
|
|
|
|
private readonly ICryptoService _cryptoService;
|
|
|
|
|
|
|
|
|
|
public MobilePasswordRepromptService(IPlatformUtilsService platformUtilsService, ICryptoService cryptoService)
|
|
|
|
|
{
|
|
|
|
|
_platformUtilsService = platformUtilsService;
|
|
|
|
|
_cryptoService = cryptoService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string[] ProtectedFields { get; } = { "LoginTotp", "LoginPassword", "H_FieldValue", "CardNumber", "CardCode" };
|
|
|
|
|
|
|
|
|
|
public async Task<bool> ShowPasswordPromptAsync()
|
|
|
|
|
{
|
2021-11-24 20:09:39 +01:00
|
|
|
|
return await _platformUtilsService.ShowPasswordDialogAsync(AppResources.PasswordConfirmation, AppResources.PasswordConfirmationDesc, ValidatePasswordAsync);
|
|
|
|
|
}
|
2021-11-11 02:46:48 +01:00
|
|
|
|
|
2021-11-24 20:09:39 +01:00
|
|
|
|
public async Task<(string password, bool valid)> ShowPasswordPromptAndGetItAsync()
|
|
|
|
|
{
|
|
|
|
|
return await _platformUtilsService.ShowPasswordDialogAndGetItAsync(AppResources.PasswordConfirmation, AppResources.PasswordConfirmationDesc, ValidatePasswordAsync);
|
|
|
|
|
}
|
2021-05-21 15:13:54 +02:00
|
|
|
|
|
2021-11-24 20:09:39 +01:00
|
|
|
|
private async Task<bool> ValidatePasswordAsync(string password)
|
|
|
|
|
{
|
|
|
|
|
// Assume user has canceled.
|
|
|
|
|
if (string.IsNullOrWhiteSpace(password))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
2021-05-21 15:13:54 +02:00
|
|
|
|
};
|
|
|
|
|
|
2021-11-24 20:09:39 +01:00
|
|
|
|
return await _cryptoService.CompareAndUpdateKeyHashAsync(password, null);
|
2021-05-21 15:13:54 +02:00
|
|
|
|
}
|
2021-11-11 02:46:48 +01:00
|
|
|
|
|
|
|
|
|
public async Task<bool> Enabled()
|
|
|
|
|
{
|
|
|
|
|
var keyConnectorService = ServiceContainer.Resolve<IKeyConnectorService>("keyConnectorService");
|
|
|
|
|
return !await keyConnectorService.GetUsesKeyConnector();
|
|
|
|
|
}
|
2021-05-21 15:13:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|