How does the "referenced assembly" verify the signature / authenticity of the "call collector"?
My question is about security between .NET assemblies. And here's the script:
- The Foundation assembly is deployed to the server .
- A series of Plugin assemblies is added to the application .
- plugins use Foundation functionality .
- Since Foundation provides confidential operations and data, it must ensure that the Plugin (call collector) is authentic and from a specific publisher.
I am new to security and have a basic understanding of strong names and digital signatures. So, if you can give a detailed explanation of the possible ways to achieve this goal, I would be very grateful.
source to share
Edit
Sorry, when you read your question again, I understand that you are not in control of the plugins.
You want to restrict the use of the base assembly based on the assembly calling it.
Unfortunately, there is no other way to do this than by checking the calling assembly in sensitive parts. If you avoid public static members, you can do the check in the constructor.
public class SensitiveClass {
private readonly byte[] SupplierXKey = new[] {...};
public SensitiveClass() {
var key = Assembly.CallingAssembly().GetName().GetPublicKey();
if (!key.SequenceEqual(SupplierXKey)) {
throw new SecurityException();
}
}
}
Please note that this solution requires your vendor to protect their code as well. You may need to extend the above code to check the caller, etc.
old wrong answer
Are you using MEF to load plugins?
Then you can create your own directory, which only allows assemblies signed with a specific key.
Something like:
public class OnlyAssembliesFromX : ComposablePartCatalog
{
private readonly byte[] SupplierXKey = new[] {...};
AggregateCatalog _catalog = new AggregateCatalog();
public OnlyAssemblisFromX(string path) {
foreach (var file in Directory.GetFiles(path)) {
var key = AssemblyName.GetAssemblyName(file)
.GetPublicKey();
if (key.SequenceEqual(SupplierXKey)) {
_catalog.Catalogs.Add(new AssemblyCatalog(file));
}
}
}
public override IQueryable<ComposablePartDefinition> Parts {
get { return _aggregateCatalog.Parts; }
}
}
source to share