Updated cdm_license_fuzzer

Implemented google c++ code style changes for cdm_license_fuzzer

exec/s: 91
Test: ./cdm_license_fuzzer
Bug: 312374669

Change-Id: Iac18772277cddad8ca182e60fc426721717d38d4
This commit is contained in:
Onkar Shinde
2023-12-12 09:01:03 +00:00
committed by Aditya Wazir
parent d866ba45aa
commit 2415894e2f

View File

@@ -14,6 +14,8 @@
* limitations under the License.
*
*/
#include <fuzzer/FuzzedDataProvider.h>
#include "cdm_client_property_set.h"
#include "cdm_identifier.h"
#include "cdm_session.h"
@@ -23,15 +25,14 @@
#include "vendor_widevine_fuzz_helper.h"
#include "wv_cdm_constants.h"
#include "wv_cdm_event_listener.h"
#include <fuzzer/FuzzedDataProvider.h>
using namespace wvcdm;
using wvutil::a2bs_hex;
using namespace video_widevine;
const static constexpr int32_t kMaxByte = 256;
const static constexpr int32_t kAPPVersion = 16;
const static constexpr int32_t kMaxAppParamSize = 10;
const static constexpr int32_t kAppVersion = 16;
static constexpr int32_t kMaxAppParamSize = 10;
const static constexpr uint32_t kProtectionScheme[] = {
0x63626331, 0x63626373, 0x31636263, 0x73636263, 0x63656e63};
const std::string kInitDataType[] = {"video/mp4", "video/webm", "cenc", "hls",
@@ -42,8 +43,8 @@ const static constexpr int32_t kSignedType[] = {
SignedMessage::LICENSE, SignedMessage::SERVICE_CERTIFICATE,
SignedMessage::ERROR_RESPONSE};
const std::string kDefaultServiceCertificate =
a2bs_hex("0ABF020803121028703454C008F63618ADE7443DB6C4C8188BE7F9900522"
const std::string kDefaultServiceCertificate = a2bs_hex(
"0ABF020803121028703454C008F63618ADE7443DB6C4C8188BE7F9900522"
"8E023082010A0282010100B52112B8D05D023FCC5D95E2C251C1C649B417"
"7CD8D2BEEF355BB06743DE661E3D2ABC3182B79946D55FDC08DFE9540781"
"5E9A6274B322A2C7F5E067BB5F0AC07A89D45AEA94B2516F075B66EF811D"
@@ -106,92 +107,89 @@ const std::string kToken = a2bs_hex(
"3C");
class FuzzCryptoSession : public CryptoSession {
public:
public:
FuzzCryptoSession(metrics::CryptoMetrics *metrics, FuzzedDataProvider *fdp)
: CryptoSession(metrics), mFdp(fdp){};
: CryptoSession(metrics), fdp_(fdp){};
bool IsOpen() override { return mFdp->ConsumeBool(); };
bool IsOpen() override { return fdp_->ConsumeBool(); };
const std::string &request_id() override { return kRequestId; };
bool GetApiVersion(uint32_t *api_version) override {
*api_version = kAPPVersion;
return mFdp->ConsumeBool();
*api_version = kAppVersion;
return fdp_->ConsumeBool();
};
CdmResponseType GenerateNonce(uint32_t *license_nonce) override {
*license_nonce = mFdp->ConsumeIntegral<uint32_t>();
return (mFdp->ConsumeBool() ? CdmResponseType(NO_ERROR)
*license_nonce = fdp_->ConsumeIntegral<uint32_t>();
return (fdp_->ConsumeBool() ? CdmResponseType(NO_ERROR)
: CdmResponseType(SESSION_LOST_STATE_ERROR));
};
CdmResponseType PrepareAndSignLicenseRequest(
const std::string& /*message*/,
std::string *core_message,
std::string *license_request_signature,
bool & /*shouldSpecifyAlgorithm*/,
const std::string & /*message*/, std::string *core_message,
std::string *license_request_signature, bool & /*shouldSpecifyAlgorithm*/,
OEMCrypto_SignatureHashAlgorithm & /*algorithm*/) override {
*core_message = mFdp->ConsumeRandomLengthString(kMaxByte);
*license_request_signature = mFdp->ConsumeRandomLengthString(kMaxByte);
return (mFdp->ConsumeBool() ? CdmResponseType(NO_ERROR)
*core_message = fdp_->ConsumeRandomLengthString(kMaxByte);
*license_request_signature = fdp_->ConsumeRandomLengthString(kMaxByte);
return (fdp_->ConsumeBool() ? CdmResponseType(NO_ERROR)
: CdmResponseType(NEED_PROVISIONING));
};
CdmResponseType LoadEntitledContentKeys(
const std::vector<CryptoKey> & /*key_array*/) override {
return (mFdp->ConsumeBool()
return (fdp_->ConsumeBool()
? CdmResponseType(KEY_ADDED)
: CdmResponseType(INSUFFICIENT_CRYPTO_RESOURCES));
};
CdmResponseType
GenerateDerivedKeys(const std::string & /*message*/,
CdmResponseType GenerateDerivedKeys(
const std::string & /*message*/,
const std::string & /*session_key*/) override {
return (mFdp->ConsumeBool()
return (fdp_->ConsumeBool()
? CdmResponseType(NO_ERROR)
: CdmResponseType(INSUFFICIENT_CRYPTO_RESOURCES));
};
CdmResponseType DeactivateUsageInformation(
const std::string & /*provider_session_token*/) override {
return (mFdp->ConsumeBool() ? CdmResponseType(NO_ERROR)
return (fdp_->ConsumeBool() ? CdmResponseType(NO_ERROR)
: CdmResponseType(SYSTEM_INVALIDATED_ERROR));
};
CdmResponseType
GenerateUsageReport(const std::string & /*provider_session_token*/,
std::string *usage_report,
CdmResponseType GenerateUsageReport(
const std::string & /*provider_session_token*/, std::string *usage_report,
UsageDurationStatus *usage_duration_status,
int64_t *seconds_since_started,
int64_t *seconds_since_last_played) override {
*usage_report = mFdp->ConsumeRandomLengthString(kMaxByte);
*usage_duration_status = mFdp->ConsumeBool()
*usage_report = fdp_->ConsumeRandomLengthString(kMaxByte);
*usage_duration_status = fdp_->ConsumeBool()
? CryptoSession::kUsageDurationPlaybackNotBegun
: CryptoSession::kUsageDurationsValid;
*seconds_since_started = mFdp->ConsumeIntegral<int64_t>();
*seconds_since_last_played = mFdp->ConsumeIntegral<int64_t>();
return (mFdp->ConsumeBool() ? CdmResponseType(NO_ERROR)
*seconds_since_started = fdp_->ConsumeIntegral<int64_t>();
*seconds_since_last_played = fdp_->ConsumeIntegral<int64_t>();
return (fdp_->ConsumeBool() ? CdmResponseType(NO_ERROR)
: CdmResponseType(SYSTEM_INVALIDATED_ERROR));
};
CdmResponseType PrepareAndSignRenewalRequest(const std::string & /*message*/,
std::string *core_message,
std::string *signature) {
*core_message = mFdp->ConsumeRandomLengthString(kMaxByte);
*signature = mFdp->ConsumeRandomLengthString(kMaxByte);
return (mFdp->ConsumeBool() ? CdmResponseType(NO_ERROR)
*core_message = fdp_->ConsumeRandomLengthString(kMaxByte);
*signature = fdp_->ConsumeRandomLengthString(kMaxByte);
return (fdp_->ConsumeBool() ? CdmResponseType(NO_ERROR)
: CdmResponseType(PARAMETER_NULL));
};
CdmResponseType UseSecondaryKey(bool /*dual_key*/) override {
return (mFdp->ConsumeBool() ? CdmResponseType(NO_ERROR)
return (fdp_->ConsumeBool() ? CdmResponseType(NO_ERROR)
: CdmResponseType(SYSTEM_INVALIDATED_ERROR));
};
CdmResponseType LoadRenewal(const std::string & /*signed_message*/,
const std::string & /*core_message*/,
const std::string & /*signature*/) override {
return (mFdp->ConsumeBool()
return (fdp_->ConsumeBool()
? CdmResponseType(KEY_ADDED)
: CdmResponseType(INSUFFICIENT_CRYPTO_RESOURCES));
};
@@ -200,38 +198,38 @@ public:
const std::string & /*core_message*/,
const std::string & /*signature*/,
CdmLicenseKeyType /*key_type*/) override {
return (mFdp->ConsumeBool()
return (fdp_->ConsumeBool()
? CdmResponseType(KEY_ADDED)
: CdmResponseType(INSUFFICIENT_CRYPTO_RESOURCES));
};
CdmSecurityLevel GetSecurityLevel() override {
return (CdmSecurityLevel)mFdp->ConsumeIntegralInRange<int32_t>(
return (CdmSecurityLevel)fdp_->ConsumeIntegralInRange<int32_t>(
kSecurityLevelUninitialized, kSecurityLevelUnknown);
}
private:
FuzzedDataProvider *mFdp;
private:
FuzzedDataProvider *fdp_;
};
class FuzzPolicyEngine : public PolicyEngine {
public:
public:
FuzzPolicyEngine(CryptoSession *crypto, FuzzedDataProvider *fdp)
: PolicyEngine("mock_session_id", nullptr, crypto), mFdp(fdp){};
: PolicyEngine("mock_session_id", nullptr, crypto), fdp_(fdp){};
void SetEntitledLicenseKeys(const std::vector<WidevinePsshData_EntitledKey>
& /*entitled_keys*/) override{};
bool CanRenew() { return mFdp->ConsumeBool(); }
bool CanRenew() { return fdp_->ConsumeBool(); }
bool GetSecondsSinceStarted(int64_t *seconds_since_started) {
*seconds_since_started = mFdp->ConsumeIntegral<int64_t>();
return mFdp->ConsumeBool();
*seconds_since_started = fdp_->ConsumeIntegral<int64_t>();
return fdp_->ConsumeBool();
}
bool GetSecondsSinceLastPlayed(int64_t *seconds_since_last_played) {
*seconds_since_last_played = mFdp->ConsumeIntegral<int64_t>();
return mFdp->ConsumeBool();
*seconds_since_last_played = fdp_->ConsumeIntegral<int64_t>();
return fdp_->ConsumeBool();
};
void UpdateLicense(const License & /*license*/,
bool /*defer_license_state_update*/){};
@@ -245,293 +243,294 @@ public:
void SetLicense(const License & /*license*/,
bool /*defer_license_state_update*/){};
private:
FuzzedDataProvider *mFdp;
private:
FuzzedDataProvider *fdp_;
};
class CdmLicenseFuzzer {
public:
CdmLicenseFuzzer(const uint8_t *data, size_t size) : mFdp(data, size){};
void process();
public:
CdmLicenseFuzzer(const uint8_t *data, size_t size) : fdp_(data, size){};
void Process();
private:
FuzzedDataProvider mFdp;
void createResponse(CdmKeyResponse *response);
void setLicenseMsg(std::string *msg);
private:
FuzzedDataProvider fdp_;
void CreateResponse(CdmKeyResponse *response);
void SetLicenseMsg(std::string *msg);
};
void policySetBool(std::function<void(bool)> function,
void PolicySetBool(std::function<void(bool)> function,
FuzzedDataProvider *fdp) {
if (fdp->ConsumeBool()) {
function(fdp->ConsumeBool());
}
}
void CdmLicenseFuzzer::setLicenseMsg(std::string *msg) {
void CdmLicenseFuzzer::SetLicenseMsg(std::string *msg) {
License license;
if (mFdp.ConsumeBool()) {
if (fdp_.ConsumeBool()) {
std::string provider_client_token =
mFdp.ConsumeRandomLengthString(kMaxByte);
fdp_.ConsumeRandomLengthString(kMaxByte);
license.set_provider_client_token(provider_client_token);
}
if (mFdp.ConsumeBool()) {
uint32_t scheme = mFdp.ConsumeBool()
? mFdp.PickValueInArray(kProtectionScheme)
: mFdp.ConsumeIntegral<uint32_t>();
if (fdp_.ConsumeBool()) {
uint32_t scheme = fdp_.ConsumeBool()
? fdp_.PickValueInArray(kProtectionScheme)
: fdp_.ConsumeIntegral<uint32_t>();
license.set_protection_scheme(scheme);
}
License::KeyContainer *container = license.add_key();
if (mFdp.ConsumeBool()) {
uint32_t keyType = mFdp.ConsumeIntegralInRange<uint8_t>(
if (fdp_.ConsumeBool()) {
uint32_t key_type = fdp_.ConsumeIntegralInRange<uint8_t>(
License::KeyContainer::SIGNING, License::KeyContainer::ENTITLEMENT);
container->set_type((License_KeyContainer_KeyType)keyType);
container->set_type((License_KeyContainer_KeyType)key_type);
}
if (mFdp.ConsumeBool()) {
const std::string ivString = mFdp.ConsumeRandomLengthString(kMaxByte);
container->set_iv(ivString);
} else if (mFdp.ConsumeBool()) {
if (fdp_.ConsumeBool()) {
const std::string iv_string = fdp_.ConsumeRandomLengthString(kMaxByte);
container->set_iv(iv_string);
} else if (fdp_.ConsumeBool()) {
container->mutable_iv();
}
if (mFdp.ConsumeBool()) {
std::string keyString = mFdp.ConsumeRandomLengthString(kMaxByte);
container->set_key(keyString);
} else if (mFdp.ConsumeBool()) {
if (fdp_.ConsumeBool()) {
std::string key_string = fdp_.ConsumeRandomLengthString(kMaxByte);
container->set_key(key_string);
} else if (fdp_.ConsumeBool()) {
container->mutable_key();
}
if (mFdp.ConsumeBool()) {
const std::string idString = mFdp.ConsumeRandomLengthString(kMaxByte);
container->set_id(idString);
} else if (mFdp.ConsumeBool()) {
if (fdp_.ConsumeBool()) {
const std::string id_string = fdp_.ConsumeRandomLengthString(kMaxByte);
container->set_id(id_string);
} else if (fdp_.ConsumeBool()) {
container->mutable_id();
}
if (mFdp.ConsumeBool()) {
const std::string trackLabel = mFdp.ConsumeRandomLengthString(kMaxByte);
container->set_track_label(trackLabel);
} else if (mFdp.ConsumeBool()) {
if (fdp_.ConsumeBool()) {
const std::string track_label = fdp_.ConsumeRandomLengthString(kMaxByte);
container->set_track_label(track_label);
} else if (fdp_.ConsumeBool()) {
container->mutable_track_label();
}
License_KeyContainer_KeyControl *keyControl =
License_KeyContainer_KeyControl *key_control =
container->mutable_key_control();
if (mFdp.ConsumeBool()) {
std::string keyControlMsg = mFdp.ConsumeRandomLengthString(kMaxByte);
keyControl->set_key_control_block(keyControlMsg);
} else if (mFdp.ConsumeBool()) {
keyControl->mutable_key_control_block();
if (fdp_.ConsumeBool()) {
std::string key_control_msg = fdp_.ConsumeRandomLengthString(kMaxByte);
key_control->set_key_control_block(key_control_msg);
} else if (fdp_.ConsumeBool()) {
key_control->mutable_key_control_block();
}
if (mFdp.ConsumeBool()) {
const std::string ivString = mFdp.ConsumeRandomLengthString(kMaxByte);
keyControl->set_iv(ivString);
} else if (mFdp.ConsumeBool()) {
keyControl->mutable_iv();
if (fdp_.ConsumeBool()) {
const std::string iv_string = fdp_.ConsumeRandomLengthString(kMaxByte);
key_control->set_iv(iv_string);
} else if (fdp_.ConsumeBool()) {
key_control->mutable_iv();
}
if (mFdp.ConsumeBool()) {
if (fdp_.ConsumeBool()) {
License_Policy *policy = license.mutable_policy();
policySetBool(std::bind(&License_Policy::set_can_persist, policy,
PolicySetBool(std::bind(&License_Policy::set_can_persist, policy,
std::placeholders::_1),
&mFdp);
&fdp_);
if (mFdp.ConsumeBool()) {
std::string server_url = mFdp.ConsumeRandomLengthString(kMaxByte);
if (fdp_.ConsumeBool()) {
std::string server_url = fdp_.ConsumeRandomLengthString(kMaxByte);
policy->set_renewal_server_url(server_url);
}
policySetBool(std::bind(&License_Policy::set_always_include_client_id,
PolicySetBool(std::bind(&License_Policy::set_always_include_client_id,
policy, std::placeholders::_1),
&mFdp);
&fdp_);
}
LicenseIdentification *id = license.mutable_id();
if (mFdp.ConsumeBool()) {
id->set_type(mFdp.ConsumeBool() ? STREAMING : OFFLINE);
if (fdp_.ConsumeBool()) {
id->set_type(fdp_.ConsumeBool() ? STREAMING : OFFLINE);
}
if (mFdp.ConsumeBool()) {
if (fdp_.ConsumeBool()) {
std::string provider_session_token =
mFdp.ConsumeRandomLengthString(kMaxByte);
fdp_.ConsumeRandomLengthString(kMaxByte);
id->set_provider_session_token(provider_session_token);
}
license.SerializeToString(msg);
}
void CdmLicenseFuzzer::createResponse(CdmKeyResponse *response) {
void CdmLicenseFuzzer::CreateResponse(CdmKeyResponse *response) {
SignedMessage signed_message;
SignedMessage type;
signed_message.set_type(
(SignedMessage_MessageType)mFdp.PickValueInArray(kSignedType));
(SignedMessage_MessageType)fdp_.PickValueInArray(kSignedType));
if (mFdp.ConsumeBool()) {
if (fdp_.ConsumeBool()) {
signed_message.mutable_service_version_info();
}
if (mFdp.ConsumeBool()) {
signed_message.set_signature(mFdp.ConsumeRandomLengthString(kMaxByte));
if (fdp_.ConsumeBool()) {
signed_message.set_signature(fdp_.ConsumeRandomLengthString(kMaxByte));
}
if (mFdp.ConsumeBool()) {
signed_message.set_session_key(mFdp.ConsumeRandomLengthString(kMaxByte));
if (fdp_.ConsumeBool()) {
signed_message.set_session_key(fdp_.ConsumeRandomLengthString(kMaxByte));
}
if (mFdp.ConsumeBool()) {
if (fdp_.ConsumeBool()) {
signed_message.set_oemcrypto_core_message(
mFdp.ConsumeRandomLengthString(kMaxByte));
fdp_.ConsumeRandomLengthString(kMaxByte));
}
if (mFdp.ConsumeBool()) {
signed_message.set_using_secondary_key(mFdp.ConsumeBool());
if (fdp_.ConsumeBool()) {
signed_message.set_using_secondary_key(fdp_.ConsumeBool());
}
if (mFdp.ConsumeBool()) {
std::string setMsg;
setLicenseMsg(&setMsg);
signed_message.set_msg(setMsg);
if (fdp_.ConsumeBool()) {
std::string set_msg;
SetLicenseMsg(&set_msg);
signed_message.set_msg(set_msg);
}
signed_message.SerializeToString(response);
}
void CdmLicenseFuzzer::process() {
CdmSessionId sessionId = mFdp.ConsumeRandomLengthString(kMaxByte);
CdmLicense cdmLicense(sessionId);
void CdmLicenseFuzzer::Process() {
CdmSessionId session_id = fdp_.ConsumeRandomLengthString(kMaxByte);
CdmLicense cdm_license(session_id);
metrics::CryptoMetrics crypto_metrics;
std::unique_ptr<CryptoSession> cryptoSession(
new FuzzCryptoSession(&crypto_metrics, &mFdp));
std::unique_ptr<PolicyEngine> policyEngine(
new FuzzPolicyEngine(cryptoSession.get(), &mFdp));
std::unique_ptr<CryptoSession> crypto_session(
new FuzzCryptoSession(&crypto_metrics, &fdp_));
std::unique_ptr<PolicyEngine> policy_engine(
new FuzzPolicyEngine(crypto_session.get(), &fdp_));
bool status = cdmLicense.Init(mFdp.ConsumeBool(), kDefaultServiceCertificate,
cryptoSession.get(), policyEngine.get());
bool status = cdm_license.Init(fdp_.ConsumeBool(), kDefaultServiceCertificate,
crypto_session.get(), policy_engine.get());
if (status) {
std::shared_ptr<metrics::SessionMetrics> cdmMetrics(
std::shared_ptr<metrics::SessionMetrics> cdm_metrics(
new metrics::SessionMetrics);
wvutil::FileSystem file_system;
std::unique_ptr<CdmSession> cdmSession(
new CdmSession(&file_system, cdmMetrics));
std::unique_ptr<FuzzCdmClientPropertySet> fuzzCdmClientPropertySet(
new FuzzCdmClientPropertySet(&mFdp));
cdmSession->Init(fuzzCdmClientPropertySet.get());
std::string dataType = mFdp.ConsumeBool()
? mFdp.PickValueInArray(kInitDataType)
: mFdp.ConsumeRandomLengthString(kMaxByte);
std::unique_ptr<InitializationData> initData(new InitializationData(
dataType, a2bs_hex(mFdp.ConsumeRandomLengthString(kMaxByte))));
std::unique_ptr<CdmSession> cdm_session(
new CdmSession(&file_system, cdm_metrics));
std::unique_ptr<FuzzCdmClientPropertySet> fuzz_cdm_client_property_set(
new FuzzCdmClientPropertySet(&fdp_));
cdm_session->Init(fuzz_cdm_client_property_set.get());
std::string data_type = fdp_.ConsumeBool()
? fdp_.PickValueInArray(kInitDataType)
: fdp_.ConsumeRandomLengthString(kMaxByte);
std::unique_ptr<InitializationData> init_data(new InitializationData(
data_type, a2bs_hex(fdp_.ConsumeRandomLengthString(kMaxByte))));
CdmKeyResponse response;
if (mFdp.ConsumeBool()) {
createResponse(&response);
if (fdp_.ConsumeBool()) {
CreateResponse(&response);
} else {
response =
mFdp.ConsumeBool() ? "" : mFdp.ConsumeRandomLengthString(kMaxByte);
fdp_.ConsumeBool() ? "" : fdp_.ConsumeRandomLengthString(kMaxByte);
}
CdmKeyMessage signedRequest = mFdp.ConsumeRandomLengthString(kMaxByte);
while (mFdp.remaining_bytes()) {
auto invokeLicenseAPI =
mFdp.PickValueInArray<const std::function<void()>>({
CdmKeyMessage signed_request = fdp_.ConsumeRandomLengthString(kMaxByte);
while (fdp_.remaining_bytes()) {
auto invoke_license_API =
fdp_.PickValueInArray<const std::function<void()>>({
[&]() {
CdmLicenseType licenseType =
(CdmLicenseType)mFdp.ConsumeIntegralInRange<int32_t>(
CdmLicenseType license_type =
(CdmLicenseType)fdp_.ConsumeIntegralInRange<int32_t>(
kLicenseTypeOffline, kLicenseTypeEmbeddedKeyData);
std::string serverUrl;
std::string server_url;
CdmAppParameterMap param;
int32_t maxSize =
mFdp.ConsumeIntegralInRange<int32_t>(0, kMaxAppParamSize);
for (size_t i = 0; i < maxSize; ++i) {
std::string key = mFdp.ConsumeRandomLengthString(kMaxByte);
std::string value = mFdp.ConsumeRandomLengthString(kMaxByte);
std::string cdmKey(key.c_str(), key.size());
std::string cdmValue(value.c_str(), value.size());
param[cdmKey] = cdmValue;
int32_t max_size =
fdp_.ConsumeIntegralInRange<int32_t>(0, kMaxAppParamSize);
for (size_t i = 0; i < max_size; ++i) {
std::string key = fdp_.ConsumeRandomLengthString(kMaxByte);
std::string value = fdp_.ConsumeRandomLengthString(kMaxByte);
std::string cdm_key(key.c_str(), key.size());
std::string cdm_value(value.c_str(), value.size());
param[cdm_key] = cdm_value;
}
std::string clientToken =
mFdp.ConsumeBool()
? mFdp.ConsumeRandomLengthString(kMaxByte)
std::string client_token =
fdp_.ConsumeBool()
? fdp_.ConsumeRandomLengthString(kMaxByte)
: kToken;
cdmLicense.PrepareKeyRequest(
*initData, clientToken,
licenseType /*kLicenseTypeStreaming*/, param,
(mFdp.ConsumeBool() ? &signedRequest : nullptr),
(mFdp.ConsumeBool() ? &serverUrl : nullptr));
cdm_license.PrepareKeyRequest(
*init_data, client_token,
license_type /*kLicenseTypeStreaming*/, param,
(fdp_.ConsumeBool() ? &signed_request : nullptr),
(fdp_.ConsumeBool() ? &server_url : nullptr));
},
[&]() {
std::string signedServiceCertificate =
mFdp.ConsumeRandomLengthString(kMaxByte);
cdmLicense.SetServiceCertificate(signedServiceCertificate);
std::string signed_service_certificate =
fdp_.ConsumeRandomLengthString(kMaxByte);
cdm_license.SetServiceCertificate(signed_service_certificate);
},
[&]() {
std::string serverUrl;
std::string server_url;
CdmAppParameterMap param;
int32_t maxSize =
mFdp.ConsumeIntegralInRange<int32_t>(0, kMaxAppParamSize);
for (size_t i = 0; i < maxSize; ++i) {
std::string key = mFdp.ConsumeRandomLengthString(kMaxByte);
std::string value = mFdp.ConsumeRandomLengthString(kMaxByte);
std::string cdmKey(key.c_str(), key.size());
std::string cdmValue(value.c_str(), value.size());
param[cdmKey] = cdmValue;
int32_t max_size =
fdp_.ConsumeIntegralInRange<int32_t>(0, kMaxAppParamSize);
for (size_t i = 0; i < max_size; ++i) {
std::string key = fdp_.ConsumeRandomLengthString(kMaxByte);
std::string value = fdp_.ConsumeRandomLengthString(kMaxByte);
std::string cdm_key(key.c_str(), key.size());
std::string cdm_value(value.c_str(), value.size());
param[cdm_key] = cdm_value;
}
cdmLicense.PrepareKeyUpdateRequest(
mFdp.ConsumeBool(), param, cdmSession.get(),
(mFdp.ConsumeBool() ? &signedRequest : nullptr),
(mFdp.ConsumeBool() ? &serverUrl : nullptr));
cdm_license.PrepareKeyUpdateRequest(
fdp_.ConsumeBool(), param, cdm_session.get(),
(fdp_.ConsumeBool() ? &signed_request : nullptr),
(fdp_.ConsumeBool() ? &server_url : nullptr));
},
[&]() {
cdmLicense.HandleKeyResponse(mFdp.ConsumeBool(), response);
cdm_license.HandleKeyResponse(fdp_.ConsumeBool(), response);
},
[&]() {
cdmLicense.HandleKeyUpdateResponse(
mFdp.ConsumeBool() /*is_renewal*/,
mFdp.ConsumeBool() /*is_restore*/, response);
cdm_license.HandleKeyUpdateResponse(
fdp_.ConsumeBool() /*is_renewal*/,
fdp_.ConsumeBool() /*is_restore*/, response);
},
[&]() { cdmLicense.HandleEmbeddedKeyData(*initData); },
[&]() { cdm_license.HandleEmbeddedKeyData(*init_data); },
[&]() {
CdmKeyResponse renewResponse;
createResponse(&renewResponse);
std::string clientToken =
mFdp.ConsumeBool()
? mFdp.ConsumeRandomLengthString(kMaxByte)
CdmKeyResponse renew_response;
CreateResponse(&renew_response);
std::string client_token =
fdp_.ConsumeBool()
? fdp_.ConsumeRandomLengthString(kMaxByte)
: kToken;
cdmLicense.RestoreOfflineLicense(
clientToken, signedRequest, response, renewResponse,
mFdp.ConsumeIntegral<int64_t>() /*playback_start_time*/,
mFdp.ConsumeIntegral<int64_t>() /*last_playback_time*/,
mFdp.ConsumeIntegral<int64_t>() /*grace_period_end_time*/,
cdmSession.get());
cdm_license.RestoreOfflineLicense(
client_token, signed_request, response, renew_response,
fdp_.ConsumeIntegral<int64_t>() /*playback_start_time*/,
fdp_.ConsumeIntegral<int64_t>() /*last_playback_time*/,
fdp_.ConsumeIntegral<int64_t>() /*grace_period_end_time*/,
cdm_session.get());
},
[&]() {
std::string clientToken =
mFdp.ConsumeBool()
? mFdp.ConsumeRandomLengthString(kMaxByte)
std::string client_token =
fdp_.ConsumeBool()
? fdp_.ConsumeRandomLengthString(kMaxByte)
: kToken;
cdmLicense.RestoreLicenseForRelease(clientToken, signedRequest,
response);
cdm_license.RestoreLicenseForRelease(client_token,
signed_request, response);
},
[&]() {
KeyId keyId = mFdp.ConsumeRandomLengthString(kMaxByte);
cdmLicense.IsKeyLoaded(keyId);
KeyId key_id = fdp_.ConsumeRandomLengthString(kMaxByte);
cdm_license.IsKeyLoaded(key_id);
},
[&]() {
std::string sessionToken;
cdmLicense.ExtractProviderSessionToken(response, &sessionToken);
std::string session_token;
cdm_license.ExtractProviderSessionToken(response,
&session_token);
},
});
invokeLicenseAPI();
invoke_license_API();
}
}
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
CdmLicenseFuzzer cdmLicenseFuzzer(data, size);
cdmLicenseFuzzer.process();
CdmLicenseFuzzer cdm_license_fuzzer(data, size);
cdm_license_fuzzer.Process();
return 0;
}