如何防止未经授权的代码访问 .NET 2.0 中的程序集?
在 .NET 1.x 中,您可以使用 StrongNameIdentityPermissionAttribute 在您的程序集上,以确保只有您签名的代码才能访问您的程序集。 根据 MSDN 文档,
在 .NET Framework 2.0 及更高版本中,对身份的要求 如果调用程序集完全信任,则权限无效。
这意味着任何完全信任的应用程序都可以绕过我的安全要求。
如何防止未经授权的代码访问 .NET 2.0 中的程序集?
In .NET 1.x, you could use the StrongNameIdentityPermissionAttribute on your assembly to ensure that only code signed by you could access your assembly. According to the MSDN documentation,
In the .NET Framework version 2.0 and later, demands for identity
permissions are ineffective if the calling assembly has full trust.
This means that any application with full trust can just bypass my security demands.
How can I prevent unauthorized code from accessing my assembly in .NET 2.0?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
按照Eric的建议,我自己检查了密钥解决了这个问题。 在我想要保护的代码中,我添加了以下调用,
然后该方法的实现是
** 更改了名称和密钥以保护无辜者。 任何与真实姓名或公司的相似之处均纯属巧合。*
As per Eric's suggestion, I solved it by checking the key myself. In the code I want to protect, I add the following call,
Then the implementation of that method is
** Names and keys changed to protect the innocent. Any likeness to real names or companies is merely a coincidence.*
请参阅这篇文章:
http:// blogs.msdn.com/ericlippert/archive/2008/10/06/preventing-third-party-derivation-part-two.aspx
特别是这一部分:
显然, .Net 设计者认为此属性对于 .Net 1.x 中的完全信任代码也不是很有效。
See this article:
http://blogs.msdn.com/ericlippert/archive/2008/10/06/preventing-third-party-derivation-part-two.aspx
Particularly this part:
Apparently, the .Net designers felt that this attribute wasn't very effective for full trust code in .Net 1.x either.
正如 Joel 所说,您在 CAS 方面运气不好。 但是,您可以在需要保护的任何方法中自行进行检查,方法是使用 Assembly.GetCallingAssembly() 获取对包含调用代码的程序集的引用,然后手动检查该程序集的强名称。
As Joel indicated, you are out of luck with regard to CAS. However, you may be able to do the check yourself in any method you need to protect by using Assembly.GetCallingAssembly() to get a reference to the assembly containing the calling code, then check the strong name on that assembly manually.