Add a static method to query security level

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

This allows one to be able to query for security level, from
Crypto factory methods before the plugins and CdmEngine objects
have been created.

Bug: 117104043
Test: WV Unit/integration tests
Change-Id: Id07f420c3cfb92166cd3bb3cf82148d52e10eb03
This commit is contained in:
Rahul Frias
2019-01-17 16:53:12 -08:00
parent 81e77bda58
commit 45b3f5761e
5 changed files with 45 additions and 0 deletions

View File

@@ -151,6 +151,9 @@ class CdmEngine {
virtual CdmResponseType QueryKeyStatus(const CdmSessionId& session_id,
CdmQueryMap* query_response);
// Query security level support
static bool IsSecurityLevelSupported(CdmSecurityLevel level);
// Query the types of usage permitted for the specified key.
virtual CdmResponseType QueryKeyAllowedUsage(const CdmSessionId& session_id,
const std::string& key_id,

View File

@@ -815,6 +815,25 @@ CdmResponseType CdmEngine::QueryOemCryptoSessionId(
return session->QueryOemCryptoSessionId(query_response);
}
bool CdmEngine::IsSecurityLevelSupported(CdmSecurityLevel level) {
LOGI("CdmEngine::IsSecurityLevelSupported");
metrics::CryptoMetrics alternate_crypto_metrics;
std::unique_ptr<CryptoSession> crypto_session(
CryptoSession::MakeCryptoSession(&alternate_crypto_metrics));
switch (level) {
case kSecurityLevelL1:
return
crypto_session->GetSecurityLevel(kLevelDefault) == kSecurityLevelL1;
case kSecurityLevelL3:
return crypto_session->GetSecurityLevel(kLevel3) == kSecurityLevelL3;
default:
LOGE("CdmEngine::IsSecurityLevelSupported: Invalid security level: %d",
level);
return false;
}
}
/*
* Composes a device provisioning request and output the request in JSON format
* in *request. It also returns the default url for the provisioning server

View File

@@ -80,6 +80,9 @@ class WvContentDecryptionModule : public android::RefBase, public TimerHandler {
virtual CdmResponseType QueryOemCryptoSessionId(
const CdmSessionId& session_id, CdmQueryMap* response);
// Query security level support
static bool IsSecurityLevelSupported(CdmSecurityLevel level);
// Provisioning related methods
virtual CdmResponseType GetProvisioningRequest(
CdmCertificateType cert_type, const std::string& cert_authority,

View File

@@ -213,6 +213,11 @@ CdmResponseType WvContentDecryptionModule::QueryOemCryptoSessionId(
return cdm_engine->QueryOemCryptoSessionId(session_id, response);
}
bool WvContentDecryptionModule::IsSecurityLevelSupported(
CdmSecurityLevel level) {
return CdmEngine::IsSecurityLevelSupported(level);
}
CdmResponseType WvContentDecryptionModule::GetProvisioningRequest(
CdmCertificateType cert_type, const std::string& cert_authority,
const CdmIdentifier& identifier, const std::string& service_certificate,

View File

@@ -4291,6 +4291,21 @@ TEST_F(WvCdmRequestLicenseTest, QueryOemCryptoSessionId) {
decryptor_.CloseSession(session_id_);
}
TEST_F(WvCdmRequestLicenseTest, IsSecurityLevelSupported) {
// Level 1 may either be or not be supported. Invoking the method without
// imposing any expecations to make sure it completes.
bool is_supported = WvContentDecryptionModule::IsSecurityLevelSupported(
wvcdm::kSecurityLevelL1);
EXPECT_FALSE(WvContentDecryptionModule::IsSecurityLevelSupported(
wvcdm::kSecurityLevelL2));
EXPECT_TRUE(WvContentDecryptionModule::IsSecurityLevelSupported(
wvcdm::kSecurityLevelL3));
EXPECT_FALSE(WvContentDecryptionModule::IsSecurityLevelSupported(
wvcdm::kSecurityLevelUnknown));
EXPECT_FALSE(WvContentDecryptionModule::IsSecurityLevelSupported(
wvcdm::kSecurityLevelUninitialized));
}
TEST_F(WvCdmRequestLicenseTest, DISABLED_OfflineLicenseDecryptionTest) {
decryptor_.OpenSession(config_.key_system(), NULL, kDefaultCdmIdentifier, NULL,
&session_id_);