public void ShouldStoreInPhysionOvationKeysDirectory() { const string path = "somePath"; var repo = new FileSystemKeyRepository(path); Assert.Equal(repo.RepositoryPath, Path.Combine(path, "Physion", "Ovation", "keys")); }
public void ShouldComputeDifferentEntropyForDifferentInstitutionAndGroup() { const string institution = "some inst"; const string group = "group"; const string product = "Ovation"; const string institution2 = "other inst"; const string group2 = "group2"; var repo = new FileSystemKeyRepository(); Assert.NotEqual(repo.EntropyBytes(institution2, group2, product), repo.EntropyBytes(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)); }
private static string ReadKey(FileSystemKeyRepository repo, string institution, string group, string product) { var keyName = String.Format("{0}__{1}__{2}", institution, group, product); using (var stream = new FileStream( Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Physion", "Ovation", "keys", keyName), FileMode.Open, FileAccess.Read)) using (var reader = new BinaryReader(stream)) { var encryptedBytes = reader.ReadBytes((int)stream.Length); var bytes = ProtectedData.Unprotect(encryptedBytes, repo.EntropyBytes(institution, group, product), DataProtectionScope.CurrentUser); return(Encoding.UTF8.GetString(bytes)); } }
private static string ReadKey(FileSystemKeyRepository repo, string institution, string group, string product) { var keyName = String.Format("{0}__{1}__{2}", institution, group, product); using(var stream = new FileStream( Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Physion", "Ovation", "keys", keyName), FileMode.Open, FileAccess.Read)) using (var reader = new BinaryReader(stream)) { var encryptedBytes = reader.ReadBytes((int)stream.Length); var bytes = ProtectedData.Unprotect(encryptedBytes, repo.EntropyBytes(institution, group, product), DataProtectionScope.CurrentUser); return Encoding.UTF8.GetString(bytes); } }
public void ShouldWriteEntropyToFile() { const string institution = "Some Institution"; const string group = "Some Group"; const string product = "Some Product"; var repo = new FileSystemKeyRepository(); var entropyBytes = repo.EntropyBytes(institution, group, product); var entropyFileName = String.Format("entropy_{0}__{1}__{2}", institution, group, product); using (var stream = new FileStream(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Physion", "Ovation", "keys", entropyFileName), FileMode.Open, FileAccess.Read) ) using (var reader = new BinaryReader(stream)) { var fileBytes = reader.ReadBytes((int)stream.Length); Assert.Equal(entropyBytes, fileBytes); } }
public void ShouldWriteEntropyToFile() { const string institution = "Some Institution"; const string group = "Some Group"; const string product = "Some Product"; var repo = new FileSystemKeyRepository(); var entropyBytes = repo.EntropyBytes(institution, group, product); var entropyFileName = String.Format("entropy_{0}__{1}__{2}", institution, group, product); using(var stream = new FileStream(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Physion", "Ovation", "keys", entropyFileName), FileMode.Open, FileAccess.Read) ) using (var reader = new BinaryReader(stream)) { var fileBytes = reader.ReadBytes((int)stream.Length); Assert.Equal(entropyBytes, fileBytes); } }
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."); } }