Skip to content
This repository has been archived by the owner on Mar 17, 2023. It is now read-only.

Commit

Permalink
Key-receiving procedure improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
3TUSK committed Jul 10, 2021
1 parent 47d953d commit b926fd1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/org/teacon/sync/PGPKeyStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,21 @@ public class PGPKeyStore {

public PGPKeyStore(Path localKeyStorePath, List<URL> keyServers, List<String> keyIds) throws Exception {
final Map<Long, PGPPublicKeyRing> keyRings = new HashMap<>();
readKeys(Files.newInputStream(localKeyStorePath), keyRings);
if (Files.exists(localKeyStorePath)) {
LOGGER.debug(MARKER, "Try reading keys from local key ring at {}", localKeyStorePath);
readKeys(Files.newInputStream(localKeyStorePath), keyRings);
}
for (String keyId : keyIds) {
if (keyRings.containsKey(Long.decode(keyId))) {
LOGGER.debug(MARKER,"Not trying to load key {} because it exists locally", keyId);
continue;
}
final String queryParams = "/pks/lookup?op=get&search=".concat(keyId);
for (URL keyServer : keyServers) {
final URL resolved = resolveSrv(keyServer);
final URL keyQuery = new URL(resolved.getProtocol(), resolved.getHost(), resolved.getPort(), queryParams);
try (InputStream input = keyQuery.openStream()) {
LOGGER.debug(MARKER, "Receiving key {} from {}", keyId, keyServer);
readKeys(input, keyRings);
break; // Stop on first available key server
} catch (Exception ignored) {
Expand Down

0 comments on commit b926fd1

Please sign in to comment.