Merges to android Pi release (part 7)

These are a set of CLs merged from the wv cdm repo to the android repo.

* Resolve intermittent decrypt error.

  Author: Jeff Fore <jfore@google.com>

  [ Merge of http://go/wvgerrit/35720 ]

  The CdmSession's closed state was not properly
  initialized resulting in intermittent
  SESSION_NOT_FOUND_FOR_DECRYPT errors.

  In CdmEngine::Decrypt the session is looked up by
  the key id. A list of open sessions is acquired
  by calling CdmSessionMap::GetSessionList and each
  session in the list is queried to see if it has
  the key.

  In building the list in CdmSessionMap::GetSessionList,
  sessions are only added to the query list *if* the session
  is not closed.

  The closed status was not initialized and during testing
  the query list would not contain the session causing
  CdmEngine::Decrypt to return SESSION_NOT_FOUND_FOR_DECRYPT
  resulting in the ce cdm api returning widevine::Cdm::kNoKey.

* No support for pre- C++11 compilation.

  Author: Gene Morgan <gmorgan@google.com>

  [ Merge of http://go/wvgerrit/35381 ]

* Handle unaligned nonce pointer in RewrapDeviceRSAKey calls.

  Author: Gene Morgan <gmorgan@google.com>

  [ Merge of http://go/wvgerrit/35340 ]

  The pointer points into a message and it may not be aligned.
  Always copy the nonce into aligned memory before checking it.

  BUG: 38140370

  Add note to CHANGELOG for this.

* Compiler strictness: more checks and code cleanup.

  Author: Gene Morgan <gmorgan@google.com>

  [ Merge of http://go/wvgerrit/35300 ]

  Use the switches proposed in b/38033653 (as much as possible - some
  conflicts with protobufs and gtest prevent fully accepting them).

  Switch to clang for x32 build; ensure that both x86-64 and x86-32 builds
  compile and link cleanly.

  BUG: 38032429
  BUG: 38033653

  This partially resolves b/38458986

* Android build fixes

  Author: Rahul Frias <rfrias@google.com>

  [ Merge of http://go/wvgerrit/35102 ]

  These corrections address compile warnings and errors for android
  and unit tests.

* Embedded License: Add sub license key sessions.

  Author: Jeff Fore <jfore@google.com>

  [ Merge of http://go/wvgerrit/33680 ]

  NOTE: this adds the AddSubSession() method, but it is not yet being
  used. Use and proper cleanup is in an upcoming CL.

* Embedded license: Add track label field.

  Author: Jeff Fore <jfore@google.com>

  [ Merge of http://go/wvgerrit/33660 ]

  A new track label field (a string) is added to the key container and the
  sub session data objects.

  This field will be used in handling sub license requests.

* Embedded license: extract keys from init_data.

  Author: Jeff Fore <jfore@google.com>

  [ Merge of http://go/wvgerrit/33621 ]

* Embedded license: add protobuf messages.

  Author: Jeff Fore <jfore@google.com>

  [ Merge of http://go/wvgerrit/33620 ]

  also sync the widevine header definition with recent naming changes.

* Improve handling of provisioning response errors.

  Author: Gene Morgan <gmorgan@google.com>

  [ Merge of http://go/wvgerrit/33600 ]

  Separate out the case of no response and the case
  where the message is believed to be a JSON+base64
  message but it doesn't parse properly.

BUG: 71650075
Test: Not currently passing. Will be addressed in a subsequent
  commit in the chain.

Change-Id: I3c86f1c54980b071aec7461ac58541836551f896
This commit is contained in:
Rahul Frias
2018-01-09 23:36:42 -08:00
parent 00da44bb68
commit 80659961ac
38 changed files with 1249 additions and 360 deletions

View File

@@ -30,48 +30,6 @@ std::string g_provisioning_server;
std::string g_license_service_certificate;
std::string g_provisioning_service_certificate;
/*
* Locate the portion of the server's response message that is between
* the strings jason_start_substr and json_end_substr. Returns the string
* through *result. If the start substring match fails, assume the entire
* string represents a serialized protobuf mesaage and return true with
* the entire string. If the end_substring match fails, return false with
* an empty *result.
*/
bool ExtractSignedMessage(const std::string& response,
const std::string& json_start_substr,
const std::string& json_end_substr,
std::string* result) {
std::string b64_string;
size_t start = response.find(json_start_substr);
if (start == response.npos) {
// Assume web safe protobuf
b64_string.assign(response);
} else {
// Assume JSON-wrapped protobuf
size_t end = response.find(json_end_substr,
start + json_start_substr.length());
if (end == response.npos) {
LOGE("ExtractSignedMessage cannot locate end substring");
result->clear();
return false;
}
size_t b64_string_size = end - start - json_start_substr.length();
b64_string.assign(response, start + json_start_substr.length(),
b64_string_size);
}
if (b64_string.empty()) {
LOGE("Response message is empty");
result->clear();
return false;
}
result->swap(b64_string);
return true;
}
} // namespace
namespace wvcdm {
@@ -219,7 +177,7 @@ class WvGenericOperationsTest : public testing::Test {
protected:
virtual void Provision() {
LOGE("WvCdmEnginePreProvTest::Provision: url=%s",
LOGE("WvGenericOperationsTest::Provision: url=%s",
g_provisioning_server.c_str());
CdmProvisioningRequest prov_request;
std::string provisioning_server_url;
@@ -232,7 +190,7 @@ class WvGenericOperationsTest : public testing::Test {
cert_type, cert_authority, &prov_request,
&provisioning_server_url));
LOGV("WvCdmEnginePreProvTest::Provision: req=%s", prov_request.c_str());
LOGV("WvGenericOperationsTest::Provision: req=%s", prov_request.c_str());
// Ignore URL provided by CdmEngine. Use ours, as configured
// for test vs. production server.
@@ -244,13 +202,12 @@ class WvGenericOperationsTest : public testing::Test {
bool ok = url_request.GetResponse(&http_message);
EXPECT_TRUE(ok);
LOGV("WvCdmEnginePreProvTest::Provision: http_message: \n%s\n",
LOGV("WvGenericOperationsTest::Provision: http_message: \n%s\n",
http_message.c_str());
ASSERT_EQ(NO_ERROR,
cdm_engine_->HandleProvisioningResponse(http_message,
&cert, &wrapped_key));
ASSERT_EQ(NO_ERROR,
cdm_engine_->SetServiceCertificate(g_license_service_certificate));
}

View File

@@ -17,7 +17,7 @@
namespace wvcdm {
// Protobuf generated classes.
using video_widevine::WidevineCencHeader;
using video_widevine::WidevinePsshData;
namespace {
@@ -164,6 +164,19 @@ const std::string kZeroSizedPsshBox = a2bs_hex(
// data:
"08011a0d7769646576696e655f74657374220f73747265616d696e675f636c697031");
const std::string kSubLicensePsshBox = a2bs_hex(
// Widevine PSSH box
"0000009f" // atom size (whole buffer)
"70737368" // atom type="pssh"
"00000000" // v0, flags=0
"edef8ba979d64acea3c827dcd51d21ed" // system id (Widevine)
"0000007f" // data size
// data:
"0801120d746573745f6b65795f69645f30120d746573745f6b65795f69645f31220f"
"746573745f636f6e74656e745f69645a250a147375625f73657373696f6e5f6b6579"
"5f69645f30120d7375625f6c6963656e73655f305a250a147375625f73657373696f"
"6e5f6b65795f69645f31120d7375625f6c6963656e73655f31");
// HLS test attribute key and values
const std::string kHlsIvHexValue = "6DF49213A781E338628D0E9C812D328E";
const std::string kHlsIvValue = "0x" + kHlsIvHexValue;
@@ -353,7 +366,9 @@ struct HlsInitDataVariant {
HlsInitDataVariant(CdmHlsMethod method, const std::string& provider,
const std::string& content_id, const std::string& key_id,
bool success)
: method_(method), provider_(provider), content_id_(content_id),
: method_(method),
provider_(provider),
content_id_(content_id),
success_(success) {
if (key_id.size() > 0) key_ids_.push_back(key_id);
}
@@ -405,18 +420,42 @@ class HlsParseTest : public ::testing::TestWithParam<HlsAttributeVariant> {};
class HlsTest : public ::testing::Test {};
} // namespace
TEST_F(InitializationDataTest, BadType) {
InitializationData init_data("bad", kSubLicensePsshBox);
EXPECT_TRUE(init_data.IsEmpty());
}
TEST_P(InitializationDataTest, Parse) {
InitializationData init_data(ISO_BMFF_VIDEO_MIME_TYPE, GetParam());
EXPECT_FALSE(init_data.IsEmpty());
}
INSTANTIATE_TEST_CASE_P(ParsePssh, InitializationDataTest,
::testing::Values(kWidevinePssh, kWidevinePsshFirst,
kWidevinePsshAfterV0Pssh,
kWidevinePsshAfterNonZeroFlags,
kWidevinePsshAfterV1Pssh,
kWidevineV1Pssh, kOtherBoxFirst,
kZeroSizedPsshBox));
INSTANTIATE_TEST_CASE_P(
ParsePssh, InitializationDataTest,
::testing::Values(kWidevinePssh, kWidevinePsshFirst,
kWidevinePsshAfterV0Pssh, kWidevinePsshAfterNonZeroFlags,
kWidevinePsshAfterV1Pssh, kWidevineV1Pssh, kOtherBoxFirst,
kZeroSizedPsshBox, kSubLicensePsshBox));
TEST_F(InitializationDataTest, ExtractSubLicense) {
InitializationData init_data(ISO_BMFF_VIDEO_MIME_TYPE, kSubLicensePsshBox);
ASSERT_FALSE(init_data.IsEmpty());
std::vector<video_widevine::SubLicense> keys =
init_data.ExtractEmbeddedKeys();
ASSERT_EQ(keys.size(), 2UL);
EXPECT_EQ(keys[0].sub_session_key_id(), "sub_session_key_id_0");
EXPECT_EQ(keys[1].sub_session_key_id(), "sub_session_key_id_1");
EXPECT_EQ(keys[0].key_msg(), "sub_license_0");
EXPECT_EQ(keys[1].key_msg(), "sub_license_1");
}
TEST_F(InitializationDataTest, ExtractEmptySubLicense) {
InitializationData init_data(ISO_BMFF_VIDEO_MIME_TYPE, kWidevinePssh);
ASSERT_FALSE(init_data.IsEmpty());
std::vector<video_widevine::SubLicense> keys =
init_data.ExtractEmbeddedKeys();
ASSERT_TRUE(keys.empty());
}
TEST_P(HlsKeyFormatVersionsExtractionTest, ExtractKeyFormatVersions) {
std::vector<std::string> versions = GetParam();
@@ -598,9 +637,9 @@ TEST_P(HlsConstructionTest, InitData) {
EXPECT_EQ(param.success_, InitializationData::ConstructWidevineInitData(
param.method_, uri, &value));
if (param.success_) {
WidevineCencHeader cenc_header;
WidevinePsshData cenc_header;
EXPECT_TRUE(cenc_header.ParseFromString(value));
EXPECT_EQ(video_widevine::WidevineCencHeader_Algorithm_AESCTR,
EXPECT_EQ(video_widevine::WidevinePsshData_Algorithm_AESCTR,
cenc_header.algorithm());
for (size_t i = 0; i < param.key_ids_.size(); ++i) {
bool key_id_found = false;
@@ -620,9 +659,14 @@ TEST_P(HlsConstructionTest, InitData) {
cenc_header.content_id());
uint32_t protection_scheme = 0;
switch (param.method_) {
case kHlsMethodAes128: protection_scheme = kFourCcCbc1; break;
case kHlsMethodSampleAes: protection_scheme = kFourCcCbcs; break;
default: break;
case kHlsMethodAes128:
protection_scheme = kFourCcCbc1;
break;
case kHlsMethodSampleAes:
protection_scheme = kFourCcCbcs;
break;
default:
break;
}
EXPECT_EQ(protection_scheme, cenc_header.protection_scheme());
}
@@ -633,8 +677,8 @@ INSTANTIATE_TEST_CASE_P(
::testing::Values(
HlsInitDataVariant(kHlsMethodAes128, "", kHlsTestContentId,
kHlsTestKeyId1, false),
HlsInitDataVariant(kHlsMethodAes128, kHlsTestProvider,
"", kHlsTestKeyId1, false),
HlsInitDataVariant(kHlsMethodAes128, kHlsTestProvider, "",
kHlsTestKeyId1, false),
HlsInitDataVariant(kHlsMethodAes128, kHlsTestProvider,
kHlsTestContentId, "", false),
HlsInitDataVariant(kHlsMethodAes128, kHlsTestProvider,
@@ -699,9 +743,9 @@ TEST_P(HlsParseTest, Parse) {
EXPECT_EQ(kHlsMethodSampleAes, init_data.hls_method());
}
WidevineCencHeader cenc_header;
WidevinePsshData cenc_header;
EXPECT_TRUE(cenc_header.ParseFromString(init_data.data()));
EXPECT_EQ(video_widevine::WidevineCencHeader_Algorithm_AESCTR,
EXPECT_EQ(video_widevine::WidevinePsshData_Algorithm_AESCTR,
cenc_header.algorithm());
if (param.key_.compare(kJsonProvider) == 0) {
EXPECT_EQ(param.value_, cenc_header.provider());

View File

@@ -599,6 +599,128 @@ TEST_F(PolicyEngineTest, PlaybackOk_PlaybackAndRental0) {
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
}
TEST_F(PolicyEngineTest, PlaybackOk_PlaybackAndLicense0_WithoutPlayback) {
License_Policy* policy = license_.mutable_policy();
policy->clear_license_duration_seconds();
policy->clear_playback_duration_seconds();
// Only |rental_duration_seconds| set.
EXPECT_CALL(*mock_clock_, GetCurrentTime())
.WillOnce(Return(kLicenseStartTime + 1))
.WillOnce(Return(kLicenseStartTime + 10))
.WillOnce(Return(kLicenseStartTime + kRentalDuration - 10))
.WillOnce(Return(kLicenseStartTime + kRentalDuration + 10));
ExpectSessionKeysChange(kKeyStatusExpired, false);
ExpectSessionKeysChange(kKeyStatusUsable, true);
EXPECT_CALL(mock_event_listener_,
OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration));
policy_engine_->SetLicense(license_);
policy_engine_->OnTimerEvent();
EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
policy_engine_->OnTimerEvent();
EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
policy_engine_->OnTimerEvent();
EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
}
TEST_F(PolicyEngineTest, PlaybackOk_PlaybackAndLicense0_WithPlayback) {
License_Policy* policy = license_.mutable_policy();
policy->clear_license_duration_seconds();
policy->clear_playback_duration_seconds();
// Only |rental_duration_seconds| set.
EXPECT_CALL(*mock_clock_, GetCurrentTime())
.WillOnce(Return(kLicenseStartTime + 1))
.WillOnce(Return(kPlaybackStartTime))
.WillOnce(Return(kLicenseStartTime + 10))
.WillOnce(Return(kLicenseStartTime + kRentalDuration + 10));
ExpectSessionKeysChange(kKeyStatusUsable, true);
EXPECT_CALL(mock_event_listener_,
OnExpirationUpdate(_, 0));
EXPECT_CALL(mock_event_listener_,
OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration));
policy_engine_->SetLicense(license_);
policy_engine_->BeginDecryption();
policy_engine_->OnTimerEvent();
EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
policy_engine_->OnTimerEvent();
EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
}
TEST_F(PolicyEngineTest, PlaybackOk_RentalAndLicense0_WithoutPlayback) {
License_Policy* policy = license_.mutable_policy();
policy->clear_license_duration_seconds();
policy->clear_rental_duration_seconds();
// Only |playback_duration_seconds| set.
EXPECT_CALL(*mock_clock_, GetCurrentTime())
.WillOnce(Return(kLicenseStartTime + 1))
.WillOnce(Return(kLicenseStartTime + 10))
.WillOnce(Return(kLicenseStartTime + kPlaybackDuration + 10));
ExpectSessionKeysChange(kKeyStatusUsable, true);
EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, 0));
policy_engine_->SetLicense(license_);
policy_engine_->OnTimerEvent();
EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
policy_engine_->OnTimerEvent();
EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
}
TEST_F(PolicyEngineTest, PlaybackOk_RentalAndLicense0_WithPlayback) {
License_Policy* policy = license_.mutable_policy();
policy->clear_license_duration_seconds();
policy->clear_rental_duration_seconds();
// Only |playback_duration_seconds| set.
EXPECT_CALL(*mock_clock_, GetCurrentTime())
.WillOnce(Return(kLicenseStartTime + 1))
.WillOnce(Return(kPlaybackStartTime))
.WillOnce(Return(kPlaybackStartTime + kPlaybackDuration - 10))
.WillOnce(Return(kPlaybackStartTime + kPlaybackDuration + 10));
ExpectSessionKeysChange(kKeyStatusExpired, false);
ExpectSessionKeysChange(kKeyStatusUsable, true);
EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, 0));
EXPECT_CALL(mock_event_listener_,
OnExpirationUpdate(_, kPlaybackStartTime + kPlaybackDuration));
policy_engine_->SetLicense(license_);
policy_engine_->BeginDecryption();
policy_engine_->OnTimerEvent();
EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
policy_engine_->OnTimerEvent();
EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
}
TEST_F(PolicyEngineTest, PlaybackOk_Durations0) {
License_Policy* policy = license_.mutable_policy();
policy->set_rental_duration_seconds(kDurationUnlimited);
@@ -2188,6 +2310,303 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseDuration0) {
EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]);
}
TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackAndRental0) {
License_Policy* policy = license_.mutable_policy();
policy->set_rental_duration_seconds(kDurationUnlimited);
policy->set_playback_duration_seconds(kDurationUnlimited);
policy->set_license_duration_seconds(kLowDuration);
// Only |license_duration_seconds| set.
EXPECT_CALL(*mock_clock_, GetCurrentTime())
.WillOnce(Return(kLicenseStartTime + 1))
.WillOnce(Return(kPlaybackStartTime))
.WillOnce(Return(kLicenseStartTime + 10))
.WillOnce(Return(kLicenseStartTime + kLowDuration - 10))
.WillOnce(Return(kLicenseStartTime + kLowDuration + 10))
.WillOnce(Return(kLicenseStartTime + kLowDuration + 10));
policy_engine_->SetLicense(license_);
policy_engine_->BeginDecryption();
policy_engine_->OnTimerEvent();
EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
CdmQueryMap query_info;
EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info));
EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]);
EXPECT_EQ(10, ParseInt(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING]));
EXPECT_EQ(LLONG_MAX,
ParseInt(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING]));
EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]);
policy_engine_->OnTimerEvent();
EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info));
EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]);
EXPECT_EQ(0, ParseInt(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING]));
EXPECT_EQ(LLONG_MAX,
ParseInt(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING]));
EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]);
}
TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackAndLicense0_WithoutPlayback) {
License_Policy* policy = license_.mutable_policy();
policy->set_rental_duration_seconds(kRentalDuration);
policy->set_playback_duration_seconds(kDurationUnlimited);
policy->set_license_duration_seconds(kDurationUnlimited);
// Only |rental_duration_seconds| set.
EXPECT_CALL(*mock_clock_, GetCurrentTime())
.WillOnce(Return(kLicenseStartTime + 1))
.WillOnce(Return(kLicenseStartTime + 10))
.WillOnce(Return(kLicenseStartTime + kRentalDuration - 10))
.WillOnce(Return(kLicenseStartTime + kRentalDuration - 10))
.WillOnce(Return(kLicenseStartTime + kRentalDuration + 10))
.WillOnce(Return(kLicenseStartTime + kRentalDuration + 10));
policy_engine_->SetLicense(license_);
policy_engine_->OnTimerEvent();
EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
policy_engine_->OnTimerEvent();
EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
CdmQueryMap query_info;
EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info));
EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]);
EXPECT_EQ(10, ParseInt(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING]));
EXPECT_EQ(LLONG_MAX,
ParseInt(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING]));
EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]);
policy_engine_->OnTimerEvent();
EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info));
EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]);
EXPECT_EQ(0, ParseInt(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING]));
EXPECT_EQ(LLONG_MAX,
ParseInt(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING]));
EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]);
}
TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackAndLicense0_WithPlayback) {
License_Policy* policy = license_.mutable_policy();
policy->set_rental_duration_seconds(kRentalDuration);
policy->set_playback_duration_seconds(kDurationUnlimited);
policy->set_license_duration_seconds(kDurationUnlimited);
// Only |rental_duration_seconds| set.
EXPECT_CALL(*mock_clock_, GetCurrentTime())
.WillOnce(Return(kLicenseStartTime + 1))
.WillOnce(Return(kPlaybackStartTime))
.WillOnce(Return(kLicenseStartTime + kPlaybackDuration - 10))
.WillOnce(Return(kLicenseStartTime + kPlaybackDuration - 10))
.WillOnce(Return(kLicenseStartTime + kPlaybackDuration + 10))
.WillOnce(Return(kLicenseStartTime + kPlaybackDuration + 10))
.WillOnce(Return(kLicenseStartTime + kRentalDuration + 10))
.WillOnce(Return(kLicenseStartTime + kRentalDuration + 10));
policy_engine_->SetLicense(license_);
policy_engine_->BeginDecryption();
policy_engine_->OnTimerEvent();
EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
CdmQueryMap query_info;
EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info));
EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]);
EXPECT_EQ(kRentalDuration - kPlaybackDuration + 10,
ParseInt(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING]));
EXPECT_EQ(LLONG_MAX,
ParseInt(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING]));
EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]);
policy_engine_->OnTimerEvent();
EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info));
EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]);
EXPECT_EQ(kRentalDuration - kPlaybackDuration - 10,
ParseInt(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING]));
EXPECT_EQ(LLONG_MAX,
ParseInt(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING]));
EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]);
policy_engine_->OnTimerEvent();
EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info));
EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]);
EXPECT_EQ(0, ParseInt(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING]));
EXPECT_EQ(LLONG_MAX,
ParseInt(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING]));
EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]);
}
TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalAndLicense0_WithoutPlayback) {
License_Policy* policy = license_.mutable_policy();
policy->set_rental_duration_seconds(kDurationUnlimited);
policy->set_playback_duration_seconds(kPlaybackDuration);
policy->set_license_duration_seconds(kDurationUnlimited);
// Only |playback_duration_seconds| set.
EXPECT_CALL(*mock_clock_, GetCurrentTime())
.WillOnce(Return(kLicenseStartTime + 1))
.WillOnce(Return(kLicenseStartTime + 10))
.WillOnce(Return(kLicenseStartTime + 10))
.WillOnce(Return(kLicenseStartTime + kPlaybackDuration + 10))
.WillOnce(Return(kLicenseStartTime + kPlaybackDuration + 10));
policy_engine_->SetLicense(license_);
policy_engine_->OnTimerEvent();
EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
CdmQueryMap query_info;
EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info));
EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]);
EXPECT_EQ(LLONG_MAX,
ParseInt(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING]));
EXPECT_EQ(kPlaybackDuration,
ParseInt(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING]));
EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]);
policy_engine_->OnTimerEvent();
EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info));
EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]);
EXPECT_EQ(LLONG_MAX,
ParseInt(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING]));
EXPECT_EQ(kPlaybackDuration,
ParseInt(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING]));
EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]);
}
TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalAndLicense0_WithPlayback) {
License_Policy* policy = license_.mutable_policy();
policy->set_rental_duration_seconds(kDurationUnlimited);
policy->set_playback_duration_seconds(kPlaybackDuration);
policy->set_license_duration_seconds(kDurationUnlimited);
// Only |playback_duration_seconds| set.
EXPECT_CALL(*mock_clock_, GetCurrentTime())
.WillOnce(Return(kLicenseStartTime + 1))
.WillOnce(Return(kPlaybackStartTime))
.WillOnce(Return(kPlaybackStartTime + 10))
.WillOnce(Return(kPlaybackStartTime + 10))
.WillOnce(Return(kPlaybackStartTime + kPlaybackDuration - 10))
.WillOnce(Return(kPlaybackStartTime + kPlaybackDuration - 10))
.WillOnce(Return(kPlaybackStartTime + kPlaybackDuration + 10))
.WillOnce(Return(kPlaybackStartTime + kPlaybackDuration + 10));
policy_engine_->SetLicense(license_);
policy_engine_->BeginDecryption();
policy_engine_->OnTimerEvent();
EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
CdmQueryMap query_info;
EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info));
EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]);
EXPECT_EQ(LLONG_MAX,
ParseInt(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING]));
EXPECT_EQ(kPlaybackDuration - 10,
ParseInt(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING]));
EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]);
policy_engine_->OnTimerEvent();
EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info));
EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]);
EXPECT_EQ(LLONG_MAX,
ParseInt(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING]));
EXPECT_EQ(10,
ParseInt(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING]));
EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]);
policy_engine_->OnTimerEvent();
EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId));
EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId));
EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info));
EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]);
EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]);
EXPECT_EQ(0,
ParseInt(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING]));
EXPECT_EQ(0,
ParseInt(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING]));
EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]);
}
TEST_F(PolicyEngineQueryTest, QuerySuccess_Durations0) {
License_Policy* policy = license_.mutable_policy();
policy->set_rental_duration_seconds(kDurationUnlimited);

View File

@@ -50,6 +50,46 @@ const CdmUsageEntryInfo kUsageEntryInfoStorageTypeUnknown = {
.storage_type = kStorageTypeUnknown,
.key_set_id = "",
.usage_info_file_name = ""};
const std::vector<std::string> kEmptyLicenseList;
const std::vector<std::string> kLicenseList = {
kUsageEntryInfoOfflineLicense1.key_set_id,
kUsageEntryInfoOfflineLicense2.key_set_id,
kUsageEntryInfoOfflineLicense3.key_set_id,
};
const std::vector<std::string> kEmptyUsageInfoFilesList;
const std::vector<std::string> kUsageInfoFileList = {
kUsageEntryInfoSecureStop1.usage_info_file_name,
kUsageEntryInfoSecureStop2.usage_info_file_name,
kUsageEntryInfoSecureStop3.usage_info_file_name,
};
const DeviceFiles::CdmUsageData kCdmUsageData1 = {
.provider_session_token = "provider_session_token_1",
.license_request = "license_request_1",
.license = "license_1",
.key_set_id = "key_set_id_1",
.usage_entry = "usage_entry_1",
.usage_entry_number = 0,
};
const DeviceFiles::CdmUsageData kCdmUsageData2 = {
.provider_session_token = "provider_session_token_2",
.license_request = "license_request_2",
.license = "license_2",
.key_set_id = "key_set_id_2",
.usage_entry = "usage_entry_2",
.usage_entry_number = 0,
};
const DeviceFiles::CdmUsageData kCdmUsageData3 = {
.provider_session_token = "provider_session_token_3",
.license_request = "license_request_3",
.license = "license_3",
.key_set_id = "key_set_id_3",
.usage_entry = "usage_entry_3",
.usage_entry_number = 0,
};
const std::vector<DeviceFiles::CdmUsageData> kEmptyUsageInfoUsageDataList;
const std::vector<DeviceFiles::CdmUsageData> kUsageInfoUsageDataList = {
kCdmUsageData1, kCdmUsageData2, kCdmUsageData3,
};
const std::vector<CdmUsageEntryInfo> kEmptyUsageEntryInfoVector;
const std::vector<CdmUsageEntryInfo> kUsageEntryInfoVector = {
kUsageEntryInfoOfflineLicense1, kUsageEntryInfoSecureStop1,
@@ -82,12 +122,17 @@ class MockDeviceFiles : public DeviceFiles {
bool(const std::string&, const std::string&, std::string*,
CdmKeyMessage*, CdmKeyResponse*, CdmUsageEntry*,
uint32_t*));
MOCK_METHOD0(DeleteAllLicenses, bool());
MOCK_METHOD7(StoreUsageInfo,
bool(const std::string&, const CdmKeyMessage&,
const CdmKeyResponse&, const std::string&,
const std::string&, const CdmUsageEntry&, uint32_t));
MOCK_METHOD2(RetrieveUsageInfo,
bool(const std::string&, std::vector<CdmUsageData>*));
MOCK_METHOD1(ListLicenses,
bool(std::vector<std::string>* key_set_ids));
MOCK_METHOD1(ListUsageInfoFiles,
bool(std::vector<std::string>* usage_info_files));
private:
FileSystem file_system_;
@@ -170,18 +215,76 @@ class UsageTableHeaderInitializationTest
public ::testing::WithParamInterface<CdmSecurityLevel> {};
TEST_P(UsageTableHeaderInitializationTest, CreateUsageTableHeader) {
std::vector<CdmUsageEntryInfo> empty_usage_entry_info;
EXPECT_CALL(*device_files_, RetrieveUsageTableInfo(NotNull(), NotNull()))
.WillOnce(DoAll(SetArgPointee<0>(kEmptyUsageTableHeader),
SetArgPointee<1>(kEmptyUsageEntryInfoVector),
Return(false)));
EXPECT_CALL(*device_files_, ListLicenses(NotNull()))
.WillOnce(DoAll(SetArgPointee<0>(kEmptyLicenseList),
Return(false)));
EXPECT_CALL(*device_files_, ListUsageInfoFiles(NotNull()))
.WillOnce(DoAll(SetArgPointee<0>(kEmptyUsageInfoFilesList),
Return(false)));
EXPECT_CALL(*crypto_session_, CreateUsageTableHeader(NotNull()))
.WillOnce(
DoAll(SetArgPointee<0>(kEmptyUsageTableHeader), Return(NO_ERROR)));
EXPECT_CALL(*device_files_, StoreUsageTableInfo(kEmptyUsageTableHeader,
kEmptyUsageEntryInfoVector))
.WillOnce(Return(true));
.Times(2)
.WillRepeatedly(Return(true));
EXPECT_TRUE(usage_table_header_->Init(GetParam(), crypto_session_));
}
TEST_P(UsageTableHeaderInitializationTest, Upgrade_UnableToRetrieveLicenses) {
EXPECT_CALL(*device_files_, RetrieveUsageTableInfo(NotNull(), NotNull()))
.WillOnce(DoAll(SetArgPointee<0>(kEmptyUsageTableHeader),
SetArgPointee<1>(kEmptyUsageEntryInfoVector),
Return(false)));
EXPECT_CALL(*device_files_, ListLicenses(NotNull()))
.WillOnce(DoAll(SetArgPointee<0>(kLicenseList),
Return(true)));
EXPECT_CALL(*device_files_, ListUsageInfoFiles(NotNull()))
.WillOnce(DoAll(SetArgPointee<0>(kEmptyUsageInfoFilesList),
Return(false)));
EXPECT_CALL(*crypto_session_, CreateUsageTableHeader(NotNull()))
.WillOnce(
DoAll(SetArgPointee<0>(kEmptyUsageTableHeader), Return(NO_ERROR)));
EXPECT_CALL(*device_files_, DeleteAllLicenses()).WillOnce(Return(true));
EXPECT_CALL(*device_files_, StoreUsageTableInfo(kEmptyUsageTableHeader,
kEmptyUsageEntryInfoVector))
.Times(2)
.WillRepeatedly(Return(true));
for (size_t i = 0; i < kLicenseList.size(); ++i)
device_files_->DeleteLicense(kLicenseList[i]);
EXPECT_TRUE(usage_table_header_->Init(GetParam(), crypto_session_));
}
TEST_P(UsageTableHeaderInitializationTest, Upgrade_UnableToRetrieveUsageInfo) {
EXPECT_CALL(*device_files_, RetrieveUsageTableInfo(NotNull(), NotNull()))
.WillOnce(DoAll(SetArgPointee<0>(kEmptyUsageTableHeader),
SetArgPointee<1>(kEmptyUsageEntryInfoVector),
Return(false)));
EXPECT_CALL(*device_files_, ListLicenses(NotNull()))
.WillOnce(DoAll(SetArgPointee<0>(kEmptyLicenseList),
Return(false)));
EXPECT_CALL(*device_files_, ListUsageInfoFiles(NotNull()))
.WillOnce(DoAll(SetArgPointee<0>(kUsageInfoFileList),
Return(true)));
EXPECT_CALL(*crypto_session_, CreateUsageTableHeader(NotNull()))
.WillOnce(
DoAll(SetArgPointee<0>(kEmptyUsageTableHeader), Return(NO_ERROR)));
EXPECT_CALL(*device_files_, StoreUsageTableInfo(kEmptyUsageTableHeader,
kEmptyUsageEntryInfoVector))
.Times(2)
.WillRepeatedly(Return(true));
for (size_t i = 0; i < kUsageInfoFileList.size(); ++i) {
EXPECT_CALL(*device_files_,
RetrieveUsageInfo(kUsageInfoFileList[i], NotNull()))
.WillOnce(DoAll(SetArgPointee<1>(kEmptyUsageInfoUsageDataList),
Return(false)));
}
EXPECT_TRUE(usage_table_header_->Init(GetParam(), crypto_session_));
}
@@ -560,7 +663,6 @@ TEST_F(UsageTableHeaderTest,
usage_entry_info_vector.size() - 3; // kUsageEntryInfoOfflineLicense1
metrics::CryptoMetrics metrics;
device_files_->DeleteAllLicenses();
EXPECT_CALL(*crypto_session_, Open(kLevelDefault)).WillOnce(Return(NO_ERROR));
EXPECT_CALL(
*crypto_session_,
@@ -1558,4 +1660,27 @@ TEST_F(UsageTableHeaderTest, DeleteEntry_LastEntriesAreSecureStopAndUnknknown) {
device_files_, &metrics));
}
// If the crypto session says the usage table header is stale, init should fail.
TEST_F(UsageTableHeaderTest, StaleHeader) {
const std::vector<CdmUsageEntryInfo> usage_entry_info_vector = {
kUsageEntryInfoOfflineLicense1, kUsageEntryInfoSecureStop1,
kUsageEntryInfoStorageTypeUnknown, kUsageEntryInfoOfflineLicense2};
EXPECT_CALL(*device_files_, RetrieveUsageTableInfo(NotNull(), NotNull()))
.WillOnce(DoAll(SetArgPointee<0>(kUsageTableHeader),
SetArgPointee<1>(usage_entry_info_vector),
Return(true)));
EXPECT_CALL(*crypto_session_, LoadUsageTableHeader(kUsageTableHeader))
.WillOnce(Return(LOAD_USAGE_HEADER_GENERATION_SKEW));
EXPECT_CALL(*crypto_session_, CreateUsageTableHeader(NotNull()))
.WillOnce(
DoAll(SetArgPointee<0>(kEmptyUsageTableHeader), Return(NO_ERROR)));
EXPECT_CALL(*device_files_, DeleteAllLicenses()).WillOnce(Return(true));
EXPECT_CALL(*device_files_, StoreUsageTableInfo(kEmptyUsageTableHeader,
kEmptyUsageEntryInfoVector))
.WillOnce(Return(true));
EXPECT_TRUE(usage_table_header_->Init(kSecurityLevelL1, crypto_session_));
}
} // namespace wvcdm