in src/main/java/org/apache/sling/cli/impl/pgp/PGPSignatureValidator.java [92:134]
private void readKeyRing(ComponentContext componentContext) {
ComponentContextHelper helper = ComponentContextHelper.wrap(componentContext);
String keysFile = helper.getProperty("sling.keys", KEYS_FILE);
Path keysFilePath = Paths.get(keysFile);
if (Files.notExists(keysFilePath)) {
try {
try (CloseableHttpClient client = httpClientFactory.newClient()) {
HttpGet get = new HttpGet(KEYS_FILE_URL);
try (CloseableHttpResponse response = client.execute(get)) {
try (InputStream content = response.getEntity().getContent()) {
IOUtils.copy(content, new FileOutputStream(keysFilePath.toFile()));
}
}
}
} catch (IOException e) {
throw new IllegalStateException(
"Cannot download Sling key file from " + KEYS_FILE_URL, e);
}
}
try (InputStream in = Files.newInputStream(keysFilePath)) {
InputStream bouncyIn = org.bouncycastle.openpgp.PGPUtil.getDecoderStream(in);
if (bouncyIn instanceof ArmoredInputStream) {
ArmoredInputStream as = (ArmoredInputStream) bouncyIn;
List<PGPPublicKeyRing> keyRings = new ArrayList<>();
while (!as.isEndOfStream()) {
PGPPublicKeyRingCollection collection = new PGPPublicKeyRingCollection(as,
new JcaKeyFingerprintCalculator());
Iterator<PGPPublicKeyRing> readKeyRings = collection.getKeyRings();
while (readKeyRings.hasNext()) {
PGPPublicKeyRing keyRing = readKeyRings.next();
keyRings.add(keyRing);
}
}
if (!keyRings.isEmpty()) {
keyRingCollection = new PGPPublicKeyRingCollection(keyRings);
} else {
throw new IllegalStateException(String.format("Sling keys file from %s does not contain any keys.", keysFile));
}
}
} catch (IOException | PGPException e) {
throw new IllegalStateException(String.format("Cannot read Sling keys file at %s.", keysFile), e);
}
}