当前位置: 首页>>代码示例>>C#>>正文


C# PermissionSet.Demand方法代码示例

本文整理汇总了C#中System.Security.PermissionSet.Demand方法的典型用法代码示例。如果您正苦于以下问题:C# PermissionSet.Demand方法的具体用法?C# PermissionSet.Demand怎么用?C# PermissionSet.Demand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.PermissionSet的用法示例。


在下文中一共展示了PermissionSet.Demand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Build

 public bool Build(X509Certificate2 certificate)
 {
     lock (this.m_syncRoot)
     {
         if ((certificate == null) || certificate.CertContext.IsInvalid)
         {
             throw new ArgumentException(SR.GetString("Cryptography_InvalidContextHandle"), "certificate");
         }
         new StorePermission(StorePermissionFlags.EnumerateCertificates | StorePermissionFlags.OpenStore).Demand();
         X509ChainPolicy chainPolicy = this.ChainPolicy;
         if ((chainPolicy.RevocationMode == X509RevocationMode.Online) && ((certificate.Extensions["2.5.29.31"] != null) || (certificate.Extensions["1.3.6.1.5.5.7.1.1"] != null)))
         {
             PermissionSet set = new PermissionSet(PermissionState.None);
             set.AddPermission(new WebPermission(PermissionState.Unrestricted));
             set.AddPermission(new StorePermission(StorePermissionFlags.AddToStore));
             set.Demand();
         }
         this.Reset();
         if (BuildChain(this.m_useMachineContext ? new IntPtr(1L) : new IntPtr(0L), certificate.CertContext, chainPolicy.ExtraStore, chainPolicy.ApplicationPolicy, chainPolicy.CertificatePolicy, chainPolicy.RevocationMode, chainPolicy.RevocationFlag, chainPolicy.VerificationTime, chainPolicy.UrlRetrievalTimeout, ref this.m_safeCertChainHandle) != 0)
         {
             return false;
         }
         this.Init();
         CAPIBase.CERT_CHAIN_POLICY_PARA pPolicyPara = new CAPIBase.CERT_CHAIN_POLICY_PARA(Marshal.SizeOf(typeof(CAPIBase.CERT_CHAIN_POLICY_PARA)));
         CAPIBase.CERT_CHAIN_POLICY_STATUS pPolicyStatus = new CAPIBase.CERT_CHAIN_POLICY_STATUS(Marshal.SizeOf(typeof(CAPIBase.CERT_CHAIN_POLICY_STATUS)));
         pPolicyPara.dwFlags = (uint) chainPolicy.VerificationFlags;
         if (!CAPISafe.CertVerifyCertificateChainPolicy(new IntPtr(1L), this.m_safeCertChainHandle, ref pPolicyPara, ref pPolicyStatus))
         {
             throw new CryptographicException(Marshal.GetLastWin32Error());
         }
         CAPISafe.SetLastError(pPolicyStatus.dwError);
         return (pPolicyStatus.dwError == 0);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:34,代码来源:X509Chain.cs

示例2: AppDomainHost

      protected AppDomainHost(Type serviceType,AppDomain appDomain,PermissionSet permissions,Uri[] baseAddresses)
      {
         State = CommunicationState.Faulted;

         //Cannot grant service permissions the host does not have
         permissions.Demand();

         string assemblyName = Assembly.GetAssembly(typeof(ServiceHostActivator)).FullName;
         m_ServiceHostActivator = appDomain.CreateInstanceAndUnwrap(assemblyName,typeof(ServiceHostActivator).ToString()) as ServiceHostActivator;

         appDomain.SetPermissionsSet(permissions);

         m_ServiceHostActivator.CreateHost(serviceType,baseAddresses);

         State = CommunicationState.Created;
      }      
开发者ID:knunery,项目名称:wcf-perf-test,代码行数:16,代码来源:AppDomainHost.cs

示例3: CanAllowConnectionAfterPermitOnlyPermission

        public void CanAllowConnectionAfterPermitOnlyPermission()
        {
            PermissionSet permissionset = new PermissionSet(PermissionState.None);

              MySqlClientPermission permission = new MySqlClientPermission(PermissionState.None);

              MySqlConnectionStringBuilder strConn = new MySqlConnectionStringBuilder(conn.ConnectionString);

              //// Allow connections only to specified database no additional optional parameters
              permission.Add("server=localhost;User Id=root;database=" + strConn.Database + ";port=" + strConn.Port + ";", "", KeyRestrictionBehavior.PreventUsage);
              permission.PermitOnly();
              permissionset.AddPermission(permission);
              permissionset.Demand();

              // this conection should be allowed
              MySqlConnection dummyconn = new MySqlConnection();
              dummyconn.ConnectionString = "server=localhost;User Id=root;database=" + strConn.Database + ";port=" + strConn.Port + ";includesecurityasserts=true;";
              dummyconn.Open();
              if (dummyconn.State == ConnectionState.Open) dummyconn.Close();
        }
开发者ID:schivei,项目名称:mysql-connector-net,代码行数:20,代码来源:MySqlClientPermissionTests.cs

示例4: loadAssembly2

        static void loadAssembly2()
        {
            Assembly assembly = Assembly.LoadFrom("assembly2.dll");

            Console.WriteLine("Strong Name : " + assembly.GetName());
            try
            {
                PermissionSet perr = new PermissionSet(PermissionState.None);

                perr.AddPermission(new FileIOPermission(PermissionState.Unrestricted));

                perr.PermitOnly();
                perr.Demand();

                Assembly2.AssemblyClass2.openPage();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);

            }
        }
开发者ID:hkalyan,项目名称:CS795HW3,代码行数:22,代码来源:Program.cs

示例5: Demand

		public void Demand ()
		{
			// check all collection in a single stack walk
			PermissionSet superset = new PermissionSet (PermissionState.None);
			foreach (PermissionSet ps in _list) {
				foreach (IPermission p in ps) {
					superset.AddPermission (p);
				}
			}
			superset.Demand ();
		}
开发者ID:runefs,项目名称:Marvin,代码行数:11,代码来源:PermissionSetCollection.cs

示例6: AssertPermissions

 partial void AssertPermissions()
 {
   // Security Asserts can only be done when the assemblies 
   // are put in the GAC as documented in 
   // http://msdn.microsoft.com/en-us/library/ff648665.aspx
   if (this.Settings.IncludeSecurityAsserts)
   {
     PermissionSet set = new PermissionSet(PermissionState.None);
     set.AddPermission(new MySqlClientPermission(ConnectionString));
     set.Demand();
     MySqlSecurityPermission.CreatePermissionSet(true).Assert(); 
   }
 }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:13,代码来源:MySqlConnection.cs

示例7: PerformMouseAction

        private static void PerformMouseAction(int coord_x, int coord_y, int something, MouseInputFlags flags)
        {
            PermissionSet permissions = new PermissionSet(PermissionState.Unrestricted);
            permissions.Demand();

            int intflags = (int)flags;

            if ((intflags & (int)MouseInputFlags.Absolute) != 0)
            {
                // Absolute position requires normalized coordinates.
                NormalizeCoordinates(ref coord_x, ref coord_y);
                intflags |= MouseeventfVirtualdesk;
            }

            INPUT mi = new INPUT();
            mi.type = InputMouse;
            mi.union.mouseInput.dx = coord_x;
            mi.union.mouseInput.dy = coord_y;
            mi.union.mouseInput.mouseData = something;
            mi.union.mouseInput.dwFlags = intflags;
            mi.union.mouseInput.time = 0;
            mi.union.mouseInput.dwExtraInfo = new IntPtr(0);

            if (SendInput(1, ref mi, Marshal.SizeOf(mi)) == 0)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }
开发者ID:natritmeyer,项目名称:bewildr,代码行数:28,代码来源:Clickr.cs

示例8: Log3

 public static void Log3(string text)
 {
     PermissionSet p = new PermissionSet(PermissionState.Unrestricted);
     p.Demand();
 }
开发者ID:dbremner,项目名称:smokey,代码行数:5,代码来源:ImperativeSecurityTest.cs

示例9: CheckSecurity

		/// <summary>
		/// Check security permissions
		/// </summary>
		public static bool CheckSecurity()
		{
			try
			{
				PermissionSet set = new PermissionSet(PermissionState.Unrestricted);
				set.Demand();
			}
			catch
			{
				return false;
			}
			return true;
		}
开发者ID:jordan49,项目名称:websitepanel,代码行数:16,代码来源:Utils.cs

示例10: SendKeyboardInput

            private static void SendKeyboardInput(Key key, bool press)
            {
                PermissionSet permissions = new PermissionSet(PermissionState.Unrestricted);
                permissions.Demand();

                NativeMethods.INPUT ki = new NativeMethods.INPUT();
                ki.type = NativeMethods.InputKeyboard;
                ki.union.keyboardInput.wVk = (short)KeyInterop.VirtualKeyFromKey(key);
                ki.union.keyboardInput.wScan = (short)NativeMethods.MapVirtualKey(ki.union.keyboardInput.wVk, 0);

                int dwFlags = 0;

                if (ki.union.keyboardInput.wScan > 0)
                {
                    dwFlags |= NativeMethods.KeyeventfScancode;
                }

                if (!press)
                {
                    dwFlags |= NativeMethods.KeyeventfKeyup;
                }

                ki.union.keyboardInput.dwFlags = dwFlags;

                ki.union.keyboardInput.time = 0;
                ki.union.keyboardInput.dwExtraInfo = new IntPtr(0);

                if (NativeMethods.SendInput(1, ref ki, Marshal.SizeOf(ki)) == 0)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
            }
开发者ID:BilldBird,项目名称:Kinect_Fitness,代码行数:32,代码来源:KeyboardToolkit.cs

示例11: Init

        /// <summary>
        /// Initializes the permissions manager with the permissions required by an install script.
        /// </summary>
        internal static void Init()
        {
            #if TRACE
            Trace.WriteLine("");
            Trace.WriteLine("Setting up File IO Permissions for: ");
            Trace.Indent();
            Trace.Write("     FOMM tmp Dir: ");
            Trace.WriteLine(Program.tmpPath);
            Trace.Write(" Install Info Dir: ");
            Trace.WriteLine(Program.GameMode.InstallInfoDirectory);
            Trace.Write("   System tmp Dir: ");
            Trace.WriteLine(Path.GetTempPath());
            Directory.GetAccessControl(Path.GetTempPath());
            Trace.WriteLine("   Settings Files: ");
            Trace.Indent();
            foreach (string strValue in Program.GameMode.SettingsFiles.Values)
                Trace.WriteLine(strValue);
            Trace.Unindent();
            Trace.WriteLine("      Other Paths: ");
            Trace.Indent();
            foreach (string strValue in Program.GameMode.AdditionalPaths.Values)
                Trace.WriteLine(strValue);
            Trace.Unindent();
            Trace.Unindent();
            Trace.Flush();
            #endif
            permissions = new PermissionSet(PermissionState.None);
            //do the following paths need to add to this?
            // savesPath - fallout 3
            FileIOPermission fipFilePermission = new FileIOPermission(FileIOPermissionAccess.AllAccess, new string[] {
                Program.tmpPath, Path.GetTempPath(),
                Program.GameMode.InstallInfoDirectory,
                Program.GameMode.PluginsPath
            });

            List<string> lstPaths = new List<string>(Program.GameMode.SettingsFiles.Values);
            lstPaths.AddRange(Program.GameMode.AdditionalPaths.Values);
            fipFilePermission.AddPathList(FileIOPermissionAccess.AllAccess, lstPaths.ToArray());
            fipFilePermission.AddPathList(FileIOPermissionAccess.Read, Environment.CurrentDirectory);

            permissions.AddPermission(fipFilePermission);
            permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));
            permissions.AddPermission(new UIPermission(UIPermissionWindow.AllWindows));
            #if TRACE
            Trace.Write("Demanding access to System tmp Dir...");
            try
            {
                permissions.Demand();
                Trace.WriteLine("Succeeded.");
            }
            catch (Exception e)
            {
                Trace.WriteLine("Failed:");
                Program.TraceException(e);
            }
            Trace.WriteLine("   System tmp Dir Permissions:");
            Trace.Indent();
            DirectorySecurity drsPermissions = Directory.GetAccessControl(Path.GetTempPath());
            Dictionary<string, List<FileSystemRights>> dicRights = new Dictionary<string, List<FileSystemRights>>();
            foreach (FileSystemAccessRule fsrRule in drsPermissions.GetAccessRules(true, true, typeof(NTAccount)))
            {
                if (!dicRights.ContainsKey(fsrRule.IdentityReference.Value))
                    dicRights[fsrRule.IdentityReference.Value] = new List<FileSystemRights>();
                dicRights[fsrRule.IdentityReference.Value].Add(fsrRule.FileSystemRights);
            }
            foreach (KeyValuePair<string, List<FileSystemRights>> kvpRight in dicRights)
            {
                Trace.WriteLine(kvpRight.Key + " =>");
                Trace.Indent();
                foreach (FileSystemRights fsrRight in kvpRight.Value)
                    Trace.WriteLine(fsrRight.ToString());
                Trace.Unindent();
            }
            Trace.Unindent();
            Trace.Write("Testing access to System tmp Dir...");
            try
            {
                File.WriteAllText(Path.Combine(Path.GetTempPath(), "testFile.txt"), "This is fun.");
                Trace.WriteLine("Passed: " + File.ReadAllText(Path.Combine(Path.GetTempPath(), "testFile.txt")));
                File.Delete(Path.Combine(Path.GetTempPath(), "testFile.txt"));
            }
            catch (Exception e)
            {
                Trace.WriteLine("Failed: ");
                Program.TraceException(e);
            }
            #endif
        }
