cstamas commented on code in PR #432: URL: https://github.com/apache/maven-resolver/pull/432#discussion_r1497444258
########## maven-resolver-generator-signer/src/main/java/org/eclipse/aether/generator/signer/gpg/GpgAgentPasswordLoader.java: ########## @@ -0,0 +1,110 @@ +/* + * 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.Named; +import javax.inject.Singleton; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.SocketException; +import java.net.StandardProtocolFamily; +import java.net.UnixDomainSocketAddress; +import java.nio.channels.Channels; +import java.nio.channels.SocketChannel; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.bouncycastle.util.encoders.Hex; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.sisu.Priority; + +@Singleton +@Named(GpgAgentPasswordLoader.NAME) +@Priority(10) +@SuppressWarnings("checkstyle:magicnumber") +public final class GpgAgentPasswordLoader implements GpgSignerFactory.KeyPasswordLoader { + public static final String NAME = "agent"; + private static final String[] SOCKET_LOCATIONS = new String[] {".gnupg/S.gpg-agent"}; + + @Override + public boolean isInteractive() { + return true; + } + + @Override + public char[] load(RepositorySystemSession session, long keyId) throws IOException { + for (String socketLocation : SOCKET_LOCATIONS) { + try { + return load(keyId, Paths.get(System.getProperty("user.home"), socketLocation)) + .toCharArray(); + } catch (SocketException e) { + // try next location + } + } + return null; + } + + private String load(long keyId, Path socketPath) throws IOException { + try (SocketChannel sock = SocketChannel.open(StandardProtocolFamily.UNIX)) { + try { + sock.connect(UnixDomainSocketAddress.of(socketPath)); + } catch (SocketException e) { + System.out.println("Cannot connect to server on socket:" + socketPath); Review Comment: reworked this: dropped use of sout, using logger proper, and exposed socket config. -- 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