Source release 17.1.2
This commit is contained in:
@@ -2,60 +2,64 @@
|
||||
// source code may only be used and distributed under the Widevine
|
||||
// License Agreement.
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "FuzzedDataProvider.h"
|
||||
#include "OEMCryptoCENC.h"
|
||||
#include "log.h"
|
||||
#include "oemcrypto_fuzz_helper.h"
|
||||
#include "oemcrypto_fuzz_structs.h"
|
||||
#include "oemcrypto_types.h"
|
||||
|
||||
namespace wvoec {
|
||||
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.LoadLicenseWithGenericCryptoKeys();
|
||||
return 0;
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
// Split data using separator.
|
||||
auto inputs = SplitInput(data, size);
|
||||
const std::vector<wvoec::FuzzedData> inputs =
|
||||
wvoec::SplitFuzzedData(data, size);
|
||||
if (inputs.size() < 2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
OEMCrypto_Generic_Api_Fuzz fuzzed_structure;
|
||||
if (inputs[0].size() < sizeof(fuzzed_structure)) {
|
||||
wvoec::OEMCrypto_Generic_Api_Fuzz fuzzed_structure;
|
||||
if (inputs[0].size < sizeof(fuzzed_structure)) {
|
||||
return 0;
|
||||
}
|
||||
// Copy OEMCrypto_Generic_Api_Fuzz from input data.
|
||||
memcpy(&fuzzed_structure, data, sizeof(fuzzed_structure));
|
||||
ConvertDataToValidEnum(OEMCrypto_CipherMode_MaxValue,
|
||||
&fuzzed_structure.cipher_mode);
|
||||
ConvertDataToValidEnum(OEMCrypto_Algorithm_MaxValue,
|
||||
&fuzzed_structure.algorithm);
|
||||
|
||||
FuzzedDataProvider fuzzed_data(inputs[0].data, inputs[0].size);
|
||||
fuzzed_data.ConsumeData(&fuzzed_structure, sizeof(fuzzed_structure));
|
||||
wvoec::ConvertDataToValidEnum(OEMCrypto_CipherMode_MaxValue,
|
||||
fuzzed_structure.cipher_mode);
|
||||
wvoec::ConvertDataToValidEnum(OEMCrypto_Algorithm_MaxValue,
|
||||
fuzzed_structure.algorithm);
|
||||
// Copy iv from input data.
|
||||
size_t iv_size = inputs[0].size() - sizeof(fuzzed_structure);
|
||||
if (iv_size == 0) {
|
||||
return 0;
|
||||
}
|
||||
vector<uint8_t> iv(iv_size);
|
||||
memcpy(iv.data(), data + sizeof(fuzzed_structure), iv_size);
|
||||
constexpr size_t iv_length = 16;
|
||||
const std::vector<uint8_t> iv = fuzzed_data.ConsumeBytes<uint8_t>(
|
||||
fuzzed_data.remaining_bytes() < iv_length ? 0 : iv_length);
|
||||
|
||||
// Copy clear buffer from input data.
|
||||
vector<uint8_t> clear_buffer(inputs[1].size());
|
||||
vector<uint8_t> encrypted_buffer(inputs[1].size());
|
||||
memcpy(clear_buffer.data(), inputs[1].data(), inputs[1].size());
|
||||
// Initialize clear and encrypted buffers.
|
||||
const std::vector<uint8_t> clear_buffer(inputs[1].data,
|
||||
inputs[1].data + inputs[1].size);
|
||||
std::vector<uint8_t> encrypted_buffer(clear_buffer.size());
|
||||
|
||||
OEMCryptoLicenseAPIFuzz license_api_fuzz;
|
||||
Session* session = license_api_fuzz.session();
|
||||
// Load license and call generic_encrypt API.
|
||||
license_api_fuzz.LoadLicense();
|
||||
OEMCryptoResult sts = OEMCrypto_SelectKey(
|
||||
session->session_id(), session->license().keys[0].key_id,
|
||||
session->license().keys[0].key_id_length, fuzzed_structure.cipher_mode);
|
||||
CheckStatusAndExitFuzzerOnFailure(sts, OEMCrypto_SUCCESS);
|
||||
// Select key and encrypt.
|
||||
wvoec::Session& session = license_api_fuzz.session();
|
||||
OEMCrypto_SelectKey(session.session_id(), session.license().keys[0].key_id,
|
||||
session.license().keys[0].key_id_length,
|
||||
fuzzed_structure.cipher_mode);
|
||||
OEMCrypto_Generic_Encrypt(
|
||||
session->session_id(), clear_buffer.data(), clear_buffer.size(),
|
||||
iv.data(), fuzzed_structure.algorithm, encrypted_buffer.data());
|
||||
session.session_id(), clear_buffer.data(), clear_buffer.size(), iv.data(),
|
||||
fuzzed_structure.algorithm, encrypted_buffer.data());
|
||||
return 0;
|
||||
}
|
||||
} // namespace wvoec
|
||||
|
||||
Reference in New Issue
Block a user