From 4855f8063e0ff031355e3b80a4faa5a26bd51e75 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Tue, 4 Jan 2022 17:23:13 +0100 Subject: [PATCH] Workaround for BC not correctly parsing RevocationKey packets --- .../subpackets/SignatureSubpacketsUtil.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketsUtil.java b/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketsUtil.java index 960d5256..986fcb7c 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketsUtil.java +++ b/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketsUtil.java @@ -10,7 +10,6 @@ import java.util.Date; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; - import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -37,7 +36,6 @@ import org.bouncycastle.openpgp.PGPPublicKey; import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.PGPSignatureList; import org.bouncycastle.openpgp.PGPSignatureSubpacketVector; -import org.bouncycastle.util.encoders.Hex; import org.pgpainless.algorithm.CompressionAlgorithm; import org.pgpainless.algorithm.Feature; import org.pgpainless.algorithm.HashAlgorithm; @@ -581,7 +579,16 @@ public final class SignatureSubpacketsUtil { if (allPackets.length == 0) { return null; } - return (P) allPackets[allPackets.length - 1]; // return last + + org.bouncycastle.bcpg.SignatureSubpacket last = allPackets[allPackets.length - 1]; + + if (type == SignatureSubpacket.revocationKey) { + // RevocationKey subpackets are not castable for some reason + // We need to manually construct the new object + return (P) new RevocationKey(last.isCritical(), last.isLongLength(), last.getData()); + } + + return (P) last; } /**