5

我想强制执行超出基本checksumPolicy=fail方法的严格 Maven 依赖策略。

这是一种尝试提供对修改后的依赖项的保护,该依赖项仍然具有有效的摘要值,也称为“依赖链攻击”。

这种情况可能来自以下情况:

  • 依赖项已更新,但作者尚未更新版本号并设法覆盖早期版本(或他们的 repo 帐户已被盗用)
  • 中间人攻击已经到位(即时重写/散列)
  • 存储库本身已被破坏

在与其他开发人员的讨论中,解决上述问题的一种方法是在 pom.xml 中列出已知的 MD5/SHA 摘要,并让 Maven 验证下载的依赖项是否具有相同的摘要。这确保了只要源代码存储库保持安全,任何包含的已被破坏的依赖项都将被检测到。

因此,我的问题是双重的:

  1. 有没有更有效的替代方法?
  2. 是否有任何现有的实现/插件可以完成这项工作?
4

2 回答 2

7

如果有人自己解决这个问题,我已经创建了一个处理它的Maven Enforcer Plugin Rule。您可以指定包含预期 SHA1 哈希值的工件 URN 列表,并让实施者验证这确实是构建中使用的内容。

它可以在 MIT 许可下通过 Maven Central 获得,源代码在 GitHub 中:https ://github.com/gary-rowe/BitcoinjEnforcerRules

虽然该项目表明它适用于 Bitcoinj 库,但它实际上是一个通用解决方案,可以包含在任何有安全意识的构建过程中。它还将扫描您现有的项目并识别任何问题区域,同时自动为您构建白名单。

下面是您在项目中使用它所需的配置示例。

<build>
  <plugins>
    ...
      <!-- Use the Enforcer to verify build integrity -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.2</version>
        <executions>
          <execution>
            <id>enforce</id>
            <phase>verify</phase>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <digestRule implementation="uk.co.froot.maven.enforcer.DigestRule">

                  <!-- Create a snapshot to build the list of URNs below -->
                  <buildSnapshot>true</buildSnapshot>

                  <!-- List of required hashes -->
                  <!-- Format is URN of groupId:artifactId:version:type:classifier:scope:hash -->
                  <!-- classifier is "null" if not present -->
                  <urns>

                    <urn>antlr:antlr:2.7.7:jar:null:compile:83cd2cd674a217ade95a4bb83a8a14f351f48bd0</urn>
                    <urn>dom4j:dom4j:1.6.1:jar:null:compile:5d3ccc056b6f056dbf0dddfdf43894b9065a8f94</urn>
                    <urn>org.bouncycastle:bcprov-jdk15:1.46:jar:null:compile:d726ceb2dcc711ef066cc639c12d856128ea1ef1</urn>
                    <urn>org.hibernate.common:hibernate-commons-annotations:4.0.1.Final:jar:null:compile:78bcf608d997d0529be2f4f781fdc89e801c9e88</urn>
                    <urn>org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final:jar:null:compile:3306a165afa81938fc3d8a0948e891de9f6b192b</urn>
                    <urn>org.hibernate:hibernate-core:4.1.8.Final:jar:null:compile:82b420eaf9f34f94ed5295454b068e62a9a58320</urn>
                    <urn>org.hibernate:hibernate-entitymanager:4.1.8.Final:jar:null:compile:70a29cc959862b975647f9a03145274afb15fc3a</urn>
                    <urn>org.javassist:javassist:3.15.0-GA:jar:null:compile:79907309ca4bb4e5e51d4086cc4179b2611358d7</urn>
                    <urn>org.jboss.logging:jboss-logging:3.1.0.GA:jar:null:compile:c71f2856e7b60efe485db39b37a31811e6c84365</urn>
                    <urn>org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:1.0.0.Final:jar:null:compile:2ab6236535e085d86f37fd97ddfdd35c88c1a419</urn>

                    <!-- A check for the rules themselves -->
                    <urn>uk.co.froot.maven.enforcer:digest-enforcer-rules:0.0.1:jar:null:runtime:16a9e04f3fe4bb143c42782d07d5faf65b32106f</urn>

                  </urns>

                </digestRule>
              </rules>
            </configuration>
          </execution>
        </executions>

        <!-- Ensure we download the enforcer rules -->
        <dependencies>
          <dependency>
            <groupId>uk.co.froot.maven.enforcer</groupId>
            <artifactId>digest-enforcer-rules</artifactId>
            <version>0.0.1</version>
          </dependency>
        </dependencies>

      </plugin>
    ...
  </plugins>
</build>
于 2013-06-16T21:58:33.490 回答
2

听起来对存储库本身来说是一项不错的工作。查看有关类似问题的其他线程。

我不熟悉 Nexus 中的 PGP 签名方案,但这听起来像是一个好的开始吗?

于 2013-01-08T14:47:33.083 回答