diff --git a/src/main/java/org/simplify4u/plugins/PublicKeyUtils.java b/src/main/java/org/simplify4u/plugins/PublicKeyUtils.java index 77e1053f..9a07e976 100644 --- a/src/main/java/org/simplify4u/plugins/PublicKeyUtils.java +++ b/src/main/java/org/simplify4u/plugins/PublicKeyUtils.java @@ -173,17 +173,20 @@ private static void verifyPublicKeyRing(PGPPublicKeyRing publicKeyRing) { private static void verifySigForSubKey(PGPPublicKey subKey, PGPPublicKeyRing publicKeyRing) { - subKey.getSignatures().forEachRemaining(s -> Try.run(() -> { + subKey.getSignaturesOfType(PGPSignature.SUBKEY_BINDING).forEachRemaining(s -> Try.run(() -> { PGPSignature sig = (PGPSignature) s; PGPPublicKey masterKey = publicKeyRing.getPublicKey(sig.getKeyID()); if (masterKey != null) { sig.init(new BcPGPContentVerifierBuilderProvider(), masterKey); if (!sig.verifyCertification(masterKey, subKey)) { throw new PGPException( - String.format("Failed signature type: %d for subKey: %s in key: %s", + String.format("Failed signature type: %x for subKey: %s in key: %s", sig.getSignatureType(), fingerprint(subKey), fingerprint(masterKey))); } + } else { + throw new PGPException(String.format("Signature type: %x Not found key 0x%016X for subKeyId: %s", + sig.getSignatureType(), sig.getKeyID(), fingerprint(subKey))); } }).get() ); diff --git a/src/test/java/org/simplify4u/plugins/PublicKeyUtilsTest.java b/src/test/java/org/simplify4u/plugins/PublicKeyUtilsTest.java index 18dde083..51b423c7 100644 --- a/src/test/java/org/simplify4u/plugins/PublicKeyUtilsTest.java +++ b/src/test/java/org/simplify4u/plugins/PublicKeyUtilsTest.java @@ -121,7 +121,7 @@ public void invalidUTF8InUserId() throws IOException, PGPException { } @Test - public void invalidDerbyClient() throws IOException, PGPException { + public void validateSubKeyWithExternalSignature() throws IOException, PGPException { try (InputStream inputStream = getClass().getResourceAsStream("/3D8B00E198E21827.asc")) { PGPPublicKeyRing publicKeyRing = PublicKeyUtils.loadPublicKeyRing(inputStream, 0x3D8B00E198E21827L);