Skip to content

Commit

Permalink
Add fuzz-der-cert driver with dictionary and corpus
Browse files Browse the repository at this point in the history
Dictionary extracted from ASN1 constants. Corpus extracted from unit tests.
NOTE: Corpus is *not* yet minimized.
  • Loading branch information
zcduthie committed Feb 14, 2024
1 parent f16fe39 commit 7ae6c8d
Show file tree
Hide file tree
Showing 70 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
group("fuzz_tests") {
deps = [
"${chip_root}/src/credentials/tests:fuzz-chip-cert",
"${chip_root}/src/credentials/tests:fuzz-der-cert",
"${chip_root}/src/lib/core/tests:fuzz-tlv-reader",
"${chip_root}/src/lib/dnssd/minimal_mdns/tests:fuzz-minmdns-packet-parsing",
"${chip_root}/src/lib/format/tests:fuzz-payload-decoder",
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
36 changes: 36 additions & 0 deletions integrations/fuzz/fuzz-der-cert.dict
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# ASN1 constants extracted from src/lib/asn1/ASN1.h

# ASN1TagClasses
kASN1TagClass_Universal = "\x00"
kASN1TagClass_Application = "\x40"
kASN1TagClass_ContextSpecific = "\x80"
kASN1TagClass_Private = "\xC0"

# ASN1UniversalTags
kASN1UniversalTag_Boolean = "\x01"
kASN1UniversalTag_Integer = "\x02"
kASN1UniversalTag_BitString = "\x03"
kASN1UniversalTag_OctetString = "\x04"
kASN1UniversalTag_Null = "\x05"
kASN1UniversalTag_ObjectId = "\x06"
kASN1UniversalTag_ObjectDesc = "\x07"
kASN1UniversalTag_External = "\x08"
kASN1UniversalTag_Real = "\x09"
kASN1UniversalTag_Enumerated = "\x0A"
kASN1UniversalTag_UTF8String = "\x0C"
kASN1UniversalTag_Sequence = "\x10"
kASN1UniversalTag_Set = "\x11"
kASN1UniversalTag_NumericString = "\x12"
kASN1UniversalTag_PrintableString = "\x13"
kASN1UniversalTag_T61String = "\x14"
kASN1UniversalTag_VideotexString = "\x15"
kASN1UniversalTag_IA5String = "\x16"
kASN1UniversalTag_UTCTime = "\x17"
kASN1UniversalTag_GeneralizedTime = "\x18"
kASN1UniversalTag_GraphicString = "\x19"
kASN1UniversalTag_VisibleString = "\x1A"
kASN1UniversalTag_GeneralString = "\x1B"
kASN1UniversalTag_UniversalString = "\x1C"

kASN1UniversalTag_Sequence_Constructed = "\x30"
kASN1UniversalTag_Set_Constructed = "\x31"
4 changes: 4 additions & 0 deletions src/credentials/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,8 @@ if (enable_fuzz_test_targets) {
sources = [ "FuzzChipCert.cpp" ]
public_deps = [ "${chip_root}/src/credentials" ]
}
chip_fuzz_target("fuzz-der-cert") {
sources = [ "FuzzDERCert.cpp" ]
public_deps = [ "${chip_root}/src/credentials" ]
}
}
25 changes: 25 additions & 0 deletions src/credentials/tests/FuzzDERCert.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <cstddef>
#include <cstdint>

#include "credentials/CHIPCert.h"

using namespace chip;
using namespace chip::Credentials;

extern "C" int LLVMFuzzerTestOneInput(const uint8_t * data, size_t len)
{
ByteSpan span(data, len);

{
ChipDN dn;
(void) ExtractSubjectDNFromX509Cert(span, dn);
}

{
uint8_t outCertBuf[kMaxCHIPCertLength];
MutableByteSpan outCert(outCertBuf);
(void) ConvertX509CertToChipCert(span, outCert);
}

return 0;
}

0 comments on commit 7ae6c8d

Please sign in to comment.