private static ConfigNode OpenCryptoConfig()
        {
            string path = Config.MachineDirectory + "machine.config";

            new FileIOPermission(FileIOPermissionAccess.Read, path).Assert();
            if (File.Exists(path))
            {
                CodeAccessPermission.RevertAssert();
                ConfigNode node = new ConfigTreeParser().Parse(path, "configuration", true);
                if (node == null)
                {
                    return(null);
                }
                ConfigNode node2 = null;
                foreach (ConfigNode node3 in node.Children)
                {
                    bool flag = false;
                    if (string.Compare(node3.Name, "mscorlib", StringComparison.Ordinal) == 0)
                    {
                        foreach (DictionaryEntry entry in node3.Attributes)
                        {
                            if (string.Compare((string)entry.Key, "version", StringComparison.Ordinal) == 0)
                            {
                                flag = true;
                                if (string.Compare((string)entry.Value, Version, StringComparison.Ordinal) == 0)
                                {
                                    node2 = node3;
                                    break;
                                }
                            }
                        }
                        if (!flag)
                        {
                            node2 = node3;
                        }
                    }
                    if (node2 != null)
                    {
                        break;
                    }
                }
                if (node2 != null)
                {
                    foreach (ConfigNode node4 in node2.Children)
                    {
                        if (string.Compare(node4.Name, "cryptographySettings", StringComparison.Ordinal) == 0)
                        {
                            return(node4);
                        }
                    }
                }
            }
            return(null);
        }
