Skip to content

Commit

Permalink
Enforce signature/key version matching when verifying
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed Aug 26, 2024
1 parent 0cc1292 commit cb17c47
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pg/src/main/java/org/bouncycastle/openpgp/PGPSignature.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.bouncycastle.bcpg.MPInteger;
import org.bouncycastle.bcpg.Packet;
import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
import org.bouncycastle.bcpg.PublicKeyPacket;
import org.bouncycastle.bcpg.SignaturePacket;
import org.bouncycastle.bcpg.SignatureSubpacket;
import org.bouncycastle.bcpg.TrustPacket;
Expand Down Expand Up @@ -156,6 +157,17 @@ public void init(PGPContentVerifierBuilderProvider verifierBuilderProvider, PGPP
{
throw new PGPException("Illegal signature type 0xFF provided.");
}

if (getVersion() == SignaturePacket.VERSION_6 && pubKey.getVersion() != PublicKeyPacket.VERSION_6)
{
throw new PGPException("MUST NOT verify v6 signature with non-v6 key.");
}

if (getVersion() == SignaturePacket.VERSION_4 && pubKey.getVersion() != PublicKeyPacket.VERSION_4)
{
throw new PGPException("MUST NOT verify v4 signature with non-v4 key.");
}

PGPContentVerifierBuilder verifierBuilder = createVerifierProvider(verifierBuilderProvider);

init(verifierBuilder.build(pubKey));
Expand Down

0 comments on commit cb17c47

Please sign in to comment.