From 513446388303727890844ea4161c516595037428 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Fri, 10 Jan 2020 18:42:39 +0100 Subject: [PATCH] Fix animalsniffer bugs! --- .../decryption_verification/DecryptionBuilder.java | 10 +++++++++- .../java/org/pgpainless/key/OpenPgpV4Fingerprint.java | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DecryptionBuilder.java b/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DecryptionBuilder.java index 39441bc4..da4c2a14 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DecryptionBuilder.java +++ b/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DecryptionBuilder.java @@ -76,10 +76,18 @@ public class DecryptionBuilder implements DecryptionBuilderInterface { public HandleMissingPublicKeys verifyWith(@Nonnull Set trustedKeyIds, @Nonnull PGPPublicKeyRingCollection publicKeyRingCollection) { Set publicKeyRings = keyRingCollectionToSet(publicKeyRingCollection); - publicKeyRings.removeIf(p -> !trustedKeyIds.contains(new OpenPgpV4Fingerprint(p))); + removeUntrustedPublicKeys(publicKeyRings, trustedKeyIds); return verifyWith(publicKeyRings); } + private void removeUntrustedPublicKeys(Set publicKeyRings, Set trustedKeyIds) { + for (PGPPublicKeyRing p : new HashSet<>(publicKeyRings)) { + if (!trustedKeyIds.contains(new OpenPgpV4Fingerprint(p))) { + publicKeyRings.remove(p); + } + } + } + private Set keyRingCollectionToSet(PGPPublicKeyRingCollection publicKeyRingCollection) { Set publicKeyRings = new HashSet<>(); for (Iterator i = publicKeyRingCollection.getKeyRings(); i.hasNext(); ) { diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/OpenPgpV4Fingerprint.java b/pgpainless-core/src/main/java/org/pgpainless/key/OpenPgpV4Fingerprint.java index c77a25bf..9bceee8a 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/OpenPgpV4Fingerprint.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/OpenPgpV4Fingerprint.java @@ -49,7 +49,7 @@ public class OpenPgpV4Fingerprint implements CharSequence, Comparable