Maven 项目中的 Jar 签名策略

发布于 2024-09-16 19:58:36 字数 816 浏览 6 评论 0原文

我们有几个 Maven 项目,它们是在构建服务器上构建的。在某些情况下,我们希望签署我们的交付成果。我们使用 Maven Jarsigner 插件 来做到这一点。

我们面临以下问题:

  • 我们应该将签名密码存储在哪里?
  • 签署 Maven 项目的好策略是什么?

我们不想将密钥库放在服务器上的某个位置并硬编码它的路径。因此,我们只是将此密钥库包装在一个 jar 中,并将其作为工件上传到我们的内部 Maven 存储库。当我们想要签署 Maven 项目时,我们使用 Maven 依赖插件< /a> 并将签名目标附加到 Maven 构建生命周期。 这里更详细信息。

为了隐藏密钥库的密码,我们将它们放入公司的 pom.xml 文件中。我们还考虑将密码存储在构建服务器上的 settings.xml 中。

当项目在开发人员计算机上构建并签名时,我们使用自签名证书对其进行签名。但是,当项目在构建服务器上构建并签名时,我们使用“官方”证书对其进行签名。

这是一个好的策略吗?

We have several maven projects, which are built on the build server. In some cases we want to sign our deliverables. We use Maven Jarsigner Plugin to do that.

We face the following questions:

  • Where should we store the passwords for signing?
  • What is a good strategy for signing maven projects?

We don't want to put our keystore somewhere on our servers and hardcode a path to it. So we just wrapped this keystore in a jar and uploaded it as an artifact to our inner maven repository. When we want to sign a maven project, we download the keystore artifact using the Maven Dependency Plugin and attach signing goal to maven build lifecycle. Here is more detailed information.

In order to hide the passwords for the keystore, we put them into our corporate pom.xml file. We also think about storing passwords in settings.xml on the build server.

When a project is built and signed on a developer machine, we sign it with self-signed certificate. But when project is built and signed on a build server, we sign it with our "official" certificate.

Is it a good strategy?

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

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

发布评论

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

评论(1

怀念你的温柔 2024-09-23 19:58:36

我使用 2 个密钥库:

  • 一个存储在 SCM 中的开发密钥库。 CI 服务器因此可以对快照进行签名。
  • 具有由受信任的证书颁发机构颁发的真实生产证书的生产密钥库。

开发密钥库密码位于 pom.xml 中。这是我的 pom.xml 的片段:

  <plugin>
    <artifactId>maven-jarsigner-plugin</artifactId>
    <version>1.2</version>
    <configuration>
      <storetype>${keystore.type}</storetype>
      <keystore>${keystore.path}</keystore>
      <alias>${keystore.alias}</alias>
      <storepass>${keystore.store.password}</storepass>
      <keypass>${keystore.key.password}</keypass>
    </configuration>
  </plugin>
  <!-- 
      ... rest of the pom.xml ...
  -->
  <properties>
    <keystore.path>cert/temp.keystore</keystore.path>
    <keystore.type>JKS</keystore.type>
    <keystore.alias>dev</keystore.alias>
    <keystore.password>dev_password</keystore.password>
    <keystore.store.password>${keystore.password}</keystore.store.password>
    <keystore.key.password>${keystore.password}</keystore.key.password>
  </properties>

~/.m2/settings.xml 中,我定义了一个 codesgining 配置文件:

<settings>
  <profiles>
    <profile>
      <id>codesigning</id>
      <properties>
        <keystore.path>/opt/prod/prod.keystore</keystore.path> 
        <keystore.alias>prod</keystore.alias>
        <keystore.type>JKS</keystore.type>
        <keystore.store.password>${keystore.password}</keystore.store.password>
        <keystore.key.password>${keystore.password}</keystore.key.password>
      </properties>
    </profile>
  </profiles>
</settings>

当我想要时签署真实证书我使用 -Pcodesigning -Dkeystore.password=strongPassword 参数调用 maven。我还配置了 maven-release-plugin 以使用 <代码>代码设计配置文件。

实际上,可以将密码存储在 settings.xml 中,只要该文件除了您之外没有人可读。

I use 2 keystores:

  • a development keystore which is stored in the SCM. The CI server can thus sign the snapshots.
  • a production keystore with a real production certificate issued by a trusted certification authority.

The development keystore password is in the pom.xml. Here is a snippet of my pom.xml:

  <plugin>
    <artifactId>maven-jarsigner-plugin</artifactId>
    <version>1.2</version>
    <configuration>
      <storetype>${keystore.type}</storetype>
      <keystore>${keystore.path}</keystore>
      <alias>${keystore.alias}</alias>
      <storepass>${keystore.store.password}</storepass>
      <keypass>${keystore.key.password}</keypass>
    </configuration>
  </plugin>
  <!-- 
      ... rest of the pom.xml ...
  -->
  <properties>
    <keystore.path>cert/temp.keystore</keystore.path>
    <keystore.type>JKS</keystore.type>
    <keystore.alias>dev</keystore.alias>
    <keystore.password>dev_password</keystore.password>
    <keystore.store.password>${keystore.password}</keystore.store.password>
    <keystore.key.password>${keystore.password}</keystore.key.password>
  </properties>

In ~/.m2/settings.xml I defined a codesgining profile:

<settings>
  <profiles>
    <profile>
      <id>codesigning</id>
      <properties>
        <keystore.path>/opt/prod/prod.keystore</keystore.path> 
        <keystore.alias>prod</keystore.alias>
        <keystore.type>JKS</keystore.type>
        <keystore.store.password>${keystore.password}</keystore.store.password>
        <keystore.key.password>${keystore.password}</keystore.key.password>
      </properties>
    </profile>
  </profiles>
</settings>

when I want to sign the real certificate I invoke maven with the -Pcodesigning -Dkeystore.password=strongPassword parameters. I also configured the maven-release-plugin to use the codesigning profile.

Actually it is possible to store the password in settings.xml as long as the file is readable by nobody but you.

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