/// <exception cref="System.Collections.Generic.KeyNotFoundException">Thrown when Hideez Client root registry key not found</exception> /// <exception cref="System.UnauthorizedAccessException">The RegistryKey is read-only, and cannot be written to; for example, the key has not been opened with write access.</exception> /// <exception cref="System.Security.SecurityException">The user does not have the permissions required to create or modify registry keys.</exception> public static void SetHesAddress(Logger log, string address) { var registryKey = HideezClientRegistryRoot.GetRootRegistryKey(true); if (registryKey == null) { throw new KeyNotFoundException($"Couldn't find Hideez Client registry key. ({HideezClientRegistryRoot.RootKeyPath})"); } registryKey.SetValue(_hesAddressRegistryValueName, address); }
public static string GetHesAddress(Logger log) { try { var registryKey = HideezClientRegistryRoot.GetRootRegistryKey(); if (registryKey == null) { throw new Exception($"Couldn't find Hideez Client registry key. ({HideezClientRegistryRoot.RootKeyPath})"); } var value = registryKey.GetValue(_hesAddressRegistryValueName); if (value == null) { throw new ArgumentNullException($"{_hesAddressRegistryValueName} value is null or empty. Please specify HES address in registry under value {_hesAddressRegistryValueName}. Key: HKLM\\SOFTWARE\\Hideez\\Client"); } if (value is string == false) { throw new FormatException($"{_hesAddressRegistryValueName} could not be cast to string. Check that its value has REG_SZ type"); } var address = value as string; if (string.IsNullOrWhiteSpace(address)) { throw new ArgumentNullException($"{_hesAddressRegistryValueName} value is null or empty. Please specify HES address in registry under value {_hesAddressRegistryValueName}. Key: HKLM\\SOFTWARE\\Hideez\\Client"); } if (Uri.TryCreate(address, UriKind.Absolute, out Uri outUri) && (outUri.Scheme == Uri.UriSchemeHttp || outUri.Scheme == Uri.UriSchemeHttps)) { return(address); } else { throw new ArgumentException($"Specified HES address: ('{address}'), " + $"is not a correct absolute uri"); } } catch (Exception ex) { log.WriteLine(ex); } return(string.Empty); }
private void InitializeDIContainer() { Container = new UnityContainer(); #if DEBUG Container.AddExtension(new Diagnostic()); #endif _log.WriteLine("Start initialize DI container"); #region ViewModels Container.RegisterType <MainViewModel>(new ContainerControlledLifetimeManager()); //Container.RegisterType<LoginSystemPageViewModel>(); //Container.RegisterType<LockSettingsPageViewModel>(); Container.RegisterType <IndicatorsViewModel>(); //Container.RegisterType<DevicesExpanderViewModel>(); Container.RegisterType <NotificationsContainerViewModel>(); Container.RegisterType <DeviceNotAuthorizedNotificationViewModel>(); Container.RegisterType <PinViewModel>(); Container.RegisterType <HelpPageViewModel>(); Container.RegisterType <SettingsPageViewModel>(); Container.RegisterType <PasswordManagerViewModel>(new ContainerControlledLifetimeManager()); Container.RegisterType <DeviceSettingsPageViewModel>(new ContainerControlledLifetimeManager()); Container.RegisterType <ServerAddressEditControlViewModel>(new ContainerControlledLifetimeManager()); Container.RegisterType <ServiceViewModel>(new ContainerControlledLifetimeManager()); Container.RegisterType <DefaultPageViewModel>(); Container.RegisterType <HardwareKeyPageViewModel>(); Container.RegisterType <SoftwareKeyPageViewModel>(); Container.RegisterType <SoftwareUnlockSettingViewModel>(new ContainerControlledLifetimeManager()); Container.RegisterType <ActivationViewModel>(); #endregion ViewModels Container.RegisterType <IStartupHelper, StartupHelper>(new ContainerControlledLifetimeManager()); Container.RegisterType <IWorkstationManager, WorkstationManager>(new ContainerControlledLifetimeManager()); Container.RegisterType <ILog, NLogWrapper>(new ContainerControlledLifetimeManager()); Container.RegisterType <IWindowsManager, WindowsManager>(new ContainerControlledLifetimeManager()); Container.RegisterType <IAppHelper, AppHelper>(new ContainerControlledLifetimeManager()); //Container.RegisterType<IDialogManager, DialogManager>(new ContainerControlledLifetimeManager()); Container.RegisterType <IFileSerializer, XmlFileSerializer>(); Container.RegisterType <IDeviceManager, DeviceManager>(new ContainerControlledLifetimeManager()); Container.RegisterType <ISupportMailContentGenerator, SupportMailContentGenerator>(new ContainerControlledLifetimeManager()); Container.RegisterType <IHotkeyManager, HotkeyManager>(new ContainerControlledLifetimeManager()); Container.RegisterType <IButtonManager, ButtonManager>(new ContainerControlledLifetimeManager()); Container.RegisterType <IActiveDevice, ActiveDevice>(new ContainerControlledLifetimeManager()); Container.RegisterType <IWorkstationIdProvider, WorkstationIdProvider>(new ContainerControlledLifetimeManager(), new InjectionConstructor(HideezClientRegistryRoot.GetRootRegistryKey(false), typeof(ILog))); Container.RegisterType <IWorkstationInfoProvider, WorkstationInfoProvider>(new ContainerControlledLifetimeManager()); Container.RegisterType <IProximityLockManager, ProximityLockManager>(new ContainerControlledLifetimeManager()); Container.RegisterType <IVaultLowBatteryMonitor, VaultLowBatteryMonitor>(new ContainerControlledLifetimeManager()); // Settings Container.RegisterType <ISettingsManager <ApplicationSettings>, HSSettingsManager <ApplicationSettings> >(new ContainerControlledLifetimeManager() , new InjectionConstructor(Path.Combine(Constants.DefaultSettingsFolderPath, Constants.ApplicationSettingsFileName), typeof(IFileSerializer), typeof(IMetaPubSub))); Container.RegisterType <ISettingsManager <HotkeySettings>, HSSettingsManager <HotkeySettings> >(new ContainerControlledLifetimeManager() , new InjectionConstructor(Path.Combine(Constants.DefaultSettingsFolderPath, Constants.HotkeySettingsFileName), typeof(IFileSerializer), typeof(IMetaPubSub))); // Service Container.RegisterType <IServiceProxy, ServiceProxy>(new ContainerControlledLifetimeManager()); Container.RegisterInstance <IMetaPubSub>(new MetaPubSub(new MetaPubSubLogger(Container.Resolve <ILog>()))); // Todo: fix this idiocity Container.RegisterType <IServiceWatchdog, ServiceWatchdog>(new ContainerControlledLifetimeManager()); Container.RegisterType <IRemoteDeviceFactory, RemoteDeviceFactory>(new ContainerControlledLifetimeManager()); // Taskbar icon Container.RegisterType <IBalloonTipNotifyManager, BalloonTipNotifyManager>(new ContainerControlledLifetimeManager()); Container.RegisterType <IMenuFactory, MenuFactory>(new ContainerControlledLifetimeManager()); Container.RegisterType <TaskbarIconViewModel>(new ContainerControlledLifetimeManager()); Container.RegisterType <ITaskbarIconManager, TaskbarIconManager>(new ContainerControlledLifetimeManager()); // Input Container.RegisterType <UserActionHandler>(new ContainerControlledLifetimeManager()); Container.RegisterType <IInputCache, InputCache>(new ContainerControlledLifetimeManager()); Container.RegisterType <IInputHandler, InputHandler>(new ContainerControlledLifetimeManager()); Container.RegisterType <IInputSimulator, InputSimulator>(new ContainerControlledLifetimeManager()); Container.RegisterInstance(typeof(ITemporaryCacheAccount), new TemporaryCacheAccount(TimeSpan.FromMinutes(1)), new ContainerControlledLifetimeManager()); Container.RegisterType <InputOtp>(); Container.RegisterType <InputPassword>(); Container.RegisterType <InputLogin>(); // QrScanner // Note: Previous BarcodeReader was renamed into BarcodeReaderGeneric when // ZXing library got updated; Its AutoRotate property was set to True in constructor Container.RegisterType <IBarcodeReader, BarcodeReader>(new ContainerControlledLifetimeManager()); Container.RegisterType <IQrScannerHelper, QrScannerHelper>(); Container.RegisterType <INotificationsManager, NotificationsManager>(new ContainerControlledLifetimeManager()); Container.RegisterType <IEventPublisher, EventPublisher>(new ContainerControlledLifetimeManager()); Container.RegisterType <MessageWindow>(new ContainerControlledLifetimeManager()); _log.WriteLine("Finish initialize DI container"); }
void Initialize() { try { NLog.LogManager.EnableLogging(); _sdkLogger = new NLogWrapper(); _log = new Logger(nameof(HideezService), _sdkLogger); _log.WriteLine($">>>>>> Starting service"); _log.WriteLine($"Service Version: {Assembly.GetEntryAssembly().GetName().Version}"); _log.WriteLine($"CLR Version: {Environment.Version}"); _log.WriteLine($"OS: {Environment.OSVersion}"); _log.WriteLine($"Command: {Environment.CommandLine}"); _log.WriteLine($">>>>> Starting messaging hub"); var pubSubLogger = new MetaPubSubLogger(_sdkLogger); _messenger = new MetaPubSub(pubSubLogger); _log.WriteLine(">>>>>> Get registry settings key"); clientRootRegistryKey = HideezClientRegistryRoot.GetRootRegistryKey(true); _log.WriteLine(">>>>>> Initialize session monitor"); _sessionInfoProvider = new SessionInfoProvider(_sdkLogger); _log.WriteLine(">>>>>> Initialize workstation id provider"); _workstationIdProvider = new WorkstationIdProvider(clientRootRegistryKey, _sdkLogger); if (string.IsNullOrWhiteSpace(_workstationIdProvider.GetWorkstationId())) { _workstationIdProvider.SaveWorkstationId(Guid.NewGuid().ToString()); } _log.WriteLine(">>>>>> Initilize audit"); var commonAppData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); string auditEventsDirectoryPath = $@"{commonAppData}\Hideez\Service\WorkstationEvents\"; _eventSaver = new EventSaver(_sessionInfoProvider, _workstationIdProvider, auditEventsDirectoryPath, _sdkLogger); _log.WriteLine(">>>>>> Initialize session timestamp monitor"); var sessionTimestampPath = $@"{commonAppData}\Hideez\Service\Timestamp\timestamp.dat"; _sessionTimestampLogger = new SessionTimestampLogger(sessionTimestampPath, _sessionInfoProvider, _eventSaver, _sdkLogger); OnServiceStarted(); _log.WriteLine(">>>>>> Initialize SDK"); InitializeSDK().Wait(); _messenger.StartServer("HideezServicePipe", () => { try { _log.WriteLine("Custom pipe config started"); var pipeSecurity = new PipeSecurity(); pipeSecurity.AddAccessRule(new PipeAccessRule( new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null), PipeAccessRights.FullControl, AccessControlType.Allow)); var pipe = new NamedPipeServerStream("HideezServicePipe", PipeDirection.InOut, 32, PipeTransmissionMode.Message, PipeOptions.Asynchronous, 4096, 4096, pipeSecurity); _log.WriteLine("Custom pipe config successful"); return(pipe); } catch (Exception ex) { _log.WriteLine("Custom pipe config failed.", ex); return(null); } }); _log.WriteLine(">>>>>> Service started"); } catch (Exception ex) { _log.WriteLine("Hideez Service has encountered an error during initialization." + Environment.NewLine + "The error must be resolved until service operation can be resumed. " + Environment.NewLine + "The service will not restart automatically.", ex, LogErrorSeverity.Fatal); // Exit code 0 prevents automatic service restart trigger on exit Environment.Exit(0); } }