Exemple #1
0
        public int Run()
        {
            var name = ConsoleUtils.Prompt("Key name");
            var code = ConsoleUtils.Prompt("Secret code");

            try
            {
                _secretStorage.LoadSecret(name, code);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine($"Could not load key: {ex.Message}");
                Console.Error.WriteLine("Please check that the name and secret code are valid.");
                return(1);
            }

            var handler = _keyHandlerFactory.GetHandler(name);

            var(accessToken, accessTokenConfig) = handler.CreateAccessToken(code, name);
            var encodedAccessToken = SaveAccessToken(accessToken, accessTokenConfig);

            Console.WriteLine();
            Console.WriteLine("Created new access token:");
            Console.WriteLine(encodedAccessToken);
            return(0);
        }
Exemple #2
0
        private int Run(string[] args)
        {
            var app = new CommandLineApplication();

            app.Name = "SecureSignTools";
            app.HelpOption("-?|-h|--help");
            app.OnExecute(() => app.ShowHelp());

            app.Command("addkey", command =>
            {
                command.Description = "Add a new key";
                var pathArg         = command.Argument("path", "Path to the key file to add");
                command.OnExecute(() =>
                {
                    var inputPath = pathArg.Value;
                    if (string.IsNullOrWhiteSpace(inputPath))
                    {
                        Console.WriteLine("Please include the file name to add");
                        return(1);
                    }

                    if (!File.Exists(inputPath))
                    {
                        throw new Exception("File does not exist: " + inputPath);
                    }

                    var handler = _keyHandlerFactory.GetHandler(inputPath);
                    handler.AddKey(inputPath);

                    Console.WriteLine();
                    Console.WriteLine("This secret code is required whenever you create an access token that uses this key.");
                    Console.WriteLine("Store this secret code in a SECURE PLACE! The code is not stored anywhere, ");
                    Console.WriteLine("so if you lose it, you will need to re-install the key.");
                    Console.ReadKey();
                    return(0);
                });
            });

            app.Command("addtoken", command =>
            {
                command.Description = "Add a new access token";
                command.OnExecute(() => ActivatorUtilities.CreateInstance <AddToken>(_provider).Run());
            });

            try
            {
                return(app.Execute(args));
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("ERROR: " + ex.Message);
#if DEBUG
                throw;
#else
                return(1);
#endif
            }
        }