slawekjaranowski commented on code in PR #432: URL: https://github.com/apache/maven-resolver/pull/432#discussion_r1501404200
########## maven-resolver-generator-signer/src/main/java/org/eclipse/aether/generator/signer/SignerArtifactGeneratorFactory.java: ########## @@ -0,0 +1,83 @@ +/* + * 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. + */ +package org.eclipse.aether.generator.signer; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.deployment.DeployRequest; +import org.eclipse.aether.installation.InstallRequest; +import org.eclipse.aether.repository.ArtifactRepository; +import org.eclipse.aether.spi.artifact.generator.ArtifactGenerator; +import org.eclipse.aether.spi.artifact.generator.ArtifactGeneratorFactory; + +@Singleton +@Named(SignerArtifactGeneratorFactory.NAME) +public final class SignerArtifactGeneratorFactory implements ArtifactGeneratorFactory { Review Comment: It is only one implementation of `SignerArtifactGeneratorFactory` why we put it in new module ... maybe should be in `maven-resolver-impl` ########## maven-resolver-generator-signer/src/main/java/org/eclipse/aether/generator/signer/SignerFactory.java: ########## @@ -0,0 +1,40 @@ +/* + * 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. + */ +package org.eclipse.aether.generator.signer; + +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.repository.ArtifactRepository; + +/** + * Component creating {@link Signer} instances. + * + * @since 2.0.0 + */ +public interface SignerFactory { Review Comment: next factory similar to `ArtifactGeneratorFactory` ########## maven-resolver-demos/maven-resolver-demo-snippets/pom.xml: ########## @@ -34,8 +34,8 @@ <properties> <Automatic-Module-Name>org.apache.maven.resolver.demo.snippets</Automatic-Module-Name> - <!-- To make Jetty work --> - <javaVersion>11</javaVersion> + <!-- To make Jetty + generator-signer work --> + <javaVersion>17</javaVersion> Review Comment: I only see that `UnixDomainSocketAddress` used in `GpgAgentPasswordLoader` requres JDK 16+ so I don't see connections with Jetty ########## maven-resolver-generator-signer/src/main/java/org/eclipse/aether/generator/signer/SignerArtifactGenerator.java: ########## @@ -0,0 +1,73 @@ +/* + * 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. + */ +package org.eclipse.aether.generator.signer; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; + +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.spi.artifact.generator.ArtifactGenerator; + +import static java.util.Objects.requireNonNull; + +final class SignerArtifactGenerator implements ArtifactGenerator { + private final ArrayList<Artifact> artifacts; + private final Collection<Signer> signers; + + SignerArtifactGenerator(Collection<Artifact> artifacts, Collection<Signer> signers) { + this.artifacts = new ArrayList<>(artifacts); + this.signers = signers; + } + + @Override + public String generatorId() { + return SignerArtifactGeneratorFactory.NAME; + } + + @Override + public Collection<? extends Artifact> generate(Collection<? extends Artifact> generatedArtifacts) { + try { + artifacts.addAll(generatedArtifacts); + ArrayList<Artifact> signatures = new ArrayList<>(); + for (Signer signer : signers) { + Collection<Artifact> s = signer.sign(artifacts); + signatures.addAll(s.stream() + .map(a -> { + HashMap<String, String> properties = new HashMap<>(a.getProperties()); + properties.put( + SignerArtifactGeneratorFactory.ARTIFACT_SIGNER_ID, Review Comment: This property `ARTIFACT_SIGNER_ID` is only used in this place .... why we add it? ########## maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultDeployer.java: ########## @@ -151,7 +162,23 @@ private DeployResult deploy(SyncContext syncContext, RepositorySystemSession ses throw new DeploymentException("Failed to deploy artifacts/metadata: " + e.getMessage(), e); } + List<Artifact> artifacts = new ArrayList<>(request.getArtifacts()); + List<? extends ArtifactGenerator> artifactGenerators = getArtifactGenerators(session, request); try { + List<Artifact> generatedArtifacts = new ArrayList<>(); + for (ArtifactGenerator artifactGenerator : artifactGenerators) { + Collection<? extends Artifact> generated = artifactGenerator.generate(generatedArtifacts); Review Comment: `generatedArtifacts` is an empty list at beginning - so how we discover artifacts to sign in `artifactGenerator.generate` ########## maven-resolver-generator-signer/src/main/java/org/eclipse/aether/generator/signer/gpg/GpgSignerFactory.java: ########## @@ -0,0 +1,206 @@ +/* + * 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. + */ +package org.eclipse.aether.generator.signer.gpg; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Map; + +import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags; +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.PGPSignatureSubpacketGenerator; +import org.bouncycastle.openpgp.PGPSignatureSubpacketVector; +import org.bouncycastle.openpgp.PGPUtil; +import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; +import org.bouncycastle.openpgp.operator.bc.BcPBESecretKeyDecryptorBuilder; +import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider; +import org.eclipse.aether.ConfigurationProperties; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.generator.signer.SignerFactory; +import org.eclipse.aether.repository.ArtifactRepository; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.spi.connector.layout.RepositoryLayout; +import org.eclipse.aether.spi.connector.layout.RepositoryLayoutProvider; +import org.eclipse.aether.transfer.NoRepositoryLayoutException; +import org.eclipse.aether.util.ConfigUtils; + +import static org.eclipse.aether.generator.signer.gpg.GpgConfigurationKeys.CONFIG_PROP_KEY_ID; + +/** + * GnuPG signer factory implementation, that is active only for {@link RemoteRepository}ies. + */ +@Singleton +@Named(GpgSignerFactory.NAME) +public final class GpgSignerFactory implements SignerFactory { + public static final String NAME = GpgConfigurationKeys.NAME; + private static final String SIGNER_KEY = GpgSignerFactory.class.getName() + ".signer"; Review Comment: unused constant ########## maven-resolver-generator-signer/src/main/java/org/eclipse/aether/generator/signer/gpg/GpgSignerFactory.java: ########## @@ -0,0 +1,206 @@ +/* + * 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. + */ +package org.eclipse.aether.generator.signer.gpg; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Map; + +import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags; +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.PGPSignatureSubpacketGenerator; +import org.bouncycastle.openpgp.PGPSignatureSubpacketVector; +import org.bouncycastle.openpgp.PGPUtil; +import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; +import org.bouncycastle.openpgp.operator.bc.BcPBESecretKeyDecryptorBuilder; +import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider; +import org.eclipse.aether.ConfigurationProperties; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.generator.signer.SignerFactory; +import org.eclipse.aether.repository.ArtifactRepository; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.spi.connector.layout.RepositoryLayout; +import org.eclipse.aether.spi.connector.layout.RepositoryLayoutProvider; +import org.eclipse.aether.transfer.NoRepositoryLayoutException; +import org.eclipse.aether.util.ConfigUtils; + +import static org.eclipse.aether.generator.signer.gpg.GpgConfigurationKeys.CONFIG_PROP_KEY_ID; + +/** + * GnuPG signer factory implementation, that is active only for {@link RemoteRepository}ies. + */ +@Singleton +@Named(GpgSignerFactory.NAME) +public final class GpgSignerFactory implements SignerFactory { + public static final String NAME = GpgConfigurationKeys.NAME; + private static final String SIGNER_KEY = GpgSignerFactory.class.getName() + ".signer"; + + public interface KeyRingMaterialLoader { + /** + * Loads the key ring material, or {@code null}. + */ + byte[] load(RepositorySystemSession session) throws IOException; + } + + public interface KeyPasswordLoader { + /** + * Returns {@code true} if this component requires user interactivity. + */ + boolean isInteractive(); + + /** + * Returns the key password, or {@code null}. + */ + char[] load(RepositorySystemSession session, long keyId) throws IOException; + } + + private final RepositoryLayoutProvider repositoryLayoutProvider; + private final Map<String, KeyRingMaterialLoader> keyMaterialLoaders; + private final Map<String, KeyPasswordLoader> keyPasswordLoaders; + + @Inject + public GpgSignerFactory( + RepositoryLayoutProvider repositoryLayoutProvider, + Map<String, KeyRingMaterialLoader> keyMaterialLoaders, + Map<String, KeyPasswordLoader> keyPasswordLoaders) { + this.repositoryLayoutProvider = repositoryLayoutProvider; + this.keyMaterialLoaders = keyMaterialLoaders; + this.keyPasswordLoaders = keyPasswordLoaders; + } + + @Override + public GpgSigner createSigner(RepositorySystemSession session, ArtifactRepository artifactRepository) { + final boolean enabled = ConfigUtils.getBoolean( + session, GpgConfigurationKeys.DEFAULT_ENABLED, GpgConfigurationKeys.CONFIG_PROP_ENABLED) + && (artifactRepository instanceof RemoteRepository); + if (!enabled) { + return null; + } + + try { + return doCreateSigner(session, repositoryLayoutProvider.newRepositoryLayout(session, (RemoteRepository) + artifactRepository)); + } catch (NoRepositoryLayoutException e) { + throw new IllegalArgumentException(e); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + private GpgSigner doCreateSigner(RepositorySystemSession session, RepositoryLayout repositoryLayout) + throws IOException { + boolean interactive = ConfigUtils.getBoolean( + session, ConfigurationProperties.DEFAULT_INTERACTIVE, ConfigurationProperties.INTERACTIVE); + + byte[] keyRingMaterial = null; + for (KeyRingMaterialLoader loader : keyMaterialLoaders.values()) { + keyRingMaterial = loader.load(session); + if (keyRingMaterial != null) { + break; + } + } + if (keyRingMaterial == null) { + throw new IllegalArgumentException("Key ring material not found"); + } + + Long keyId = null; + String keyIdStr = ConfigUtils.getString(session, null, CONFIG_PROP_KEY_ID); Review Comment: `keyId` should also be provided by environment value -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org