开发者ID:BioBrainX,项目名称:fomm,代码行数:91,代码来源:PermissionsManager.cs

示例12: main

        /// <summary>
        /// The main.
        /// </summary>
        private void main()
        {
            Console.WriteLine("=======ClueBuddy=======");
            try {
                var savingPermissions = new PermissionSet(null);
                savingPermissions.AddPermission(new FileDialogPermission(FileDialogPermissionAccess.Save));
                savingPermissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.SerializationFormatter));
                savingPermissions.AddPermission(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess));

                // briefly demand these permissions to detect whether we'll succeed later
                savingPermissions.Demand();
            } catch (SecurityException) {
                ConsoleHelper.WriteColor(ConsoleColor.Red, "WARNING: insufficient permissions to save games.");
            }
            while (true) {
                try {
                    if (this.game != null && this.game.AreCluesConflicted) {
                        this.ResolveConflicts();
                    }

                    var mainMenu = new Dictionary<char, string>();
                    mainMenu.Add('L', "Load game");
                    mainMenu.Add('N', "New game");
                    if (this.game != null) {
                        mainMenu.Add('S', "Save game");
                        mainMenu.Add('T', "Play a Turn");
                        mainMenu.Add('G', "See Grid");
                        mainMenu.Add('C', "List Clues");
                        mainMenu.Add('F', "Force enter a clue");
                    }
                    mainMenu.Add('Q', "Quit");
                    switch (ConsoleHelper.Choose("Main menu:", mainMenu, s => s).Key) {
                        case 'L':
                            this.LoadGame();
                            break;
                        case 'N':
                            this.ChooseGame();
                            if (this.game == null) break;
                            this.SetupPlayers();
                            this.game.Start();
                            this.prepareNewOrLoadedGameState();
                            this.LearnOwnHand();
                            break;
                        case 'S':
                            this.SaveGame();
                            break;
                        case 'T':
                            this.TakeTurn();
                            break;
                        case 'F':
                            this.ForceClue();
                            break;
                        case 'G':
                            this.PrintGrid();
                            break;
                        case 'C':
                            this.ListClues();
                            break;
                        case 'Q':
                            return;
                    }
                } catch (SecurityException ex) {
                    Console.Error.WriteLine("Insufficient permissions: {0}.", ex.Demanded);
                } catch (Exception e) {
                    if (e is OutOfMemoryException || e is StackOverflowException) throw;
                    if (ConsoleHelper.Choose(string.Format("An {0} exception was thrown: {1}.{2}Do you want to try to continue the game?",
                        e.GetType().Name, e.Message, Environment.NewLine), false, new[] { "Yes", "No" }) == 1)
                        throw;
                }
            }
        }
