log out on stamp mismatch when syncing

This commit is contained in:
Kyle Spearrin 2019-05-29 23:41:43 -04:00
parent 1c08901698
commit 67970afc1e
2 changed files with 8 additions and 4 deletions

View File

@ -23,6 +23,7 @@ namespace Bit.Core.Services
private readonly ICollectionService _collectionService;
private readonly IStorageService _storageService;
private readonly IMessagingService _messagingService;
private readonly Action _logoutCallback;
public SyncService(
IUserService userService,
@ -33,7 +34,8 @@ namespace Bit.Core.Services
ICryptoService cryptoService,
ICollectionService collectionService,
IStorageService storageService,
IMessagingService messagingService)
IMessagingService messagingService,
Action logoutCallback)
{
_userService = userService;
_apiService = apiService;
@ -44,6 +46,7 @@ namespace Bit.Core.Services
_collectionService = collectionService;
_storageService = storageService;
_messagingService = messagingService;
_logoutCallback = logoutCallback;
}
public bool SyncInProgress { get; set; }
@ -297,8 +300,8 @@ namespace Bit.Core.Services
var stamp = await _userService.GetSecurityStampAsync();
if(stamp != null && stamp != response.SecurityStamp)
{
// TODO logout callback
throw new Exception("Stamp has changed.");
_logoutCallback?.Invoke();
return;
}
await _cryptoService.SetEncKeyAsync(response.Key);
await _cryptoService.SetEncPrivateKeyAsync(response.PrivateKey);

View File

@ -44,7 +44,8 @@ namespace Bit.Core.Utilities
var lockService = new LockService(cryptoService, userService, platformUtilsService, storageService,
folderService, cipherService, collectionService, searchService, messagingService);
var syncService = new SyncService(userService, apiService, settingsService, folderService,
cipherService, cryptoService, collectionService, storageService, messagingService);
cipherService, cryptoService, collectionService, storageService, messagingService,
() => messagingService.Send("logout"));
var passwordGenerationService = new PasswordGenerationService(cryptoService, storageService,
cryptoFunctionService);
var totpService = new TotpService(storageService, cryptoFunctionService);