diff --git a/fuzzer/cdm_session_fuzzer.cpp b/fuzzer/cdm_session_fuzzer.cpp index 01ffbe13..f02ae54d 100644 --- a/fuzzer/cdm_session_fuzzer.cpp +++ b/fuzzer/cdm_session_fuzzer.cpp @@ -55,65 +55,65 @@ class FuzzEventListener : public WvCdmEventListener { }; class CdmSessionFuzzer { -public: - CdmSessionFuzzer(const uint8_t *data, size_t size) : mFdp(data, size){}; - void process(); + public: + CdmSessionFuzzer(const uint8_t *data, size_t size) : fdp_(data, size){}; + void Process(); -private: - FuzzedDataProvider mFdp; - void invokeCdmSessionAPIs(CdmSession *cdmSession); - void invokeCdmSessionMapAPIs(); + private: + FuzzedDataProvider fdp_; + void InvokeCdmSessionAPIs(CdmSession *cdm_session); + void InvokeCdmSessionMapAPIs(); CdmResponseType - initCdmSession(CdmSession *cdmSession, - FuzzCdmClientPropertySet *fuzzCdmClientPropertySet, - CdmSessionId forcedsessionId, - FuzzEventListener *fuzzeventListener, bool forcedLevel); - void createResponse(CdmKeyResponse *response); - void setLicenseMsg(std::string *msg); - void storeLicense(DeviceFiles::CdmLicenseData licenseData); + InitCdmSession(CdmSession *cdm_session, + FuzzCdmClientPropertySet *fuzz_cdm_client_property_set, + CdmSessionId forced_session_id, + FuzzEventListener *fuzz_event_listener, bool forced_level); + void CreateResponse(CdmKeyResponse *response); + void SetLicenseMsg(std::string *msg); + void StoreLicense(DeviceFiles::CdmLicenseData license_data); }; class FuzzFile : public File { -public: - FuzzFile(FuzzedDataProvider *fdp) : mFdp(fdp) {} + public: + FuzzFile(FuzzedDataProvider *fdp) : fdp_(fdp) {} ssize_t Read(char *buffer, size_t bytes) { - std::vector initData = mFdp->ConsumeBytes( - mFdp->ConsumeIntegralInRange(kMinByte, bytes)); - buffer = initData.data(); - return initData.size(); + std::vector init_data = fdp_->ConsumeBytes( + fdp_->ConsumeIntegralInRange(kMinByte, bytes)); + buffer = init_data.data(); + return init_data.size(); }; ssize_t Write(const char * /* buffer*/, size_t bytes) { - return mFdp->ConsumeIntegralInRange(kMinByte, bytes); + return fdp_->ConsumeIntegralInRange(kMinByte, bytes); }; -private: - FuzzedDataProvider *mFdp; + private: + FuzzedDataProvider *fdp_; }; class FuzzFileSystem : public FileSystem { -public: - FuzzFileSystem(FuzzedDataProvider *fdp) : mFdp(fdp) {} + public: + FuzzFileSystem(FuzzedDataProvider *fdp) : fdp_(fdp) {} std::unique_ptr Open(const std::string &, int) { - return std::unique_ptr(new FuzzFile(mFdp)); + return std::unique_ptr(new FuzzFile(fdp_)); } - bool Exists(const std::string &) { return mFdp->ConsumeBool(); } + bool Exists(const std::string &) { return fdp_->ConsumeBool(); } - bool Remove(const std::string &) { return mFdp->ConsumeBool(); } + bool Remove(const std::string &) { return fdp_->ConsumeBool(); } ssize_t FileSize(const std::string &) { - return mFdp->ConsumeIntegralInRange(kMinByte, kMaxByte); + return fdp_->ConsumeIntegralInRange(kMinByte, kMaxByte); } bool List(const std::string &, std::vector *) { - return mFdp->ConsumeBool(); + return fdp_->ConsumeBool(); } -private: - FuzzedDataProvider *mFdp; + private: + FuzzedDataProvider *fdp_; }; void policySetBool(std::function function, @@ -123,446 +123,446 @@ void policySetBool(std::function function, } } -void CdmSessionFuzzer::setLicenseMsg(std::string *msg) { +void CdmSessionFuzzer::SetLicenseMsg(std::string *msg) { video_widevine::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.ConsumeIntegral(); + if (fdp_.ConsumeBool()) { + uint32_t scheme = fdp_.ConsumeIntegral(); license.set_protection_scheme(scheme); } video_widevine::License::KeyContainer *container = license.add_key(); - if (mFdp.ConsumeBool()) { - uint32_t keyType = mFdp.ConsumeIntegralInRange( + if (fdp_.ConsumeBool()) { + uint32_t key_type = fdp_.ConsumeIntegralInRange( video_widevine::License::KeyContainer::SIGNING, video_widevine::License::KeyContainer::ENTITLEMENT); - container->set_type((video_widevine::License_KeyContainer_KeyType)keyType); + container->set_type((video_widevine::License_KeyContainer_KeyType)key_type); } - if (mFdp.ConsumeBool()) { + if (fdp_.ConsumeBool()) { container->mutable_iv(); } - if (mFdp.ConsumeBool()) { - std::string keyString = mFdp.ConsumeRandomLengthString(kMaxByte); - container->set_key(keyString); + if (fdp_.ConsumeBool()) { + std::string key_string = fdp_.ConsumeRandomLengthString(kMaxByte); + container->set_key(key_string); } - if (mFdp.ConsumeBool()) { + if (fdp_.ConsumeBool()) { container->mutable_id(); } - if (mFdp.ConsumeBool()) { + if (fdp_.ConsumeBool()) { container->mutable_track_label(); } - video_widevine::License_KeyContainer_KeyControl *keyControl = + video_widevine::License_KeyContainer_KeyControl *key_control = container->mutable_key_control(); - if (mFdp.ConsumeBool()) { - keyControl->mutable_key_control_block(); + if (fdp_.ConsumeBool()) { + key_control->mutable_key_control_block(); } - if (mFdp.ConsumeBool()) { - keyControl->mutable_iv(); + if (fdp_.ConsumeBool()) { + key_control->mutable_iv(); } - if (mFdp.ConsumeBool()) { + if (fdp_.ConsumeBool()) { video_widevine::License_Policy *policy = license.mutable_policy(); policySetBool(std::bind(&video_widevine::License_Policy::set_can_persist, policy, std::placeholders::_1), - &mFdp); - if (mFdp.ConsumeBool()) { - std::string server_url = mFdp.ConsumeRandomLengthString(kMaxByte); + &fdp_); + if (fdp_.ConsumeBool()) { + std::string server_url = fdp_.ConsumeRandomLengthString(kMaxByte); policy->set_renewal_server_url(server_url); } policySetBool( std::bind(&video_widevine::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() ? video_widevine::STREAMING + if (fdp_.ConsumeBool()) { + id->set_type(fdp_.ConsumeBool() ? video_widevine::STREAMING : video_widevine::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 CdmSessionFuzzer::createResponse(CdmKeyResponse *response) { +void CdmSessionFuzzer::CreateResponse(CdmKeyResponse *response) { video_widevine::SignedMessage signed_message; video_widevine::SignedMessage type; signed_message.set_type(video_widevine::SignedMessage::LICENSE); signed_message.mutable_service_version_info(); - std::string sign = mFdp.ConsumeRandomLengthString(kMaxByte); + std::string sign = fdp_.ConsumeRandomLengthString(kMaxByte); sign.resize(kMaxId, '0'); signed_message.set_signature(sign); - std::string key = mFdp.ConsumeRandomLengthString(kMaxByte); + std::string key = fdp_.ConsumeRandomLengthString(kMaxByte); key.resize(kMaxId, '0'); signed_message.set_session_key(key); - std::string message = mFdp.ConsumeRandomLengthString(kMaxByte); + std::string message = fdp_.ConsumeRandomLengthString(kMaxByte); message.resize(kMaxId, '0'); signed_message.set_oemcrypto_core_message(message); - signed_message.set_using_secondary_key(mFdp.ConsumeBool()); - std::string setMsg = mFdp.ConsumeRandomLengthString(kMaxByte); - signed_message.set_msg(setMsg); + signed_message.set_using_secondary_key(fdp_.ConsumeBool()); + std::string set_msg = fdp_.ConsumeRandomLengthString(kMaxByte); + signed_message.set_msg(set_msg); signed_message.SerializeToString(response); } -CdmResponseType CdmSessionFuzzer::initCdmSession( - CdmSession *cdmSession, FuzzCdmClientPropertySet *fuzzCdmClientPropertySet, - CdmSessionId forcedsessionId, FuzzEventListener *fuzzeventListener, - bool forcedLevel) { +CdmResponseType CdmSessionFuzzer::InitCdmSession( + CdmSession *cdm_session, FuzzCdmClientPropertySet *fuzz_cdm_client_property_set, + CdmSessionId forced_session_id, FuzzEventListener *fuzz_event_listener, + bool forced_level) { CdmResponseType result; - if (mFdp.ConsumeBool()) { + if (fdp_.ConsumeBool()) { result = - cdmSession->Init(fuzzCdmClientPropertySet /*cdm_client_property_set*/, - &forcedsessionId /*forced_session_id*/, - fuzzeventListener /*event_listener*/, forcedLevel); + cdm_session->Init(fuzz_cdm_client_property_set /*cdm_client_property_set*/, + &forced_session_id /*forced_session_id*/, + fuzz_event_listener /*event_listener*/, forced_level); } else { result = - cdmSession->Init(fuzzCdmClientPropertySet /*cdm_client_property_set*/); + cdm_session->Init(fuzz_cdm_client_property_set /*cdm_client_property_set*/); } return result; } -void CdmSessionFuzzer::storeLicense(DeviceFiles::CdmLicenseData licenseData) { - FuzzFileSystem fileSystemdev(&mFdp); - DeviceFiles deviceFiles(mFdp.ConsumeBool() ? &fileSystemdev : nullptr); - deviceFiles.Init((CdmSecurityLevel)mFdp.ConsumeIntegralInRange( +void CdmSessionFuzzer::StoreLicense(DeviceFiles::CdmLicenseData license_data) { + FuzzFileSystem file_system_dev(&fdp_); + DeviceFiles deviceFiles(fdp_.ConsumeBool() ? &file_system_dev : nullptr); + deviceFiles.Init((CdmSecurityLevel)fdp_.ConsumeIntegralInRange( kSecurityLevelL1, kSecurityLevelL3)); - std::map appParameters; + std::map app_parameters; - appParameters[mFdp.ConsumeBytesAsString(kMaxByte)] = - mFdp.ConsumeBytesAsString(kMaxByte); - licenseData.key_set_id = - std::to_string(mFdp.ConsumeIntegralInRange(kMinId, kMaxId)); - licenseData.state = - (CdmOfflineLicenseState)mFdp.ConsumeIntegralInRange( + app_parameters[fdp_.ConsumeBytesAsString(kMaxByte)] = + fdp_.ConsumeBytesAsString(kMaxByte); + license_data.key_set_id = + std::to_string(fdp_.ConsumeIntegralInRange(kMinId, kMaxId)); + license_data.state = + (CdmOfflineLicenseState)fdp_.ConsumeIntegralInRange( kLicenseStateActive, kLicenseStateUnknown); - licenseData.pssh_data = mFdp.ConsumeRandomLengthString(kMaxByte); - licenseData.license_request = mFdp.ConsumeRandomLengthString(kMaxByte); - licenseData.license = mFdp.ConsumeRandomLengthString(kMaxByte); - licenseData.license_renewal_request = - mFdp.ConsumeRandomLengthString(kMaxByte); - licenseData.license_renewal = mFdp.ConsumeRandomLengthString(kMaxByte); - licenseData.release_server_url = mFdp.ConsumeRandomLengthString(kMaxByte); - licenseData.playback_start_time = mFdp.ConsumeIntegral(); - licenseData.last_playback_time = mFdp.ConsumeIntegral(); - licenseData.grace_period_end_time = mFdp.ConsumeIntegral(); - licenseData.app_parameters = appParameters; - licenseData.usage_entry = mFdp.ConsumeRandomLengthString(kMaxByte); - licenseData.usage_entry_index = mFdp.ConsumeIntegral(); - licenseData.drm_certificate = mFdp.ConsumeRandomLengthString(kMaxByte); - licenseData.wrapped_private_key = CryptoWrappedKey( - (CryptoWrappedKey::Type)mFdp.ConsumeIntegralInRange( + license_data.pssh_data = fdp_.ConsumeRandomLengthString(kMaxByte); + license_data.license_request = fdp_.ConsumeRandomLengthString(kMaxByte); + license_data.license = fdp_.ConsumeRandomLengthString(kMaxByte); + license_data.license_renewal_request = + fdp_.ConsumeRandomLengthString(kMaxByte); + license_data.license_renewal = fdp_.ConsumeRandomLengthString(kMaxByte); + license_data.release_server_url = fdp_.ConsumeRandomLengthString(kMaxByte); + license_data.playback_start_time = fdp_.ConsumeIntegral(); + license_data.last_playback_time = fdp_.ConsumeIntegral(); + license_data.grace_period_end_time = fdp_.ConsumeIntegral(); + license_data.app_parameters = app_parameters; + license_data.usage_entry = fdp_.ConsumeRandomLengthString(kMaxByte); + license_data.usage_entry_index = fdp_.ConsumeIntegral(); + license_data.drm_certificate = fdp_.ConsumeRandomLengthString(kMaxByte); + license_data.wrapped_private_key = CryptoWrappedKey( + (CryptoWrappedKey::Type)fdp_.ConsumeIntegralInRange( CryptoWrappedKey::kUninitialized, CryptoWrappedKey::kEcc), - mFdp.ConsumeRandomLengthString(kMaxByte)); + fdp_.ConsumeRandomLengthString(kMaxByte)); DeviceFiles::ResponseType result; - deviceFiles.StoreLicense(licenseData, &result); + deviceFiles.StoreLicense(license_data, &result); } -void CdmSessionFuzzer::invokeCdmSessionAPIs(CdmSession *cdmSession) { +void CdmSessionFuzzer::InvokeCdmSessionAPIs(CdmSession *cdm_session) { CdmKeyResponse response; - createResponse(&response); - CdmKeyRequest keyRequest; - CdmKeyMessage signedRequest; - keyRequest.message = signedRequest; - keyRequest.type = (CdmKeyRequestType)mFdp.ConsumeIntegralInRange( + CreateResponse(&response); + CdmKeyRequest key_request; + CdmKeyMessage signed_request; + key_request.message = signed_request; + key_request.type = (CdmKeyRequestType)fdp_.ConsumeIntegralInRange( kKeyRequestTypeUnknown, kKeyRequestTypeRelease); std::string url; - keyRequest.url = url; - while (mFdp.remaining_bytes()) { - auto invokeCdmSessionAPI = mFdp.PickValueInArray< + key_request.url = url; + while (fdp_.remaining_bytes()) { + auto invokeCdmSessionAPI = fdp_.PickValueInArray< const std::function>( - {[&]() { cdmSession->AddKey(response /*key_response*/); }, + {[&]() { cdm_session->AddKey(response /*key_response*/); }, [&]() { - FuzzCdmClientPropertySet propertyset(&mFdp); - propertyset.enable_privacy_mode(); - propertyset.set_service_certificate(kTestSignedCertificate); + FuzzCdmClientPropertySet property_set(&fdp_); + property_set.enable_privacy_mode(); + property_set.set_service_certificate(kTestSignedCertificate); PropertiesTestPeer::ForceReinit(); PropertiesTestPeer::AddSessionPropertySet( - mFdp.ConsumeBool() ? kTestSessionId1 - : mFdp.ConsumeRandomLengthString(kMaxByte), - &propertyset); - std::string rawServiceCertificate; + fdp_.ConsumeBool() ? kTestSessionId1 + : fdp_.ConsumeRandomLengthString(kMaxByte), + &property_set); + std::string raw_service_certificate; PropertiesTestPeer::GetServiceCertificate( - mFdp.ConsumeBool() ? kTestSessionId1 - : mFdp.ConsumeRandomLengthString(kMaxByte), - &rawServiceCertificate); - cdmSession->SetServiceCertificate( - rawServiceCertificate /*service_certificate*/); + fdp_.ConsumeBool() ? kTestSessionId1 + : fdp_.ConsumeRandomLengthString(kMaxByte), + &raw_service_certificate); + cdm_session->SetServiceCertificate( + raw_service_certificate /*service_certificate*/); }, [&]() { - CdmQueryMap queryResponse; - cdmSession->QueryKeyStatus(&queryResponse /*query_response*/); + CdmQueryMap query_response; + cdm_session->QueryKeyStatus(&query_response /*query_response*/); }, [&]() { - const std::string oecVersion = std::to_string( - mFdp.ConsumeIntegralInRange(kMinId, kMaxId)); - std::string dataType = mFdp.PickValueInArray(kInitType); - std::unique_ptr initData(new InitializationData( - dataType, a2bs_hex(mFdp.ConsumeRandomLengthString(kMaxByte)), - oecVersion)); - CdmLicenseType licenseType = - (CdmLicenseType)mFdp.ConsumeIntegralInRange( + const std::string oec_version = std::to_string( + fdp_.ConsumeIntegralInRange(kMinId, kMaxId)); + std::string data_type = fdp_.PickValueInArray(kInitType); + std::unique_ptr init_data(new InitializationData( + data_type, a2bs_hex(fdp_.ConsumeRandomLengthString(kMaxByte)), + oec_version)); + CdmLicenseType license_type = + (CdmLicenseType)fdp_.ConsumeIntegralInRange( kLicenseTypeOffline, kLicenseTypeEmbeddedKeyData); - CdmAppParameterMap appParameters; - cdmSession->GenerateKeyRequest( - *initData /*init_data*/, licenseType /*license_type*/, - appParameters /*app_parameters*/, &keyRequest /*key_request*/); + CdmAppParameterMap app_parameters; + cdm_session->GenerateKeyRequest( + *init_data /*init_data*/, license_type /*license_type*/, + app_parameters /*app_parameters*/, &key_request /*key_request*/); }, [&]() { - CdmQueryMap queryResponse; - cdmSession->QueryStatus(&queryResponse /*query_response*/); + CdmQueryMap query_response; + cdm_session->QueryStatus(&query_response /*query_response*/); }, [&]() { - DeviceFiles::CdmLicenseData licenseData; - storeLicense(licenseData); - std::string randomData = mFdp.ConsumeRandomLengthString(kMaxByte); - const CdmKeySetId keySetId = - mFdp.ConsumeBool() - ? (kKeyId + wvutil::b2a_hex(randomData)) + DeviceFiles::CdmLicenseData license_data; + StoreLicense(license_data); + std::string random_data = fdp_.ConsumeRandomLengthString(kMaxByte); + const CdmKeySetId key_set_id = + fdp_.ConsumeBool() + ? (kKeyId + wvutil::b2a_hex(random_data)) : std::to_string( - mFdp.ConsumeIntegralInRange(kMinId, kMaxId)); - CdmLicenseType licenseType = - (CdmLicenseType)mFdp.ConsumeIntegralInRange( + fdp_.ConsumeIntegralInRange(kMinId, kMaxId)); + CdmLicenseType license_type = + (CdmLicenseType)fdp_.ConsumeIntegralInRange( kLicenseTypeOffline, kLicenseTypeEmbeddedKeyData); - int errorDetail = mFdp.ConsumeIntegral(); - cdmSession->RestoreOfflineSession(keySetId /*key_set_id*/, - licenseType /*license_type*/, - &errorDetail /*error_detail*/); + int error_detail = fdp_.ConsumeIntegral(); + cdm_session->RestoreOfflineSession(key_set_id /*key_set_id*/, + license_type /*license_type*/, + &error_detail /*error_detail*/); }, [&]() { - DeviceFiles::CdmUsageData usageData; - usageData.provider_session_token = - mFdp.ConsumeRandomLengthString(kMaxByte); - usageData.license_request = mFdp.ConsumeRandomLengthString(kMaxByte); - usageData.license = mFdp.ConsumeRandomLengthString(kMaxByte); - std::string randomData = mFdp.ConsumeRandomLengthString(kMaxByte); - usageData.key_set_id = - mFdp.ConsumeBool() - ? (kKeyId + wvutil::b2a_hex(randomData)) + DeviceFiles::CdmUsageData usage_Data; + usage_Data.provider_session_token = + fdp_.ConsumeRandomLengthString(kMaxByte); + usage_Data.license_request = fdp_.ConsumeRandomLengthString(kMaxByte); + usage_Data.license = fdp_.ConsumeRandomLengthString(kMaxByte); + std::string random_data = fdp_.ConsumeRandomLengthString(kMaxByte); + usage_Data.key_set_id = + fdp_.ConsumeBool() + ? (kKeyId + wvutil::b2a_hex(random_data)) : std::to_string( - mFdp.ConsumeIntegralInRange(kMinId, kMaxId)); - usageData.usage_entry = mFdp.ConsumeRandomLengthString(kMaxByte); - usageData.usage_entry_index = mFdp.ConsumeIntegral(); - usageData.drm_certificate = mFdp.ConsumeRandomLengthString(kMaxByte); - usageData.wrapped_private_key = CryptoWrappedKey( - (CryptoWrappedKey::Type)mFdp.ConsumeIntegralInRange( + fdp_.ConsumeIntegralInRange(kMinId, kMaxId)); + usage_Data.usage_entry = fdp_.ConsumeRandomLengthString(kMaxByte); + usage_Data.usage_entry_index = fdp_.ConsumeIntegral(); + usage_Data.drm_certificate = fdp_.ConsumeRandomLengthString(kMaxByte); + usage_Data.wrapped_private_key = CryptoWrappedKey( + (CryptoWrappedKey::Type)fdp_.ConsumeIntegralInRange( CryptoWrappedKey::kUninitialized, CryptoWrappedKey::kEcc), - mFdp.ConsumeRandomLengthString(kMaxByte)); - int errorDetail = mFdp.ConsumeIntegral(); - cdmSession->RestoreUsageSession(usageData /*usage_data*/, - &errorDetail /*error_detail*/); + fdp_.ConsumeRandomLengthString(kMaxByte)); + int error_detail = fdp_.ConsumeIntegral(); + cdm_session->RestoreUsageSession(usage_Data /*usage_data*/, + &error_detail /*error_detail*/); }, [&]() { - const std::string keyId = std::to_string( - mFdp.ConsumeIntegralInRange(kMinId, kMaxId)); - CdmKeyAllowedUsage keyUsage; - cdmSession->QueryKeyAllowedUsage(keyId /*key_id*/, - &keyUsage /*key_usage*/); + const std::string key_id = std::to_string( + fdp_.ConsumeIntegralInRange(kMinId, kMaxId)); + CdmKeyAllowedUsage key_usage; + cdm_session->QueryKeyAllowedUsage(key_id /*key_id*/, + &key_usage /*key_usage*/); }, [&]() { - CdmQueryMap queryResponse; - cdmSession->QueryOemCryptoSessionId( - &queryResponse /*query_response*/); + CdmQueryMap query_response; + cdm_session->QueryOemCryptoSessionId( + &query_response /*query_response*/); }, [&]() { - const KeyId keyId = std::to_string( - mFdp.ConsumeIntegralInRange(kMinId, kMaxId)); - CdmDecryptionParametersV16 params(keyId); - const uint8_t encryptBufferParam = mFdp.ConsumeIntegral(); - void *decryptBufferParam; - size_t decryptbufferOffsetParam = mFdp.ConsumeIntegral(); - size_t length = mFdp.ConsumeIntegral(); - const std::vector iv = mFdp.ConsumeBytes(kMaxSize); - CdmDecryptionSample sample(&encryptBufferParam, decryptBufferParam, - decryptbufferOffsetParam, length, iv); - CdmDecryptionSubsample subsample(mFdp.ConsumeIntegral(), - mFdp.ConsumeIntegral()); - sample.subsamples.push_back(subsample); + const KeyId key_id = std::to_string( + fdp_.ConsumeIntegralInRange(kMinId, kMaxId)); + CdmDecryptionParametersV16 params(key_id); + const uint8_t encrypt_buffer_param = fdp_.ConsumeIntegral(); + void *decrypt_buffer_param; + size_t decrypt_buffer_offset_param = fdp_.ConsumeIntegral(); + size_t length = fdp_.ConsumeIntegral(); + const std::vector iv = fdp_.ConsumeBytes(kMaxSize); + CdmDecryptionSample sample(&encrypt_buffer_param, decrypt_buffer_param, + decrypt_buffer_offset_param, length, iv); + CdmDecryptionSubsample sub_sample(fdp_.ConsumeIntegral(), + fdp_.ConsumeIntegral()); + sample.subsamples.push_back(sub_sample); params.samples.push_back(sample); - cdmSession->Decrypt(params /*parameters*/); + cdm_session->Decrypt(params /*parameters*/); }, [&]() { - cdmSession->GenerateRenewalRequest(&keyRequest /*key_request*/); + cdm_session->GenerateRenewalRequest(&key_request /*key_request*/); }, - [&]() { cdmSession->RenewKey(response /*key_response*/); }, + [&]() { cdm_session->RenewKey(response /*key_response*/); }, [&]() { - const KeyId keyId = std::to_string( - mFdp.ConsumeIntegralInRange(kMinId, kMaxId)); - cdmSession->IsKeyLoaded(keyId /*key_id*/); + const KeyId key_id = std::to_string( + fdp_.ConsumeIntegralInRange(kMinId, kMaxId)); + cdm_session->IsKeyLoaded(key_id /*key_id*/); }, - [&]() { cdmSession->GetDurationRemaining(); }, + [&]() { cdm_session->GetDurationRemaining(); }, [&]() { - cdmSession->NotifyResolution( - mFdp.ConsumeIntegral() /*width*/, - mFdp.ConsumeIntegral() /*height*/); + cdm_session->NotifyResolution( + fdp_.ConsumeIntegral() /*width*/, + fdp_.ConsumeIntegral() /*height*/); }, [&]() { - cdmSession->OnTimerEvent(mFdp.ConsumeBool() /*update_usage*/); + cdm_session->OnTimerEvent(fdp_.ConsumeBool() /*update_usage*/); }, [&]() { - const CdmKeySetId keySetId = - kKeyId + mFdp.ConsumeRandomLengthString(kMaxByte); - cdmSession->OnKeyReleaseEvent(keySetId /*key_set_id*/); + const CdmKeySetId key_set_id = + kKeyId + fdp_.ConsumeRandomLengthString(kMaxByte); + cdm_session->OnKeyReleaseEvent(key_set_id /*key_set_id*/); }, [&]() { - std::string appId = + std::string app_id = kSessionId + std::to_string( - mFdp.ConsumeIntegralInRange(kMinId, kMaxId)); - cdmSession->GetApplicationId(&appId /*app_id*/); + fdp_.ConsumeIntegralInRange(kMinId, kMaxId)); + cdm_session->GetApplicationId(&app_id /*app_id*/); }, - [&]() { cdmSession->UpdateUsageEntryInformation(); }, - [&]() { cdmSession->GenerateSessionId(); }, + [&]() { cdm_session->UpdateUsageEntryInformation(); }, + [&]() { cdm_session->GenerateSessionId(); }, [&]() { - const std::string inBuffer = - mFdp.ConsumeRandomLengthString(kMaxByte); - const std::string keyId = std::to_string( - mFdp.ConsumeIntegralInRange(kMinId, kMaxId)); - const std::string iv = mFdp.ConsumeRandomLengthString(kMaxByte); + const std::string in_buffer = + fdp_.ConsumeRandomLengthString(kMaxByte); + const std::string key_id = std::to_string( + fdp_.ConsumeIntegralInRange(kMinId, kMaxId)); + const std::string iv = fdp_.ConsumeRandomLengthString(kMaxByte); CdmEncryptionAlgorithm algorithm = - mFdp.ConsumeBool() + fdp_.ConsumeBool() ? CdmEncryptionAlgorithm::kEncryptionAlgorithmAesCbc128 : CdmEncryptionAlgorithm::kEncryptionAlgorithmUnknown; - std::string outBuffer = mFdp.ConsumeRandomLengthString(kMaxByte); - cdmSession->GenericEncrypt(inBuffer /*in_buffer*/, keyId /*key_id*/, - iv, algorithm, &outBuffer /*out_buffer*/); + std::string out_buffer = fdp_.ConsumeRandomLengthString(kMaxByte); + cdm_session->GenericEncrypt(in_buffer /*in_buffer*/, key_id /*key_id*/, + iv, algorithm, &out_buffer /*out_buffer*/); }, [&]() { - const std::string inBuffer = - mFdp.ConsumeRandomLengthString(kMaxByte); - const std::string keyId = std::to_string( - mFdp.ConsumeIntegralInRange(kMinId, kMaxId)); - const std::string iv = mFdp.ConsumeRandomLengthString(kMaxByte); + const std::string in_buffer = + fdp_.ConsumeRandomLengthString(kMaxByte); + const std::string key_id = std::to_string( + fdp_.ConsumeIntegralInRange(kMinId, kMaxId)); + const std::string iv = fdp_.ConsumeRandomLengthString(kMaxByte); CdmEncryptionAlgorithm algorithm = - mFdp.ConsumeBool() + fdp_.ConsumeBool() ? CdmEncryptionAlgorithm::kEncryptionAlgorithmAesCbc128 : CdmEncryptionAlgorithm::kEncryptionAlgorithmUnknown; - std::string outBuffer = mFdp.ConsumeRandomLengthString(kMaxByte); - cdmSession->GenericDecrypt(inBuffer /*in_buffer*/, keyId /*key_id*/, - iv, algorithm, &outBuffer /*out_buffer*/); + std::string out_buffer = fdp_.ConsumeRandomLengthString(kMaxByte); + cdm_session->GenericDecrypt(in_buffer /*in_buffer*/, key_id /*key_id*/, + iv, algorithm, &out_buffer /*out_buffer*/); }, [&]() { - const std::string message = mFdp.ConsumeRandomLengthString(kMaxByte); - const std::string keyId = std::to_string( - mFdp.ConsumeIntegralInRange(kMinId, kMaxId)); + const std::string message = fdp_.ConsumeRandomLengthString(kMaxByte); + const std::string key_id = std::to_string( + fdp_.ConsumeIntegralInRange(kMinId, kMaxId)); CdmSigningAlgorithm algorithm = - mFdp.ConsumeBool() + fdp_.ConsumeBool() ? CdmSigningAlgorithm::kSigningAlgorithmHmacSha256 : CdmSigningAlgorithm::kSigningAlgorithmUnknown; - std::string signature = mFdp.ConsumeRandomLengthString(kMaxByte); - cdmSession->GenericSign(message, keyId /*key_id*/, algorithm, + std::string signature = fdp_.ConsumeRandomLengthString(kMaxByte); + cdm_session->GenericSign(message, key_id /*key_id*/, algorithm, &signature); }, [&]() { - const std::string message = mFdp.ConsumeRandomLengthString(kMaxByte); - const std::string keyId = std::to_string( - mFdp.ConsumeIntegralInRange(kMinId, kMaxId)); + const std::string message = fdp_.ConsumeRandomLengthString(kMaxByte); + const std::string key_id = std::to_string( + fdp_.ConsumeIntegralInRange(kMinId, kMaxId)); CdmSigningAlgorithm algorithm = - mFdp.ConsumeBool() + fdp_.ConsumeBool() ? CdmSigningAlgorithm::kSigningAlgorithmHmacSha256 : CdmSigningAlgorithm::kSigningAlgorithmUnknown; const std::string signature = - mFdp.ConsumeRandomLengthString(kMaxByte); - cdmSession->GenericVerify(message, keyId /*key_id*/, algorithm, + fdp_.ConsumeRandomLengthString(kMaxByte); + cdm_session->GenericVerify(message, key_id /*key_id*/, algorithm, signature); }, [&]() { - uint32_t frameNumber = mFdp.ConsumeIntegral(); - const std::string hash = mFdp.ConsumeRandomLengthString(kMaxByte); - cdmSession->SetDecryptHash(frameNumber /*frame_number*/, hash); + uint32_t frame_number = fdp_.ConsumeIntegral(); + const std::string hash = fdp_.ConsumeRandomLengthString(kMaxByte); + cdm_session->SetDecryptHash(frame_number /*frame_number*/, hash); }, [&]() { - std::string hashErrorString = - mFdp.ConsumeRandomLengthString(kMaxByte); - cdmSession->GetDecryptHashError( - &hashErrorString /*hash_error_string*/); + std::string hash_error_string = + fdp_.ConsumeRandomLengthString(kMaxByte); + cdm_session->GetDecryptHashError( + &hash_error_string /*hash_error_string*/); }, - [&]() { cdmSession->ReleaseKey(response /*key_response*/); }, + [&]() { cdm_session->ReleaseKey(response /*key_response*/); }, [&]() { - cdmSession->GenerateReleaseRequest(&keyRequest /*key_request*/); + cdm_session->GenerateReleaseRequest(&key_request /*key_request*/); }}); invokeCdmSessionAPI(); } - UsageEntryIndex entryIndex = mFdp.ConsumeIntegral(); - cdmSession->DeleteUsageEntry(entryIndex /*usage_entry_index*/); - cdmSession->DeleteLicenseFile(); - cdmSession->RemoveKeys(); - cdmSession->RemoveLicense(); + UsageEntryIndex entry_index = fdp_.ConsumeIntegral(); + cdm_session->DeleteUsageEntry(entry_index /*usage_entry_index*/); + cdm_session->DeleteLicenseFile(); + cdm_session->RemoveKeys(); + cdm_session->RemoveLicense(); } -void CdmSessionFuzzer::invokeCdmSessionMapAPIs() { - FuzzFileSystem fileSystemMap(&mFdp); - CdmSessionMap cdmsessionMap; - std::shared_ptr CdmMetricsMap( +void CdmSessionFuzzer::InvokeCdmSessionMapAPIs() { + FuzzFileSystem file_system_map(&fdp_); + CdmSessionMap cdm_session_map; + std::shared_ptr cdm_metrics_map( new metrics::SessionMetrics); - CdmSession *session = new CdmSession(&fileSystemMap, CdmMetricsMap); - const CdmSessionId forcedSessionId = + CdmSession *session = new CdmSession(&file_system_map, cdm_metrics_map); + const CdmSessionId forced_session_id = kSessionId + - std::to_string(mFdp.ConsumeIntegralInRange(kMinId, kMaxId)); - cdmsessionMap.Add(forcedSessionId /*id*/, session /*session*/); - while (mFdp.remaining_bytes()) { + std::to_string(fdp_.ConsumeIntegralInRange(kMinId, kMaxId)); + cdm_session_map.Add(forced_session_id /*id*/, session /*session*/); + while (fdp_.remaining_bytes()) { auto invokeCdmSessionMapAPI = - mFdp.PickValueInArray>({ - [&]() { cdmsessionMap.Exists(forcedSessionId /*id*/); }, - [&]() { cdmsessionMap.Size(); }, + fdp_.PickValueInArray>({ + [&]() { cdm_session_map.Exists(forced_session_id /*id*/); }, + [&]() { cdm_session_map.Size(); }, [&]() { - std::shared_ptr cdmsessionShared; - cdmsessionMap.FindSession(forcedSessionId /*id*/, - &cdmsessionShared /*session*/); + std::shared_ptr cdm_session_shared; + cdm_session_map.FindSession(forced_session_id /*id*/, + &cdm_session_shared /*session*/); }, [&]() { CdmSessionList sessions; - cdmsessionMap.GetSessionList(sessions); + cdm_session_map.GetSessionList(sessions); }, }); invokeCdmSessionMapAPI(); - cdmsessionMap.CloseSession(forcedSessionId); + cdm_session_map.CloseSession(forced_session_id); } } -void CdmSessionFuzzer::process() { - if (mFdp.ConsumeBool()) { - FuzzFileSystem fileSystem(&mFdp); - FuzzEventListener fuzzeventListener; +void CdmSessionFuzzer::Process() { + if (fdp_.ConsumeBool()) { + FuzzFileSystem file_system(&fdp_); + FuzzEventListener fuzz_event_listener; std::shared_ptr metrics = std::make_shared(); - std::unique_ptr cdmSession = - std::make_unique(&fileSystem, metrics); - std::unique_ptr fuzzCdmClientPropertySet( - new FuzzCdmClientPropertySet(&mFdp)); - const CdmSessionId forcedSessionId = + std::unique_ptr cdm_session = + std::make_unique(&file_system, metrics); + std::unique_ptr fuzz_cdm_client_property_set( + new FuzzCdmClientPropertySet(&fdp_)); + const CdmSessionId forced_session_id = kSessionId + - std::to_string(mFdp.ConsumeIntegralInRange(kMinId, kMaxId)); - bool forcedLevel = mFdp.ConsumeBool(); + std::to_string(fdp_.ConsumeIntegralInRange(kMinId, kMaxId)); + bool forced_level = fdp_.ConsumeBool(); CdmResponseType result = - initCdmSession(cdmSession.get(), fuzzCdmClientPropertySet.get(), - forcedSessionId, &fuzzeventListener, forcedLevel); + InitCdmSession(cdm_session.get(), fuzz_cdm_client_property_set.get(), + forced_session_id, &fuzz_event_listener, forced_level); if (result == NO_ERROR) { - invokeCdmSessionAPIs(cdmSession.get()); + InvokeCdmSessionAPIs(cdm_session.get()); } } else { - invokeCdmSessionMapAPIs(); + InvokeCdmSessionMapAPIs(); } } extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - CdmSessionFuzzer cdmSessionFuzzer(data, size); - cdmSessionFuzzer.process(); + CdmSessionFuzzer cdm_session_fuzzer(data, size); + cdm_session_fuzzer.Process(); return 0; }