mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 18:29:39 +02:00
key packet fuzzing tests: Use OpenPGPKey/OpenPGPCertificate API
This commit is contained in:
parent
5939b747b0
commit
8f41fb0f27
2 changed files with 11 additions and 28 deletions
|
@ -6,33 +6,24 @@ package org.pgpainless.sop.fuzzing;
|
|||
|
||||
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
|
||||
import com.code_intelligence.jazzer.junit.FuzzTest;
|
||||
import org.bouncycastle.bcpg.BCPGInputStream;
|
||||
import org.bouncycastle.bcpg.UnsupportedPacketVersionException;
|
||||
import org.bouncycastle.openpgp.PGPObjectFactory;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.bc.BcPGPObjectFactory;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPKeyReader;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PublicKeyPacketFuzzTest {
|
||||
|
||||
@FuzzTest(maxDuration = "30m")
|
||||
public void parsePublicKeyPacket(FuzzedDataProvider provider)
|
||||
{
|
||||
private final OpenPGPKeyReader reader = new OpenPGPKeyReader();
|
||||
|
||||
@FuzzTest(maxDuration = "60s")
|
||||
public void parsePublicKeyPacket(FuzzedDataProvider provider) {
|
||||
byte[] encoding = provider.consumeRemainingAsBytes();
|
||||
if (encoding.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ByteArrayInputStream bIn = new ByteArrayInputStream(encoding);
|
||||
BCPGInputStream pIn = new BCPGInputStream(bIn);
|
||||
PGPObjectFactory objFac = new BcPGPObjectFactory(pIn);
|
||||
try {
|
||||
Object next = objFac.nextObject();
|
||||
if (next == null) return;
|
||||
|
||||
PGPPublicKeyRing pubKey = (PGPPublicKeyRing) next;
|
||||
reader.parseCertificate(encoding);
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
} catch (UnsupportedPacketVersionException e) {
|
||||
|
|
|
@ -6,18 +6,16 @@ package org.pgpainless.sop.fuzzing;
|
|||
|
||||
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
|
||||
import com.code_intelligence.jazzer.junit.FuzzTest;
|
||||
import org.bouncycastle.bcpg.BCPGInputStream;
|
||||
import org.bouncycastle.bcpg.UnsupportedPacketVersionException;
|
||||
import org.bouncycastle.openpgp.PGPObjectFactory;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.bc.BcPGPObjectFactory;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPKeyReader;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SecretKeyPacketFuzzTest {
|
||||
|
||||
@FuzzTest(maxDuration = "30m")
|
||||
private final OpenPGPKeyReader reader = new OpenPGPKeyReader();
|
||||
|
||||
@FuzzTest(maxDuration = "6ßs")
|
||||
public void parseSecretKeyPacket(FuzzedDataProvider provider)
|
||||
{
|
||||
byte[] encoding = provider.consumeRemainingAsBytes();
|
||||
|
@ -25,14 +23,8 @@ public class SecretKeyPacketFuzzTest {
|
|||
return;
|
||||
}
|
||||
|
||||
ByteArrayInputStream bIn = new ByteArrayInputStream(encoding);
|
||||
BCPGInputStream pIn = new BCPGInputStream(bIn);
|
||||
PGPObjectFactory objFac = new BcPGPObjectFactory(pIn);
|
||||
try {
|
||||
Object next = objFac.nextObject();
|
||||
if (next == null) return;
|
||||
|
||||
PGPSecretKeyRing secKey = (PGPSecretKeyRing) next;
|
||||
reader.parseKey(encoding);
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
} catch (UnsupportedPacketVersionException e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue