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 static MonoSecurityMode mono_security_mode
= MONO_SECURITY_MODE_NONE
;
15 mono_security_set_mode (MonoSecurityMode mode
)
17 mono_security_mode
= mode
;
21 mono_security_get_mode (void)
23 return mono_security_mode
;
26 #ifndef DISABLE_SECURITY
28 static MonoSecurityManager secman
;
31 mono_security_manager_get_methods (void)
33 /* Already initialized ? */
34 if (secman
.securitymanager
)
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
);
50 mono_security_manager_get_methods (void)
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
68 mono_is_ecma_key (const char *publickey
, int size
)
71 if ((publickey
== NULL
) || (size
!= MONO_ECMA_KEY_LENGTH
) || (publickey
[8] != 0x04))
74 for (i
=0; i
< size
; i
++) {
75 if ((publickey
[i
] != 0x00) && (i
!= 8))
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.
90 mono_get_context_capture_method (void)
92 static MonoMethod
*method
= NULL
;
94 if (mono_image_get_assembly (mono_defaults
.corlib
)->aname
.major
< 2)
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);
107 /* System.Security icalls */
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
);
119 ves_icall_System_Security_SecurityManager_set_SecurityEnabled (MonoBoolean value
)