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

[MGPG-115] Show more info about key used to sign #84

Merged
merged 1 commit into from Mar 23, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/org/apache/maven/plugins/gpg/AbstractGpgSigner.java
Expand Up @@ -124,10 +124,24 @@ public void setPublicKeyring(String path) {

public abstract String signerName();

/**
* Must be invoked BEFORE signing!
*
* @since 3.2.0
*/
public void prepare() throws MojoFailureException {}

/**
* Should return some identification about the used key for logging purposes.
* Can be invoked only AFTER {@link #prepare()} was invoked.
*
* @since 3.2.2
*/
public abstract String getKeyInfo();

/**
* Create a detached signature file for the provided file.
* Can be invoked only AFTER {@link #prepare()} was invoked.
*
* @param file The file to sign
* @return A reference to the generated signature file
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/apache/maven/plugins/gpg/BcSigner.java
Expand Up @@ -33,6 +33,7 @@
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -361,6 +362,15 @@ public void prepare() throws MojoFailureException {
}
}

@Override
public String getKeyInfo() {
Iterator<String> userIds = secretKey.getPublicKey().getUserIDs();
if (userIds.hasNext()) {
return userIds.next();
}
return Hex.toHexString(secretKey.getPublicKey().getFingerprint());
}

@Override
protected void generateSignatureForFile(File file, File signature) throws MojoExecutionException {
try (InputStream in = Files.newInputStream(file.toPath());
Expand Down
Expand Up @@ -88,7 +88,7 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException {
signer.setBaseDirectory(project.getBasedir());

getLog().info("Signer '" + signer.signerName() + "' is signing " + items.size() + " file"
+ ((items.size() > 1) ? "s" : ""));
+ ((items.size() > 1) ? "s" : "") + " with key " + signer.getKeyInfo());

for (FilesCollector.Item item : items) {
getLog().debug("Generating signature for " + item.getFile());
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/apache/maven/plugins/gpg/GpgSigner.java
Expand Up @@ -34,7 +34,7 @@
*/
public class GpgSigner extends AbstractGpgSigner {
public static final String NAME = "gpg";
private String executable;
private final String executable;

public GpgSigner(String executable) {
this.executable = executable;
Expand All @@ -45,6 +45,11 @@ public String signerName() {
return NAME;
}

@Override
public String getKeyInfo() {
return keyname != null ? keyname : "default";
}

/**
* {@inheritDoc}
*/
Expand Down
Expand Up @@ -340,7 +340,7 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException {
signer.setBaseDirectory(new File("").getAbsoluteFile());

getLog().info("Signer '" + signer.signerName() + "' is signing " + artifacts.size() + " file"
+ ((artifacts.size() > 1) ? "s" : ""));
+ ((artifacts.size() > 1) ? "s" : "") + " with key " + signer.getKeyInfo());

ArrayList<Artifact> signatures = new ArrayList<>();
for (Artifact a : artifacts) {
Expand Down