Changes included in this CL: 166806: Update OEMCrypto_GetDeviceInformation() | https://widevine-internal-review.googlesource.com/c/cdm/+/166806 166808: Update Android L3 after OEMCrypto_GetDeviceInformation() signature changes | https://widevine-internal-review.googlesource.com/c/cdm/+/166808 166809: Decode device info and write it to CSR payload | https://widevine-internal-review.googlesource.com/c/cdm/+/166809 167158: Fix Android include path and copy_files | https://widevine-internal-review.googlesource.com/c/cdm/+/167158 167159: Fix common typos and use inclusive language suggested by Android linter | https://widevine-internal-review.googlesource.com/c/cdm/+/167159 165618: Explicitly state python3 where needed. | https://widevine-internal-review.googlesource.com/c/cdm/+/165618 166757: Update Android.bp for Android | https://widevine-internal-review.googlesource.com/c/cdm/+/166757 164993: Refactor basic oemcrypto unit tests | https://widevine-internal-review.googlesource.com/c/cdm/+/164993 164978: Update OEMCrypto Unit Test Docs | https://widevine-internal-review.googlesource.com/c/cdm/+/164978 166941: Update make files for OEMCrypto | https://widevine-internal-review.googlesource.com/c/cdm/+/166941 165279: Refactor license unit tests | https://widevine-internal-review.googlesource.com/c/cdm/+/165279 165318: Refactor provisioning unit tests | https://widevine-internal-review.googlesource.com/c/cdm/+/165318 164800: Add extra check for renew on license load unit test | https://widevine-internal-review.googlesource.com/c/cdm/+/164800 165860: Remove duplicate definition of MaybeHex() | https://widevine-internal-review.googlesource.com/c/cdm/+/165860 164889: Updated CoreCommonRequestFromMessage and fix test | https://widevine-internal-review.googlesource.com/c/cdm/+/164889 164967: Add OPK pre-hook and post-hook error codes | https://widevine-internal-review.googlesource.com/c/cdm/+/164967 165140: Add hidden device_id_length to v18 provisioning message | https://widevine-internal-review.googlesource.com/c/cdm/+/165140 165204: Fix memory leak in oemcrypto test | https://widevine-internal-review.googlesource.com/c/cdm/+/165204 165958: Fix oemcrypto_generic_verify_fuzz mutator signature offset | https://widevine-internal-review.googlesource.com/c/cdm/+/165958 166037: Support SHA-256 in OEMCrypto Session Util | https://widevine-internal-review.googlesource.com/c/cdm/+/166037 Test: Run GtsMediaTests on Pixel 7 Bug: 270612144 Change-Id: Iff0820a2de7d043a820470a130af65b0dcadb759
133 lines
5.4 KiB
C++
133 lines
5.4 KiB
C++
// Copyright 2020 Google LLC. All Rights Reserved. This file and proprietary
|
|
// source code may only be used and distributed under the Widevine
|
|
// License Agreement.
|
|
|
|
#include "FuzzedDataProvider.h"
|
|
#include "OEMCryptoCENC.h"
|
|
#include "oec_session_util.h"
|
|
#include "oemcrypto_fuzz_helper.h"
|
|
#include "oemcrypto_fuzz_structs.h"
|
|
#include "oemcrypto_types.h"
|
|
|
|
namespace wvoec {
|
|
|
|
// Properties deserialized from fuzzed data.
|
|
struct FuzzedProperties {
|
|
OEMCrypto_Generic_Api_Fuzz structure;
|
|
std::vector<uint8_t> buffer;
|
|
std::vector<uint8_t> signature;
|
|
};
|
|
|
|
// Contains value only if has_value is true.
|
|
struct OptionalFuzzedProperties {
|
|
FuzzedProperties value;
|
|
bool has_value;
|
|
};
|
|
|
|
OEMCryptoLicenseAPIFuzz license_api_fuzz;
|
|
|
|
OptionalFuzzedProperties DeserializeFuzzedData(const uint8_t* data,
|
|
size_t size) {
|
|
OptionalFuzzedProperties fuzzed_properties;
|
|
const std::vector<FuzzedData> inputs = SplitFuzzedData(data, size);
|
|
if (inputs.size() < 2 ||
|
|
inputs[0].size < sizeof(fuzzed_properties.value.structure)) {
|
|
fuzzed_properties.has_value = false;
|
|
return fuzzed_properties;
|
|
}
|
|
FuzzedDataProvider fuzzed_data(inputs[0].data, inputs[0].size);
|
|
fuzzed_data.ConsumeData(&fuzzed_properties.value.structure,
|
|
sizeof(fuzzed_properties.value.structure));
|
|
ConvertDataToValidEnum(OEMCrypto_CipherMode_MaxValue,
|
|
&fuzzed_properties.value.structure.cipher_mode);
|
|
ConvertDataToValidEnum(OEMCrypto_Algorithm_MaxValue,
|
|
&fuzzed_properties.value.structure.algorithm);
|
|
fuzzed_properties.value.buffer = fuzzed_data.ConsumeRemainingBytes<uint8_t>();
|
|
fuzzed_properties.value.signature.assign(inputs[1].data,
|
|
inputs[1].data + inputs[1].size);
|
|
fuzzed_properties.has_value = true;
|
|
return fuzzed_properties;
|
|
}
|
|
|
|
extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {
|
|
RedirectStdoutToFile();
|
|
license_api_fuzz.LoadLicense();
|
|
return 0;
|
|
}
|
|
|
|
extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data, size_t size,
|
|
size_t max_size, unsigned int seed) {
|
|
// Deserialize fuzzed data.
|
|
OptionalFuzzedProperties fuzzed_properties =
|
|
DeserializeFuzzedData(data, size);
|
|
if (!fuzzed_properties.has_value) {
|
|
return 0;
|
|
}
|
|
|
|
// Select key and perform verification.
|
|
Session* const session = license_api_fuzz.session();
|
|
vector<uint8_t> key_handle;
|
|
GetKeyHandleIntoVector(
|
|
session->session_id(), session->license().keys[0].key_id,
|
|
session->license().keys[0].key_id_length,
|
|
fuzzed_properties.value.structure.cipher_mode, key_handle);
|
|
if (OEMCrypto_Generic_Verify(key_handle.data(), key_handle.size(),
|
|
fuzzed_properties.value.buffer.data(),
|
|
fuzzed_properties.value.buffer.size(),
|
|
fuzzed_properties.value.structure.algorithm,
|
|
fuzzed_properties.value.signature.data(),
|
|
fuzzed_properties.value.signature.size()) !=
|
|
OEMCrypto_SUCCESS) {
|
|
// Generate a new signature.
|
|
size_t signature_length = 0;
|
|
OEMCrypto_Generic_Sign(key_handle.data(), key_handle.size(),
|
|
fuzzed_properties.value.buffer.data(),
|
|
fuzzed_properties.value.buffer.size(),
|
|
fuzzed_properties.value.structure.algorithm, nullptr,
|
|
&signature_length);
|
|
fuzzed_properties.value.signature.resize(signature_length);
|
|
OEMCrypto_Generic_Sign(key_handle.data(), key_handle.size(),
|
|
fuzzed_properties.value.buffer.data(),
|
|
fuzzed_properties.value.buffer.size(),
|
|
fuzzed_properties.value.structure.algorithm,
|
|
fuzzed_properties.value.signature.data(),
|
|
&signature_length);
|
|
const size_t signature_offset = sizeof(fuzzed_properties.value.structure) +
|
|
fuzzed_properties.value.buffer.size() +
|
|
sizeof(kFuzzDataSeparator);
|
|
size = signature_offset + signature_length;
|
|
if (size > max_size) {
|
|
return 0;
|
|
}
|
|
memcpy(data + signature_offset, fuzzed_properties.value.signature.data(),
|
|
signature_length);
|
|
}
|
|
return LLVMFuzzerMutate(data, size, max_size);
|
|
}
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|
// Deserialize fuzzed data.
|
|
const OptionalFuzzedProperties fuzzed_properties =
|
|
DeserializeFuzzedData(data, size);
|
|
if (!fuzzed_properties.has_value) {
|
|
return 0;
|
|
}
|
|
|
|
// Select key and perform verification.
|
|
Session* const session = license_api_fuzz.session();
|
|
vector<uint8_t> key_handle;
|
|
GetKeyHandleIntoVector(
|
|
session->session_id(), session->license().keys[0].key_id,
|
|
session->license().keys[0].key_id_length,
|
|
fuzzed_properties.value.structure.cipher_mode, key_handle);
|
|
OEMCrypto_Generic_Verify(key_handle.data(), key_handle.size(),
|
|
fuzzed_properties.value.buffer.data(),
|
|
fuzzed_properties.value.buffer.size(),
|
|
fuzzed_properties.value.structure.algorithm,
|
|
fuzzed_properties.value.signature.data(),
|
|
fuzzed_properties.value.signature.size());
|
|
return 0;
|
|
}
|
|
|
|
} // namespace wvoec
|