Add OEMCrypto_GenerateCertificateKeyPair fuzzer
Merged from https://widevine-internal-review.googlesource.com/168817 Merged from https://widevine-internal-review.googlesource.com/169915 Change-Id: If4d3f4cd2b028765072a14c74781e9750dc3e38b
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
// Copyright 2023 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine
|
||||
// License Agreement.
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "FuzzedDataProvider.h"
|
||||
#include "OEMCryptoCENC.h"
|
||||
#include "oemcrypto_fuzz_helper.h"
|
||||
|
||||
using namespace wvoec;
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
// Redirect printf and log statements from oemcrypto functions to a file to
|
||||
// reduce noise
|
||||
RedirectStdoutToFile();
|
||||
|
||||
static OEMCryptoProvisioningAPIFuzz provisioning_api_fuzz;
|
||||
FuzzedDataProvider fuzzed_data(data, size);
|
||||
|
||||
// public_key and public_key_length parameters
|
||||
size_t public_key_length_data =
|
||||
fuzzed_data.ConsumeIntegralInRange<size_t>(0, MAX_FUZZ_OUTPUT_LENGTH);
|
||||
std::vector<uint8_t> public_key(public_key_length_data);
|
||||
size_t* const public_key_length =
|
||||
fuzzed_data.ConsumeBool() ? &public_key_length_data : nullptr;
|
||||
|
||||
// public_key_signature and public_key_signature_length parameters
|
||||
size_t public_key_signature_length_data =
|
||||
fuzzed_data.ConsumeIntegralInRange<size_t>(0, MAX_FUZZ_OUTPUT_LENGTH);
|
||||
std::vector<uint8_t> public_key_signature(public_key_signature_length_data);
|
||||
size_t* const public_key_signature_length =
|
||||
fuzzed_data.ConsumeBool() ? &public_key_signature_length_data : nullptr;
|
||||
|
||||
// wrapped_private_key and wrapped_private_key_length parameters
|
||||
size_t wrapped_private_key_length_data =
|
||||
fuzzed_data.ConsumeIntegralInRange<size_t>(0, MAX_FUZZ_OUTPUT_LENGTH);
|
||||
std::vector<uint8_t> wrapped_private_key(wrapped_private_key_length_data);
|
||||
size_t* const wrapped_private_key_length =
|
||||
fuzzed_data.ConsumeBool() ? &wrapped_private_key_length_data : nullptr;
|
||||
|
||||
// key_type parameter
|
||||
OEMCrypto_PrivateKeyType key_type_data;
|
||||
OEMCrypto_PrivateKeyType* const key_type =
|
||||
fuzzed_data.ConsumeBool() ? &key_type_data : nullptr;
|
||||
|
||||
OEMCrypto_GenerateCertificateKeyPair(
|
||||
provisioning_api_fuzz.session()->session_id(), public_key.data(),
|
||||
public_key_length, public_key_signature.data(),
|
||||
public_key_signature_length, wrapped_private_key.data(),
|
||||
wrapped_private_key_length, key_type);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user