Revise usage entry metadata

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

In OEMCrypto V13, usage table header and usage entries are stored in
persistent non-secure storage and loaded and unloaded from the TEE.
Information needs to be maintained to assist finding the associated license
or usage information. This information has been revised for usage information
to use key set id and usage info file name rather than provider session
token and app id.

The app id is stored in a hashed form (usage info file name) and was not
extractable during the upgrade process to OEMCrypto V13. Due to this
DeviceFiles UsageInfo routines have switched to use usage info file name
rather than app id as a key.

b/34327459

Test: Verified by unit/integration tests on angler
Change-Id: I95aa0435d0955c61fc45b951f5b5d44de2ba5cfc
This commit is contained in:
Rahul Frias
2017-02-07 10:41:02 -08:00
parent b384408dd2
commit e75d3a6512
9 changed files with 279 additions and 153 deletions

View File

@@ -29,17 +29,13 @@ class DeviceFiles {
kLicenseStateUnknown,
} LicenseState;
typedef enum {
kStorageLicense, // persistent license
kStorageUsageInfo, // secure stop
} UsageEntryStorage;
struct UsageEntryInfo {
UsageEntryStorage storage_type;
std::string key_set_id; // used when storage_type is kStorageLicense
std::string
provider_session_token; // used when storage_type is kStorageUsageInfo
std::string app_id; // used when storage_type is kStorageUsageInfo
struct CdmUsageData {
std::string provider_session_token;
CdmKeyMessage license_request;
CdmKeyResponse license;
std::string key_set_id;
CdmUsageEntry usage_entry;
uint32_t usage_entry_number;
};
DeviceFiles(FileSystem*);
@@ -87,28 +83,40 @@ class DeviceFiles {
virtual bool ReserveLicenseId(const std::string& key_set_id);
virtual bool UnreserveLicenseId(const std::string& key_set_id);
// Use this method to create a |usage_info_file_name| from an |app_id|
static std::string GetUsageInfoFileName(const std::string& app_id);
// The UsageInfo methods have been revised to use |usage_info_file_name|
// rather than |app_id| as a parameter. Use the helper method above to
// translate.
// OEMCrypto API 13 introduced big usage tables which required
// migration from usage tables stored by the TEE to usage table
// header+usage entries stored in unsecured persistent storage. The upgrade
// required creation of reverse lookup tables (CdmUsageEntryInfo).
// |app_id| however was hashed and unextractable, and necessitated the
// switch to |usage_info_file_name|
virtual bool StoreUsageInfo(const std::string& provider_session_token,
const CdmKeyMessage& key_request,
const CdmKeyResponse& key_response,
const std::string& app_id,
const std::string& usage_info_file_name,
const std::string& key_set_id,
const CdmUsageEntry& usage_entry,
uint32_t usage_entry_number);
virtual bool DeleteUsageInfo(const std::string& app_id,
virtual bool DeleteUsageInfo(const std::string& usage_info_file_name,
const std::string& provider_session_token);
// Delete usage information from the file system. Puts a list of all the
// psts that were deleted from the file into |provider_session_tokens|.
virtual bool DeleteAllUsageInfoForApp(
const std::string& app_id,
const std::string& usage_info_file_name,
std::vector<std::string>* provider_session_tokens);
// Retrieve one usage info from the file. Subsequent calls will retrieve
// subsequent entries in the table for this app_id.
virtual bool RetrieveUsageInfo(
const std::string& app_id,
const std::string& usage_info_file_name,
std::vector<std::pair<CdmKeyMessage, CdmKeyResponse> >* usage_info);
// Retrieve the usage info entry specified by |provider_session_token|.
// Returns false if the entry could not be found.
virtual bool RetrieveUsageInfo(const std::string& app_id,
virtual bool RetrieveUsageInfo(const std::string& usage_info_file_name,
const std::string& provider_session_token,
CdmKeyMessage* license_request,
CdmKeyResponse* license_response,
@@ -116,13 +124,25 @@ class DeviceFiles {
uint32_t* usage_entry_number);
// Retrieve the usage info entry specified by |key_set_id|.
// Returns false if the entry could not be found.
virtual bool RetrieveUsageInfoByKeySetId(const std::string& app_id,
const std::string& key_set_id,
std::string* provider_session_token,
CdmKeyMessage* license_request,
CdmKeyResponse* license_response,
CdmUsageEntry* usage_entry,
uint32_t* usage_entry_number);
virtual bool RetrieveUsageInfoByKeySetId(
const std::string& usage_info_file_name,
const std::string& key_set_id,
std::string* provider_session_token,
CdmKeyMessage* license_request,
CdmKeyResponse* license_response,
CdmUsageEntry* usage_entry,
uint32_t* usage_entry_number);
// These APIs support upgrading from usage tables to usage tabler header +
// entries introduced in OEMCrypto V13.
virtual bool ListUsageInfoFiles(std::vector<std::string>* usage_file_names);
virtual bool RetrieveUsageInfo(const std::string& usage_info_file_name,
std::vector<CdmUsageData>* usage_data);
// This method overwrites rather than appends data to the usage file
virtual bool StoreUsageInfo(const std::string& usage_info_file_name,
const std::vector<CdmUsageData>& usage_data);
virtual bool StoreHlsAttributes(const std::string& key_set_id,
const CdmHlsMethod method,
@@ -134,11 +154,11 @@ class DeviceFiles {
virtual bool StoreUsageTableInfo(
const CdmUsageTableHeader& usage_table_header,
const std::vector<UsageEntryInfo>& usage_entry_info);
const std::vector<CdmUsageEntryInfo>& usage_entry_info);
virtual bool RetrieveUsageTableInfo(
CdmUsageTableHeader* usage_table_header,
std::vector<UsageEntryInfo>* usage_entry_info);
std::vector<CdmUsageEntryInfo>* usage_entry_info);
private:
// Helpers that wrap the File interface and automatically handle hashing, as
@@ -157,7 +177,6 @@ class DeviceFiles {
static std::string GetCertificateFileName();
static std::string GetHlsAttributesFileNameExtension();
static std::string GetLicenseFileNameExtension();
static std::string GetUsageInfoFileName(const std::string& app_id);
static std::string GetUsageTableFileName();
static std::string GetFileNameSafeHash(const std::string& input);

View File

@@ -364,6 +364,18 @@ enum CdmUsageSupportType {
kUsageEntrySupport,
};
enum CdmUsageEntryStorageType {
kStorageLicense,
kStorageUsageInfo,
kStorageUnknown,
};
struct CdmUsageEntryInfo {
CdmUsageEntryStorageType storage_type;
CdmKeySetId key_set_id;
std::string usage_info_file_name;
};
class CdmKeyAllowedUsage {
public:
CdmKeyAllowedUsage() {

View File

@@ -1056,7 +1056,8 @@ CdmResponseType CdmEngine::GetUsageInfo(const std::string& app_id,
CdmKeyResponse license_response;
std::string usage_entry;
uint32_t usage_entry_number = 0;
if (!handle.RetrieveUsageInfo(app_id, ssid, &license_request,
if (!handle.RetrieveUsageInfo(DeviceFiles::GetUsageInfoFileName(app_id),
ssid, &license_request,
&license_response, &usage_entry,
&usage_entry_number)) {
usage_property_set_->set_security_level(kLevel3);
@@ -1071,7 +1072,8 @@ CdmResponseType CdmEngine::GetUsageInfo(const std::string& app_id,
LOGE("CdmEngine::GetUsageInfo: device file init error");
return GET_USAGE_INFO_ERROR_2;
}
if (!handle.RetrieveUsageInfo(app_id, ssid, &license_request,
if (!handle.RetrieveUsageInfo(DeviceFiles::GetUsageInfoFileName(app_id),
ssid, &license_request,
&license_response, &usage_entry,
&usage_entry_number)) {
// No entry found for that ssid.
@@ -1151,7 +1153,8 @@ CdmResponseType CdmEngine::GetUsageInfo(const std::string& app_id,
}
std::vector<std::pair<CdmKeyMessage, CdmKeyResponse> > license_info;
if (!handle.RetrieveUsageInfo(app_id, &license_info)) {
if (!handle.RetrieveUsageInfo(DeviceFiles::GetUsageInfoFileName(app_id),
&license_info)) {
LOGE("CdmEngine::GetUsageInfo: unable to read usage information");
return GET_USAGE_INFO_ERROR_4;
}
@@ -1210,7 +1213,9 @@ CdmResponseType CdmEngine::ReleaseAllUsageInfo(const std::string& app_id) {
DeviceFiles handle(file_system_);
if (handle.Init(static_cast<CdmSecurityLevel>(j))) {
std::vector<std::string> provider_session_tokens;
if (!handle.DeleteAllUsageInfoForApp(app_id, &provider_session_tokens)) {
if (!handle.DeleteAllUsageInfoForApp(
DeviceFiles::GetUsageInfoFileName(app_id),
&provider_session_tokens)) {
LOGE("CdmEngine::ReleaseAllUsageInfo: failed to delete L%d secure"
"stops", j);
status = RELEASE_ALL_USAGE_INFO_ERROR_1;
@@ -1291,10 +1296,10 @@ CdmResponseType CdmEngine::LoadUsageSession(const CdmKeySetId& key_set_id,
CdmKeyResponse key_response;
std::string usage_entry;
uint32_t usage_entry_number = 0;
if (!handle.RetrieveUsageInfoByKeySetId(app_id, key_set_id,
&provider_session_token, &key_message,
&key_response, &usage_entry,
&usage_entry_number)) {
if (!handle.RetrieveUsageInfoByKeySetId(
DeviceFiles::GetUsageInfoFileName(app_id), key_set_id,
&provider_session_token, &key_message, &key_response,
&usage_entry, &usage_entry_number)) {
LOGE("CdmEngine::LoadUsageSession: unable to find usage information");
return LOAD_USAGE_INFO_MISSING;
}

View File

@@ -627,8 +627,10 @@ CdmResponseType CdmSession::StoreLicense() {
std::string usage_entry;
uint32_t usage_entry_number = 0;
if (!file_handle_->StoreUsageInfo(provider_session_token, key_request_,
key_response_, app_id, key_set_id_,
usage_entry, usage_entry_number)) {
key_response_,
DeviceFiles::GetUsageInfoFileName(app_id),
key_set_id_, usage_entry,
usage_entry_number)) {
LOGE("CdmSession::StoreLicense: Unable to store usage info");
return STORE_USAGE_INFO_ERROR;
}
@@ -666,7 +668,8 @@ bool CdmSession::DeleteLicense() {
std::string app_id;
GetApplicationId(&app_id);
return file_handle_->DeleteUsageInfo(
app_id, license_parser_->provider_session_token());
DeviceFiles::GetUsageInfoFileName(app_id),
license_parser_->provider_session_token());
}
}

View File

@@ -40,6 +40,8 @@ using video_widevine_client::sdk::
UsageTableInfo_UsageEntryInfo_UsageEntryStorage_LICENSE;
using video_widevine_client::sdk::
UsageTableInfo_UsageEntryInfo_UsageEntryStorage_USAGE_INFO;
using video_widevine_client::sdk::
UsageTableInfo_UsageEntryInfo_UsageEntryStorage_UNKNOWN;
namespace {
@@ -386,7 +388,7 @@ bool DeviceFiles::UnreserveLicenseId(const std::string& key_set_id) {
bool DeviceFiles::StoreUsageInfo(const std::string& provider_session_token,
const CdmKeyMessage& key_request,
const CdmKeyResponse& key_response,
const std::string& app_id,
const std::string& usage_info_file_name,
const std::string& key_set_id,
const std::string& usage_entry,
uint32_t usage_entry_number) {
@@ -396,12 +398,11 @@ bool DeviceFiles::StoreUsageInfo(const std::string& provider_session_token,
}
video_widevine_client::sdk::File file;
std::string file_name = GetUsageInfoFileName(app_id);
if (!FileExists(file_name)) {
if (!FileExists(usage_info_file_name)) {
file.set_type(video_widevine_client::sdk::File::USAGE_INFO);
file.set_version(video_widevine_client::sdk::File::VERSION_1);
} else {
if (!RetrieveHashedFile(file_name, &file)) {
if (!RetrieveHashedFile(usage_info_file_name, &file)) {
LOGW("DeviceFiles::StoreUsageInfo: Unable to parse file");
return false;
}
@@ -420,18 +421,17 @@ bool DeviceFiles::StoreUsageInfo(const std::string& provider_session_token,
std::string serialized_file;
file.SerializeToString(&serialized_file);
return StoreFileWithHash(file_name, serialized_file);
return StoreFileWithHash(usage_info_file_name, serialized_file);
}
bool DeviceFiles::DeleteUsageInfo(const std::string& app_id,
bool DeviceFiles::DeleteUsageInfo(const std::string& usage_info_file_name,
const std::string& provider_session_token) {
if (!initialized_) {
LOGW("DeviceFiles::DeleteUsageInfo: not initialized");
return false;
}
video_widevine_client::sdk::File file;
std::string file_name = GetUsageInfoFileName(app_id);
if (!RetrieveHashedFile(file_name, &file)) return false;
if (!RetrieveHashedFile(usage_info_file_name, &file)) return false;
UsageInfo* usage_info = file.mutable_usage_info();
int index = 0;
@@ -460,11 +460,11 @@ bool DeviceFiles::DeleteUsageInfo(const std::string& app_id,
std::string serialized_file;
file.SerializeToString(&serialized_file);
return StoreFileWithHash(file_name, serialized_file);
return StoreFileWithHash(usage_info_file_name, serialized_file);
}
bool DeviceFiles::DeleteAllUsageInfoForApp(
const std::string& app_id,
const std::string& usage_info_file_name,
std::vector<std::string>* provider_session_tokens) {
if (!initialized_) {
LOGW("DeviceFiles::DeleteAllUsageInfoForApp: not initialized");
@@ -476,22 +476,21 @@ bool DeviceFiles::DeleteAllUsageInfoForApp(
}
provider_session_tokens->clear();
std::string file_name = GetUsageInfoFileName(app_id);
if (!FileExists(file_name)) return true;
if (!FileExists(usage_info_file_name)) return true;
video_widevine_client::sdk::File file;
if (RetrieveHashedFile(file_name, &file)) {
if (RetrieveHashedFile(usage_info_file_name, &file)) {
for (int i = 0; i < file.usage_info().sessions_size(); ++i) {
provider_session_tokens->push_back(file.usage_info().sessions(i).token());
}
} else {
LOGW("DeviceFiles::DeleteAllUsageInfoForApp: Unable to retrieve file");
}
return RemoveFile(file_name);
return RemoveFile(usage_info_file_name);
}
bool DeviceFiles::RetrieveUsageInfo(
const std::string& app_id,
const std::string& usage_info_file_name,
std::vector<std::pair<CdmKeyMessage, CdmKeyResponse> >* usage_info) {
if (!initialized_) {
LOGW("DeviceFiles::RetrieveUsageInfo: not initialized");
@@ -505,14 +504,14 @@ bool DeviceFiles::RetrieveUsageInfo(
return false;
}
std::string file_name = GetUsageInfoFileName(app_id);
if (!FileExists(file_name) || GetFileSize(file_name) == 0) {
if (!FileExists(usage_info_file_name) ||
GetFileSize(usage_info_file_name) == 0) {
usage_info->resize(0);
return true;
}
video_widevine_client::sdk::File file;
if (!RetrieveHashedFile(file_name, &file)) {
if (!RetrieveHashedFile(usage_info_file_name, &file)) {
LOGW("DeviceFiles::RetrieveUsageInfo: Unable to parse file");
return false;
}
@@ -527,7 +526,7 @@ bool DeviceFiles::RetrieveUsageInfo(
return true;
}
bool DeviceFiles::RetrieveUsageInfo(const std::string& app_id,
bool DeviceFiles::RetrieveUsageInfo(const std::string& usage_info_file_name,
const std::string& provider_session_token,
CdmKeyMessage* license_request,
CdmKeyResponse* license_response,
@@ -538,9 +537,8 @@ bool DeviceFiles::RetrieveUsageInfo(const std::string& app_id,
return false;
}
std::string file_name = GetUsageInfoFileName(app_id);
video_widevine_client::sdk::File file;
if (!RetrieveHashedFile(file_name, &file)) {
if (!RetrieveHashedFile(usage_info_file_name, &file)) {
return false;
}
@@ -560,7 +558,7 @@ bool DeviceFiles::RetrieveUsageInfo(const std::string& app_id,
}
bool DeviceFiles::RetrieveUsageInfoByKeySetId(
const std::string& app_id,
const std::string& usage_info_file_name,
const std::string& key_set_id,
std::string* provider_session_token,
CdmKeyMessage* license_request,
@@ -572,9 +570,8 @@ bool DeviceFiles::RetrieveUsageInfoByKeySetId(
return false;
}
std::string file_name = GetUsageInfoFileName(app_id);
video_widevine_client::sdk::File file;
if (!RetrieveHashedFile(file_name, &file)) {
if (!RetrieveHashedFile(usage_info_file_name, &file)) {
return false;
}
@@ -594,6 +591,97 @@ bool DeviceFiles::RetrieveUsageInfoByKeySetId(
return false;
}
bool DeviceFiles::StoreUsageInfo(const std::string& usage_info_file_name,
const std::vector<CdmUsageData>& usage_data) {
if (!initialized_) {
LOGW("DeviceFiles::StoreUsageInfo: not initialized");
return false;
}
video_widevine_client::sdk::File file;
file.set_type(video_widevine_client::sdk::File::USAGE_INFO);
file.set_version(video_widevine_client::sdk::File::VERSION_1);
UsageInfo* usage_info = file.mutable_usage_info();
for (size_t i = 0; i < usage_data.size(); ++i) {
UsageInfo_ProviderSession* provider_session = usage_info->add_sessions();
provider_session->set_token(usage_data[i].provider_session_token.data(),
usage_data[i].provider_session_token.size());
provider_session->set_license_request(usage_data[i].license_request.data(),
usage_data[i].license_request.size());
provider_session->set_license(usage_data[i].license.data(),
usage_data[i].license.size());
provider_session->set_key_set_id(usage_data[i].key_set_id.data(),
usage_data[i].key_set_id.size());
provider_session->set_usage_entry(usage_data[i].usage_entry);
provider_session->set_usage_entry_number(usage_data[i].usage_entry_number);
}
std::string serialized_file;
file.SerializeToString(&serialized_file);
return StoreFileWithHash(usage_info_file_name, serialized_file);
}
bool DeviceFiles::RetrieveUsageInfo(const std::string& usage_info_file_name,
std::vector<CdmUsageData>* usage_data) {
if (!initialized_) {
LOGW("DeviceFiles::RetrieveUsageInfo: not initialized");
return false;
}
video_widevine_client::sdk::File file;
if (!RetrieveHashedFile(usage_info_file_name, &file)) {
return false;
}
usage_data->resize(file.usage_info().sessions_size());
for (int i = 0; i < file.usage_info().sessions_size(); ++i) {
(*usage_data)[i].provider_session_token =
file.usage_info().sessions(i).token();
(*usage_data)[i].license_request =
file.usage_info().sessions(i).license_request();
(*usage_data)[i].license = file.usage_info().sessions(i).license();
(*usage_data)[i].key_set_id = file.usage_info().sessions(i).key_set_id();
(*usage_data)[i].usage_entry = file.usage_info().sessions(i).usage_entry();
(*usage_data)[i].usage_entry_number =
file.usage_info().sessions(i).usage_entry_number();
}
return false;
}
bool DeviceFiles::ListUsageInfoFiles(
std::vector<std::string>* usage_info_file_names) {
if (!initialized_) {
LOGW("DeviceFiles::ListUsageInfoFiles: not initialized");
return false;
}
// Get list of filenames
std::vector<std::string> filenames;
if (!ListFiles(&filenames)) {
return false;
}
// Scan list of all filenames and return only usage info filenames
usage_info_file_names->clear();
for (size_t i = 0; i < filenames.size(); i++) {
std::string* name = &filenames[i];
std::size_t pos_prefix = name->find(kUsageInfoFileNamePrefix);
std::size_t pos_suffix = name->find(kUsageInfoFileNameExt);
if (pos_prefix == std::string::npos ||
pos_suffix == std::string::npos) {
// Skip this file - extension does not match
continue;
}
usage_info_file_names->push_back(*name);
}
return true;
}
bool DeviceFiles::StoreHlsAttributes(
const std::string& key_set_id, const CdmHlsMethod method,
const std::vector<uint8_t>& media_segment_iv) {
@@ -693,7 +781,7 @@ bool DeviceFiles::DeleteHlsAttributes(const std::string& key_set_id) {
bool DeviceFiles::StoreUsageTableInfo(
const CdmUsageTableHeader& usage_table_header,
const std::vector<DeviceFiles::UsageEntryInfo>& usage_entry_info) {
const std::vector<CdmUsageEntryInfo>& usage_entry_info) {
if (!initialized_) {
LOGW("DeviceFiles::StoreUsageTableHeader: not initialized");
return false;
@@ -710,23 +798,23 @@ bool DeviceFiles::StoreUsageTableInfo(
for (size_t i = 0; i < usage_entry_info.size(); ++i) {
UsageTableInfo_UsageEntryInfo* info =
usage_table_info->add_usage_entry_info();
info->set_key_set_id(usage_entry_info[i].key_set_id);
switch (usage_entry_info[i].storage_type) {
case kStorageLicense:
info->set_storage(
UsageTableInfo_UsageEntryInfo_UsageEntryStorage_LICENSE);
info->set_key_set_id(usage_entry_info[i].key_set_id);
break;
case kStorageUsageInfo:
info->set_storage(
UsageTableInfo_UsageEntryInfo_UsageEntryStorage_USAGE_INFO);
info->set_provider_session_token(
usage_entry_info[i].provider_session_token);
info->set_app_id(usage_entry_info[i].app_id);
info->set_usage_info_file_name(
usage_entry_info[i].usage_info_file_name);
break;
case kStorageUnknown:
default:
LOGW("DeviceFiles::StoreUsageTableHeader: unknown storage type: %d",
usage_entry_info[i].storage_type);
return false;
info->set_storage(
UsageTableInfo_UsageEntryInfo_UsageEntryStorage_UNKNOWN);
break;
}
}
@@ -738,7 +826,7 @@ bool DeviceFiles::StoreUsageTableInfo(
bool DeviceFiles::RetrieveUsageTableInfo(
CdmUsageTableHeader* usage_table_header,
std::vector<DeviceFiles::UsageEntryInfo>* usage_entry_info) {
std::vector<CdmUsageEntryInfo>* usage_entry_info) {
if (!initialized_) {
LOGW("DeviceFiles::RetrieveUsageTableInfo: not initialized");
return false;
@@ -782,21 +870,20 @@ bool DeviceFiles::RetrieveUsageTableInfo(
for (int i = 0; i < usage_table_info.usage_entry_info_size(); ++i) {
const UsageTableInfo_UsageEntryInfo& info =
usage_table_info.usage_entry_info(i);
(*usage_entry_info)[i].key_set_id = info.key_set_id();
switch (info.storage()) {
case UsageTableInfo_UsageEntryInfo_UsageEntryStorage_LICENSE:
(*usage_entry_info)[i].storage_type = kStorageLicense;
(*usage_entry_info)[i].key_set_id = info.key_set_id();
break;
case UsageTableInfo_UsageEntryInfo_UsageEntryStorage_USAGE_INFO:
(*usage_entry_info)[i].storage_type = kStorageUsageInfo;
(*usage_entry_info)[i].provider_session_token =
info.provider_session_token();
(*usage_entry_info)[i].app_id = info.app_id();
(*usage_entry_info)[i].usage_info_file_name =
info.usage_info_file_name();
break;
case UsageTableInfo_UsageEntryInfo_UsageEntryStorage_UNKNOWN:
default:
LOGW("DeviceFiles::RetrieveUsageTableInfo: Unknown storage type: %d",
info.storage());
return false;
(*usage_entry_info)[i].storage_type = kStorageUnknown;
break;
}
}

View File

@@ -74,12 +74,12 @@ message UsageTableInfo {
enum UsageEntryStorage {
LICENSE = 1;
USAGE_INFO = 2;
UNKNOWN = 3;
}
optional UsageEntryStorage storage = 1;
optional bytes key_set_id = 2; // used if storage is LICENSE
optional bytes provider_session_token = 3; // used if storage is USAGE_INFO
optional bytes app_id = 4; // used if storage is USAGE_INFO
optional bytes key_set_id = 2;
optional bytes usage_info_file_name = 3; // hash of the app_id
}
optional bytes usage_table_header = 1;

View File

@@ -1475,33 +1475,30 @@ HlsAttributesInfo kHlsAttributesTestData[] = {
// Usage Table and Entry Test Data
// Note: Make sure the number of entries in kUsageEntriesTestData and
// kUsageTableInfoTestData are equal.
DeviceFiles::UsageEntryInfo kUsageEntriesTestData[] = {
CdmUsageEntryInfo kUsageEntriesTestData[] = {
// usage entry 0
{
DeviceFiles::kStorageLicense, "ksid0", "", "",
kStorageLicense, "ksid0", "",
},
// usage entry 1
{
DeviceFiles::kStorageLicense, "ksid1", "", "",
kStorageLicense, "ksid1", "",
},
// usage entry 2
{
DeviceFiles::kStorageUsageInfo, "", "provider_session_token_2",
"app_id_2",
kStorageUsageInfo, "", "app_id_2",
},
// usage entry 3
{
DeviceFiles::kStorageUsageInfo, "", "provider_session_token_3",
"app_id_3",
kStorageUsageInfo, "", "app_id_3",
},
// usage entry 4
{
DeviceFiles::kStorageLicense, "ksid4", "", "",
kStorageLicense, "ksid4", "",
},
// usage entry 5
{
DeviceFiles::kStorageUsageInfo, "", "provider_session_token_5",
"app_id_5",
kStorageUsageInfo, "", "app_id_5",
},
};
@@ -1513,50 +1510,47 @@ struct UsageTableTestInfo {
UsageTableTestInfo kUsageTableInfoTestData[] = {
// usage table 0
{a2bs_hex("5574517CCC"),
a2bs_hex("0A18080510013A120A055574517CCC1209080112056B73696430122018268E3F"
"384F28D04BEE00304089C000463C22E987532855390915FD02C36B5C")},
// usage table 1
{a2bs_hex("CA870203010001288001"),
a2bs_hex("0A28080510013A220A0ACA8702030100012880011209080112056B7369643012"
"09080112056B7369643112202D3638164ADC3B4276734A8EDE96C40BFE14DDB2"
"8013337A3A1A9DFC09F34923")},
a2bs_hex("0A2C080510013A260A0ACA870203010001288001120B080112056B736964301A"
"00120B080112056B736964311A00122049A8F3481444A5B64B6C4F05FBCC2EF8"
"CB67444A08654763F2F5B80F658D7B38")},
// usage table 2
{a2bs_hex("7A7D507618A5D3A68F05228E023082010A028201"),
a2bs_hex("0A5A080510013A540A147A7D507618A5D3A68F05228E023082010A0282011209"
"080112056B736964301209080112056B73696431122608021A1870726F766964"
"65725F73657373696F6E5F746F6B656E5F3222086170705F69645F321220CB07"
"CA08A1E76C61A5F45067176B960A9DB40D169025AF245CF1AFC66C979F47")},
a2bs_hex("0A46080510013A400A147A7D507618A5D3A68F05228E023082010A028201120B"
"080112056B736964301A00120B080112056B736964311A00120E080212001A08"
"6170705F69645F321220783E93A02223BDB94E743856C0F69C35B213ACCDDE91"
"93E48E9186AA83B80584")},
// usage table 3
{a2bs_hex("E83A4902772DAFD2740B7748E9C3B1752D6F12859CED07E82969B4EC"),
a2bs_hex("0A8B01080510013A84010A1CE83A4902772DAFD2740B7748E9C3B1752D6F1285"
"9CED07E82969B4EC1209080112056B736964301209080112056B736964311226"
"08021A1870726F76696465725F73657373696F6E5F746F6B656E5F3222086170"
"705F69645F32122608021A1870726F76696465725F73657373696F6E5F746F6B"
"656E5F3322086170705F69645F331220C4157F80E81C923A9F0885CE6B928D15"
"7E1648384C3E44F04A966815EB09B260")},
a2bs_hex("0A5E080510013A580A1CE83A4902772DAFD2740B7748E9C3B1752D6F12859CED"
"07E82969B4EC120B080112056B736964301A00120B080112056B736964311A00"
"120E080212001A086170705F69645F32120E080212001A086170705F69645F33"
"122084E67F1338727291BC3D92E28442DC8B0F44CB5AF7B98A799313B7EB7F55"
"ED18")},
// usage table 4
{a2bs_hex("CA870203010001288001300112800250D1F8B1ECF849B60FF93E37C4DEEF"
"52F1CCFC047EF42300131F9C4758F4"),
a2bs_hex("0AA701080510013AA0010A2DCA870203010001288001300112800250D1F8B1EC"
"F849B60FF93E37C4DEEF52F1CCFC047EF42300131F9C4758F41209080112056B"
"736964301209080112056B73696431122608021A1870726F76696465725F7365"
"7373696F6E5F746F6B656E5F3222086170705F69645F32122608021A1870726F"
"76696465725F73657373696F6E5F746F6B656E5F3322086170705F69645F3312"
"09080112056B7369643412203F75C53693E7A3DC9BA5BF3E23D7EFCF3C05687A"
"A6082E3AB78F563525981999")},
a2bs_hex("0A7C080510013A760A2DCA870203010001288001300112800250D1F8B1ECF849"
"B60FF93E37C4DEEF52F1CCFC047EF42300131F9C4758F4120B080112056B7369"
"64301A00120B080112056B736964311A00120E080212001A086170705F69645F"
"32120E080212001A086170705F69645F33120B080112056B736964341A001220"
"1CDFCFED5E58A1DF77E1B335305424E1F0260340F9CC15985684C43A4207652"
"1")},
// usage table 5
{a2bs_hex("EC83A4902772DAFD2740B7748E9C3B1752D6F12859CED07E8882969B433E"
"C29AC6FDBE79230B0FAED5D94CF6B829A420BBE3270323941776EE60DD6B"),
a2bs_hex("0ADE01080510013AD7010A3CEC83A4902772DAFD2740B7748E9C3B1752D6F128"
a2bs_hex("0A9C01080510013A95010A3CEC83A4902772DAFD2740B7748E9C3B1752D6F128"
"59CED07E8882969B433EC29AC6FDBE79230B0FAED5D94CF6B829A420BBE32703"
"23941776EE60DD6B1209080112056B736964301209080112056B736964311226"
"08021A1870726F76696465725F73657373696F6E5F746F6B656E5F3222086170"
"705F69645F32122608021A1870726F76696465725F73657373696F6E5F746F6B"
"656E5F3322086170705F69645F331209080112056B73696434122608021A1870"
"726F76696465725F73657373696F6E5F746F6B656E5F3522086170705F69645F"
"3512203B35BD5C615BBA79008A7A1DA29AFA69F5CD529DFDE794A0544E423B72"
"1CB8E8")},
"23941776EE60DD6B120B080112056B736964301A00120B080112056B73696431"
"1A00120E080212001A086170705F69645F32120E080212001A086170705F6964"
"5F33120B080112056B736964341A00120E080212001A086170705F69645F3512"
"20305C7A27A918268119E1996FC182C153DF805034A387F90C3585749E764731"
"32")},
};
class MockFile : public File {
@@ -2253,7 +2247,9 @@ TEST_P(DeviceFilesUsageInfoTest, Read) {
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));
std::vector<std::pair<CdmKeyMessage, CdmKeyResponse> > license_info;
ASSERT_TRUE(device_files.RetrieveUsageInfo(app_id, &license_info));
ASSERT_TRUE(device_files.RetrieveUsageInfo(
DeviceFiles::GetUsageInfoFileName(app_id),
&license_info));
if (index >= 0) {
EXPECT_EQ(static_cast<size_t>(index), license_info.size());
for (size_t i = 0; i < license_info.size(); ++i) {
@@ -2319,9 +2315,10 @@ TEST_P(DeviceFilesUsageInfoTest, Store) {
DeviceFiles device_files(&file_system);
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));
ASSERT_TRUE(device_files.StoreUsageInfo(pst, license_request, license, app_id,
key_set_id, usage_entry,
usage_entry_number));
ASSERT_TRUE(device_files.StoreUsageInfo(
pst, license_request, license,
DeviceFiles::GetUsageInfoFileName(app_id),
key_set_id, usage_entry, usage_entry_number));
}
TEST_P(DeviceFilesUsageInfoTest, Delete) {
@@ -2369,9 +2366,13 @@ TEST_P(DeviceFilesUsageInfoTest, Delete) {
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));
if (index >= 1) {
ASSERT_TRUE(device_files.DeleteUsageInfo(app_id, pst));
ASSERT_TRUE(device_files.DeleteUsageInfo(
DeviceFiles::GetUsageInfoFileName(app_id),
pst));
} else {
ASSERT_FALSE(device_files.DeleteUsageInfo(app_id, pst));
ASSERT_FALSE(device_files.DeleteUsageInfo(
DeviceFiles::GetUsageInfoFileName(app_id),
pst));
}
}
@@ -2405,7 +2406,9 @@ TEST_P(DeviceFilesUsageInfoTest, DeleteAll) {
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));
std::vector<std::string> psts;
ASSERT_TRUE(device_files.DeleteAllUsageInfoForApp(app_id, &psts));
ASSERT_TRUE(device_files.DeleteAllUsageInfoForApp(
DeviceFiles::GetUsageInfoFileName(app_id),
&psts));
if (index < 0) {
EXPECT_EQ(0u, psts.size());
} else {
@@ -2499,20 +2502,14 @@ TEST_P(DeviceFilesUsageTableTest, Store) {
size_t entry_data_length = 0;
std::vector<std::string> entry_data;
std::vector<DeviceFiles::UsageEntryInfo> usage_entry_info;
std::vector<CdmUsageEntryInfo> usage_entry_info;
usage_entry_info.resize(index + 1);
for (int i = 0; i <= index; ++i) {
usage_entry_info[i] = kUsageEntriesTestData[i];
if (kUsageEntriesTestData[i].storage_type == DeviceFiles::kStorageLicense) {
entry_data.push_back(kUsageEntriesTestData[i].key_set_id);
entry_data_length += kUsageEntriesTestData[i].key_set_id.size();
} else {
entry_data.push_back(kUsageEntriesTestData[i].provider_session_token);
entry_data.push_back(kUsageEntriesTestData[i].app_id);
entry_data_length +=
kUsageEntriesTestData[i].provider_session_token.size() +
kUsageEntriesTestData[i].app_id.size();
}
entry_data.push_back(kUsageEntriesTestData[i].key_set_id);
entry_data.push_back(kUsageEntriesTestData[i].usage_info_file_name);
entry_data_length += kUsageEntriesTestData[i].key_set_id.size() +
kUsageEntriesTestData[i].usage_info_file_name.size();
}
entry_data.push_back(kUsageTableInfoTestData[index].usage_table_header);
entry_data_length += kUsageTableInfoTestData[index].usage_table_header.size();
@@ -2555,7 +2552,7 @@ TEST_P(DeviceFilesUsageTableTest, Read) {
DeviceFiles device_files(&file_system);
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));
std::vector<DeviceFiles::UsageEntryInfo> usage_entry_info;
std::vector<CdmUsageEntryInfo> usage_entry_info;
CdmUsageTableHeader usage_table_header;
ASSERT_TRUE(device_files.RetrieveUsageTableInfo(&usage_table_header,
&usage_entry_info));
@@ -2566,17 +2563,11 @@ TEST_P(DeviceFilesUsageTableTest, Read) {
for (size_t i = 0; i <= index; ++i) {
EXPECT_EQ(kUsageEntriesTestData[i].storage_type,
usage_entry_info[i].storage_type);
if (usage_entry_info[i].storage_type == DeviceFiles::kStorageLicense) {
EXPECT_EQ(kUsageEntriesTestData[i].key_set_id,
usage_entry_info[i].key_set_id);
EXPECT_EQ(kEmptyString, usage_entry_info[i].provider_session_token);
EXPECT_EQ(kEmptyString, usage_entry_info[i].app_id);
} else {
EXPECT_EQ(kEmptyString, usage_entry_info[i].key_set_id);
EXPECT_EQ(kUsageEntriesTestData[i].provider_session_token,
usage_entry_info[i].provider_session_token);
EXPECT_EQ(kUsageEntriesTestData[i].app_id, usage_entry_info[i].app_id);
}
EXPECT_EQ(kUsageEntriesTestData[i].key_set_id,
usage_entry_info[i].key_set_id);
EXPECT_EQ(
kUsageEntriesTestData[i].usage_info_file_name,
usage_entry_info[i].usage_info_file_name);
}
}

View File

@@ -842,7 +842,9 @@ TEST_F(WvCdmExtendedDurationTest, UsageOverflowTest) {
DeviceFiles handle(&file_system);
EXPECT_TRUE(handle.Init(security_level));
std::vector<std::string> provider_session_tokens;
EXPECT_TRUE(handle.DeleteAllUsageInfoForApp("", &provider_session_tokens));
EXPECT_TRUE(handle.DeleteAllUsageInfoForApp(
DeviceFiles::GetUsageInfoFileName(""),
&provider_session_tokens));
for (size_t i = 0; i < kMaxUsageTableSize + 100; ++i) {
decryptor_.OpenSession(g_key_system, property_set, kDefaultCdmIdentifier,

View File

@@ -2380,7 +2380,9 @@ TEST_P(WvCdmUsageTest, WithClientId) {
DeviceFiles handle(&file_system);
EXPECT_TRUE(handle.Init(security_level));
std::vector<std::string> psts;
EXPECT_TRUE(handle.DeleteAllUsageInfoForApp(app_id, &psts));
EXPECT_TRUE(handle.DeleteAllUsageInfoForApp(
DeviceFiles::GetUsageInfoFileName(app_id),
&psts));
RenewWithClientIdTestConfiguration* config = GetParam();
std::string key_id;
@@ -2498,7 +2500,9 @@ TEST_F(WvCdmRequestLicenseTest, UsageInfoRetryTest) {
DeviceFiles handle(&file_system);
EXPECT_TRUE(handle.Init(security_level));
std::vector<std::string> psts;
EXPECT_TRUE(handle.DeleteAllUsageInfoForApp(app_id, &psts));
EXPECT_TRUE(handle.DeleteAllUsageInfoForApp(
DeviceFiles::GetUsageInfoFileName(app_id),
&psts));
SubSampleInfo* data = &usage_info_sub_samples_icp[0];
decryptor_.OpenSession(g_key_system, NULL, kDefaultCdmIdentifier, NULL,
@@ -2581,7 +2585,9 @@ TEST_P(WvCdmUsageInfoTest, UsageInfo) {
DeviceFiles handle(&file_system);
EXPECT_TRUE(handle.Init(security_level));
std::vector<std::string> psts;
EXPECT_TRUE(handle.DeleteAllUsageInfoForApp(usage_info_data->app_id, &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;
@@ -2655,7 +2661,8 @@ TEST_F(WvCdmRequestLicenseTest, UsageReleaseAllTest) {
DeviceFiles handle(&file_system);
EXPECT_TRUE(handle.Init(security_level));
std::vector<std::string> psts;
EXPECT_TRUE(handle.DeleteAllUsageInfoForApp("", &psts));
EXPECT_TRUE(handle.DeleteAllUsageInfoForApp(
DeviceFiles::GetUsageInfoFileName(""), &psts));
for (size_t i = 0; i < N_ELEM(usage_info_sub_samples_icp); ++i) {
SubSampleInfo* data = usage_info_sub_samples_icp + i;