From e7ed0f76a391ab553cf31aa800dbf64e0457d1a8 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sat, 31 Jul 2021 22:25:12 +0200 Subject: [PATCH] Properly ignore marker packets when reading keys/sigs --- .../key/collection/PGPKeyRingCollection.java | 20 +++++++++---------- .../pgpainless/key/parsing/KeyRingReader.java | 10 +++++----- .../pgpainless/signature/SignatureUtils.java | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/collection/PGPKeyRingCollection.java b/pgpainless-core/src/main/java/org/pgpainless/key/collection/PGPKeyRingCollection.java index 0cc9fccd..e705434f 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/collection/PGPKeyRingCollection.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/collection/PGPKeyRingCollection.java @@ -15,9 +15,17 @@ */ package org.pgpainless.key.collection; -import org.bouncycastle.bcpg.MarkerPacket; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import javax.annotation.Nonnull; + import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPKeyRing; +import org.bouncycastle.openpgp.PGPMarker; import org.bouncycastle.openpgp.PGPObjectFactory; import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; @@ -26,14 +34,6 @@ import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.openpgp.PGPUtil; import org.pgpainless.implementation.ImplementationFactory; -import javax.annotation.Nonnull; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - /** * This class describes a logic of handling a collection of different {@link PGPKeyRing}. The logic was inspired by * {@link PGPSecretKeyRingCollection} and {@link PGPPublicKeyRingCollection}. @@ -65,7 +65,7 @@ public class PGPKeyRingCollection { List publicKeyRings = new ArrayList<>(); while ((obj = pgpFact.nextObject()) != null) { - if (obj instanceof MarkerPacket) { + if (obj instanceof PGPMarker) { // Skip marker packets continue; } diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/parsing/KeyRingReader.java b/pgpainless-core/src/main/java/org/pgpainless/key/parsing/KeyRingReader.java index bf04abc9..63f411f6 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/parsing/KeyRingReader.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/parsing/KeyRingReader.java @@ -26,8 +26,8 @@ import java.util.List; import javax.annotation.Nonnull; import org.bouncycastle.bcpg.ArmoredInputStream; -import org.bouncycastle.bcpg.MarkerPacket; import org.bouncycastle.openpgp.PGPException; +import org.bouncycastle.openpgp.PGPMarker; import org.bouncycastle.openpgp.PGPObjectFactory; import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; @@ -117,7 +117,7 @@ public class KeyRingReader { if (next == null) { break; } - if (next instanceof MarkerPacket) { + if (next instanceof PGPMarker) { continue; } if (next instanceof PGPPublicKeyRing) { @@ -142,7 +142,7 @@ public class KeyRingReader { if (next == null) { break; } - if (next instanceof MarkerPacket) { + if (next instanceof PGPMarker) { continue; } if (next instanceof PGPPublicKeyRing) { @@ -172,7 +172,7 @@ public class KeyRingReader { if (next == null) { break; } - if (next instanceof MarkerPacket) { + if (next instanceof PGPMarker) { continue; } if (next instanceof PGPSecretKeyRing) { @@ -198,7 +198,7 @@ public class KeyRingReader { if (next == null) { break; } - if (next instanceof MarkerPacket) { + if (next instanceof PGPMarker) { continue; } if (next instanceof PGPSecretKeyRing) { diff --git a/pgpainless-core/src/main/java/org/pgpainless/signature/SignatureUtils.java b/pgpainless-core/src/main/java/org/pgpainless/signature/SignatureUtils.java index 0c677f2c..85869c1c 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/signature/SignatureUtils.java +++ b/pgpainless-core/src/main/java/org/pgpainless/signature/SignatureUtils.java @@ -24,12 +24,12 @@ import java.util.Date; import java.util.List; import org.bouncycastle.bcpg.sig.IssuerKeyID; -import org.bouncycastle.bcpg.MarkerPacket; import org.bouncycastle.bcpg.sig.KeyExpirationTime; import org.bouncycastle.bcpg.sig.RevocationReason; import org.bouncycastle.bcpg.sig.SignatureExpirationTime; import org.bouncycastle.openpgp.PGPCompressedData; import org.bouncycastle.openpgp.PGPException; +import org.bouncycastle.openpgp.PGPMarker; import org.bouncycastle.openpgp.PGPObjectFactory; import org.bouncycastle.openpgp.PGPPublicKey; import org.bouncycastle.openpgp.PGPSecretKey; @@ -202,7 +202,7 @@ public class SignatureUtils { Object nextObject = objectFactory.nextObject(); while (nextObject != null) { - if (nextObject instanceof MarkerPacket) { + if (nextObject instanceof PGPMarker) { nextObject = objectFactory.nextObject(); continue; }