Add OEMCrypto_GetKeyHandle fuzzer
Merged from https://widevine-internal-review.googlesource.com/174934 Change-Id: If44423ed51cc2ff10c1b471d39db962a653d8c14
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
// 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"
|
||||
|
||||
namespace {
|
||||
|
||||
// Avoid calling non-trivial destructor.
|
||||
wvoec::OEMCryptoLicenseAPIFuzz& license_api_fuzz =
|
||||
*new wvoec::OEMCryptoLicenseAPIFuzz;
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {
|
||||
wvoec::RedirectStdoutToFile();
|
||||
license_api_fuzz.Initialize();
|
||||
license_api_fuzz.LoadLicense();
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
FuzzedDataProvider fuzzed_data(data, size);
|
||||
|
||||
const OEMCryptoCipherMode cipher_mode =
|
||||
wvoec::ConvertDataToValidEnum(fuzzed_data, OEMCrypto_CipherMode_MaxValue);
|
||||
|
||||
// key_handle and key_handle_length parameters
|
||||
size_t key_handle_length_data = fuzzed_data.ConsumeIntegralInRange<size_t>(
|
||||
0, wvoec::MAX_FUZZ_OUTPUT_LENGTH);
|
||||
std::vector<uint8_t> key_handle(key_handle_length_data);
|
||||
size_t* const key_handle_length =
|
||||
fuzzed_data.ConsumeBool() ? &key_handle_length_data : nullptr;
|
||||
|
||||
const std::vector<uint8_t> content_key_id =
|
||||
fuzzed_data.ConsumeRemainingBytes<uint8_t>();
|
||||
|
||||
OEMCrypto_GetKeyHandle(license_api_fuzz.session().session_id(),
|
||||
content_key_id.data(), content_key_id.size(),
|
||||
cipher_mode, key_handle.data(), key_handle_length);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user