This is a followup from my previous question, I want to examine the StrongName of an assembly before loading it (either via a file on the hard disk or via the byte data). To ensure that it's been created by me.
Are there any security risks to consider when using Assembly.LoadFrom
or Assembly.Load
, could malicious code be executed by loading it into these variables? Should I consider loading these assemblies in an AppDomain to read them?
Here's the rest of my code:
Assembly dll = Assembly.LoadFrom("UnauthorisedPlugin.dll");
byte[] thisDllKey = Assembly.GetExecutingAssembly().GetName().GetPublicKey();
byte[] dllKey = dll.GetName().GetPublicKey();
if (Enumerable.SequenceEqual(thisDllKey, dllKey))
{
Type pluginType = dll.GetTypes().Single();
IPlugin unauthPlugin = (IPlugin)Activator.CreateInstance(pluginType);
Console.WriteLine(unauthPlugin.Run());
}
else
{
Console.WriteLine("The DLL is not authorised");
}
Console.ReadLine();