将安全沙箱从 .NET 2.0 移植到 .NET 4.0

发布于 2024-09-28 10:58:06 字数 1011 浏览 1 评论 0 原文

我有工作的 .NET 2.0 插件,它采用外部应用程序创建的 AppDomain,并使用 AppDomain.SetAppDomainPolicy() 方法应用用户定义的安全策略 (PolicyLevel)。但是,此方法在 .NET 4.0 中已过时,并且在运行时失败。这是示例代码:  

AppDomain domain = ExternalApplication.GetAppDomain(); //This call is from external program which I can’t change.

PolicyLevel pl = GetUserDefinedPolicyLevel()

领域。 SetAppDomainPolicy(pl); //这在 .NET 4.0 中失败

  我看到 4.0 示例通过使用以下调用设置 AppDomain 安全性:

AppDomain.CreateDomain( stringFriendlyName, Evidence securityInfo, AppDomainSetup info, PermissionSet grantSet, params StrongName[] fullTrustAssemblies);

  但是,当 AppDomain 已创建时,将使用此 API。在我的情况下,插件必须使用现有的应用程序域。

我发现的另一个解决方案是使用 .config 文件并添加 元素来强制执行旧版 AppDomain 安全性。在我的情况下,这也不是一个选项,因为我有一个应用程序插件,并且无法添加 .config 文件。

在 .NET 4.0 中创建 AppDomain 后,有没有办法在运行时更改 AppDomain 安全性?

我希望这应该是可能的,因为否则 4.0 看起来会删除在运行时加强安全性的能力。

谢谢

I have working .NET 2.0 addin that takes an AppDomain created by an external application and applies user-defined security policy (PolicyLevel) by using AppDomain.SetAppDomainPolicy() method. However, this method is obsolete in .NET 4.0 and fails at runtime. Here is a sample code:  

AppDomain domain = ExternalApplication.GetAppDomain(); //This call is from external program which I can’t change.

PolicyLevel pl = GetUserDefinedPolicyLevel()

domain. SetAppDomainPolicy(pl); //This fails in .NET 4.0

I saw 4.0 example setting AppDomain security by using following call:

AppDomain.CreateDomain( string friendlyName, Evidence securityInfo, AppDomainSetup info, PermissionSet grantSet, params StrongName[] fullTrustAssemblies);

However, this API is used when an AppDomain is already created. In my situation the addin has to use existing AppDomains.

Another solution I found was to use .config files and add <NetFx40_LegacySecurityPolicy enabled="true" /> element to enforce legacy AppDomain security. This is also not an option in my case since I have an addin for applications and I can’t add .config files.

Is there a way to change AppDomain security at runtime after it has been created in .NET 4.0?

I hope that this should be possible, since otherwise it would look like 4.0 removed the ability to tighten security at run-time.

Thanks

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文