开发者ID:AArnott,项目名称:ClueBuddy,代码行数:74,代码来源:Program.cs

示例13: PermissionSetDemo

		public static void PermissionSetDemo()
		{
			
			Console.WriteLine("Executing Permission Set Demo");
			try
			{
				// Open a permission set.
				PermissionSet ps1 = new PermissionSet(PermissionState.None);
				Console.WriteLine("Adding permission to open a file from a file dialog box.");
				// Add a permission to the permission set.
				ps1.AddPermission(new FileDialogPermission(FileDialogPermissionAccess.Open));
				Console.WriteLine("Demanding Permission to open a file.");
				ps1.Demand();
				Console.WriteLine("Demand succeeded.");
				Console.WriteLine("Adding permission to save a file from a file dialog box.");
				ps1.AddPermission(new FileDialogPermission(FileDialogPermissionAccess.Save));
				Console.WriteLine("Demanding permission to open and save a file.");
				ps1.Demand();
				Console.WriteLine("Demand succeeded.");
				Console.WriteLine("Adding a permission to read environment variable USERNAME.");
				ps1.AddPermission(new EnvironmentPermission(EnvironmentPermissionAccess.Read, "USERNAME"));
				ps1.Demand();
				Console.WriteLine("Demand succeeded.");
				Console.WriteLine("Adding permission to read environment variable COMPUTERNAME.");
				ps1.AddPermission(new EnvironmentPermission(EnvironmentPermissionAccess.Read, "COMPUTERNAME"));
				// Demand all the permissions in the set.
				Console.WriteLine("Demand all permissions.");
				ps1.Demand();
				Console.WriteLine("Demand succeeded.");
				// Display the number of permissions in the set.
				Console.WriteLine("Number of permissions = " + ps1.Count);
				// Display the value of the IsSynchronized property.
				Console.WriteLine("IsSynchronized property = " + ps1.IsSynchronized);
				// Display the value of the IsReadOnly property.
				Console.WriteLine("IsReadOnly property = " + ps1.IsReadOnly);
				// Display the value of the SyncRoot property.
				Console.WriteLine("SyncRoot property = " + ps1.SyncRoot);
				// Display the result of a call to the ContainsNonCodeAccessPermissions method.
				// Gets a value indicating whether the PermissionSet contains permissions
				// that are not derived from CodeAccessPermission.
				// Returns true if the PermissionSet contains permissions that are not 
				// derived from CodeAccessPermission; otherwise, false.
				Console.WriteLine("ContainsNonCodeAccessPermissions method returned " + ps1.ContainsNonCodeAccessPermissions());
				Console.WriteLine("Value of the permission set ToString = \n" + ps1.ToString());
				PermissionSet ps2 = new PermissionSet(PermissionState.None);
				// Create a second permission set and compare it to the first permission set.
				ps2.AddPermission(new EnvironmentPermission(EnvironmentPermissionAccess.Read, "USERNAME"));
				ps2.AddPermission(new EnvironmentPermission(EnvironmentPermissionAccess.Write, "COMPUTERNAME"));
				Console.WriteLine("Permission set 2 = " + ps2);
				IEnumerator list = ps1.GetEnumerator();
				Console.WriteLine("Permissions in first permission set:");
				foreach (var permission in ps1)
					Console.WriteLine(permission.ToString());
				Console.WriteLine("Second permission IsSubSetOf first permission = " + ps2.IsSubsetOf(ps1));
				// Display the intersection of two permission sets.
				PermissionSet ps3 = ps2.Intersect(ps1);
				Console.WriteLine("The intersection of the first permission set and the second permission set = " + ps3.ToString());
				// Create a new permission set.
				PermissionSet ps4 = new PermissionSet(PermissionState.None);
				ps4.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read, "C:\\Temp\\Testfile.txt"));
				ps4.AddPermission(new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Append, "C:\\Temp\\Testfile.txt"));
				// Display the union of two permission sets.
				PermissionSet ps5 = ps3.Union(ps4);
				Console.WriteLine("The union of permission set 3 and permission set 4 = " + ps5.ToString());
				// Remove FileIOPermission from the permission set.
				ps5.RemovePermission(typeof(FileIOPermission));
				Console.WriteLine("The last permission set after removing FileIOPermission = " + ps5.ToString());
				// Change the permission set using SetPermission
				ps5.SetPermission(new EnvironmentPermission(EnvironmentPermissionAccess.AllAccess, "USERNAME"));
				Console.WriteLine("Permission set after SetPermission = " + ps5.ToString());
				// Display result of ToXml and FromXml operations.
				PermissionSet ps6 = new PermissionSet(PermissionState.None);
				ps6.FromXml(ps5.ToXml());
				Console.WriteLine("Result of ToFromXml = " + ps6.ToString() + "\n");
				// Display result of PermissionSet.GetEnumerator.
				IEnumerator psEnumerator = ps1.GetEnumerator();
				while (psEnumerator.MoveNext())
				{
					Console.WriteLine(psEnumerator.Current.ToString());
				}
				// Check for an unrestricted permission set.
				PermissionSet ps7 = new PermissionSet(PermissionState.Unrestricted);
				Console.WriteLine("Permission set is unrestricted = " + ps7.IsUnrestricted());
				// Create and display a copy of a permission set.
				ps7 = ps5.Copy();
				Console.WriteLine("Result of copy = " + ps7.ToString());
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message.ToString());
			}
		}
