Source release 18.5.0
This commit is contained in:
136
oemcrypto/test/fuzz_tests/oemcrypto_entitled_key_session_fuzz.cc
Normal file
136
oemcrypto/test/fuzz_tests/oemcrypto_entitled_key_session_fuzz.cc
Normal file
@@ -0,0 +1,136 @@
|
||||
// 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 {
|
||||
|
||||
enum class ApiMethod {
|
||||
kOpenSession,
|
||||
kCloseSession,
|
||||
kCreateEntitledKeySession,
|
||||
kReassociateEntitledKeySession,
|
||||
kRemoveEntitledKeySession,
|
||||
kMaxValue = kRemoveEntitledKeySession,
|
||||
};
|
||||
|
||||
struct Session {
|
||||
OEMCrypto_SESSION value;
|
||||
std::vector<OEMCrypto_SESSION>::const_iterator iterator;
|
||||
};
|
||||
|
||||
Session PickSession(FuzzedDataProvider& fuzzed_data,
|
||||
const std::vector<OEMCrypto_SESSION>& sessions) {
|
||||
Session session;
|
||||
|
||||
session.iterator =
|
||||
sessions.cbegin() +
|
||||
fuzzed_data.ConsumeIntegralInRange<size_t>(0, sessions.size());
|
||||
|
||||
if (session.iterator != sessions.cend()) {
|
||||
session.value = *session.iterator;
|
||||
} else {
|
||||
session.value = fuzzed_data.ConsumeIntegral<OEMCrypto_SESSION>();
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
wvoec::RedirectStdoutToFile();
|
||||
|
||||
wvoec::SessionUtil session_util;
|
||||
wvoec::InitializeFuzz(session_util);
|
||||
|
||||
// Contains all open and some closed OEMCrypto sessions.
|
||||
std::vector<OEMCrypto_SESSION> oec_sessions;
|
||||
|
||||
// Contains all current and some removed key sessions.
|
||||
std::vector<OEMCrypto_SESSION> key_sessions;
|
||||
|
||||
FuzzedDataProvider fuzzed_data(data, size);
|
||||
|
||||
while (fuzzed_data.remaining_bytes() > 0) {
|
||||
switch (fuzzed_data.ConsumeEnum<ApiMethod>()) {
|
||||
case ApiMethod::kOpenSession: {
|
||||
OEMCrypto_SESSION session = 0;
|
||||
const OEMCryptoResult result = OEMCrypto_OpenSession(&session);
|
||||
|
||||
if (result == OEMCrypto_SUCCESS) {
|
||||
oec_sessions.push_back(session);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ApiMethod::kCloseSession: {
|
||||
const Session session = PickSession(fuzzed_data, oec_sessions);
|
||||
|
||||
const OEMCryptoResult result = OEMCrypto_CloseSession(session.value);
|
||||
|
||||
if (result == OEMCrypto_SUCCESS &&
|
||||
session.iterator != oec_sessions.cend() &&
|
||||
fuzzed_data.ConsumeBool()) {
|
||||
oec_sessions.erase(session.iterator);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ApiMethod::kCreateEntitledKeySession: {
|
||||
const OEMCrypto_SESSION oec_session =
|
||||
PickSession(fuzzed_data, oec_sessions).value;
|
||||
|
||||
OEMCrypto_SESSION key_session_data = 0;
|
||||
OEMCrypto_SESSION* const key_session =
|
||||
fuzzed_data.ConsumeBool() ? &key_session_data : nullptr;
|
||||
|
||||
const OEMCryptoResult result =
|
||||
OEMCrypto_CreateEntitledKeySession(oec_session, key_session);
|
||||
|
||||
if (result == OEMCrypto_SUCCESS) {
|
||||
key_sessions.push_back(*key_session);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ApiMethod::kReassociateEntitledKeySession: {
|
||||
const OEMCrypto_SESSION key_session =
|
||||
PickSession(fuzzed_data, key_sessions).value;
|
||||
|
||||
const OEMCrypto_SESSION oec_session =
|
||||
PickSession(fuzzed_data, oec_sessions).value;
|
||||
|
||||
OEMCrypto_ReassociateEntitledKeySession(key_session, oec_session);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ApiMethod::kRemoveEntitledKeySession: {
|
||||
const Session key_session = PickSession(fuzzed_data, key_sessions);
|
||||
|
||||
const OEMCryptoResult result =
|
||||
OEMCrypto_RemoveEntitledKeySession(key_session.value);
|
||||
|
||||
if (result == OEMCrypto_SUCCESS &&
|
||||
key_session.iterator != key_sessions.cend() &&
|
||||
fuzzed_data.ConsumeBool()) {
|
||||
key_sessions.erase(key_session.iterator);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OEMCrypto_Terminate();
|
||||
return 0;
|
||||
}
|
||||
@@ -46,7 +46,6 @@ void SessionFuzz::Terminate() {
|
||||
void OEMCryptoLicenseAPIFuzz::Initialize() {
|
||||
session_fuzz_.Initialize();
|
||||
session_fuzz_.InstallTestDrmKey();
|
||||
session_fuzz_.session().GenerateNonce();
|
||||
}
|
||||
|
||||
void OEMCryptoLicenseAPIFuzz::Terminate() {
|
||||
|
||||
@@ -21,12 +21,6 @@
|
||||
'oemcrypto_copy_buffer_fuzz.cc',
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'oemcrypto_opk_create_and_remove_entitled_key_session_fuzz',
|
||||
'sources': [
|
||||
'oemcrypto_create_and_remove_entitled_key_session_fuzz.cc',
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'oemcrypto_opk_deactivate_usage_entry_fuzz',
|
||||
'sources': [
|
||||
@@ -66,6 +60,12 @@
|
||||
'<(oemcrypto_dir)/opk/ports/trusty/serialization_adapter/shared_memory.c',
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'oemcrypto_opk_entitled_key_session_fuzz',
|
||||
'sources': [
|
||||
'oemcrypto_entitled_key_session_fuzz.cc',
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'oemcrypto_opk_generate_certificate_key_pair_first_stage_fuzz',
|
||||
'sources': [
|
||||
|
||||
@@ -19,12 +19,6 @@
|
||||
'oemcrypto_copy_buffer_fuzz.cc',
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'oemcrypto_create_and_remove_entitled_key_session_fuzz',
|
||||
'sources': [
|
||||
'oemcrypto_create_and_remove_entitled_key_session_fuzz.cc',
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'oemcrypto_deactivate_usage_entry_fuzz',
|
||||
'sources': [
|
||||
@@ -43,6 +37,12 @@
|
||||
'oemcrypto_decrypt_hash_fuzz.cc',
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'oemcrypto_entitled_key_session_fuzz',
|
||||
'sources': [
|
||||
'oemcrypto_entitled_key_session_fuzz.cc',
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'oemcrypto_generate_certificate_key_pair_first_stage_fuzz',
|
||||
'sources': [
|
||||
|
||||
Reference in New Issue
Block a user