Changeset 582


Ignore:
Timestamp:
11/19/08 00:58:20 (6 years ago)
Author:
lowjoel
Message:

-Added the attribute for a Core plugin, which will only be checked for if the assembly is signed by the same signature used for the Manager assembly. Core plugins cannot be disabled (hence Core)
-Plugins can now be disabled, and unsigned plugins are not loaded by default (users must enable it in settings)

Location:
branches/eraser6
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/DefaultPlugins/Properties/AssemblyInfo.cs

    r568 r582  
    3232// You can specify all the values or you can default the Revision and Build Numbers  
    3333// by using the '*' as shown below: 
    34 [assembly: AssemblyVersion("1.0.0.0")] 
    35 [assembly: AssemblyFileVersion("1.0.0.0")] 
     34[assembly: AssemblyVersion("6.0.0.1")] 
     35[assembly: AssemblyFileVersion("6.0.0.1")] 
     36 
     37// The plugin is a Core Eraser plugin, declare it so. 
     38[assembly: Eraser.Manager.Plugin.Core] 
  • branches/eraser6/Eraser/SettingsPanel.Designer.cs

    r569 r582  
    213213            this.pluginsManager.ContextMenuStrip = this.pluginsMenu; 
    214214            this.pluginsManager.FullRowSelect = true; 
     215            this.pluginsManager.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] { 
     216            ((System.Windows.Forms.ListViewGroup)(resources.GetObject("pluginsManager.Groups"))), 
     217            ((System.Windows.Forms.ListViewGroup)(resources.GetObject("pluginsManager.Groups1")))}); 
    215218            this.errorProvider.SetIconAlignment(this.pluginsManager, ((System.Windows.Forms.ErrorIconAlignment)(resources.GetObject("pluginsManager.IconAlignment")))); 
    216219            this.pluginsManager.Name = "pluginsManager"; 
    217220            this.pluginsManager.UseCompatibleStateImageBehavior = false; 
    218221            this.pluginsManager.View = System.Windows.Forms.View.Details; 
     222            this.pluginsManager.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.pluginsManager_ItemCheck); 
    219223            //  
    220224            // pluginsManagerColName 
  • branches/eraser6/Eraser/SettingsPanel.cs

    r581 r582  
    7272 
    7373            item.Checked = instance.Plugin != null || 
    74                 Manager.ManagerLibrary.Instance.Settings.ApprovedPlugins.IndexOf( 
    75                     instance.AssemblyInfo.GUID) != -1; 
     74                (Manager.ManagerLibrary.Instance.Settings.PluginApprovals.ContainsKey( 
     75                    instance.AssemblyInfo.GUID) && Manager.ManagerLibrary.Instance. 
     76                    Settings.PluginApprovals[instance.AssemblyInfo.GUID] 
     77                ); 
     78 
     79            item.Group = instance.IsCore ? pluginsManager.Groups[0] : 
     80                pluginsManager.Groups[1]; 
    7681            item.SubItems.Add(instance.Assembly.GetName().Version.ToString()); 
    7782            item.SubItems.Add(instance.Assembly.Location); 
     
    233238                foreach (string item in defaultsList) 
    234239                    defaults += "\t" + item + "\n"; 
    235                 MessageBox.Show(S._("The following settings held invalid values:\n\n" + 
     240                MessageBox.Show(this, S._("The following settings held invalid values:\n\n" + 
    236241                    "{0}\nThese settings have now been set to naive defaults.\n\n" + 
    237242                    "Please check that the new settings suit your required level of security.", 
     
    298303        } 
    299304 
     305        private void pluginsManager_ItemCheck(object sender, ItemCheckEventArgs e) 
     306        { 
     307            ListViewItem item = pluginsManager.Items[e.Index]; 
     308            PluginInstance instance = (PluginInstance)item.Tag; 
     309            if (instance.IsCore) 
     310                e.NewValue = CheckState.Checked; 
     311        } 
     312 
    300313        private void pluginsMenu_Opening(object sender, CancelEventArgs e) 
    301314        { 
     
    328341            managerSettings.ExecuteMissedTasksImmediately = schedulerMissedImmediate.Checked; 
    329342 
    330             List<Guid> approvedPlugins = managerSettings.ApprovedPlugins; 
     343            bool pluginApprovalsChanged = false; 
     344            Dictionary<Guid, bool> pluginApprovals = managerSettings.PluginApprovals; 
    331345            foreach (ListViewItem item in pluginsManager.Items) 
    332346            { 
    333347                PluginInstance plugin = (PluginInstance)item.Tag; 
    334                 if (item.Checked) 
    335                 { 
    336                     if (approvedPlugins.IndexOf(plugin.AssemblyInfo.GUID) == -1) 
    337                         approvedPlugins.Add(plugin.AssemblyInfo.GUID); 
    338                 } 
    339                 else 
    340                     approvedPlugins.Remove(plugin.AssemblyInfo.GUID); 
    341             } 
    342             managerSettings.ApprovedPlugins = approvedPlugins; 
     348                Guid guid = plugin.AssemblyInfo.GUID; 
     349                if (!pluginApprovals.ContainsKey(guid)) 
     350                { 
     351                    pluginApprovals.Add(guid, item.Checked); 
     352                    pluginApprovalsChanged = true; 
     353                } 
     354                else if (pluginApprovals[guid] != item.Checked) 
     355                { 
     356                    pluginApprovals[guid] = item.Checked; 
     357                    pluginApprovalsChanged = true; 
     358                } 
     359            } 
     360            managerSettings.PluginApprovals = pluginApprovals; 
     361            if (pluginApprovalsChanged) 
     362            { 
     363                MessageBox.Show(this, S._("Plugins which have just be approved will only be loaded " + 
     364                    "the next time Eraser is started."), S._("Eraser"), MessageBoxButtons.OK, 
     365                    MessageBoxIcon.Information); 
     366            } 
    343367 
    344368            //Error checks for the rest that do. 
     
    378402            { 
    379403                settings.Language = ((Language)uiLanguage.SelectedItem).Name; 
    380                 MessageBox.Show(S._("The new UI language will take only effect when Eraser is restarted."), 
    381                     S._("Eraser"), MessageBoxButtons.OK, MessageBoxIcon.Information); 
     404                MessageBox.Show(this, S._("The new UI language will take only effect when " + 
     405                    "Eraser is restarted."), S._("Eraser"), MessageBoxButtons.OK, 
     406                    MessageBoxIcon.Information); 
    382407            } 
    383408            managerSettings.DefaultFileErasureMethod = 
     
    389414            if (newPRNG.GUID != managerSettings.ActivePRNG) 
    390415            { 
    391                 MessageBox.Show(S._("The new randomness data source will only be used when " + 
     416                MessageBox.Show(this, S._("The new randomness data source will only be used when " + 
    392417                    "the next task is run.\nCurrently running tasks will use the old source."), 
    393418                    S._("Eraser"), MessageBoxButtons.OK, MessageBoxIcon.Information); 
  • branches/eraser6/Eraser/SettingsPanel.resx

    r498 r582  
    215215  </data> 
    216216  <data name="&gt;&gt;$this.Type" xml:space="preserve"> 
    217     <value>Eraser.BasePanel, Eraser, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null</value> 
     217    <value>Eraser.BasePanel, Eraser, Version=6.0.0.1, Culture=neutral, PublicKeyToken=3ecfb0f1525474f0</value> 
    218218  </data> 
    219219  <data name="titleIcon.IconAlignment" type="System.Windows.Forms.ErrorIconAlignment, System.Windows.Forms"> 
     
    605605  </data> 
    606606  <data name="&gt;&gt;scheduler.Type" xml:space="preserve"> 
    607     <value>Eraser.LightGroup, Eraser, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null</value> 
     607    <value>Eraser.LightGroup, Eraser, Version=6.0.0.1, Culture=neutral, PublicKeyToken=3ecfb0f1525474f0</value> 
    608608  </data> 
    609609  <data name="&gt;&gt;scheduler.Parent" xml:space="preserve"> 
     
    661661    <value>System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> 
    662662  </data> 
     663  <data name="pluginsManager.Groups" mimetype="application/x-microsoft.net.object.binary.base64"> 
     664    <value> 
     665        AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w 
     666        LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACJTeXN0 
     667        ZW0uV2luZG93cy5Gb3Jtcy5MaXN0Vmlld0dyb3VwBAAAAAZIZWFkZXIPSGVhZGVyQWxpZ25tZW50A1Rh 
     668        ZwROYW1lAQQCAShTeXN0ZW0uV2luZG93cy5Gb3Jtcy5Ib3Jpem9udGFsQWxpZ25tZW50AgAAAAIAAAAG 
     669        AwAAAAxDb3JlIHBsdWdpbnMF/P///yhTeXN0ZW0uV2luZG93cy5Gb3Jtcy5Ib3Jpem9udGFsQWxpZ25t 
     670        ZW50AQAAAAd2YWx1ZV9fAAgCAAAAAAAAAAoGBQAAABVwbHVnaW5zTWFuYWdlckdycENvcmUL 
     671</value> 
     672  </data> 
     673  <data name="pluginsManager.Groups1" mimetype="application/x-microsoft.net.object.binary.base64"> 
     674    <value> 
     675        AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w 
     676        LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACJTeXN0 
     677        ZW0uV2luZG93cy5Gb3Jtcy5MaXN0Vmlld0dyb3VwBAAAAAZIZWFkZXIPSGVhZGVyQWxpZ25tZW50A1Rh 
     678        ZwROYW1lAQQCAShTeXN0ZW0uV2luZG93cy5Gb3Jtcy5Ib3Jpem9udGFsQWxpZ25tZW50AgAAAAIAAAAG 
     679        AwAAAA1PdGhlciBwbHVnaW5zBfz///8oU3lzdGVtLldpbmRvd3MuRm9ybXMuSG9yaXpvbnRhbEFsaWdu 
     680        bWVudAEAAAAHdmFsdWVfXwAIAgAAAAAAAAAKBgUAAAAZcGx1Z2luc01hbmFnZXJHcnBFeHRlcm5hbAs= 
     681</value> 
     682  </data> 
    663683  <data name="pluginsManager.IconAlignment" type="System.Windows.Forms.ErrorIconAlignment, System.Windows.Forms"> 
    664684    <value>TopLeft</value> 
     
    713733  </data> 
    714734  <data name="&gt;&gt;plugins.Type" xml:space="preserve"> 
    715     <value>Eraser.LightGroup, Eraser, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null</value> 
     735    <value>Eraser.LightGroup, Eraser, Version=6.0.0.1, Culture=neutral, PublicKeyToken=3ecfb0f1525474f0</value> 
    716736  </data> 
    717737  <data name="&gt;&gt;plugins.Parent" xml:space="preserve"> 
     
    857877  </data> 
    858878  <data name="&gt;&gt;erase.Type" xml:space="preserve"> 
    859     <value>Eraser.LightGroup, Eraser, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null</value> 
     879    <value>Eraser.LightGroup, Eraser, Version=6.0.0.1, Culture=neutral, PublicKeyToken=3ecfb0f1525474f0</value> 
    860880  </data> 
    861881  <data name="&gt;&gt;erase.Parent" xml:space="preserve"> 
     
    9831003  </data> 
    9841004  <data name="&gt;&gt;ui.Type" xml:space="preserve"> 
    985     <value>Eraser.LightGroup, Eraser, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null</value> 
     1005    <value>Eraser.LightGroup, Eraser, Version=6.0.0.1, Culture=neutral, PublicKeyToken=3ecfb0f1525474f0</value> 
    9861006  </data> 
    9871007  <data name="&gt;&gt;ui.Parent" xml:space="preserve"> 
  • branches/eraser6/Eraser/Strings.NL.resx

    r561 r582  
    148148    <value>Kan geen taak lijst vinden. Alle taken zijn verdwenen.</value> 
    149149  </data> 
    150   <data name="Could not load the setting {0} for plugin {1}.The setting has been lost." xml:space="preserve"> 
     150  <data name="Could not load the setting {0} for plugin {1}. The setting has been lost." xml:space="preserve"> 
    151151    <value>(Untranslated)</value> 
    152152  </data> 
     
    205205    <value>De volgende instellingen had ongeldige waarden:\n\n{0}\nDeze instellingen zijn omgezet naar lege standaards.\nKijk goed na of de nieuwe instelling u bevalt met de benodigde beveiliging niveau.</value> 
    206206  </data> 
     207  <data name="Plugins which have just be approved will only be loaded the next time Eraser is started." xml:space="preserve"> 
     208    <value>(Untranslated)</value> 
     209  </data> 
    207210  <data name="An invalid language was selected." xml:space="preserve"> 
    208211    <value>Een foutieve taal was geselecteerd.</value> 
  • branches/eraser6/Eraser/Strings.en.resx

    r561 r582  
    148148    <value>Could not load task list. All task entries have been lost.</value> 
    149149  </data> 
    150   <data name="Could not load the setting {0} for plugin {1}.The setting has been lost." xml:space="preserve"> 
    151     <value>Could not load the setting {0} for plugin {1}.The setting has been lost.</value> 
     150  <data name="Could not load the setting {0} for plugin {1}. The setting has been lost." xml:space="preserve"> 
     151    <value>Could not load the setting {0} for plugin {1}. The setting has been lost.</value> 
    152152  </data> 
    153153  <data name="{0} out of {1}" xml:space="preserve"> 
     
    205205    <value>The following settings held invalid values:\n\n{0}\nThese settings have now been set to naive defaults.\n\nPlease check that the new settings suit your required level of security.</value> 
    206206  </data> 
     207  <data name="Plugins which have just be approved will only be loaded the next time Eraser is started." xml:space="preserve"> 
     208    <value>Plugins which have just be approved will only be loaded the next time Eraser is started.</value> 
     209  </data> 
    207210  <data name="An invalid language was selected." xml:space="preserve"> 
    208211    <value>An invalid language was selected.</value> 
  • branches/eraser6/Eraser/Strings.resx

    r561 r582  
    148148    <value>Could not load task list. All task entries have been lost.</value> 
    149149  </data> 
    150   <data name="Could not load the setting {0} for plugin {1}.The setting has been lost." xml:space="preserve"> 
    151     <value>Could not load the setting {0} for plugin {1}.The setting has been lost.</value> 
     150  <data name="Could not load the setting {0} for plugin {1}. The setting has been lost." xml:space="preserve"> 
     151    <value>Could not load the setting {0} for plugin {1}. The setting has been lost.</value> 
    152152  </data> 
    153153  <data name="{0} out of {1}" xml:space="preserve"> 
     
    205205    <value>The following settings held invalid values:\n\n{0}\nThese settings have now been set to naive defaults.\n\nPlease check that the new settings suit your required level of security.</value> 
    206206  </data> 
     207  <data name="Plugins which have just be approved will only be loaded the next time Eraser is started." xml:space="preserve"> 
     208    <value>Plugins which have just be approved will only be loaded the next time Eraser is started.</value> 
     209  </data> 
    207210  <data name="An invalid language was selected." xml:space="preserve"> 
    208211    <value>An invalid language was selected.</value> 
  • branches/eraser6/Manager/Plugins.cs

    r571 r582  
    2727using System.Windows.Forms; 
    2828using System.Runtime.InteropServices; 
     29using Eraser.Util; 
    2930 
    3031namespace Eraser.Manager.Plugin 
     
    178179                plugins.Add(instance); 
    179180 
    180             //First check the plugin for the presence of a signature. 
    181             if (reflectAssembly.GetName().GetPublicKey().Length == 0) 
    182             { 
    183                 //If the user did not allow the plug-in to load, don't load it. 
    184                 if (ManagerLibrary.Instance.Settings.ApprovedPlugins. 
    185                     IndexOf(instance.AssemblyInfo.GUID) == -1) 
    186                 { 
    187                     return; 
    188                 } 
     181            //The plugin was not disabled or it was loaded for the first time. Check 
     182            //the plugin for the presence of a valid signature. 
     183            Dictionary<Guid, bool> approvals = ManagerLibrary.Instance.Settings.PluginApprovals; 
     184            if ((reflectAssembly.GetName().GetPublicKey().Length == 0 || 
     185                !MsCorEEAPI.VerifyStrongName(filePath)) && 
     186                !approvals.ContainsKey(instance.AssemblyInfo.GUID)) 
     187            { 
     188                return; 
    189189            } 
    190190 
    191191            //Load the plugin 
    192192            instance.Assembly = Assembly.LoadFrom(filePath); 
     193 
     194            //See if the plugin belongs to us (same signature) and if the assembly 
     195            //declares an IsCore attribute. 
     196            if (reflectAssembly.GetName().GetPublicKey().Length == 
     197                Assembly.GetExecutingAssembly().GetName().GetPublicKey().Length) 
     198            { 
     199                bool sameKey = true; 
     200                byte[] reflectAssemblyKey = reflectAssembly.GetName().GetPublicKey(); 
     201                byte[] thisAssemblyKey = Assembly.GetExecutingAssembly().GetName().GetPublicKey(); 
     202                for (int i = 0, j = reflectAssemblyKey.Length; i != j; ++i) 
     203                    if (reflectAssemblyKey[i] != thisAssemblyKey[i]) 
     204                    { 
     205                        sameKey = false; 
     206                        break; 
     207                    } 
     208 
     209                //Check for the IsCore attribute. 
     210                if (sameKey) 
     211                { 
     212                    object[] attr = instance.Assembly.GetCustomAttributes(typeof(CoreAttribute), true); 
     213                    if (attr.Length != 0) 
     214                        instance.IsCore = true; 
     215                } 
     216            } 
     217 
     218            //See if the user disabled this plugin (users cannot disable Core plugins) 
     219            if (approvals.ContainsKey(instance.AssemblyInfo.GUID) && 
     220                !approvals[instance.AssemblyInfo.GUID] && !instance.IsCore) 
     221            { 
     222                return; 
     223            } 
    193224 
    194225            //Initialize the plugin 
     
    202233        } 
    203234 
    204         Assembly AssemblyResolve(object sender, ResolveEventArgs args) 
     235        private Assembly AssemblyResolve(object sender, ResolveEventArgs args) 
    205236        { 
    206237            lock (plugins) 
     
    211242        } 
    212243 
    213         Assembly ResolveReflectionDependency(object sender, ResolveEventArgs args) 
     244        private Assembly ResolveReflectionDependency(object sender, ResolveEventArgs args) 
    214245        { 
    215246            return Assembly.ReflectionOnlyLoad(args.Name); 
     
    234265            Assembly = assembly; 
    235266            Plugin = plugin; 
     267            isCore = false; 
    236268        } 
    237269 
     
    275307 
    276308        /// <summary> 
     309        /// Gets whether the plugin is required for the functioning of Eraser (and 
     310        /// therefore cannot be disabled.) 
     311        /// </summary> 
     312        public bool IsCore 
     313        { 
     314            get 
     315            { 
     316                return isCore; 
     317            } 
     318            internal set 
     319            { 
     320                isCore = value; 
     321            } 
     322        } 
     323 
     324        /// <summary> 
    277325        /// Gets the IPlugin interface which the plugin exposed. 
    278326        /// </summary> 
     
    291339        private Assembly assembly; 
    292340        private AssemblyInfo assemblyInfo; 
     341        private bool isCore; 
    293342        private IPlugin plugin; 
    294343    } 
     
    362411        void DisplaySettings(Control parent); 
    363412    } 
     413 
     414    /// <summary> 
     415    /// Declares that the entity referenced is a core plugin and cannot be unloaded. 
     416    /// Only plugins signed with the same signature as the Manager library will be 
     417    /// considered to be safe and therefore checked for this attribute. 
     418    /// </summary> 
     419    [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)] 
     420    public sealed class CoreAttribute : Attribute 
     421    { 
     422    } 
    364423} 
  • branches/eraser6/Util/Util.csproj

    r574 r582  
    4646    <Compile Include="CryptAPI.cs" /> 
    4747    <Compile Include="Localisation.cs" /> 
     48    <Compile Include="MsCorEEAPI.cs" /> 
    4849    <Compile Include="StreamInfo.cs" /> 
    4950    <Compile Include="KernelAPI.cs" /> 
Note: See TracChangeset for help on using the changeset viewer.