diff --git a/src/main/java/org/pgpainless/pgpainless/decryption_verification/DecryptionBuilder.java b/src/main/java/org/pgpainless/pgpainless/decryption_verification/DecryptionBuilder.java index 0823e095..1e065843 100644 --- a/src/main/java/org/pgpainless/pgpainless/decryption_verification/DecryptionBuilder.java +++ b/src/main/java/org/pgpainless/pgpainless/decryption_verification/DecryptionBuilder.java @@ -25,6 +25,7 @@ import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; +import org.pgpainless.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.pgpainless.key.protection.SecretKeyRingProtector; public class DecryptionBuilder implements DecryptionBuilderInterface { @@ -61,12 +62,18 @@ public class DecryptionBuilder implements DecryptionBuilderInterface { class VerifyWithImpl implements VerifyWith { @Override - public HandleMissingPublicKeys verifyWith(Set trustedKeyIds, + public HandleMissingPublicKeys verifyWith(Set trustedKeyIds, PGPPublicKeyRingCollection publicKeyRingCollection) { Set publicKeyRings = new HashSet<>(); for (Iterator i = publicKeyRingCollection.getKeyRings(); i.hasNext(); ) { PGPPublicKeyRing p = i.next(); - if (trustedKeyIds.contains(p.getPublicKey().getKeyID())) { + OpenPgpV4Fingerprint fingerprint; + try { + fingerprint = new OpenPgpV4Fingerprint(p); + } catch (PGPException e) { + throw new IllegalArgumentException(e); + } + if (trustedKeyIds.contains(fingerprint)) { publicKeyRings.add(p); } } @@ -89,7 +96,7 @@ public class DecryptionBuilder implements DecryptionBuilderInterface { class HandleMissingPublicKeysImpl implements HandleMissingPublicKeys { @Override - public Build handleMissingPublicKeysWith(org.pgpainless.pgpainless.decryption_verification.MissingPublicKeyCallback callback) { + public Build handleMissingPublicKeysWith(MissingPublicKeyCallback callback) { DecryptionBuilder.this.missingPublicKeyCallback = callback; return new BuildImpl(); } diff --git a/src/main/java/org/pgpainless/pgpainless/decryption_verification/DecryptionBuilderInterface.java b/src/main/java/org/pgpainless/pgpainless/decryption_verification/DecryptionBuilderInterface.java index 081c68bf..49e23e72 100644 --- a/src/main/java/org/pgpainless/pgpainless/decryption_verification/DecryptionBuilderInterface.java +++ b/src/main/java/org/pgpainless/pgpainless/decryption_verification/DecryptionBuilderInterface.java @@ -23,6 +23,7 @@ import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; +import org.pgpainless.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.pgpainless.key.protection.SecretKeyRingProtector; public interface DecryptionBuilderInterface { @@ -39,7 +40,7 @@ public interface DecryptionBuilderInterface { interface VerifyWith { - HandleMissingPublicKeys verifyWith(Set trustedFingerprints, PGPPublicKeyRingCollection publicKeyRings); + HandleMissingPublicKeys verifyWith(Set trustedFingerprints, PGPPublicKeyRingCollection publicKeyRings); HandleMissingPublicKeys verifyWith(Set publicKeyRings); @@ -49,7 +50,7 @@ public interface DecryptionBuilderInterface { interface HandleMissingPublicKeys { - Build handleMissingPublicKeysWith(org.pgpainless.pgpainless.decryption_verification.MissingPublicKeyCallback callback); + Build handleMissingPublicKeysWith(MissingPublicKeyCallback callback); Build ignoreMissingPublicKeys(); } diff --git a/src/main/java/org/pgpainless/pgpainless/key/OpenPgpV4Fingerprint.java b/src/main/java/org/pgpainless/pgpainless/key/OpenPgpV4Fingerprint.java index f16d1947..1158c1a5 100644 --- a/src/main/java/org/pgpainless/pgpainless/key/OpenPgpV4Fingerprint.java +++ b/src/main/java/org/pgpainless/pgpainless/key/OpenPgpV4Fingerprint.java @@ -14,17 +14,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smackx.ox; +package org.pgpainless.pgpainless.key; import javax.xml.bind.DatatypeConverter; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.Arrays; -import org.jivesoftware.smack.util.Objects; - import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPublicKey; +import org.bouncycastle.openpgp.PGPPublicKeyRing; +import org.bouncycastle.openpgp.PGPSecretKey; +import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.util.encoders.Hex; /** @@ -41,9 +42,10 @@ public class OpenPgpV4Fingerprint implements CharSequence, Comparable