Example #2
0
 private static ConfigNode OpenCryptoConfig()
 {
   string str = Config.MachineDirectory + "machine.config";
   new FileIOPermission(FileIOPermissionAccess.Read, str).Assert();
   if (!File.Exists(str))
     return (ConfigNode) null;
   CodeAccessPermission.RevertAssert();
   ConfigNode configNode1 = new ConfigTreeParser().Parse(str, "configuration", true);
   if (configNode1 == null)
     return (ConfigNode) null;
   ConfigNode configNode2 = (ConfigNode) null;
   foreach (ConfigNode child in configNode1.Children)
   {
     bool flag = false;
     if (string.Compare(child.Name, "mscorlib", StringComparison.Ordinal) == 0)
     {
       foreach (DictionaryEntry attribute in child.Attributes)
       {
         if (string.Compare((string) attribute.Key, "version", StringComparison.Ordinal) == 0)
         {
           flag = true;
           if (string.Compare((string) attribute.Value, CryptoConfig.Version, StringComparison.Ordinal) == 0)
           {
             configNode2 = child;
             break;
           }
         }
       }
       if (!flag)
         configNode2 = child;
     }
     if (configNode2 != null)
       break;
   }
   if (configNode2 == null)
     return (ConfigNode) null;
   foreach (ConfigNode child in configNode2.Children)
   {
     if (string.Compare(child.Name, "cryptographySettings", StringComparison.Ordinal) == 0)
       return child;
   }
   return (ConfigNode) null;
 }
        private Hashtable GetSatelliteAssembliesFromConfig()
        {
            string configurationFileInternal = AppDomain.CurrentDomain.FusionStore.ConfigurationFileInternal;

            if (configurationFileInternal == null)
            {
                return(null);
            }
            if (((configurationFileInternal.Length >= 2) && ((configurationFileInternal[1] == Path.VolumeSeparatorChar) || ((configurationFileInternal[0] == Path.DirectorySeparatorChar) && (configurationFileInternal[1] == Path.DirectorySeparatorChar)))) && !File.InternalExists(configurationFileInternal))
            {
                return(null);
            }
            ConfigTreeParser parser     = new ConfigTreeParser();
            string           configPath = "/configuration/satelliteassemblies";
            ConfigNode       node       = null;

            try
            {
                node = parser.Parse(configurationFileInternal, configPath, true);
            }
            catch (Exception)
            {
            }
            if (node == null)
            {
                return(null);
            }
            Hashtable hashtable = new Hashtable(StringComparer.OrdinalIgnoreCase);

            foreach (ConfigNode node2 in node.Children)
            {
                if (!string.Equals(node2.Name, "assembly"))
                {
                    throw new ApplicationException(Environment.GetResourceString("XMLSyntax_InvalidSyntaxSatAssemTag", new object[] { Path.GetFileName(configurationFileInternal), node2.Name }));
                }
                if (node2.Attributes.Count == 0)
                {
                    throw new ApplicationException(Environment.GetResourceString("XMLSyntax_InvalidSyntaxSatAssemTagNoAttr", new object[] { Path.GetFileName(configurationFileInternal) }));
                }
                DictionaryEntry entry = node2.Attributes[0];
                string          str3  = (string)entry.Value;
                if ((!object.Equals(entry.Key, "name") || string.IsNullOrEmpty(str3)) || (node2.Attributes.Count > 1))
                {
                    throw new ApplicationException(Environment.GetResourceString("XMLSyntax_InvalidSyntaxSatAssemTagBadAttr", new object[] { Path.GetFileName(configurationFileInternal), entry.Key, entry.Value }));
                }
                ArrayList list = new ArrayList(5);
                foreach (ConfigNode node3 in node2.Children)
                {
                    if (node3.Value != null)
                    {
                        list.Add(node3.Value);
                    }
                }
                string[] strArray = new string[list.Count];
                for (int i = 0; i < strArray.Length; i++)
                {
                    string cultureName = (string)list[i];
                    strArray[i] = cultureName;
                    if (FrameworkEventSource.IsInitialized)
                    {
                        FrameworkEventSource.Log.ResourceManagerAddingCultureFromConfigFile(this.BaseNameField, this.MainAssembly, cultureName);
                    }
                }
                hashtable.Add(str3, strArray);
            }
            return(hashtable);
        }
        private static void InitializeConfigInfo()
        {
            // set up the version string
            Type myType = typeof(CryptoConfig);

            _Version = myType.Assembly.GetVersion().ToString();
            if (defaultNameHT == null)
            {
                lock (lockType) {
                    if (defaultNameHT == null)
                    {
                        defaultNameHT = CreateDefaultMappingHT();
                    }
                }
            }
            if (defaultOidHT == null)
            {
                lock (lockType) {
                    if (defaultOidHT == null)
                    {
                        defaultOidHT = CreateDefaultOidHT();
                    }
                }
            }
            if (defaultCalgHT == null)
            {
                lock (lockType) {
                    if (defaultCalgHT == null)
                    {
                        defaultCalgHT = CreateDefaultCalgHT();
                    }
                }
            }

            if ((machineNameHT == null) && (machineOidHT == null))
            {
                lock (lockType) {
                    String machineConfigFile = machineConfigDir + machineConfigFilename;
                    if (File.Exists(machineConfigFile))
                    {
                        // we need to assert here the right to read the machineConfigFile, since
                        // the parser now checks for this right.
                        (new FileIOPermission(FileIOPermissionAccess.Read, machineConfigFile)).Assert();
                        ConfigTreeParser parser   = new ConfigTreeParser();
                        ConfigNode       rootNode = parser.Parse(machineConfigFile, "configuration");

                        if (rootNode == null)
                        {
                            goto endInitialization;
                        }
                        // now, find the mscorlib tag with our version
                        ArrayList  rootChildren = rootNode.Children;
                        ConfigNode mscorlibNode = null;
                        foreach (ConfigNode node in rootChildren)
                        {
                            if (node.Name.Equals("mscorlib"))
                            {
                                ArrayList attribs = node.Attributes;
                                if (attribs.Count > 0)
                                {
                                    DictionaryEntry attribute = (DictionaryEntry)node.Attributes[0];
                                    if (attribute.Key.Equals("version"))
                                    {
                                        if (attribute.Value.Equals(_Version))
                                        {
                                            mscorlibNode = node;
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    mscorlibNode = node;
                                }
                            }
                        }
                        if (mscorlibNode == null)
                        {
                            goto endInitialization;
                        }
                        // look for cryptosettings
                        ArrayList  mscorlibChildren = mscorlibNode.Children;
                        ConfigNode cryptoSettings   = null;
                        foreach (ConfigNode node in mscorlibChildren)
                        {
                            // take the first one that matches
                            if (node.Name.Equals("cryptographySettings"))
                            {
                                cryptoSettings = node;
                                break;
                            }
                        }
                        if (cryptoSettings == null)
                        {
                            goto endInitialization;
                        }
                        // See if there's a CryptoNameMapping section (at most one)
                        ConfigNode cryptoNameMapping = null;
                        foreach (ConfigNode node in cryptoSettings.Children)
                        {
                            if (node.Name.Equals("cryptoNameMapping"))
                            {
                                cryptoNameMapping = node;
                                break;
                            }
                        }
                        if (cryptoNameMapping == null)
                        {
                            goto initializeOIDMap;
                        }
                        // We have a name mapping section, so now we have to build up the type aliases
                        // in CryptoClass elements and the mappings.
                        ArrayList  cryptoNameMappingChildren = cryptoNameMapping.Children;
                        ConfigNode cryptoClasses             = null;
                        // find the cryptoClases element
                        foreach (ConfigNode node in cryptoNameMappingChildren)
                        {
                            if (node.Name.Equals("cryptoClasses"))
                            {
                                cryptoClasses = node;
                                break;
                            }
                        }
                        // if we didn't find it, no mappings
                        if (cryptoClasses == null)
                        {
                            goto initializeOIDMap;
                        }
                        Hashtable typeAliases  = new Hashtable();
                        Hashtable nameMappings = new Hashtable();
                        foreach (ConfigNode node in cryptoClasses.Children)
                        {
                            if (node.Name.Equals("cryptoClass"))
                            {
                                if (node.Attributes.Count > 0)
                                {
                                    DictionaryEntry attribute = (DictionaryEntry)node.Attributes[0];
                                    typeAliases.Add(attribute.Key, attribute.Value);
                                }
                            }
                        }
                        // Now process the name mappings
                        foreach (ConfigNode node in cryptoNameMappingChildren)
                        {
                            if (node.Name.Equals("nameEntry"))
                            {
                                String friendlyName = null;
                                String className    = null;
                                foreach (DictionaryEntry attribNode in node.Attributes)
                                {
                                    if (((String)attribNode.Key).Equals("name"))
                                    {
                                        friendlyName = (String)attribNode.Value;
                                        continue;
                                    }
                                    if (((String)attribNode.Key).Equals("class"))
                                    {
                                        className = (String)attribNode.Value;
                                        continue;
                                    }
                                }
                                if ((friendlyName != null) && (className != null))
                                {
                                    String typeName = (String)typeAliases[className];
                                    if (typeName != null)
                                    {
                                        nameMappings.Add(friendlyName, typeName);
                                    }
                                }
                            }
                        }
                        machineNameHT = nameMappings;
initializeOIDMap:
                        // Now, process the OID mappings
                        // See if there's an oidMap section (at most one)
                        ConfigNode oidMapNode = null;
                        foreach (ConfigNode node in cryptoSettings.Children)
                        {
                            if (node.Name.Equals("oidMap"))
                            {
                                oidMapNode = node;
                                break;
                            }
                        }
                        if (oidMapNode == null)
                        {
                            goto endInitialization;
                        }
                        Hashtable oidMapHT = new Hashtable();
                        foreach (ConfigNode node in oidMapNode.Children)
                        {
                            if (node.Name.Equals("oidEntry"))
                            {
                                String oidString    = null;
                                String friendlyName = null;
                                foreach (DictionaryEntry attribNode in node.Attributes)
                                {
                                    if (((String)attribNode.Key).Equals("OID"))
                                    {
                                        oidString = (String)attribNode.Value;
                                        continue;
                                    }
                                    if (((String)attribNode.Key).Equals("name"))
                                    {
                                        friendlyName = (String)attribNode.Value;
                                        continue;
                                    }
                                }
                                if ((friendlyName != null) && (oidString != null))
                                {
                                    oidMapHT.Add(friendlyName, oidString);
                                }
                            }
                        }
                        machineOidHT = oidMapHT;
                    }
                }
            }
endInitialization:
            isInitialized = true;
        }