security - Maven 3 密码加密是如何工作的?

标签 security maven encryption passwords

我正在尝试了解 Maven 3 的[密码加密功能。我发现这个功能的记录很少并且令人困惑。例如,feature documentationa blog post by the author of the feature在几个问题上互相矛盾。

这个问题比 How does maven --encrypt-master-password work 更广泛并且不被 Maven encrypt-master-password good practice for choosing password 覆盖.

具体来说,我试图回答文档中未涵盖的以下问题。我已将迄今为止收集到的信息以斜体显示在每个问题下方。

  1. 加密的主密码仅通过 settings-security.xml 中的存在即可提供安全性吗?在只有一个用户可以访问的文件夹中( ~/.m2 )?如果是这样,为什么要费心加密“主密码”(为什么不只使用一些随机值)?难道“主密码”真的只是密码函数的熵输入吗?称其为密码令人困惑 - 我希望 Maven 在解密任何加密的服务器密码之前提示我输入此密码,但它没有。

我的理解是,是的,这仅通过存在于操作系统 protected 文件中来提供安全性。我相信 Maven 允许您加密主密码,这样如果您丢失了 settings-security.xml文件,您可以重新生成它。这是正确的吗?

  • 主密码和服务器密码是否使用相同的加密过程/密码?服务器密码是基于主密码的,所以算法上肯定有一些不同。这个的源代码在哪里?
  • Marcelo Morales' answer on How does maven --encrypt-master-password work链接到plexus-cihper project on GitHub 。目前尚不清楚这只是密码,还是提供密码功能的实际 Maven 插件。

  • 我发现多次加密的相同主密码或服务器密码会产生不同的哈希值。根据Marcelo Morales' answer on How does maven --encrypt-master-password work ,这是因为在加密之前将“JVM 配置特定(通常是 SHA1PRNG)64 位随机盐”添加到密码中。 Maven 在编译时使用存储的密码时对其进行解密。这是否意味着盐必须储存在某个地方?
  • 我不知道

  • 我还观察到,如果主密码被重新加密并存储在 settings-security.xml 中,则使用一个加密主密码加密的常规密码仍然有效。文件,即使加密的主密码密文现在不同。有人可以解释一下这是如何工作的吗?
  • 我不知道。在我看来,Maven 正在做一些可疑的事情或在某处存储明文。

  • 我的理解是加密密码只能与<server />一起使用settings.xml 中的标签文件。这是真的? settings.xml中定义的服务器在哪里会被使用吗?
  • 我的理解是<server />定义可以在 <repositories /> 中使用和<distributionManagement /> ,但不是<scm /> 。有人可以验证一下吗?

  • 对于这样一个关键的功能(构建系统安全性),在我看来,存在很多困惑和糟糕的文档。有人能指出 Maven 3 网站上的文档是如何工作的吗?是否有某个 wiki 链接可以让我尝试改进文档?
  • 我不知道

    抱歉,文字墙很长,感谢您的回答。

    最佳答案

    我的答案是基于阅读 Maven 源代码并做了一些研究。

    1. Does the encrypted master password provide security simply by existing in settings-security.xml in a folder that only one user can access (~/.m2)? If so, why bother with encrypting a 'master password' (why not just use some random value)? Isn't the 'master password' really just an entropy input to the cryptographic function? Calling it a password is confusing - I expected Maven to prompt me for this password before de-crypting any encrypted server passwords, but it did not.

    主密码是加密函数的输入,用于加密/解密服务器密码。如果某人拥有您的个人加密服务器密码,他们将无法解密它们,除非他们也拥有您的主密码。这意味着您可以与其他人自由共享您的 Maven settings.xml 文件,而他们无法解密您的服务器密码。这也是主密码保存在单独文件中的原因。

    这个基本原理在encryption guide中有一些解释。

    1. Do the master password and server passwords use the same encryption process/cipher? The server passwords are based on the master password, so there must be some difference in the algorithm. Where is the source code for this located?

    据我所知,主密码是使用与服务器密码相同的密码进行加密的。解密服务器密码时,主密码(未加密形式)是输入;解密主密码时,魔术字符串“settings.security”用作附加输入。

    可以查看源码PBECipherMavenCli.java .

    1. I have observed that the same master password or server password encrypted multiple times gives different hashes. According to Marcelo Morales' answer on How does maven --encrypt-master-password work, this is because 'a JVM-configuration-specific (usually SHA1PRNG) 64-bit random salt' is added to the password prior to encrypting. Maven decrypts stored passwords when they are used at compile time. Doesn't this mean the salts have to be stored somewhere?

    处理盐的传统方法是随机盐与加密文本一起存储。请参阅Wikipedia article .

    根据上面链接的源代码,salt 似乎存储为 Base64 解码字节的前 8 个字节,位于加密密码之前。

    1. I have also observed that a regular password encrypted using one encrypted master password will still work if the master password is re-encrypted and stored in the settings-security.xml file, even though the encrypted master password ciphertext is now different. Can someone explain how this works?

    这是因为使用了主密码的解密形式,而不是加密的“密文”。因此重新加密不会影响服务器密码加解密。

    我不知道您最后两个(5 和 6)问题的答案。

    关于security - Maven 3 密码加密是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30769636/

    相关文章:

    python - CTR 中的 AES 如何与 PyCrypto 一起用于 Python?

    Java、rsa加密

    javascript - 能否加密一个 n 位数字,返回一个唯一的 n 位数字?

    maven - 我可以在单个artifactId上发布多个 Artifact 吗?

    security - 编译前保护 SWF

    java - 如何创建密码?

    javascript - 哈希安全漏洞 - 如何修复?

    java - Maven checkstyle https 配置

    java - 如何修复丢失 token 错误

    java - Android应用程序中的模式输入