Clean up fuzz helper classes

- Remove OEMCrypto state changes hidden in constructors and destructors.
- Use composition instead of inheritance to structure classes.
- Avoid calling non-trivial destructors for objects with static
  lifetime.

Merged from https://widevine-internal-review.googlesource.com/168497
Merged from https://widevine-internal-review.googlesource.com/171170
Merged from https://widevine-internal-review.googlesource.com/171171
Merged from https://widevine-internal-review.googlesource.com/171870

Change-Id: I20476a7b1132d11f011b8650ec01e3c2dc3fc0e8
This commit is contained in:
Ian Benz
2023-03-20 17:46:15 +00:00
committed by Robert Shih
parent af070601b0
commit 53fe55cb72
30 changed files with 518 additions and 398 deletions

View File

@@ -1,9 +1,12 @@
// 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<FuzzedData> SplitFuzzedData(const uint8_t* data, size_t size) {
@@ -22,6 +25,26 @@ std::vector<FuzzedData> SplitFuzzedData(const uint8_t* data, size_t size) {
return result;
}
void InitializeFuzz(SessionUtil& session_util) {
wvoec::global_features.Initialize();
OEMCrypto_SetSandbox(kTestSandbox, sizeof(kTestSandbox));
OEMCrypto_Initialize();
OEMCrypto_EnterTestMode();
session_util.EnsureTestROT();
}
void OEMCryptoLicenseAPIFuzz::Initialize() {
InitializeFuzz(session_util_);
session_.open();
session_util_.InstallTestDrmKey(&session_);
session_.GenerateNonce();
}
void OEMCryptoLicenseAPIFuzz::Terminate() {
session_.close();
OEMCrypto_Terminate();
}
void OEMCryptoLicenseAPIFuzz::LoadLicense() {
license_messages_.SignAndVerifyRequest();
license_messages_.CreateDefaultResponse();
@@ -30,6 +53,18 @@ void OEMCryptoLicenseAPIFuzz::LoadLicense() {
CheckStatusAndExitFuzzerOnFailure(sts, OEMCrypto_SUCCESS);
}
void OEMCryptoProvisioningAPIFuzz::Intialize() {
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();
@@ -62,4 +97,5 @@ void CheckStatusAndExitFuzzerOnFailure(OEMCryptoResult result,
abort();
}
}
} // namespace wvoec