argh
[mono.git] / mcs / tools / security / StrongNameManager.cs
old mode 100755 (executable)
new mode 100644 (file)
index 2ce553b..e47b6b8
@@ -9,6 +9,7 @@
 
 using System;
 using System.Collections;
+using System.Globalization;
 using System.IO;
 using System.Reflection;
 using System.Security;
@@ -20,16 +21,21 @@ using Mono.Xml;
 
 namespace Mono.Security {
 
-       /*
-        *      StrongNameManager.Verify
-        *              |
-        *              |                       yes
-        *      Assembly.GlobalAssemblyCache -----------\
-        *              |                               |
-        *              | no                            |
+       /* RUNTIME
+        *                              yes
+        *      in_gac ---------------------------------\
         *              |                               |
-        *              \/              not found       |
-        *              Token --------------------------|
+        *              | no                            \/
+        *              |                       return true
+        * CLASS LIBRARY|
+        *              |
+        *              |
+        *              |                               
+        *      bool StrongNameManager.MustVerify
+        *              |
+        *              |
+        *              \/              not found       
+        *              Token --------------------------\
         *              |                               |
         *              | present ?                     |
         *              |                               |
@@ -43,12 +49,9 @@ namespace Mono.Security {
         *              |                               |
         *              | present ?                     |
         *              | or "*"                        |
-        *              \/                              |
-        *      SKIP VERIFICATION               VERIFY ASSEMBLY
-        *              |                               |
-        *              |                               |
         *              \/                              \/
-        *      return true                     return StrongName.Verify()
+        *      return false                    return true
+        *      SKIP VERIFICATION               VERIFY ASSEMBLY
         */
 
        internal class StrongNameManager {
@@ -90,15 +93,18 @@ namespace Mono.Security {
                                        sp.LoadXml (xml);
                                }
                                SecurityElement root = sp.ToXml ();
-                               if ((root != null) && (root.Tag == "strongNames")) {
-                                       SecurityElement mapping  = root.SearchForChildByTag ("pubTokenMapping");
-                                       if ((mapping != null) && (mapping.Children.Count > 0)) {
-                                               LoadMapping (mapping);
-                                       }
-
-                                       SecurityElement settings = root.SearchForChildByTag ("verificationSettings");
-                                       if ((settings != null) && (settings.Children.Count > 0)) {
-                                               LoadVerificationSettings (settings);
+                               if ((root != null) && (root.Tag == "configuration")) {
+                                       SecurityElement strongnames  = root.SearchForChildByTag ("strongNames");
+                                       if ((strongnames != null) && (strongnames.Children.Count > 0)) {
+                                               SecurityElement mapping  = strongnames.SearchForChildByTag ("pubTokenMapping");
+                                               if ((mapping != null) && (mapping.Children.Count > 0)) {
+                                                       LoadMapping (mapping);
+                                               }
+
+                                               SecurityElement settings = strongnames.SearchForChildByTag ("verificationSettings");
+                                               if ((settings != null) && (settings.Children.Count > 0)) {
+                                                       LoadVerificationSettings (settings);
+                                               }
                                        }
                                }
                        }
@@ -118,6 +124,7 @@ namespace Mono.Security {
                                        string token = item.Attribute ("Token");
                                        if ((token == null) || (token.Length != 16))
                                                continue; // invalid entry
+                                       token = token.ToUpper (CultureInfo.InvariantCulture);
 
                                        string publicKey = item.Attribute ("PublicKey");
                                        if (publicKey == null)
@@ -149,6 +156,7 @@ namespace Mono.Security {
                                        string token = item.Attribute ("Token");
                                        if (token == null)
                                                continue;       // bad entry
+                                       token = token.ToUpper (CultureInfo.InvariantCulture);
 
                                        string assembly = item.Attribute ("Assembly");
                                        if (assembly == null)
@@ -212,10 +220,16 @@ namespace Mono.Security {
                                return true;
 
                        string token = CryptoConvert.ToHex (an.GetPublicKeyToken ());
-                       
                        Element el = (Element) tokens [token];
                        if (el != null) {
+                               // look for this specific assembly first
                                string users = el.GetUsers (an.Name);
+                               if (users == null) {
+                                       // nothing for the specific assembly
+                                       // so look for "*" assembly
+                                       users = el.GetUsers ("*");
+                               }
+
                                if (users != null) {
                                        // applicable to any user ?
                                        if (users == "*")
@@ -234,6 +248,11 @@ namespace Mono.Security {
                        StringBuilder sb = new StringBuilder ();
                        sb.Append ("Public Key Token\tAssemblies\t\tUsers");
                        sb.Append (Environment.NewLine);
+                       if (tokens == null) {
+                               sb.Append ("none");
+                               return sb.ToString ();
+                       }
+
                        foreach (DictionaryEntry token in tokens) {
                                sb.Append ((string)token.Key);
                                Element t = (Element) token.Value;