public void Run(DecryptEntryVerbOptions options)
        {
            var categories = options.GetCategories();
            var entries    = options.GetEntries();

            if (categories.Count != entries.Count)
            {
                throw new EnvCryptConsoleException("count of categories and entries do not match");
            }

            var categoryEntryPairs = new List <CategoryEntryPair>();

            for (uint catI = 0; catI < categories.Count; catI++)
            {
                var toAdd = new CategoryEntryPair(categories[(int)catI], entries[(int)catI]);
                categoryEntryPairs.Add(toAdd);
            }


            var builder = new DecryptGenericWorkflowBuilder(
                new DecryptPlainTextEntryWorkflowBuilder(),
                new DecryptRsaEntryWorkflowBuilder(),
                new DecryptAesEntryWorkflowBuilder());
            var result = builder.Build().Run(new DecryptGenericWorkflowOptions()
            {
                CategoryEntryPair             = categoryEntryPairs,
                DatFilePath                   = options.DatFile,
                KeyFilePath                   = options.KeyFile,
                ThrowExceptionIfEntryNotFound = true,
            });

            OutputToConsole(result);
        }
Пример #2
0
        public void Run(CommandLineOptions options)
        {
            Logger.Info("Uninstalling service: {0}", options.ServiceName);
            ServiceInstaller.Uninstall(options.ServiceName, false);

            string fidPassword = null;

            if (string.IsNullOrWhiteSpace(options.FunctionalId))
            {
                options.FunctionalId = null;
            }
            else
            {
                Logger.Info("Decrypting password. Category: {0}  Entry: {1}",
                            options.Category, options.Entry);

                var builder = new DecryptGenericWorkflowBuilder(
                    new DecryptPlainTextEntryWorkflowBuilder(),
                    new DecryptRsaEntryWorkflowBuilder(),
                    new DecryptAesEntryWorkflowBuilder());
                var result = builder.Build().Run(new DecryptGenericWorkflowOptions()
                {
                    CategoryEntryPair = new []
                    {
                        new CategoryEntryPair(options.Category, options.Entry),
                    },
                    DatFilePath = options.DatFile,
                    KeyFilePath = options.KeyFile,
                    ThrowExceptionIfEntryNotFound = true,
                });

                if (result.Count == 0)
                {
                    throw new Exception("could not find Category: " + options.Category + " Entry:" + options.Entry);
                }
                fidPassword = result[0].DecryptedValue;
            }

            Logger.Info("Installing service: {0}", options.ServiceName);
            ServiceInstaller.Install(
                name: options.ServiceName,
                displayName: options.DisplayName,
                startType: GetBootFlag(options.GetServiceStartType()),
                binaryPath: "\"" + options.BinaryPath + "\"",
                runAsFid: options.FunctionalId,
                fidPassword: fidPassword);
        }
Пример #3
0
        private static void Run(string datFilePath, string keyFilePath)
        {
            if (!File.Exists(datFilePath))
            {
                Logger.Fatal()
                .Message("DAT file does not exist: {0}", datFilePath)
                .Write();
                Environment.Exit(1);
            }


            if (!File.Exists(keyFilePath))
            {
                Logger.Fatal()
                .Message("Private key file does not exist: {0}", keyFilePath)
                .Write();
                Environment.Exit(1);
            }


            var auditLogDir = Path.Combine(Path.GetDirectoryName(datFilePath), "..", "AuditLogs");

            var builder = new DecryptGenericWorkflowBuilder(
                GetPlainTextEntryWorkflowBuilder(auditLogDir),
                GetRsaEntryWorkflowBuilder(auditLogDir),
                GetAesEntryWorkflowBuilder(auditLogDir));
            var result = builder.Build().Run(new DecryptGenericWorkflowOptions()
            {
                CategoryEntryPair             = GetPairsFromConfig(),
                DatFilePath                   = datFilePath,
                KeyFilePath                   = keyFilePath,
                ThrowExceptionIfEntryNotFound = true,
            });


            foreach (var r in result)
            {
                Logger.Info()
                .Message("Category: {0}\tEntry: {1}\t\tValue: {2}", r.CategoryEntryPair.Category, r.CategoryEntryPair.Entry,
                         r.DecryptedValue)
                .Write();
            }
        }