Merge changes I939e4797,Iefbfe2dd,I002202b4,I09262da0
* changes: Core CDM: Remove usage info as a run-time type. Core CDM: Do not store/retrieve USAGE_INFO entries. Core CDM: Remove usage info API from DeviceFiles. Core CDM: Removed ability to add secure stop entry.
This commit is contained in:
@@ -484,9 +484,8 @@ CdmResponseType CdmSession::AddKeyInternal(const CdmKeyResponse& key_response) {
|
||||
LOGE("CDM does not support secure stop licenses");
|
||||
return ADD_KEY_ERROR;
|
||||
}
|
||||
sts = usage_table_header_->AddEntry(
|
||||
crypto_session_.get(), /* is_persistent */ true, key_set_id_,
|
||||
/* usage_info_filename */ "", key_response, &usage_entry_number_);
|
||||
sts = usage_table_header_->AddEntry(crypto_session_.get(), key_set_id_,
|
||||
key_response, &usage_entry_number_);
|
||||
crypto_metrics_->usage_table_header_add_entry_.Increment(sts);
|
||||
if (sts != NO_ERROR) return sts;
|
||||
provider_session_token_ = std::move(provider_session_token);
|
||||
@@ -1050,9 +1049,9 @@ bool CdmSession::VerifyOfflineUsageEntry() {
|
||||
return false;
|
||||
}
|
||||
const CdmUsageEntryInfo& usage_entry_info =
|
||||
usage_table_header_->usage_entry_info().at(usage_entry_number_);
|
||||
if (usage_entry_info.storage_type != kStorageLicense ||
|
||||
usage_entry_info.key_set_id != key_set_id_) {
|
||||
usage_table_header_->entry_info_list().at(usage_entry_number_);
|
||||
if (usage_entry_info.IsEmpty() ||
|
||||
usage_entry_info.key_set_id() != key_set_id_) {
|
||||
LOGD("License usage entry does not match");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -32,17 +32,6 @@ using video_widevine_client::sdk::License_LicenseState_ACTIVE;
|
||||
using video_widevine_client::sdk::License_LicenseState_RELEASING;
|
||||
using video_widevine_client::sdk::NameValue;
|
||||
using video_widevine_client::sdk::OemCertificate;
|
||||
using video_widevine_client::sdk::UsageInfo;
|
||||
using video_widevine_client::sdk::UsageInfo_DrmUsageCertificate;
|
||||
using video_widevine_client::sdk::UsageInfo_ProviderSession;
|
||||
using video_widevine_client::sdk::UsageTableInfo;
|
||||
using video_widevine_client::sdk::UsageTableInfo_UsageEntryInfo;
|
||||
using video_widevine_client::sdk::
|
||||
UsageTableInfo_UsageEntryInfo_UsageEntryStorage_LICENSE;
|
||||
using video_widevine_client::sdk::
|
||||
UsageTableInfo_UsageEntryInfo_UsageEntryStorage_UNKNOWN;
|
||||
using video_widevine_client::sdk::
|
||||
UsageTableInfo_UsageEntryInfo_UsageEntryStorage_USAGE_INFO;
|
||||
|
||||
// Stringify turns macro arguments into static C strings.
|
||||
// Example: STRINGIFY(this_argument) -> "this_argument"
|
||||
@@ -184,111 +173,6 @@ 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
|
||||
@@ -1007,512 +891,12 @@ 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();
|
||||
@@ -1630,8 +1014,10 @@ bool DeviceFiles::DeleteHlsAttributes(const std::string& key_set_id) {
|
||||
|
||||
bool DeviceFiles::StoreUsageTableInfo(
|
||||
const CdmUsageTableHeader& usage_table_header,
|
||||
const std::vector<CdmUsageEntryInfo>& usage_entry_info) {
|
||||
const std::vector<CdmUsageEntryInfo>& usage_entry_info_list) {
|
||||
RETURN_FALSE_IF_UNINITIALIZED();
|
||||
using video_widevine_client::sdk::UsageTableInfo;
|
||||
using UsageEntryInfo = UsageTableInfo::UsageEntryInfo;
|
||||
|
||||
// Fill in file information
|
||||
video_widevine_client::sdk::File file;
|
||||
@@ -1639,35 +1025,22 @@ bool DeviceFiles::StoreUsageTableInfo(
|
||||
file.set_type(video_widevine_client::sdk::File::USAGE_TABLE_INFO);
|
||||
file.set_version(video_widevine_client::sdk::File::VERSION_1);
|
||||
|
||||
UsageTableInfo* usage_table_info = file.mutable_usage_table_info();
|
||||
usage_table_info->set_usage_table_header(usage_table_header);
|
||||
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_last_use_time(usage_entry_info[i].last_use_time);
|
||||
info->set_offline_license_expiry_time(
|
||||
usage_entry_info[i].offline_license_expiry_time);
|
||||
break;
|
||||
case kStorageUsageInfo:
|
||||
info->set_storage(
|
||||
UsageTableInfo_UsageEntryInfo_UsageEntryStorage_USAGE_INFO);
|
||||
info->set_usage_info_file_name(
|
||||
usage_entry_info[i].usage_info_file_name);
|
||||
info->set_last_use_time(usage_entry_info[i].last_use_time);
|
||||
break;
|
||||
case kStorageTypeUnknown:
|
||||
default:
|
||||
info->set_storage(
|
||||
UsageTableInfo_UsageEntryInfo_UsageEntryStorage_UNKNOWN);
|
||||
break;
|
||||
UsageTableInfo* stored_table_info = file.mutable_usage_table_info();
|
||||
stored_table_info->set_usage_table_header(usage_table_header);
|
||||
|
||||
for (const auto& entry_info : usage_entry_info_list) {
|
||||
UsageEntryInfo* stored_info = stored_table_info->add_usage_entry_info();
|
||||
if (entry_info.HasKeySetId()) {
|
||||
stored_info->set_storage(UsageEntryInfo::LICENSE);
|
||||
stored_info->set_key_set_id(entry_info.key_set_id());
|
||||
stored_info->set_last_use_time(entry_info.last_use_time());
|
||||
stored_info->set_offline_license_expiry_time(
|
||||
entry_info.license_expiry_time());
|
||||
} else {
|
||||
stored_info->set_storage(UsageEntryInfo::UNKNOWN);
|
||||
}
|
||||
}
|
||||
usage_table_info->set_use_lru(true);
|
||||
stored_table_info->set_use_lru(true);
|
||||
|
||||
std::string serialized_file;
|
||||
file.SerializeToString(&serialized_file);
|
||||
@@ -1678,13 +1051,15 @@ bool DeviceFiles::StoreUsageTableInfo(
|
||||
|
||||
bool DeviceFiles::RetrieveUsageTableInfo(
|
||||
CdmUsageTableHeader* usage_table_header,
|
||||
std::vector<CdmUsageEntryInfo>* usage_entry_info, bool* lru_upgrade,
|
||||
std::vector<CdmUsageEntryInfo>* usage_entry_info_list, bool* lru_upgrade,
|
||||
bool* has_usage_info_entries) {
|
||||
RETURN_FALSE_IF_UNINITIALIZED();
|
||||
RETURN_FALSE_IF_NULL(usage_table_header);
|
||||
RETURN_FALSE_IF_NULL(usage_entry_info);
|
||||
RETURN_FALSE_IF_NULL(usage_entry_info_list);
|
||||
RETURN_FALSE_IF_NULL(lru_upgrade);
|
||||
RETURN_FALSE_IF_NULL(has_usage_info_entries);
|
||||
using video_widevine_client::sdk::UsageTableInfo;
|
||||
using UsageEntryInfo = UsageTableInfo::UsageEntryInfo;
|
||||
|
||||
video_widevine_client::sdk::File file;
|
||||
if (RetrieveHashedFile(GetUsageTableFileName(), &file) != kNoError) {
|
||||
@@ -1711,35 +1086,28 @@ bool DeviceFiles::RetrieveUsageTableInfo(
|
||||
return false;
|
||||
}
|
||||
|
||||
const UsageTableInfo& usage_table_info = file.usage_table_info();
|
||||
const UsageTableInfo& stored_table_info = file.usage_table_info();
|
||||
|
||||
*lru_upgrade = !usage_table_info.use_lru();
|
||||
*lru_upgrade = !stored_table_info.use_lru();
|
||||
*has_usage_info_entries = false;
|
||||
*usage_table_header = stored_table_info.usage_table_header();
|
||||
usage_entry_info_list->clear();
|
||||
usage_entry_info_list->reserve(stored_table_info.usage_entry_info_size());
|
||||
|
||||
*usage_table_header = usage_table_info.usage_table_header();
|
||||
usage_entry_info->resize(usage_table_info.usage_entry_info_size());
|
||||
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].last_use_time = info.last_use_time();
|
||||
(*usage_entry_info)[i].offline_license_expiry_time =
|
||||
info.offline_license_expiry_time();
|
||||
break;
|
||||
case UsageTableInfo_UsageEntryInfo_UsageEntryStorage_USAGE_INFO:
|
||||
(*usage_entry_info)[i].storage_type = kStorageTypeUnknown;
|
||||
*has_usage_info_entries = true;
|
||||
break;
|
||||
case UsageTableInfo_UsageEntryInfo_UsageEntryStorage_UNKNOWN:
|
||||
default:
|
||||
(*usage_entry_info)[i].storage_type = kStorageTypeUnknown;
|
||||
break;
|
||||
for (const auto& stored_entry_info : stored_table_info.usage_entry_info()) {
|
||||
CdmUsageEntryInfo entry_info;
|
||||
entry_info.Clear();
|
||||
if (stored_entry_info.storage() == UsageEntryInfo::LICENSE) {
|
||||
entry_info.SetKeySetId(stored_entry_info.key_set_id());
|
||||
entry_info.SetLastUseTime(stored_entry_info.last_use_time());
|
||||
entry_info.SetLicenseExpiryTime(
|
||||
stored_entry_info.offline_license_expiry_time());
|
||||
} else if (stored_entry_info.storage() == UsageEntryInfo::USAGE_INFO) {
|
||||
// USAGE_INFO are deprecated, do not retrieve this entries.
|
||||
*has_usage_info_entries = true;
|
||||
}
|
||||
usage_entry_info_list->emplace_back(std::move(entry_info));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2133,14 +1501,6 @@ 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
@@ -95,19 +95,6 @@ const char* CdmOfflineLicenseStateToString(
|
||||
return UnknownValueRep(license_state);
|
||||
}
|
||||
|
||||
const char* CdmUsageEntryStorageTypeToString(CdmUsageEntryStorageType type) {
|
||||
switch (type) {
|
||||
case kStorageLicense:
|
||||
return "License";
|
||||
case kStorageUsageInfo:
|
||||
return "UsageInfo";
|
||||
case kStorageTypeUnknown:
|
||||
// Special value used to indicate an empty entry.
|
||||
return "None";
|
||||
}
|
||||
return UnknownValueRep(type);
|
||||
}
|
||||
|
||||
const char* RequestedSecurityLevelToString(
|
||||
RequestedSecurityLevel security_level) {
|
||||
switch (security_level) {
|
||||
|
||||
Reference in New Issue
Block a user