Consolidate update usage table calls
[ Merge of http://go/wvgerrit/23980 ] In OEMCrypto version 13, usage information is updated by calls to OEMCrypto_UpdateUsageEntry. In previous versions calls were made to OEMCrypto_UpdateUsageTable instead. Both need to be supported as the OEMCrypto version may vary by device. This consolidates calls to OEMCrypto_UpdateUsageTable so that they can be disabled if OEMCrypto version >= 13. No functional changes other than disabling by OEMCrypto version were introduced in this section. Helper routines have been added to device files as well. b/34327459 Test: Verified by unit, integration tests on angler Change-Id: If5d4bbbe7589e7cc1094999ba21f727eb6c92c3b
This commit is contained in:
@@ -430,28 +430,25 @@ CdmResponseType CryptoSession::Open(SecurityLevel requested_security_level) {
|
||||
void CryptoSession::Close() {
|
||||
LOGV("CloseSession: id=%ld open=%s", (uint32_t)oec_session_id_,
|
||||
open_ ? "true" : "false");
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
if (!open_) return;
|
||||
|
||||
OEMCryptoResult close_sts;
|
||||
M_TIME(
|
||||
close_sts = OEMCrypto_CloseSession(
|
||||
oec_session_id_),
|
||||
metrics_,
|
||||
oemcrypto_close_session_,
|
||||
close_sts);
|
||||
if (OEMCrypto_SUCCESS == close_sts) {
|
||||
open_ = false;
|
||||
if (update_usage_table_after_close_session_) {
|
||||
OEMCryptoResult update_sts;
|
||||
M_TIME(
|
||||
update_sts = OEMCrypto_UpdateUsageTable(),
|
||||
metrics_,
|
||||
oemcrypto_update_usage_table_,
|
||||
update_sts);
|
||||
if ( update_sts != OEMCrypto_SUCCESS)
|
||||
LOGW("CryptoSession::Close: OEMCrypto_UpdateUsageTable error=%ld", update_sts);
|
||||
}
|
||||
bool update_usage_table = false;
|
||||
{
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
if (!open_) return;
|
||||
|
||||
M_TIME(
|
||||
close_sts = OEMCrypto_CloseSession(
|
||||
oec_session_id_),
|
||||
metrics_,
|
||||
oemcrypto_close_session_,
|
||||
close_sts);
|
||||
if (OEMCrypto_SUCCESS == close_sts)
|
||||
open_ = false;
|
||||
update_usage_table = update_usage_table_after_close_session_;
|
||||
}
|
||||
if (close_sts == OEMCrypto_SUCCESS && update_usage_table) {
|
||||
UpdateUsageInformation();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -623,27 +620,25 @@ CdmResponseType CryptoSession::LoadKeys(
|
||||
metrics_,
|
||||
oemcrypto_load_keys_,
|
||||
sts);
|
||||
CdmResponseType result = KEY_ADDED;
|
||||
if (OEMCrypto_SUCCESS == sts) {
|
||||
if (!provider_session_token.empty()) {
|
||||
if (!provider_session_token.empty())
|
||||
update_usage_table_after_close_session_ = true;
|
||||
M_TIME(
|
||||
sts = OEMCrypto_UpdateUsageTable(),
|
||||
metrics_,
|
||||
oemcrypto_update_usage_table_,
|
||||
sts);
|
||||
if (sts != OEMCrypto_SUCCESS) {
|
||||
LOGW("CryptoSession::LoadKeys: OEMCrypto_UpdateUsageTable error=%ld",
|
||||
sts);
|
||||
}
|
||||
}
|
||||
return KEY_ADDED;
|
||||
result = KEY_ADDED;
|
||||
} else if (OEMCrypto_ERROR_TOO_MANY_KEYS == sts) {
|
||||
LOGE("CryptoSession::LoadKeys: OEMCrypto_LoadKeys error=%d", sts);
|
||||
return INSUFFICIENT_CRYPTO_RESOURCES;
|
||||
result = INSUFFICIENT_CRYPTO_RESOURCES;
|
||||
} else {
|
||||
LOGE("CryptoSession::LoadKeys: OEMCrypto_LoadKeys error=%d", sts);
|
||||
return LOAD_KEY_ERROR;
|
||||
result = LOAD_KEY_ERROR;
|
||||
}
|
||||
|
||||
// Leaving critical section
|
||||
crypto_lock_.Release();
|
||||
|
||||
if (!provider_session_token.empty())
|
||||
UpdateUsageInformation();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CryptoSession::LoadCertificatePrivateKey(std::string& wrapped_key) {
|
||||
@@ -1053,6 +1048,13 @@ CdmResponseType CryptoSession::UpdateUsageInformation() {
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
if (!initialized_) return UNKNOWN_ERROR;
|
||||
|
||||
CdmUsageSupportType usage_support_type;
|
||||
if (GetUsageSupportType(&usage_support_type) == NO_ERROR &&
|
||||
usage_support_type == kUsageEntrySupport) {
|
||||
LOGV("UpdateUsageInformation: deprecated for OEMCrypto v13+");
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
OEMCryptoResult status;
|
||||
M_TIME(
|
||||
status = OEMCrypto_UpdateUsageTable(),
|
||||
@@ -1207,40 +1209,34 @@ CdmResponseType CryptoSession::ReleaseUsageInformation(
|
||||
const std::string& message, const std::string& signature,
|
||||
const std::string& provider_session_token) {
|
||||
LOGV("ReleaseUsageInformation: id=%ld", (uint32_t)oec_session_id_);
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
const uint8_t* msg = reinterpret_cast<const uint8_t*>(message.data());
|
||||
const uint8_t* sig = reinterpret_cast<const uint8_t*>(signature.data());
|
||||
const uint8_t* pst = msg + GetOffset(message, provider_session_token);
|
||||
{
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
const uint8_t* msg = reinterpret_cast<const uint8_t*>(message.data());
|
||||
const uint8_t* sig = reinterpret_cast<const uint8_t*>(signature.data());
|
||||
const uint8_t* pst = msg + GetOffset(message, provider_session_token);
|
||||
|
||||
OEMCryptoResult status;
|
||||
M_TIME(
|
||||
status = OEMCrypto_DeleteUsageEntry(
|
||||
oec_session_id_,
|
||||
pst,
|
||||
provider_session_token.length(),
|
||||
msg,
|
||||
message.length(),
|
||||
sig,
|
||||
signature.length()),
|
||||
metrics_,
|
||||
oemcrypto_delete_usage_entry_,
|
||||
status);
|
||||
OEMCryptoResult status;
|
||||
M_TIME(
|
||||
status = OEMCrypto_DeleteUsageEntry(
|
||||
oec_session_id_,
|
||||
pst,
|
||||
provider_session_token.length(),
|
||||
msg,
|
||||
message.length(),
|
||||
sig,
|
||||
signature.length()),
|
||||
metrics_,
|
||||
oemcrypto_delete_usage_entry_,
|
||||
status);
|
||||
|
||||
if (OEMCrypto_SUCCESS != status) {
|
||||
LOGE("CryptoSession::ReleaseUsageInformation: Report Usage error=%ld",
|
||||
status);
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
M_TIME(
|
||||
status = OEMCrypto_UpdateUsageTable(),
|
||||
metrics_,
|
||||
oemcrypto_update_usage_table_,
|
||||
status);
|
||||
if (status != OEMCrypto_SUCCESS) {
|
||||
LOGW("CryptoSession::ReleaseUsageInformation: update table error=%ld",
|
||||
status);
|
||||
if (OEMCrypto_SUCCESS != status) {
|
||||
LOGE("CryptoSession::ReleaseUsageInformation: Report Usage error=%ld",
|
||||
status);
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
UpdateUsageInformation();
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -1249,28 +1245,22 @@ CdmResponseType CryptoSession::DeleteUsageInformation(
|
||||
CdmResponseType response = NO_ERROR;
|
||||
LOGV("CryptoSession::DeleteUsageInformation");
|
||||
OEMCryptoResult status;
|
||||
M_TIME(
|
||||
status = OEMCrypto_ForceDeleteUsageEntry(
|
||||
reinterpret_cast<const uint8_t*>(provider_session_token.c_str()),
|
||||
provider_session_token.length()),
|
||||
metrics_,
|
||||
oemcrypto_force_delete_usage_entry_,
|
||||
status);
|
||||
if (OEMCrypto_SUCCESS != status) {
|
||||
LOGE("CryptoSession::DeleteUsageInformation: Delete Usage Table error =%ld",
|
||||
status);
|
||||
response = UNKNOWN_ERROR;
|
||||
}
|
||||
M_TIME(
|
||||
status = OEMCrypto_UpdateUsageTable(),
|
||||
metrics_,
|
||||
oemcrypto_update_usage_table_,
|
||||
status);
|
||||
if (status != OEMCrypto_SUCCESS) {
|
||||
LOGE("CryptoSession::DeleteUsageInformation: update table error=%ld",
|
||||
status);
|
||||
response = UNKNOWN_ERROR;
|
||||
{
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
M_TIME(
|
||||
status = OEMCrypto_ForceDeleteUsageEntry(
|
||||
reinterpret_cast<const uint8_t*>(provider_session_token.c_str()),
|
||||
provider_session_token.length()),
|
||||
metrics_,
|
||||
oemcrypto_force_delete_usage_entry_,
|
||||
status);
|
||||
if (OEMCrypto_SUCCESS != status) {
|
||||
LOGE("CryptoSession::DeleteUsageInformation: Delete Usage Table error "
|
||||
"= %ld", status);
|
||||
response = UNKNOWN_ERROR;
|
||||
}
|
||||
}
|
||||
UpdateUsageInformation();
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -1278,58 +1268,46 @@ CdmResponseType CryptoSession::DeleteMultipleUsageInformation(
|
||||
const std::vector<std::string>& provider_session_tokens) {
|
||||
LOGV("CryptoSession::DeleteMultipleUsageInformation");
|
||||
CdmResponseType response = NO_ERROR;
|
||||
for (size_t i=0; i < provider_session_tokens.size(); ++i) {
|
||||
OEMCryptoResult status;
|
||||
M_TIME(
|
||||
status = OEMCrypto_ForceDeleteUsageEntry(
|
||||
reinterpret_cast<const uint8_t*>(provider_session_tokens[i].c_str()),
|
||||
provider_session_tokens[i].length()),
|
||||
metrics_,
|
||||
oemcrypto_force_delete_usage_entry_,
|
||||
status);
|
||||
if (OEMCrypto_SUCCESS != status) {
|
||||
LOGW("CryptoSession::DeleteMultipleUsageInformation: "
|
||||
"Delete Usage Table error =%ld", status);
|
||||
response = UNKNOWN_ERROR;
|
||||
{
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
for (size_t i=0; i < provider_session_tokens.size(); ++i) {
|
||||
OEMCryptoResult status;
|
||||
M_TIME(
|
||||
status = OEMCrypto_ForceDeleteUsageEntry(
|
||||
reinterpret_cast<const uint8_t*>(
|
||||
provider_session_tokens[i].c_str()),
|
||||
provider_session_tokens[i].length()),
|
||||
metrics_,
|
||||
oemcrypto_force_delete_usage_entry_,
|
||||
status);
|
||||
if (OEMCrypto_SUCCESS != status) {
|
||||
LOGW("CryptoSession::DeleteMultipleUsageInformation: "
|
||||
"Delete Usage Table error =%ld", status);
|
||||
response = UNKNOWN_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
OEMCryptoResult status;
|
||||
M_TIME(
|
||||
status = OEMCrypto_UpdateUsageTable(),
|
||||
metrics_,
|
||||
oemcrypto_update_usage_table_,
|
||||
status);
|
||||
if (status != OEMCrypto_SUCCESS) {
|
||||
LOGE("CryptoSession::DeleteMultipleUsageInformation: update table error=%ld",
|
||||
status);
|
||||
response = UNKNOWN_ERROR;
|
||||
}
|
||||
UpdateUsageInformation();
|
||||
return response;
|
||||
}
|
||||
|
||||
CdmResponseType CryptoSession::DeleteAllUsageReports() {
|
||||
LOGV("DeleteAllUsageReports");
|
||||
OEMCryptoResult status;
|
||||
M_TIME(
|
||||
status = OEMCrypto_DeleteOldUsageTable(),
|
||||
metrics_,
|
||||
oemcrypto_delete_usage_table_,
|
||||
status);
|
||||
if (OEMCrypto_SUCCESS != status) {
|
||||
LOGE("CryptoSession::DeleteAllUsageReports: Delete Usage Table error =%ld",
|
||||
status);
|
||||
{
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
M_TIME(
|
||||
status = OEMCrypto_DeleteOldUsageTable(),
|
||||
metrics_,
|
||||
oemcrypto_delete_usage_table_,
|
||||
status);
|
||||
if (OEMCrypto_SUCCESS != status) {
|
||||
LOGE("CryptoSession::DeleteAllUsageReports: Delete Usage Table error "
|
||||
"=%ld", status);
|
||||
}
|
||||
}
|
||||
|
||||
M_TIME(
|
||||
status = OEMCrypto_UpdateUsageTable(),
|
||||
metrics_,
|
||||
oemcrypto_update_usage_table_,
|
||||
status);
|
||||
if (status != OEMCrypto_SUCCESS) {
|
||||
LOGE("CryptoSession::DeletaAllUsageReports: update table error=%ld",
|
||||
status);
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
UpdateUsageInformation();
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -1879,7 +1857,7 @@ CdmResponseType CryptoSession::CreateUsageTableHeader(
|
||||
}
|
||||
|
||||
if (result != OEMCrypto_SUCCESS) {
|
||||
LOGE("CreateUsageTableHeader; usage table header creation failed: %d",
|
||||
LOGE("CreateUsageTableHeader: usage table header creation failed: %d",
|
||||
result);
|
||||
return CREATE_USAGE_TABLE_ERROR;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user