2005-11-07 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Mon, 7 Nov 2005 19:08:52 +0000 (19:08 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Mon, 7 Nov 2005 19:08:52 +0000 (19:08 -0000)
* security-manager.h: Added definitions to deal with strongname key
pairs bigger (and smaller) than 1024 bits.
* reflection.c: Remove hardcoded strongname size (128 bytes) and
adjust wrt the public key length being used.

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

mono/metadata/ChangeLog
mono/metadata/reflection.c
mono/metadata/security-manager.h

index c4678f92a397a7dc79e09f398ce6c33a46bd2ea1..36b127765ceb2daa4cd809e3955bc1b6d4464921 100644 (file)
@@ -1,3 +1,10 @@
+2005-11-07  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * security-manager.h: Added definitions to deal with strongname key 
+       pairs bigger (and smaller) than 1024 bits.
+       * reflection.c: Remove hardcoded strongname size (128 bytes) and 
+       adjust wrt the public key length being used.
+
 2005-11-03  Atsushi Enomoto  <atsushi@ximian.com>
 
        * marshal.c, icall.c : reverted sig->pinvoke changes which broke
index f274d95b365babd9164609b6b66788a429421ee6..0a50f403bc8bd6d50e409a119db0d1b121a362fc 100644 (file)
@@ -20,6 +20,7 @@
 #include "mono/metadata/object-internals.h"
 #include <mono/metadata/exception.h>
 #include <mono/metadata/marshal.h>
+#include <mono/metadata/security-manager.h>
 #include <stdio.h>
 #include <glib.h>
 #include <errno.h>
@@ -3782,8 +3783,18 @@ load_public_key (MonoArray *pkey, MonoDynamicImage *assembly) {
        token = mono_image_add_stream_data (&assembly->blob, blob_size, b - blob_size);
        mono_image_add_stream_data (&assembly->blob, mono_array_addr (pkey, guint8, 0), len);
 
-       /* need to get the actual value from the key type... */
-       assembly->strong_name_size = 128;
+       /* Special case: check for ECMA key (16 bytes) */
+       if ((len == MONO_ECMA_KEY_LENGTH) && mono_is_ecma_key (mono_array_addr (pkey, guint8, 0), len)) {
+               /* In this case we must reserve 128 bytes (1024 bits) for the signature */
+               assembly->strong_name_size = MONO_DEFAULT_PUBLIC_KEY_LENGTH;
+       } else if (len >= MONO_PUBLIC_KEY_HEADER_LENGTH + MONO_MINIMUM_PUBLIC_KEY_LENGTH) {
+               /* minimum key size (in 2.0) is 384 bits */
+               assembly->strong_name_size = len - MONO_PUBLIC_KEY_HEADER_LENGTH;
+       } else {
+               /* FIXME - verifier */
+               g_warning ("Invalid public key length: %d bits (total: %d)", MONO_PUBLIC_KEY_BIT_SIZE (len), len);
+               assembly->strong_name_size = MONO_DEFAULT_PUBLIC_KEY_LENGTH; /* to be safe */
+       }
        assembly->strong_name = g_malloc0 (assembly->strong_name_size);
 
        return token;
index c2e32acf6892e1bd668db27ee08a26dc16dcaf8d..7fc070069bae2c83c7599d2668074f71ee9149d0 100644 (file)
 /* Definitions */
 
 #define MONO_ECMA_KEY_LENGTH                   16
+#define MONO_PUBLIC_KEY_HEADER_LENGTH          32
+#define MONO_MINIMUM_PUBLIC_KEY_LENGTH         48
+#define MONO_DEFAULT_PUBLIC_KEY_LENGTH         128
+
+#define MONO_PUBLIC_KEY_BIT_SIZE(x)            ((x - MONO_PUBLIC_KEY_HEADER_LENGTH) << 3)
 
 enum {
        MONO_METADATA_SECURITY_OK               = 0x00,