Renaming of Usage Table related variables and types.

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

This CL makes major changes to the names of variables and types that
are related to the usage table, header, entries, entry indexes, and
other related data.

The renaming followed these rules:
1)  "Usage table header" will exclusively refer to the header blob
    that is OEMCrypto specific.  The CDM class "UsageTableHeader"
    is the CDM-layer's abstraction around the "usage table" concept.
    The name has been updated to reflect that.
2)  The "Cdm" prefix is only used for the CDM-specific data types for
    the usage table and entry info.  It has been removed from
    OEMCrypto-specific types.
    - UsageTableHeader -> CdmUsageTable
    - CdmUsageTableHeader -> UsageTableHeader
    - CdmUsageEntry -> UsageEntry
3)  The "usage_" prefix has been removed from variables when the usage
    table or usage entries are the subject of the function or class.
4)  UsageEntryIndex is the type for entry indexes, instead of directly
    using uint32_t.  This matches how we wrap other types in
    "wv_cdm_types.h"
5)  Changed entry "number" to entry "index".
6)  Vectors of elements have been renamed to be either pluralized or
    have a suffix "_list".
7)  "Usage info" was occasionally being used to refer to the usage
    table or entries generally, rather than specifically secure-stop.
    - CryptoSession::HasUsageInfoSupport() -> HasUsageTableSupport()

The most major change is that the files "usage_table_header*" have
been renamed to be "cdm_usage_table*".

Bug: 242914226
Test: run_x86_64_tests and request_license_test
Change-Id: Iee98446b71f4f2934d3c9e0fb949eb05b84d1f8c
This commit is contained in:
Alex Dale
2022-12-20 15:21:10 -08:00
parent 0080d04579
commit 1603ba127f
24 changed files with 1321 additions and 1382 deletions

View File

