You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2020/11/01 11:36:31 UTC
[maven-studies] 04/15: First working version
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch maven-sign-plugin
in repository https://gitbox.apache.org/repos/asf/maven-studies.git
commit 88f3a767149cf8c2ec8cf98be08884ab455e55eb
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Sun Oct 4 11:16:34 2020 +0200
First working version
---
README.md | 16 ++
pom.xml | 71 +++++++-
.../invoker.properties | 2 +-
.../{standard-packaging => pom-packaging}/pom.xml | 13 +-
src/it/settings.xml | 13 ++
src/it/standard-packaging/invoker.properties | 2 +-
src/it/standard-packaging/pom.xml | 36 +++-
src/it/standard-packaging/test.dat | 1 +
.../plugins/sign/PGPSecretKeyInfoFromSettings.java | 68 ++++++++
.../org/apache/maven/plugins/sign/SignMojo.java | 190 +++++++++++++--------
.../org/apache/maven/plugins/sign/SignResult.java | 41 +++++
.../maven/plugins/sign/pgp/PGPSecretKeyInfo.java | 47 +++++
.../apache/maven/plugins/sign/pgp/PGPSigner.java | 151 ++++++++++++++++
.../maven/plugins/sign/pgp/PGPSignerException.java | 40 +++++
.../sign/PGPSecretKeyInfoFromSettingsTest.java | 76 +++++++++
.../maven/plugins/sign/pgp/PGPSignerTest.java | 97 +++++++++++
src/test/resources/pgp-priv-key.asc | 83 +++++++++
src/test/resources/pgp-public-key.asc | 41 +++++
src/test/resources/settings-security.xml | 4 +
19 files changed, 889 insertions(+), 103 deletions(-)
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..eeaf82f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,16 @@
+# PGP sign plugin
+
+Create PGP signature for all artifacts in maven project
+
+## Assumptions
+ - first version require maven 3.7.0-SNAPSHOT
+ - use build/consumer feature
+
+## TODO
+ - documentations
+ - check if all artifacts are ready to sign - if package goal was running
+ - verify password encryption in settings.xml
+ - detect expired key
+ - signing by sub key
+ - review it test from GPG plugin - maybe some case should be addressed
+ - decision - if we should move pgp code to external project
diff --git a/pom.xml b/pom.xml
index 0f4885e..f208d91 100644
--- a/pom.xml
+++ b/pom.xml
@@ -56,7 +56,7 @@
</distributionManagement>
<properties>
- <mavenVersion>3.6.0</mavenVersion>
+ <mavenVersion>3.7.0-SNAPSHOT</mavenVersion>
<javaVersion>8</javaVersion>
</properties>
@@ -88,15 +88,72 @@
</dependency>
<dependency>
+ <groupId>org.bouncycastle</groupId>
+ <artifactId>bcpg-jdk15on</artifactId>
+ <version>1.66</version>
+ </dependency>
+
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.13</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>3.5.10</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.7.30</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
- <profiles>
+ <build>
+
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>src/test/resources*/**</exclude>
+ <exclude>README.md</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <!-- update extra-enforcer-rules version - old throw NPE for BC -->
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>extra-enforcer-rules</artifactId>
+ <version>1.3</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+
+ </build>
+ <profiles>
<profile>
<id>run-its</id>
<build>
@@ -105,18 +162,18 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<configuration>
- <goals>
- <goal>install</goal>
- </goals>
- <debug>true</debug>
+ <debug>false</debug>
<showErrors>true</showErrors>
<showVersion>true</showVersion>
<streamLogs>true</streamLogs>
+ <properties>
+ <settings.security>${project.basedir}/src/test/resources/settings-security.xml</settings.security>
+ </properties>
</configuration>
</plugin>
</plugins>
</build>
</profile>
-
</profiles>
+
</project>
diff --git a/src/it/standard-packaging/invoker.properties b/src/it/pom-packaging/invoker.properties
similarity index 91%
copy from src/it/standard-packaging/invoker.properties
copy to src/it/pom-packaging/invoker.properties
index 07fd24e..1113391 100644
--- a/src/it/standard-packaging/invoker.properties
+++ b/src/it/pom-packaging/invoker.properties
@@ -17,5 +17,5 @@
# under the License.
#
-invoker.goals = install -Drevision=1.1.1-SNAPSHOT
+invoker.goals = install --no-transfer-progress -Drevision=1.1.1-SNAPSHOT
diff --git a/src/it/standard-packaging/pom.xml b/src/it/pom-packaging/pom.xml
similarity index 85%
copy from src/it/standard-packaging/pom.xml
copy to src/it/pom-packaging/pom.xml
index e4cda5c..0d2a078 100644
--- a/src/it/standard-packaging/pom.xml
+++ b/src/it/pom-packaging/pom.xml
@@ -27,9 +27,11 @@
<groupId>test-group</groupId>
<artifactId>test1</artifactId>
<version>${revision}</version>
+ <packaging>pom</packaging>
<build>
<plugins>
+
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-sign-plugin</artifactId>
@@ -37,7 +39,6 @@
<executions>
<execution>
- <id>with-reflection</id>
<goals>
<goal>sign</goal>
</goals>
@@ -46,16 +47,6 @@
</configuration>
</execution>
- <execution>
- <id>with-method-call</id>
- <goals>
- <goal>sign</goal>
- </goals>
- <configuration>
- <useReflection>false</useReflection>
- </configuration>
- </execution>
-
</executions>
</plugin>
</plugins>
diff --git a/src/it/settings.xml b/src/it/settings.xml
index 28f9d85..c79c1a8 100644
--- a/src/it/settings.xml
+++ b/src/it/settings.xml
@@ -52,4 +52,17 @@
</pluginRepositories>
</profile>
</profiles>
+
+ <servers>
+
+ <server>
+ <id>pgpKey</id>
+ <username>AC71B3E31C0C0D38</username>
+ <privateKey>@project.basedir@/src/test/resources/pgp-priv-key.asc</privateKey>
+ <!-- testPass -->
+ <!-- passphrase>{sM9eNH++jOkHSAUJGpZe6pSpJi7Z9l8hZII8w9GPSFs=}</passphrase -->
+ <passphrase>testPass</passphrase>
+ </server>
+
+ </servers>
</settings>
diff --git a/src/it/standard-packaging/invoker.properties b/src/it/standard-packaging/invoker.properties
index 07fd24e..1113391 100644
--- a/src/it/standard-packaging/invoker.properties
+++ b/src/it/standard-packaging/invoker.properties
@@ -17,5 +17,5 @@
# under the License.
#
-invoker.goals = install -Drevision=1.1.1-SNAPSHOT
+invoker.goals = install --no-transfer-progress -Drevision=1.1.1-SNAPSHOT
diff --git a/src/it/standard-packaging/pom.xml b/src/it/standard-packaging/pom.xml
index e4cda5c..059e8ce 100644
--- a/src/it/standard-packaging/pom.xml
+++ b/src/it/standard-packaging/pom.xml
@@ -30,29 +30,47 @@
<build>
<plugins>
+
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-sign-plugin</artifactId>
- <version>@project.version@</version>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>3.2.0</version>
<executions>
-
<execution>
- <id>with-reflection</id>
+ <id>attach-artifacts</id>
+ <phase>package</phase>
<goals>
- <goal>sign</goal>
+ <goal>attach-artifact</goal>
</goals>
<configuration>
- <useReflection>true</useReflection>
+ <artifacts>
+ <artifact>
+ <file>test.dat</file>
+ <type>dat</type>
+ </artifact>
+ <artifact>
+ <file>test.dat</file>
+ <type>dat</type>
+ <classifier>c1</classifier>
+ </artifact>
+ </artifacts>
</configuration>
</execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-sign-plugin</artifactId>
+ <version>@project.version@</version>
+ <executions>
<execution>
- <id>with-method-call</id>
<goals>
<goal>sign</goal>
</goals>
<configuration>
- <useReflection>false</useReflection>
+ <useReflection>true</useReflection>
</configuration>
</execution>
diff --git a/src/it/standard-packaging/test.dat b/src/it/standard-packaging/test.dat
new file mode 100644
index 0000000..082b346
--- /dev/null
+++ b/src/it/standard-packaging/test.dat
@@ -0,0 +1 @@
+test data
diff --git a/src/main/java/org/apache/maven/plugins/sign/PGPSecretKeyInfoFromSettings.java b/src/main/java/org/apache/maven/plugins/sign/PGPSecretKeyInfoFromSettings.java
new file mode 100644
index 0000000..1e27276
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/sign/PGPSecretKeyInfoFromSettings.java
@@ -0,0 +1,68 @@
+package org.apache.maven.plugins.sign;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.plugins.sign.pgp.PGPSecretKeyInfo;
+import org.apache.maven.settings.Server;
+
+import java.io.File;
+import java.math.BigInteger;
+import java.util.Objects;
+
+/**
+ * Information about pgp key from settings server
+ *
+ * @author Slawomir Jaranowski
+ */
+public class PGPSecretKeyInfoFromSettings implements PGPSecretKeyInfo
+{
+
+ private final Server settingsServer;
+
+ PGPSecretKeyInfoFromSettings( Server settingsServer )
+ {
+ this.settingsServer = Objects.requireNonNull( settingsServer );
+ }
+
+ @Override
+ public Long getKeyId()
+ {
+ try
+ {
+ return new BigInteger( settingsServer.getUsername(), 16 ).longValue();
+ }
+ catch ( NumberFormatException e )
+ {
+ return null;
+ }
+ }
+
+ @Override
+ public char[] getPassphrase()
+ {
+ return settingsServer.getPassphrase().toCharArray();
+ }
+
+ @Override
+ public File getFile()
+ {
+ return new File( settingsServer.getPrivateKey() );
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/sign/SignMojo.java b/src/main/java/org/apache/maven/plugins/sign/SignMojo.java
index 19dcf43..0c9c8e4 100644
--- a/src/main/java/org/apache/maven/plugins/sign/SignMojo.java
+++ b/src/main/java/org/apache/maven/plugins/sign/SignMojo.java
@@ -19,31 +19,38 @@ package org.apache.maven.plugins.sign;
* under the License.
*/
+import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
+import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.sign.pgp.PGPSigner;
+import org.apache.maven.plugins.sign.pgp.PGPSignerException;
import org.apache.maven.project.MavenProject;
-import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.artifact.DefaultArtifact;
+import org.apache.maven.project.MavenProjectHelper;
+import org.apache.maven.project.artifact.ProjectArtifact;
import org.eclipse.aether.transform.FileTransformer;
-import org.eclipse.aether.transform.FileTransformerManager;
-import java.io.BufferedReader;
-import java.io.File;
+import javax.inject.Inject;
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.stream.Collectors;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
/**
* Sign project artifacts.
+ *
+ * @author Slawomir Jaranowski
*/
@Slf4j
@Mojo( name = "sign", defaultPhase = LifecyclePhase.VERIFY )
@@ -56,95 +63,130 @@ public class SignMojo extends AbstractMojo
@Parameter( defaultValue = "${session}", required = true, readonly = true )
protected MavenSession session;
- @Parameter( defaultValue = "${repositorySystemSession}", readonly = true )
- private RepositorySystemSession repoSession;
+ @Inject
+ private MavenProjectHelper projectHelper;
- @Parameter
- private boolean useReflection;
+ private PGPSigner pgpSigner;
@Override
public void execute() throws MojoExecutionException
{
+ try
+ {
+ pgpSigner = new PGPSigner(
+ new PGPSecretKeyInfoFromSettings( session.getSettings().getServer( "pgpKey" ) ) );
+ }
+ catch ( PGPSignerException e )
+ {
+ throw new MojoExecutionException( e.getMessage(), e );
+ }
+
+ // collect artifact to sign
+ Set<Artifact> artifactsToSign = new HashSet<>();
+
+ artifactsToSign.add( new ProjectArtifact( project ) );
+ artifactsToSign.add( project.getArtifact() );
+ artifactsToSign.addAll( project.getAttachedArtifacts() );
+ // sign and attach signature to project
+ artifactsToSign.stream()
+ .map( this::signArtefact )
+ .flatMap( List::stream )
+ .forEach( this::attacheSignResult );
+ }
+
+ /**
+ * Sign given artifact. In result we can have many signatures, transformers can produce multiple output for one
+ * artifact.
+ * <p>
+ * This method ask transformers for inputStream for all artifact mutations, and sign each stream.
+ *
+ * @param artifact artifact to sign
+ * @return sign result
+ */
+ @SneakyThrows
+ private List<SignResult> signArtefact( Artifact artifact )
+ {
+ LOGGER.info( "Sign artifact: {}", artifact );
- LOGGER.info( "session: {}", session );
- LOGGER.info( "repoSession: {}", repoSession );
- LOGGER.info( "Artifact : {}", project.getArtifact() );
- LOGGER.info( "AttachedArtifacts: {}", project.getAttachedArtifacts() );
- LOGGER.info( "project.getFile: {}", project.getFile() );
+ org.eclipse.aether.artifact.Artifact srcArtifact = new org.eclipse.aether.artifact.DefaultArtifact(
+ artifact.getGroupId(),
+ artifact.getArtifactId(),
+ artifact.getClassifier(),
+ artifact.getArtifactHandler().getExtension(),
+ artifact.getVersion(),
+ null,
+ artifact.getFile() );
- Artifact pomArtifact = new DefaultArtifact( project.getArtifact().getGroupId(),
- project.getArtifact().getArtifactId(), "", // classifier
- "pom", project.getArtifact().getVersion() );
- pomArtifact = pomArtifact.setFile( project.getFile() );
+ Collection<FileTransformer> transformersForArtifact = session.getRepositorySession().getFileTransformerManager()
+ .getTransformersForArtifact( srcArtifact );
+ List<SignResult> result = new ArrayList<>();
- if ( useReflection )
+ if ( transformersForArtifact.isEmpty() )
{
- try
- {
- getFileTransformerFromReflection( repoSession, pomArtifact );
- }
- catch ( NoSuchMethodException nme )
- {
- LOGGER.info( " noSuchMethod: {}", nme.getMessage(), nme );
- }
- catch ( InvocationTargetException | IllegalAccessException e )
- {
- throw new MojoExecutionException( e.getMessage(), e );
- }
+ result.add( makeSign( new BufferedInputStream( new FileInputStream( srcArtifact.getFile() ) ),
+ srcArtifact.getArtifactId(),
+ srcArtifact.getClassifier(),
+ srcArtifact.getExtension() ) );
}
else
{
- getFileTransformerFromMethodCall( repoSession, pomArtifact );
+ for ( FileTransformer fileTransformer : transformersForArtifact )
+ {
+ org.eclipse.aether.artifact.Artifact dstArtifact = fileTransformer.transformArtifact( srcArtifact );
+ result.add( makeSign( fileTransformer.transformData( srcArtifact.getFile() ),
+ dstArtifact.getArtifactId(),
+ dstArtifact.getClassifier(),
+ dstArtifact.getExtension() ) );
+ }
}
- }
-
- private void getFileTransformerFromMethodCall( RepositorySystemSession repoSession, Artifact pomArtifact )
- {
- LOGGER.info( " -> getFileTransformerFromMethodCall" );
- FileTransformerManager fileTransformerManager = repoSession.getFileTransformerManager();
- Collection<FileTransformer> transformersForArtifact = fileTransformerManager
- .getTransformersForArtifact( pomArtifact );
-
- LOGGER.info( " -> transformers: {}", transformersForArtifact );
+ return result;
}
- private void getFileTransformerFromReflection( RepositorySystemSession repoSession, Artifact pomArtifact )
- throws NoSuchMethodException, InvocationTargetException, IllegalAccessException
+ /**
+ * Sign given input stream. In result we will have file with signature.
+ *
+ * @param inputStream data to sign
+ * @param artifactId used for build filename
+ * @param classifier used for build filename
+ * @param extension used for build filename
+ * @return result of signing
+ * @throws PGPSignerException if some thing wrong
+ */
+ private SignResult makeSign( InputStream inputStream, String artifactId, String classifier, String extension )
+ throws PGPSignerException
{
- LOGGER.info( " -> getFileTransformerFromReflection" );
- Method getFileTransformerManagerMethod = repoSession.getClass().getMethod( "getFileTransformerManager" );
- LOGGER.info( " -> getFileTransformerManagerMethod : {}", getFileTransformerManagerMethod );
+ String targetExt = extension + ".asc";
- Object fileTransformerManager = getFileTransformerManagerMethod.invoke( repoSession );
- LOGGER.info( " -> fileTransformerManager: {}", fileTransformerManager );
- if ( fileTransformerManager == null )
+ String targetName = artifactId;
+ if ( classifier != null && !classifier.isEmpty() )
{
- return;
+ targetName += "-" + classifier;
}
+ targetName += "." + targetExt;
- Method getTransformersForArtifactMethod = fileTransformerManager.getClass()
- .getMethod( "getTransformersForArtifact", Artifact.class );
+ Path target = Paths.get( project.getBuild().getDirectory(), targetName );
- LOGGER.info( " -> getTransformersForArtifactMethod : {}", getTransformersForArtifactMethod );
- getTransformersForArtifactMethod.setAccessible( true );
- Collection<?> transformersForArtifact = (Collection<?>) getTransformersForArtifactMethod
- .invoke( fileTransformerManager, pomArtifact );
- LOGGER.info( " -> transformersForArtifact: {}", transformersForArtifact );
+ pgpSigner.sign( inputStream, target );
- // what to do - if have more then one transformer ???
- for ( Object o : transformersForArtifact )
- {
- LOGGER.info( " -> transformer: {}", o );
- Method transformDataMethod = o.getClass().getMethod( "transformData", File.class );
- transformDataMethod.setAccessible( true );
- InputStream inputStream = (InputStream) transformDataMethod.invoke( o, pomArtifact.getFile() );
- String outPom = new BufferedReader( new InputStreamReader( inputStream ) ).lines()
- .collect( Collectors.joining( "\n" ) );
- LOGGER.info( "outPom:\n{}", outPom );
- }
+ return SignResult.builder()
+ .classifier( classifier )
+ .extension( targetExt )
+ .file( target.toFile() )
+ .build();
+ }
+
+ /**
+ * Attache sign result to project.
+ */
+ private void attacheSignResult( SignResult signResult )
+ {
+ LOGGER.info( "Attache signature: {}", signResult );
+
+ projectHelper
+ .attachArtifact( project, signResult.getExtension(), signResult.getClassifier(), signResult.getFile() );
}
}
diff --git a/src/main/java/org/apache/maven/plugins/sign/SignResult.java b/src/main/java/org/apache/maven/plugins/sign/SignResult.java
new file mode 100644
index 0000000..3cc2031
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/sign/SignResult.java
@@ -0,0 +1,41 @@
+package org.apache.maven.plugins.sign;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import lombok.Builder;
+import lombok.ToString;
+import lombok.Value;
+
+import java.io.File;
+
+/**
+ * Result of signing artifact.
+ *
+ * @author Slawomir Jaranowski
+ */
+@Value
+@Builder
+@ToString
+public class SignResult
+{
+ String classifier;
+ String extension;
+ File file;
+}
diff --git a/src/main/java/org/apache/maven/plugins/sign/pgp/PGPSecretKeyInfo.java b/src/main/java/org/apache/maven/plugins/sign/pgp/PGPSecretKeyInfo.java
new file mode 100644
index 0000000..d319c3a
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/sign/pgp/PGPSecretKeyInfo.java
@@ -0,0 +1,47 @@
+package org.apache.maven.plugins.sign.pgp;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+
+/**
+ * Secret key info.
+ *
+ * @author Slawomir Jaranowski
+ */
+public interface PGPSecretKeyInfo
+{
+ /**
+ * Fingerprint of signing key
+ * @return fingerprint
+ */
+ Long getKeyId();
+
+ char[] getPassphrase();
+
+ /**
+ * Filename with secret key
+ * @return filename of secret key
+ */
+ File getFile();
+
+
+
+}
diff --git a/src/main/java/org/apache/maven/plugins/sign/pgp/PGPSigner.java b/src/main/java/org/apache/maven/plugins/sign/pgp/PGPSigner.java
new file mode 100644
index 0000000..6a874b4
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/sign/pgp/PGPSigner.java
@@ -0,0 +1,151 @@
+package org.apache.maven.plugins.sign.pgp;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import lombok.extern.slf4j.Slf4j;
+import org.bouncycastle.bcpg.ArmoredOutputStream;
+import org.bouncycastle.bcpg.BCPGOutputStream;
+import org.bouncycastle.bcpg.HashAlgorithmTags;
+import org.bouncycastle.openpgp.PGPException;
+import org.bouncycastle.openpgp.PGPPrivateKey;
+import org.bouncycastle.openpgp.PGPSecretKey;
+import org.bouncycastle.openpgp.PGPSecretKeyRing;
+import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
+import org.bouncycastle.openpgp.PGPSignature;
+import org.bouncycastle.openpgp.PGPSignatureGenerator;
+import org.bouncycastle.openpgp.PGPUtil;
+import org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator;
+import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder;
+import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Signig data by PGP.
+ *
+ * @author Slawomir Jaranowski
+ */
+@Slf4j
+public class PGPSigner
+{
+
+ private final PGPSecretKeyInfo keyInfo;
+
+ private PGPSecretKey secretKey;
+ private PGPPrivateKey pgpPrivateKey;
+
+ public PGPSigner( PGPSecretKeyInfo keyInfo ) throws PGPSignerException
+ {
+
+ this.keyInfo = keyInfo;
+ try
+ {
+ loadKey();
+ }
+ catch ( IOException | PGPException e )
+ {
+ throw new PGPSignerException( e );
+ }
+
+ List<String> uIds = new ArrayList<>();
+ secretKey.getUserIDs().forEachRemaining( uIds::add );
+
+ LOGGER.info( "Loaded keyId: {}, uIds: {}", String.format( "%16X", secretKey.getKeyID() ), uIds );
+ }
+
+ /**
+ * Find and load private key form file.
+ */
+ private void loadKey() throws IOException, PGPException, PGPSignerException
+ {
+ InputStream inputStream = PGPUtil.getDecoderStream( new FileInputStream( keyInfo.getFile() ) );
+ PGPSecretKeyRingCollection pgpSecretKeyRingCollection = new PGPSecretKeyRingCollection( inputStream,
+ new JcaKeyFingerprintCalculator() );
+
+ Long keyId = keyInfo.getKeyId();
+ if ( keyId != null )
+ {
+ secretKey = pgpSecretKeyRingCollection.getSecretKey( keyId );
+ }
+ else
+ {
+ // retrieve first master key
+ Iterator<PGPSecretKeyRing> keyRings = pgpSecretKeyRingCollection.getKeyRings();
+ if ( keyRings.hasNext() )
+ {
+ PGPSecretKeyRing secretKeys = keyRings.next();
+ secretKey = secretKeys.getSecretKey();
+ }
+ }
+
+ if ( secretKey == null )
+ {
+ throw new PGPSignerException( "Secret key not found" );
+ }
+
+ pgpPrivateKey = secretKey
+ .extractPrivateKey( new JcePBESecretKeyDecryptorBuilder().build( keyInfo.getPassphrase() ) );
+ }
+
+ /**
+ * Generate PGP signature for a given input stream.
+ *
+ * @param inputStream stream with data to calculate signature
+ * @param outputPath a destination of signature
+ * @throws PGPSignerException if some IO problems
+ */
+ public void sign( InputStream inputStream, Path outputPath ) throws PGPSignerException
+ {
+
+ PGPSignatureGenerator sGen = new PGPSignatureGenerator(
+ new JcaPGPContentSignerBuilder( secretKey.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA256 ) );
+
+ try
+ {
+ sGen.init( PGPSignature.BINARY_DOCUMENT, pgpPrivateKey );
+
+ int i;
+ while ( ( i = inputStream.read() ) >= 0 )
+ {
+ sGen.update( (byte) i );
+ }
+
+ Files.createDirectories( outputPath.getParent() );
+
+ try ( OutputStream out = Files.newOutputStream( outputPath );
+ BCPGOutputStream bcpgOutputStream = new BCPGOutputStream( new ArmoredOutputStream( out ) ) )
+ {
+ sGen.generate().encode( bcpgOutputStream );
+ }
+ }
+ catch ( PGPException | IOException e )
+ {
+ throw new PGPSignerException( e );
+ }
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/sign/pgp/PGPSignerException.java b/src/main/java/org/apache/maven/plugins/sign/pgp/PGPSignerException.java
new file mode 100644
index 0000000..29b9d49
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/sign/pgp/PGPSignerException.java
@@ -0,0 +1,40 @@
+package org.apache.maven.plugins.sign.pgp;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Exception during signing process
+ *
+ * @author Slawomir Jaranowski
+ */
+public class PGPSignerException extends Exception
+{
+ private static final long serialVersionUID = 6613555179186499887L;
+
+ public PGPSignerException( Throwable cause )
+ {
+ super( cause );
+ }
+
+ public PGPSignerException( String message )
+ {
+ super( message );
+ }
+}
diff --git a/src/test/java/org/apache/maven/plugins/sign/PGPSecretKeyInfoFromSettingsTest.java b/src/test/java/org/apache/maven/plugins/sign/PGPSecretKeyInfoFromSettingsTest.java
new file mode 100644
index 0000000..c013703
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/sign/PGPSecretKeyInfoFromSettingsTest.java
@@ -0,0 +1,76 @@
+package org.apache.maven.plugins.sign;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+import org.apache.maven.settings.Server;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.io.File;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
+import static org.mockito.Mockito.when;
+
+@RunWith( MockitoJUnitRunner.class )
+public class PGPSecretKeyInfoFromSettingsTest
+{
+
+ private static final String KEY_ID_HEX = "ABCDEF0123456789";
+ private static final long KEY_ID = 0xABCDEF0123456789L;
+
+ private static final String KEY_FILE_STR = "test.asc";
+ private static final File KEY_FILE = new File( KEY_FILE_STR );
+
+ private static final String KEY_PASS_STR = "pass";
+ private static final char[] KEY_PASS = KEY_PASS_STR.toCharArray();
+
+ @Mock
+ private Server server;
+
+ @Test
+ public void allProperties()
+ {
+ // given
+ when( server.getUsername() ).thenReturn( KEY_ID_HEX );
+ when( server.getPrivateKey() ).thenReturn( KEY_FILE_STR );
+ when( server.getPassphrase() ).thenReturn( KEY_PASS_STR );
+
+ // when
+ PGPSecretKeyInfoFromSettings info = new PGPSecretKeyInfoFromSettings( server );
+
+ // then
+ assertThat( info.getKeyId(), is( KEY_ID ) );
+ assertThat( info.getFile(), is( KEY_FILE ) );
+ assertThat( info.getPassphrase(), is( KEY_PASS ) );
+ }
+
+ @Test
+ public void npeShouldBeThrowForNullServer()
+ {
+ assertThrows( NullPointerException.class,
+ () -> new PGPSecretKeyInfoFromSettings( null ) );
+ }
+
+}
diff --git a/src/test/java/org/apache/maven/plugins/sign/pgp/PGPSignerTest.java b/src/test/java/org/apache/maven/plugins/sign/pgp/PGPSignerTest.java
new file mode 100644
index 0000000..7ffe2e2
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/sign/pgp/PGPSignerTest.java
@@ -0,0 +1,97 @@
+package org.apache.maven.plugins.sign.pgp;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import lombok.extern.slf4j.Slf4j;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.io.File;
+
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.when;
+
+@Slf4j
+@RunWith( MockitoJUnitRunner.class )
+public class PGPSignerTest
+{
+
+ @Mock
+ private PGPSecretKeyInfo keyInfo;
+
+ @Test
+ public void loadKeyWithAllProperties()
+ {
+
+ // given
+ when( keyInfo.getFile() )
+ .thenReturn( new File( getClass().getResource( "/pgp-priv-key.asc" ).getFile() ) );
+ when( keyInfo.getKeyId() ).thenReturn( 0xAC71B3E31C0C0D38L );
+ when( keyInfo.getPassphrase() ).thenReturn( "testPass".toCharArray() );
+
+ Exception throwException = null;
+
+ // when
+ try
+ {
+ new PGPSigner( keyInfo );
+
+ }
+ catch ( Exception e )
+ {
+ throwException = e;
+ LOGGER.info( "{}", e.getMessage(), e );
+ }
+
+ // then
+ assertNull( throwException );
+ }
+
+ @Test
+ public void loadDefaultKey()
+ {
+
+ // given
+ when( keyInfo.getFile() )
+ .thenReturn( new File( getClass().getResource( "/pgp-priv-key.asc" ).getFile() ) );
+ when( keyInfo.getKeyId() ).thenReturn( null );
+ when( keyInfo.getPassphrase() ).thenReturn( "testPass".toCharArray() );
+
+ Exception throwException = null;
+
+ // when
+ try
+ {
+ new PGPSigner( keyInfo );
+
+ }
+ catch ( Exception e )
+ {
+ throwException = e;
+ LOGGER.info( "{}", e.getMessage(), e );
+ }
+
+ // then
+ assertNull( throwException );
+ }
+
+}
diff --git a/src/test/resources/pgp-priv-key.asc b/src/test/resources/pgp-priv-key.asc
new file mode 100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eW6DgD7syhUp8xOKVHeHAd4GrK
+FITSf7nIigqvWeK5daWDx7Fq/HuoimvS0u7mEcoRb7b9vOXh0A1LfCJOGTq7OBra
+iOR8CdmnaDkMe9j01dJx9mW7dyl72MvDy7mYNG+01RSc2icuogMFr9YqWfEez5bX
+AckOuKKwXjM9GkC5T8OHi0xKvOqQ5d89Ea0WTCe37opzVvFXq1MnZS70+AJxlXKe
+1ycgUpUoh3RLSMRWQlpx3NVZUNyeAtwtHAqBjp0woJSYfaZJHHRYJqBktRGeaTmZ
+w2hIq+al1i/wKp542EWdpyoK9QH2nNa00KadBclLJitkaFWoFPfHpQVtDp81I+kr
+0oXqkizwpP6tlL/Q7DCzoIkBtgQYAQgAIBYhBLwGXcqpA6d4X/eebqxxs+McDA04
+BQJfeL5fAhsMAAoJEKxxs+McDA048bkL/1Rv9i43SMsWuSLOrg0xh2/QGSC3YPF/
+ywX00/kHmTHPMh2wW1AYE5oIntACP0sjl3XvGtYfOuCQ5P1+Fxokx6+gHikt8d2m
+7f4trtWGHQakwhsKVoj4EpZl2HO34QUAJUc7GdAqBndKOyPfwWHjnOHaspJjmx/c
+yIESPpZsgxtJFeeRJEa+DhjyAti9KDvWUHHvnN+1lCaM2EqJt2qF10u8W9k+bE7U
+WqEkxCUckWlDbSbFbhl8VYrWIzvMgh0PxoFA5Fe6hx9/TjUT+4uzp/viYhKngAo3
+6Mr/JLk6Xi/isbxWTenI/cLgfV01OI3BDNcchEiXyLA7lKmzoL6NjLvdJxhjJJ3b
+8kxoLHVIvj9W2BVkFiQj/t1Ao4f1zGlFosuENYe96OOB0QIfGs8/w97+BcctzpM4
+OA54GKK86kxla2KPxbE9Ya2WwFfKp6AYgGASQQpwYj8wNwUM7riHlEOv095gsNr1
+TnuOuk+PPRNMa/pbsW2Y7IK4wESFu3IJ9Q==
+=dmNK
+-----END PGP PRIVATE KEY BLOCK-----
diff --git a/src/test/resources/pgp-public-key.asc b/src/test/resources/pgp-public-key.asc
new file mode 100644
index 0000000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vWUHHvnN+1lCaM2EqJt2qF10u8W9k+bE7UWqEkxCUckWlDbSbFbhl8VYrW
+IzvMgh0PxoFA5Fe6hx9/TjUT+4uzp/viYhKngAo36Mr/JLk6Xi/isbxWTenI/cLg
+fV01OI3BDNcchEiXyLA7lKmzoL6NjLvdJxhjJJ3b8kxoLHVIvj9W2BVkFiQj/t1A
+o4f1zGlFosuENYe96OOB0QIfGs8/w97+BcctzpM4OA54GKK86kxla2KPxbE9Ya2W
+wFfKp6AYgGASQQpwYj8wNwUM7riHlEOv095gsNr1TnuOuk+PPRNMa/pbsW2Y7IK4
+wESFu3IJ9Q==
+=cXTv
+-----END PGP PUBLIC KEY BLOCK-----
diff --git a/src/test/resources/settings-security.xml b/src/test/resources/settings-security.xml
new file mode 100644
index 0000000..ba4bba5
--- /dev/null
+++ b/src/test/resources/settings-security.xml
@@ -0,0 +1,4 @@
+<settingsSecurity>
+ <!-- masterPass -->
+ <master>{AQdp0H14ZZAHqlyH5GyKbN0GFUh2q4pvBnGqgTxH5RE=}</master>
+</settingsSecurity>