Пример #1
0
        public async Task UpdateAfterWipe()
        {
            await _hardwareVaultService.SetReadyStatusAsync(_testingOptions.HardwareVault);

            var result = await _hardwareVaultService.GetVaultByIdAsync(_testingOptions.HardwareVaultId);

            Assert.True(result.HasNewLicense);
            Assert.Null(result.MasterPassword);
            Assert.Equal(VaultStatus.Ready, result.Status);
        }
Пример #2
0
        public async Task RemoveHardwareVaultAsync(string vaultId, VaultStatusReason reason, bool isNeedBackup = false)
        {
            if (vaultId == null)
            {
                throw new ArgumentNullException(nameof(vaultId));
            }

            _dataProtectionService.Validate();

            var vault = await _hardwareVaultService.GetVaultByIdAsync(vaultId);

            if (vault == null)
            {
                throw new Exception($"Vault {vaultId} not found.");
            }

            if (vault.Status != VaultStatus.Reserved && vault.Status != VaultStatus.Active &&
                vault.Status != VaultStatus.Locked && vault.Status != VaultStatus.Suspended)
            {
                throw new Exception($"Vault {vaultId} in a status that does not allow to remove.");
            }

            using (TransactionScope transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                await _hardwareVaultTaskService.DeleteTasksByVaultIdAsync(vaultId);

                await _workstationService.DeleteProximityByVaultIdAsync(vaultId);

                if (vault.Status == VaultStatus.Reserved && !vault.IsStatusApplied)
                {
                    await _hardwareVaultService.SetReadyStatusAsync(vault);
                }
                else
                {
                    var employeeVaultsCount = vault.Employee.HardwareVaults.Count();

                    if (employeeVaultsCount == 1)
                    {
                        await RemovePrimaryAccountIdAsync(vault.EmployeeId);

                        await _accountService.DeleteAccountsByEmployeeIdAsync(vault.EmployeeId);
                    }

                    vault.StatusReason = reason;
                    await _hardwareVaultService.SetDeactivatedStatusAsync(vault);
                }

                transactionScope.Complete();
            }
        }
        public async Task UpdateHardwareVaultStatusAsync(string vaultId, string workstationId)
        {
            var remoteDevice = await ConnectDevice(vaultId, workstationId).TimeoutAfter(30_000);

            await remoteDevice.RefreshDeviceInfo();

            if (remoteDevice == null)
            {
                throw new HideezException(HideezErrorCode.HesFailedEstablishRemoteDeviceConnection);
            }

            var vault = await _hardwareVaultService.GetVaultByIdAsync(vaultId);

            if (vault == null)
            {
                throw new HideezException(HideezErrorCode.HesDeviceNotFound);
            }

            switch (vault.Status)
            {
            case VaultStatus.Ready:
                throw new HideezException(HideezErrorCode.HesDeviceNotAssignedToAnyUser);

            case VaultStatus.Reserved:
                // Required Link
                if (remoteDevice.AccessLevel.IsLinkRequired)
                {
                    await _remoteTaskService.LinkVaultAsync(remoteDevice, vault);

                    break;
                }
                // Transition to Active status
                if (!remoteDevice.AccessLevel.IsLinkRequired && !remoteDevice.IsLocked)
                {
                    await _remoteTaskService.AccessVaultAsync(remoteDevice, vault);

                    await _hardwareVaultService.SetActiveStatusAsync(vault);

                    break;
                }
                // Transition to Locked status
                if (remoteDevice.IsLocked && !remoteDevice.IsCanUnlock)
                {
                    await _hardwareVaultService.SetLockedStatusAsync(vault);

                    break;
                }
                break;

            case VaultStatus.Active:
                // Transition to Locked status
                if (remoteDevice.IsLocked)
                {
                    await _hardwareVaultService.SetLockedStatusAsync(vault);

                    break;
                }
                break;

            case VaultStatus.Locked:
                throw new HideezException(HideezErrorCode.HesDeviceLocked);

            case VaultStatus.Suspended:
                // Apply Suspend status
                if (!vault.IsStatusApplied)
                {
                    await _remoteTaskService.SuspendVaultAsync(remoteDevice, vault);

                    break;
                }
                else
                {
                    // Transition to Locked status
                    if (remoteDevice.IsLocked && !remoteDevice.IsCanUnlock)
                    {
                        await _hardwareVaultService.SetLockedStatusAsync(vault);

                        break;
                    }
                    // Transition to Active status
                    if (!remoteDevice.IsLocked)
                    {
                        await _hardwareVaultService.SetActiveStatusAsync(vault);

                        break;
                    }
                }
                break;

            case VaultStatus.Deactivated:
                await _remoteTaskService.WipeVaultAsync(remoteDevice, vault);

                await _hardwareVaultService.SetReadyStatusAsync(vault);

                throw new HideezException(HideezErrorCode.DeviceHasBeenWiped);

            case VaultStatus.Compromised:
                throw new HideezException(HideezErrorCode.HesDeviceCompromised);

            default:
                throw new Exception($"Unhandled vault status. ({vault.Status})");
            }
        }