Update secure stops by key set ID.

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

Previously, when updating a secure stop / usage info record, the
existing record was identified by PST.  It was assumed that apps would
never use the same PST for different licenses; however, this was never
enforced.  Certain GTS tests use the same PST across multiple tests to
identify different licenses.  Depending on the order of operations,
the periodic updating of the usage entry might overwrite the wrong
entry.

Key set IDs are generated by the CDM, and are guaranteed to be unique
within the scope of the same file system.  Given that key set IDs are
not expected to be transfered to different licenses, using the key
set ID to identify secure stop / usage info records eliminates the
possibility of overwriting the wrong entry.

Bug: 263316107
Test: device_files_unittest
Test: GTS MediaDrmParameterizedTests and MediaDrmStressTest
Change-Id: I2e2d50d188e05c8ca6b8095549796b913ea72d7a
This commit is contained in:
Alex Dale
2023-02-01 15:33:13 -08:00
parent 659301abd3
commit 5ae1d0fa6e
4 changed files with 901 additions and 241 deletions

View File

@@ -262,7 +262,6 @@ class DeviceFiles {
virtual bool StoreUsageInfo(const std::string& usage_info_file_name,
const std::vector<CdmUsageData>& usage_data);
virtual bool UpdateUsageInfo(const std::string& usage_info_file_name,
const std::string& provider_session_token,
const CdmUsageData& usage_data);
virtual bool StoreHlsAttributes(const std::string& key_set_id,

View File

@@ -1159,8 +1159,7 @@ bool CdmSession::UpdateUsageInfo() {
usage_data.usage_entry_index = usage_entry_index_;
return file_handle_->UpdateUsageInfo(
DeviceFiles::GetUsageInfoFileName(app_id), usage_provider_session_token_,
usage_data);
DeviceFiles::GetUsageInfoFileName(app_id), usage_data);
}
void CdmSession::UpdateRequestLatencyTiming(CdmResponseType sts) {

View File

@@ -1379,7 +1379,6 @@ bool DeviceFiles::StoreUsageInfo(const std::string& usage_info_file_name,
}
bool DeviceFiles::UpdateUsageInfo(const std::string& usage_info_file_name,
const std::string& provider_session_token,
const CdmUsageData& usage_data) {
RETURN_FALSE_IF_UNINITIALIZED();
@@ -1388,43 +1387,52 @@ bool DeviceFiles::UpdateUsageInfo(const std::string& usage_info_file_name,
LOGE("Usage info file does not exist");
return false;
}
if (RetrieveHashedFile(usage_info_file_name, &file) != kNoError) {
LOGE("Unable to retrieve usage info file");
return false;
}
video_widevine_client::sdk::UsageInfo* usage_info = file.mutable_usage_info();
int index = 0;
for (; index < file.usage_info().sessions_size(); ++index) {
if (file.usage_info().sessions(index).token() == provider_session_token) {
UsageInfo* usage_info = file.mutable_usage_info();
UsageInfo_ProviderSession* provider_session =
usage_info->mutable_sessions(index);
provider_session->set_license_request(usage_data.license_request);
provider_session->set_license(usage_data.license);
provider_session->set_key_set_id(usage_data.key_set_id);
provider_session->set_usage_entry(usage_data.usage_entry);
provider_session->set_usage_entry_index(usage_data.usage_entry_index);
if (usage_data.drm_certificate.size() > 0) {
uint32_t drm_certificate_id;
if (!FindOrInsertUsageCertificate(usage_data.drm_certificate,
usage_data.wrapped_private_key,
usage_info, &drm_certificate_id)) {
LOGE("Unable to find a certificate in to update the usage info");
return false;
}
provider_session->set_drm_certificate_id(drm_certificate_id);
}
std::string serialized_file;
file.SerializeToString(&serialized_file);
return StoreFileWithHash(usage_info_file_name, serialized_file) ==
kNoError;
}
for (; index < usage_info->sessions_size(); ++index) {
// Use key set ID to identify usage info. PST is not guaranteed
// to be unique.
if (usage_info->sessions(index).key_set_id() == usage_data.key_set_id)
break;
}
if (index == usage_info->sessions_size()) {
LOGE("Failed to find usage info: key_set_id = %s",
IdToString(usage_data.key_set_id));
return false;
}
return false;
video_widevine_client::sdk::UsageInfo::ProviderSession* session =
usage_info->mutable_sessions(index);
// Verify that the PST are the same.
if (session->token() != usage_data.provider_session_token) {
LOGE("Mismatch PST: key_set_id = %s", IdToString(usage_data.key_set_id));
return false;
}
// Update session.
session->set_license_request(usage_data.license_request);
session->set_license(usage_data.license);
session->set_usage_entry(usage_data.usage_entry);
session->set_usage_entry_index(usage_data.usage_entry_index);
if (usage_data.drm_certificate.size() > 0) {
uint32_t drm_certificate_id;
if (!FindOrInsertUsageCertificate(usage_data.drm_certificate,
usage_data.wrapped_private_key,
usage_info, &drm_certificate_id)) {
LOGE("Unable to find a certificate in to update the usage info");
return false;
}
session->set_drm_certificate_id(drm_certificate_id);
}
std::string serialized_file;
file.SerializeToString(&serialized_file);
return StoreFileWithHash(usage_info_file_name, serialized_file) == kNoError;
}
bool DeviceFiles::RetrieveUsageInfo(const std::string& usage_info_file_name,

File diff suppressed because it is too large Load Diff