2007-08-07 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Tue, 7 Aug 2007 11:19:34 +0000 (11:19 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Tue, 7 Aug 2007 11:19:34 +0000 (11:19 -0000)
* icall-def.h, security.c, security.h :
  added icall wrapper to ProtectedMemory.[Unprotect|Protect]Data().

svn path=/trunk/mono/; revision=83575

mono/metadata/ChangeLog
mono/metadata/icall-def.h
mono/metadata/security.c
mono/metadata/security.h

index 30fcd085223651b23607119794e77488afcdd0e7..28db00293dce661b2264d357b3d12d6f4834e1f8 100644 (file)
@@ -1,3 +1,8 @@
+2007-08-07  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * icall-def.h, security.c, security.h :
+         added icall wrapper to ProtectedMemory.[Unprotect|Protect]Data().
+
 2007-08-07  Martin Baulig  <martin@ximian.com>
 
        * mono-debug-debugger.h
index 6ee8ef90f10261d23d663bf405ac630093e7a6de..23632b38fffbe08b86fd92e89b456ed589421eb2 100644 (file)
@@ -660,6 +660,10 @@ ICALL_TYPE(WINPRIN, "System.Security.Principal.WindowsPrincipal", WINPRIN_1)
 ICALL(WINPRIN_1, "IsMemberOfGroupId", ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupId)
 ICALL(WINPRIN_2, "IsMemberOfGroupName", ves_icall_System_Security_Principal_WindowsPrincipal_IsMemberOfGroupName)
 
+ICALL_TYPE(SECSTRING, "System.Security.SecureString", SECSTRING_1)
+ICALL(SECSTRING_1, "DecryptInternal", ves_icall_System_Security_SecureString_DecryptInternal)
+ICALL(SECSTRING_2, "EncryptInternal", ves_icall_System_Security_SecureString_EncryptInternal)
+
 ICALL_TYPE(SECMAN, "System.Security.SecurityManager", SECMAN_1)
 ICALL(SECMAN_1, "GetLinkDemandSecurity", ves_icall_System_Security_SecurityManager_GetLinkDemandSecurity)
 ICALL(SECMAN_2, "get_CheckExecutionRights", ves_icall_System_Security_SecurityManager_get_CheckExecutionRights)
index 9004f38233b30d11d2b654ca6deafc412139ae95..debff3de88830170107c53c16385345ff9d625d2 100644 (file)
@@ -964,3 +964,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);
+}
index 82920d212bc4650956e5feb9f0d98475a4e8114e..2d145cf7b7275d7f50544cfc3c006ee758f59cab 100644 (file)
@@ -49,6 +49,11 @@ extern MonoBoolean ves_icall_Mono_Security_Cryptography_KeyPairPersistence_Prote
 /* System.Security.Policy.Evidence */
 MonoBoolean ves_icall_System_Security_Policy_Evidence_IsAuthenticodePresent (MonoReflectionAssembly *refass) MONO_INTERNAL;
 
+/* System.Security.SecureString */
+extern void ves_icall_System_Security_SecureString_DecryptInternal (MonoArray *data, MonoObject *scope) MONO_INTERNAL;
+extern void ves_icall_System_Security_SecureString_EncryptInternal (MonoArray *data, MonoObject *scope) MONO_INTERNAL;
+void invoke_protected_memory_method (MonoArray *data, MonoObject *scope, gboolean encrypt);
+
 G_END_DECLS
 
 #endif /* _MONO_METADATA_SECURITY_H_ */