Cherry pick 18.4 changes to udc-widevine-dev

Get the udc-widevine-dev Android branch and oemcrypto-v18 cdm branch in
sync. The commit ID for 18.4 on oemcrypto-v18 is
https://widevine-internal.git.corp.google.com/cdm/+/a2f23a2281e5e06dc2867585bdc516fa132b639.

Merged from go/wvgerrit/190151

Bug: 290252845
Test: unit tests passing on Panther device
Change-Id: I63fa3f1c784f737ca1480e5febe4f3f5a8a49948
This commit is contained in:
Vicky Min
2024-02-01 19:18:44 +00:00
parent 540c8dfd50
commit 4129b3ac9f
48 changed files with 1491 additions and 330 deletions

View 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;
}

View File

@@ -0,0 +1,37 @@
#include "oemcrypto_session_tests_helper.h"
#include "properties.h"
using namespace wvoec;
static bool is_init = false;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
SessionUtil session_helper;
if (!is_init) {
wvoec::global_features.Initialize();
wvoec::global_features.RestrictFilter("*");
wvutil::Properties::Init();
is_init = true;
}
OEMCrypto_Initialize();
OEMCrypto_EnterTestMode();
session_helper.EnsureTestROT();
Session s;
s.open();
s.GenerateDerivedKeysFromKeybox(session_helper.keybox_);
static const uint32_t SignatureBufferMaxLength = size;
vector<uint8_t> signature(SignatureBufferMaxLength);
size_t signature_length = signature.size();
OEMCryptoResult sts;
sts = OEMCrypto_GenerateSignature(s.session_id(), data, size, &signature[0],
&signature_length);
s.close();
OEMCrypto_Terminate();
return 0;
}