Address CE CDM test failures and code review comments

The android CL ag/13947818 was submitted before some CE CDM test
failures were noticed and code review comments were received.

Bug: 184813991
Test: WV unit/integration test
Change-Id: Ic31ca5bc5e46994e01eca56248e6bdffedd779f3
This commit is contained in:
Rahul Frias
2021-04-08 01:30:47 -07:00
parent 985d0b5129
commit d802baa4d4
5 changed files with 53 additions and 51 deletions

View File

@@ -230,7 +230,8 @@ class CdmSession {
const std::string& certificate,
const CryptoWrappedKey& wrapped_private_key);
CdmResponseType LoadPrivateKey(const CryptoWrappedKey& wrapped_private_key);
CdmResponseType LoadPrivateKey(const std::string& certificate,
const CryptoWrappedKey& wrapped_private_key);
bool GenerateKeySetId(bool atsc_mode_enabled, CdmKeySetId* key_set_id);

View File

@@ -172,6 +172,9 @@ CdmResponseType CdmSession::Init(CdmClientPropertySet* cdm_client_property_set,
if (cdm_client_property_set != nullptr)
atsc_mode_enabled_ = cdm_client_property_set->use_atsc_mode();
// If a DRM certificate does not exist, indicate that provisioning is needed.
// The actual validation and loading of a certificate will happen when
// a key request is generated or an offline license is loaded.
if (!file_handle_->HasCertificate(atsc_mode_enabled_))
return NEED_PROVISIONING;
@@ -1251,31 +1254,14 @@ CdmResponseType CdmSession::LoadPrivateKey() {
return NEED_PROVISIONING;
}
CdmResponseType status = LoadPrivateKey(private_key);
if (status == NO_ERROR) {
drm_certificate_ = drm_certificate;
wrapped_private_key_.set_type(private_key.type());
wrapped_private_key_.set_key(private_key.key());
}
return status;
return LoadPrivateKey(drm_certificate, private_key);
}
CdmResponseType CdmSession::LoadPrivateOrLegacyKey(
const std::string& certificate, const CryptoWrappedKey& private_key) {
// Use provided key if valid
if (!certificate.empty() && private_key.IsValid()) {
CdmResponseType status = LoadPrivateKey(private_key);
if (status == NO_ERROR) {
drm_certificate_ = certificate;
wrapped_private_key_.set_type(private_key.type());
wrapped_private_key_.set_key(private_key.key());
}
return status;
}
if (!certificate.empty() && private_key.IsValid())
return LoadPrivateKey(certificate, private_key);
// Otherwise use key from legacy certificate
std::string drm_certificate;
@@ -1285,19 +1271,11 @@ CdmResponseType CdmSession::LoadPrivateOrLegacyKey(
DeviceFiles::kCertificateValid)
return NEED_PROVISIONING;
CdmResponseType status = LoadPrivateKey(wrapped_private_key);
if (status == NO_ERROR) {
drm_certificate_ = drm_certificate;
wrapped_private_key_.set_type(wrapped_private_key.type());
wrapped_private_key_.set_key(wrapped_private_key.key());
}
return status;
return LoadPrivateKey(drm_certificate, wrapped_private_key);
}
CdmResponseType CdmSession::LoadPrivateKey(
const CryptoWrappedKey& private_key) {
const std::string& drm_certificate, const CryptoWrappedKey& private_key) {
CdmResponseType load_cert_sts;
M_TIME(
load_cert_sts = crypto_session_->LoadCertificatePrivateKey(private_key),
@@ -1308,6 +1286,9 @@ CdmResponseType CdmSession::LoadPrivateKey(
case NO_ERROR:
metrics_->drm_certificate_key_type_.Record(
DrmKeyTypeToMetricValue(private_key.type()));
drm_certificate_ = drm_certificate;
wrapped_private_key_ = std::move(private_key);
return NO_ERROR;
case SESSION_LOST_STATE_ERROR:
case SYSTEM_INVALIDATED_ERROR:

View File

@@ -127,8 +127,8 @@ 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();
const bool has_certificate = device_certificate.has_certificate();
const bool has_key = device_certificate.has_wrapped_private_key();
// If no certificate information, nothing to be done. DeviceCertificate
// is a legacy DRM certificate

View File

@@ -397,16 +397,36 @@ void WvCdmTestBase::Provision() {
void WvCdmTestBase::EnsureProvisioned() {
CdmSessionId session_id;
FileSystem file_system;
// OpenSession will check if a DRM certificate exists, while
// GenerateKeyRequest will actually load the wrapped private key.
// Either may return a NEED_PROVISIONING error, so both have to be checked.
TestCdmEngine cdm_engine(&file_system,
std::shared_ptr<EngineMetrics>(new EngineMetrics));
CdmResponseType status = cdm_engine.OpenSession(config_.key_system(), nullptr,
nullptr, &session_id);
CdmAppParameterMap app_parameters;
CdmKeySetId key_set_id;
InitializationData init_data(ISO_BMFF_VIDEO_MIME_TYPE, binary_key_id());
CdmKeyRequest key_request;
if (status == NO_ERROR) {
status = cdm_engine.GenerateKeyRequest(session_id, key_set_id, init_data,
kLicenseTypeStreaming,
app_parameters, &key_request);
}
if (status == NEED_PROVISIONING) {
Provision();
status = cdm_engine.OpenSession(config_.key_system(), nullptr, nullptr,
&session_id);
ASSERT_EQ(NO_ERROR, status);
status = cdm_engine.GenerateKeyRequest(session_id, key_set_id, init_data,
kLicenseTypeStreaming,
app_parameters, &key_request);
ASSERT_EQ(KEY_MESSAGE, status);
}
ASSERT_EQ(NO_ERROR, status);
ASSERT_EQ(KEY_MESSAGE, status);
ASSERT_NE("", session_id) << "Could not open CDM session.";
ASSERT_TRUE(cdm_engine.IsOpenSession(session_id));
ASSERT_EQ(NO_ERROR, cdm_engine.CloseSession(session_id));