Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Account Deletion SSO with CME OTP parameter #1751

Merged
merged 1 commit into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Android/MainApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public MainApplication(IntPtr handle, JniHandleOwnership transer)
var deleteAccountActionFlowExecutioner = new DeleteAccountActionFlowExecutioner(
ServiceContainer.Resolve<IApiService>("apiService"),
ServiceContainer.Resolve<IMessagingService>("messagingService"),
ServiceContainer.Resolve<ICryptoService>("cryptoService"),
ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService"),
ServiceContainer.Resolve<IDeviceActionService>("deviceActionService"));
ServiceContainer.Register<IDeleteAccountActionFlowExecutioner>("deleteAccountActionFlowExecutioner", deleteAccountActionFlowExecutioner);

var verificationActionsFlowHelper = new VerificationActionsFlowHelper(
ServiceContainer.Resolve<IKeyConnectorService>("keyConnectorService"),
ServiceContainer.Resolve<IPasswordRepromptService>("passwordRepromptService"));
ServiceContainer.Resolve<IPasswordRepromptService>("passwordRepromptService"),
ServiceContainer.Resolve<ICryptoService>("cryptoService"));
ServiceContainer.Register<IVerificationActionsFlowHelper>("verificationActionsFlowHelper", verificationActionsFlowHelper);
}
#if !FDROID
Expand Down
7 changes: 2 additions & 5 deletions src/App/Pages/Accounts/DeleteAccountViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,16 @@ public class DeleteAccountActionFlowExecutioner : IDeleteAccountActionFlowExecut
{
readonly IApiService _apiService;
readonly IMessagingService _messagingService;
readonly ICryptoService _cryptoService;
readonly IPlatformUtilsService _platformUtilsService;
readonly IDeviceActionService _deviceActionService;

public DeleteAccountActionFlowExecutioner(IApiService apiService,
IMessagingService messagingService,
ICryptoService cryptoService,
IPlatformUtilsService platformUtilsService,
IDeviceActionService deviceActionService)
{
_apiService = apiService;
_messagingService = messagingService;
_cryptoService = cryptoService;
_platformUtilsService = platformUtilsService;
_deviceActionService = deviceActionService;
}
Expand All @@ -81,10 +78,10 @@ public async Task Execute(IActionFlowParmeters parameters)
{
await _deviceActionService.ShowLoadingAsync(AppResources.DeletingYourAccount);

var masterPasswordHashKey = await _cryptoService.HashPasswordAsync(parameters.Secret, null);
await _apiService.DeleteAccountAsync(new Core.Models.Request.DeleteAccountRequest
{
MasterPasswordHash = masterPasswordHashKey
MasterPasswordHash = parameters.VerificationType == Core.Enums.VerificationType.MasterPassword ? parameters.Secret : (string)null,
OTP = parameters.VerificationType == Core.Enums.VerificationType.OTP ? parameters.Secret : (string)null
});

await _deviceActionService.HideLoadingAsync();
Expand Down
4 changes: 3 additions & 1 deletion src/App/Pages/Accounts/VerificationCodeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Windows.Input;
using Bit.App.Utilities;
using Bit.Core;
using Bit.Core.Enums;
#if !FDROID
using Microsoft.AppCenter.Crashes;
#endif
Expand Down Expand Up @@ -144,7 +145,7 @@ await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequi

await _deviceActionService.ShowLoadingAsync(AppResources.Verifying);

if (!await _userVerificationService.VerifyUser(Secret, Core.Enums.VerificationType.OTP))
if (!await _userVerificationService.VerifyUser(Secret, VerificationType.OTP))
{
await _deviceActionService.HideLoadingAsync();
return;
Expand All @@ -154,6 +155,7 @@ await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequi

var parameters = _verificationActionsFlowHelper.GetParameters();
parameters.Secret = Secret;
parameters.VerificationType = VerificationType.OTP;
await _verificationActionsFlowHelper.ExecuteAsync(parameters);

Secret = string.Empty;
Expand Down
15 changes: 12 additions & 3 deletions src/App/Utilities/VerificationActionsFlowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ IVerificationActionsFlowHelper Configure(VerificationFlowAction action,

public interface IActionFlowParmeters
{
VerificationType VerificationType { get; set; }

string Secret { get; set; }
}

public class DefaultActionFlowParameters : IActionFlowParmeters
{
public VerificationType VerificationType { get; set; }

public string Secret { get; set; }
}

Expand Down Expand Up @@ -58,6 +62,7 @@ public class VerificationActionsFlowHelper : IVerificationActionsFlowHelper
{
private readonly IKeyConnectorService _keyConnectorService;
private readonly IPasswordRepromptService _passwordRepromptService;
private readonly ICryptoService _cryptoService;

private VerificationFlowAction? _action;
private IActionFlowParmeters _parameters;
Expand All @@ -67,10 +72,12 @@ public class VerificationActionsFlowHelper : IVerificationActionsFlowHelper
private readonly Dictionary<VerificationFlowAction, IActionFlowExecutioner> _actionExecutionerDictionary = new Dictionary<VerificationFlowAction, IActionFlowExecutioner>();

public VerificationActionsFlowHelper(IKeyConnectorService keyConnectorService,
IPasswordRepromptService passwordRepromptService)
IPasswordRepromptService passwordRepromptService,
ICryptoService cryptoService)
{
_keyConnectorService = keyConnectorService;
_passwordRepromptService = passwordRepromptService;
_cryptoService = cryptoService;

_actionExecutionerDictionary.Add(VerificationFlowAction.DeleteAccount, ServiceContainer.Resolve<IDeleteAccountActionFlowExecutioner>("deleteAccountActionFlowExecutioner"));
}
Expand Down Expand Up @@ -113,8 +120,10 @@ public async Task ValidateAndExecuteAsync()
return;
}

GetParameters().Secret = password;
await ExecuteAsync(_parameters);
var parameters = GetParameters();
parameters.Secret = await _cryptoService.HashPasswordAsync(password, null);
parameters.VerificationType = VerificationType.MasterPassword;
await ExecuteAsync(parameters);
break;
case VerificationType.OTP:
await Application.Current.MainPage.Navigation.PushModalAsync(new NavigationPage(
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Models/Request/DeleteAccountRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
public class DeleteAccountRequest
{
public string MasterPasswordHash { get; set; }

public string OTP { get; set; }
}
}
6 changes: 2 additions & 4 deletions src/Core/Services/UserVerificationService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Threading.Tasks;
using Bit.Core.Abstractions;
using Bit.Core.Enums;
using Bit.Core.Models.Request;
using Bit.Core.Services;
using Bit.Core.Abstractions;
using System.Threading.Tasks;

namespace Bit.Core.Services
{
Expand Down
6 changes: 3 additions & 3 deletions src/iOS.Core/Utilities/iOSCoreHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ await ServiceContainer.Resolve<IStateService>("stateService").SaveAsync(
var deleteAccountActionFlowExecutioner = new DeleteAccountActionFlowExecutioner(
ServiceContainer.Resolve<IApiService>("apiService"),
ServiceContainer.Resolve<IMessagingService>("messagingService"),
ServiceContainer.Resolve<ICryptoService>("cryptoService"),
ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService"),
ServiceContainer.Resolve<IDeviceActionService>("deviceActionService"));
ServiceContainer.Register<IDeleteAccountActionFlowExecutioner>("deleteAccountActionFlowExecutioner", deleteAccountActionFlowExecutioner);

var verificationActionsFlowHelper = new VerificationActionsFlowHelper(
ServiceContainer.Resolve<IKeyConnectorService>("keyConnectorService"),
ServiceContainer.Resolve<IPasswordRepromptService>("passwordRepromptService"));
ServiceContainer.Resolve<IKeyConnectorService>("keyConnectorService"),
ServiceContainer.Resolve<IPasswordRepromptService>("passwordRepromptService"),
ServiceContainer.Resolve<ICryptoService>("cryptoService"));
ServiceContainer.Register<IVerificationActionsFlowHelper>("verificationActionsFlowHelper", verificationActionsFlowHelper);

if (postBootstrapFunc != null)
Expand Down