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

View file

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