Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt to new GPG Mojo #4411

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@
<!-- see https://docs.sonatype.org/display/Repository/How+To+Generate+PGP+Signatures+With+Maven -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.7</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand Down
6 changes: 5 additions & 1 deletion tycho-gpg-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<maven>${minimal-maven-version}</maven>
</prerequisites>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
Expand All @@ -44,7 +48,7 @@
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@

import java.io.File;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;

public abstract class AbstractGpgMojoExtension extends AbstractGpgMojo {

@Override
protected ProxySignerWithPublicKeyAccess newSigner(MavenProject project)
throws MojoExecutionException, MojoFailureException {
protected ProxySignerWithPublicKeyAccess newSigner(MavenProject project) throws MojoFailureException {
return new ProxySignerWithPublicKeyAccess(super.newSigner(project), getSigner(), getPGPInfo(), getSecretKeys());
}

@Override
protected AbstractGpgSigner createSigner(String name) throws MojoFailureException {
//due to legacy reasons we actually used a GpgSigner as a delegate
//(see org.apache.maven.plugins.gpg.ProxySignerWithPublicKeyAccess.getSigner(File, File))
//it would be better to actually create the BouncyCastleSigner already here!
return super.createSigner(GpgSigner.NAME);
}

protected String getSigner() {
return "gpg";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ProxySignerWithPublicKeyAccess(AbstractGpgSigner delegate, String signer,
this.delegate = delegate;
this.setLog(delegate.getLog());
// The pgpInfo is used only for testing purposes.
if ("bc".equals(signer) || pgpInfo != null || secretKeys != null) {
if (BouncyCastleSigner.NAME.equals(signer) || pgpInfo != null || secretKeys != null) {
try {
this.signer = getSigner(pgpInfo, secretKeys);
} catch (MojoExecutionException | MojoFailureException | IOException | PGPException e) {
Expand Down Expand Up @@ -216,4 +216,14 @@ private String getKeys(boolean isPublic) throws MojoExecutionException {
throw new MojoExecutionException("Unable to execute gpg command", e);
}
}

@Override
public String signerName() {
return signer.signerName();
}

@Override
public String getKeyInfo() {
return signer.getKeyInfo();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.security.Security;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.gpg.AbstractGpgSigner;
Expand Down Expand Up @@ -57,6 +58,7 @@
import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider;
import org.bouncycastle.openpgp.operator.bc.BcPGPKeyPair;
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder;
import org.bouncycastle.util.encoders.Hex;

public class BouncyCastleSigner extends AbstractGpgSigner {

Expand All @@ -74,6 +76,8 @@ public class BouncyCastleSigner extends AbstractGpgSigner {

private PGPPrivateKey privateKey;

public static final String NAME = "bc";

/**
* Create an empty instance that needs to be configured before it is used.
*
Expand Down Expand Up @@ -349,4 +353,18 @@ public static void main(String[] args) throws Exception {
signer.generateSignature(target.toFile());
}
}

@Override
public String signerName() {
return NAME;
}

@Override
public String getKeyInfo() {
Iterator<String> userIds = secretKey.getPublicKey().getUserIDs();
if (userIds.hasNext()) {
return userIds.next();
}
return Hex.toHexString(secretKey.getPublicKey().getFingerprint());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected File getSecretKeys() {
}

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
public void doExecute() throws MojoExecutionException, MojoFailureException {

var signer = newSigner(project);
var keys = KeyStore.create();
Expand Down
Loading