Add certificate information to offline licenses

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

Offline licenses will now store the DRM certificate information. This
allows for expired certificates to be deleted and replaced without
losing the ability to use offline licenses.

Bug: 169740403
Test: WV unit/integration tests
      DeviceFilesTest.RetrieveLicenses
      DeviceFilesTest.StoreLicenses
Change-Id: Ic0de6328d32e0000d1b58c81019e6c2227278cc4
This commit is contained in:
Rahul Frias
2021-03-19 23:26:54 -07:00
parent f6b4d140f4
commit 57ebb70fe7
5 changed files with 391 additions and 38 deletions

View File

@@ -1042,6 +1042,7 @@ CdmResponseType CdmSession::StoreLicense() {
bool CdmSession::StoreLicense(DeviceFiles::LicenseState state,
int* error_detail) {
DeviceFiles::ResponseType error_detail_alt = DeviceFiles::kNoError;
std::string drm_certificate;
DeviceFiles::CdmLicenseData license_data{
key_set_id_,
state,
@@ -1056,7 +1057,9 @@ bool CdmSession::StoreLicense(DeviceFiles::LicenseState state,
policy_engine_->GetGracePeriodEndTime(),
app_parameters_,
usage_entry_,
usage_entry_number_};
usage_entry_number_,
drm_certificate,
CryptoWrappedKey()};
bool result = file_handle_->StoreLicense(license_data, &error_detail_alt);
if (error_detail != nullptr) {

View File

@@ -86,11 +86,13 @@ using video_widevine_client::sdk::
namespace {
const char kHlsAttributesFileNameExt[] = ".hal";
const char kUsageInfoFileNamePrefix[] = "usage";
const char kUsageInfoFileNameExt[] = ".bin";
const char kLicenseFileNameExt[] = ".lic";
const char kEmptyFileName[] = "";
const char kFalse[] = "false";
const char kHlsAttributesFileNameExt[] = ".hal";
const char kLicenseFileNameExt[] = ".lic";
const char kTrue[] = "true";
const char kUsageInfoFileNameExt[] = ".bin";
const char kUsageInfoFileNamePrefix[] = "usage";
const char kUsageTableFileName[] = "usgtable.bin";
const char kWildcard[] = "*";
constexpr int64_t kFourMonthsInSeconds = (2 * 30 + 2 * 31) * 24 * 60 * 60;
@@ -124,6 +126,22 @@ bool ExtractFromDeviceCertificate(const DeviceCertificate& device_certificate,
RETURN_FALSE_IF_NULL(certificate);
RETURN_FALSE_IF_NULL(private_key);
bool has_certificate = device_certificate.has_certificate();
bool has_key = device_certificate.has_wrapped_private_key();
// If no certificate information, nothing to be done. DeviceCertificate
// is a legacy DRM certificate
if (!has_certificate && !has_key) return true;
// Flag if not a default certificate
if (!(has_certificate && has_key)) {
LOGE(
"Device certificate proto belongs to neither a default or legacy cert. "
"has_certificate: %s, has_key: %s",
has_certificate ? kTrue : kFalse, has_key ? kTrue : kFalse);
return false;
}
*certificate = device_certificate.certificate();
private_key->Clear();
private_key->set_key(device_certificate.wrapped_private_key());
@@ -504,6 +522,13 @@ bool DeviceFiles::StoreLicense(const CdmLicenseData& license_data,
}
license->set_usage_entry(license_data.usage_entry);
license->set_usage_entry_number(license_data.usage_entry_number);
if (license_data.drm_certificate.size() > 0) {
DeviceCertificate* device_certificate = license->mutable_drm_certificate();
if (!SetDeviceCertificate(license_data.drm_certificate,
license_data.wrapped_private_key,
device_certificate))
return false;
}
std::string serialized_file;
file.SerializeToString(&serialized_file);
@@ -587,7 +612,16 @@ bool DeviceFiles::RetrieveLicense(const std::string& key_set_id,
}
license_data->usage_entry = license.usage_entry();
license_data->usage_entry_number = license.usage_entry_number();
return true;
if (!license.has_drm_certificate()) {
license_data->drm_certificate.clear();
license_data->wrapped_private_key.Clear();
return true;
}
return ExtractFromDeviceCertificate(license.drm_certificate(),
&license_data->drm_certificate,
&license_data->wrapped_private_key);
}
bool DeviceFiles::DeleteLicense(const std::string& key_set_id) {