diff --git a/libwvdrmengine/cdm/test/cdm_extended_duration_test.cpp b/libwvdrmengine/cdm/test/cdm_extended_duration_test.cpp index 49f13633..55d2874e 100644 --- a/libwvdrmengine/cdm/test/cdm_extended_duration_test.cpp +++ b/libwvdrmengine/cdm/test/cdm_extended_duration_test.cpp @@ -984,68 +984,6 @@ TEST_F(WvCdmExtendedDurationTest, DecryptionCloseSessionConcurrencyTest) { decryptor_->CloseSession(session_id); } -// TODO(rfrias): Rewite this test when OEMCrypto v13 is the minimum version -// supported. The limitation of 50 usage entries are no longer present -// when using usage table header+entries. -TEST_F(WvCdmExtendedDurationTest, DISABLED_UsageOverflowTest) { - Provision(); - TestWvCdmClientPropertySet client_property_set; - TestWvCdmClientPropertySet* property_set = nullptr; - - CdmSecurityLevel security_level = GetDefaultSecurityLevel(); - FileSystem file_system; - DeviceFiles handle(&file_system); - EXPECT_TRUE(handle.Init(security_level)); - std::vector provider_session_tokens; - EXPECT_TRUE(handle.DeleteAllUsageInfoForApp( - DeviceFiles::GetUsageInfoFileName(""), &provider_session_tokens)); - - for (size_t i = 0; i < kMaxUsageTableSize + 100; ++i) { - decryptor_->OpenSession(config_.key_system(), property_set, - kDefaultCdmIdentifier, nullptr, &session_id_); - std::string key_id = wvutil::a2bs_hex( - "000000427073736800000000" // blob size and pssh - "EDEF8BA979D64ACEA3C827DCD51D21ED00000022" // Widevine system id - "08011a0d7769646576696e655f74657374220f73" // pssh data - "747265616d696e675f636c697035"); - - GenerateKeyRequest(key_id, kLicenseTypeStreaming); - VerifyKeyRequestResponse(config_.license_server(), config_.client_auth(), - false); - decryptor_->CloseSession(session_id_); - } - - CdmUsageInfo usage_info; - CdmUsageInfoReleaseMessage release_msg; - CdmResponseType status = - decryptor_->GetUsageInfo("", kDefaultCdmIdentifier, &usage_info); - EXPECT_EQ(usage_info.empty() ? NO_ERROR : KEY_MESSAGE, status); - int error_count = 0; - while (usage_info.size() > 0) { - for (size_t i = 0; i < usage_info.size(); ++i) { - release_msg = GetUsageInfoResponse(config_.license_server(), - config_.client_auth(), usage_info[i]); - EXPECT_EQ(NO_ERROR, - decryptor_->ReleaseUsageInfo(release_msg, kDefaultCdmIdentifier)) - << i << "/" << usage_info.size() << " (err " << (error_count++) << ")" - << release_msg; - } - ASSERT_LE(error_count, 100); // Give up after 100 failures. - status = decryptor_->GetUsageInfo("", kDefaultCdmIdentifier, &usage_info); - switch (status) { - case KEY_MESSAGE: - EXPECT_FALSE(usage_info.empty()); - break; - case NO_ERROR: - EXPECT_TRUE(usage_info.empty()); - break; - default: - FAIL() << "GetUsageInfo failed with error " << static_cast(status); - break; - } - } -} - // This test verifies that sessions allocated internally during key release // message generation are deallocated after their time to live period expires // by timer events (if other sessions are open). @@ -1342,215 +1280,6 @@ TEST_P(WvCdmStreamingNoPstTest, UsageTest) { INSTANTIATE_TEST_CASE_P(Cdm, WvCdmStreamingNoPstTest, ::testing::Values(0, 1, 2)); -class WvCdmStreamingPstTest : public WvCdmExtendedDurationTest, - public ::testing::WithParamInterface {}; - -TEST_P(WvCdmStreamingPstTest, UsageTest) { - Unprovision(); - Provision(); - - decryptor_->OpenSession(config_.key_system(), nullptr, kDefaultCdmIdentifier, - nullptr, &session_id_); - GenerateKeyRequest(kStreamingClip8PstInitData, kLicenseTypeStreaming); - VerifyKeyRequestResponse(config_.license_server(), config_.client_auth(), - false); - - ValidateResponse(video_widevine::STREAMING, true); - - int64_t initial_license_duration_remaining = 0; - int64_t initial_playback_duration_remaining = 0; - QueryKeyStatus(true, false, &initial_license_duration_remaining, - &initial_playback_duration_remaining); - - sleep(kMinute); - int64_t expected_seconds_since_license_received = kMinute; - int64_t expected_seconds_since_initial_playback = 0; - int64_t expected_seconds_since_last_playback = 0; - - for (size_t i = 0; i < GetParam(); ++i) { - // Decrypt data - SubSampleInfo* data = &kEncryptedStreamingClip8SubSample; - for (size_t i = 0; i < data->num_of_subsamples; i++) { - std::vector decrypt_buffer((data + i)->encrypt_data.size()); - CdmDecryptionParameters decryption_parameters( - &(data + i)->key_id, &(data + i)->encrypt_data.front(), - (data + i)->encrypt_data.size(), &(data + i)->iv, - (data + i)->block_offset, &decrypt_buffer[0]); - decryption_parameters.is_encrypted = (data + i)->is_encrypted; - decryption_parameters.is_secure = (data + i)->is_secure; - decryption_parameters.subsample_flags = (data + i)->subsample_flags; - EXPECT_EQ(NO_ERROR, - decryptor_->Decrypt(session_id_, (data + i)->validate_key_id, - decryption_parameters)); - - EXPECT_EQ((data + i)->decrypt_data, decrypt_buffer); - } - - sleep(kMinute); - expected_seconds_since_license_received += kMinute; - expected_seconds_since_initial_playback += kMinute; - expected_seconds_since_last_playback = kMinute; - } - - // Query and validate usage information - int64_t license_duration_remaining = 0; - int64_t playback_duration_remaining = 0; - QueryKeyStatus(true, false, &license_duration_remaining, - &playback_duration_remaining); - - if (initial_license_duration_remaining == kUnlimitedDurationValue) { - EXPECT_EQ(license_duration_remaining, kUnlimitedDurationValue); - } else { - EXPECT_NEAR(initial_license_duration_remaining - license_duration_remaining, - expected_seconds_since_license_received, kClockTolerance) - << "initial_license_duration_remaining = " - << initial_license_duration_remaining - << ", license_duration_remaining = " << license_duration_remaining; - } - - if (initial_playback_duration_remaining == kUnlimitedDurationValue) { - EXPECT_EQ(playback_duration_remaining, kUnlimitedDurationValue); - } else { - EXPECT_NEAR(initial_playback_duration_remaining - playback_duration_remaining, - expected_seconds_since_initial_playback, kClockTolerance) - << "initial_playback_duration_remaining = " - << initial_playback_duration_remaining - << ", playback_duration_remaining = " << playback_duration_remaining; - } - - decryptor_->CloseSession(session_id_); -} - -INSTANTIATE_TEST_CASE_P(Cdm, WvCdmStreamingPstTest, ::testing::Values(0, 1, 2)); - -class WvCdmStreamingUsageReportTest - : public WvCdmExtendedDurationTest, - public ::testing::WithParamInterface {}; - -TEST_P(WvCdmStreamingUsageReportTest, UsageTest) { - Unprovision(); - Provision(); - - decryptor_->OpenSession(config_.key_system(), nullptr, kDefaultCdmIdentifier, - nullptr, &session_id_); - GenerateKeyRequest(kStreamingClip8PstInitData, kLicenseTypeStreaming); - VerifyKeyRequestResponse(config_.license_server(), config_.client_auth(), - false); - - ValidateResponse(video_widevine::STREAMING, true); - - int64_t initial_license_duration_remaining = 0; - int64_t initial_playback_duration_remaining = 0; - QueryKeyStatus(true, false, &initial_license_duration_remaining, - &initial_playback_duration_remaining); - - sleep(kMinute); - int64_t expected_seconds_since_license_received = kMinute; - int64_t expected_seconds_since_initial_playback = 0; - int64_t expected_seconds_since_last_playback = 0; - - for (size_t i = 0; i < GetParam(); ++i) { - // Decrypt data - SubSampleInfo* data = &kEncryptedStreamingClip8SubSample; - for (size_t i = 0; i < data->num_of_subsamples; i++) { - std::vector decrypt_buffer((data + i)->encrypt_data.size()); - CdmDecryptionParameters decryption_parameters( - &(data + i)->key_id, &(data + i)->encrypt_data.front(), - (data + i)->encrypt_data.size(), &(data + i)->iv, - (data + i)->block_offset, &decrypt_buffer[0]); - decryption_parameters.is_encrypted = (data + i)->is_encrypted; - decryption_parameters.is_secure = (data + i)->is_secure; - decryption_parameters.subsample_flags = (data + i)->subsample_flags; - EXPECT_EQ(NO_ERROR, - decryptor_->Decrypt(session_id_, (data + i)->validate_key_id, - decryption_parameters)); - - EXPECT_EQ((data + i)->decrypt_data, decrypt_buffer); - } - - sleep(kMinute); - expected_seconds_since_license_received += kMinute; - expected_seconds_since_initial_playback += kMinute; - expected_seconds_since_last_playback = kMinute; - } - - // Query and validate usage information - int64_t license_duration_remaining = 0; - int64_t playback_duration_remaining = 0; - QueryKeyStatus(true, false, &license_duration_remaining, - &playback_duration_remaining); - - // For unlimited "rental durations", the "license duration" will - // effectively be unlimited. Remaining license duration in this - // case is represented by |kUnlimitedDurationValue| and will not - // change over time. - if (initial_license_duration_remaining == kUnlimitedDurationValue) { - EXPECT_EQ(license_duration_remaining, kUnlimitedDurationValue); - } else { - EXPECT_NEAR(initial_license_duration_remaining - license_duration_remaining, - expected_seconds_since_license_received, kClockTolerance) - << "initial_license_duration_remaining = " - << initial_license_duration_remaining - << ", license_duration_remaining = " << license_duration_remaining; - } - - if (initial_playback_duration_remaining == kUnlimitedDurationValue) { - EXPECT_EQ(playback_duration_remaining, kUnlimitedDurationValue); - } else { - EXPECT_NEAR(initial_playback_duration_remaining - playback_duration_remaining, - expected_seconds_since_initial_playback, kClockTolerance) - << "initial_playback_duration_remaining = " - << initial_playback_duration_remaining - << ", playback_duration_remaining = " << playback_duration_remaining; - } - - decryptor_->CloseSession(session_id_); - - // Create usage report and validate - CdmUsageInfo usage_info; - CdmUsageInfoReleaseMessage release_msg; - CdmResponseType status = - decryptor_->GetUsageInfo("", kDefaultCdmIdentifier, &usage_info); - EXPECT_EQ(usage_info.empty() ? NO_ERROR : KEY_MESSAGE, status); - int error_count = 0; - while (usage_info.size() > 0) { - for (size_t i = 0; i < usage_info.size(); ++i) { - ValidateReleaseRequest(usage_info[i], - expected_seconds_since_initial_playback != 0, - expected_seconds_since_license_received, - expected_seconds_since_initial_playback, - expected_seconds_since_last_playback); - release_msg = GetUsageInfoResponse(config_.license_server(), - config_.client_auth(), usage_info[i]); - EXPECT_EQ(NO_ERROR, - decryptor_->ReleaseUsageInfo(release_msg, kDefaultCdmIdentifier)) - << i << "/" << usage_info.size() << " (err " << (error_count++) << ")" - << release_msg; - } - ASSERT_LE(error_count, 100); // Give up after 100 failures. - status = decryptor_->GetUsageInfo("", kDefaultCdmIdentifier, &usage_info); - switch (status) { - case KEY_MESSAGE: - EXPECT_FALSE(usage_info.empty()); - break; - case NO_ERROR: - EXPECT_TRUE(usage_info.empty()); - break; - default: - FAIL() << "GetUsageInfo failed with error " << static_cast(status); - break; - } - } - - // Validate that update usage table entry is exercised. - drm_metrics::WvCdmMetrics metrics; - ASSERT_EQ(NO_ERROR, decryptor_->GetMetrics(kDefaultCdmIdentifier, &metrics)); - ValidateHasUpdateUsageEntry(metrics); -} - -INSTANTIATE_TEST_CASE_P(Cdm, WvCdmStreamingUsageReportTest, - ::testing::Values(0, 1, 2)); - class WvCdmOfflineUsageReportTest : public WvCdmExtendedDurationTest, public ::testing::WithParamInterface {}; diff --git a/libwvdrmengine/cdm/test/request_license_test.cpp b/libwvdrmengine/cdm/test/request_license_test.cpp index 9288984e..d354056b 100644 --- a/libwvdrmengine/cdm/test/request_license_test.cpp +++ b/libwvdrmengine/cdm/test/request_license_test.cpp @@ -109,7 +109,7 @@ struct SubSampleInfo { uint8_t subsample_flags; }; -SubSampleInfo clear_sub_sample = { +const SubSampleInfo clear_sub_sample = { true, 1, true, @@ -138,7 +138,7 @@ SubSampleInfo clear_sub_sample = { 0, OEMCrypto_FirstSubsample | OEMCrypto_LastSubsample}; -SubSampleInfo clear_sub_samples[2] = { +const SubSampleInfo clear_sub_samples[2] = { // block 0, key SD, encrypted, 128b {true, 1, true, false, false, wvutil::a2bs_hex("371EA35E1A985D75D198A7F41020DC23"), @@ -170,7 +170,7 @@ SubSampleInfo clear_sub_samples[2] = { wvutil::a2b_hex("f6f4b1e600a5b67813ed2bded913ba9f"), 0, OEMCrypto_LastSubsample}}; -SubSampleInfo clear_sub_sample_no_key = { +const SubSampleInfo clear_sub_sample_no_key = { false, 1, false, @@ -199,7 +199,7 @@ SubSampleInfo clear_sub_sample_no_key = { 0, OEMCrypto_FirstSubsample | OEMCrypto_LastSubsample}; -SubSampleInfo single_encrypted_sub_sample = { +const SubSampleInfo single_encrypted_sub_sample = { // key SD, encrypted, 256b true, 1, @@ -229,7 +229,7 @@ SubSampleInfo single_encrypted_sub_sample = { 0, OEMCrypto_FirstSubsample | OEMCrypto_LastSubsample}; -SubSampleInfo single_encrypted_offline_sub_sample = { +const SubSampleInfo single_encrypted_offline_sub_sample = { // key SD, encrypted, 256b true, 1, @@ -259,7 +259,7 @@ SubSampleInfo single_encrypted_offline_sub_sample = { 0, OEMCrypto_FirstSubsample | OEMCrypto_LastSubsample}; -SubSampleInfo switch_key_encrypted_sub_samples[2] = { +const SubSampleInfo switch_key_encrypted_sub_samples[2] = { // block 0, key SD, encrypted, 256b {true, 2, true, true, false, wvutil::a2bs_hex("371EA35E1A985D75D198A7F41020DC23"), @@ -307,7 +307,7 @@ SubSampleInfo switch_key_encrypted_sub_samples[2] = { wvutil::a2b_hex("f56ab022666de858920e532f19bb32f6"), 0, OEMCrypto_FirstSubsample | OEMCrypto_LastSubsample}}; -SubSampleInfo partial_encrypted_sub_samples[3] = { +const SubSampleInfo partial_encrypted_sub_samples[3] = { // block 1, key SD, encrypted, 1-125b, offset 0 {true, 3, true, true, false, wvutil::a2bs_hex("371EA35E1A985D75D198A7F41020DC23"), @@ -349,7 +349,7 @@ SubSampleInfo partial_encrypted_sub_samples[3] = { wvutil::a2b_hex("6ba18dd40f49da7f64c368e4db43fc93"), 11, OEMCrypto_LastSubsample}}; -SubSampleInfo single_encrypted_sub_sample_short_expiry = { +const SubSampleInfo single_encrypted_sub_sample_short_expiry = { // key 1, encrypted, 256b true, 1, @@ -379,7 +379,7 @@ SubSampleInfo single_encrypted_sub_sample_short_expiry = { 0, OEMCrypto_FirstSubsample | OEMCrypto_LastSubsample}; -SubSampleInfo usage_info_sub_samples_icp[] = { +const SubSampleInfo usage_info_sub_samples_icp[] = { {true, 1, true, true, false, wvutil::a2bs_hex("E82DDD1D07CBB31CDD31EBAAE0894609"), wvutil::a2b_hex( @@ -491,7 +491,7 @@ SubSampleInfo usage_info_sub_samples_icp[] = { wvutil::a2b_hex("964c2dfda920357c668308d52d33c652"), 0, OEMCrypto_FirstSubsample | OEMCrypto_LastSubsample}}; -SubSampleInfo kEntitlementWithKeyRotationSubSampleSinglePssh[] = { +const SubSampleInfo kEntitlementWithKeyRotationSubSampleSinglePssh[] = { {true, 1, true, true, false, wvutil::a2bs_hex("c8326486bb5d5c4a958f00b1111afc81"), wvutil::a2b_hex( @@ -537,7 +537,7 @@ SubSampleInfo kEntitlementWithKeyRotationSubSampleSinglePssh[] = { wvutil::a2b_hex("f6f4b1e600a5b67813ed2bded913ba9f"), 0, OEMCrypto_FirstSubsample | OEMCrypto_LastSubsample}}; -SubSampleInfo kEntitlementWithKeyRotationSubSampleDualPssh[] = { +const SubSampleInfo kEntitlementWithKeyRotationSubSampleDualPssh[] = { {true, 1, true, true, false, wvutil::a2bs_hex("1D9B8E13B59951169348FF8D5B9394C0"), wvutil::a2b_hex( @@ -588,12 +588,12 @@ const uint32_t kSingleEncryptedSubSampleIcpLicenseDurationExpiration = 5; const uint32_t kSingleEncryptedSubSampleIcpLicenseExpirationWindow = 2; struct SessionSharingSubSampleInfo { - SubSampleInfo* sub_sample; + const SubSampleInfo* sub_sample; bool session_sharing_enabled; wvcdm::CdmIdentifier cdm_identifier; }; -SessionSharingSubSampleInfo session_sharing_sub_samples[] = { +const SessionSharingSubSampleInfo session_sharing_sub_samples[] = { {&clear_sub_sample, false, wvcdm::kDefaultCdmIdentifier}, {&clear_sub_sample, true, wvcdm::kDefaultCdmIdentifier}, {&clear_sub_sample_no_key, false, wvcdm::kDefaultCdmIdentifier}, @@ -604,65 +604,38 @@ SessionSharingSubSampleInfo session_sharing_sub_samples[] = { // identifier. {&single_encrypted_sub_sample, true, kExampleIdentifier}}; -struct UsageInfoSubSampleInfo { - SubSampleInfo* sub_sample; - uint32_t usage_info; - wvcdm::RequestedSecurityLevel security_level; - std::string app_id; -}; - -void PrintTo(UsageInfoSubSampleInfo* param, std::ostream* os) { - if (param) { - *os << "info=" << param->usage_info << ", " - << "level=" << (param->security_level == wvcdm::kLevel3 ? "L3" : "L1") - << " app_id=" << param->app_id; - } else { - *os << ""; - } -} - -UsageInfoSubSampleInfo usage_info_sub_sample_info[] = { - {&usage_info_sub_samples_icp[0], 1, wvcdm::kLevelDefault, ""}, - {&usage_info_sub_samples_icp[0], 3, wvcdm::kLevelDefault, ""}, - {&usage_info_sub_samples_icp[0], 5, wvcdm::kLevelDefault, ""}, - {&usage_info_sub_samples_icp[0], 3, wvcdm::kLevelDefault, "other app id"}, - {&usage_info_sub_samples_icp[0], 1, wvcdm::kLevel3, ""}, - {&usage_info_sub_samples_icp[0], 3, wvcdm::kLevel3, ""}, - {&usage_info_sub_samples_icp[0], 5, wvcdm::kLevel3, ""}, - {&usage_info_sub_samples_icp[0], 3, wvcdm::kLevel3, "other app id"}}; - struct UsageLicenseAndSubSampleInfo { std::string pssh; - SubSampleInfo* sub_sample; + const SubSampleInfo* sub_sample; std::string provider_session_token; }; -std::string kPsshStreamingClip3 = wvutil::a2bs_hex( +const std::string kPsshStreamingClip3 = wvutil::a2bs_hex( "000000427073736800000000" // blob size and pssh "EDEF8BA979D64ACEA3C827DCD51D21ED00000022" // Widevine system id "08011a0d7769646576696e655f74657374220f73" // pssh data "747265616d696e675f636c697033"); -std::string kPsshStreamingClip4 = wvutil::a2bs_hex( +const std::string kPsshStreamingClip4 = wvutil::a2bs_hex( "000000427073736800000000" // blob size and pssh "EDEF8BA979D64ACEA3C827DCD51D21ED00000022" // Widevine system id "08011a0d7769646576696e655f74657374220f73" // pssh data "747265616d696e675f636c697034"); -std::string kPsshStreamingClip5 = wvutil::a2bs_hex( +const std::string kPsshStreamingClip5 = wvutil::a2bs_hex( "000000427073736800000000" // blob size and pssh "EDEF8BA979D64ACEA3C827DCD51D21ED00000022" // Widevine system id "08011a0d7769646576696e655f74657374220f73" // pssh data "747265616d696e675f636c697035"); -std::string kPsshStreamingClip7 = wvutil::a2bs_hex( +const std::string kPsshStreamingClip7 = wvutil::a2bs_hex( "000000427073736800000000" // blob size and pssh "EDEF8BA979D64ACEA3C827DCD51D21ED00000022" // Widevine system id "08011a0d7769646576696e655f74657374220f73" // pssh data "747265616d696e675f636c697037"); -std::string kPsshStreamingClip20 = wvutil::a2bs_hex( +const std::string kPsshStreamingClip20 = wvutil::a2bs_hex( "000000437073736800000000" // blob size and pssh "EDEF8BA979D64ACEA3C827DCD51D21ED00000023" // Widevine system id "08011a0d7769646576696e655f746573" // pssh data "74221073747265616d696e675f636c69703230"); -std::string kPsshStreamingClip21 = wvutil::a2bs_hex( +const std::string kPsshStreamingClip21 = wvutil::a2bs_hex( "000000437073736800000000" // blob size and pssh "EDEF8BA979D64ACEA3C827DCD51D21ED00000023" // Widevine system id "08011a0d7769646576696e655f746573" // pssh data @@ -890,8 +863,8 @@ RenewWithClientIdTestConfiguration usage_client_id_test_configuration[] = { struct EntitlementTestConfiguration { std::string entitlement_pssh; std::string key_rotation_pssh; - SubSampleInfo* sub_sample_with_initial_keys; - SubSampleInfo* sub_sample_with_rotated_keys; + const SubSampleInfo* sub_sample_with_initial_keys; + const SubSampleInfo* sub_sample_with_rotated_keys; }; EntitlementTestConfiguration kEntitlementTestConfiguration[] = { @@ -1740,7 +1713,7 @@ class DecryptCallbackTester { public: DecryptCallbackTester( const android::sp& decryptor, - SubSampleInfo* sub_sample_info) + const SubSampleInfo* sub_sample_info) : decryptor_(decryptor), sub_sample_info_(sub_sample_info) {} void Decrypt(const CdmSessionId& session_id, @@ -1764,7 +1737,7 @@ class DecryptCallbackTester { private: android::sp decryptor_; - SubSampleInfo* sub_sample_info_; + const SubSampleInfo* sub_sample_info_; }; class TestWvCdmHlsEventListener : public WvCdmEventListener { @@ -3529,7 +3502,7 @@ TEST_F(WvCdmRequestLicenseTest, OfflineLicenseRenewalAndRelease) { EXPECT_FALSE(key_set_id_.empty()); // Verify that we can decrypt a subsample - SubSampleInfo* data = &single_encrypted_offline_sub_sample; + const SubSampleInfo* data = &single_encrypted_offline_sub_sample; std::vector decrypt_buffer(data->encrypt_data.size()); CdmDecryptionParameters decryption_parameters( &data->key_id, &data->encrypt_data.front(), data->encrypt_data.size(), @@ -3627,7 +3600,7 @@ TEST_F(WvCdmRequestLicenseTest, RemoveKeys) { GenerateKeyRequest(binary_key_id(), kLicenseTypeStreaming); VerifyKeyRequestResponse(config_.license_server(), config_.client_auth()); - SubSampleInfo* data = &single_encrypted_sub_sample; + const SubSampleInfo* data = &single_encrypted_sub_sample; std::vector decrypt_buffer(data->encrypt_data.size()); CdmDecryptionParameters decryption_parameters( &data->key_id, &data->encrypt_data.front(), data->encrypt_data.size(), @@ -3923,1143 +3896,6 @@ INSTANTIATE_TEST_CASE_P( ::testing::Range(&offline_release_client_id_test_configuration[0], &offline_release_client_id_test_configuration[4])); -class WvCdmUsageTest : public WvCdmRequestLicenseTest, - public ::testing::WithParamInterface< - RenewWithClientIdTestConfiguration*> {}; - -TEST_P(WvCdmUsageTest, WithClientId) { - Unprovision(); - Provision(); - - CdmSecurityLevel security_level = GetDefaultSecurityLevel(); - std::string app_id = ""; - FileSystem file_system; - DeviceFiles handle(&file_system); - EXPECT_TRUE(handle.Init(security_level)); - std::vector psts; - EXPECT_TRUE(handle.DeleteAllUsageInfoForApp( - DeviceFiles::GetUsageInfoFileName(app_id), &psts)); - - RenewWithClientIdTestConfiguration* config = GetParam(); - std::string key_id; - - if (config->always_include_client_id) { - key_id = wvutil::a2bs_hex( // streaming_clip20 - "000000437073736800000000" // blob size and pssh - "EDEF8BA979D64ACEA3C827DCD51D21ED00000023" // Widevine system id - "08011a0d7769646576696e655f746573" // pssh data - "74221073747265616d696e675f636c69703230"); - } else { - key_id = wvutil::a2bs_hex( // streaming_clip3 - "000000427073736800000000" // blob size and pssh - "EDEF8BA979D64ACEA3C827DCD51D21ED00000022" // Widevine system id - "08011a0d7769646576696e655f746573" // pssh data - "74220f73747265616d696e675f636c697033"); - } - wvcdm::CdmAppParameterMap app_parameters; - TestWvCdmClientPropertySet property_set; - - SubSampleInfo* data = &usage_info_sub_samples_icp[0]; - decryptor_->OpenSession(config_.key_system(), &property_set, - kDefaultCdmIdentifier, nullptr, &session_id_); - - GenerateKeyRequest(key_id, app_parameters, kLicenseTypeStreaming, - &property_set); - - std::string key_response; - VerifyKeyRequestResponse(config_.license_server(), config_.client_auth(), - true, &key_response); - - // Validate signed license - SignedMessage signed_message; - EXPECT_TRUE(signed_message.ParseFromString(key_response)) - << config->test_description; - EXPECT_EQ(SignedMessage::LICENSE, signed_message.type()) - << config->test_description; - EXPECT_TRUE(signed_message.has_signature()) << config->test_description; - EXPECT_TRUE(!signed_message.msg().empty()) << config->test_description; - - // Verify license request - video_widevine::License license; - EXPECT_TRUE(license.ParseFromString(signed_message.msg())) - << config->test_description; - - // Verify always_include_client_id - EXPECT_EQ(config->always_include_client_id, - license.policy().has_always_include_client_id()); - - EXPECT_FALSE(license.id().provider_session_token().empty()); - - std::vector decrypt_buffer(data->encrypt_data.size()); - CdmDecryptionParameters decryption_parameters( - &data->key_id, &data->encrypt_data.front(), data->encrypt_data.size(), - &data->iv, data->block_offset, &decrypt_buffer[0]); - decryption_parameters.is_encrypted = data->is_encrypted; - decryption_parameters.is_secure = data->is_secure; - decryption_parameters.subsample_flags = data->subsample_flags; - EXPECT_EQ(NO_ERROR, decryptor_->Decrypt(session_id_, data->validate_key_id, - decryption_parameters)); - - EXPECT_TRUE(std::equal(data->decrypt_data.begin(), data->decrypt_data.end(), - decrypt_buffer.begin())); - decryptor_->CloseSession(session_id_); - - CdmUsageInfo usage_info; - CdmUsageInfoReleaseMessage release_msg; - CdmResponseType status = - decryptor_->GetUsageInfo(app_id, kDefaultCdmIdentifier, &usage_info); - - EXPECT_EQ(KEY_MESSAGE, status); - ASSERT_FALSE(usage_info.empty()); - - // Validate signed renewal request - EXPECT_TRUE(signed_message.ParseFromString(usage_info[0])) - << config->test_description; - EXPECT_EQ(SignedMessage::LICENSE_REQUEST, signed_message.type()) - << config->test_description; - EXPECT_TRUE(signed_message.has_signature()) << config->test_description; - EXPECT_TRUE(!signed_message.msg().empty()) << config->test_description; - - // Verify license request - video_widevine::LicenseRequest license_renewal; - EXPECT_TRUE(license_renewal.ParseFromString(signed_message.msg())) - << config->test_description; - - // Verify ClientId - EXPECT_EQ(config->always_include_client_id && !config->enable_privacy_mode, - license_renewal.has_client_id()) - << config->test_description; - - if (config->enable_privacy_mode) { - EXPECT_EQ(config->always_include_client_id, - license_renewal.has_encrypted_client_id()) - << config->test_description; - EXPECT_NE( - 0u, license_renewal.encrypted_client_id().encrypted_client_id().size()); - } - - release_msg = GetUsageInfoResponse(config_.license_server(), - config_.client_auth(), usage_info[0]); - EXPECT_EQ(NO_ERROR, - decryptor_->ReleaseUsageInfo(release_msg, kDefaultCdmIdentifier)); -} - -INSTANTIATE_TEST_CASE_P( - Cdm, WvCdmUsageTest, - ::testing::Range(&usage_client_id_test_configuration[0], - &usage_client_id_test_configuration[2])); - -TEST_F(WvCdmRequestLicenseTest, UsageInfoRetryTest) { - Unprovision(); - Provision(); - - CdmSecurityLevel security_level = GetDefaultSecurityLevel(); - std::string app_id = ""; - FileSystem file_system; - DeviceFiles handle(&file_system); - EXPECT_TRUE(handle.Init(security_level)); - std::vector psts; - EXPECT_TRUE(handle.DeleteAllUsageInfoForApp( - DeviceFiles::GetUsageInfoFileName(app_id), &psts)); - - SubSampleInfo* data = &usage_info_sub_samples_icp[0]; - decryptor_->OpenSession(config_.key_system(), nullptr, kDefaultCdmIdentifier, - nullptr, &session_id_); - std::string key_id = wvutil::a2bs_hex( - "000000427073736800000000" // blob size and pssh - "EDEF8BA979D64ACEA3C827DCD51D21ED00000022" // Widevine system id - "08011a0d7769646576696e655f74657374220f73" // pssh data - "747265616d696e675f636c697033"); - - GenerateKeyRequest(key_id, kLicenseTypeStreaming, nullptr); - VerifyUsageKeyRequestResponse(config_.license_server(), - config_.client_auth()); - - std::vector decrypt_buffer(data->encrypt_data.size()); - CdmDecryptionParameters decryption_parameters( - &data->key_id, &data->encrypt_data.front(), data->encrypt_data.size(), - &data->iv, data->block_offset, &decrypt_buffer[0]); - decryption_parameters.is_encrypted = data->is_encrypted; - decryption_parameters.is_secure = data->is_secure; - decryption_parameters.subsample_flags = data->subsample_flags; - EXPECT_EQ(NO_ERROR, decryptor_->Decrypt(session_id_, data->validate_key_id, - decryption_parameters)); - - EXPECT_TRUE(std::equal(data->decrypt_data.begin(), data->decrypt_data.end(), - decrypt_buffer.begin())); - decryptor_->CloseSession(session_id_); - - CdmUsageInfo usage_info; - CdmUsageInfoReleaseMessage release_msg; - CdmResponseType status = - decryptor_->GetUsageInfo(app_id, kDefaultCdmIdentifier, &usage_info); - EXPECT_EQ(usage_info.empty() ? NO_ERROR : KEY_MESSAGE, status); - - // Discard and retry to verify usage reports can be generated multiple times - // before release. - status = decryptor_->GetUsageInfo(app_id, kDefaultCdmIdentifier, &usage_info); - EXPECT_EQ(usage_info.empty() ? NO_ERROR : KEY_MESSAGE, status); - int error_count = 0; - while (usage_info.size() > 0) { - for (size_t i = 0; i < usage_info.size(); ++i) { - release_msg = GetUsageInfoResponse(config_.license_server(), - config_.client_auth(), usage_info[i]); - EXPECT_EQ(NO_ERROR, decryptor_->ReleaseUsageInfo(release_msg, - kDefaultCdmIdentifier)) - << i << "/" << usage_info.size() << " (err " << (error_count++) << ")" - << release_msg; - } - ASSERT_LE(error_count, 100); // Give up after 100 failures. - status = - decryptor_->GetUsageInfo(app_id, kDefaultCdmIdentifier, &usage_info); - switch (status) { - case KEY_MESSAGE: - EXPECT_FALSE(usage_info.empty()); - break; - case NO_ERROR: - EXPECT_TRUE(usage_info.empty()); - break; - default: - FAIL() << "GetUsageInfo failed with error " << static_cast(status); - break; - } - } -} - -TEST_F(WvCdmRequestLicenseTest, UsageInfo_ReleaseThreeRecords) { - Unprovision(); - Provision(); - - CdmSecurityLevel security_level = GetDefaultSecurityLevel(); - std::string app_id = ""; - FileSystem file_system; - DeviceFiles handle(&file_system); - EXPECT_TRUE(handle.Init(security_level)); - std::vector psts; - EXPECT_TRUE(handle.DeleteAllUsageInfoForApp( - DeviceFiles::GetUsageInfoFileName(app_id), &psts)); - - std::string session_id_clip3, session_id_clip4, session_id_clip7; - - // Open session for streaming_clip3 and verify decryption is successful - decryptor_->OpenSession(config_.key_system(), nullptr, kDefaultCdmIdentifier, - nullptr, &session_id_clip3); - - session_id_ = session_id_clip3; - GenerateKeyRequest(kPsshStreamingClip3, kLicenseTypeStreaming, nullptr); - VerifyUsageKeyRequestResponse(config_.license_server(), - config_.client_auth()); - - EXPECT_TRUE( - VerifyDecryption(session_id_clip3, usage_info_sub_samples_icp[0])); - - // Open session for streaming_clip4 and verify decryption is successful - decryptor_->OpenSession(config_.key_system(), nullptr, kDefaultCdmIdentifier, - nullptr, &session_id_clip4); - - session_id_ = session_id_clip4; - GenerateKeyRequest(kPsshStreamingClip4, kLicenseTypeStreaming, nullptr); - VerifyUsageKeyRequestResponse(config_.license_server(), - config_.client_auth()); - - EXPECT_TRUE( - VerifyDecryption(session_id_clip4, usage_info_sub_samples_icp[1])); - - // Open session for streaming_clip7 and verify decryption is successful - decryptor_->OpenSession(config_.key_system(), nullptr, kDefaultCdmIdentifier, - nullptr, &session_id_clip7); - - session_id_ = session_id_clip7; - GenerateKeyRequest(kPsshStreamingClip7, kLicenseTypeStreaming, nullptr); - VerifyUsageKeyRequestResponse(config_.license_server(), - config_.client_auth()); - - EXPECT_TRUE( - VerifyDecryption(session_id_clip7, usage_info_sub_samples_icp[4])); - - // Close session for streaming_clip4 and release usage information - decryptor_->CloseSession(session_id_clip4); - - CdmUsageInfo usage_info; - CdmUsageInfoReleaseMessage release_msg; - CdmResponseType status = - decryptor_->GetUsageInfo(app_id, kProviderSessionTokenStreamingClip4, - kDefaultCdmIdentifier, &usage_info); - EXPECT_EQ(KEY_MESSAGE, status); - ASSERT_EQ(1, usage_info.size()); - release_msg = GetUsageInfoResponse(config_.license_server(), - config_.client_auth(), usage_info[0]); - EXPECT_EQ(NO_ERROR, - decryptor_->ReleaseUsageInfo(release_msg, kDefaultCdmIdentifier)); - - decryptor_->CloseSession(session_id_clip7); - - status = decryptor_->GetUsageInfo(app_id, kProviderSessionTokenStreamingClip7, - kDefaultCdmIdentifier, &usage_info); - EXPECT_EQ(KEY_MESSAGE, status); - EXPECT_EQ(1, usage_info.size()); - release_msg = GetUsageInfoResponse(config_.license_server(), - config_.client_auth(), usage_info[0]); - EXPECT_EQ(NO_ERROR, - decryptor_->ReleaseUsageInfo(release_msg, kDefaultCdmIdentifier)); - - decryptor_->CloseSession(session_id_clip3); - - status = decryptor_->GetUsageInfo(app_id, kProviderSessionTokenStreamingClip3, - kDefaultCdmIdentifier, &usage_info); - EXPECT_EQ(KEY_MESSAGE, status); - EXPECT_EQ(1, usage_info.size()); - release_msg = GetUsageInfoResponse(config_.license_server(), - config_.client_auth(), usage_info[0]); - EXPECT_EQ(NO_ERROR, - decryptor_->ReleaseUsageInfo(release_msg, kDefaultCdmIdentifier)); -} - -class WvCdmUsageInfoTest - : public WvCdmRequestLicenseTest, - public ::testing::WithParamInterface {}; - -TEST_P(WvCdmUsageInfoTest, UsageInfo) { - Unprovision(); - - UsageInfoSubSampleInfo* usage_info_data = GetParam(); - TestWvCdmClientPropertySet client_property_set; - TestWvCdmClientPropertySet* property_set = nullptr; - if (kLevel3 == usage_info_data->security_level) { - client_property_set.set_security_level(QUERY_VALUE_SECURITY_LEVEL_L3); - property_set = &client_property_set; - Provision(kDefaultCdmIdentifier, kLevel3); - Provision(); - } else { - Provision(); - } - - CdmSecurityLevel security_level = GetDefaultSecurityLevel(); - FileSystem file_system; - DeviceFiles handle(&file_system); - EXPECT_TRUE(handle.Init(security_level)); - std::vector psts; - EXPECT_TRUE(handle.DeleteAllUsageInfoForApp( - DeviceFiles::GetUsageInfoFileName(usage_info_data->app_id), &psts)); - - for (size_t i = 0; i < usage_info_data->usage_info; ++i) { - SubSampleInfo* data = usage_info_data->sub_sample + i; - decryptor_->OpenSession(config_.key_system(), property_set, - kDefaultCdmIdentifier, nullptr, &session_id_); - std::string key_id = wvutil::a2bs_hex( - "000000427073736800000000" // blob size and pssh - "EDEF8BA979D64ACEA3C827DCD51D21ED00000022" // Widevine system id - "08011a0d7769646576696e655f74657374220f73" // pssh data - "747265616d696e675f636c6970"); - - char ch = 0x33 + i; - key_id.append(1, ch); - - GenerateKeyRequest(key_id, kLicenseTypeStreaming, property_set); - - // TODO(rfrias): streaming_clip6 is a streaming license without a pst - if (ch == '6') - VerifyKeyRequestResponse(config_.license_server(), config_.client_auth(), - false); - else - VerifyUsageKeyRequestResponse(config_.license_server(), - config_.client_auth()); - - std::vector decrypt_buffer(data->encrypt_data.size()); - CdmDecryptionParameters decryption_parameters( - &data->key_id, &data->encrypt_data.front(), data->encrypt_data.size(), - &data->iv, data->block_offset, &decrypt_buffer[0]); - decryption_parameters.is_encrypted = data->is_encrypted; - decryption_parameters.is_secure = data->is_secure; - decryption_parameters.subsample_flags = data->subsample_flags; - EXPECT_EQ(NO_ERROR, decryptor_->Decrypt(session_id_, data->validate_key_id, - decryption_parameters)); - - EXPECT_TRUE(std::equal(data->decrypt_data.begin(), data->decrypt_data.end(), - decrypt_buffer.begin())); - decryptor_->CloseSession(session_id_); - } - - CdmUsageInfo usage_info; - CdmUsageInfoReleaseMessage release_msg; - CdmResponseType status = decryptor_->GetUsageInfo( - usage_info_data->app_id, kDefaultCdmIdentifier, &usage_info); - EXPECT_EQ(usage_info.empty() ? NO_ERROR : KEY_MESSAGE, status); - int error_count = 0; - while (usage_info.size() > 0) { - for (size_t i = 0; i < usage_info.size(); ++i) { - release_msg = GetUsageInfoResponse(config_.license_server(), - config_.client_auth(), usage_info[i]); - EXPECT_EQ(NO_ERROR, decryptor_->ReleaseUsageInfo(release_msg, - kDefaultCdmIdentifier)) - << i << "/" << usage_info.size() << " (err " << (error_count++) << ")" - << release_msg; - } - ASSERT_LE(error_count, 100); // Give up after 100 failures. - status = decryptor_->GetUsageInfo(usage_info_data->app_id, - kDefaultCdmIdentifier, &usage_info); - EXPECT_EQ(usage_info.empty() ? NO_ERROR : KEY_MESSAGE, status); - } -} - -INSTANTIATE_TEST_CASE_P(Cdm, WvCdmUsageInfoTest, - ::testing::Values(&usage_info_sub_sample_info[0], - &usage_info_sub_sample_info[1], - &usage_info_sub_sample_info[2], - &usage_info_sub_sample_info[3], - &usage_info_sub_sample_info[4], - &usage_info_sub_sample_info[5], - &usage_info_sub_sample_info[6], - &usage_info_sub_sample_info[7])); - -TEST_F(WvCdmRequestLicenseTest, UsageRemoveAllTest) { - Unprovision(); - - std::string app_id_empty = ""; - std::string app_id_not_empty = "not empty"; - - TestWvCdmClientPropertySet property_set; - Provision(); - - CdmSecurityLevel security_level = GetDefaultSecurityLevel(); - FileSystem file_system; - DeviceFiles handle(&file_system); - EXPECT_TRUE(handle.Init(security_level)); - std::vector psts; - EXPECT_TRUE(handle.DeleteAllUsageInfoForApp( - DeviceFiles::GetUsageInfoFileName(""), &psts)); - - for (size_t i = 0; i < ArraySize(usage_info_sub_samples_icp); ++i) { - SubSampleInfo* data = usage_info_sub_samples_icp + i; - property_set.set_app_id(i % 2 == 0 ? app_id_empty : app_id_not_empty); - decryptor_->OpenSession(config_.key_system(), &property_set, - kDefaultCdmIdentifier, nullptr, &session_id_); - std::string key_id = wvutil::a2bs_hex( - "000000427073736800000000" // blob size and pssh - "EDEF8BA979D64ACEA3C827DCD51D21ED00000022" // Widevine system id - "08011a0d7769646576696e655f74657374220f73" // pssh data - "747265616d696e675f636c6970"); - - char ch = 0x33 + i; - key_id.append(1, ch); - - GenerateKeyRequest(key_id, kLicenseTypeStreaming, &property_set); - - // TODO(rfrias): streaming_clip6 is a streaming license without a pst - if (ch == '6') - VerifyKeyRequestResponse(config_.license_server(), config_.client_auth(), - false); - else - VerifyUsageKeyRequestResponse(config_.license_server(), - config_.client_auth()); - - std::vector decrypt_buffer(data->encrypt_data.size()); - CdmDecryptionParameters decryption_parameters( - &data->key_id, &data->encrypt_data.front(), data->encrypt_data.size(), - &data->iv, data->block_offset, &decrypt_buffer[0]); - decryption_parameters.is_encrypted = data->is_encrypted; - decryption_parameters.is_secure = data->is_secure; - decryption_parameters.subsample_flags = data->subsample_flags; - EXPECT_EQ(NO_ERROR, decryptor_->Decrypt(session_id_, data->validate_key_id, - decryption_parameters)); - - EXPECT_TRUE(std::equal(data->decrypt_data.begin(), data->decrypt_data.end(), - decrypt_buffer.begin())); - decryptor_->CloseSession(session_id_); - } - - CdmUsageInfo usage_info; - EXPECT_EQ(KEY_MESSAGE, decryptor_->GetUsageInfo( - app_id_empty, kDefaultCdmIdentifier, &usage_info)); - EXPECT_TRUE(usage_info.size() > 0); - EXPECT_EQ(KEY_MESSAGE, - decryptor_->GetUsageInfo(app_id_not_empty, kDefaultCdmIdentifier, - &usage_info)); - EXPECT_TRUE(usage_info.size() > 0); - - EXPECT_EQ(NO_ERROR, decryptor_->RemoveAllUsageInfo(app_id_not_empty, - kDefaultCdmIdentifier)); - - EXPECT_EQ(NO_ERROR, - decryptor_->GetUsageInfo(app_id_not_empty, kDefaultCdmIdentifier, - &usage_info)); - EXPECT_TRUE(usage_info.empty()); - EXPECT_EQ(KEY_MESSAGE, decryptor_->GetUsageInfo( - app_id_empty, kDefaultCdmIdentifier, &usage_info)); - EXPECT_TRUE(usage_info.size() > 0); - - EXPECT_EQ(NO_ERROR, decryptor_->RemoveAllUsageInfo(app_id_empty, - kDefaultCdmIdentifier)); - - EXPECT_EQ(NO_ERROR, - decryptor_->GetUsageInfo(app_id_not_empty, kDefaultCdmIdentifier, - &usage_info)); - EXPECT_TRUE(usage_info.empty()); - EXPECT_EQ(NO_ERROR, decryptor_->GetUsageInfo( - app_id_empty, kDefaultCdmIdentifier, &usage_info)); - EXPECT_TRUE(usage_info.empty()); -} - -TEST_F(WvCdmRequestLicenseTest, RemoveCorruptedUsageInfoTest) { - Unprovision(); - - std::string app_id_empty = ""; - std::string app_id_not_empty = "not empty"; - - TestWvCdmClientPropertySet property_set; - Provision(); - - CdmSecurityLevel security_level = GetDefaultSecurityLevel(); - FileSystem file_system; - DeviceFiles handle(&file_system); - ASSERT_TRUE(handle.Init(security_level)); - std::vector psts; - EXPECT_TRUE(handle.DeleteAllUsageInfoForApp( - DeviceFiles::GetUsageInfoFileName(""), &psts)); - - for (size_t i = 0; i < ArraySize(usage_info_sub_samples_icp); ++i) { - SubSampleInfo* data = usage_info_sub_samples_icp + i; - property_set.set_app_id(i % 2 == 0 ? app_id_empty : app_id_not_empty); - decryptor_->OpenSession(config_.key_system(), &property_set, - kDefaultCdmIdentifier, nullptr, &session_id_); - std::string key_id = wvutil::a2bs_hex( - "000000427073736800000000" // blob size and pssh - "EDEF8BA979D64ACEA3C827DCD51D21ED00000022" // Widevine system id - "08011a0d7769646576696e655f74657374220f73" // pssh data - "747265616d696e675f636c6970"); - - char ch = 0x33 + i; - key_id.append(1, ch); - - GenerateKeyRequest(key_id, kLicenseTypeStreaming, &property_set); - - // TODO(rfrias): streaming_clip6 is a streaming license without a pst - if (ch == '6') - VerifyKeyRequestResponse(config_.license_server(), config_.client_auth(), - false); - else - VerifyUsageKeyRequestResponse(config_.license_server(), - config_.client_auth()); - - std::vector decrypt_buffer(data->encrypt_data.size()); - CdmDecryptionParameters decryption_parameters( - &data->key_id, &data->encrypt_data.front(), data->encrypt_data.size(), - &data->iv, data->block_offset, &decrypt_buffer[0]); - decryption_parameters.is_encrypted = data->is_encrypted; - decryption_parameters.is_secure = data->is_secure; - decryption_parameters.subsample_flags = data->subsample_flags; - EXPECT_EQ(NO_ERROR, decryptor_->Decrypt(session_id_, data->validate_key_id, - decryption_parameters)); - - EXPECT_TRUE(std::equal(data->decrypt_data.begin(), data->decrypt_data.end(), - decrypt_buffer.begin())); - decryptor_->CloseSession(session_id_); - } - - CdmUsageInfo usage_info; - EXPECT_EQ(KEY_MESSAGE, decryptor_->GetUsageInfo( - app_id_empty, kDefaultCdmIdentifier, &usage_info)); - EXPECT_TRUE(usage_info.size() > 0); - EXPECT_EQ(KEY_MESSAGE, - decryptor_->GetUsageInfo(app_id_not_empty, kDefaultCdmIdentifier, - &usage_info)); - EXPECT_TRUE(usage_info.size() > 0); - - // Read in usage info file - std::string path; - EXPECT_TRUE(Properties::GetDeviceFilesBasePath(security_level, &path)); - std::string usage_info_not_empty_app_id_file_name = - path + DeviceFiles::GetUsageInfoFileName(app_id_not_empty); - - ssize_t file_size = - file_system.FileSize(usage_info_not_empty_app_id_file_name); - EXPECT_LT(4, file_size); - std::unique_ptr file = file_system.Open( - usage_info_not_empty_app_id_file_name, FileSystem::kReadOnly); - ASSERT_NE(file, nullptr); - std::string file_data; - file_data.resize(file_size); - ssize_t bytes = file->Read(&file_data[0], file_data.size()); - EXPECT_EQ(file_size, bytes); - - // Corrupt the hash of the usage info file with non-empty app id and write - // it back out - memset(&file_data[0] + bytes - 4, 0, 4); - file = file_system.Open(usage_info_not_empty_app_id_file_name, - FileSystem::kCreate | FileSystem::kTruncate); - ASSERT_NE(file, nullptr); - bytes = file->Write(file_data.data(), file_data.size()); - EXPECT_EQ(file_size, bytes); - - EXPECT_EQ(NO_ERROR, decryptor_->RemoveAllUsageInfo(app_id_not_empty, - kDefaultCdmIdentifier)); - - EXPECT_EQ(NO_ERROR, - decryptor_->GetUsageInfo(app_id_not_empty, kDefaultCdmIdentifier, - &usage_info)); - EXPECT_TRUE(usage_info.empty()); - EXPECT_EQ(KEY_MESSAGE, decryptor_->GetUsageInfo( - app_id_empty, kDefaultCdmIdentifier, &usage_info)); - EXPECT_TRUE(usage_info.size() > 0); - - // Read in usage info file - std::string usage_info_empty_app_id_file_name = - path + DeviceFiles::GetUsageInfoFileName(app_id_empty); - - file_size = file_system.FileSize(usage_info_empty_app_id_file_name); - EXPECT_LT(4, file_size); - file = file_system.Open(usage_info_empty_app_id_file_name, - FileSystem::kReadOnly); - ASSERT_NE(file, nullptr); - file_data.resize(file_size); - bytes = file->Read(&file_data[0], file_data.size()); - EXPECT_EQ(file_size, bytes); - - // Corrupt the hash of the usage info file with empty app id and write it - // back out - memset(&file_data[0] + bytes - 4, 0, 4); - file = file_system.Open(usage_info_empty_app_id_file_name, - FileSystem::kCreate | FileSystem::kTruncate); - ASSERT_NE(file, nullptr); - bytes = file->Write(file_data.data(), file_data.size()); - EXPECT_EQ(file_size, bytes); - - EXPECT_EQ(NO_ERROR, decryptor_->RemoveAllUsageInfo(app_id_empty, - kDefaultCdmIdentifier)); - - EXPECT_EQ(NO_ERROR, - decryptor_->GetUsageInfo(app_id_not_empty, kDefaultCdmIdentifier, - &usage_info)); - EXPECT_TRUE(usage_info.empty()); - EXPECT_EQ(NO_ERROR, decryptor_->GetUsageInfo( - app_id_empty, kDefaultCdmIdentifier, &usage_info)); - EXPECT_TRUE(usage_info.empty()); -} - -TEST_F(WvCdmRequestLicenseTest, RemoveCorruptedUsageInfoTest2) { - Unprovision(); - - std::string app_id_empty = ""; - std::string app_id_not_empty = "not empty"; - - TestWvCdmClientPropertySet property_set; - Provision(); - - CdmSecurityLevel security_level = GetDefaultSecurityLevel(); - FileSystem file_system; - DeviceFiles handle(&file_system); - EXPECT_TRUE(handle.Init(security_level)); - std::vector psts; - EXPECT_TRUE(handle.DeleteAllUsageInfoForApp( - DeviceFiles::GetUsageInfoFileName(""), &psts)); - - for (size_t i = 0; i < ArraySize(usage_info_sub_samples_icp); ++i) { - SubSampleInfo* data = usage_info_sub_samples_icp + i; - property_set.set_app_id(i % 2 == 0 ? app_id_empty : app_id_not_empty); - decryptor_->OpenSession(config_.key_system(), &property_set, - kDefaultCdmIdentifier, nullptr, &session_id_); - std::string key_id = wvutil::a2bs_hex( - "000000427073736800000000" // blob size and pssh - "EDEF8BA979D64ACEA3C827DCD51D21ED00000022" // Widevine system id - "08011a0d7769646576696e655f74657374220f73" // pssh data - "747265616d696e675f636c6970"); - - char ch = 0x33 + i; - key_id.append(1, ch); - - GenerateKeyRequest(key_id, kLicenseTypeStreaming, &property_set); - - // TODO(rfrias): streaming_clip6 is a streaming license without a pst - if (ch == '6') - VerifyKeyRequestResponse(config_.license_server(), config_.client_auth(), - false); - else - VerifyUsageKeyRequestResponse(config_.license_server(), - config_.client_auth()); - - std::vector decrypt_buffer(data->encrypt_data.size()); - CdmDecryptionParameters decryption_parameters( - &data->key_id, &data->encrypt_data.front(), data->encrypt_data.size(), - &data->iv, data->block_offset, &decrypt_buffer[0]); - decryption_parameters.is_encrypted = data->is_encrypted; - decryption_parameters.is_secure = data->is_secure; - decryption_parameters.subsample_flags = data->subsample_flags; - EXPECT_EQ(NO_ERROR, decryptor_->Decrypt(session_id_, data->validate_key_id, - decryption_parameters)); - - EXPECT_TRUE(std::equal(data->decrypt_data.begin(), data->decrypt_data.end(), - decrypt_buffer.begin())); - decryptor_->CloseSession(session_id_); - } - - CdmUsageInfo usage_info; - EXPECT_EQ(KEY_MESSAGE, decryptor_->GetUsageInfo( - app_id_empty, kDefaultCdmIdentifier, &usage_info)); - EXPECT_TRUE(usage_info.size() > 0); - EXPECT_EQ(KEY_MESSAGE, - decryptor_->GetUsageInfo(app_id_not_empty, kDefaultCdmIdentifier, - &usage_info)); - EXPECT_TRUE(usage_info.size() > 0); - - // Read in usage info file - std::string path; - EXPECT_TRUE(Properties::GetDeviceFilesBasePath(security_level, &path)); - std::string usage_info_not_empty_app_id_file_name = - path + DeviceFiles::GetUsageInfoFileName(app_id_not_empty); - - ssize_t file_size = - file_system.FileSize(usage_info_not_empty_app_id_file_name); - EXPECT_LT(4, file_size); - std::unique_ptr file = file_system.Open( - usage_info_not_empty_app_id_file_name, FileSystem::kReadOnly); - ASSERT_NE(file, nullptr); - std::string file_data; - file_data.resize(file_size); - ssize_t bytes = file->Read(&file_data[0], file_data.size()); - EXPECT_EQ(file_size, bytes); - - video_widevine_client::sdk::HashedFile hash_file; - - EXPECT_TRUE(hash_file.ParseFromString(file_data)); - size_t pos = file_data.find(hash_file.hash()); - EXPECT_NE(std::string::npos, pos); - EXPECT_NE(0u, pos); - - // Corrupt the protobuf key field of the hash of the usage info file - // with non-empty app id and write it back out - file_data[pos - 1] = 0xff; - - file = file_system.Open(usage_info_not_empty_app_id_file_name, - FileSystem::kCreate | FileSystem::kTruncate); - ASSERT_NE(file, nullptr); - bytes = file->Write(file_data.data(), file_data.size()); - EXPECT_EQ(file_size, bytes); - - EXPECT_EQ(NO_ERROR, decryptor_->RemoveAllUsageInfo(app_id_not_empty, - kDefaultCdmIdentifier)); - - EXPECT_EQ(NO_ERROR, - decryptor_->GetUsageInfo(app_id_not_empty, kDefaultCdmIdentifier, - &usage_info)); - EXPECT_TRUE(usage_info.empty()); - EXPECT_EQ(KEY_MESSAGE, decryptor_->GetUsageInfo( - app_id_empty, kDefaultCdmIdentifier, &usage_info)); - EXPECT_TRUE(usage_info.size() > 0); - - // Read in usage info file - std::string usage_info_empty_app_id_file_name = - path + DeviceFiles::GetUsageInfoFileName(app_id_empty); - - file_size = file_system.FileSize(usage_info_empty_app_id_file_name); - EXPECT_LT(4, file_size); - file = file_system.Open(usage_info_empty_app_id_file_name, - FileSystem::kReadOnly); - ASSERT_NE(file, nullptr); - file_data.resize(file_size); - bytes = file->Read(&file_data[0], file_data.size()); - EXPECT_EQ(file_size, bytes); - - EXPECT_TRUE(hash_file.ParseFromString(file_data)); - pos = file_data.find(hash_file.hash()); - EXPECT_NE(std::string::npos, pos); - EXPECT_NE(0u, pos); - - // Corrupt the protobuf key field of the hash of the usage info file - // with empty app id and write it back out - file_data[pos - 1] = 0xff; - - file = file_system.Open(usage_info_empty_app_id_file_name, - FileSystem::kCreate | FileSystem::kTruncate); - ASSERT_NE(file, nullptr); - bytes = file->Write(file_data.data(), file_data.size()); - EXPECT_EQ(file_size, bytes); - - EXPECT_EQ(NO_ERROR, decryptor_->RemoveAllUsageInfo(app_id_empty, - kDefaultCdmIdentifier)); - - EXPECT_EQ(NO_ERROR, - decryptor_->GetUsageInfo(app_id_not_empty, kDefaultCdmIdentifier, - &usage_info)); - EXPECT_TRUE(usage_info.empty()); - EXPECT_EQ(NO_ERROR, decryptor_->GetUsageInfo( - app_id_empty, kDefaultCdmIdentifier, &usage_info)); - EXPECT_TRUE(usage_info.empty()); -} - -TEST_F(WvCdmRequestLicenseTest, GetSecureStopIdsTest) { - Unprovision(); - - std::string app_id_empty = ""; - - TestWvCdmClientPropertySet property_set; - Provision(); - - CdmSecurityLevel security_level = GetDefaultSecurityLevel(); - FileSystem file_system; - DeviceFiles handle(&file_system); - EXPECT_TRUE(handle.Init(security_level)); - std::vector psts; - EXPECT_TRUE(handle.DeleteAllUsageInfoForApp( - DeviceFiles::GetUsageInfoFileName(""), &psts)); - - std::vector retrieved_secure_stop_ids; - EXPECT_EQ(NO_ERROR, - decryptor_->GetSecureStopIds(app_id_empty, kDefaultCdmIdentifier, - &retrieved_secure_stop_ids)); - EXPECT_TRUE(retrieved_secure_stop_ids.empty()); - - // First fetch licenses for the default app - for (size_t i = 0; i < ArraySize(kUsageLicenseTestVector1); ++i) { - SubSampleInfo* data = kUsageLicenseTestVector1[i].sub_sample; - - property_set.set_app_id(app_id_empty); - decryptor_->OpenSession(config_.key_system(), &property_set, - kDefaultCdmIdentifier, nullptr, &session_id_); - GenerateKeyRequest(kUsageLicenseTestVector1[i].pssh, kLicenseTypeStreaming, - &property_set); - - VerifyUsageKeyRequestResponse(config_.license_server(), - config_.client_auth()); - - std::vector decrypt_buffer(data->encrypt_data.size()); - CdmDecryptionParameters decryption_parameters( - &data->key_id, &data->encrypt_data.front(), data->encrypt_data.size(), - &data->iv, data->block_offset, &decrypt_buffer[0]); - decryption_parameters.is_encrypted = data->is_encrypted; - decryption_parameters.is_secure = data->is_secure; - decryption_parameters.subsample_flags = data->subsample_flags; - EXPECT_EQ(NO_ERROR, decryptor_->Decrypt(session_id_, data->validate_key_id, - decryption_parameters)); - - EXPECT_TRUE(std::equal(data->decrypt_data.begin(), data->decrypt_data.end(), - decrypt_buffer.begin())); - decryptor_->CloseSession(session_id_); - } - - // Provision the other identifier - Provision(kExampleIdentifier, kLevelDefault); - - // Verify that there are usage records for the default identifier but - // none yet for the non-default one - std::vector expected_provider_session_tokens; - for (size_t i = 0; i < ArraySize(kUsageLicenseTestVector1); ++i) { - expected_provider_session_tokens.push_back( - kUsageLicenseTestVector1[i].provider_session_token); - } - - EXPECT_EQ(NO_ERROR, - decryptor_->GetSecureStopIds(app_id_empty, kDefaultCdmIdentifier, - &retrieved_secure_stop_ids)); - EXPECT_EQ(ArraySize(kUsageLicenseTestVector1), - retrieved_secure_stop_ids.size()); - EXPECT_THAT(retrieved_secure_stop_ids, - UnorderedElementsAreArray(expected_provider_session_tokens)); - - EXPECT_EQ(NO_ERROR, decryptor_->GetSecureStopIds( - kExampleIdentifier.app_package_name, - kDefaultCdmIdentifier, &retrieved_secure_stop_ids)); - EXPECT_TRUE(retrieved_secure_stop_ids.empty()); - - // Now fetch licenses for the other identifier - for (size_t i = 0; i < ArraySize(kUsageLicenseTestVector2); ++i) { - SubSampleInfo* data = kUsageLicenseTestVector2[i].sub_sample; - - property_set.set_app_id(kExampleIdentifier.app_package_name); - EXPECT_EQ(NO_ERROR, decryptor_->OpenSession( - config_.key_system(), &property_set, - kExampleIdentifier, nullptr, &session_id_)); - std::string init_data_type = "video/mp4"; - CdmAppParameterMap app_parameters; - GenerateKeyRequest(wvcdm::KEY_MESSAGE, init_data_type, - kUsageLicenseTestVector2[i].pssh, app_parameters, - kLicenseTypeStreaming, kExampleIdentifier, - &property_set); - - VerifyUsageKeyRequestResponse(config_.license_server(), - config_.client_auth()); - - std::vector decrypt_buffer(data->encrypt_data.size()); - CdmDecryptionParameters decryption_parameters( - &data->key_id, &data->encrypt_data.front(), data->encrypt_data.size(), - &data->iv, data->block_offset, &decrypt_buffer[0]); - decryption_parameters.is_encrypted = data->is_encrypted; - decryption_parameters.is_secure = data->is_secure; - decryption_parameters.subsample_flags = data->subsample_flags; - EXPECT_EQ(NO_ERROR, decryptor_->Decrypt(session_id_, data->validate_key_id, - decryption_parameters)); - - EXPECT_TRUE(std::equal(data->decrypt_data.begin(), data->decrypt_data.end(), - decrypt_buffer.begin())); - decryptor_->CloseSession(session_id_); - } - - // Verify that there are usage records for both the default and - // non-default identifier. - EXPECT_EQ(NO_ERROR, decryptor_->GetSecureStopIds( - kDefaultCdmIdentifier.app_package_name, - kDefaultCdmIdentifier, &retrieved_secure_stop_ids)); - EXPECT_EQ(ArraySize(kUsageLicenseTestVector1), - retrieved_secure_stop_ids.size()); - EXPECT_THAT(retrieved_secure_stop_ids, - UnorderedElementsAreArray(expected_provider_session_tokens)); - - retrieved_secure_stop_ids.clear(); - expected_provider_session_tokens.clear(); - - for (size_t i = 0; i < ArraySize(kUsageLicenseTestVector2); ++i) { - expected_provider_session_tokens.push_back( - kUsageLicenseTestVector2[i].provider_session_token); - } - - EXPECT_EQ(NO_ERROR, decryptor_->GetSecureStopIds( - kExampleIdentifier.app_package_name, - kExampleIdentifier, &retrieved_secure_stop_ids)); - EXPECT_EQ(ArraySize(kUsageLicenseTestVector2), - retrieved_secure_stop_ids.size()); - EXPECT_THAT(retrieved_secure_stop_ids, - UnorderedElementsAreArray(expected_provider_session_tokens)); - - EXPECT_EQ(NO_ERROR, - decryptor_->RemoveAllUsageInfo( - kDefaultCdmIdentifier.app_package_name, kDefaultCdmIdentifier)); - EXPECT_EQ(NO_ERROR, - decryptor_->RemoveAllUsageInfo(kExampleIdentifier.app_package_name, - kExampleIdentifier)); - - EXPECT_EQ(NO_ERROR, decryptor_->GetSecureStopIds( - kDefaultCdmIdentifier.app_package_name, - kDefaultCdmIdentifier, &retrieved_secure_stop_ids)); - EXPECT_TRUE(retrieved_secure_stop_ids.empty()); - EXPECT_EQ(NO_ERROR, decryptor_->GetSecureStopIds( - kExampleIdentifier.app_package_name, - kExampleIdentifier, &retrieved_secure_stop_ids)); - EXPECT_TRUE(retrieved_secure_stop_ids.empty()); -} - -TEST_F(WvCdmRequestLicenseTest, UsageRecoveryTest) { - Unprovision(); - - std::string app_id_empty = ""; - - TestWvCdmClientPropertySet property_set; - Provision(); - - CdmSecurityLevel security_level = GetDefaultSecurityLevel(); - FileSystem file_system; - DeviceFiles handle(&file_system); - EXPECT_TRUE(handle.Init(security_level)); - std::vector psts; - EXPECT_TRUE(handle.DeleteAllUsageInfoForApp( - DeviceFiles::GetUsageInfoFileName(""), &psts)); - - // Fetch a usage license - SubSampleInfo* data = kUsageLicenseTestVector1[0].sub_sample; - - property_set.set_app_id(app_id_empty); - decryptor_->OpenSession(config_.key_system(), &property_set, - kDefaultCdmIdentifier, nullptr, &session_id_); - GenerateKeyRequest(kUsageLicenseTestVector1[0].pssh, kLicenseTypeStreaming, - &property_set); - - VerifyUsageKeyRequestResponse(config_.license_server(), - config_.client_auth()); - - std::vector decrypt_buffer(data->encrypt_data.size()); - CdmDecryptionParameters decryption_parameters( - &data->key_id, &data->encrypt_data.front(), data->encrypt_data.size(), - &data->iv, data->block_offset, &decrypt_buffer[0]); - decryption_parameters.is_encrypted = data->is_encrypted; - decryption_parameters.is_secure = data->is_secure; - decryption_parameters.subsample_flags = data->subsample_flags; - EXPECT_EQ(NO_ERROR, decryptor_->Decrypt(session_id_, data->validate_key_id, - decryption_parameters)); - - EXPECT_TRUE(std::equal(data->decrypt_data.begin(), data->decrypt_data.end(), - decrypt_buffer.begin())); - decryptor_->CloseSession(session_id_); - - std::string path; - EXPECT_TRUE(Properties::GetDeviceFilesBasePath(security_level, &path)); - std::string usage_info_file_name = - path + DeviceFiles::GetUsageInfoFileName(app_id_empty); - - // Read in usage info file - ssize_t file_size = file_system.FileSize(usage_info_file_name); - EXPECT_LT(4, file_size); - std::unique_ptr file = - file_system.Open(usage_info_file_name, FileSystem::kReadOnly); - ASSERT_NE(file, nullptr); - std::string file_data; - file_data.resize(file_size); - ssize_t bytes = file->Read(&file_data[0], file_data.size()); - EXPECT_EQ(file_size, bytes); - - // Corrupt the hash of the usage info file and write it back out - memset(&file_data[0] + bytes - 4, 0, 4); - file = file_system.Open(usage_info_file_name, - FileSystem::kCreate | FileSystem::kTruncate); - ASSERT_NE(file, nullptr); - bytes = file->Write(file_data.data(), file_data.size()); - EXPECT_EQ(file_size, bytes); - - // Fetch a second usage license, this should fail as the usage table is - // corrupt - decryptor_->OpenSession(config_.key_system(), &property_set, - kDefaultCdmIdentifier, nullptr, &session_id_); - GenerateKeyRequest(kUsageLicenseTestVector1[1].pssh, kLicenseTypeStreaming, - &property_set); - - std::string response; - VerifyKeyRequestResponse(wvcdm::STORE_USAGE_INFO_ERROR, - config_.license_server(), config_.client_auth(), - true, &response); - - decryptor_->CloseSession(session_id_); - - // Fetch the second usage license and verify that it is usable - decryptor_->OpenSession(config_.key_system(), &property_set, - kDefaultCdmIdentifier, nullptr, &session_id_); - GenerateKeyRequest(kUsageLicenseTestVector1[1].pssh, kLicenseTypeStreaming, - &property_set); - - VerifyUsageKeyRequestResponse(config_.license_server(), - config_.client_auth()); - - data = kUsageLicenseTestVector1[1].sub_sample; - - decrypt_buffer.resize(data->encrypt_data.size()); - decryption_parameters.key_id = &data->key_id; - decryption_parameters.encrypt_buffer = &data->encrypt_data.front(); - decryption_parameters.encrypt_length = data->encrypt_data.size(); - decryption_parameters.iv = &data->iv; - decryption_parameters.block_offset = data->block_offset; - decryption_parameters.decrypt_buffer = &decrypt_buffer[0]; - decryption_parameters.decrypt_buffer_length = data->encrypt_data.size(); - decryption_parameters.is_encrypted = data->is_encrypted; - decryption_parameters.is_secure = data->is_secure; - decryption_parameters.subsample_flags = data->subsample_flags; - EXPECT_EQ(NO_ERROR, decryptor_->Decrypt(session_id_, data->validate_key_id, - decryption_parameters)); - - EXPECT_TRUE(std::equal(data->decrypt_data.begin(), data->decrypt_data.end(), - decrypt_buffer.begin())); - decryptor_->CloseSession(session_id_); -} - -TEST_F(WvCdmRequestLicenseTest, UsageRemoveSecureStopTest) { - Unprovision(); - - std::string app_id_empty = ""; - - TestWvCdmClientPropertySet property_set; - Provision(); - - CdmSecurityLevel security_level = GetDefaultSecurityLevel(); - FileSystem file_system; - DeviceFiles handle(&file_system); - EXPECT_TRUE(handle.Init(security_level)); - std::vector psts; - EXPECT_TRUE(handle.DeleteAllUsageInfoForApp( - DeviceFiles::GetUsageInfoFileName(""), &psts)); - - // First fetch licenses for the default app - for (size_t i = 0; i < ArraySize(kUsageLicenseTestVector1); ++i) { - SubSampleInfo* data = kUsageLicenseTestVector1[i].sub_sample; - - property_set.set_app_id(app_id_empty); - decryptor_->OpenSession(config_.key_system(), &property_set, - kDefaultCdmIdentifier, nullptr, &session_id_); - GenerateKeyRequest(kUsageLicenseTestVector1[i].pssh, kLicenseTypeStreaming, - &property_set); - - VerifyUsageKeyRequestResponse(config_.license_server(), - config_.client_auth()); - - std::vector decrypt_buffer(data->encrypt_data.size()); - CdmDecryptionParameters decryption_parameters( - &data->key_id, &data->encrypt_data.front(), data->encrypt_data.size(), - &data->iv, data->block_offset, &decrypt_buffer[0]); - decryption_parameters.is_encrypted = data->is_encrypted; - decryption_parameters.is_secure = data->is_secure; - decryption_parameters.subsample_flags = data->subsample_flags; - EXPECT_EQ(NO_ERROR, decryptor_->Decrypt(session_id_, data->validate_key_id, - decryption_parameters)); - - EXPECT_TRUE(std::equal(data->decrypt_data.begin(), data->decrypt_data.end(), - decrypt_buffer.begin())); - decryptor_->CloseSession(session_id_); - } - - // Provision and fetch licenses for the other identifier - Provision(kExampleIdentifier, kLevelDefault); - - for (size_t i = 0; i < ArraySize(kUsageLicenseTestVector2); ++i) { - SubSampleInfo* data = kUsageLicenseTestVector2[i].sub_sample; - - property_set.set_app_id(kExampleIdentifier.app_package_name); - EXPECT_EQ(NO_ERROR, decryptor_->OpenSession( - config_.key_system(), &property_set, - kExampleIdentifier, nullptr, &session_id_)); - std::string init_data_type = "video/mp4"; - CdmAppParameterMap app_parameters; - GenerateKeyRequest(wvcdm::KEY_MESSAGE, init_data_type, - kUsageLicenseTestVector2[i].pssh, app_parameters, - kLicenseTypeStreaming, kExampleIdentifier, - &property_set); - - VerifyUsageKeyRequestResponse(config_.license_server(), - config_.client_auth()); - - std::vector decrypt_buffer(data->encrypt_data.size()); - CdmDecryptionParameters decryption_parameters( - &data->key_id, &data->encrypt_data.front(), data->encrypt_data.size(), - &data->iv, data->block_offset, &decrypt_buffer[0]); - decryption_parameters.is_encrypted = data->is_encrypted; - decryption_parameters.is_secure = data->is_secure; - decryption_parameters.subsample_flags = data->subsample_flags; - EXPECT_EQ(NO_ERROR, decryptor_->Decrypt(session_id_, data->validate_key_id, - decryption_parameters)); - - EXPECT_TRUE(std::equal(data->decrypt_data.begin(), data->decrypt_data.end(), - decrypt_buffer.begin())); - decryptor_->CloseSession(session_id_); - } - - // Release usage records for both the default and non-default identifier. - std::vector secure_stop_ids; - EXPECT_EQ(NO_ERROR, decryptor_->GetSecureStopIds( - kDefaultCdmIdentifier.app_package_name, - kDefaultCdmIdentifier, &secure_stop_ids)); - EXPECT_EQ(ArraySize(kUsageLicenseTestVector1), secure_stop_ids.size()); - - for (size_t i = 0; i < secure_stop_ids.size(); ++i) { - EXPECT_EQ(NO_ERROR, decryptor_->RemoveUsageInfo( - kDefaultCdmIdentifier.app_package_name, - kDefaultCdmIdentifier, secure_stop_ids[i])); - } - - EXPECT_EQ(NO_ERROR, decryptor_->GetSecureStopIds( - kDefaultCdmIdentifier.app_package_name, - kDefaultCdmIdentifier, &secure_stop_ids)); - EXPECT_TRUE(secure_stop_ids.empty()); - - EXPECT_EQ(NO_ERROR, - decryptor_->GetSecureStopIds(kExampleIdentifier.app_package_name, - kExampleIdentifier, &secure_stop_ids)); - EXPECT_EQ(ArraySize(kUsageLicenseTestVector2), secure_stop_ids.size()); - - for (size_t i = 0; i < secure_stop_ids.size(); ++i) { - EXPECT_EQ(NO_ERROR, decryptor_->RemoveUsageInfo( - kExampleIdentifier.app_package_name, - kExampleIdentifier, secure_stop_ids[i])); - } - - EXPECT_EQ(NO_ERROR, - decryptor_->GetSecureStopIds(kExampleIdentifier.app_package_name, - kExampleIdentifier, &secure_stop_ids)); - EXPECT_TRUE(secure_stop_ids.empty()); -} - // TODO(rfrias): Enable when b/123370099 has been addressed TEST_F(WvCdmRequestLicenseTest, VerifyProviderClientToken) { Unprovision(); @@ -5793,10 +4629,11 @@ TEST_F(WvCdmRequestLicenseTest, KeyControlBlockDecryptionTest) { class WvCdmSessionSharingTest : public WvCdmRequestLicenseTest, - public ::testing::WithParamInterface {}; + public ::testing::WithParamInterface { +}; TEST_P(WvCdmSessionSharingTest, SessionSharingTest) { - SessionSharingSubSampleInfo* session_sharing_info = GetParam(); + const SessionSharingSubSampleInfo* session_sharing_info = GetParam(); CdmIdentifier cdm_identifier = session_sharing_info->cdm_identifier; if (!cdm_identifier.IsEquivalentToDefault()) { @@ -5829,7 +4666,7 @@ TEST_P(WvCdmSessionSharingTest, SessionSharingTest) { GenerateKeyRequest(gp_key_id2, kLicenseTypeStreaming, cdm_identifier); VerifyKeyRequestResponse(config_.license_server(), gp_client_auth2); - SubSampleInfo* data = session_sharing_info->sub_sample; + const SubSampleInfo* data = session_sharing_info->sub_sample; std::vector decrypt_buffer(data->encrypt_data.size()); CdmDecryptionParameters decryption_parameters( &data->key_id, &data->encrypt_data.front(), data->encrypt_data.size(), @@ -5897,7 +4734,7 @@ TEST_F(WvCdmRequestLicenseTest, SessionSharingTest) { GenerateKeyRequest(init_data2, kLicenseTypeStreaming); VerifyKeyRequestResponse(config_.license_server(), gp_client_auth2); - SubSampleInfo* data = &single_encrypted_sub_sample_short_expiry; + const SubSampleInfo* data = &single_encrypted_sub_sample_short_expiry; std::vector decrypt_buffer(data->encrypt_data.size()); CdmDecryptionParameters decryption_parameters( @@ -5937,7 +4774,7 @@ TEST_F(WvCdmRequestLicenseTest, DecryptionKeyExpiredTest) { "000000347073736800000000" // blob size and pssh "EDEF8BA979D64ACEA3C827DCD51D21ED00000014" // Widevine system id "0801121030313233343536373839616263646566"); // pssh data - SubSampleInfo* data = &single_encrypted_sub_sample_short_expiry; + const SubSampleInfo* data = &single_encrypted_sub_sample_short_expiry; decryptor_->OpenSession(config_.key_system(), nullptr, kDefaultCdmIdentifier, nullptr, &session_id_); if (data->retrieve_key) { @@ -6048,10 +4885,10 @@ TEST_F(WvCdmRequestLicenseTest, SessionKeyChangeNotificationTest) { class WvCdmDecryptionTest : public WvCdmRequestLicenseTest, - public ::testing::WithParamInterface {}; + public ::testing::WithParamInterface {}; TEST_P(WvCdmDecryptionTest, DecryptionTest) { - SubSampleInfo* data = GetParam(); + const SubSampleInfo* data = GetParam(); decryptor_->OpenSession(config_.key_system(), nullptr, kDefaultCdmIdentifier, nullptr, &session_id_); if (data->retrieve_key) { @@ -6100,10 +4937,10 @@ INSTANTIATE_TEST_CASE_P(Cdm, WvCdmDecryptionTest, class WvCdmSessionSharingNoKeyTest : public WvCdmRequestLicenseTest, - public ::testing::WithParamInterface {}; + public ::testing::WithParamInterface {}; TEST_P(WvCdmSessionSharingNoKeyTest, DecryptionTest) { - SubSampleInfo* data = GetParam(); + const SubSampleInfo* data = GetParam(); TestWvCdmClientPropertySet property_set; property_set.set_session_sharing_mode(true); @@ -6555,7 +5392,7 @@ TEST_F(WvCdmRequestLicenseTest, RemoveOfflineLicenseWithMissingUsageEntry) { EXPECT_TRUE(handle.StoreLicense(license_data, &sub_result)); EXPECT_EQ(DeviceFiles::kNoError, sub_result); - std::vector key_set_ids; + std::vector key_set_ids; EXPECT_EQ(NO_ERROR, decryptor_->ListStoredLicenses( security_level, kDefaultCdmIdentifier, &key_set_ids)); // Note: It is possible that future changes to the CDM will cause this @@ -6605,10 +5442,10 @@ TEST_F(WvCdmRequestLicenseTest, RemoveOfflineLicenseWithMissingUsageEntry) { class WvCdmRequestLicenseRollbackTest : public WvCdmRequestLicenseTest, - public ::testing::WithParamInterface { + public ::testing::WithParamInterface { public: WvCdmRequestLicenseRollbackTest() { - SubSampleInfo* data = &single_encrypted_sub_sample_short_expiry; + const SubSampleInfo* data = &single_encrypted_sub_sample_short_expiry; decrypt_buffer_.resize(data->encrypt_data.size()); decryption_parameters_ = CdmDecryptionParameters( &data->key_id, &data->encrypt_data.front(), data->encrypt_data.size(), diff --git a/libwvdrmengine/mediadrm/test/WVDrmPlugin_hal_test.cpp b/libwvdrmengine/mediadrm/test/WVDrmPlugin_hal_test.cpp index 630ec29e..c1079bf3 100644 --- a/libwvdrmengine/mediadrm/test/WVDrmPlugin_hal_test.cpp +++ b/libwvdrmengine/mediadrm/test/WVDrmPlugin_hal_test.cpp @@ -47,8 +47,6 @@ using ::aidl::android::hardware::drm::KeyValue; using ::aidl::android::hardware::drm::OfflineLicenseState; using ::aidl::android::hardware::drm::ProvideProvisionResponseResult; using ::aidl::android::hardware::drm::ProvisionRequest; -using ::aidl::android::hardware::drm::SecureStop; -using ::aidl::android::hardware::drm::SecureStopId; using ::aidl::android::hardware::drm::SecurityLevel; using ::aidl::android::hardware::drm::Status; @@ -91,10 +89,7 @@ using wvcdm::CdmOfflineLicenseState; using wvcdm::CdmProvisioningRequest; using wvcdm::CdmProvisioningResponse; using wvcdm::CdmQueryMap; -using wvcdm::CdmSecureStopId; using wvcdm::CdmSecurityLevel; -using wvcdm::CdmUsageInfo; -using wvcdm::CdmUsageInfoReleaseMessage; using wvcdm::EMPTY_ORIGIN; using wvcdm::kCertificateWidevine; using wvcdm::KEY_ID_SIZE; @@ -222,22 +217,6 @@ public: bool), (override)); - MOCK_METHOD(CdmResponseType, GetUsageInfo, - (const std::string &, const CdmIdentifier &, CdmUsageInfo *), - (override)); - - MOCK_METHOD(CdmResponseType, GetUsageInfo, - (const std::string &, const CdmSecureStopId &, - const CdmIdentifier &, CdmUsageInfo *), - (override)); - - MOCK_METHOD(CdmResponseType, RemoveAllUsageInfo, - (const std::string &, const CdmIdentifier &), (override)); - - MOCK_METHOD(CdmResponseType, ReleaseUsageInfo, - (const CdmUsageInfoReleaseMessage &, const CdmIdentifier &), - (override)); - MOCK_METHOD(bool, IsValidServiceCertificate, (const std::string &), (override)); @@ -980,75 +959,6 @@ TEST_F(WVDrmPluginHalTest, RejectsAtscUnprovisionDeviceRequests) { ASSERT_EQ(Status::ERROR_DRM_CANNOT_HANDLE, status); } -TEST_F(WVDrmPluginHalTest, GetsSecureStops) { - static const uint32_t kStopSize = 53; - static const uint32_t kStopCount = 7; - uint8_t stopsRaw[kStopCount][kStopSize]; - FILE *fp = fopen("/dev/urandom", "r"); - ASSERT_NE(fp, nullptr) << "Failed to open /dev/urandom"; - for (uint32_t i = 0; i < kStopCount; ++i) { - fread(stopsRaw[i], sizeof(uint8_t), kStopSize, fp); - } - fclose(fp); - - CdmUsageInfo mCdmStops; - for (uint32_t i = 0; i < kStopCount; ++i) { - mCdmStops.push_back(std::string(stopsRaw[i], stopsRaw[i] + kStopSize)); - } - - const char *app_id = "my_app_id"; - EXPECT_CALL(*mCdm, GetUsageInfo(StrEq(app_id), _, _)) - .WillOnce( - DoAll(SetArgPointee<2>(mCdmStops), testing::Return(wvcdm::NO_ERROR))); - - auto ret = - mPlugin->setPropertyString(std::string("appId"), std::string(app_id)); - EXPECT_TRUE(ret.isOk()); - - std::vector secureStops; - ret = mPlugin->getSecureStops(&secureStops); - EXPECT_TRUE(ret.isOk()); - - std::vector> stops; - for (const auto &stop : secureStops) { - stops.push_back(stop.opaqueData); - } - - size_t index = 0; - for (const auto &stop : stops) { - EXPECT_THAT(stop, ElementsAreArray(stopsRaw[index++], kStopSize)); - } - EXPECT_EQ(kStopCount, index); -} - -TEST_F(WVDrmPluginHalTest, ReleasesAllSecureStops) { - EXPECT_CALL(*mCdm, RemoveAllUsageInfo(StrEq(""), _)).Times(1); - - auto ret = mPlugin->setPropertyString(std::string("appId"), ""); - EXPECT_TRUE(ret.isOk()); - - ret = mPlugin->releaseAllSecureStops(); - EXPECT_TRUE(ret.isOk()); -} - -TEST_F(WVDrmPluginHalTest, ReleasesSecureStop) { - static const uint32_t kMessageSize = 128; - uint8_t messageRaw[kMessageSize]; - FILE *fp = fopen("/dev/urandom", "r"); - ASSERT_NE(fp, nullptr) << "Failed to open /dev/urandom"; - fread(messageRaw, sizeof(uint8_t), kMessageSize, fp); - fclose(fp); - - EXPECT_CALL(*mCdm, - ReleaseUsageInfo(ElementsAreArray(messageRaw, kMessageSize), _)) - .Times(1); - - SecureStopId stopId; - stopId.secureStopId.assign(messageRaw, messageRaw + kMessageSize); - auto ret = mPlugin->releaseSecureStop(stopId); - EXPECT_TRUE(ret.isOk()); -} - TEST_F(WVDrmPluginHalTest, ReturnsExpectedPropertyValues) { CdmQueryMap l1Map; l1Map[QUERY_KEY_SECURITY_LEVEL] = QUERY_VALUE_SECURITY_LEVEL_L1; diff --git a/libwvdrmengine/mediadrm/test/hidl/WVDrmPlugin_test.cpp b/libwvdrmengine/mediadrm/test/hidl/WVDrmPlugin_test.cpp index 527711bf..95215a9c 100644 --- a/libwvdrmengine/mediadrm/test/hidl/WVDrmPlugin_test.cpp +++ b/libwvdrmengine/mediadrm/test/hidl/WVDrmPlugin_test.cpp @@ -59,16 +59,6 @@ using ::testing::Values; using ::testing::WithParamInterface; using ::testing::internal::ElementsAreArrayMatcher; -using wvcdm::kCertificateWidevine; -using wvcdm::kKeyRequestTypeInitial; -using wvcdm::kKeyRequestTypeRelease; -using wvcdm::kKeyRequestTypeRenewal; -using wvcdm::kLicenseTypeOffline; -using wvcdm::kLicenseTypeRelease; -using wvcdm::kLicenseTypeStreaming; -using wvcdm::kSecurityLevelL1; -using wvcdm::kSecurityLevelL3; -using wvutil::Base64Encode; using wvcdm::CdmAppParameterMap; using wvcdm::CdmCertificateType; using wvcdm::CdmClientPropertySet; @@ -84,10 +74,7 @@ using wvcdm::CdmOfflineLicenseState; using wvcdm::CdmProvisioningRequest; using wvcdm::CdmProvisioningResponse; using wvcdm::CdmQueryMap; -using wvcdm::CdmSecureStopId; using wvcdm::CdmSecurityLevel; -using wvcdm::CdmUsageInfo; -using wvcdm::CdmUsageInfoReleaseMessage; using wvcdm::EMPTY_ORIGIN; using wvcdm::kCertificateWidevine; using wvcdm::KEY_ID_SIZE; @@ -121,6 +108,7 @@ using wvcdm::QUERY_VALUE_SECURITY_LEVEL_L1; using wvcdm::QUERY_VALUE_SECURITY_LEVEL_L3; using wvcdm::SESSION_ID_PREFIX; using wvcdm::WvCdmEventListener; +using wvutil::Base64Encode; namespace { const std::string kEmptyString; @@ -204,21 +192,6 @@ class MockCDM : public WvContentDecryptionModule { MOCK_METHOD(bool, IsProvisioned, (CdmSecurityLevel, const std::string&, const std::string&, bool), (override)); - MOCK_METHOD(CdmResponseType, GetUsageInfo, (const std::string&, - const CdmIdentifier&, - CdmUsageInfo*), (override)); - - MOCK_METHOD(CdmResponseType, GetUsageInfo, (const std::string&, - const CdmSecureStopId&, - const CdmIdentifier&, - CdmUsageInfo*), (override)); - - MOCK_METHOD(CdmResponseType, RemoveAllUsageInfo, (const std::string&, - const CdmIdentifier&), (override)); - - MOCK_METHOD(CdmResponseType, ReleaseUsageInfo, - (const CdmUsageInfoReleaseMessage&, const CdmIdentifier&), (override)); - MOCK_METHOD(bool, IsValidServiceCertificate, (const std::string&), (override)); MOCK_METHOD(CdmResponseType, GetMetrics, (const CdmIdentifier&, @@ -1144,96 +1117,6 @@ TEST_F(WVDrmPluginTest, RejectsAtscUnprovisionDeviceRequests) { ASSERT_EQ(Status::ERROR_DRM_CANNOT_HANDLE, status); } -TEST_F(WVDrmPluginTest, GetsSecureStops) { - android::sp> cdm = new StrictMock(); - StrictMock crypto; - std::string appPackageName; - - static const uint32_t kStopSize = 53; - static const uint32_t kStopCount = 7; - uint8_t stopsRaw[kStopCount][kStopSize]; - FILE* fp = fopen("/dev/urandom", "r"); - for (uint32_t i = 0; i < kStopCount; ++i) { - fread(stopsRaw[i], sizeof(uint8_t), kStopSize, fp); - } - fclose(fp); - - CdmUsageInfo cdmStops; - for (uint32_t i = 0; i < kStopCount; ++i) { - cdmStops.push_back(std::string(stopsRaw[i], stopsRaw[i] + kStopSize)); - } - - const char* app_id = "my_app_id"; - EXPECT_CALL(*cdm, GetUsageInfo(StrEq(app_id), _, _)) - .WillOnce( - DoAll(SetArgPointee<2>(cdmStops), testing::Return(wvcdm::NO_ERROR))); - - std::vector> stops; - - WVDrmPlugin plugin(cdm.get(), appPackageName, &crypto, false); - Status status = - plugin.setPropertyString(hidl_string("appId"), hidl_string(app_id)); - ASSERT_EQ(Status::OK, status); - - plugin.getSecureStops([&](Status status, hidl_vec hSecureStops) { - ASSERT_EQ(Status::OK, status); - - std::vector secureStops(hSecureStops); - std::vector::iterator iter = secureStops.begin(); - std::vector stop; - while (iter != secureStops.end()) { - stop = (*iter++).opaqueData; - stops.push_back(stop); - } - }); - - size_t index = 0; - for (auto stop : stops) { - EXPECT_THAT(stop, ElementsAreArray(stopsRaw[index++], kStopSize)); - } - EXPECT_EQ(kStopCount, index); -} - -TEST_F(WVDrmPluginTest, ReleasesAllSecureStops) { - android::sp> cdm = new StrictMock(); - StrictMock crypto; - std::string appPackageName; - - EXPECT_CALL(*cdm, RemoveAllUsageInfo(StrEq(""), _)).Times(1); - - WVDrmPlugin plugin(cdm.get(), appPackageName, &crypto, false); - - Status status = - plugin.setPropertyString(hidl_string("appId"), hidl_string("")); - ASSERT_EQ(Status::OK, status); - - status = plugin.releaseAllSecureStops(); - ASSERT_EQ(Status::OK, status); -} - -TEST_F(WVDrmPluginTest, ReleasesSecureStop) { - android::sp> cdm = new StrictMock(); - StrictMock crypto; - std::string appPackageName; - - static const uint32_t kMessageSize = 128; - uint8_t messageRaw[kMessageSize]; - FILE* fp = fopen("/dev/urandom", "r"); - fread(messageRaw, sizeof(uint8_t), kMessageSize, fp); - fclose(fp); - - std::vector message; - message.assign(messageRaw, messageRaw + kMessageSize); - - EXPECT_CALL(*cdm, - ReleaseUsageInfo(ElementsAreArray(messageRaw, kMessageSize), _)) - .Times(1); - - WVDrmPlugin plugin(cdm.get(), appPackageName, &crypto, false); - Status status = plugin.releaseSecureStop(toHidlVec(message)); - ASSERT_EQ(Status::OK, status); -} - TEST_F(WVDrmPluginTest, ReturnsExpectedPropertyValues) { android::sp> cdm = new StrictMock(); StrictMock crypto;