2009-01-09 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / metadata / security.c
index 771eb548bab0550f96b39747a377c8646be47064..f621f319eb881c2b96bb52cc20bd50bf615e1e16 100644 (file)
@@ -11,6 +11,7 @@
 #include <config.h>
 #endif
 
+#include <mono/metadata/assembly.h>
 #include <mono/metadata/appdomain.h>
 #include <mono/metadata/image.h>
 #include <mono/metadata/exception.h>
@@ -427,7 +428,7 @@ ves_icall_System_Security_Principal_WindowsIdentity_GetRoles (gpointer token)
 
                                if (uniname) {
                                        MonoString *str = mono_string_new_utf16 (domain, uniname, size);
-                                       mono_array_set (array, MonoString *, i, str);
+                                       mono_array_setref (array, i, str);
                                        g_free (uniname);
                                }
                        }
@@ -964,3 +965,45 @@ ves_icall_System_Security_Policy_Evidence_IsAuthenticodePresent (MonoReflectionA
        }
        return FALSE;
 }
+
+
+/* System.Security.SecureString related internal calls */
+
+static MonoImage *system_security_assembly = NULL;
+
+void
+ves_icall_System_Security_SecureString_DecryptInternal (MonoArray *data, MonoObject *scope)
+{
+       invoke_protected_memory_method (data, scope, FALSE);
+}
+void
+ves_icall_System_Security_SecureString_EncryptInternal (MonoArray* data, MonoObject *scope)
+{
+       invoke_protected_memory_method (data, scope, TRUE);
+}
+
+void invoke_protected_memory_method (MonoArray *data, MonoObject *scope, gboolean encrypt)
+{
+       MonoClass *klass;
+       MonoMethod *method;
+       void *params [2];
+
+       MONO_ARCH_SAVE_REGS;
+
+       if (system_security_assembly == NULL) {
+               system_security_assembly = mono_image_loaded ("System.Security");
+               if (!system_security_assembly) {
+                       MonoAssembly *sa = mono_assembly_open ("System.Security.dll", NULL);
+                       if (!sa)
+                               g_assert_not_reached ();
+                       system_security_assembly = mono_assembly_get_image (sa);
+               }
+       }
+
+       klass = mono_class_from_name (system_security_assembly,
+                                                                 "System.Security.Cryptography", "ProtectedMemory");
+       method = mono_class_get_method_from_name (klass, encrypt ? "Protect" : "Unprotect", 2);
+       params [0] = data;
+       params [1] = scope; /* MemoryProtectionScope.SameProcess */
+       mono_runtime_invoke (method, NULL, params, NULL);
+}