Exemplo n.º 1
0
        public async Task GetVaultByIdAsync()
        {
            var result = await _hardwareVaultService.GetVaultByIdAsync(_testingOptions.HardwareVaultId);

            Assert.NotNull(result);
            Assert.Equal(_testingOptions.HardwareVaultId, result.Id);
            Assert.Equal(_testingOptions.HardwareVault.MAC, result.MAC);
        }
Exemplo n.º 2
0
        public async Task<ActionResult<HardwareVault>> GetHardwareVaultById(string id)
        {
            var vault = await _hardwareVaultService.GetVaultByIdAsync(id);

            if (vault == null)
                return NotFound();

            return vault;
        }
Exemplo n.º 3
0
        public async Task UpdateLastSeenAsync(string vaultId)
        {
            var vault = await _hardwareVaultService.GetVaultByIdAsync(vaultId);

            if (vault?.EmployeeId == null)
            {
                return;
            }

            var employee = await _employeeRepository.GetByIdAsync(vault.EmployeeId);

            if (employee == null)
            {
                return;
            }

            employee.LastSeen = DateTime.UtcNow;
            await _employeeRepository.UpdateOnlyPropAsync(employee, new string[] { nameof(Employee.LastSeen) });
        }
        private async Task <HardwareVault> ValidateAndGetHardwareVaultAsync(string vaultId, bool isLinkRequired)
        {
            var vault = await _hardwareVaultService.GetVaultByIdAsync(vaultId);

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

            if (!isLinkRequired && vault.MasterPassword == null)
            {
                throw new HideezException(HideezErrorCode.HesDeviceLinkedToAnotherServer);
            }

            if (isLinkRequired && vault.MasterPassword != null && vault.Status != VaultStatus.Reserved && vault.Status != VaultStatus.Deactivated)
            {
                throw new HideezException(HideezErrorCode.HesVaultWasManuallyWiped);
            }

            return(vault);
        }
Exemplo n.º 5
0
        public async Task ExecuteRemoteTasks(string vaultId, Device remoteDevice, bool primaryAccountOnly)
        {
            _dataProtectionService.Validate();

            var vault = await _hardwareVaultService.GetVaultByIdAsync(vaultId);

            if (vault == null)
            {
                throw new HESException(HESCode.HardwareVaultNotFound);
            }

            // Tasks query
            var query = _hardwareVaultTaskService
                        .TaskQuery()
                        .Include(t => t.HardwareVault)
                        .Include(t => t.Account)
                        .Where(t => t.HardwareVaultId == vaultId);

            if (primaryAccountOnly)
            {
                query = query.Where(x => x.AccountId == vault.Employee.PrimaryAccountId || x.Operation == TaskOperation.Primary);
            }

            query = query.OrderBy(x => x.CreatedAt).AsNoTracking();

            var tasks = await query.ToListAsync();

            while (tasks.Any())
            {
                foreach (var task in tasks)
                {
                    task.Password  = _dataProtectionService.Decrypt(task.Password);
                    task.OtpSecret = _dataProtectionService.Decrypt(task.OtpSecret);
                    await ExecuteRemoteTask(remoteDevice, task);
                    await TaskCompleted(task.Id);
                }

                tasks = await query.ToListAsync();
            }

            await _hardwareVaultService.UpdateNeedSyncAsync(vault, false);

            await _synchronizationService.HardwareVaultStateChanged(vault.Id);
        }
Exemplo n.º 6
0
        private async Task <HwVaultInfoFromHesDto> GetHardwareVaultInfoAsync(HwVaultInfoFromClientDto dto)
        {
            var vault = await _hardwareVaultService.GetVaultByIdAsync(dto.VaultSerialNo);

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

            return(new HwVaultInfoFromHesDto()
            {
                OwnerName = vault.Employee?.FullName,
                OwnerEmail = vault.Employee?.Email,
                VaultMac = vault.MAC,
                VaultSerialNo = vault.Id,
                VaultRfid = vault.RFID,
                NeedUpdateLicense = vault.HasNewLicense,
                NeedStateUpdate = await _remoteDeviceConnectionsService.CheckIsNeedUpdateHwVaultStatusAsync(dto),
                NeedUpdateOSAccounts = vault.HardwareVaultTasks.Any(x => x.Operation == TaskOperation.Primary || x.AccountId == vault.Employee.PrimaryAccountId),
                NeedUpdateNonOSAccounts = vault.HardwareVaultTasks.Any(x => x.Operation != TaskOperation.Primary && x.AccountId != vault.Employee.PrimaryAccountId)
            });
        }