2 * security-manager.c: Security Manager (Unmanaged side)
5 * Sebastien Pouliot <sebastien@ximian.com>
7 * Copyright 2005-2009 Novell, Inc (http://www.novell.com)
10 #include "security-manager.h"
12 /* Class lazy loading functions */
13 static GENERATE_GET_CLASS_WITH_CACHE (security_manager, System.Security, SecurityManager)
15 static MonoSecurityMode mono_security_mode = MONO_SECURITY_MODE_NONE;
18 mono_security_set_mode (MonoSecurityMode mode)
20 mono_security_mode = mode;
24 mono_security_get_mode (void)
26 return mono_security_mode;
29 #ifndef DISABLE_SECURITY
31 static MonoSecurityManager secman;
34 mono_security_manager_get_methods (void)
36 /* Already initialized ? */
37 if (secman.securitymanager)
41 secman.securitymanager = mono_class_get_security_manager_class ();
42 if (!secman.securitymanager->inited)
43 mono_class_init (secman.securitymanager);
51 mono_security_manager_get_methods (void)
56 #endif /* DISABLE_SECURITY */
59 * @publickey An encoded (with header) public key
60 * @size The length of the public key
62 * returns TRUE if the public key is the ECMA "key", FALSE otherwise
64 * ECMA key isn't a real public key - it's simply an empty (but valid) header
65 * so it's length (16) and value (00000000000000000400000000000000) are
69 mono_is_ecma_key (const char *publickey, int size)
72 if ((publickey == NULL) || (size != MONO_ECMA_KEY_LENGTH) || (publickey [8] != 0x04))
75 for (i=0; i < size; i++) {
76 if ((publickey [i] != 0x00) && (i != 8))
83 * Context propagation is required when:
84 * (a) the security manager is active (1.x and later)
85 * (b) other contexts needs to be propagated (2.x and later)
87 * returns NULL if no context propagation is required, else the returns the
88 * MonoMethod to call to Capture the ExecutionContext.
91 mono_get_context_capture_method (void)
93 static MonoMethod *method = NULL;
95 if (mono_image_get_assembly (mono_defaults.corlib)->aname.major < 2)
98 /* older corlib revisions won't have the class (nor the method) */
99 if (mono_defaults.executioncontext_class && !method) {
100 mono_class_init (mono_defaults.executioncontext_class);
101 method = mono_class_get_method_from_name (mono_defaults.executioncontext_class, "Capture", 0);
108 /* System.Security icalls */
111 ves_icall_System_Security_SecurityManager_get_SecurityEnabled (void)
113 /* SecurityManager is internal for Moonlight and SecurityEnabled is used to know if CoreCLR is active
114 * (e.g. plugin executing in the browser) or not (e.g. smcs compiling source code with corlib 2.1)
116 return (mono_security_get_mode () == MONO_SECURITY_MODE_CORE_CLR);
120 ves_icall_System_Security_SecurityManager_set_SecurityEnabled (MonoBoolean value)