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
9f8ce475eb
commit
7656bcd101
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.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")
|
||||||
|
public void parsePublicKeyPacket(FuzzedDataProvider provider) {
|
||||||
byte[] encoding = provider.consumeRemainingAsBytes();
|
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) {
|
||||||
|
|
|
@ -6,18 +6,16 @@ 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.consumeRemainingAsBytes();
|
byte[] encoding = provider.consumeRemainingAsBytes();
|
||||||
|
@ -25,14 +23,8 @@ public class SecretKeyPacketFuzzTest {
|
||||||
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) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue