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 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.
32 #if NET_2_1 && !MONOTOUCH
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 internal static IPermission CheckPermissionSet (Assembly a, PermissionSet ps, bool noncas)
62 internal static IPermission CheckPermissionSet (AppDomain ad, PermissionSet ps)
67 internal static PermissionSet Decode (byte[] encodedPermissions)
72 internal static PermissionSet Decode (IntPtr permissions, int length)
77 public static bool IsGranted (IPermission perm)
82 public static PermissionSet ResolvePolicy (Evidence evidence)
87 public static PermissionSet ResolvePolicy (Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, out PermissionSet denied)
93 internal static bool ResolvePolicyLevel (ref PermissionSet ps, PolicyLevel pl, Evidence evidence)
98 internal static PolicyLevel ResolvingPolicyLevel {
102 internal static void ReflectedLinkDemandInvoke (MethodBase mb)
106 // called by the runtime when CoreCLR is enabled
108 private static void ThrowException (Exception ex)
113 // internal - get called by the class loader
116 // - class inheritance
117 // - method overrides
118 private unsafe static bool InheritanceDemand (AppDomain ad, Assembly a, RuntimeDeclSecurityActions *actions)
123 private static void InheritanceDemandSecurityException (int securityViolation, Assembly a, Type t, MethodInfo method)
127 // internal - get called at JIT time
129 private static void DemandUnmanaged ()
133 // internal - get called by JIT generated code
135 private static void InternalDemand (IntPtr permissions, int length)
139 private static void InternalDemandChoice (IntPtr permissions, int length)
143 private unsafe static bool LinkDemand (Assembly a, RuntimeDeclSecurityActions *klass, RuntimeDeclSecurityActions *method)
148 private static bool LinkDemandUnmanaged (Assembly a)
153 private static bool LinkDemandFullTrust (Assembly a)
158 private static void LinkDemandSecurityException (int securityViolation, IntPtr methodHandle)