Merge "Simplify How Request ID Indices are Generated"

This commit is contained in:
John Bruce
2019-01-24 05:27:18 +00:00
committed by Android (Google) Code Review
4 changed files with 20 additions and 29 deletions

View File

@@ -78,9 +78,9 @@ namespace wvcdm {
std::mutex CryptoSession::crypto_lock_;
bool CryptoSession::initialized_ = false;
int CryptoSession::session_count_ = 0;
uint64_t CryptoSession::request_id_index_ = 0;
UsageTableHeader* CryptoSession::usage_table_header_l1_ = NULL;
UsageTableHeader* CryptoSession::usage_table_header_l3_ = NULL;
std::atomic<uint64_t> CryptoSession::request_id_index_source_(0);
size_t GetOffset(std::string message, std::string field) {
size_t pos = message.find(field);
@@ -167,7 +167,6 @@ CryptoSession::CryptoSession(metrics::CryptoMetrics* metrics)
is_usage_support_type_valid_(false),
usage_support_type_(kUnknownUsageSupport),
usage_table_header_(NULL),
request_id_base_(0),
cipher_mode_(kCipherModeCtr),
api_version_(0) {
assert(metrics);
@@ -749,10 +748,16 @@ CdmResponseType CryptoSession::Open(SecurityLevel requested_security_level) {
return LOAD_SYSTEM_ID_ERROR;
}
uint64_t request_id_base;
OEMCryptoResult random_sts = OEMCrypto_GetRandom(
reinterpret_cast<uint8_t*>(&request_id_base_), sizeof(request_id_base_));
reinterpret_cast<uint8_t*>(&request_id_base), sizeof(request_id_base));
metrics_->oemcrypto_get_random_.Increment(random_sts);
++request_id_index_;
uint64_t request_id_index =
request_id_index_source_.fetch_add(1, std::memory_order_relaxed);
request_id_ = HexEncode(reinterpret_cast<uint8_t*>(&request_id_base),
sizeof(request_id_base)) +
HexEncode(reinterpret_cast<uint8_t*>(&request_id_index),
sizeof(request_id_index));
if (!GetApiVersion(&api_version_)) {
LOGE("CryptoSession::Open: GetApiVersion failed");
@@ -819,21 +824,6 @@ void CryptoSession::Close() {
}
}
bool CryptoSession::GenerateRequestId(std::string* req_id_str) {
LOGV("CryptoSession::GenerateRequestId: Lock");
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
if (!req_id_str) {
LOGE("CryptoSession::GenerateRequestId: No output destination provided.");
return false;
}
*req_id_str = HexEncode(reinterpret_cast<uint8_t*>(&request_id_base_),
sizeof(request_id_base_)) +
HexEncode(reinterpret_cast<uint8_t*>(&request_id_index_),
sizeof(request_id_index_));
return true;
}
bool CryptoSession::PrepareRequest(const std::string& message,
bool is_provisioning,
std::string* signature) {

View File

@@ -300,8 +300,7 @@ CdmResponseType CdmLicense::PrepareKeyRequest(
return KEY_MESSAGE;
}
std::string request_id;
crypto_session_->GenerateRequestId(&request_id);
const std::string& request_id = crypto_session_->request_id();
LicenseRequest license_request;
CdmResponseType status;