Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement OpenPGP v6 & LibrePGP v5 signature verification #1725

Closed
wants to merge 18 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PGPOnePassSignature: check salt size
vanitasvitae committed Jul 1, 2024
commit b1b1b3a8e3e117e46d355e332b702c234c5f0d2c
18 changes: 18 additions & 0 deletions pg/src/main/java/org/bouncycastle/openpgp/PGPOnePassSignature.java
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@

import org.bouncycastle.bcpg.BCPGInputStream;
import org.bouncycastle.bcpg.BCPGOutputStream;
import org.bouncycastle.bcpg.HashUtils;
import org.bouncycastle.bcpg.OnePassSignaturePacket;
import org.bouncycastle.bcpg.Packet;
import org.bouncycastle.bcpg.SignaturePacket;
@@ -65,9 +66,26 @@ public void init(PGPContentVerifierBuilderProvider verifierBuilderProvider, PGPP
lastb = 0;
sigOut = verifier.getOutputStream();

checkSaltSize();
updateWithSalt();
}

private void checkSaltSize()
throws PGPException
{
if (getVersion() != SignaturePacket.VERSION_6)
{
return;
}

int expectedSaltSize = HashUtils.getV6SignatureSaltSizeInBytes(getHashAlgorithm());
if (expectedSaltSize != getSalt().length)
{
throw new PGPException("RFC9580 defines the salt size for " + PGPUtil.getDigestName(getHashAlgorithm()) +
" as " + expectedSaltSize + " octets, but signature has " + getSalt().length + " octets.");
}
}

private void updateWithSalt()
throws PGPException
{