Example #1
0
        public void ShouldWriteKeyToLocalAppStorage()
        {
            var repo = new FileSystemKeyRepository();

            const string institution = "Some Institution";
            const string group       = "Some Group";
            const string product     = "Some Product";

            const string key = "abc123";

            repo.WriteKey(institution, group, product, key);

            Assert.Equal(key, ReadKey(repo, institution, group, product));
        }
        public void ShouldWriteKeyToLocalAppStorage()
        {
            var repo = new FileSystemKeyRepository();

            const string institution = "Some Institution";
            const string group = "Some Group";
            const string product = "Some Product";

            const string key = "abc123";

            repo.WriteKey(institution, group, product, key);

            Assert.Equal(key, ReadKey(repo, institution, group, product));
        }
        static void Main(string[] args)
        {
            bool show_help = false;
            string institution = null;
            string group = null;
            const string product = "Ovation";
            bool system_key = false;

            var p = new OptionSet() {
            { "h|help",  "show this message and exit",
              v => show_help = v != null },
              {"i=|institution=", "licensed institution",
              (string v) => institution = v},
              {"g=|group=", "licensed group",
              (string v) => group = v},
              {"s|system", "add key to system query server (requires Administrator role)",
                  v => system_key = v != null}
            };

            List<string> extra;
            try
            {
                extra = p.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("keyconsole: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `keyconsole --help' for more information.");
                return;
            }

            if (show_help)
            {
                ShowHelp(p);
                return;
            }

            if (institution == null)
            {
                Console.Write("keyconsole: ");
                Console.WriteLine("You must provide the licensed institution.");
                Console.WriteLine("Try `keyconsole --help' for more information.");
                return;
            }

            if (group == null)
            {
                Console.Write("keyconsole: ");
                Console.WriteLine("You must provide the licensed group.");
                Console.WriteLine("Try `keyconsole --help' for more information.");
                return;
            }

            if (system_key && !IsUserAdministrator())
            {
                Console.Write("keyconsole: ");
                Console.WriteLine("Writing a key to the system (query server) key store requires administrator role.");
                Console.WriteLine("Run keyconsole as Administrator.");
                return;
            }

            var fsManager = new FileSystemKeyRepository();

            Console.Write("Shared ecnryption key:");
            var keyBuilder = ReadConsoleKey();
            Console.WriteLine("");

            Console.WriteLine("Re-enter shared encryption key:");
            var keyBuilderComp = ReadConsoleKey();
            Console.WriteLine("");

            if (!keyBuilder.ToString().Equals(keyBuilderComp.ToString()))
            {
                Console.Write("keyconsole: ");
                Console.WriteLine("Keys do not match. Keys have not been modified");
                return;
            }

            try
            {
                fsManager.WriteKey(institution, group, product, keyBuilder.ToString());
                if (system_key)
                {
                    var proxy = new KeyRepositoryClient();
                    proxy.WriteKey(institution, group, product, keyBuilder.ToString());
                }
            }
            catch (Exception ex)
            {
                Console.Write("keyconsole: ");
                Console.WriteLine(ex.Message);
                Console.WriteLine("Try `keyconsole --help' for more information.");
            }
        }