ruby gem 中的校验和有什么意义

What's the point of checksums inside the ruby gem

所以 .gem 文件是包含 data.gz 元数据 data.gz 和校验和的 tarball。在 data.gz 取消存档之前正在验证校验和,但我不明白这有什么意义。它似乎没有提供任何真正的安全优势

通常你只是 运行 gem install somegemfilename 但如果你出于某种原因选择从 https://rubygems.org/gems/ 下载 gem 那么你需要手动 运行该文件的校验和。

例子

下载类似 https://rubygems.org/downloads/foo-0.0.2.gem 的文件 然后在您的终端中转到下载文件的位置,然后 运行:

sha256sum foo-0.0.2.gem
# it should output the same checksum shown at https://rubygems.org/gems/foo
=> 523009a5b977f79c8eaa79b521e416f26482bc4fbbcc04bd08580696e303a715

仅此一项就足够安全了。然而,这些似乎是额外的安全层,以确保每个由 tar xf somegem.gem 解压的 gz 文件都可以根据 checksums.yaml 的内容单独检查,checksums.yaml 提供了几个变体校验和。

简短的回答是您不需要担心它们,但如果您想深入到那个级别,它们就在您身边。

根据@NikitaMisharin 的评论更新:

是的,我明白你的观点并且倾向于同意你的观点。它看起来像是非常古老的遗留 Ruby 代码并在 this commit.

中引入
commit 9ac0e9149295f356f3aee2e6a7c3a4e22d0a904e
Author: Chad Fowler <chad@chadfowler.com>
Date:   Sun Nov 23 01:53:27 2003 +0000

    Generate MD5 checksum for gem and store it in the file.  Will be used to validate gem file before installation.


    git-svn-id: svn+ssh://rubyforge.org/var/svn/rubygems/trunk@66 3d4018f9-ac1a-0410-99e9-8a154d859a19

我倾向于得出结论,这是一种检查代码完整性的原始方法,自从使用将在 Rubygems.org 标准 gem 存储库上发布的校验和以来,它已经发展。

我想这可能是遗留下来的遗留支持?但我想如果你真的想确定,也许问 Chad Fowler?

可能需要更多背景知识 read this documentation which is linked directly on rubygems.org security section

问过维护者,这是他的回答

I believe I encountered some errors with truncated gems that RubyGems could not detect. Adding the checksums would allow RubyGems to determine if the gem download had completed successfully and had not been corrupted either during the download or while being cached on-disk.

The checksums allow RubyGems to say “this file is corrupt” instead of a more-confusing error due to a truncated .gem (.tar) file, Zlib failure, etc.