Merge pull request #2202 from mono/revert-2090-mono-4.2.0-branch-bug25480
[mono-project.git] / mono / metadata / security-manager.c
blob967cf6fd32068ad7a4b1b90c645deb811cb8a049
1 /*
2 * security-manager.c: Security Manager (Unmanaged side)
4 * Author:
5 * Sebastien Pouliot <sebastien@ximian.com>
7 * Copyright 2005-2009 Novell, Inc (http://www.novell.com)
8 */
10 #include "security-manager.h"
12 static MonoSecurityMode mono_security_mode = MONO_SECURITY_MODE_NONE;
14 void
15 mono_security_set_mode (MonoSecurityMode mode)
17 mono_security_mode = mode;
20 MonoSecurityMode
21 mono_security_get_mode (void)
23 return mono_security_mode;
26 #ifndef DISABLE_SECURITY
28 static MonoSecurityManager secman;
30 MonoSecurityManager*
31 mono_security_manager_get_methods (void)
33 /* Already initialized ? */
34 if (secman.securitymanager)
35 return &secman;
37 /* Initialize */
38 secman.securitymanager = mono_class_from_name (mono_defaults.corlib,
39 "System.Security", "SecurityManager");
40 g_assert (secman.securitymanager);
41 if (!secman.securitymanager->inited)
42 mono_class_init (secman.securitymanager);
44 return &secman;
47 #else
49 MonoSecurityManager*
50 mono_security_manager_get_methods (void)
52 return NULL;
55 #endif /* DISABLE_SECURITY */
58 * @publickey An encoded (with header) public key
59 * @size The length of the public key
61 * returns TRUE if the public key is the ECMA "key", FALSE otherwise
63 * ECMA key isn't a real public key - it's simply an empty (but valid) header
64 * so it's length (16) and value (00000000000000000400000000000000) are
65 * constants.
67 gboolean
68 mono_is_ecma_key (const char *publickey, int size)
70 int i;
71 if ((publickey == NULL) || (size != MONO_ECMA_KEY_LENGTH) || (publickey [8] != 0x04))
72 return FALSE;
74 for (i=0; i < size; i++) {
75 if ((publickey [i] != 0x00) && (i != 8))
76 return FALSE;
78 return TRUE;
82 * Context propagation is required when:
83 * (a) the security manager is active (1.x and later)
84 * (b) other contexts needs to be propagated (2.x and later)
86 * returns NULL if no context propagation is required, else the returns the
87 * MonoMethod to call to Capture the ExecutionContext.
89 MonoMethod*
90 mono_get_context_capture_method (void)
92 static MonoMethod *method = NULL;
94 if (mono_image_get_assembly (mono_defaults.corlib)->aname.major < 2)
95 return NULL;
97 /* older corlib revisions won't have the class (nor the method) */
98 if (mono_defaults.executioncontext_class && !method) {
99 mono_class_init (mono_defaults.executioncontext_class);
100 method = mono_class_get_method_from_name (mono_defaults.executioncontext_class, "Capture", 0);
103 return method;
107 /* System.Security icalls */
109 MonoBoolean
110 ves_icall_System_Security_SecurityManager_get_SecurityEnabled (void)
112 /* SecurityManager is internal for Moonlight and SecurityEnabled is used to know if CoreCLR is active
113 * (e.g. plugin executing in the browser) or not (e.g. smcs compiling source code with corlib 2.1)
115 return (mono_security_get_mode () == MONO_SECURITY_MODE_CORE_CLR);
118 void
119 ves_icall_System_Security_SecurityManager_set_SecurityEnabled (MonoBoolean value)