2 // System.Security.SecurityManager.cs
5 // Nick Drochak(ndrochak@gol.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
9 // Portions (C) 2004 Motus Technologies Inc. (http://www.motus.com)
10 // Copyright (C) 2004-2005, 2009-2010 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Reflection;
35 using System.Runtime.CompilerServices;
36 using System.Runtime.InteropServices;
37 using System.Security.Policy;
39 namespace System.Security {
41 // Must match MonoDeclSecurityActions in /mono/metadata/reflection.h
42 internal struct RuntimeDeclSecurityActions {
43 public RuntimeDeclSecurityEntry cas;
44 public RuntimeDeclSecurityEntry noncas;
45 public RuntimeDeclSecurityEntry choice;
48 internal static class SecurityManager {
50 // note: this let us differentiate between running in the browser (w/CoreCLR) and
\r
51 // running on the desktop (e.g. smcs compiling stuff)
\r
52 extern public static bool SecurityEnabled {
53 [MethodImplAttribute (MethodImplOptions.InternalCall)]
57 public static bool HasElevatedPermissions {
61 internal static IPermission CheckPermissionSet (Assembly a, PermissionSet ps, bool noncas)
66 internal static IPermission CheckPermissionSet (AppDomain ad, PermissionSet ps)
71 internal static PermissionSet Decode (byte[] encodedPermissions)
76 internal static PermissionSet Decode (IntPtr permissions, int length)
81 public static bool IsGranted (IPermission perm)
86 public static PermissionSet ResolvePolicy (Evidence evidence)
91 public static PermissionSet ResolvePolicy (Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, out PermissionSet denied)
97 internal static bool ResolvePolicyLevel (ref PermissionSet ps, PolicyLevel pl, Evidence evidence)
102 internal static PolicyLevel ResolvingPolicyLevel {
106 internal static void ReflectedLinkDemandInvoke (MethodBase mb)
110 // called by the runtime when CoreCLR is enabled
112 private static void ThrowException (Exception ex)
117 // internal - get called by the class loader
120 // - class inheritance
121 // - method overrides
122 private unsafe static bool InheritanceDemand (AppDomain ad, Assembly a, RuntimeDeclSecurityActions *actions)
127 private static void InheritanceDemandSecurityException (int securityViolation, Assembly a, Type t, MethodInfo method)
131 // internal - get called at JIT time
133 private static void DemandUnmanaged ()
137 // internal - get called by JIT generated code
139 private static void InternalDemand (IntPtr permissions, int length)
143 private static void InternalDemandChoice (IntPtr permissions, int length)
147 private unsafe static bool LinkDemand (Assembly a, RuntimeDeclSecurityActions *klass, RuntimeDeclSecurityActions *method)
152 private static bool LinkDemandUnmanaged (Assembly a)
157 private static bool LinkDemandFullTrust (Assembly a)
162 private static void LinkDemandSecurityException (int securityViolation, IntPtr methodHandle)