async void LoadPasswordManager() { try { Mouse.OverrideCursor = Cursors.Wait; if (_pm == null) { _pm = new DevicePasswordManager(Device, _log); } await _pm.Load(); foreach (var a in _pm.Accounts) { _log.WriteLine("PM", $"Account {a.Key},\t {a.StorageId},\t {a.Flags:X},\t {a.IsPrimary},\t {a.Name},\t {a.Login},\t {a.Apps},\t {a.Urls}"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Mouse.OverrideCursor = null; } }
async Task <Credentials> GetCredentials(IDevice device) { ushort primaryAccountKey = await DevicePasswordManager.GetPrimaryAccountKey(device); var credentials = await GetCredentials(device, primaryAccountKey); return(credentials); }
private async Task DeleteAccountAsync(Device remoteDevice, HardwareVaultTask task) { var account = await _accountService.GetAccountByIdNoTrackingAsync(task.AccountId); bool isPrimary = account.Employee.PrimaryAccountId == task.AccountId; var storageId = new StorageId(account.StorageId); var pm = new DevicePasswordManager(remoteDevice, null); await pm.DeleteAccount(storageId, isPrimary); }
private async Task SetAccountAsPrimaryAsync(Device remoteDevice, HardwareVaultTask task) { var account = await _accountService.GetAccountByIdNoTrackingAsync(task.AccountId); var storageId = new StorageId(account.StorageId); var pm = new DevicePasswordManager(remoteDevice, null); await pm.SaveOrUpdateAccount(storageId, task.Timestamp, null, null, null, null, null, null, true, new AccountFlagsOptions() { IsReadOnly = true }); }
private async Task AddAccountAsync(Device remoteDevice, HardwareVaultTask task) { var account = await _accountService.GetAccountByIdNoTrackingAsync(task.AccountId); bool isPrimary = account.Employee.PrimaryAccountId == task.AccountId; var pm = new DevicePasswordManager(remoteDevice, null); await pm.SaveOrUpdateAccount(new StorageId(account.StorageId), task.Timestamp, account.Name, task.Password, account.Login, task.OtpSecret, account.Apps, account.Urls, isPrimary, new AccountFlagsOptions() { IsReadOnly = true }); }
async Task CreateRemoteDeviceAsync(CancellationToken cancellationToken) { if (_remoteDevice != null || IsCreatingRemoteDevice) { return; } HideezErrorCode initErrorCode = HideezErrorCode.Ok; try { _log.WriteLine($"({SerialNo}) Establishing remote vault connection"); if (cancellationToken.IsCancellationRequested) { initErrorCode = HideezErrorCode.RemoteDeviceCreationCancelled; return; } _log.WriteLine("Checking for available channels"); var channelsReply = await _metaMessenger.ProcessOnServer <GetAvailableChannelsMessageReply>(new GetAvailableChannelsMessage(SerialNo)); var channels = channelsReply.FreeChannels; if (channels.Length == 0) { throw new Exception(string.Format(TranslationSource.Instance["Vault.Error.NoAvailableChannels"], SerialNo)); // Todo: separate exception type } var channelNo = channels.FirstOrDefault(); _log.WriteLine($"{channels.Length} channels available"); if (cancellationToken.IsCancellationRequested) { initErrorCode = HideezErrorCode.RemoteDeviceCreationCancelled; return; } ShowInfo(string.Format(TranslationSource.Instance["Vault.Notification.PreparingForAuth"], SerialNo), Mac); IsCreatingRemoteDevice = true; _remoteDevice = await _remoteDeviceFactory.CreateRemoteDeviceAsync(SerialNo, channelNo, _remoteDeviceMessenger); _remoteDevice.PropertyChanged += RemoteDevice_PropertyChanged; if (cancellationToken.IsCancellationRequested) { initErrorCode = HideezErrorCode.RemoteDeviceCreationCancelled; return; } await _remoteDevice.VerifyAndInitialize(cancellationToken); if (cancellationToken.IsCancellationRequested) { initErrorCode = HideezErrorCode.RemoteDeviceCreationCancelled; return; } if (!_remoteDevice.IsAuthorized) { ShowInfo(string.Empty, Mac); } if (_remoteDevice.SerialNo != SerialNo) { throw new Exception(TranslationSource.Instance["Vault.Error.InvalidRemoteSerialNo"]); } _log.WriteLine($"({SerialNo}) Creating password manager"); PasswordManager = new DevicePasswordManager(_remoteDevice, null); _remoteDevice.StorageModified += RemoteDevice_StorageModified; _remoteDevice.ButtonPressed += RemoteDevice_ButtonPressed; _log.WriteLine($"({SerialNo}) Remote vault connection established"); } catch (HideezException ex) { _log.WriteLine(ex); if (ex.ErrorCode != HideezErrorCode.ChannelInitializationFailed) { ShowError(ex.Message, Mac); } initErrorCode = ex.ErrorCode; } catch (Exception ex) { _log.WriteLine(ex); ShowError(ex.Message, Mac); initErrorCode = HideezErrorCode.UnknownError; } finally { await _metaMessenger.Publish(new HidePinUiMessage()); if (initErrorCode != HideezErrorCode.Ok) { await ShutdownRemoteDeviceAsync(initErrorCode); } IsCreatingRemoteDevice = false; } }
async void WriteAccount() { try { Mouse.OverrideCursor = Cursors.Wait; var pm = new DevicePasswordManager(Device, _log); // array of records //for (int i = 0; i < 100; i++) //{ // var account = new AccountRecord() // { // Key = 0, // Name = $"My Google Account {i}", // Login = $"admin_{i}@hideez.com", // Password = $"my_password_{i}", // OtpSecret = $"asdasd_{i}", // Apps = $"12431412412342134_{i}", // Urls = $"www.hideez.com;www.google.com_{i}", // IsPrimary = i == 0 // }; // var key = await pm.SaveOrUpdateAccount(account.Key, account.Flags, account.Name, // account.Password, account.Login, account.OtpSecret, // account.Apps, account.Urls, // account.IsPrimary); // Debug.WriteLine($"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Writing {i} account"); //} // single record var account = new AccountRecord() { StorageId = new StorageId(), Timestamp = ConvertUtils.ConvertToUnixTime(DateTime.Now), Name = $"{Data} My Google Account {_counter}", Login = $"{Data} [email protected] {_counter}", Password = $"{Data} my_password_{_counter}", OtpSecret = $"DPMYUOUOQDCAABSIAE5DFBANESXGOHDV", Apps = $"{Data} 12431412412342134_{_counter}", Urls = $"{Data} www.hideez.com;www.google.com_{_counter}", IsPrimary = false }; _counter++; await pm.SaveOrUpdateAccount( account.StorageId, account.Timestamp, account.Name, account.Password, account.Login, account.OtpSecret, account.Apps, account.Urls, account.IsPrimary //,(ushort)(StorageTableFlags.RESERVED7 | StorageTableFlags.RESERVED6) //,(ushort)(StorageTableFlags.RESERVED7 | StorageTableFlags.RESERVED6) ); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Mouse.OverrideCursor = null; } }