.NET:可执行文件应该进行强名称签名吗?私有 DLL 怎么样?

发布于 2024-08-21 14:30:24 字数 1302 浏览 3 评论 0 原文

我的应用程序由三个程序集组成:一个引用几个 DLL 的 EXE。这些 DLL 是我的应用程序私有的 - 它们仅由该可执行文件使用。

应该给这些程序集起一个响亮的名字吗?

FxCop 建议他们应该 - 对于目前生产的所有组件:

CA2210:标志<装配>具有强名称键。

但是,此建议说:

一般来说,您应该避免对应用程序 EXE 程序集进行强命名。

您可能希望避免使用应用程序私有的强命名组件。

我应该给这些程序集起一个响亮的名字吗?在这种情况下这样做(或不这样做)有什么好处?

编辑:

查看了几个具有类似结构的应用程序,在这个问题上似乎没有达成共识。 Paint.NETCrack.NET 不是强名称,而 的强名称.NET ReflectorSnoop 是。

有趣的是,对于 Expression 套件,Microsoft 采用了后一种方法:例如,在 Expression Blend 中,他们选择对 Blend.exe 和随附的 DLL(例如 Microsoft.Expression.Blend.dll)进行强名称签名。

似乎我不太可能收到第一个问题的简单答案:“我应该给这些程序集起一个强名称吗?”。然而,我的第二个问题仍然存在:

在这种情况下,强名称签名二进制文件有什么好处吗?或者说,不这样做有什么好处吗?

编辑 2:

如果没有压倒性的理由选择任何一种方式,我倾向于给我的程序集起一个响亮的名称。因此,我对是否有人可以对此进行扩展(从第一个链接开始)感兴趣:

“强命名会使管理依赖项变得更加困难,并为私有组件增加不必要的开销。”

My application consists of three assemblies: a single EXE which references a couple of DLLs. The DLLs are private to my application - they are used only by this executable.

Should these assemblies be given a strong name?

FxCop suggests that they should - for all of the assemblies it currently produces:

CA2210: Sign <assembly> with a strong name key.

However, this advice says:

In general, you should avoid strong-naming application EXE assemblies.

and

you may want to avoid strong-naming components that are private to your application.

Should I give these assemblies a strong name? What are the benefits of doing so (or not doing so) in this case?

Edit:

Looking at several applications with a similar structure, there seems to be no consensus on this issue. The binaries of Paint.NET and Crack.NET are not strong-named, whereas those of .NET Reflector and Snoop are.

Interestingly, with the Expression suite Microsoft have taken the latter approach: in Expression Blend, for example, they have chosen to strong-name sign both Blend.exe and the accompanying DLLs (such as Microsoft.Expression.Blend.dll).

It seems that I am unlikely to receive a simple answer to my first question: "Should I give these assemblies a strong name?". However, my second question still stands:

Are there any benefits to strong-name signing binaries in this situation? Or, are there any benefits to not doing so?

Edit 2:

If there are no overwhelming reasons to go either way, I am inclined towards giving my assemblies a strong name. I'd thus be interested in whether anyone can expand upon this (from the first link):

"strong-naming can make it more difficult to manage dependencies and add unnecessary overhead for private components."

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

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

发布评论

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

评论(4

自在安然 2024-08-28 14:30:24

在我看来,在这种情况下强名称签名的好处如下:

  • 防止攻击者用使用另一密钥签名(或根本未签名)的 DLL 替换 DLL,而无需替换 EXE(因为 EXE 包含引用)其中包括公钥)。
  • 防止攻击者在保留现有密钥的同时修改程序集(因为这将导致签名验证失败)。但请注意,从 .NET 3.5 SP1 开始,这种情况下的签名验证为 默认禁用
  • 可以防止应用程序使用不匹配版本的程序集运行 - 如果由于部署错误而错误地替换了 DLL,则应用程序将无法加载它,而不是尝试使用(可能不兼容的)错误版本。
  • 避免 FxCop 警告。

签名的缺点(我相信这些是链接文章所指的):

  • 用兼容的较新版本替换 DLL(例如,为了修复错误)需要替换 EXE。
  • 在 .NET 版本中 < 3.5 SP1,由于签名验证,强名称程序集需要更长的时间来加载。
  • 强名称 DLL 的加载时间也较长,因为加载程序在本地查找之前会执行 GAC 搜索(在这种情况下是徒劳的)。

