-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fuzz testing that was used to find previous fixes
This fuzz testing and seed corpus helped validate for protocol flaws in decoding TDF's. This testing is time consuming, and Jazzer sometimes has some weird IO blocking behavior that is not actually indicative of a flaw. For that reason this is not part of CI, and instead is run through `fuzz.sh` when needed.
- Loading branch information
Showing
16 changed files
with
230 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
tests=("fuzzNanoTDF", "fuzzTDF", "fuzzZipRead") | ||
base_seed_dir="src/test/resources/io/opentdf/platform/sdk/FuzzingInputs/" | ||
|
||
for test in "${tests[@]}"; do | ||
seed_dir="${base_seed_dir}${test}" | ||
echo "Running $test fuzzing with seeds from $seed_dir" | ||
mvn verify -P fuzz -Djazzer.testDir=$seed_dir | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.opentdf.platform.sdk; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.ByteBuffer; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.text.ParseException; | ||
|
||
import org.apache.commons.codec.DecoderException; | ||
import org.apache.commons.compress.utils.SeekableInMemoryByteChannel; | ||
|
||
import com.code_intelligence.jazzer.api.FuzzedDataProvider; | ||
import com.code_intelligence.jazzer.junit.FuzzTest; | ||
import com.google.gson.JsonParseException; | ||
import com.nimbusds.jose.JOSEException; | ||
|
||
import io.opentdf.platform.sdk.TDF.FailedToCreateGMAC; | ||
import io.opentdf.platform.sdk.TDF.Reader; | ||
|
||
public class Fuzzing { | ||
private static final String testDuration = "600s"; | ||
private static final OutputStream ignoreOutputStream = new OutputStream() { | ||
@Override | ||
public void write(int b) { | ||
// ignored | ||
} | ||
|
||
@Override | ||
public void write(byte b[], int off, int len) { | ||
// ignored | ||
} | ||
}; | ||
|
||
@FuzzTest(maxDuration=testDuration) | ||
public void fuzzNanoTDF(FuzzedDataProvider data) throws IOException { | ||
byte[] fuzzBytes = data.consumeRemainingAsBytes(); | ||
NanoTDF nanoTDF = new NanoTDF(); | ||
nanoTDF.readNanoTDF(ByteBuffer.wrap(fuzzBytes), ignoreOutputStream, NanoTDFTest.kas); | ||
} | ||
|
||
@FuzzTest(maxDuration=testDuration) | ||
public void fuzzTDF(FuzzedDataProvider data) throws FailedToCreateGMAC, NoSuchAlgorithmException, IOException, JOSEException, ParseException, DecoderException { | ||
byte[] fuzzBytes = data.consumeRemainingAsBytes(); | ||
byte[] key = new byte[32]; // use consistent zero key for performance and so fuzz can relate to seed | ||
var assertionVerificationKeys = new Config.AssertionVerificationKeys(); | ||
assertionVerificationKeys.defaultKey = new AssertionConfig.AssertionKey(AssertionConfig.AssertionKeyAlg.HS256, key); | ||
Config.TDFReaderConfig readerConfig = Config.newTDFReaderConfig( | ||
Config.withAssertionVerificationKeys(assertionVerificationKeys)); | ||
TDF tdf = new TDF(); | ||
|
||
try { | ||
Reader reader = tdf.loadTDF(new SeekableInMemoryByteChannel(fuzzBytes), TDFTest.kas, readerConfig); | ||
|
||
reader.readPayload(ignoreOutputStream); | ||
} catch (SDKException | InvalidZipException | JsonParseException | IOException | IllegalArgumentException e) { | ||
// expected failure cases | ||
} | ||
} | ||
|
||
@FuzzTest(maxDuration=testDuration) | ||
public void fuzzZipRead(FuzzedDataProvider data) { | ||
byte[] fuzzBytes = data.consumeRemainingAsBytes(); | ||
try { | ||
ZipReaderTest.testReadingZipChannel(new SeekableInMemoryByteChannel(fuzzBytes), false); | ||
} catch (InvalidZipException | IllegalArgumentException | JsonParseException | IOException e) { | ||
// cases which are expected with invalid fuzzed inputs | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+361 Bytes
sdk/src/test/resources/io/opentdf/platform/sdk/FuzzingInputs/fuzzNanoTDF/sample.ntdf
Binary file not shown.
Binary file added
BIN
+1.97 KB
sdk/src/test/resources/io/opentdf/platform/sdk/FuzzingInputs/fuzzTDF/crash-InvalidManifest-1
Binary file not shown.
Binary file added
BIN
+1.97 KB
sdk/src/test/resources/io/opentdf/platform/sdk/FuzzingInputs/fuzzTDF/crash-InvalidManifest-2
Binary file not shown.
Binary file added
BIN
+1.97 KB
sdk/src/test/resources/io/opentdf/platform/sdk/FuzzingInputs/fuzzTDF/crash-InvalidManifest-3
Binary file not shown.
Binary file added
BIN
+1.97 KB
sdk/src/test/resources/io/opentdf/platform/sdk/FuzzingInputs/fuzzTDF/crash-InvalidManifest-4
Binary file not shown.
Binary file added
BIN
+1.97 KB
...rces/io/opentdf/platform/sdk/FuzzingInputs/fuzzTDF/crash-InvalidManifest-NullKeyAccessObj
Binary file not shown.
Binary file added
BIN
+1.97 KB
...resources/io/opentdf/platform/sdk/FuzzingInputs/fuzzTDF/crash-InvalidManifest-NullSegment
Binary file not shown.
Binary file added
BIN
+1.97 KB
sdk/src/test/resources/io/opentdf/platform/sdk/FuzzingInputs/fuzzTDF/sample.tdf
Binary file not shown.
Binary file added
BIN
+1.34 KB
sdk/src/test/resources/io/opentdf/platform/sdk/FuzzingInputs/fuzzZipRead/crash-NullSignature
Binary file not shown.
Binary file added
BIN
+99 Bytes
...tdf/platform/sdk/FuzzingInputs/fuzzZipRead/crash-f39ad8416aef7cf275f84683aaa0efd15f24272a
Binary file not shown.
Binary file added
BIN
+1.71 KB
sdk/src/test/resources/io/opentdf/platform/sdk/FuzzingInputs/fuzzZipRead/sample.txt.tdf
Binary file not shown.