Esempio n. 1
0
        /// <summary>
        /// Loads all required resources.
        /// </summary>
        protected void Initialise()
        {
            EmbeddedResources.Load();
            CreateNotifyIcon();
            LoadConfigFile();

#if DEBUG
            Log.Initialise();
#else
            if (ConfigManager.Config.CreateLogFile)
            {
                Log.Initialise();
            }
#endif
            Log.Send("------------------------------");
            Log.Send($"Starting pass-winmenu {Version}");
            Log.Send("------------------------------");

            AssignHotkeys(hotkeys);

            var gpg = new GPG();
            gpg.FindGpgInstallation(ConfigManager.Config.Gpg.GpgPath);
            if (ConfigManager.Config.Gpg.GpgAgent.Config.AllowConfigManagement)
            {
                gpg.UpdateAgentConfig(ConfigManager.Config.Gpg.GpgAgent.Config.Keys);
            }
            passwordManager = new PasswordManager(ConfigManager.Config.PasswordStore.Location, EncryptedFileExtension, gpg);
            passwordManager.PinentryFixEnabled = ConfigManager.Config.Gpg.PinentryFix;

            if (ConfigManager.Config.Git.UseGit)
            {
                try
                {
                    if (ConfigManager.Config.Git.SyncMode == SyncMode.NativeGit)
                    {
                        git = new Git(ConfigManager.Config.PasswordStore.Location, ConfigManager.Config.Git.GitPath);
                    }
                    else
                    {
                        git = new Git(ConfigManager.Config.PasswordStore.Location);
                    }
                }
                catch (RepositoryNotFoundException)
                {
                    // Password store doesn't appear to be a Git repository.
                    // Git support will be disabled.
                }
                catch (TypeInitializationException e) when(e.InnerException is DllNotFoundException)
                {
                    ShowErrorWindow("The git2 DLL could not be found. Git support will be disabled.");
                }
                catch (Exception e)
                {
                    ShowErrorWindow($"Failed to open the password store Git repository ({e.GetType().Name}: {e.Message}). Git support will be disabled.");
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Loads all required resources.
        /// </summary>
        private void Initialise()
        {
#if DEBUG
            Log.Initialise();
#else
            if (ConfigManager.Config.CreateLogFile)
            {
                Log.Initialise();
            }
#endif
            // Load compiled-in resources.
            EmbeddedResources.Load();

            Log.Send("------------------------------");
            Log.Send($"Starting pass-winmenu {Version}");
            Log.Send("------------------------------");

            // Set the security protocol to TLS 1.2 only.
            // We only use this for update checking (Git push over HTTPS is not handled by .NET).
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            // Create the notification service first, so it's available if initialisation fails.
            notificationService = Notifications.Create();

            // Now load the configuration options that we'll need
            // to continue initialising the rest of the applications.
            LoadConfigFile();

            // Create the GPG wrapper.
            gpg = new GPG();
            gpg.FindGpgInstallation(ConfigManager.Config.Gpg.GpgPath);
            if (ConfigManager.Config.Gpg.GpgAgent.Config.AllowConfigManagement)
            {
                gpg.UpdateAgentConfig(ConfigManager.Config.Gpg.GpgAgent.Config.Keys);
            }
            // Create the Git wrapper, if enabled.
            InitialiseGit(ConfigManager.Config.Git, ConfigManager.Config.PasswordStore.Location);

            // Initialise the internal password manager.
            passwordManager = new PasswordManager(ConfigManager.Config.PasswordStore.Location, EncryptedFileExtension, gpg);
            passwordManager.PinentryFixEnabled = ConfigManager.Config.Gpg.PinentryFix;

            clipboard     = new ClipboardHelper();
            dialogCreator = new DialogCreator(notificationService, passwordManager, git, gpg);
            InitialiseUpdateChecker();

            actionDispatcher = new ActionDispatcher(notificationService, passwordManager, dialogCreator, clipboard, git, updateChecker);

            notificationService.AddMenuActions(actionDispatcher);

            // Assign our hotkeys.
            hotkeys = new HotkeyManager();
            AssignHotkeys(hotkeys);
        }
Esempio n. 3
0
        /// <summary>
        /// Loads all required resources.
        /// </summary>
        private void Initialise()
        {
            // Load compiled-in resources.
            EmbeddedResources.Load();

            Log.Send("------------------------------");
            Log.Send($"Starting pass-winmenu {Version}");
            Log.Send("------------------------------");

            Log.Send($"Enabled security protocols: {ServicePointManager.SecurityProtocol}");

            // Create the notification service first, so it's available if initialisation fails.
            notificationService = Notifications.Create();

            // Initialise the DI Container builder.
            var builder = new ContainerBuilder();

            builder.Register(_ => notificationService)
            .AsImplementedInterfaces()
            .SingleInstance();

            // Now load the configuration options that we'll need
            // to continue initialising the rest of the applications.
            var runtimeConfig = RuntimeConfiguration.Parse(Environment.GetCommandLineArgs());

            LoadConfigFile(runtimeConfig);

            builder.Register(_ => ConfigManager.Config).AsSelf();
            builder.Register(_ => ConfigManager.Config.Gpg).AsSelf();
            builder.Register(_ => ConfigManager.Config.Git).AsSelf();
            builder.Register(_ => ConfigManager.Config.PasswordStore).AsSelf();
            builder.Register(_ => ConfigManager.Config.Application.UpdateChecking).AsSelf();
            builder.Register(_ => ConfigManager.Config.PasswordStore.UsernameDetection).AsSelf();

#if DEBUG
            Log.EnableFileLogging();
#else
            if (ConfigManager.Config.CreateLogFile)
            {
                Log.EnableFileLogging();
            }
#endif

            // Register actions and hotkeys
            builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(ActionDispatcher)))
            .InNamespaceOf <ActionDispatcher>()
            .Except <ActionDispatcher>()
            .AsImplementedInterfaces();
            builder.RegisterType <HotkeyManager>()
            .AsSelf();

            builder.RegisterType <ActionDispatcher>()
            .WithParameter(
                (p, ctx) => p.ParameterType == typeof(Dictionary <HotkeyAction, IAction>),
                (info, context) => context.Resolve <IEnumerable <IAction> >().ToDictionary(a => a.ActionType));

            // Register environment wrappers
            builder.RegisterTypes(
                typeof(FileSystem),
                typeof(SystemEnvironment),
                typeof(Processes),
                typeof(ExecutablePathResolver)
                ).AsImplementedInterfaces();

            // Register GPG types
            builder.RegisterTypes(
                typeof(GpgInstallationFinder),
                typeof(GpgHomedirResolver),
                typeof(GpgAgentConfigReader),
                typeof(GpgAgentConfigUpdater),
                typeof(GpgTransport),
                typeof(GpgAgent),
                typeof(GpgResultVerifier),
                typeof(GPG)
                ).AsImplementedInterfaces()
            .AsSelf();

            // Register GPG installation
            // Single instance, as there is no need to look for the same GPG installation multiple times.
            builder.Register(context => context.Resolve <GpgInstallationFinder>().FindGpgInstallation(ConfigManager.Config.Gpg.GpgPath))
            .SingleInstance();

            builder.RegisterType <DialogCreator>()
            .AsSelf();

            // Register the internal password manager
            builder.Register(context => context.Resolve <IFileSystem>().DirectoryInfo.FromDirectoryName(context.Resolve <PasswordStoreConfig>().Location))
            .Named("PasswordStore", typeof(IDirectoryInfo));

            builder.RegisterType <GpgRecipientFinder>().WithParameter(
                (parameter, context) => true,
                (parameter, context) => context.ResolveNamed <IDirectoryInfo>("PasswordStore"))
            .AsImplementedInterfaces();

            builder.RegisterType <PasswordManager>().WithParameter(
                (parameter, context) => parameter.ParameterType == typeof(IDirectoryInfo),
                (parameter, context) => context.ResolveNamed <IDirectoryInfo>("PasswordStore"))
            .AsImplementedInterfaces()
            .AsSelf();

            builder.RegisterType <PasswordFileParser>().AsSelf();

            // Create the Git wrapper, if enabled.
            // This needs to be a single instance to stop startup warnings being displayed multiple times.
            builder.RegisterType <GitSyncStrategies>().AsSelf();
            builder.Register(CreateSyncService)
            .AsSelf()
            .SingleInstance();

            builder.Register(context => UpdateCheckerFactory.CreateUpdateChecker(context.Resolve <UpdateCheckingConfig>(), context.Resolve <INotificationService>()));
            builder.RegisterType <RemoteUpdateCheckerFactory>().AsSelf();
            builder.Register(context => context.Resolve <RemoteUpdateCheckerFactory>().Build()).AsSelf();

            // Build the container
            container = builder.Build();

            var gpgConfig = container.Resolve <GpgConfig>();
            if (gpgConfig.GpgAgent.Config.AllowConfigManagement)
            {
                container.Resolve <GpgAgentConfigUpdater>().UpdateAgentConfig(gpgConfig.GpgAgent.Config.Keys);
            }

            var actionDispatcher = container.Resolve <ActionDispatcher>();

            notificationService.AddMenuActions(actionDispatcher);

            // Assign our hotkeys.
            AssignHotkeys(actionDispatcher);

            // Start checking for updates
            updateChecker       = container.Resolve <UpdateChecker>();
            remoteUpdateChecker = container.Resolve <Option <RemoteUpdateChecker> >();

            if (container.Resolve <UpdateCheckingConfig>().CheckForUpdates)
            {
                updateChecker.Start();
            }
            remoteUpdateChecker.Apply(c => c.Start());
        }