Source release 17.1.2
This commit is contained in:
@@ -1,36 +1,81 @@
|
||||
// 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 "OEMCryptoCENC.h"
|
||||
#include "oemcrypto_fuzz_helper.h"
|
||||
|
||||
namespace wvoec {
|
||||
|
||||
void RedirectStdoutToFile() { freopen("log.txt", "a", stdout); }
|
||||
|
||||
std::vector<std::vector<uint8_t>> SplitInput(const uint8_t* data, size_t size) {
|
||||
std::vector<std::vector<uint8_t>> result;
|
||||
auto current_pos = data;
|
||||
auto end = data + size;
|
||||
// Using memmem to find separator
|
||||
while (const uint8_t* pos = reinterpret_cast<const uint8_t*>(
|
||||
memmem(current_pos, end - current_pos, kFuzzDataSeparator,
|
||||
sizeof(kFuzzDataSeparator)))) {
|
||||
result.push_back({current_pos, pos});
|
||||
current_pos = pos + sizeof(kFuzzDataSeparator);
|
||||
std::vector<FuzzedData> SplitFuzzedData(const uint8_t* data, size_t size) {
|
||||
std::vector<FuzzedData> result;
|
||||
const uint8_t* const end = data + size;
|
||||
// Using memmem to find separator.
|
||||
while (
|
||||
const uint8_t* const separator = reinterpret_cast<const uint8_t*>(memmem(
|
||||
data, end - data, kFuzzDataSeparator, sizeof(kFuzzDataSeparator)))) {
|
||||
result.push_back({data, static_cast<size_t>(separator - data)});
|
||||
data = separator + sizeof(kFuzzDataSeparator);
|
||||
}
|
||||
if (current_pos < end) {
|
||||
result.push_back({current_pos, end});
|
||||
if (data < end) {
|
||||
result.push_back({data, static_cast<size_t>(end - data)});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void OEMCryptoLicenseAPIFuzz::LoadLicense() {
|
||||
void InitializeFuzz(SessionUtil& session_util) {
|
||||
wvoec::global_features.Initialize();
|
||||
OEMCrypto_SetSandbox(kTestSandbox, sizeof(kTestSandbox));
|
||||
OEMCrypto_Initialize();
|
||||
session_util.EnsureTestKeys();
|
||||
}
|
||||
|
||||
void SessionFuzz::Initialize() {
|
||||
InitializeFuzz(session_util_);
|
||||
session_.open();
|
||||
}
|
||||
|
||||
void SessionFuzz::Terminate() {
|
||||
session_.close();
|
||||
OEMCrypto_Terminate();
|
||||
}
|
||||
|
||||
void OEMCryptoLicenseAPIFuzz::Initialize() {
|
||||
session_fuzz_.Initialize();
|
||||
session_fuzz_.InstallTestRSAKey();
|
||||
session_fuzz_.session().GenerateNonce();
|
||||
}
|
||||
|
||||
void OEMCryptoLicenseAPIFuzz::Terminate() {
|
||||
session_fuzz_.Terminate();
|
||||
}
|
||||
|
||||
void OEMCryptoLicenseAPIFuzz::LoadLicense(bool generic_crypto_keys) {
|
||||
license_messages_.SignAndVerifyRequest();
|
||||
license_messages_.CreateDefaultResponse();
|
||||
if (generic_crypto_keys) {
|
||||
license_messages_.CreateResponseWithGenericCryptoKeys();
|
||||
} else {
|
||||
license_messages_.CreateDefaultResponse();
|
||||
}
|
||||
license_messages_.EncryptAndSignResponse();
|
||||
OEMCryptoResult sts = license_messages_.LoadResponse();
|
||||
CheckStatusAndExitFuzzerOnFailure(sts, OEMCrypto_SUCCESS);
|
||||
}
|
||||
|
||||
void OEMCryptoProvisioningAPIFuzz::Initialize() {
|
||||
InitializeFuzz(session_util_);
|
||||
|
||||
// Opens a session and Generates Nonce.
|
||||
provisioning_messages_.PrepareSession(session_util_.keybox_);
|
||||
}
|
||||
|
||||
void OEMCryptoProvisioningAPIFuzz::Terminate() {
|
||||
session_.close();
|
||||
OEMCrypto_Terminate();
|
||||
}
|
||||
|
||||
void OEMCryptoProvisioningAPIFuzz::LoadProvisioning() {
|
||||
provisioning_messages_.SignAndVerifyRequest();
|
||||
provisioning_messages_.CreateDefaultResponse();
|
||||
@@ -63,4 +108,5 @@ void CheckStatusAndExitFuzzerOnFailure(OEMCryptoResult result,
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace wvoec
|
||||
|
||||
Reference in New Issue
Block a user