gpt4 book ai didi

maven - 尝试在 settings.xml 中加密 gpg 密码

转载 作者:行者123 更新时间:2023-12-01 09:47:08 26 4
gpt4 key购买 nike

我有一个尝试使用 maven-gpg-plugin 的 Maven 构建。如果我在 settings.xml 中有明文密码,一切正常。如果我粘贴加密密码,我会收到“密码错误”错误。我的步骤的详细信息如下,但是对我做错了什么有任何想法吗?另外,作为一个附带问题,我很惊讶“mvn -ep”的多次运行给出了不同的结果。我原以为能够解密,应该返回相同的结果。我很好奇对此的解释。

首先,我生成并分发了我的 key 对,遵循 these instructions from sonotype .接下来,我用我的密码更新了我的 ~/.m2/settings.xml 文件,如 explained by apache .最后,我建了。它工作得很好。是时候加密了。

关注 encryption advice from apache我创建了一个(maven)主密码,将其放入 settings-security.xml,加密 gpg 密码,并将其放入 settings.xml。 (我已经以各种方式尝试过,包括在每个阶段都使用相同的密码。)现在,当我尝试构建时,我得到了错误:

gpg: no default secret key: Bad passphrase
gpg: signing failed: Bad passphrase

如果我在 settings.xml 中将密码改回纯文本,一切都会重新开始。如果我将“-X”添加到我的 maven 构建中,我会看到它正在查找 settings-security.xml。 (实际上,如果我删除文件,我只能看到它什么时候找不到它。)
gpg --gen-key
<choose defaults of RSA/RSA, 2048, and no expiration. Enter in values for name and email.>
gpg --keyserver hkp://pool.sks-keyservers.net --send-keys <key>
mvn clean gpg:sign
mvn -emp <password>
<put encrypted password into ~/.m2/settings-security.xml>
mvn -ep <password>
<put encrypted password into ~/.m2/settings.xml>
mvn clean gpg:sign

pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>example</groupId>
<artifactId>example.test</artifactId>
<version>develop-SNAPSHOT</version>
<packaging>pom</packaging>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>

设置.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<settings>
<profiles>
<profile>
<id>ossrh</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg</gpg.executable>
<gpg.passphrase>{pQ...lV}</gpg.passphrase>
</properties>
</profile>
</profiles>
</settings>

设置-security.xml:
<settingsSecurity>
<master>{KC...jm}</master>
</settingsSecurity>

最佳答案

仔细阅读,似乎只有 settings.xml 中的“服务器”部分可以有加密密码。但是,使用来自 yet another apache webpage 的信息,我能够使上述用例正常工作。我所做的大部分都是正确的,我只需要进行以下修改。

1)我将我的 pom.xml 执行部分更改为现在阅读:

    <executions>
<execution>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<keyname>${gpg.keyname}</keyname>
<passphraseServerId>${gpg.keyname}</passphraseServerId>
</configuration>
</execution>
</executions>

2) 我得到了我的公共(public) gpg key (“gpg --list-key | grep ^pub”,8 个 HEX 数字值)。我将在下一步中将其列为 A1234567。

3)我更新了 settings.xml 如下:
<?xml version="1.0" encoding="UTF-8" ?>
<settings>
<profiles>
<profile>
<id>ossrh</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg</gpg.executable>
<gpg.keyname>A1234567</gpg.keyname>
</properties>
</profile>
</profiles>
<servers>
<server>
<id>A1234567</id>
<passphrase>{pQ...lV}</passphrase>
</server>
</servers>
</settings>

4)“mvn clean gpg:sign”不起作用,但“mvn clean install”可以。我真正的用例是让“mvn clean install”工作,所以我没有费心去弄清楚这一点。 (我敢打赌它与生命周期阶段有关。)

关于maven - 尝试在 settings.xml 中加密 gpg 密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31197080/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com