Revert "Core CDM: Remove usage info API from DeviceFiles."
This reverts commit 244e6301bd.
Reason for revert: Feature rejected by Android
Bug: 242289743
Change-Id: I00a6e223dfabd85a5f12a224dfea6456a24a1770
This commit is contained in:
committed by
Android (Google) Code Review
parent
244e6301bd
commit
3012cd1ee6
@@ -164,10 +164,103 @@ class DeviceFiles {
|
||||
virtual bool ReserveLicenseId(const std::string& key_set_id);
|
||||
virtual bool UnreserveLicenseId(const std::string& key_set_id);
|
||||
|
||||
// Usage info has been deprecated, however, these two methods remain
|
||||
// for the removal of their storage data.
|
||||
// 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& usage_info_file_name, const std::string& key_set_id,
|
||||
const CdmUsageEntry& usage_entry, uint32_t usage_entry_number,
|
||||
const std::string& drm_certificate, const CryptoWrappedKey& wrapped_key);
|
||||
|
||||
// Retrieve usage identifying information stored on the file system.
|
||||
// The caller needs to specify at least one of |ksids| or
|
||||
// |provider_session_tokens|
|
||||
virtual bool ListUsageIds(const std::string& app_id,
|
||||
std::vector<std::string>* ksids,
|
||||
std::vector<std::string>* provider_session_tokens);
|
||||
|
||||
// Get the provider session token for the given key_set_id.
|
||||
virtual bool GetProviderSessionToken(const std::string& app_id,
|
||||
const std::string& key_set_id,
|
||||
std::string* provider_session_token);
|
||||
|
||||
virtual bool DeleteUsageInfo(const std::string& usage_info_file_name,
|
||||
const std::string& provider_session_token);
|
||||
|
||||
// Deletes a set of provider sessions from the specified usage info.
|
||||
// Sessions removed are based on the provided |key_set_ids|. If
|
||||
// there are no remaining sessions associated with the usage info
|
||||
// then the file will be deleted; otherwise, the remaining sessions
|
||||
// are written back to the usage info file.
|
||||
//
|
||||
// Args:
|
||||
// usage_info_file_name: name of the file containing the usage info
|
||||
// message. This name should _not_ be the complete path, just
|
||||
// the file name.
|
||||
// key_set_ids: The list of key set IDs to be removed from the
|
||||
// usage info. Note that any key set ids that are not present
|
||||
// in the usage info are silently ignored.
|
||||
// Returns:
|
||||
// `true` if the file existed, and operations were completed as
|
||||
// expected. `false` if the file does not exist or if there is an
|
||||
// issue writing the result back to file.
|
||||
virtual bool DeleteMultipleUsageInfoByKeySetIds(
|
||||
const std::string& usage_info_file_name,
|
||||
const std::vector<std::string>& key_set_ids);
|
||||
|
||||
// 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& usage_info_file_name,
|
||||
std::vector<std::string>* provider_session_tokens);
|
||||
|
||||
virtual bool DeleteAllUsageInfo();
|
||||
|
||||
// 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& usage_info_file_name,
|
||||
const std::string& provider_session_token,
|
||||
CdmKeyMessage* license_request,
|
||||
CdmKeyResponse* license_response,
|
||||
CdmUsageEntry* usage_entry,
|
||||
uint32_t* usage_entry_number,
|
||||
std::string* drm_certificate,
|
||||
CryptoWrappedKey* wrapped_key);
|
||||
// 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& 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, std::string* drm_certificate,
|
||||
CryptoWrappedKey* wrapped_key);
|
||||
|
||||
// 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);
|
||||
virtual bool RetrieveUsageInfo(const std::string& usage_info_file_name,
|
||||
const std::string& provider_session_token,
|
||||
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 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,
|
||||
const CdmHlsMethod method,
|
||||
|
||||
@@ -184,6 +184,111 @@ bool ExtractFromDeviceCertificate(const DeviceCertificate& device_certificate,
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FindOrInsertUsageCertificate(const std::string& drm_certificate,
|
||||
const CryptoWrappedKey& wrapped_private_key,
|
||||
UsageInfo* usage_info,
|
||||
uint32_t* drm_certificate_id) {
|
||||
RETURN_FALSE_IF_NULL(usage_info);
|
||||
RETURN_FALSE_IF_NULL(drm_certificate_id);
|
||||
|
||||
// Scan |drm_certificate_cache| for |drm_certificate|. If present,
|
||||
// return the id
|
||||
std::set<uint32_t> ids;
|
||||
for (const UsageInfo_DrmUsageCertificate& drm_device_cert :
|
||||
usage_info->drm_certificate_cache()) {
|
||||
if (drm_device_cert.drm_certificate().certificate() == drm_certificate) {
|
||||
*drm_certificate_id = drm_device_cert.drm_certificate_id();
|
||||
return true;
|
||||
}
|
||||
ids.insert(drm_device_cert.drm_certificate_id());
|
||||
}
|
||||
|
||||
uint32_t last_id = 0;
|
||||
|
||||
// |drm_certificate| is not in the cache. Find the first non-contiguous
|
||||
// id number to insert
|
||||
for (uint32_t id : ids) {
|
||||
if (id > last_id + 1) {
|
||||
break;
|
||||
}
|
||||
last_id = id;
|
||||
}
|
||||
|
||||
if (ids.empty())
|
||||
*drm_certificate_id = 0;
|
||||
else
|
||||
*drm_certificate_id = last_id + 1;
|
||||
|
||||
// Now insert into |drm_certificate_cache|
|
||||
UsageInfo_DrmUsageCertificate* drm_usage_certificate =
|
||||
usage_info->add_drm_certificate_cache();
|
||||
drm_usage_certificate->set_drm_certificate_id(*drm_certificate_id);
|
||||
|
||||
return SetDeviceCertificate(drm_certificate, wrapped_private_key,
|
||||
drm_usage_certificate->mutable_drm_certificate());
|
||||
}
|
||||
|
||||
bool FindUsageCertificate(
|
||||
uint32_t drm_certificate_id,
|
||||
const google::protobuf::RepeatedPtrField<UsageInfo_DrmUsageCertificate>&
|
||||
drm_certificate_cache,
|
||||
std::string* drm_certificate, CryptoWrappedKey* wrapped_private_key) {
|
||||
for (const UsageInfo_DrmUsageCertificate& drm_usage_cert :
|
||||
drm_certificate_cache) {
|
||||
if (drm_usage_cert.drm_certificate_id() == drm_certificate_id) {
|
||||
return ExtractFromDeviceCertificate(drm_usage_cert.drm_certificate(),
|
||||
drm_certificate, wrapped_private_key);
|
||||
}
|
||||
}
|
||||
|
||||
LOGE("Unable to find any certificate in usage cache for entry: %d",
|
||||
drm_certificate_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UsageCertificateCacheCleanUp(UsageInfo* usage_info) {
|
||||
const google::protobuf::RepeatedPtrField<UsageInfo_ProviderSession>&
|
||||
provider_sessions = usage_info->sessions();
|
||||
google::protobuf::RepeatedPtrField<UsageInfo_DrmUsageCertificate>*
|
||||
drm_certificate_cache = usage_info->mutable_drm_certificate_cache();
|
||||
|
||||
// Find all the DRM certificate ids in |drm_certificate_cache|
|
||||
std::set<uint32_t> ids;
|
||||
for (const UsageInfo_DrmUsageCertificate& drm_usage_cert :
|
||||
*drm_certificate_cache) {
|
||||
ids.insert(drm_usage_cert.drm_certificate_id());
|
||||
}
|
||||
|
||||
// Next find all the DRM certificate ids in |provider_sessions|
|
||||
std::set<uint32_t> session_ids;
|
||||
for (const UsageInfo_ProviderSession& session : provider_sessions) {
|
||||
session_ids.insert(session.drm_certificate_id());
|
||||
}
|
||||
|
||||
// Now find all the entry numbers for DRM certificates in
|
||||
// |drm_device_certificates| but not in |provider_sessions|. These need to
|
||||
// be removed.
|
||||
std::set<uint32_t> ids_to_erase;
|
||||
std::set_difference(ids.begin(), ids.end(), session_ids.begin(),
|
||||
session_ids.end(),
|
||||
std::inserter(ids_to_erase, ids_to_erase.begin()));
|
||||
|
||||
const auto is_deletable =
|
||||
[&ids_to_erase](
|
||||
const UsageInfo_DrmUsageCertificate& usage_certificate) -> bool {
|
||||
return std::find(ids_to_erase.cbegin(), ids_to_erase.cend(),
|
||||
usage_certificate.drm_certificate_id()) !=
|
||||
ids_to_erase.cend();
|
||||
};
|
||||
|
||||
drm_certificate_cache->erase(
|
||||
std::remove_if(drm_certificate_cache->begin(),
|
||||
drm_certificate_cache->end(), is_deletable),
|
||||
drm_certificate_cache->end());
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
@@ -902,12 +1007,512 @@ bool DeviceFiles::UnreserveLicenseId(const std::string& key_set_id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeviceFiles::StoreUsageInfo(
|
||||
const std::string& provider_session_token, const CdmKeyMessage& key_request,
|
||||
const CdmKeyResponse& key_response, const std::string& usage_info_file_name,
|
||||
const std::string& key_set_id, const std::string& usage_entry,
|
||||
uint32_t usage_entry_number, const std::string& drm_certificate,
|
||||
const CryptoWrappedKey& wrapped_private_key) {
|
||||
RETURN_FALSE_IF_UNINITIALIZED();
|
||||
video_widevine_client::sdk::File file;
|
||||
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(usage_info_file_name, &file) != kNoError) {
|
||||
LOGE("Unable to retrieve usage info file");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
UsageInfo* usage_info = file.mutable_usage_info();
|
||||
UsageInfo_ProviderSession* provider_session = usage_info->add_sessions();
|
||||
|
||||
provider_session->set_token(provider_session_token.data(),
|
||||
provider_session_token.size());
|
||||
provider_session->set_license_request(key_request.data(), key_request.size());
|
||||
provider_session->set_license(key_response.data(), key_response.size());
|
||||
provider_session->set_key_set_id(key_set_id.data(), key_set_id.size());
|
||||
provider_session->set_usage_entry(usage_entry);
|
||||
provider_session->set_usage_entry_number(usage_entry_number);
|
||||
|
||||
if (drm_certificate.size() > 0) {
|
||||
uint32_t drm_certificate_id;
|
||||
if (!FindOrInsertUsageCertificate(drm_certificate, wrapped_private_key,
|
||||
usage_info, &drm_certificate_id)) {
|
||||
LOGE("Unable to insert a certificate in the usage certificate cache");
|
||||
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;
|
||||
}
|
||||
|
||||
bool DeviceFiles::ListUsageIds(
|
||||
const std::string& app_id, std::vector<std::string>* ksids,
|
||||
std::vector<std::string>* provider_session_tokens) {
|
||||
RETURN_FALSE_IF_UNINITIALIZED();
|
||||
|
||||
if (ksids == nullptr && provider_session_tokens == nullptr) {
|
||||
LOGE(
|
||||
"Both output parameters |ksids| and |provider_session_tokens| are "
|
||||
"not provided");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Empty or non-existent file == no usage records.
|
||||
std::string file_name = GetUsageInfoFileName(app_id);
|
||||
if (!FileExists(file_name) || GetFileSize(file_name) == 0) {
|
||||
if (ksids != nullptr) ksids->clear();
|
||||
if (provider_session_tokens != nullptr) provider_session_tokens->clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
video_widevine_client::sdk::File file;
|
||||
if (RetrieveHashedFile(file_name, &file) != kNoError) {
|
||||
LOGE("Unable to retrieve usage info file");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ksids != nullptr) ksids->clear();
|
||||
if (provider_session_tokens != nullptr) provider_session_tokens->clear();
|
||||
|
||||
const int num_records = file.usage_info().sessions_size();
|
||||
for (int i = 0; i < num_records; ++i) {
|
||||
if ((ksids != nullptr) &&
|
||||
!file.usage_info().sessions(i).key_set_id().empty()) {
|
||||
ksids->push_back(file.usage_info().sessions(i).key_set_id());
|
||||
}
|
||||
if ((provider_session_tokens != nullptr) &&
|
||||
!file.usage_info().sessions(i).token().empty()) {
|
||||
provider_session_tokens->push_back(file.usage_info().sessions(i).token());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeviceFiles::GetProviderSessionToken(const std::string& app_id,
|
||||
const std::string& key_set_id,
|
||||
std::string* provider_session_token) {
|
||||
RETURN_FALSE_IF_UNINITIALIZED();
|
||||
RETURN_FALSE_IF_NULL(provider_session_token);
|
||||
|
||||
std::string file_name = GetUsageInfoFileName(app_id);
|
||||
if (!FileExists(file_name) || GetFileSize(file_name) == 0) {
|
||||
LOGE("Usage info file does not exists or is an empty file");
|
||||
return false;
|
||||
}
|
||||
|
||||
video_widevine_client::sdk::File file;
|
||||
if (RetrieveHashedFile(file_name, &file) != kNoError) {
|
||||
LOGE("Unable to retrieve usage info file");
|
||||
return false;
|
||||
}
|
||||
|
||||
const int num_records = static_cast<int>(file.usage_info().sessions_size());
|
||||
for (int i = 0; i < num_records; ++i) {
|
||||
if (file.usage_info().sessions(i).key_set_id() == key_set_id) {
|
||||
*provider_session_token = file.usage_info().sessions(i).token();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DeviceFiles::DeleteUsageInfo(const std::string& usage_info_file_name,
|
||||
const std::string& provider_session_token) {
|
||||
RETURN_FALSE_IF_UNINITIALIZED();
|
||||
video_widevine_client::sdk::File file;
|
||||
if (RetrieveHashedFile(usage_info_file_name, &file) != kNoError) {
|
||||
LOGE("Unable to retrieve usage info file");
|
||||
return false;
|
||||
}
|
||||
|
||||
UsageInfo* usage_info = file.mutable_usage_info();
|
||||
int index = 0;
|
||||
bool found = false;
|
||||
for (; index < usage_info->sessions_size(); ++index) {
|
||||
if (usage_info->sessions(index).token() == provider_session_token) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
LOGE("Unable to find provider session token: pst = %s",
|
||||
wvutil::b2a_hex(provider_session_token).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
google::protobuf::RepeatedPtrField<UsageInfo_ProviderSession>* sessions =
|
||||
usage_info->mutable_sessions();
|
||||
if (index < usage_info->sessions_size() - 1) {
|
||||
sessions->SwapElements(index, usage_info->sessions_size() - 1);
|
||||
}
|
||||
sessions->RemoveLast();
|
||||
UsageCertificateCacheCleanUp(usage_info);
|
||||
|
||||
std::string serialized_file;
|
||||
file.SerializeToString(&serialized_file);
|
||||
return StoreFileWithHash(usage_info_file_name, serialized_file) == kNoError;
|
||||
}
|
||||
|
||||
bool DeviceFiles::DeleteAllUsageInfoForApp(
|
||||
const std::string& usage_info_file_name,
|
||||
std::vector<std::string>* provider_session_tokens) {
|
||||
RETURN_FALSE_IF_UNINITIALIZED();
|
||||
RETURN_FALSE_IF_NULL(provider_session_tokens);
|
||||
|
||||
provider_session_tokens->clear();
|
||||
|
||||
if (!FileExists(usage_info_file_name)) return true;
|
||||
|
||||
video_widevine_client::sdk::File file;
|
||||
if (RetrieveHashedFile(usage_info_file_name, &file) == kNoError) {
|
||||
for (int i = 0; i < file.usage_info().sessions_size(); ++i) {
|
||||
provider_session_tokens->push_back(file.usage_info().sessions(i).token());
|
||||
}
|
||||
} else {
|
||||
LOGW("Unable to retrieve usage info file");
|
||||
}
|
||||
return RemoveFile(usage_info_file_name);
|
||||
}
|
||||
|
||||
bool DeviceFiles::DeleteMultipleUsageInfoByKeySetIds(
|
||||
const std::string& usage_info_file_name,
|
||||
const std::vector<std::string>& key_set_ids) {
|
||||
if (!FileExists(usage_info_file_name)) return false;
|
||||
if (key_set_ids.empty()) {
|
||||
LOGW("No key set IDs provided");
|
||||
return true;
|
||||
}
|
||||
|
||||
video_widevine_client::sdk::File file;
|
||||
if (RetrieveHashedFile(usage_info_file_name, &file) != kNoError) {
|
||||
LOGW("Unable to retrieve usage info file");
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto is_deletable =
|
||||
[&key_set_ids](
|
||||
const video_widevine_client::sdk::UsageInfo::ProviderSession& session)
|
||||
-> bool {
|
||||
return std::find(key_set_ids.cbegin(), key_set_ids.cend(),
|
||||
session.key_set_id()) != key_set_ids.cend();
|
||||
};
|
||||
|
||||
auto sessions = file.mutable_usage_info()->mutable_sessions();
|
||||
const int initial_size = sessions->size();
|
||||
sessions->erase(
|
||||
std::remove_if(sessions->begin(), sessions->end(), is_deletable),
|
||||
sessions->end());
|
||||
|
||||
if (sessions->size() == initial_size) {
|
||||
// Nothing deleted.
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sessions->size() > 0) {
|
||||
UsageCertificateCacheCleanUp(file.mutable_usage_info());
|
||||
std::string serialized_file;
|
||||
file.SerializeToString(&serialized_file);
|
||||
return StoreFileWithHash(usage_info_file_name, serialized_file) == kNoError;
|
||||
}
|
||||
|
||||
return RemoveFile(usage_info_file_name);
|
||||
}
|
||||
|
||||
bool DeviceFiles::DeleteAllUsageInfo() {
|
||||
RETURN_FALSE_IF_UNINITIALIZED();
|
||||
return RemoveFile(kUsageInfoFileNamePrefix + std::string(kWildcard) +
|
||||
kUsageInfoFileNameExt);
|
||||
}
|
||||
|
||||
bool DeviceFiles::RetrieveUsageInfo(const std::string& usage_info_file_name,
|
||||
const std::string& provider_session_token,
|
||||
CdmKeyMessage* license_request,
|
||||
CdmKeyResponse* license,
|
||||
std::string* usage_entry,
|
||||
uint32_t* usage_entry_number,
|
||||
std::string* drm_certificate,
|
||||
CryptoWrappedKey* wrapped_private_key) {
|
||||
RETURN_FALSE_IF_UNINITIALIZED();
|
||||
RETURN_FALSE_IF_NULL(license_request);
|
||||
RETURN_FALSE_IF_NULL(license);
|
||||
RETURN_FALSE_IF_NULL(usage_entry);
|
||||
RETURN_FALSE_IF_NULL(usage_entry_number);
|
||||
RETURN_FALSE_IF_NULL(drm_certificate);
|
||||
RETURN_FALSE_IF_NULL(wrapped_private_key);
|
||||
|
||||
video_widevine_client::sdk::File file;
|
||||
if (RetrieveHashedFile(usage_info_file_name, &file) != kNoError) {
|
||||
LOGE("Unable to retrieve usage info file");
|
||||
return false;
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
for (; index < file.usage_info().sessions_size(); ++index) {
|
||||
if (file.usage_info().sessions(index).token() == provider_session_token) {
|
||||
*license_request = file.usage_info().sessions(index).license_request();
|
||||
*license = file.usage_info().sessions(index).license();
|
||||
*usage_entry = file.usage_info().sessions(index).usage_entry();
|
||||
*usage_entry_number = static_cast<uint32_t>(
|
||||
file.usage_info().sessions(index).usage_entry_number());
|
||||
|
||||
if (!file.usage_info().sessions(index).has_drm_certificate_id()) {
|
||||
drm_certificate->clear();
|
||||
wrapped_private_key->Clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!FindUsageCertificate(
|
||||
file.usage_info().sessions(index).drm_certificate_id(),
|
||||
file.usage_info().drm_certificate_cache(), drm_certificate,
|
||||
wrapped_private_key)) {
|
||||
LOGE("Unable to find DRM certificate information from usage cache");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DeviceFiles::RetrieveUsageInfoByKeySetId(
|
||||
const std::string& usage_info_file_name, const std::string& key_set_id,
|
||||
std::string* provider_session_token, CdmKeyMessage* license_request,
|
||||
CdmKeyResponse* license, std::string* usage_entry,
|
||||
uint32_t* usage_entry_number, std::string* drm_certificate,
|
||||
CryptoWrappedKey* wrapped_private_key) {
|
||||
RETURN_FALSE_IF_UNINITIALIZED();
|
||||
RETURN_FALSE_IF_NULL(license_request);
|
||||
RETURN_FALSE_IF_NULL(license);
|
||||
RETURN_FALSE_IF_NULL(usage_entry);
|
||||
RETURN_FALSE_IF_NULL(usage_entry_number);
|
||||
RETURN_FALSE_IF_NULL(drm_certificate);
|
||||
RETURN_FALSE_IF_NULL(wrapped_private_key);
|
||||
|
||||
video_widevine_client::sdk::File file;
|
||||
if (RetrieveHashedFile(usage_info_file_name, &file) != kNoError) {
|
||||
LOGE("Unable to retrieve usage info file");
|
||||
return false;
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
for (; index < file.usage_info().sessions_size(); ++index) {
|
||||
if (file.usage_info().sessions(index).key_set_id() == key_set_id) {
|
||||
*provider_session_token = file.usage_info().sessions(index).token();
|
||||
*license_request = file.usage_info().sessions(index).license_request();
|
||||
*license = file.usage_info().sessions(index).license();
|
||||
*usage_entry = file.usage_info().sessions(index).usage_entry();
|
||||
*usage_entry_number = static_cast<uint32_t>(
|
||||
file.usage_info().sessions(index).usage_entry_number());
|
||||
|
||||
if (!file.usage_info().sessions(index).has_drm_certificate_id()) {
|
||||
drm_certificate->clear();
|
||||
wrapped_private_key->Clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!FindUsageCertificate(
|
||||
file.usage_info().sessions(index).drm_certificate_id(),
|
||||
file.usage_info().drm_certificate_cache(), drm_certificate,
|
||||
wrapped_private_key)) {
|
||||
LOGE("Unable to find DRM certificate information from usage cache");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DeviceFiles::StoreUsageInfo(const std::string& usage_info_file_name,
|
||||
const std::vector<CdmUsageData>& usage_data) {
|
||||
RETURN_FALSE_IF_UNINITIALIZED();
|
||||
|
||||
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);
|
||||
|
||||
if (usage_data[i].drm_certificate.size() > 0) {
|
||||
uint32_t drm_certificate_id;
|
||||
if (!FindOrInsertUsageCertificate(usage_data[i].drm_certificate,
|
||||
usage_data[i].wrapped_private_key,
|
||||
usage_info, &drm_certificate_id)) {
|
||||
LOGE("Unable to insert a certificate in the usage certificate cache");
|
||||
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;
|
||||
}
|
||||
|
||||
bool DeviceFiles::UpdateUsageInfo(const std::string& usage_info_file_name,
|
||||
const std::string& provider_session_token,
|
||||
const CdmUsageData& usage_data) {
|
||||
RETURN_FALSE_IF_UNINITIALIZED();
|
||||
|
||||
video_widevine_client::sdk::File file;
|
||||
if (!FileExists(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;
|
||||
}
|
||||
|
||||
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_number(usage_data.usage_entry_number);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DeviceFiles::RetrieveUsageInfo(const std::string& usage_info_file_name,
|
||||
std::vector<CdmUsageData>* usage_data) {
|
||||
RETURN_FALSE_IF_UNINITIALIZED();
|
||||
RETURN_FALSE_IF_NULL(usage_data);
|
||||
|
||||
if (!FileExists(usage_info_file_name) ||
|
||||
GetFileSize(usage_info_file_name) == 0) {
|
||||
usage_data->resize(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
video_widevine_client::sdk::File file;
|
||||
if (RetrieveHashedFile(usage_info_file_name, &file) != kNoError) {
|
||||
LOGE("Unable to retrieve usage info 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 = static_cast<uint32_t>(
|
||||
file.usage_info().sessions(i).usage_entry_number());
|
||||
|
||||
if (!file.usage_info().sessions(i).has_drm_certificate_id()) {
|
||||
(*usage_data)[i].drm_certificate.clear();
|
||||
(*usage_data)[i].wrapped_private_key.Clear();
|
||||
} else {
|
||||
if (!FindUsageCertificate(
|
||||
file.usage_info().sessions(i).drm_certificate_id(),
|
||||
file.usage_info().drm_certificate_cache(),
|
||||
&(*usage_data)[i].drm_certificate,
|
||||
&(*usage_data)[i].wrapped_private_key)) {
|
||||
LOGW("Unable to find DRM certificate information from usage cache");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeviceFiles::RetrieveUsageInfo(const std::string& usage_info_file_name,
|
||||
const std::string& provider_session_token,
|
||||
CdmUsageData* usage_data) {
|
||||
RETURN_FALSE_IF_UNINITIALIZED();
|
||||
RETURN_FALSE_IF_NULL(usage_data);
|
||||
|
||||
video_widevine_client::sdk::File file;
|
||||
if (RetrieveHashedFile(usage_info_file_name, &file) != kNoError) {
|
||||
LOGE("Unable to retrieve usage info file");
|
||||
return false;
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
for (; index < file.usage_info().sessions_size(); ++index) {
|
||||
if (file.usage_info().sessions(index).token() == provider_session_token) {
|
||||
usage_data->provider_session_token =
|
||||
file.usage_info().sessions(index).token();
|
||||
usage_data->license_request =
|
||||
file.usage_info().sessions(index).license_request();
|
||||
usage_data->license = file.usage_info().sessions(index).license();
|
||||
usage_data->key_set_id = file.usage_info().sessions(index).key_set_id();
|
||||
usage_data->usage_entry = file.usage_info().sessions(index).usage_entry();
|
||||
usage_data->usage_entry_number = static_cast<uint32_t>(
|
||||
file.usage_info().sessions(index).usage_entry_number());
|
||||
|
||||
if (!file.usage_info().sessions(index).has_drm_certificate_id()) {
|
||||
usage_data->drm_certificate.clear();
|
||||
usage_data->wrapped_private_key.Clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!FindUsageCertificate(
|
||||
file.usage_info().sessions(index).drm_certificate_id(),
|
||||
file.usage_info().drm_certificate_cache(),
|
||||
&usage_data->drm_certificate, &usage_data->wrapped_private_key)) {
|
||||
LOGE("Unable to find DRM certificate information from usage cache");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DeviceFiles::ListUsageInfoFiles(
|
||||
std::vector<std::string>* usage_info_file_names) {
|
||||
RETURN_FALSE_IF_UNINITIALIZED();
|
||||
@@ -1528,6 +2133,14 @@ std::string DeviceFiles::GetLicenseFileNameExtension() {
|
||||
return kLicenseFileNameExt;
|
||||
}
|
||||
|
||||
std::string DeviceFiles::GetUsageInfoFileName(const std::string& app_id) {
|
||||
std::string hash;
|
||||
if (app_id != "") {
|
||||
hash = GetFileNameSafeHash(app_id);
|
||||
}
|
||||
return kUsageInfoFileNamePrefix + hash + kUsageInfoFileNameExt;
|
||||
}
|
||||
|
||||
std::string DeviceFiles::GetOkpInfoFileName() { return kOkpInfoFileName; }
|
||||
|
||||
std::string DeviceFiles::GetFileNameSafeHash(const std::string& input) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user