How can I verify authenticode signatures on managed referenced assemblies before they are loaded? #119726
Replies: 3 comments 8 replies
-
..... If they can change your own assemblies, what's preventing them from changing your loader code? And that's assuming that your dependencies have authenticode configured, which isn't a given. What is it you're trying to protect against here? |
Beta Was this translation helpful? Give feedback.
-
This is not .NET's responsibility. Windows already provides this. If you implemented it, say for a plugin model, then a plugin that has the right signature could disable further checks. In addition, someone can simply edit your code to always return true regardless of what the result is. Whereas when Windows does it none of the problems apply, it's outside of your apps control. This is what WDAC is for. |
Beta Was this translation helpful? Give feedback.
-
Maybe have a look at AvaloniaUI then? im no maintanainer, just noting its a framework a la wpf built for modern net and cross platform and supports NAOT avalonia aot they even have compatibility shim aimed at WPF developers that allows nearly drop in replacement of WPF with Avalonia but is paid and idk if it supports naot |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
With the goal of verifying that my managed dependency assemblies haven't been tampered with, I would like to verify they pass authenticode checks with a known certificate before loading them.
With that in mind I would like setup an event handler similar to NativeLibrary.SetDllImportResolver such that I can check for an authenticode signature with a known certificate owner on a managed assembly before its loaded. I have found the AppDomain.AssemblyLoad event but that is executed after the assembly is loaded into the runtime.
I realize for a plugin or dynamic assembly load I could do this check before I call the relevant functions but for statically linked dependency assemblies that load when a type is used there doesn't seem to be a way to hook this behavior.
The only "workaround" I can think of is to verify all managed assemblies in main before any external types are referenced.
I can fully appreciate this use case is fraught with infinite loop pitfalls. For example: How could I ever load the X509Cert type to verify the assembly that contains the X509 types? I guess I am not too worried about the .net system assemblies, just my own assemblies from being changed.
Beta Was this translation helpful? Give feedback.
All reactions