确实令人遗憾的是,选择要么是强命名(因此需要引用来匹配精确的键和精确的版本),要么不是强命名(并且不需要两者匹配)。如果可以需要密钥但不需要特定版本,那么也许可以获得签名的前两个好处,而不会遇到第一个缺点。也许可以通过应用强名称然后使用 app.config 处理版本控制问题来实现?

As I see it, these are the benefits to strong-name signing in this situation:

  • Prevents an attacker replacing a DLL with one signed using another key (or not signed at all), without also replacing the EXE (since the EXE contains a reference which includes the public key).
  • Prevents an attacker modifying an assembly while retaining the existing key (since this will cause signature verification to fail). Note, however, that as of .NET 3.5 SP1, signature verification in this situation is disabled by default.
  • Could prevent the application from running with mismatched versions of assemblies - if a DLL has been incorrectly replaced due to a deployment error, the application will fail to load it rather than trying to use a (potentially incompatible) wrong version.
  • Avoids FxCop warnings.

And the drawbacks to signing (I believe these are what the linked article is referring to):

  • Replacing a DLL with a compatible newer version (in order to fix a bug, for example) requires replacing the EXE.
  • In .NET versions < 3.5 SP1, strong-named assemblies take longer to load due to signature verification.
  • Strong-named DLLs also take longer to load because the loader performs a (futile in this situation) search of the GAC before looking locally.

It does seem a shame that the choice is either strong-naming (and thus requiring references to match an exact key and an exact version), or not strong-naming (and not requiring either to match). If it were possible to require a key but not a particular version, perhaps it would be possible to get the first 2 benefits of signing without also getting the first drawback. Maybe this is possible by applying a strong name and then dealing with the versioning issue using app.config?

凉城 2024-08-28 14:30:24

强命名程序集仅确保版本兼容性。这与信任议会不同。

换句话说,“强名称”仅指确切的程序集二进制文件与编译时使用的版本号的组合。

如果您对这些程序集进行 GAC,那么 CLR 只会验证它一次。当时大会已开始。这可以提高性能。然而,我的经验表明它是最小的。

强命名的程序集可以替换为非强命名的程序集;这提出了关于强命名不是任何类型的安全功能的部分。

我个人的观点是,与它们相关的疼痛程度并不能证明它们的使用是合理的。痛苦在于他们如何使用自动化测试工具。

https:// web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-5054496.html

Strong naming assemblies ONLY ensures version compatibility. This is not the same thing as trusting the assembly.

In other words, the "strong name" ONLY refers to that exact assembly binary in combination with the version number in use at the time of compile.

If you GAC those assemblies, then the CLR will only verify it once. At the time the assembly is gac'd. This can result in a performance improvement. However, my experience has shown it to be minimal.

A strong named assembly can be replaced with one that is not strong named; which brings up the part about strong naming NOT being any type of security feature.

My personal opinion is that the level of pain associated with them does not justify their use. The pain being how they screw with automated testing tools.

https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-5054496.html

无尽的现实 2024-08-28 14:30:24

对程序集进行签名可确保程序集在编译后不会被修改。只要您是唯一的私钥所有者,就没有人能够使用您的密钥退出程序集。

当然,这并不是绝对的保护。黑客可以修改程序集并从所有程序集中删除强名称签名(和引用)。这些组件也可以工作。

但在这种情况下,您可以说修改不是由您进行的。

Signing assemblies ensures that assemblies are not modified after compilation. And as long as you are the only private key owner no one is able to resign the assembly with your key.

Sure, this is not an absolute protection. A hacker can modify assemblies and remove strong name signatures (and references) from all assemblies. These assemblies would also work.

But in such a case you are able to say that the modifications are not made by you.

沧笙踏歌 2024-08-28 14:30:24

如果您对程序集进行签名,则任何引用的程序集都会公开公开,它们也必须进行签名。否则,您将有充分的理由得到编译错误。

我认为强命名程序集的主要用途是将其放入 GAC 中。

我认为没有必要对 exe 进行强命名。

只是我的2比索......

If you sign an assembly, any referenced assemblies are publicly exposed they must be signed too. Otherwise you will get a compile error for good reason.

I think the primary use for strong naming an assembly is to get it into the GAC.

I don't see a need to strong name an exe.

just my 2 pesos....

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