开发者ID:oblivious,项目名称:Oblivious,代码行数:92,代码来源:Program.cs

示例14: Build

        public bool Build(X509Certificate2 certificate)
        {
            if (certificate == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("certificate");
            if (certificate.Handle == IntPtr.Zero)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("certificate", SR.GetString(SR.ArgumentInvalidCertificate));

            SafeCertChainHandle safeCertChainHandle = SafeCertChainHandle.InvalidHandle;
            X509ChainPolicy chainPolicy = this.ChainPolicy;
            chainPolicy.VerificationTime = DateTime.Now;
            if (chainPolicy.RevocationMode == X509RevocationMode.Online)
            {
                if (certificate.Extensions[CAPI.szOID_CRL_DIST_POINTS] != null ||
                    certificate.Extensions[CAPI.szOID_AUTHORITY_INFO_ACCESS] != null)
                {
                    // If there is a CDP or AIA extension, we demand unrestricted network access and store add permission
                    // since CAPI can download certificates into the CA store from the network.
                    PermissionSet ps = new PermissionSet(PermissionState.None);
                    ps.AddPermission(new WebPermission(PermissionState.Unrestricted));
                    ps.AddPermission(new StorePermission(StorePermissionFlags.AddToStore));
                    ps.Demand();
                }
            }

            BuildChain(this.useMachineContext ? new IntPtr(CAPI.HCCE_LOCAL_MACHINE) : new IntPtr(CAPI.HCCE_CURRENT_USER),
                    certificate.Handle,
                    chainPolicy.ExtraStore,
                    chainPolicy.ApplicationPolicy,
                    chainPolicy.CertificatePolicy,
                    chainPolicy.RevocationMode,
                    chainPolicy.RevocationFlag,
                    chainPolicy.VerificationTime,
                    chainPolicy.UrlRetrievalTimeout,
                    out safeCertChainHandle);

            // Verify the chain using the specified policy.
            CAPI.CERT_CHAIN_POLICY_PARA PolicyPara = new CAPI.CERT_CHAIN_POLICY_PARA(Marshal.SizeOf(typeof(CAPI.CERT_CHAIN_POLICY_PARA)));
            CAPI.CERT_CHAIN_POLICY_STATUS PolicyStatus = new CAPI.CERT_CHAIN_POLICY_STATUS(Marshal.SizeOf(typeof(CAPI.CERT_CHAIN_POLICY_STATUS)));

            // Ignore peertrust.  Peer trust caused the chain to succeed out-of-the-box in Vista.
            // This new flag is only available in Vista.
            PolicyPara.dwFlags = (uint)chainPolicy.VerificationFlags | CAPI.CERT_CHAIN_POLICY_IGNORE_PEER_TRUST_FLAG;

            if (!CAPI.CertVerifyCertificateChainPolicy(new IntPtr(this.chainPolicyOID),
                                                       safeCertChainHandle,
                                                       ref PolicyPara,
                                                       ref PolicyStatus))
            {
                int error = Marshal.GetLastWin32Error();
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(error));
            }

            if (PolicyStatus.dwError != CAPI.S_OK)
            {
                int error = (int)PolicyStatus.dwError;
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenValidationException(SR.GetString(SR.X509ChainBuildFail,
                    SecurityUtils.GetCertificateId(certificate), new CryptographicException(error).Message)));
            }

            return true;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:61,代码来源:X509CertificateChain.cs

示例15: GetServicePermission

 /// <summary>
 /// Gets the service control permission.
 /// </summary>
 /// <param name="svc">The SVC.</param>
 /// <returns></returns>
 /// <exception cref="System.Security.SecurityException">when the permission cannot be acquired</exception>
 private PermissionSet GetServicePermission(ManagedService svc)
 {
     MyLogger.Trace("Entering {0} for service: {1}", MethodBase.GetCurrentMethod().Name, svc.ConsulServiceName);
     // Creates a permission set that allows no access to the resource.
     PermissionSet ps = new PermissionSet(System.Security.Permissions.PermissionState.None);
     // Sets the security permission flag to use for this permission set.
     ps.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.Assertion));
     // Initializes a new instance of the System.ServiceProcess.ServiceControllerPermission class.
     ps.AddPermission(new ServiceControllerPermission(ServiceControllerPermissionAccess.Control, Environment.MachineName, svc.WindowsServiceName));
     ps.Demand();
     return ps;
 }
开发者ID:jango2015,项目名称:Orek,代码行数:18,代码来源:ServiceManagement.cs


注:本文中的System.Security.PermissionSet.Demand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。