限制 Codedom 编译的程序集

发布于 2024-08-15 13:04:42 字数 269 浏览 3 评论 0原文

我为我的应用程序编写了一个插件管理器,它利用 codedom 将 C# 代码编译到类库中并实例化其类型。 它工作得很好,现在我希望限制已编译程序集的权限。不幸的是我不知道该怎么做。 据我了解,我应该以某种方式使用 CompilerParameters.Evidence,但我不清楚如何使用。 为了清楚起见,我不想简单地将程序集分类为某个区域,我想将其限制为在插件管理器构造函数中作为参数传递的权限集。我还想提一下,我不会将程序集加载到新的 appdomin 中,它与应用程序的其余部分在同一域上执行。

谢谢。

i've written a plugin manager for my app , it utilizes codedom to compile c# code into a class library and instanciate its types.
it works perfectly , and now i wish to restrict the permissions on the compiled assembly.unfortunatly i dont know how to do so.
as far as i understand i should use CompilerParameters.Evidence in some way, but it is unclear to me of how.
for te sake of clearity , i dont wish to simply categorize the assmbly as a certain zone, i want to limit it to a permission set that is passed as an argument in the plugin managers constructor. i also would like to mention that i do not load the assembly into a new appdomin , it is executed on the same domain as the rest of the application.

thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

驱逐舰岛风号 2024-08-22 13:04:42

处理安全性的 CodeDOM 示例对于 google 来说很棘手。经过几个小时的阅读,我发现了两种方法。

最好的似乎是托管插件框架,因为它是专为您的用例场景而设计的。
限制插件汇编代码访问

CAS(代码访问安全) 也是一种选择,但它似乎不太受欢迎并且正在退出。 中摘取的示例

var myEvidence = new Evidence(new object[] {SecurityZone.Internet});
var newDomain = AppDomain.CreateDomain("InternetDomain");
myDomain.Load("MyUntrustedAssembly.dll", myEvidence);
myDomain.CreateInstanceAndUnwrap("MyUntrustedAssembly","MyUntrustedObjectType");

这是从 [SO post][3] CAS 参考文献
.NET/Security:限制运行时加载的程序集访问某些 API
http://www.gamedev.net/community/forums/topic。 asp?topic_id=418038
http://www.go4answers.com/Example/codedom-security-64586。 ASPX

CodeDOM examples that handle security are tricky to google. After several hours of reading I have found two approaches.

The best seems to be the Managed Addin Framework because it is designed for exactly your use case senario.
Restrict plug-in assembly code access

CAS (Code Access Security) is also an option but it appears to be less popular and on the way out. Here is an example lifted from this [SO post][3]

var myEvidence = new Evidence(new object[] {SecurityZone.Internet});
var newDomain = AppDomain.CreateDomain("InternetDomain");
myDomain.Load("MyUntrustedAssembly.dll", myEvidence);
myDomain.CreateInstanceAndUnwrap("MyUntrustedAssembly","MyUntrustedObjectType");

CAS References
.NET/Security: Limiting runtime-loaded assemblies from accessing certain APIs
http://www.gamedev.net/community/forums/topic.asp?topic_id=418038
http://www.go4answers.com/Example/codedom-security-64586.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文