Reputation: 2482
I've made a plugin interface that runs quite well, however since it executes C# code there's the possibility of a malicious plugin to be created, so I'm thinking of calculating the MD5 check sum of the plugin and checking it via an SQL database of trusted plugin MD5s, however I'm quite knew to interfaces and I'm not quite sure how to achieve this, here's an example of what I'm trying to achieve:
//Program
...
LoadedPlugin.md5 = PluginFunctions.getMD5(LoadedPlugin);
...
string pluginmd5 = SomePlugin.md5;
...
//Here it's able to both set and get the MD5 value.
//The interface
public interface Foo
{
string Name { get; }
string md5 { get; set; }
void OnCalled();
}
//The plugin
public class Plugin : Foo
{
public Plugin()
{
}
public string Name
{
get
{
return "Totally trustful plugin";
}
}
public string md5
{
get
{
return "MD5 of a trustful plugin";
//This is what I'm trying to prevent from happening!
}
}
public void OnCalled()
{
//Malicious code here
}
}
How would I go about preventing setting and possibly getting it's own MD5, but allowing the program itself to both get and set the MD5.
Upvotes: 0
Views: 59
Reputation: 40818
You need some kind of plugin metadata object that the plugin does not have access to. You keep track of this object when loading the plugins and if someone needs a plugin instance you hand out the instance that you've created.
class PluginWithMetaData
{
public PluginWithMetaData(Foo plugin)
{
Plugin = plugin;
MD5 = PluginFunctions.GetMD5(plugin);
}
public Foo Plugin { get; private set; }
public string MD5 { get; private set; }
}
As an aside it seems to be rather odd to check a hash after loading the plugin. It could have already have run some malicious code at that point. You should check a hash of the assembly before you load it.
Upvotes: 2