@@ -17,6 +17,7 @@
#include "advance_iv_ctr.h"
#include "arraysize.h"
#include "cdm_random.h"
#include "cdm_usage_table.h"
#include "content_key_session.h"
#include "crypto_key.h"
#include "entitlement_key_session.h"
@@ -28,7 +29,6 @@
#include "properties.h"
#include "pst_report.h"
#include "string_conversions.h"
#include "usage_table_header.h"
#include "wv_cdm_constants.h"
// Stringify turns macro arguments into static C strings.
@@ -211,8 +211,8 @@ bool CryptoSession::initialized_ = false;
bool CryptoSession::needs_keybox_provisioning_ = false;
int CryptoSession::session_count_ = 0;
int CryptoSession::termination_counter_ = 0;
std::unique_ptr<UsageTableHeader> CryptoSession::usage_table_header_l1_;
std::unique_ptr<UsageTableHeader> CryptoSession::usage_table_header_l3_;
std::unique_ptr<CdmUsageTable> CryptoSession::usage_table_l1_;
std::unique_ptr<CdmUsageTable> CryptoSession::usage_table_l3_;
std::recursive_mutex CryptoSession::usage_table_mutex_;
std::atomic<uint64_t> CryptoSession::request_id_index_source_(0);
std::unique_ptr<okp::SystemFallbackPolicy>
@@ -400,8 +400,8 @@ void CryptoSession::ReinitializeForTest() {
}
initialized_ = false;
// Tables will be reinitialized by tests when needed.
usage_table_header_l1_.reset();
usage_table_header_l3_.reset();
usage_table_l1_.reset();
usage_table_l3_.reset();
}
// Give up if we cannot initialize at all.
const OEMCryptoResult status = OEMCrypto_Initialize();
@@ -479,8 +479,8 @@ bool CryptoSession::TryTerminate() {
});
if (terminated) {
UsageTableLock lock(usage_table_mutex_);
usage_table_header_l1_.reset();
usage_table_header_l3_.reset();
usage_table_l1_.reset();
usage_table_l3_.reset();
}
return terminated;
}
@@ -491,9 +491,9 @@ void CryptoSession::DisableDelayedTermination() {
[&] { termination_counter_ = 0; });
}
bool CryptoSession::SetUpUsageTableHeader(
bool CryptoSession::SetUpUsageTable(
RequestedSecurityLevel requested_security_level) {
if (usage_table_header_ != nullptr) {
if (usage_table_ != nullptr) {
LOGE("Usage table is already set up for the current crypto session");
return false;
}
@@ -508,7 +508,7 @@ bool CryptoSession::SetUpUsageTableHeader(
// Check if usage support is available.
bool supports_usage_table = false;
if (!HasUsageInfoSupport(requested_security_level, &supports_usage_table)) {
if (!HasUsageTableSupport(requested_security_level, &supports_usage_table)) {
metrics_->oemcrypto_usage_table_support_.SetError(
USAGE_INFORMATION_SUPPORT_FAILED);
return false;
@@ -519,30 +519,28 @@ bool CryptoSession::SetUpUsageTableHeader(
return false;
}
LOGV("Usage table lock: SetUpUsageTableHeader()");
LOGV("Usage table lock: SetUpUsageTable()");
UsageTableLock auto_lock(usage_table_mutex_);
// TODO(b/141350978): Prevent any recursive logic.
// Manipulate only the usage table for the requested security level.
std::unique_ptr<UsageTableHeader>& header = security_level == kSecurityLevelL1
? usage_table_header_l1_
: usage_table_header_l3_;
if (!header) {
std::unique_ptr<CdmUsageTable>& table =
security_level == kSecurityLevelL1 ? usage_table_l1_ : usage_table_l3_;
if (!table) {
// This may be called twice within the same thread when the table
// is initialized. On the second call |header| will not be null,
// causing this block to be skipped.
header.reset(new UsageTableHeader());
if (!header->Init(security_level, this)) {
table.reset(new CdmUsageTable());
if (!table->Init(security_level, this)) {
LOGE("Failed to initialize and sync usage usage table");
// Must be cleared globally to prevent the next session to be
// opened from using the invalid UsageTableHeader.
header.reset();
// opened from using the invalid CdmUsageTable.
table.reset();
return false;
}
}
usage_table_header_ = header.get();
metrics_->usage_table_header_initial_size_.Record(
usage_table_header_->size());
usage_table_ = table.get();
metrics_->usage_table_header_initial_size_.Record(usage_table_->size());
return true;
}
@@ -890,7 +888,7 @@ CdmResponseType CryptoSession::Open(
RETURN_IF_UNINITIALIZED(CRYPTO_SESSION_NOT_INITIALIZED);
if (open_) return CdmResponseType(NO_ERROR);
if (!SetUpUsageTableHeader(requested_security_level)) {
if (!SetUpUsageTable(requested_security_level)) {
// Ignore errors since we do not know when a session is opened,
// if it is intended to be used for offline/usage session related
// or otherwise.
@@ -962,7 +960,7 @@ void CryptoSession::Close() {
metrics_->oemcrypto_close_session_.Increment(close_sts);
// Clear cached values.
has_usage_info_support_ = kBooleanUnset;
has_usage_table_support_ = kBooleanUnset;
oem_token_.clear();
system_id_ = NULL_SYSTEM_ID;
pre_provision_token_type_ = kClientTokenUninitialized;
@@ -975,7 +973,7 @@ void CryptoSession::Close() {
case OEMCrypto_SUCCESS:
case OEMCrypto_ERROR_INVALID_SESSION:
case OEMCrypto_ERROR_SYSTEM_INVALIDATED:
usage_table_header_ = nullptr;
usage_table_ = nullptr;
open_ = false;
break;
case OEMCrypto_ERROR_CLOSE_SESSION_FAILED:
@@ -1837,38 +1835,38 @@ CdmResponseType CryptoSession::Decrypt(
}
}
bool CryptoSession::HasUsageInfoSupport(bool* has_support) {
bool CryptoSession::HasUsageTableSupport(bool* has_support) {
RETURN_IF_NOT_OPEN(false);
RETURN_IF_NULL(has_support, false);
return WithOecReadLock("HasUsageInfoSupport", [&] {
return WithOecReadLock("HasUsageTableSupport", [&] {
// Use cached value if set.
if (has_usage_info_support_ != kBooleanUnset) {
*has_support = (has_usage_info_support_ == kBooleanTrue);
if (has_usage_table_support_ != kBooleanUnset) {
*has_support = (has_usage_table_support_ == kBooleanTrue);
return true;
}
if (!HasUsageInfoSupportInternal(requested_security_level_, has_support)) {
if (!HasUsageTableSupportInternal(requested_security_level_, has_support)) {
return false;
}
// Cache result if successful.
has_usage_info_support_ = (*has_support ? kBooleanTrue : kBooleanFalse);
has_usage_table_support_ = (*has_support ? kBooleanTrue : kBooleanFalse);
return true;
});
}
bool CryptoSession::HasUsageInfoSupport(
bool CryptoSession::HasUsageTableSupport(
RequestedSecurityLevel requested_security_level, bool* has_support) {
RETURN_IF_UNINITIALIZED(false);
RETURN_IF_NULL(has_support, false);
return WithOecReadLock("HasUsageInfoSupport", [&] {
return HasUsageInfoSupportInternal(requested_security_level, has_support);
return WithOecReadLock("HasUsageTableSupport", [&] {
return HasUsageTableSupportInternal(requested_security_level, has_support);
});
}
bool CryptoSession::HasUsageInfoSupportInternal(
bool CryptoSession::HasUsageTableSupportInternal(
RequestedSecurityLevel requested_security_level, bool* has_support) {
LOGV("requested_security_level = %s",
RequestedSecurityLevelToString(requested_security_level));
*has_support = WithOecReadLock("HasUsageInfoSupport", [&] {
*has_support = WithOecReadLock("HasUsageTableSupport", [&] {
return OEMCrypto_SupportsUsageTable(requested_security_level);
});
return true;
@@ -2646,7 +2644,7 @@ CdmResponseType CryptoSession::GenericVerify(const std::string& message,
CdmResponseType CryptoSession::CreateUsageTableHeader(
RequestedSecurityLevel requested_security_level,
CdmUsageTableHeader* usage_table_header) {
UsageTableHeader* usage_table_header) {
LOGV("Creating usage table header: requested_security_level = %s",
RequestedSecurityLevelToString(requested_security_level));
RETURN_IF_NULL(usage_table_header, PARAMETER_NULL);
@@ -2687,7 +2685,7 @@ CdmResponseType CryptoSession::CreateUsageTableHeader(
CdmResponseType CryptoSession::LoadUsageTableHeader(
RequestedSecurityLevel requested_security_level,
const CdmUsageTableHeader& usage_table_header) {
const UsageTableHeader& usage_table_header) {
LOGV("Loading usage table header: requested_security_level = %s",
RequestedSecurityLevelToString(requested_security_level));
@@ -2728,7 +2726,7 @@ CdmResponseType CryptoSession::LoadUsageTableHeader(
CdmResponseType CryptoSession::ShrinkUsageTableHeader(
RequestedSecurityLevel requested_security_level, uint32_t new_entry_count,
CdmUsageTableHeader* usage_table_header) {
UsageTableHeader* usage_table_header) {
LOGV("Shrinking usage table header: requested_security_level = %s",
RequestedSecurityLevelToString(requested_security_level));
RETURN_IF_NULL(usage_table_header, PARAMETER_NULL);
@@ -2766,14 +2764,14 @@ CdmResponseType CryptoSession::ShrinkUsageTableHeader(
}
}
CdmResponseType CryptoSession::CreateUsageEntry(uint32_t* entry_number) {
CdmResponseType CryptoSession::CreateUsageEntry(UsageEntryIndex* entry_index) {
LOGV("Creating usage entry: id = %u", oec_session_id_);
RETURN_IF_NULL(entry_number, PARAMETER_NULL);
RETURN_IF_NULL(entry_index, PARAMETER_NULL);
OEMCryptoResult result;
WithOecWriteLock("CreateUsageEntry", [&] {
result = OEMCrypto_CreateNewUsageEntry(oec_session_id_, entry_number);
result = OEMCrypto_CreateNewUsageEntry(oec_session_id_, entry_index);
metrics_->oemcrypto_create_new_usage_entry_.Increment(result);
});
@@ -2796,14 +2794,14 @@ CdmResponseType CryptoSession::CreateUsageEntry(uint32_t* entry_number) {
}
}
CdmResponseType CryptoSession::LoadUsageEntry(
uint32_t entry_number, const CdmUsageEntry& usage_entry) {
CdmResponseType CryptoSession::LoadUsageEntry(UsageEntryIndex entry_index,
const UsageEntry& usage_entry) {
LOGV("Loading usage entry: id = %u", oec_session_id_);
OEMCryptoResult result;
WithOecWriteLock("LoadUsageEntry", [&] {
result = OEMCrypto_LoadUsageEntry(
oec_session_id_, entry_number,
oec_session_id_, entry_index,
reinterpret_cast<const uint8_t*>(usage_entry.data()),
usage_entry.size());
metrics_->oemcrypto_load_usage_entry_.Increment(result);
@@ -2839,7 +2837,7 @@ CdmResponseType CryptoSession::LoadUsageEntry(
}
CdmResponseType CryptoSession::UpdateUsageEntry(
CdmUsageTableHeader* usage_table_header, CdmUsageEntry* usage_entry) {
UsageTableHeader* usage_table_header, UsageEntry* usage_entry) {
LOGV("Updating usage entry: id = %u", oec_session_id_);
RETURN_IF_NULL(usage_table_header, PARAMETER_NULL);
@@ -2880,19 +2878,19 @@ CdmResponseType CryptoSession::UpdateUsageEntry(
"UpdateUsageEntry");
}
CdmResponseType CryptoSession::MoveUsageEntry(uint32_t new_entry_number) {
CdmResponseType CryptoSession::MoveUsageEntry(UsageEntryIndex new_entry_index) {
LOGV("Moving usage entry: id = %u", oec_session_id_);
OEMCryptoResult result;
WithOecWriteLock("MoveUsageEntry", [&] {
result = OEMCrypto_MoveEntry(oec_session_id_, new_entry_number);
result = OEMCrypto_MoveEntry(oec_session_id_, new_entry_index);
metrics_->oemcrypto_move_entry_.Increment(result);
});
switch (result) {
case OEMCrypto_ERROR_ENTRY_IN_USE:
LOGW("OEMCrypto_MoveEntry failed: Destination index in use: index = %u",
new_entry_number);
new_entry_index);
return CRYPTO_ERROR(MOVE_USAGE_ENTRY_DESTINATION_IN_USE, result);
default:
return MapOEMCryptoResult(result, MOVE_USAGE_ENTRY_UNKNOWN_ERROR,