public void GetPathListNoAccess() { RegistryPermission ep = new RegistryPermission(PermissionState.None); ep.AddPathList(RegistryPermissionAccess.Read, keyCurrentUser); ep.AddPathList(RegistryPermissionAccess.Write, keyLocalMachine); Assert.AreEqual(String.Empty, ep.GetPathList(RegistryPermissionAccess.NoAccess), "GetPathList-NoAccess"); }
public void AddPathList() { RegistryPermission ep = new RegistryPermission(PermissionState.None); ep.AddPathList(RegistryPermissionAccess.AllAccess, keyLocalMachine); // LAMESPEC NoAccess do not remove the keyLocalMachine from AllAccess ep.AddPathList(RegistryPermissionAccess.NoAccess, keyLocalMachine); ep.AddPathList(RegistryPermissionAccess.Read, keyCurrentUser); ep.AddPathList(RegistryPermissionAccess.Write, keyCurrentUser); SecurityElement se = ep.ToXml(); // Note: Debugger can mess results (try to run without stepping) Assert.AreEqual(@"HKEY_LOCAL_MACHINE\SOFTWARE\Novell\Novell iFolder\1.00.000", se.Attribute("Create"), "AddPathList-ToXml-Create"); Assert.AreEqual(@"HKEY_LOCAL_MACHINE\SOFTWARE\Novell\Novell iFolder\1.00.000;HKEY_CURRENT_USER\Software\Novell iFolder\spouliot\Home", se.Attribute("Read"), "AddPathList-ToXml-Read"); Assert.AreEqual(@"HKEY_LOCAL_MACHINE\SOFTWARE\Novell\Novell iFolder\1.00.000;HKEY_CURRENT_USER\Software\Novell iFolder\spouliot\Home", se.Attribute("Write"), "AddPathList-ToXml-Write"); }
private static void CheckSecurity() { RegistryPermission regPerm = new RegistryPermission(RegistryPermissionAccess.Write, "HKEY_CLASSES_ROOT\\" + _menuName); regPerm.AddPathList(RegistryPermissionAccess.Write, "HKEY_CLASSES_ROOT\\" + _menuCommand); regPerm.Demand(); }
/// <summary> /// Enumerate Names of Services and their DisplayNames. /// </summary> //[RegistryPermissionAttribute(SecurityAction.Demand, Unrestricted = true)] internal static void EnumServices() { //We need AllAccess for Enumeration. RegistryPermission f = new RegistryPermission(RegistryPermissionAccess.AllAccess, @"HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\"); using (RegistryKey services = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Services", false)) { foreach (String name in services.GetSubKeyNames()) { try { serviceslist.Add(name.ToLower()); f.AddPathList(RegistryPermissionAccess.Read, @"System\CurrentControlSet\Services\" + name); using (RegistryKey service = services.OpenSubKey(name, false)) { Object displayname = service.GetValue("DisplayName"); if (displayname != null) { //Debug.WriteLine(displayname.ToString()); serviceslist.Add(displayname.ToString().ToLower()); } } } catch { //SBCore fails on WHS And propably W2K3 Server too. //MessageBox.Show(name); } } } }
private void CheckSecurity(string MenuName) { //check registry permissions RegistryPermission regPerm; regPerm = new RegistryPermission(RegistryPermissionAccess.Write, "HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell\\" + MenuName); regPerm.AddPathList(RegistryPermissionAccess.Write, "HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell\\" + MenuName + "\\command"); regPerm.Demand(); }
private void CheckSecurity() { //check registry permissions RegistryPermission regPerm; regPerm = new RegistryPermission(RegistryPermissionAccess.Write, "HKEY_CLASSES_ROOT\\" + MenuName); regPerm.AddPathList(RegistryPermissionAccess.Write, "HKEY_CLASSES_ROOT\\" + Command); regPerm.Demand(); }
public void GetPathList() { RegistryPermission ep = new RegistryPermission(PermissionState.None); Assert.AreEqual(String.Empty, ep.GetPathList(RegistryPermissionAccess.Create), "GetPathList-Create-Empty"); Assert.AreEqual(String.Empty, ep.GetPathList(RegistryPermissionAccess.Read), "GetPathList-Read-Empty"); Assert.AreEqual(String.Empty, ep.GetPathList(RegistryPermissionAccess.Write), "GetPathList-Write-Empty"); ep.AddPathList(RegistryPermissionAccess.Create, keyLocalMachine); ep.AddPathList(RegistryPermissionAccess.Create, keyCurrentUser); Assert.AreEqual(keyLocalMachine + ";" + keyCurrentUser, ep.GetPathList(RegistryPermissionAccess.Create), "GetPathList-Read"); ep.AddPathList(RegistryPermissionAccess.Read, keyLocalMachine); Assert.AreEqual(keyLocalMachine, ep.GetPathList(RegistryPermissionAccess.Read), "GetPathList-Read"); ep.AddPathList(RegistryPermissionAccess.Write, keyCurrentUser); Assert.AreEqual(keyCurrentUser, ep.GetPathList(RegistryPermissionAccess.Write), "GetPathList-Write"); }
public void AddPathList_Subset() { RegistryPermission ep = new RegistryPermission(PermissionState.None); ep.AddPathList(RegistryPermissionAccess.AllAccess, keyLocalMachine); ep.AddPathList(RegistryPermissionAccess.AllAccess, keyLocalMachineSubset); SecurityElement se = ep.ToXml(); Assert.AreEqual(keyLocalMachineSubset, se.Attribute("Create"), "AddPathList-ToXml-Create"); Assert.AreEqual(keyLocalMachineSubset, se.Attribute("Read"), "AddPathList-ToXml-Read"); Assert.AreEqual(keyLocalMachineSubset, se.Attribute("Write"), "AddPathList-ToXml-Write"); ep = new RegistryPermission(PermissionState.None); ep.AddPathList(RegistryPermissionAccess.AllAccess, keyLocalMachine); ep.AddPathList(RegistryPermissionAccess.Create, keyLocalMachineSubset); ep.AddPathList(RegistryPermissionAccess.Read, keyCurrentUser); se = ep.ToXml(); Assert.AreEqual(keyLocalMachineSubset, se.Attribute("Create"), "AddPathList-ToXml-Create"); Assert.AreEqual(keyLocalMachine + ";" + keyCurrentUser, se.Attribute("Read"), "AddPathList-ToXml-Read"); Assert.AreEqual(keyLocalMachine, se.Attribute("Write"), "AddPathList-ToXml-Write"); }
//</Snippet6> //<Snippet9> // AddPathList adds access for the specified registry variables to the existing state of the permission. // SetPathList sets new access for the specified registry variable names to the existing state of the permission. // GetPathList gets paths for all registry variables with the specified RegistryPermissionAccess. private static bool SetGetPathListDemo() { try { Console.WriteLine("********************************************************\n"); //<Snippet10> RegistryPermission readPerm1; Console.WriteLine("Creating RegistryPermission with AllAccess rights for 'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0'"); readPerm1 = new RegistryPermission(RegistryPermissionAccess.AllAccess, "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"); //</Snippet10> Console.WriteLine("Adding 'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION' to the write access list, " + "and \n 'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor\\0' " + "to the read access list."); readPerm1.AddPathList(RegistryPermissionAccess.Write, "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION"); readPerm1.AddPathList(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor\\0"); Console.WriteLine("Read access list before SetPathList = " + readPerm1.GetPathList(RegistryPermissionAccess.Read)); Console.WriteLine("Setting read access rights to \n'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0'"); readPerm1.SetPathList(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"); Console.WriteLine("Read access list after SetPathList = \n" + readPerm1.GetPathList(RegistryPermissionAccess.Read)); Console.WriteLine("Write access = \n" + readPerm1.GetPathList(RegistryPermissionAccess.Write)); Console.WriteLine("Write access Registry variables = \n" + readPerm1.GetPathList(RegistryPermissionAccess.AllAccess)); } catch (ArgumentException e) { // RegistryPermissionAccess.AllAccess can not be used as a parameter for GetPathList. Console.WriteLine("An ArgumentException occured as a result of using AllAccess. " + "AllAccess cannot be used as a parameter in GetPathList because it represents more than one " + "type of registry variable access : \n" + e); } return(true); }
/// <summary> /// 修正するレジストリに権限を与える。 /// </summary> /// <param name="menuname">ルートレジストリパス</param> /// <param name="command">命令レジストリパス</param> private void PermissionReg(String menuname, String command) { try { RegistryPermission regPerm = new RegistryPermission( RegistryPermissionAccess.Write, HKEY_CLASSES_ROOT + menuname); regPerm.AddPathList( RegistryPermissionAccess.Write, HKEY_CLASSES_ROOT + command); regPerm.Demand(); } catch (Exception e) { Console.WriteLine(e.ToString()); throw e; } }
public static void RegistryPermissionCallMethods() { Permissions.RegistryPermissionAccess rpa = new Permissions.RegistryPermissionAccess(); RegistryPermission rp = new RegistryPermission(new Permissions.PermissionState()); RegistryPermission rp2 = new RegistryPermission(rpa, new System.Security.AccessControl.AccessControlActions(), "testpath"); RegistryPermission rp3 = new RegistryPermission(rpa, "testpath"); rp.AddPathList(rpa, "testpath"); IPermission ip = rp.Copy(); string path = rp.GetPathList(rpa); IPermission ip2 = rp.Intersect(ip); bool testbool = rp.IsSubsetOf(ip); testbool = rp.IsUnrestricted(); rp.SetPathList(rpa, "testpath"); ip2 = rp.Union(ip); SecurityElement se = new SecurityElement(""); rp.FromXml(se); se = rp.ToXml(); }
public void EncryptRegistryDetails(string installlocation, string wsurl, string dirlocation) { RegistryPermission fwrite = new RegistryPermission(RegistryPermissionAccess.Write, "HKLM\\SOFTWARE\\"); fwrite.AddPathList(RegistryPermissionAccess.Write, "HKLM\\SOFTWARE\\"); RegistryKey OurKey = Registry.LocalMachine; // Create OurKey set to HKEY_LOCAL_MACHINE OurKey = OurKey.OpenSubKey("SOFTWARE", true); // Set it to HKEY_LOCAL_MACHINE\SOFTWARE OurKey.CreateSubKey("TerraScan"); // Create the key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan OurKey.CreateSubKey(@"TerraScan\TerraScanApplication"); // Create a sub key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan\TerraScanDatabase OurKey = OurKey.OpenSubKey(@"TerraScan\TerraScanApplication", true); OurKey.SetValue("InstallLocation", installurl); OurKey.SetValue("WebServiceURL", webserviceurl); OurKey.SetValue("InstallDirectory", iisrootdirectory); OurKey.SetValue("MSWCFURL", mswcfurl); OurKey.SetValue("Version", "1.0.25.36"); OurKey.Close(); OurKey = null; RegistryKey ComponentIDKey = Registry.LocalMachine; // Create OurKey set to HKEY_LOCAL_MACHINE ComponentIDKey = ComponentIDKey.OpenSubKey("SOFTWARE", true); // Set it to HKEY_LOCAL_MACHINE\SOFTWARE ComponentIDKey.CreateSubKey("TerraScan"); // Create the key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan ComponentIDKey.CreateSubKey(@"TerraScan\ComponentID"); // Create a sub key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan\TerraScanDatabase ComponentIDKey = ComponentIDKey.OpenSubKey(@"TerraScan\ComponentID", true); ComponentIDKey.SetValue("ComponentID", "1"); ComponentIDKey.Close(); ComponentIDKey = null; #region to be used only if necessary //key = ciphwrp.Key; //installlocationiv = ciphwrp.AsymmIV; //wsurliv = ciphwrp.AsymmIV; //dirlocationiv = ciphwrp.AsymmIV; //bool testciphercreate = this.createCiphers(installlocation, wsurl, dirlocation); //if (testciphercreate == true) //{ // try // { // cipherInstallLocation = ciphwrp.EncryptMessage(plainTextInstallLocation, key, out installlocationiv); // cipherWSUrl = ciphwrp.EncryptMessage(plainTextWSUrl, key, out wsurliv); // cipherDirLocation = ciphwrp.EncryptMessage(plainTextDirLocation, key, out dirlocationiv); // } // catch (System.Security.SecurityException sec) // { // MessageBox.Show(sec.Message); // } //} //RegistryPermission fwrite = new RegistryPermission(RegistryPermissionAccess.Write, "HKLM\\SOFTWARE\\"); //fwrite.AddPathList(RegistryPermissionAccess.Write, "HKLM\\SOFTWARE\\"); //RegistryKey OurKey = Registry.LocalMachine; // Create OurKey set to HKEY_LOCAL_MACHINE //OurKey = OurKey.OpenSubKey("SOFTWARE", true); // Set it to HKEY_LOCAL_MACHINE\SOFTWARE //OurKey.CreateSubKey("TerraScan"); // Create the key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan //OurKey.CreateSubKey(@"TerraScan\TerraScanApplication"); // Create a sub key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan\TerraScanDatabase //OurKey = OurKey.OpenSubKey(@"TerraScan\TerraScanApplication", true); //OurKey.SetValue("InstallLocation", cipherWSUrl); //OurKey.SetValue("WebServiceURL", cipherInstallLocation); //OurKey.SetValue("InstallDirectory", cipherDirLocation); //OurKey.SetValue("Version", "1.0.25.36"); //OurKey.Close(); //OurKey = null; //RegistryKey ComponentIDKey = Registry.LocalMachine; // Create OurKey set to HKEY_LOCAL_MACHINE //ComponentIDKey = ComponentIDKey.OpenSubKey("SOFTWARE", true); // Set it to HKEY_LOCAL_MACHINE\SOFTWARE //ComponentIDKey.CreateSubKey("TerraScan"); // Create the key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan //ComponentIDKey.CreateSubKey(@"TerraScan\ComponentID"); // Create a sub key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan\TerraScanDatabase //ComponentIDKey = ComponentIDKey.OpenSubKey(@"TerraScan\ComponentID", true); //ComponentIDKey.SetValue("ComponentID", "1"); //RegistryKey ClrKey = Registry.ClassesRoot; // Create OurKey set to HKEY_LOCAL_MACHINE //ClrKey.CreateSubKey("TerraScan"); // Create the key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan //ClrKey.CreateSubKey(@"TerraScan\TerraScanApplication"); //ClrKey = ClrKey.OpenSubKey(@"TerraScan\TerraScanApplication", true); //ClrKey.SetValue("key", key); //ClrKey.SetValue("installlocationiv", installlocationiv); //ClrKey.SetValue("wsurliv", wsurliv); //ClrKey.SetValue("dirlocationiv", dirlocationiv); //ClrKey.Close(); //ClrKey = null; #endregion }
}// ValidateData internal override IPermission GetCurrentPermission() { // Change cells so we get data committed to the grid m_dg.CurrentCell = new DataGridCell(0, 1); m_dg.CurrentCell = new DataGridCell(0, 0); RegistryPermission perm = null; if (m_radUnrestricted.Checked == true) { perm = new RegistryPermission(PermissionState.Unrestricted); } else { perm = new RegistryPermission(PermissionState.None); StringCollection scRead = new StringCollection(); StringCollection scWrite = new StringCollection(); StringCollection scCreate = new StringCollection(); for (int i = 0; i < m_dt.Rows.Count; i++) { // Make sure we have a registry permission to add if (m_dg[i, 0] is String && ((String)m_dg[i, 0]).Length > 0) { // Does this path have read permissions if ((bool)m_dg[i, 1]) { scRead.Add((String)m_dg[i, 0]); } // Does this path have write permissions if ((bool)m_dg[i, 2]) { scWrite.Add((String)m_dg[i, 0]); } // Does this have append permissions if ((bool)m_dg[i, 3]) { scCreate.Add((String)m_dg[i, 0]); } } else { // Make sure they didn't check any boxes and not include // an empty path bool fCheckedBox = false; for (int j = 1; j <= 3 && !fCheckedBox; j++) { fCheckedBox = (bool)m_dg[i, j]; } if (fCheckedBox) { MessageBox(CResourceStore.GetString("RegPerm:NeedRegName"), CResourceStore.GetString("RegPerm:NeedRegNameTitle"), MB.ICONEXCLAMATION); return(null); } } } String sAdd = PathListFunctions.JoinStringCollection(scRead); if (sAdd.Length > 0) { perm.AddPathList(RegistryPermissionAccess.Read, sAdd); } String sWrite = PathListFunctions.JoinStringCollection(scWrite); if (sWrite.Length > 0) { perm.AddPathList(RegistryPermissionAccess.Write, sWrite); } String sCreate = PathListFunctions.JoinStringCollection(scCreate); if (sCreate.Length > 0) { perm.AddPathList(RegistryPermissionAccess.Create, sCreate); } } return(perm); }// GetCurrentPermission
/// <summary> /// Encrypts the registry details. /// </summary> /// <param name="ImpersonateUserName">Name of the impersonate user.</param> /// <param name="ImpersonatePassword">The impersonate password.</param> /// <param name="DatabaseUserName">Name of the database user.</param> /// <param name="DatabasePassword">The database password.</param> public void EncryptRegistryDetails(string ImpersonateUserName, string ImpersonatePassword, string DatabaseUserName, string DatabasePassword) { key = ciphwrp.Key; usernameiv = ciphwrp.AsymmIV; passwordiv = ciphwrp.AsymmIV; sausernameiv = ciphwrp.AsymmIV; sapasswordiv = ciphwrp.AsymmIV; RegistryPermission fwrite = new RegistryPermission(RegistryPermissionAccess.Write, "HKLM\\SOFTWARE\\"); fwrite.AddPathList(RegistryPermissionAccess.Write, "HKLM\\SOFTWARE\\"); RegistryKey OurKey = Registry.LocalMachine; // Create OurKey set to HKEY_LOCAL_MACHINE OurKey = OurKey.OpenSubKey("SOFTWARE", true); // Set it to HKEY_LOCAL_MACHINE\SOFTWARE OurKey.CreateSubKey("TerraScan"); // Create the key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan OurKey.CreateSubKey(@"TerraScan\TerraScanWCF"); // Create a sub key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan\TerraScanDatabase OurKey = OurKey.OpenSubKey(@"TerraScan\TerraScanWCF", true); // OurKey.SetValue("LDAP", ldap); // OurKey.SetValue("DomainName", domainName); // OurKey.SetValue("InstallDirectory", iisrootdirectory); OurKey.SetValue("DatabaseServer", databaseServerInstall); OurKey.SetValue("DatabaseName", databaseNameInstall); OurKey.SetValue("DatabaseAuthentication", dbauthencticationInstall); OurKey.SetValue("Version", "1.0.25.36"); OurKey.Close(); OurKey = null; RegistryKey ComponentIDKey = Registry.LocalMachine; // Create OurKey set to HKEY_LOCAL_MACHINE ComponentIDKey = ComponentIDKey.OpenSubKey("SOFTWARE", true); // Set it to HKEY_LOCAL_MACHINE\SOFTWARE ComponentIDKey.CreateSubKey("TerraScan"); // Create the key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan ComponentIDKey.CreateSubKey(@"TerraScan\ComponentID"); // Create a sub key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan\TerraScanDatabase ComponentIDKey = ComponentIDKey.OpenSubKey(@"TerraScan\ComponentID", true); ComponentIDKey.SetValue("ComponentID", "1"); ComponentIDKey.Close(); ComponentIDKey = null; bool testciphercreate = this.createCiphers(ImpersonateUserName, ImpersonatePassword, DatabaseUserName, DatabasePassword); if (testciphercreate == true) { try { cipherImpUserName = ciphwrp.EncryptMessage(ByteImpUserName, key, out usernameiv); cipherImpPassword = ciphwrp.EncryptMessage(ByteImpPassword, key, out passwordiv); cipherDBUserName = ciphwrp.EncryptMessage(ByteDBUserName, key, out sausernameiv); cipherDBPassword = ciphwrp.EncryptMessage(ByteDBPassword, key, out sapasswordiv); } catch (System.Security.SecurityException sec) { MessageBox.Show(sec.Message); } } RegistryKey EncryptOurKey = Registry.LocalMachine; // Create OurKey set to HKEY_LOCAL_MACHINE EncryptOurKey = EncryptOurKey.OpenSubKey("SOFTWARE", true); // Set it to HKEY_LOCAL_MACHINE\SOFTWARE EncryptOurKey.CreateSubKey("TerraScan"); // Create the key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan EncryptOurKey.CreateSubKey(@"TerraScan\TerraScanMSWCF"); // Create a sub key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan\TerraScanDatabase EncryptOurKey = EncryptOurKey.OpenSubKey(@"TerraScan\TerraScanMSWCF", true); EncryptOurKey.SetValue("ImpersonatedUserName", cipherImpUserName); EncryptOurKey.SetValue("ImpersonatedPassword", cipherImpPassword); EncryptOurKey.SetValue("DatabaseUserName", cipherDBUserName); EncryptOurKey.SetValue("DatabasePassword", cipherDBPassword); EncryptOurKey.Close(); EncryptOurKey = null; RegistryKey ClrKey = Registry.ClassesRoot; // Create OurKey set to HKEY_LOCAL_MACHINE ClrKey.CreateSubKey("TerraScan"); // Create the key HKEY_LOCAL_MACHINE\SOFTWARE\TerraScan ClrKey.CreateSubKey(@"TerraScan\TerraScanMSWCF"); ClrKey = ClrKey.OpenSubKey(@"TerraScan\TerraScanMSWCF", true); ClrKey.SetValue("key", key); ClrKey.SetValue("usernameiv", usernameiv); ClrKey.SetValue("passwordiv", passwordiv); ClrKey.SetValue("sausernameiv", sausernameiv); ClrKey.SetValue("sapasswordiv", sapasswordiv); ClrKey.Close(); ClrKey = null; }