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