Skip to content

Commit

Permalink
Add fuzz test for PKCS7_verify
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Dec 11, 2024
1 parent 1be42a3 commit e493a3f
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions fuzz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fuzzer(ocsp)
fuzzer(ocsp_http)
fuzzer(ocsp_parse_url)
fuzzer(pkcs12)
fuzzer(pkcs7_verify)
fuzzer(pkcs8)
fuzzer(pkcs8_v2)
fuzzer(privkey)
Expand Down
85 changes: 85 additions & 0 deletions fuzz/pkcs7_verify.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC

#include <cstdint>
#include <cstring>

#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/pkcs7.h>
#include <openssl/rsa.h>
#include <openssl/x509.h>
#include <openssl/pem.h>

const char *amazon_ca_cert = "-----BEGIN CERTIFICATE-----"
"MIIFQTCCAymgAwIBAgITBmyf0pY1hp8KD+WGePhbJruKNzANBgkqhkiG9w0BAQwF\n"
"ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6\n"
"b24gUm9vdCBDQSAyMB4XDTE1MDUyNjAwMDAwMFoXDTQwMDUyNjAwMDAwMFowOTEL\n"
"MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv\n"
"b3QgQ0EgMjCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK2Wny2cSkxK\n"
"gXlRmeyKy2tgURO8TW0G/LAIjd0ZEGrHJgw12MBvIITplLGbhQPDW9tK6Mj4kHbZ\n"
"W0/jTOgGNk3Mmqw9DJArktQGGWCsN0R5hYGCrVo34A3MnaZMUnbqQ523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CMFa6ybRoVGld45pIq2WWQgj9sAq+uEjonljYE1x2igGOpm/Hl\n"
"urR8FLBOybEfdF849lHqm/osohHUqS0nGkWxr7JOcQ3AWEbWaQbLU8uz/mtBzUF+\n"
"fUwPfHJ5elnNXkoOrJupmHN5fLT0zLm4BwyydFy4x2+IoZCn9Kr5v2c69BoVYh63\n"
"n749sSmvZ6ES8lgQGVMDMBu4Gon2nL2XA46jCfMdiyHxtN/kHNGfZQIG6lzWE7OE\n"
"76KlXIx3KadowGuuQNKotOrN8I1LOJwZmhsoVLiJkO/KdYE+HvJkJMcYr07/R54H\n"
"9jVlpNMKVv/1F2Rs76giJUmTtt8AF9pYfl3uxRuw0dFfIRDH+fO6AgonB8Xx1sfT\n"
"4PsJYGw=\n"
"-----END CERTIFICATE-----\n";

OPENSSL_BEGIN_ALLOW_DEPRECATED
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
BIO* bio_amazon = nullptr;
X509* amazon_cert = nullptr;
X509_STORE* store = nullptr;
STACK_OF(X509)* certs = nullptr;
PKCS7* pkcs7(d2i_PKCS7(nullptr, &buf, len));
if (!pkcs7) {
goto end;
}
bio_amazon = BIO_new_mem_buf(amazon_ca_cert, strlen(amazon_ca_cert));
if (!bio_amazon) {
goto end;
}
amazon_cert =
PEM_read_bio_X509(bio_amazon, nullptr, nullptr, nullptr);
store = X509_STORE_new();
if (!store) {
goto end;
}
if (!X509_STORE_add_cert(store, X509_dup(amazon_cert))) {
goto end;
}
certs = sk_X509_new_null();
if (!sk_X509_unshift(certs, amazon_cert)) {
goto end;
}
amazon_cert = nullptr;

PKCS7_verify(pkcs7, certs, store, nullptr, nullptr, 0);

end:
BIO_free(bio_amazon);
X509_free(amazon_cert);
X509_STORE_free(store);
sk_X509_free(certs);
PKCS7_free(pkcs7);
return 0;
}
OPENSSL_END_ALLOW_DEPRECATED

0 comments on commit e493a3f

Please sign in to comment.