1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-09 18:29:39 +02:00

Compare commits

...

5 commits

10 changed files with 22 additions and 42 deletions

2
.gitignore vendored
View file

@ -34,4 +34,4 @@ push_html.sh
node_modules node_modules
pgpainless-sop/.cifuzz-corpus/* */.cifuzz-corpus/*

View file

@ -347,12 +347,7 @@ class OpenPgpMessageInputStream(
"Symmetrically Encrypted Data Packet at depth ${layerMetadata.depth} encountered.") "Symmetrically Encrypted Data Packet at depth ${layerMetadata.depth} encountered.")
syntaxVerifier.next(InputSymbol.ENCRYPTED_DATA) syntaxVerifier.next(InputSymbol.ENCRYPTED_DATA)
val encDataList = packetInputStream!!.readEncryptedDataList() val encDataList = packetInputStream!!.readEncryptedDataList()
if (encDataList.isEmpty) { if (!encDataList.isIntegrityProtected && !encDataList.isEmpty && !encDataList.get(0).isAEAD) {
LOGGER.debug(
"Missing encrypted session key packet.")
return false
}
if (!encDataList.isIntegrityProtected && !encDataList.get(0).isAEAD) {
LOGGER.warn("Symmetrically Encrypted Data Packet is not integrity-protected.") LOGGER.warn("Symmetrically Encrypted Data Packet is not integrity-protected.")
if (!options.isIgnoreMDCErrors()) { if (!options.isIgnoreMDCErrors()) {
throw MessageNotIntegrityProtectedException() throw MessageNotIntegrityProtectedException()

View file

@ -19,7 +19,7 @@ dependencies {
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
// Jazzer for Fuzzing // Jazzer for Fuzzing
testImplementation "com.code-intelligence:jazzer-junit:0.24.0" testImplementation "com.code-intelligence:jazzer-junit:$jazzerVersion"
// Logging // Logging
testImplementation "ch.qos.logback:logback-classic:$logbackVersion" testImplementation "ch.qos.logback:logback-classic:$logbackVersion"

View file

@ -22,7 +22,7 @@ public class AsciiArmorFuzzTest {
maxDuration = "60s" maxDuration = "60s"
) )
public void armorAndDearmorData(FuzzedDataProvider data) throws IOException { public void armorAndDearmorData(FuzzedDataProvider data) throws IOException {
byte[] bytes = data.consumeBytes(1024); byte[] bytes = data.consumeRemainingAsBytes();
byte[] armored = sop.armor().data(bytes).getBytes(); byte[] armored = sop.armor().data(bytes).getBytes();
if (Arrays.areEqual(bytes, armored)) { if (Arrays.areEqual(bytes, armored)) {

View file

@ -10,6 +10,7 @@ import org.bouncycastle.util.encoders.Hex;
import org.bouncycastle.util.io.Streams; import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.pgpainless.exception.MissingDecryptionMethodException;
import org.pgpainless.exception.ModificationDetectionException; import org.pgpainless.exception.ModificationDetectionException;
import org.pgpainless.sop.SOPImpl; import org.pgpainless.sop.SOPImpl;
import sop.SOP; import sop.SOP;
@ -75,7 +76,7 @@ public class EncryptedMessageFuzzingTest {
maxDuration = "60s" maxDuration = "60s"
) )
public void decryptFuzzedMessage(FuzzedDataProvider provider) { public void decryptFuzzedMessage(FuzzedDataProvider provider) {
byte[] ciphertext = provider.consumeBytes(8192); byte[] ciphertext = provider.consumeRemainingAsBytes();
if (ciphertext.length == 0) { if (ciphertext.length == 0) {
return; return;
} }

View file

@ -22,7 +22,7 @@ public class ParseCertFuzzTest {
@FuzzTest(maxDuration = "30s") @FuzzTest(maxDuration = "30s")
public void parseOpenPGPCert(FuzzedDataProvider data) throws IOException { public void parseOpenPGPCert(FuzzedDataProvider data) throws IOException {
byte[] certEncoding = data.consumeBytes(8192); byte[] certEncoding = data.consumeRemainingAsBytes();
if (certEncoding.length == 0) { if (certEncoding.length == 0) {
return; return;
} }

View file

@ -6,33 +6,24 @@ package org.pgpainless.sop.fuzzing;
import com.code_intelligence.jazzer.api.FuzzedDataProvider; import com.code_intelligence.jazzer.api.FuzzedDataProvider;
import com.code_intelligence.jazzer.junit.FuzzTest; import com.code_intelligence.jazzer.junit.FuzzTest;
import org.bouncycastle.bcpg.BCPGInputStream;
import org.bouncycastle.bcpg.UnsupportedPacketVersionException; import org.bouncycastle.bcpg.UnsupportedPacketVersionException;
import org.bouncycastle.openpgp.PGPObjectFactory; import org.bouncycastle.openpgp.api.OpenPGPKeyReader;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.bc.BcPGPObjectFactory;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
public class PublicKeyPacketFuzzTest { public class PublicKeyPacketFuzzTest {
@FuzzTest(maxDuration = "30m") private final OpenPGPKeyReader reader = new OpenPGPKeyReader();
public void parsePublicKeyPacket(FuzzedDataProvider provider)
{ @FuzzTest(maxDuration = "60s")
byte[] encoding = provider.consumeBytes(8192); public void parsePublicKeyPacket(FuzzedDataProvider provider) {
byte[] encoding = provider.consumeRemainingAsBytes();
if (encoding.length == 0) { if (encoding.length == 0) {
return; return;
} }
ByteArrayInputStream bIn = new ByteArrayInputStream(encoding);
BCPGInputStream pIn = new BCPGInputStream(bIn);
PGPObjectFactory objFac = new BcPGPObjectFactory(pIn);
try { try {
Object next = objFac.nextObject(); reader.parseCertificate(encoding);
if (next == null) return;
PGPPublicKeyRing pubKey = (PGPPublicKeyRing) next;
} catch (IOException e) { } catch (IOException e) {
// ignore // ignore
} catch (UnsupportedPacketVersionException e) { } catch (UnsupportedPacketVersionException e) {

View file

@ -6,33 +6,25 @@ package org.pgpainless.sop.fuzzing;
import com.code_intelligence.jazzer.api.FuzzedDataProvider; import com.code_intelligence.jazzer.api.FuzzedDataProvider;
import com.code_intelligence.jazzer.junit.FuzzTest; import com.code_intelligence.jazzer.junit.FuzzTest;
import org.bouncycastle.bcpg.BCPGInputStream;
import org.bouncycastle.bcpg.UnsupportedPacketVersionException; import org.bouncycastle.bcpg.UnsupportedPacketVersionException;
import org.bouncycastle.openpgp.PGPObjectFactory; import org.bouncycastle.openpgp.api.OpenPGPKeyReader;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.bc.BcPGPObjectFactory;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
public class SecretKeyPacketFuzzTest { public class SecretKeyPacketFuzzTest {
@FuzzTest(maxDuration = "30m") private final OpenPGPKeyReader reader = new OpenPGPKeyReader();
@FuzzTest(maxDuration = "6ßs")
public void parseSecretKeyPacket(FuzzedDataProvider provider) public void parseSecretKeyPacket(FuzzedDataProvider provider)
{ {
byte[] encoding = provider.consumeBytes(8192); byte[] encoding = provider.consumeRemainingAsBytes();
if (encoding.length == 0) { if (encoding.length == 0) {
return; return;
} }
ByteArrayInputStream bIn = new ByteArrayInputStream(encoding);
BCPGInputStream pIn = new BCPGInputStream(bIn);
PGPObjectFactory objFac = new BcPGPObjectFactory(pIn);
try { try {
Object next = objFac.nextObject(); reader.parseKey(encoding);
if (next == null) return;
PGPSecretKeyRing secKey = (PGPSecretKeyRing) next;
} catch (IOException e) { } catch (IOException e) {
// ignore // ignore
} catch (UnsupportedPacketVersionException e) { } catch (UnsupportedPacketVersionException e) {

View file

@ -273,7 +273,7 @@ public class SignatureFuzzTest {
maxDuration = "60s" maxDuration = "60s"
) )
public void verifyFuzzedSig(FuzzedDataProvider provider) throws IOException { public void verifyFuzzedSig(FuzzedDataProvider provider) throws IOException {
byte[] sig = provider.consumeBytes(1024); byte[] sig = provider.consumeRemainingAsBytes();
if (sig.length == 0) { if (sig.length == 0) {
return; return;
} }

View file

@ -10,6 +10,7 @@ allprojects {
bouncyCastleVersion = '1.82-SNAPSHOT' bouncyCastleVersion = '1.82-SNAPSHOT'
bouncyPgVersion = bouncyCastleVersion bouncyPgVersion = bouncyCastleVersion
junitVersion = '5.8.2' junitVersion = '5.8.2'
jazzerVersion = '0.24.0'
logbackVersion = '1.5.13' logbackVersion = '1.5.13'
mockitoVersion = '4.5.1' mockitoVersion = '4.5.1'
slf4jVersion = '1.7.36' slf4jVersion = '1.7.36'