Change from custom Lock to std::mutex.
[ Merge of http://go/wvgerrit/67884 ] Now that we can use C++11, we should use the cross-platform std::mutex type, not the custom pthread version. Bug: 111850982 Test: WV unit/integration tests Change-Id: If2fde2836826c5184609e6b1f3a6511206bd4594
This commit is contained in:
@@ -110,7 +110,6 @@ LOCAL_SRC_FILES := \
|
|||||||
$(UTIL_SRC_DIR)/clock.cpp \
|
$(UTIL_SRC_DIR)/clock.cpp \
|
||||||
$(UTIL_SRC_DIR)/file_store.cpp \
|
$(UTIL_SRC_DIR)/file_store.cpp \
|
||||||
$(UTIL_SRC_DIR)/file_utils.cpp \
|
$(UTIL_SRC_DIR)/file_utils.cpp \
|
||||||
$(UTIL_SRC_DIR)/lock.cpp \
|
|
||||||
$(UTIL_SRC_DIR)/log.cpp \
|
$(UTIL_SRC_DIR)/log.cpp \
|
||||||
$(SRC_DIR)/properties_android.cpp \
|
$(SRC_DIR)/properties_android.cpp \
|
||||||
$(SRC_DIR)/timer.cpp \
|
$(SRC_DIR)/timer.cpp \
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#define WVCDM_CORE_CDM_ENGINE_H_
|
#define WVCDM_CORE_CDM_ENGINE_H_
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -16,7 +17,6 @@
|
|||||||
#include "disallow_copy_and_assign.h"
|
#include "disallow_copy_and_assign.h"
|
||||||
#include "file_store.h"
|
#include "file_store.h"
|
||||||
#include "initialization_data.h"
|
#include "initialization_data.h"
|
||||||
#include "lock.h"
|
|
||||||
#include "metrics_collections.h"
|
#include "metrics_collections.h"
|
||||||
#include "oemcrypto_adapter.h"
|
#include "oemcrypto_adapter.h"
|
||||||
#include "service_certificate.h"
|
#include "service_certificate.h"
|
||||||
@@ -338,7 +338,7 @@ class CdmEngine {
|
|||||||
int64_t last_usage_information_update_time_;
|
int64_t last_usage_information_update_time_;
|
||||||
|
|
||||||
// Protect release_key_sets_ from non-thread-safe operations.
|
// Protect release_key_sets_ from non-thread-safe operations.
|
||||||
Lock release_key_sets_lock_;
|
std::mutex release_key_sets_lock_;
|
||||||
|
|
||||||
// TODO(rfrias): Replace with two sets of locks, one to protect
|
// TODO(rfrias): Replace with two sets of locks, one to protect
|
||||||
// the CdmSessionMap and a per-session lock to control access to
|
// the CdmSessionMap and a per-session lock to control access to
|
||||||
@@ -349,7 +349,7 @@ class CdmEngine {
|
|||||||
// The layer above the CDM implementation is expected to handle thread
|
// The layer above the CDM implementation is expected to handle thread
|
||||||
// synchronization to make sure other functions that access sessions do not
|
// synchronization to make sure other functions that access sessions do not
|
||||||
// occur simultaneously with OpenSession or CloseSession.
|
// occur simultaneously with OpenSession or CloseSession.
|
||||||
Lock session_map_lock_;
|
std::mutex session_map_lock_;
|
||||||
|
|
||||||
CORE_DISALLOW_COPY_AND_ASSIGN(CdmEngine);
|
CORE_DISALLOW_COPY_AND_ASSIGN(CdmEngine);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
#include "cdm_session.h"
|
#include "cdm_session.h"
|
||||||
#include "disallow_copy_and_assign.h"
|
#include "disallow_copy_and_assign.h"
|
||||||
#include "lock.h"
|
|
||||||
#include "wv_cdm_types.h"
|
#include "wv_cdm_types.h"
|
||||||
|
|
||||||
namespace wvcdm {
|
namespace wvcdm {
|
||||||
|
|||||||
@@ -7,13 +7,13 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "OEMCryptoCENC.h"
|
#include "OEMCryptoCENC.h"
|
||||||
#include "disallow_copy_and_assign.h"
|
#include "disallow_copy_and_assign.h"
|
||||||
#include "key_session.h"
|
#include "key_session.h"
|
||||||
#include "lock.h"
|
|
||||||
#include "metrics_collections.h"
|
#include "metrics_collections.h"
|
||||||
#include "oemcrypto_adapter.h"
|
#include "oemcrypto_adapter.h"
|
||||||
#include "timer_metric.h"
|
#include "timer_metric.h"
|
||||||
@@ -278,7 +278,7 @@ class CryptoSession {
|
|||||||
|
|
||||||
static const size_t kAes128BlockSize = 16; // Block size for AES_CBC_128
|
static const size_t kAes128BlockSize = 16; // Block size for AES_CBC_128
|
||||||
static const size_t kSignatureSize = 32; // size for HMAC-SHA256 signature
|
static const size_t kSignatureSize = 32; // size for HMAC-SHA256 signature
|
||||||
static Lock crypto_lock_;
|
static std::mutex crypto_lock_;
|
||||||
static bool initialized_;
|
static bool initialized_;
|
||||||
static int session_count_;
|
static int session_count_;
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
#include "cdm_client_property_set.h"
|
#include "cdm_client_property_set.h"
|
||||||
#include "disallow_copy_and_assign.h"
|
#include "disallow_copy_and_assign.h"
|
||||||
#include "lock.h"
|
|
||||||
#include "wv_cdm_types.h"
|
#include "wv_cdm_types.h"
|
||||||
|
|
||||||
#if defined(UNIT_TEST)
|
#if defined(UNIT_TEST)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#define WVCDM_CORE_USAGE_TABLE_HEADER_H_
|
#define WVCDM_CORE_USAGE_TABLE_HEADER_H_
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -13,7 +14,6 @@
|
|||||||
#include "device_files.h"
|
#include "device_files.h"
|
||||||
#include "disallow_copy_and_assign.h"
|
#include "disallow_copy_and_assign.h"
|
||||||
#include "file_store.h"
|
#include "file_store.h"
|
||||||
#include "lock.h"
|
|
||||||
#include "metrics_collections.h"
|
#include "metrics_collections.h"
|
||||||
#include "wv_cdm_types.h"
|
#include "wv_cdm_types.h"
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ class UsageTableHeader {
|
|||||||
|
|
||||||
// Synchonizes access to the Usage Table Header and bookkeeping
|
// Synchonizes access to the Usage Table Header and bookkeeping
|
||||||
// data-structures
|
// data-structures
|
||||||
Lock usage_table_header_lock_;
|
std::mutex usage_table_header_lock_;
|
||||||
|
|
||||||
metrics::CryptoMetrics alternate_crypto_metrics_;
|
metrics::CryptoMetrics alternate_crypto_metrics_;
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ CdmEngine::CdmEngine(FileSystem* file_system, const std::string& spoid)
|
|||||||
|
|
||||||
CdmEngine::~CdmEngine() {
|
CdmEngine::~CdmEngine() {
|
||||||
usage_session_.reset();
|
usage_session_.reset();
|
||||||
AutoLock lock(session_map_lock_);
|
std::unique_lock<std::mutex> lock(session_map_lock_);
|
||||||
session_map_.Terminate();
|
session_map_.Terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ CdmResponseType CdmEngine::OpenSession(
|
|||||||
CdmSessionId id = new_session->session_id();
|
CdmSessionId id = new_session->session_id();
|
||||||
LOGI("CdmEngine::OpenSession: %s", id.c_str());
|
LOGI("CdmEngine::OpenSession: %s", id.c_str());
|
||||||
|
|
||||||
AutoLock lock(session_map_lock_);
|
std::unique_lock<std::mutex> lock(session_map_lock_);
|
||||||
session_map_.Add(id, new_session.release());
|
session_map_.Add(id, new_session.release());
|
||||||
if (session_id) *session_id = id;
|
if (session_id) *session_id = id;
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
@@ -167,7 +167,7 @@ CdmResponseType CdmEngine::OpenKeySetSession(
|
|||||||
// resources (CryptoSession etc).
|
// resources (CryptoSession etc).
|
||||||
bool key_set_in_use = false;
|
bool key_set_in_use = false;
|
||||||
{
|
{
|
||||||
AutoLock lock(release_key_sets_lock_);
|
std::unique_lock<std::mutex> lock(release_key_sets_lock_);
|
||||||
key_set_in_use =
|
key_set_in_use =
|
||||||
release_key_sets_.find(key_set_id) != release_key_sets_.end();
|
release_key_sets_.find(key_set_id) != release_key_sets_.end();
|
||||||
}
|
}
|
||||||
@@ -180,7 +180,7 @@ CdmResponseType CdmEngine::OpenKeySetSession(
|
|||||||
|
|
||||||
if (sts != NO_ERROR) return sts;
|
if (sts != NO_ERROR) return sts;
|
||||||
|
|
||||||
AutoLock lock(release_key_sets_lock_);
|
std::unique_lock<std::mutex> lock(release_key_sets_lock_);
|
||||||
release_key_sets_[key_set_id] = std::make_pair(session_id,
|
release_key_sets_[key_set_id] = std::make_pair(session_id,
|
||||||
clock_.GetCurrentTime() + kReleaseSessionTimeToLive);
|
clock_.GetCurrentTime() + kReleaseSessionTimeToLive);
|
||||||
|
|
||||||
@@ -189,7 +189,7 @@ CdmResponseType CdmEngine::OpenKeySetSession(
|
|||||||
|
|
||||||
CdmResponseType CdmEngine::CloseSession(const CdmSessionId& session_id) {
|
CdmResponseType CdmEngine::CloseSession(const CdmSessionId& session_id) {
|
||||||
LOGI("CdmEngine::CloseSession: %s", session_id.c_str());
|
LOGI("CdmEngine::CloseSession: %s", session_id.c_str());
|
||||||
AutoLock lock(session_map_lock_);
|
std::unique_lock<std::mutex> lock(session_map_lock_);
|
||||||
if (!session_map_.CloseSession(session_id)) {
|
if (!session_map_.CloseSession(session_id)) {
|
||||||
LOGE("CdmEngine::CloseSession: session not found = %s", session_id.c_str());
|
LOGE("CdmEngine::CloseSession: session not found = %s", session_id.c_str());
|
||||||
return SESSION_NOT_FOUND_1;
|
return SESSION_NOT_FOUND_1;
|
||||||
@@ -202,7 +202,7 @@ CdmResponseType CdmEngine::CloseKeySetSession(const CdmKeySetId& key_set_id) {
|
|||||||
|
|
||||||
CdmSessionId session_id;
|
CdmSessionId session_id;
|
||||||
{
|
{
|
||||||
AutoLock lock(release_key_sets_lock_);
|
std::unique_lock<std::mutex> lock(release_key_sets_lock_);
|
||||||
CdmReleaseKeySetMap::iterator iter = release_key_sets_.find(key_set_id);
|
CdmReleaseKeySetMap::iterator iter = release_key_sets_.find(key_set_id);
|
||||||
if (iter == release_key_sets_.end()) {
|
if (iter == release_key_sets_.end()) {
|
||||||
LOGE("CdmEngine::CloseKeySetSession: key set id not found = %s",
|
LOGE("CdmEngine::CloseKeySetSession: key set id not found = %s",
|
||||||
@@ -214,7 +214,7 @@ CdmResponseType CdmEngine::CloseKeySetSession(const CdmKeySetId& key_set_id) {
|
|||||||
|
|
||||||
CdmResponseType sts = CloseSession(session_id);
|
CdmResponseType sts = CloseSession(session_id);
|
||||||
|
|
||||||
AutoLock lock(release_key_sets_lock_);
|
std::unique_lock<std::mutex> lock(release_key_sets_lock_);
|
||||||
CdmReleaseKeySetMap::iterator iter = release_key_sets_.find(key_set_id);
|
CdmReleaseKeySetMap::iterator iter = release_key_sets_.find(key_set_id);
|
||||||
if (iter != release_key_sets_.end()) {
|
if (iter != release_key_sets_.end()) {
|
||||||
release_key_sets_.erase(iter);
|
release_key_sets_.erase(iter);
|
||||||
@@ -223,7 +223,7 @@ CdmResponseType CdmEngine::CloseKeySetSession(const CdmKeySetId& key_set_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool CdmEngine::IsOpenSession(const CdmSessionId& session_id) {
|
bool CdmEngine::IsOpenSession(const CdmSessionId& session_id) {
|
||||||
AutoLock lock(session_map_lock_);
|
std::unique_lock<std::mutex> lock(session_map_lock_);
|
||||||
return session_map_.Exists(session_id);
|
return session_map_.Exists(session_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,7 +251,7 @@ CdmResponseType CdmEngine::GenerateKeyRequest(
|
|||||||
return INVALID_SESSION_ID;
|
return INVALID_SESSION_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoLock lock(release_key_sets_lock_);
|
std::unique_lock<std::mutex> lock(release_key_sets_lock_);
|
||||||
CdmReleaseKeySetMap::iterator iter = release_key_sets_.find(key_set_id);
|
CdmReleaseKeySetMap::iterator iter = release_key_sets_.find(key_set_id);
|
||||||
if (iter == release_key_sets_.end()) {
|
if (iter == release_key_sets_.end()) {
|
||||||
LOGE("CdmEngine::GenerateKeyRequest: key set ID not found = %s",
|
LOGE("CdmEngine::GenerateKeyRequest: key set ID not found = %s",
|
||||||
@@ -328,7 +328,7 @@ CdmResponseType CdmEngine::AddKey(const CdmSessionId& session_id,
|
|||||||
return EMPTY_KEYSET_ID_ENG_3;
|
return EMPTY_KEYSET_ID_ENG_3;
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoLock lock(release_key_sets_lock_);
|
std::unique_lock<std::mutex> lock(release_key_sets_lock_);
|
||||||
CdmReleaseKeySetMap::iterator iter = release_key_sets_.find(*key_set_id);
|
CdmReleaseKeySetMap::iterator iter = release_key_sets_.find(*key_set_id);
|
||||||
if (iter == release_key_sets_.end()) {
|
if (iter == release_key_sets_.end()) {
|
||||||
LOGE("CdmEngine::AddKey: key set id not found = %s", key_set_id->c_str());
|
LOGE("CdmEngine::AddKey: key set id not found = %s", key_set_id->c_str());
|
||||||
@@ -1525,7 +1525,7 @@ CdmResponseType CdmEngine::Decrypt(const CdmSessionId& session_id,
|
|||||||
// else we must be level 1 direct and we don't need to return a buffer.
|
// else we must be level 1 direct and we don't need to return a buffer.
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoLock lock(session_map_lock_);
|
std::unique_lock<std::mutex> lock(session_map_lock_);
|
||||||
std::shared_ptr<CdmSession> session;
|
std::shared_ptr<CdmSession> session;
|
||||||
if (session_id.empty()) {
|
if (session_id.empty()) {
|
||||||
CdmSessionList sessions;
|
CdmSessionList sessions;
|
||||||
@@ -1646,7 +1646,7 @@ bool CdmEngine::FindSessionForKey(const KeyId& key_id,
|
|||||||
|
|
||||||
uint32_t session_sharing_id = Properties::GetSessionSharingId(*session_id);
|
uint32_t session_sharing_id = Properties::GetSessionSharingId(*session_id);
|
||||||
|
|
||||||
AutoLock lock(session_map_lock_);
|
std::unique_lock<std::mutex> lock(session_map_lock_);
|
||||||
CdmSessionList sessions;
|
CdmSessionList sessions;
|
||||||
session_map_.GetSessionList(sessions);
|
session_map_.GetSessionList(sessions);
|
||||||
|
|
||||||
@@ -1703,7 +1703,7 @@ void CdmEngine::OnTimerEvent() {
|
|||||||
bool is_usage_update_needed = false;
|
bool is_usage_update_needed = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
AutoLock lock(session_map_lock_);
|
std::unique_lock<std::mutex> lock(session_map_lock_);
|
||||||
CdmSessionList sessions;
|
CdmSessionList sessions;
|
||||||
session_map_.GetSessionList(sessions);
|
session_map_.GetSessionList(sessions);
|
||||||
|
|
||||||
@@ -1798,7 +1798,7 @@ void CdmEngine::CloseExpiredReleaseSessions() {
|
|||||||
|
|
||||||
std::set<CdmSessionId> close_session_set;
|
std::set<CdmSessionId> close_session_set;
|
||||||
{
|
{
|
||||||
AutoLock lock(release_key_sets_lock_);
|
std::unique_lock<std::mutex> lock(release_key_sets_lock_);
|
||||||
for (CdmReleaseKeySetMap::iterator iter = release_key_sets_.begin();
|
for (CdmReleaseKeySetMap::iterator iter = release_key_sets_.begin();
|
||||||
iter != release_key_sets_.end();) {
|
iter != release_key_sets_.end();) {
|
||||||
if (iter->second.second < current_time) {
|
if (iter->second.second < current_time) {
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ void DeleteX509Stack(STACK_OF(X509)* stack) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace wvcdm {
|
namespace wvcdm {
|
||||||
Lock CryptoSession::crypto_lock_;
|
std::mutex CryptoSession::crypto_lock_;
|
||||||
bool CryptoSession::initialized_ = false;
|
bool CryptoSession::initialized_ = false;
|
||||||
int CryptoSession::session_count_ = 0;
|
int CryptoSession::session_count_ = 0;
|
||||||
uint64_t CryptoSession::request_id_index_ = 0;
|
uint64_t CryptoSession::request_id_index_ = 0;
|
||||||
@@ -212,7 +212,7 @@ CdmResponseType CryptoSession::GetProvisioningMethod(
|
|||||||
|
|
||||||
void CryptoSession::Init() {
|
void CryptoSession::Init() {
|
||||||
LOGV("CryptoSession::Init");
|
LOGV("CryptoSession::Init");
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
session_count_ += 1;
|
session_count_ += 1;
|
||||||
if (!initialized_) {
|
if (!initialized_) {
|
||||||
std::string sandbox_id;
|
std::string sandbox_id;
|
||||||
@@ -235,7 +235,7 @@ void CryptoSession::Init() {
|
|||||||
void CryptoSession::Terminate() {
|
void CryptoSession::Terminate() {
|
||||||
LOGV("CryptoSession::Terminate: initialized_=%d, session_count_=%d",
|
LOGV("CryptoSession::Terminate: initialized_=%d, session_count_=%d",
|
||||||
initialized_, session_count_);
|
initialized_, session_count_);
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
if (session_count_ > 0) {
|
if (session_count_ > 0) {
|
||||||
session_count_ -= 1;
|
session_count_ -= 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -322,7 +322,7 @@ bool CryptoSession::GetProvisioningToken(std::string* token) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LOGV("CryptoSession::GetProvisioningToken: Lock");
|
LOGV("CryptoSession::GetProvisioningToken: Lock");
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
|
|
||||||
if (!initialized_) {
|
if (!initialized_) {
|
||||||
metrics_->crypto_session_get_token_.Increment(false);
|
metrics_->crypto_session_get_token_.Increment(false);
|
||||||
@@ -380,7 +380,7 @@ bool CryptoSession::GetInternalDeviceUniqueId(std::string* device_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOGV("CryptoSession::GetInternalDeviceUniqueId: Lock");
|
LOGV("CryptoSession::GetInternalDeviceUniqueId: Lock");
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
if (!initialized_) {
|
if (!initialized_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -473,7 +473,7 @@ bool CryptoSession::GetSystemId(uint32_t* system_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOGV("CryptoSession::GetSystemId: Lock");
|
LOGV("CryptoSession::GetSystemId: Lock");
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
if (!initialized_ || !open_) {
|
if (!initialized_ || !open_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -642,7 +642,7 @@ bool CryptoSession::GetProvisioningId(std::string* provisioning_id) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
LOGV("CryptoSession::GetProvisioningId: Lock");
|
LOGV("CryptoSession::GetProvisioningId: Lock");
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
if (!initialized_) {
|
if (!initialized_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -663,7 +663,7 @@ bool CryptoSession::GetProvisioningId(std::string* provisioning_id) {
|
|||||||
} else {
|
} else {
|
||||||
OEMCryptoResult sts;
|
OEMCryptoResult sts;
|
||||||
LOGV("CryptoSession::GetProvisioningId: Lock");
|
LOGV("CryptoSession::GetProvisioningId: Lock");
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
M_TIME(
|
M_TIME(
|
||||||
sts = OEMCrypto_GetKeyData(buf, &buf_size, requested_security_level_),
|
sts = OEMCrypto_GetKeyData(buf, &buf_size, requested_security_level_),
|
||||||
metrics_, oemcrypto_get_key_data_, sts, metrics::Pow2Bucket(buf_size));
|
metrics_, oemcrypto_get_key_data_, sts, metrics::Pow2Bucket(buf_size));
|
||||||
@@ -688,7 +688,7 @@ CdmResponseType CryptoSession::Open(SecurityLevel requested_security_level) {
|
|||||||
requested_security_level == kLevel3
|
requested_security_level == kLevel3
|
||||||
? QUERY_VALUE_SECURITY_LEVEL_L3.c_str()
|
? QUERY_VALUE_SECURITY_LEVEL_L3.c_str()
|
||||||
: QUERY_VALUE_SECURITY_LEVEL_DEFAULT.c_str());
|
: QUERY_VALUE_SECURITY_LEVEL_DEFAULT.c_str());
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
if (!initialized_) return UNKNOWN_ERROR;
|
if (!initialized_) return UNKNOWN_ERROR;
|
||||||
if (open_) return NO_ERROR;
|
if (open_) return NO_ERROR;
|
||||||
}
|
}
|
||||||
@@ -699,7 +699,7 @@ CdmResponseType CryptoSession::Open(SecurityLevel requested_security_level) {
|
|||||||
if (result != NO_ERROR) return result;
|
if (result != NO_ERROR) return result;
|
||||||
|
|
||||||
LOGV("CryptoSession::Open: Lock");
|
LOGV("CryptoSession::Open: Lock");
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
OEMCrypto_SESSION sid;
|
OEMCrypto_SESSION sid;
|
||||||
requested_security_level_ = requested_security_level;
|
requested_security_level_ = requested_security_level;
|
||||||
OEMCryptoResult sts = OEMCrypto_OpenSession(&sid, requested_security_level);
|
OEMCryptoResult sts = OEMCrypto_OpenSession(&sid, requested_security_level);
|
||||||
@@ -753,10 +753,10 @@ CdmResponseType CryptoSession::Open(SecurityLevel requested_security_level) {
|
|||||||
// Ignore errors since we do not know when a session is opened,
|
// Ignore errors since we do not know when a session is opened,
|
||||||
// if it is intended to be used for offline/usage session related
|
// if it is intended to be used for offline/usage session related
|
||||||
// or otherwise.
|
// or otherwise.
|
||||||
crypto_lock_.Release();
|
auto_lock.unlock();
|
||||||
bool is_usage_table_header_inited =
|
bool is_usage_table_header_inited =
|
||||||
(*header)->Init(security_level, this);
|
(*header)->Init(security_level, this);
|
||||||
crypto_lock_.Acquire();
|
auto_lock.lock();
|
||||||
if (!is_usage_table_header_inited) {
|
if (!is_usage_table_header_inited) {
|
||||||
delete *header;
|
delete *header;
|
||||||
*header = NULL;
|
*header = NULL;
|
||||||
@@ -783,7 +783,7 @@ void CryptoSession::Close() {
|
|||||||
OEMCryptoResult close_sts;
|
OEMCryptoResult close_sts;
|
||||||
bool update_usage_table = false;
|
bool update_usage_table = false;
|
||||||
{
|
{
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
if (!open_) return;
|
if (!open_) return;
|
||||||
|
|
||||||
close_sts = OEMCrypto_CloseSession(oec_session_id_);
|
close_sts = OEMCrypto_CloseSession(oec_session_id_);
|
||||||
@@ -799,7 +799,7 @@ void CryptoSession::Close() {
|
|||||||
|
|
||||||
bool CryptoSession::GenerateRequestId(std::string* req_id_str) {
|
bool CryptoSession::GenerateRequestId(std::string* req_id_str) {
|
||||||
LOGV("CryptoSession::GenerateRequestId: Lock");
|
LOGV("CryptoSession::GenerateRequestId: Lock");
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
if (!req_id_str) {
|
if (!req_id_str) {
|
||||||
LOGE("CryptoSession::GenerateRequestId: No output destination provided.");
|
LOGE("CryptoSession::GenerateRequestId: No output destination provided.");
|
||||||
return false;
|
return false;
|
||||||
@@ -816,7 +816,7 @@ bool CryptoSession::PrepareRequest(const std::string& message,
|
|||||||
bool is_provisioning,
|
bool is_provisioning,
|
||||||
std::string* signature) {
|
std::string* signature) {
|
||||||
LOGV("CryptoSession::PrepareRequest: Lock");
|
LOGV("CryptoSession::PrepareRequest: Lock");
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
|
|
||||||
if (!signature) {
|
if (!signature) {
|
||||||
LOGE("CryptoSession::PrepareRequest : No output destination provided.");
|
LOGE("CryptoSession::PrepareRequest : No output destination provided.");
|
||||||
@@ -837,7 +837,7 @@ bool CryptoSession::PrepareRequest(const std::string& message,
|
|||||||
bool CryptoSession::PrepareRenewalRequest(const std::string& message,
|
bool CryptoSession::PrepareRenewalRequest(const std::string& message,
|
||||||
std::string* signature) {
|
std::string* signature) {
|
||||||
LOGV("CryptoSession::PrepareRenewalRequest: Lock");
|
LOGV("CryptoSession::PrepareRenewalRequest: Lock");
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
|
|
||||||
if (!signature) {
|
if (!signature) {
|
||||||
LOGE(
|
LOGE(
|
||||||
@@ -862,7 +862,7 @@ CdmResponseType CryptoSession::LoadKeys(
|
|||||||
CdmResponseType result = KEY_ADDED;
|
CdmResponseType result = KEY_ADDED;
|
||||||
{
|
{
|
||||||
LOGV("CryptoSession::LoadKeys: Lock");
|
LOGV("CryptoSession::LoadKeys: Lock");
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
|
|
||||||
if (key_type == kLicenseKeyTypeEntitlement &&
|
if (key_type == kLicenseKeyTypeEntitlement &&
|
||||||
key_session_->Type() != KeySession::kEntitlement) {
|
key_session_->Type() != KeySession::kEntitlement) {
|
||||||
@@ -901,7 +901,7 @@ CdmResponseType CryptoSession::LoadKeys(
|
|||||||
CdmResponseType CryptoSession::LoadEntitledContentKeys(
|
CdmResponseType CryptoSession::LoadEntitledContentKeys(
|
||||||
const std::vector<CryptoKey>& key_array) {
|
const std::vector<CryptoKey>& key_array) {
|
||||||
LOGV("CryptoSession::LoadEntitledContentKeys: Lock");
|
LOGV("CryptoSession::LoadEntitledContentKeys: Lock");
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
|
|
||||||
OEMCryptoResult sts = key_session_->LoadEntitledContentKeys(key_array);
|
OEMCryptoResult sts = key_session_->LoadEntitledContentKeys(key_array);
|
||||||
|
|
||||||
@@ -920,7 +920,7 @@ CdmResponseType CryptoSession::LoadEntitledContentKeys(
|
|||||||
|
|
||||||
bool CryptoSession::LoadCertificatePrivateKey(std::string& wrapped_key) {
|
bool CryptoSession::LoadCertificatePrivateKey(std::string& wrapped_key) {
|
||||||
LOGV("CryptoSession::LoadCertificatePrivateKey: Lock");
|
LOGV("CryptoSession::LoadCertificatePrivateKey: Lock");
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
|
|
||||||
// Call OEMCrypto_GetOEMPublicCertificate before OEMCrypto_LoadDeviceRSAKey
|
// Call OEMCrypto_GetOEMPublicCertificate before OEMCrypto_LoadDeviceRSAKey
|
||||||
// so it caches the OEMCrypto Public Key and then throw away result
|
// so it caches the OEMCrypto Public Key and then throw away result
|
||||||
@@ -950,7 +950,7 @@ bool CryptoSession::RefreshKeys(const std::string& message,
|
|||||||
const std::string& signature, int num_keys,
|
const std::string& signature, int num_keys,
|
||||||
const CryptoKey* key_array) {
|
const CryptoKey* key_array) {
|
||||||
LOGV("CryptoSession::RefreshKeys: Lock");
|
LOGV("CryptoSession::RefreshKeys: Lock");
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
|
|
||||||
const uint8_t* msg = reinterpret_cast<const uint8_t*>(message.data());
|
const uint8_t* msg = reinterpret_cast<const uint8_t*>(message.data());
|
||||||
std::vector<OEMCrypto_KeyRefreshObject> load_key_array(num_keys);
|
std::vector<OEMCrypto_KeyRefreshObject> load_key_array(num_keys);
|
||||||
@@ -1155,7 +1155,7 @@ CdmResponseType CryptoSession::Decrypt(const CdmDecryptionParameters& params) {
|
|||||||
pattern_descriptor.encrypt = params.pattern_descriptor.encrypt_blocks;
|
pattern_descriptor.encrypt = params.pattern_descriptor.encrypt_blocks;
|
||||||
pattern_descriptor.skip = params.pattern_descriptor.skip_blocks;
|
pattern_descriptor.skip = params.pattern_descriptor.skip_blocks;
|
||||||
pattern_descriptor.offset = 0; // Deprecated field
|
pattern_descriptor.offset = 0; // Deprecated field
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
// Check if key needs to be selected
|
// Check if key needs to be selected
|
||||||
if (params.is_encrypted) {
|
if (params.is_encrypted) {
|
||||||
CdmResponseType result = SelectKey(*params.key_id, params.cipher_mode);
|
CdmResponseType result = SelectKey(*params.key_id, params.cipher_mode);
|
||||||
@@ -1216,7 +1216,7 @@ bool CryptoSession::UsageInformationSupport(bool* has_support) {
|
|||||||
CdmResponseType CryptoSession::UpdateUsageInformation() {
|
CdmResponseType CryptoSession::UpdateUsageInformation() {
|
||||||
LOGV("CryptoSession::UpdateUsageInformation: id=%lu",
|
LOGV("CryptoSession::UpdateUsageInformation: id=%lu",
|
||||||
oec_session_id_);
|
oec_session_id_);
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
if (!initialized_) return UNKNOWN_ERROR;
|
if (!initialized_) return UNKNOWN_ERROR;
|
||||||
|
|
||||||
if (usage_table_header_ != NULL) {
|
if (usage_table_header_ != NULL) {
|
||||||
@@ -1237,7 +1237,7 @@ CdmResponseType CryptoSession::DeactivateUsageInformation(
|
|||||||
const std::string& provider_session_token) {
|
const std::string& provider_session_token) {
|
||||||
LOGV("DeactivateUsageInformation: id=%lu", oec_session_id_);
|
LOGV("DeactivateUsageInformation: id=%lu", oec_session_id_);
|
||||||
|
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
uint8_t* pst = reinterpret_cast<uint8_t*>(
|
uint8_t* pst = reinterpret_cast<uint8_t*>(
|
||||||
const_cast<char*>(provider_session_token.data()));
|
const_cast<char*>(provider_session_token.data()));
|
||||||
|
|
||||||
@@ -1269,7 +1269,7 @@ CdmResponseType CryptoSession::GenerateUsageReport(
|
|||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
uint8_t* pst = reinterpret_cast<uint8_t*>(
|
uint8_t* pst = reinterpret_cast<uint8_t*>(
|
||||||
const_cast<char*>(provider_session_token.data()));
|
const_cast<char*>(provider_session_token.data()));
|
||||||
|
|
||||||
@@ -1355,7 +1355,7 @@ CdmResponseType CryptoSession::ReleaseUsageInformation(
|
|||||||
const std::string& provider_session_token) {
|
const std::string& provider_session_token) {
|
||||||
LOGV("ReleaseUsageInformation: id=%lu", oec_session_id_);
|
LOGV("ReleaseUsageInformation: id=%lu", oec_session_id_);
|
||||||
{
|
{
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
if (usage_table_header_ != NULL) {
|
if (usage_table_header_ != NULL) {
|
||||||
LOGW("ReleaseUsageInformation: deprecated for OEMCrypto v13+");
|
LOGW("ReleaseUsageInformation: deprecated for OEMCrypto v13+");
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
@@ -1387,7 +1387,7 @@ CdmResponseType CryptoSession::DeleteUsageInformation(
|
|||||||
LOGV("CryptoSession::DeleteUsageInformation");
|
LOGV("CryptoSession::DeleteUsageInformation");
|
||||||
OEMCryptoResult status;
|
OEMCryptoResult status;
|
||||||
{
|
{
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
status = OEMCrypto_ForceDeleteUsageEntry(
|
status = OEMCrypto_ForceDeleteUsageEntry(
|
||||||
reinterpret_cast<const uint8_t*>(provider_session_token.c_str()),
|
reinterpret_cast<const uint8_t*>(provider_session_token.c_str()),
|
||||||
provider_session_token.length());
|
provider_session_token.length());
|
||||||
@@ -1409,7 +1409,7 @@ CdmResponseType CryptoSession::DeleteMultipleUsageInformation(
|
|||||||
LOGV("CryptoSession::DeleteMultipleUsageInformation");
|
LOGV("CryptoSession::DeleteMultipleUsageInformation");
|
||||||
CdmResponseType response = NO_ERROR;
|
CdmResponseType response = NO_ERROR;
|
||||||
{
|
{
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
for (size_t i = 0; i < provider_session_tokens.size(); ++i) {
|
for (size_t i = 0; i < provider_session_tokens.size(); ++i) {
|
||||||
OEMCryptoResult status = OEMCrypto_ForceDeleteUsageEntry(
|
OEMCryptoResult status = OEMCrypto_ForceDeleteUsageEntry(
|
||||||
reinterpret_cast<const uint8_t*>(provider_session_tokens[i].c_str()),
|
reinterpret_cast<const uint8_t*>(provider_session_tokens[i].c_str()),
|
||||||
@@ -1432,7 +1432,7 @@ CdmResponseType CryptoSession::DeleteAllUsageReports() {
|
|||||||
LOGV("DeleteAllUsageReports");
|
LOGV("DeleteAllUsageReports");
|
||||||
OEMCryptoResult status;
|
OEMCryptoResult status;
|
||||||
{
|
{
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
status = OEMCrypto_DeleteOldUsageTable();
|
status = OEMCrypto_DeleteOldUsageTable();
|
||||||
metrics_->oemcrypto_delete_usage_table_.Increment(status);
|
metrics_->oemcrypto_delete_usage_table_.Increment(status);
|
||||||
if (OEMCrypto_SUCCESS != status) {
|
if (OEMCrypto_SUCCESS != status) {
|
||||||
@@ -1461,7 +1461,7 @@ bool CryptoSession::GenerateNonce(uint32_t* nonce) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOGV("CryptoSession::GenerateNonce: Lock");
|
LOGV("CryptoSession::GenerateNonce: Lock");
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
|
|
||||||
OEMCryptoResult result = OEMCrypto_GenerateNonce(oec_session_id_, nonce);
|
OEMCryptoResult result = OEMCrypto_GenerateNonce(oec_session_id_, nonce);
|
||||||
metrics_->oemcrypto_generate_nonce_.Increment(result);
|
metrics_->oemcrypto_generate_nonce_.Increment(result);
|
||||||
@@ -1831,7 +1831,7 @@ CdmResponseType CryptoSession::GenericEncrypt(const std::string& in_buffer,
|
|||||||
out_buffer->resize(in_buffer.size());
|
out_buffer->resize(in_buffer.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
// TODO(jfore): We need to select a key with a cipher mode and algorithm
|
// TODO(jfore): We need to select a key with a cipher mode and algorithm
|
||||||
// doesn't seem to fit. Is it ok to just use a default value here?
|
// doesn't seem to fit. Is it ok to just use a default value here?
|
||||||
// Or do we need to pass it in?
|
// Or do we need to pass it in?
|
||||||
@@ -1884,7 +1884,7 @@ CdmResponseType CryptoSession::GenericDecrypt(const std::string& in_buffer,
|
|||||||
out_buffer->resize(in_buffer.size());
|
out_buffer->resize(in_buffer.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
// TODO(jfore): We need to select a key with a cipher mode and algorithm
|
// TODO(jfore): We need to select a key with a cipher mode and algorithm
|
||||||
// doesn't seem to fit. Is it ok to just use a default value here?
|
// doesn't seem to fit. Is it ok to just use a default value here?
|
||||||
// Or do we need to pass it in?
|
// Or do we need to pass it in?
|
||||||
@@ -1934,7 +1934,7 @@ CdmResponseType CryptoSession::GenericSign(const std::string& message,
|
|||||||
OEMCryptoResult sts;
|
OEMCryptoResult sts;
|
||||||
size_t length = signature->size();
|
size_t length = signature->size();
|
||||||
|
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
// TODO(jfore): We need to select a key with a cipher mode and algorithm
|
// TODO(jfore): We need to select a key with a cipher mode and algorithm
|
||||||
// doesn't seem to fit. Is it ok to just use a default value here?
|
// doesn't seem to fit. Is it ok to just use a default value here?
|
||||||
// Or do we need to pass it in?
|
// Or do we need to pass it in?
|
||||||
@@ -1988,7 +1988,7 @@ CdmResponseType CryptoSession::GenericVerify(const std::string& message,
|
|||||||
return INVALID_PARAMETERS_ENG_16;
|
return INVALID_PARAMETERS_ENG_16;
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
// TODO(jfore): We need to select a key with a cipher mode and algorithm
|
// TODO(jfore): We need to select a key with a cipher mode and algorithm
|
||||||
// doesn't seem to fit. Is it ok to just use a default value here?
|
// doesn't seem to fit. Is it ok to just use a default value here?
|
||||||
// Or do we need to pass it in?
|
// Or do we need to pass it in?
|
||||||
@@ -2276,7 +2276,7 @@ bool CryptoSession::CreateOldUsageEntry(
|
|||||||
const std::string& server_mac_key, const std::string& client_mac_key,
|
const std::string& server_mac_key, const std::string& client_mac_key,
|
||||||
const std::string& provider_session_token) {
|
const std::string& provider_session_token) {
|
||||||
LOGV("CreateOldUsageEntry: Lock");
|
LOGV("CreateOldUsageEntry: Lock");
|
||||||
AutoLock auto_lock(crypto_lock_);
|
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||||
|
|
||||||
if (server_mac_key.size() < MAC_KEY_SIZE ||
|
if (server_mac_key.size() < MAC_KEY_SIZE ||
|
||||||
client_mac_key.size() < MAC_KEY_SIZE) {
|
client_mac_key.size() < MAC_KEY_SIZE) {
|
||||||
|
|||||||
@@ -18,14 +18,16 @@
|
|||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <condition_variable>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include "file_store.h"
|
#include "file_store.h"
|
||||||
#include "level3.h"
|
#include "level3.h"
|
||||||
#include "lock.h"
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "metrics_collections.h"
|
#include "metrics_collections.h"
|
||||||
#include "properties.h"
|
#include "properties.h"
|
||||||
@@ -382,35 +384,25 @@ class WatchDog {
|
|||||||
public:
|
public:
|
||||||
// Created by main thread.
|
// Created by main thread.
|
||||||
WatchDog(std::vector<uint8_t> sandbox_id) {
|
WatchDog(std::vector<uint8_t> sandbox_id) {
|
||||||
pthread_mutex_init(&mutex_, NULL);
|
|
||||||
pthread_cond_init(&condition_, NULL);
|
|
||||||
status_ = OEMCrypto_SUCCESS;
|
status_ = OEMCrypto_SUCCESS;
|
||||||
gave_up_ = false;
|
gave_up_ = false;
|
||||||
sandbox_id_ = sandbox_id;
|
sandbox_id_ = sandbox_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deleted by either thread.
|
// Deleted by either thread.
|
||||||
~WatchDog() {
|
~WatchDog() {}
|
||||||
pthread_cond_destroy(&condition_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Starts worker thread.
|
// Starts worker thread.
|
||||||
void StartThread() {
|
void StartThread() {
|
||||||
running_ = true;
|
running_ = true;
|
||||||
if(pthread_create(&thread_, NULL, RunWatchDog, this)) {
|
thread_ = std::thread(&RunWatchDog, this);
|
||||||
LOGE("Could not create watch dog thread.");
|
|
||||||
status_ = OEMCrypto_ERROR_INIT_FAILED;
|
|
||||||
running_ = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function called by new worker thread in pthread_create.
|
// Function called by new worker thread.
|
||||||
static void *RunWatchDog(void *watcher) {
|
static void RunWatchDog(void *watcher) {
|
||||||
WatchDog* dog = reinterpret_cast<WatchDog *>(watcher);
|
WatchDog* dog = reinterpret_cast<WatchDog *>(watcher);
|
||||||
dog->DoInit();
|
dog->DoInit();
|
||||||
dog->SignalDoneAndCleanUp();
|
dog->SignalDoneAndCleanUp();
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called by worker thread.
|
// Called by worker thread.
|
||||||
@@ -475,50 +467,48 @@ class WatchDog {
|
|||||||
|
|
||||||
// Called by worker thread after DoInit has finshed.
|
// Called by worker thread after DoInit has finshed.
|
||||||
void SignalDoneAndCleanUp() {
|
void SignalDoneAndCleanUp() {
|
||||||
pthread_mutex_lock(&mutex_);
|
bool should_delete;
|
||||||
running_ = false;
|
{
|
||||||
pthread_cond_signal(&condition_);
|
std::unique_lock<std::mutex> lock(mutex_);
|
||||||
// If the main thread gave up, it won't delete this, so we must.
|
running_ = false;
|
||||||
bool should_delete = gave_up_;
|
condition_.notify_all();
|
||||||
pthread_mutex_unlock(&mutex_);
|
// If the main thread gave up, it won't delete this, so we must.
|
||||||
|
should_delete = gave_up_;
|
||||||
|
}
|
||||||
// https://isocpp.org/wiki/faq/freestore-mgmt#delete-this
|
// https://isocpp.org/wiki/faq/freestore-mgmt#delete-this
|
||||||
if (should_delete) delete this;
|
if (should_delete) delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called by main thread to wait for worker thread.
|
// Called by main thread to wait for worker thread.
|
||||||
OEMCryptoResult WaitForStatusAndCleanUp() {
|
OEMCryptoResult WaitForStatusAndCleanUp() {
|
||||||
pthread_mutex_lock(&mutex_);
|
bool should_delete;
|
||||||
struct timespec time_to_giveup;
|
OEMCryptoResult status;
|
||||||
clock_gettime(CLOCK_REALTIME, &time_to_giveup);
|
{
|
||||||
time_to_giveup.tv_sec += 120; // wait 2 minutes.
|
std::unique_lock<std::mutex> lock(mutex_);
|
||||||
if (running_) {
|
if (running_) {
|
||||||
pthread_cond_timedwait(&condition_, &mutex_, &time_to_giveup);
|
condition_.wait_for(lock, std::chrono::minutes(2));
|
||||||
|
}
|
||||||
|
if (running_) {
|
||||||
|
gave_up_ = true;
|
||||||
|
status_ = OEMCrypto_ERROR_INIT_FAILED;
|
||||||
|
LOGE("XXX WATCH DOG ERROR XXX");
|
||||||
|
// HACK: this normally just returns an error. However, we are using it
|
||||||
|
// as a signal to dump debugging information.
|
||||||
|
Level3_GetOEMPublicCertificate(0, NULL, NULL);
|
||||||
|
SaveFailureInformation();
|
||||||
|
// This is controversial. The argument for an abort here is that if we
|
||||||
|
// do not abort, we will suck all the life out of the user's battery.
|
||||||
|
// By saving information to the file system, above, we can still track
|
||||||
|
// metrics.
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
// If we gave up waiting for init thread, we should not delete the mutex
|
||||||
|
// out from under it.
|
||||||
|
should_delete = !gave_up_;
|
||||||
|
status = status_;
|
||||||
}
|
}
|
||||||
if (running_) {
|
|
||||||
gave_up_ = true;
|
|
||||||
status_ = OEMCrypto_ERROR_INIT_FAILED;
|
|
||||||
LOGE("XXX WATCH DOG ERROR XXX");
|
|
||||||
// HACK: this normally just returns an error. However, we are using it
|
|
||||||
// as a signal to dump debugging information.
|
|
||||||
Level3_GetOEMPublicCertificate(0, NULL, NULL);
|
|
||||||
SaveFailureInformation();
|
|
||||||
// This tells the worker thread to clean up after itself. It is not
|
|
||||||
// really needed since we are going to abort. However, if somebody
|
|
||||||
// removes the "abort()" below, then this is needed.
|
|
||||||
pthread_detach(thread_);
|
|
||||||
// This is controversial. The argument for an abort here is that if we
|
|
||||||
// do not abort, we will suck all the life out of the user's battery. By
|
|
||||||
// saving information to the file system, above, we can still track
|
|
||||||
// metrics.
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
// If we gave up waiting for init thread, we should not delete the mutex
|
|
||||||
// out from under it.
|
|
||||||
bool should_delete = !gave_up_;
|
|
||||||
OEMCryptoResult status = status_;
|
|
||||||
pthread_mutex_unlock(&mutex_);
|
|
||||||
if (should_delete) {
|
if (should_delete) {
|
||||||
pthread_join(thread_, NULL);
|
thread_.join();
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
@@ -528,9 +518,9 @@ class WatchDog {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
OEMCryptoResult status_;
|
OEMCryptoResult status_;
|
||||||
pthread_t thread_;
|
std::thread thread_;
|
||||||
pthread_mutex_t mutex_;
|
std::mutex mutex_;
|
||||||
pthread_cond_t condition_;
|
std::condition_variable condition_;
|
||||||
bool running_;
|
bool running_;
|
||||||
bool gave_up_;
|
bool gave_up_;
|
||||||
std::vector<uint8_t> sandbox_id_;
|
std::vector<uint8_t> sandbox_id_;
|
||||||
@@ -952,7 +942,7 @@ class Adapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LevelSession GetSession(OEMCrypto_SESSION session) {
|
LevelSession GetSession(OEMCrypto_SESSION session) {
|
||||||
wvcdm::AutoLock auto_lock(session_map_lock_);
|
std::unique_lock<std::mutex> auto_lock(session_map_lock_);
|
||||||
map_iterator pair = session_map_.find(session);
|
map_iterator pair = session_map_.find(session);
|
||||||
if (pair == session_map_.end()) {
|
if (pair == session_map_.end()) {
|
||||||
return LevelSession();
|
return LevelSession();
|
||||||
@@ -974,7 +964,7 @@ class Adapter {
|
|||||||
*session = new_session.session + kLevel3Offset;
|
*session = new_session.session + kLevel3Offset;
|
||||||
}
|
}
|
||||||
if (result == OEMCrypto_SUCCESS) {
|
if (result == OEMCrypto_SUCCESS) {
|
||||||
wvcdm::AutoLock auto_lock(session_map_lock_);
|
std::unique_lock<std::mutex> auto_lock(session_map_lock_);
|
||||||
// Make sure session is not already in my list of sessions.
|
// Make sure session is not already in my list of sessions.
|
||||||
while (session_map_.find(*session) != session_map_.end()) {
|
while (session_map_.find(*session) != session_map_.end()) {
|
||||||
(*session)++;
|
(*session)++;
|
||||||
@@ -986,7 +976,7 @@ class Adapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OEMCryptoResult CloseSession(OEMCrypto_SESSION session) {
|
OEMCryptoResult CloseSession(OEMCrypto_SESSION session) {
|
||||||
wvcdm::AutoLock auto_lock(session_map_lock_);
|
std::unique_lock<std::mutex> auto_lock(session_map_lock_);
|
||||||
map_iterator pair = session_map_.find(session);
|
map_iterator pair = session_map_.find(session);
|
||||||
if (pair == session_map_.end()) {
|
if (pair == session_map_.end()) {
|
||||||
return OEMCrypto_ERROR_INVALID_SESSION;
|
return OEMCrypto_ERROR_INVALID_SESSION;
|
||||||
@@ -1004,7 +994,7 @@ class Adapter {
|
|||||||
struct FunctionPointers level1_;
|
struct FunctionPointers level1_;
|
||||||
struct FunctionPointers level3_;
|
struct FunctionPointers level3_;
|
||||||
std::map<OEMCrypto_SESSION, LevelSession> session_map_;
|
std::map<OEMCrypto_SESSION, LevelSession> session_map_;
|
||||||
wvcdm::Lock session_map_lock_;
|
std::mutex session_map_lock_;
|
||||||
std::vector<uint8_t> sandbox_id_;
|
std::vector<uint8_t> sandbox_id_;
|
||||||
// This is just for debugging the map between session ids.
|
// This is just for debugging the map between session ids.
|
||||||
// If we add this to the level 3 session id, then the external session
|
// If we add this to the level 3 session id, then the external session
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ CdmResponseType UsageTableHeader::AddEntry(
|
|||||||
|
|
||||||
if (status != NO_ERROR) return status;
|
if (status != NO_ERROR) return status;
|
||||||
|
|
||||||
AutoLock auto_lock(usage_table_header_lock_);
|
std::unique_lock<std::mutex> auto_lock(usage_table_header_lock_);
|
||||||
if (*usage_entry_number < usage_entry_info_.size()) {
|
if (*usage_entry_number < usage_entry_info_.size()) {
|
||||||
LOGE("UsageTableHeader::AddEntry: new entry %d smaller than table size: %d",
|
LOGE("UsageTableHeader::AddEntry: new entry %d smaller than table size: %d",
|
||||||
*usage_entry_number, usage_entry_info_.size());
|
*usage_entry_number, usage_entry_info_.size());
|
||||||
@@ -198,7 +198,7 @@ CdmResponseType UsageTableHeader::LoadEntry(CryptoSession* crypto_session,
|
|||||||
uint32_t usage_entry_number) {
|
uint32_t usage_entry_number) {
|
||||||
{
|
{
|
||||||
LOGV("UsageTableHeader::LoadEntry: Lock");
|
LOGV("UsageTableHeader::LoadEntry: Lock");
|
||||||
AutoLock auto_lock(usage_table_header_lock_);
|
std::unique_lock<std::mutex> auto_lock(usage_table_header_lock_);
|
||||||
|
|
||||||
if (usage_entry_number >= usage_entry_info_.size()) {
|
if (usage_entry_number >= usage_entry_info_.size()) {
|
||||||
LOGE(
|
LOGE(
|
||||||
@@ -234,7 +234,7 @@ CdmResponseType UsageTableHeader::LoadEntry(CryptoSession* crypto_session,
|
|||||||
CdmResponseType UsageTableHeader::UpdateEntry(CryptoSession* crypto_session,
|
CdmResponseType UsageTableHeader::UpdateEntry(CryptoSession* crypto_session,
|
||||||
CdmUsageEntry* usage_entry) {
|
CdmUsageEntry* usage_entry) {
|
||||||
LOGV("UsageTableHeader::UpdateEntryL: Lock");
|
LOGV("UsageTableHeader::UpdateEntryL: Lock");
|
||||||
AutoLock auto_lock(usage_table_header_lock_);
|
std::unique_lock<std::mutex> auto_lock(usage_table_header_lock_);
|
||||||
CdmResponseType status =
|
CdmResponseType status =
|
||||||
crypto_session->UpdateUsageEntry(&usage_table_header_, usage_entry);
|
crypto_session->UpdateUsageEntry(&usage_table_header_, usage_entry);
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ CdmResponseType UsageTableHeader::DeleteEntry(uint32_t usage_entry_number,
|
|||||||
DeviceFiles* handle,
|
DeviceFiles* handle,
|
||||||
metrics::CryptoMetrics* metrics) {
|
metrics::CryptoMetrics* metrics) {
|
||||||
LOGV("UsageTableHeader::DeleteEntry: Lock");
|
LOGV("UsageTableHeader::DeleteEntry: Lock");
|
||||||
AutoLock auto_lock(usage_table_header_lock_);
|
std::unique_lock<std::mutex> auto_lock(usage_table_header_lock_);
|
||||||
if (usage_entry_number >= usage_entry_info_.size()) {
|
if (usage_entry_number >= usage_entry_info_.size()) {
|
||||||
LOGE("UsageTableHeader::DeleteEntry: usage entry number %d larger than "
|
LOGE("UsageTableHeader::DeleteEntry: usage entry number %d larger than "
|
||||||
"usage entry size %d", usage_entry_number, usage_entry_info_.size());
|
"usage entry size %d", usage_entry_number, usage_entry_info_.size());
|
||||||
|
|||||||
@@ -7,13 +7,13 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include <utils/RefBase.h>
|
#include <utils/RefBase.h>
|
||||||
|
|
||||||
#include "cdm_identifier.h"
|
#include "cdm_identifier.h"
|
||||||
#include "disallow_copy_and_assign.h"
|
#include "disallow_copy_and_assign.h"
|
||||||
#include "file_store.h"
|
#include "file_store.h"
|
||||||
#include "lock.h"
|
|
||||||
#include "metrics.pb.h"
|
#include "metrics.pb.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "wv_cdm_types.h"
|
#include "wv_cdm_types.h"
|
||||||
@@ -165,14 +165,14 @@ class WvContentDecryptionModule : public android::RefBase, public TimerHandler {
|
|||||||
void DisablePolicyTimer();
|
void DisablePolicyTimer();
|
||||||
void OnTimerEvent();
|
void OnTimerEvent();
|
||||||
|
|
||||||
static Lock session_sharing_id_generation_lock_;
|
static std::mutex session_sharing_id_generation_lock_;
|
||||||
Lock policy_timer_lock_;
|
std::mutex policy_timer_lock_;
|
||||||
Timer policy_timer_;
|
Timer policy_timer_;
|
||||||
|
|
||||||
// instance variables
|
// instance variables
|
||||||
// This manages the lifetime of the CDM instances.
|
// This manages the lifetime of the CDM instances.
|
||||||
std::map<CdmIdentifier, CdmInfo> cdms_;
|
std::map<CdmIdentifier, CdmInfo> cdms_;
|
||||||
Lock cdms_lock_;
|
std::mutex cdms_lock_;
|
||||||
|
|
||||||
// This contains weak pointers to the CDM instances contained in |cdms_|.
|
// This contains weak pointers to the CDM instances contained in |cdms_|.
|
||||||
std::map<std::string, CdmEngine*> cdm_by_session_id_;
|
std::map<std::string, CdmEngine*> cdm_by_session_id_;
|
||||||
|
|||||||
@@ -8,12 +8,12 @@
|
|||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "attribute_handler.h"
|
#include "attribute_handler.h"
|
||||||
#include "field_tuples.h"
|
#include "field_tuples.h"
|
||||||
#include "lock.h"
|
|
||||||
|
|
||||||
namespace wvcdm {
|
namespace wvcdm {
|
||||||
namespace metrics {
|
namespace metrics {
|
||||||
@@ -51,7 +51,7 @@ class BaseCounterMetric {
|
|||||||
* across multiple threads preventing the caller from worrying about
|
* across multiple threads preventing the caller from worrying about
|
||||||
* locking.
|
* locking.
|
||||||
*/
|
*/
|
||||||
Lock internal_lock_;
|
std::mutex internal_lock_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// The CounterMetric class is used to track a counter such as the number of
|
// The CounterMetric class is used to track a counter such as the number of
|
||||||
|
|||||||
@@ -7,13 +7,13 @@
|
|||||||
|
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "OEMCryptoCENC.h"
|
#include "OEMCryptoCENC.h"
|
||||||
#include "attribute_handler.h"
|
#include "attribute_handler.h"
|
||||||
#include "distribution.h"
|
#include "distribution.h"
|
||||||
#include "lock.h"
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "metrics.pb.h"
|
#include "metrics.pb.h"
|
||||||
#include "pow2bucket.h"
|
#include "pow2bucket.h"
|
||||||
@@ -50,7 +50,7 @@ class BaseEventMetric {
|
|||||||
* This locks the internal state of the event metric to ensure safety across
|
* This locks the internal state of the event metric to ensure safety across
|
||||||
* multiple threads preventing the caller from worrying about locking.
|
* multiple threads preventing the caller from worrying about locking.
|
||||||
*/
|
*/
|
||||||
Lock internal_lock_;
|
std::mutex internal_lock_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// The EventMetric class is used to capture statistics about an event such as
|
// The EventMetric class is used to capture statistics about an event such as
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <mutex>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
#include "OEMCryptoCENC.h"
|
#include "OEMCryptoCENC.h"
|
||||||
@@ -313,7 +314,7 @@ class OemCryptoDynamicAdapterMetrics {
|
|||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable Lock adapter_lock_;
|
mutable std::mutex adapter_lock_;
|
||||||
ValueMetric<OEMCryptoInitializationMode> oemcrypto_initialization_mode_;
|
ValueMetric<OEMCryptoInitializationMode> oemcrypto_initialization_mode_;
|
||||||
ValueMetric<uint32_t> oemcrypto_l1_api_version_;
|
ValueMetric<uint32_t> oemcrypto_l1_api_version_;
|
||||||
ValueMetric<uint32_t> oemcrypto_l1_min_api_version_;
|
ValueMetric<uint32_t> oemcrypto_l1_min_api_version_;
|
||||||
@@ -405,7 +406,7 @@ class EngineMetrics {
|
|||||||
cdm_engine_unprovision_;
|
cdm_engine_unprovision_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable Lock session_metrics_lock_;
|
mutable std::mutex session_metrics_lock_;
|
||||||
std::vector<metrics::SessionMetrics *> session_metrics_list_;
|
std::vector<metrics::SessionMetrics *> session_metrics_list_;
|
||||||
// This is used to populate the engine lifespan metric
|
// This is used to populate the engine lifespan metric
|
||||||
metrics::TimerMetric life_span_internal_;
|
metrics::TimerMetric life_span_internal_;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace metrics {
|
|||||||
|
|
||||||
void BaseCounterMetric::Increment(const std::string &counter_key,
|
void BaseCounterMetric::Increment(const std::string &counter_key,
|
||||||
int64_t value) {
|
int64_t value) {
|
||||||
AutoLock lock(internal_lock_);
|
std::unique_lock<std::mutex> lock(internal_lock_);
|
||||||
|
|
||||||
if (value_map_.find(counter_key) == value_map_.end()) {
|
if (value_map_.find(counter_key) == value_map_.end()) {
|
||||||
value_map_[counter_key] = value;
|
value_map_[counter_key] = value;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace wvcdm {
|
|||||||
namespace metrics {
|
namespace metrics {
|
||||||
|
|
||||||
BaseEventMetric::~BaseEventMetric() {
|
BaseEventMetric::~BaseEventMetric() {
|
||||||
AutoLock lock(internal_lock_);
|
std::unique_lock<std::mutex> lock(internal_lock_);
|
||||||
|
|
||||||
for (std::map<std::string, Distribution *>::iterator it = value_map_.begin();
|
for (std::map<std::string, Distribution *>::iterator it = value_map_.begin();
|
||||||
it != value_map_.end(); it++) {
|
it != value_map_.end(); it++) {
|
||||||
@@ -19,7 +19,7 @@ BaseEventMetric::~BaseEventMetric() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BaseEventMetric::Record(const std::string &key, double value) {
|
void BaseEventMetric::Record(const std::string &key, double value) {
|
||||||
AutoLock lock(internal_lock_);
|
std::unique_lock<std::mutex> lock(internal_lock_);
|
||||||
|
|
||||||
Distribution *distribution;
|
Distribution *distribution;
|
||||||
|
|
||||||
|
|||||||
@@ -186,23 +186,23 @@ OemCryptoDynamicAdapterMetrics::OemCryptoDynamicAdapterMetrics()
|
|||||||
|
|
||||||
void OemCryptoDynamicAdapterMetrics::SetInitializationMode(
|
void OemCryptoDynamicAdapterMetrics::SetInitializationMode(
|
||||||
OEMCryptoInitializationMode mode) {
|
OEMCryptoInitializationMode mode) {
|
||||||
AutoLock lock(adapter_lock_);
|
std::unique_lock<std::mutex> lock(adapter_lock_);
|
||||||
oemcrypto_initialization_mode_.Record(mode);
|
oemcrypto_initialization_mode_.Record(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OemCryptoDynamicAdapterMetrics::SetL1ApiVersion(uint32_t version) {
|
void OemCryptoDynamicAdapterMetrics::SetL1ApiVersion(uint32_t version) {
|
||||||
AutoLock lock(adapter_lock_);
|
std::unique_lock<std::mutex> lock(adapter_lock_);
|
||||||
oemcrypto_l1_api_version_.Record(version);
|
oemcrypto_l1_api_version_.Record(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OemCryptoDynamicAdapterMetrics::SetL1MinApiVersion(uint32_t version) {
|
void OemCryptoDynamicAdapterMetrics::SetL1MinApiVersion(uint32_t version) {
|
||||||
AutoLock lock(adapter_lock_);
|
std::unique_lock<std::mutex> lock(adapter_lock_);
|
||||||
oemcrypto_l1_min_api_version_.Record(version);
|
oemcrypto_l1_min_api_version_.Record(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OemCryptoDynamicAdapterMetrics::Serialize(
|
void OemCryptoDynamicAdapterMetrics::Serialize(
|
||||||
WvCdmMetrics::EngineMetrics *engine_metrics) const {
|
WvCdmMetrics::EngineMetrics *engine_metrics) const {
|
||||||
AutoLock lock(adapter_lock_);
|
std::unique_lock<std::mutex> lock(adapter_lock_);
|
||||||
|
|
||||||
engine_metrics->set_allocated_oemcrypto_initialization_mode(
|
engine_metrics->set_allocated_oemcrypto_initialization_mode(
|
||||||
oemcrypto_initialization_mode_.ToProto());
|
oemcrypto_initialization_mode_.ToProto());
|
||||||
@@ -213,7 +213,7 @@ void OemCryptoDynamicAdapterMetrics::Serialize(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OemCryptoDynamicAdapterMetrics::Clear() {
|
void OemCryptoDynamicAdapterMetrics::Clear() {
|
||||||
AutoLock lock(adapter_lock_);
|
std::unique_lock<std::mutex> lock(adapter_lock_);
|
||||||
|
|
||||||
oemcrypto_initialization_mode_.Clear();
|
oemcrypto_initialization_mode_.Clear();
|
||||||
oemcrypto_l1_api_version_.Clear();
|
oemcrypto_l1_api_version_.Clear();
|
||||||
@@ -235,7 +235,7 @@ EngineMetrics::EngineMetrics() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EngineMetrics::~EngineMetrics() {
|
EngineMetrics::~EngineMetrics() {
|
||||||
AutoLock lock(session_metrics_lock_);
|
std::unique_lock<std::mutex> lock(session_metrics_lock_);
|
||||||
std::vector<SessionMetrics *>::iterator i;
|
std::vector<SessionMetrics *>::iterator i;
|
||||||
if (!session_metrics_list_.empty()) {
|
if (!session_metrics_list_.empty()) {
|
||||||
LOGV("EngineMetrics::~EngineMetrics. Session count: %d",
|
LOGV("EngineMetrics::~EngineMetrics. Session count: %d",
|
||||||
@@ -249,14 +249,14 @@ EngineMetrics::~EngineMetrics() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SessionMetrics *EngineMetrics::AddSession() {
|
SessionMetrics *EngineMetrics::AddSession() {
|
||||||
AutoLock lock(session_metrics_lock_);
|
std::unique_lock<std::mutex> lock(session_metrics_lock_);
|
||||||
SessionMetrics *metrics = new SessionMetrics();
|
SessionMetrics *metrics = new SessionMetrics();
|
||||||
session_metrics_list_.push_back(metrics);
|
session_metrics_list_.push_back(metrics);
|
||||||
return metrics;
|
return metrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EngineMetrics::RemoveSession(wvcdm::CdmSessionId session_id) {
|
void EngineMetrics::RemoveSession(wvcdm::CdmSessionId session_id) {
|
||||||
AutoLock lock(session_metrics_lock_);
|
std::unique_lock<std::mutex> lock(session_metrics_lock_);
|
||||||
session_metrics_list_.erase(
|
session_metrics_list_.erase(
|
||||||
std::remove_if(session_metrics_list_.begin(), session_metrics_list_.end(),
|
std::remove_if(session_metrics_list_.begin(), session_metrics_list_.end(),
|
||||||
CompareSessionIds(session_id)),
|
CompareSessionIds(session_id)),
|
||||||
@@ -264,7 +264,7 @@ void EngineMetrics::RemoveSession(wvcdm::CdmSessionId session_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EngineMetrics::Serialize(WvCdmMetrics *wv_metrics) const {
|
void EngineMetrics::Serialize(WvCdmMetrics *wv_metrics) const {
|
||||||
AutoLock lock(session_metrics_lock_);
|
std::unique_lock<std::mutex> lock(session_metrics_lock_);
|
||||||
WvCdmMetrics::EngineMetrics *engine_metrics =
|
WvCdmMetrics::EngineMetrics *engine_metrics =
|
||||||
wv_metrics->mutable_engine_metrics();
|
wv_metrics->mutable_engine_metrics();
|
||||||
// Serialize the most recent metrics from the OemCyrpto dynamic adapter.
|
// Serialize the most recent metrics from the OemCyrpto dynamic adapter.
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const int kCdmPolicyTimerDurationSeconds = 1;
|
|||||||
|
|
||||||
namespace wvcdm {
|
namespace wvcdm {
|
||||||
|
|
||||||
Lock WvContentDecryptionModule::session_sharing_id_generation_lock_;
|
std::mutex WvContentDecryptionModule::session_sharing_id_generation_lock_;
|
||||||
|
|
||||||
WvContentDecryptionModule::WvContentDecryptionModule() {}
|
WvContentDecryptionModule::WvContentDecryptionModule() {}
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ CdmResponseType WvContentDecryptionModule::OpenSession(
|
|||||||
const CdmIdentifier& identifier, WvCdmEventListener* event_listener,
|
const CdmIdentifier& identifier, WvCdmEventListener* event_listener,
|
||||||
CdmSessionId* session_id) {
|
CdmSessionId* session_id) {
|
||||||
if (property_set && property_set->is_session_sharing_enabled()) {
|
if (property_set && property_set->is_session_sharing_enabled()) {
|
||||||
AutoLock auto_lock(session_sharing_id_generation_lock_);
|
std::unique_lock<std::mutex> auto_lock(session_sharing_id_generation_lock_);
|
||||||
if (property_set->session_sharing_id() == 0)
|
if (property_set->session_sharing_id() == 0)
|
||||||
property_set->set_session_sharing_id(GenerateSessionSharingId());
|
property_set->set_session_sharing_id(GenerateSessionSharingId());
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,7 @@ CdmResponseType WvContentDecryptionModule::CloseSession(
|
|||||||
CdmEngine* cdm_engine = GetCdmForSessionId(session_id);
|
CdmEngine* cdm_engine = GetCdmForSessionId(session_id);
|
||||||
// TODO(rfrias): Avoid reusing the error codes from CdmEngine.
|
// TODO(rfrias): Avoid reusing the error codes from CdmEngine.
|
||||||
if (!cdm_engine) return SESSION_NOT_FOUND_1;
|
if (!cdm_engine) return SESSION_NOT_FOUND_1;
|
||||||
AutoLock auto_lock(cdms_lock_);
|
std::unique_lock<std::mutex> auto_lock(cdms_lock_);
|
||||||
CdmResponseType sts = cdm_engine->CloseSession(session_id);
|
CdmResponseType sts = cdm_engine->CloseSession(session_id);
|
||||||
cdm_engine->GetMetrics()->cdm_engine_close_session_.Increment(sts);
|
cdm_engine->GetMetrics()->cdm_engine_close_session_.Increment(sts);
|
||||||
if (sts == NO_ERROR) {
|
if (sts == NO_ERROR) {
|
||||||
@@ -366,7 +366,7 @@ CdmResponseType WvContentDecryptionModule::GetMetrics(
|
|||||||
if (!metrics) {
|
if (!metrics) {
|
||||||
return PARAMETER_NULL;
|
return PARAMETER_NULL;
|
||||||
}
|
}
|
||||||
AutoLock auto_lock(cdms_lock_);
|
std::unique_lock<std::mutex> auto_lock(cdms_lock_);
|
||||||
auto it = cdms_.find(identifier);
|
auto it = cdms_.find(identifier);
|
||||||
if (it == cdms_.end()) {
|
if (it == cdms_.end()) {
|
||||||
LOGE("WVContentDecryptionModule::GetMetrics. cdm_identifier not found");
|
LOGE("WVContentDecryptionModule::GetMetrics. cdm_identifier not found");
|
||||||
@@ -382,7 +382,7 @@ WvContentDecryptionModule::CdmInfo::CdmInfo()
|
|||||||
|
|
||||||
CdmEngine* WvContentDecryptionModule::EnsureCdmForIdentifier(
|
CdmEngine* WvContentDecryptionModule::EnsureCdmForIdentifier(
|
||||||
const CdmIdentifier& identifier) {
|
const CdmIdentifier& identifier) {
|
||||||
AutoLock auto_lock(cdms_lock_);
|
std::unique_lock<std::mutex> auto_lock(cdms_lock_);
|
||||||
if (cdms_.find(identifier) == cdms_.end()) {
|
if (cdms_.find(identifier) == cdms_.end()) {
|
||||||
// Accessing the map entry will create a new instance using the default
|
// Accessing the map entry will create a new instance using the default
|
||||||
// constructor. We then need to provide it with two pieces of info: The
|
// constructor. We then need to provide it with two pieces of info: The
|
||||||
@@ -411,7 +411,7 @@ CdmEngine* WvContentDecryptionModule::GetCdmForSessionId(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WvContentDecryptionModule::CloseAllCdms() {
|
void WvContentDecryptionModule::CloseAllCdms() {
|
||||||
AutoLock auto_lock(cdms_lock_);
|
std::unique_lock<std::mutex> auto_lock(cdms_lock_);
|
||||||
|
|
||||||
for (auto it = cdms_.begin(); it != cdms_.end();) {
|
for (auto it = cdms_.begin(); it != cdms_.end();) {
|
||||||
it = cdms_.erase(it);
|
it = cdms_.erase(it);
|
||||||
@@ -426,7 +426,7 @@ CdmResponseType WvContentDecryptionModule::CloseCdm(
|
|||||||
// Acquire the cdms_lock_ first, in its own scope.
|
// Acquire the cdms_lock_ first, in its own scope.
|
||||||
bool cdms_empty = false;
|
bool cdms_empty = false;
|
||||||
{
|
{
|
||||||
AutoLock auto_lock(cdms_lock_);
|
std::unique_lock<std::mutex> auto_lock(cdms_lock_);
|
||||||
auto it = cdms_.find(cdm_identifier);
|
auto it = cdms_.find(cdm_identifier);
|
||||||
if (it == cdms_.end()) {
|
if (it == cdms_.end()) {
|
||||||
LOGE("WVContentDecryptionModule::Close. cdm_identifier not found.");
|
LOGE("WVContentDecryptionModule::Close. cdm_identifier not found.");
|
||||||
@@ -453,20 +453,20 @@ CdmResponseType WvContentDecryptionModule::CloseCdm(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WvContentDecryptionModule::EnablePolicyTimer() {
|
void WvContentDecryptionModule::EnablePolicyTimer() {
|
||||||
AutoLock auto_lock(policy_timer_lock_);
|
std::unique_lock<std::mutex> auto_lock(policy_timer_lock_);
|
||||||
if (!policy_timer_.IsRunning())
|
if (!policy_timer_.IsRunning())
|
||||||
policy_timer_.Start(this, kCdmPolicyTimerDurationSeconds);
|
policy_timer_.Start(this, kCdmPolicyTimerDurationSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WvContentDecryptionModule::DisablePolicyTimer() {
|
void WvContentDecryptionModule::DisablePolicyTimer() {
|
||||||
AutoLock auto_lock(policy_timer_lock_);
|
std::unique_lock<std::mutex> auto_lock(policy_timer_lock_);
|
||||||
if (policy_timer_.IsRunning()) {
|
if (policy_timer_.IsRunning()) {
|
||||||
policy_timer_.Stop();
|
policy_timer_.Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WvContentDecryptionModule::OnTimerEvent() {
|
void WvContentDecryptionModule::OnTimerEvent() {
|
||||||
AutoLock auto_lock(cdms_lock_);
|
std::unique_lock<std::mutex> auto_lock(cdms_lock_);
|
||||||
for (auto it = cdms_.begin(); it != cdms_.end(); ++it) {
|
for (auto it = cdms_.begin(); it != cdms_.end(); ++it) {
|
||||||
it->second.cdm_engine->OnTimerEvent();
|
it->second.cdm_engine->OnTimerEvent();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ CryptoEngine::CryptoEngine(std::unique_ptr<wvcdm::FileSystem>&& file_system)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CryptoEngine::~CryptoEngine() {
|
CryptoEngine::~CryptoEngine() {
|
||||||
wvcdm::AutoLock lock(session_table_lock_);
|
std::unique_lock<std::mutex> lock(session_table_lock_);
|
||||||
ActiveSessions::iterator it;
|
ActiveSessions::iterator it;
|
||||||
for (it = sessions_.begin(); it != sessions_.end(); ++it) {
|
for (it = sessions_.begin(); it != sessions_.end(); ++it) {
|
||||||
delete it->second;
|
delete it->second;
|
||||||
@@ -53,7 +53,7 @@ bool CryptoEngine::Initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SessionId CryptoEngine::OpenSession() {
|
SessionId CryptoEngine::OpenSession() {
|
||||||
wvcdm::AutoLock lock(session_table_lock_);
|
std::unique_lock<std::mutex> lock(session_table_lock_);
|
||||||
static OEMCrypto_SESSION unique_id = 1;
|
static OEMCrypto_SESSION unique_id = 1;
|
||||||
SessionId id = ++unique_id;
|
SessionId id = ++unique_id;
|
||||||
sessions_[id] = MakeSession(id);
|
sessions_[id] = MakeSession(id);
|
||||||
@@ -68,7 +68,7 @@ UsageTable* CryptoEngine::MakeUsageTable() { return new UsageTable(this); }
|
|||||||
|
|
||||||
bool CryptoEngine::DestroySession(SessionId sid) {
|
bool CryptoEngine::DestroySession(SessionId sid) {
|
||||||
SessionContext* sctx = FindSession(sid);
|
SessionContext* sctx = FindSession(sid);
|
||||||
wvcdm::AutoLock lock(session_table_lock_);
|
std::unique_lock<std::mutex> lock(session_table_lock_);
|
||||||
if (sctx) {
|
if (sctx) {
|
||||||
sessions_.erase(sid);
|
sessions_.erase(sid);
|
||||||
delete sctx;
|
delete sctx;
|
||||||
@@ -79,7 +79,7 @@ bool CryptoEngine::DestroySession(SessionId sid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SessionContext* CryptoEngine::FindSession(SessionId sid) {
|
SessionContext* CryptoEngine::FindSession(SessionId sid) {
|
||||||
wvcdm::AutoLock lock(session_table_lock_);
|
std::unique_lock<std::mutex> lock(session_table_lock_);
|
||||||
ActiveSessions::iterator it = sessions_.find(sid);
|
ActiveSessions::iterator it = sessions_.find(sid);
|
||||||
if (it != sessions_.end()) {
|
if (it != sessions_.end()) {
|
||||||
return it->second;
|
return it->second;
|
||||||
|
|||||||
@@ -11,13 +11,13 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <openssl/rsa.h>
|
#include <openssl/rsa.h>
|
||||||
|
|
||||||
#include "OEMCryptoCENC.h"
|
#include "OEMCryptoCENC.h"
|
||||||
#include "file_store.h"
|
#include "file_store.h"
|
||||||
#include "lock.h"
|
|
||||||
#include "oemcrypto_auth_ref.h"
|
#include "oemcrypto_auth_ref.h"
|
||||||
#include "oemcrypto_key_ref.h"
|
#include "oemcrypto_key_ref.h"
|
||||||
#include "oemcrypto_rsa_key_shared.h"
|
#include "oemcrypto_rsa_key_shared.h"
|
||||||
@@ -201,7 +201,7 @@ class CryptoEngine {
|
|||||||
uint8_t* destination_;
|
uint8_t* destination_;
|
||||||
ActiveSessions sessions_;
|
ActiveSessions sessions_;
|
||||||
AuthenticationRoot root_of_trust_;
|
AuthenticationRoot root_of_trust_;
|
||||||
wvcdm::Lock session_table_lock_;
|
std::mutex session_table_lock_;
|
||||||
std::unique_ptr<wvcdm::FileSystem> file_system_;
|
std::unique_ptr<wvcdm::FileSystem> file_system_;
|
||||||
std::unique_ptr<UsageTable> usage_table_;
|
std::unique_ptr<UsageTable> usage_table_;
|
||||||
|
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ OldUsageTable::OldUsageTable(CryptoEngine *ce) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OldUsageTableEntry *OldUsageTable::FindEntry(const std::vector<uint8_t> &pst) {
|
OldUsageTableEntry *OldUsageTable::FindEntry(const std::vector<uint8_t> &pst) {
|
||||||
wvcdm::AutoLock lock(lock_);
|
std::unique_lock<std::mutex> lock(lock_);
|
||||||
return FindEntryLocked(pst);
|
return FindEntryLocked(pst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,13 +192,13 @@ OldUsageTableEntry *OldUsageTable::CreateEntry(
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
OldUsageTableEntry *entry = new OldUsageTableEntry(this, pst_hash);
|
OldUsageTableEntry *entry = new OldUsageTableEntry(this, pst_hash);
|
||||||
wvcdm::AutoLock lock(lock_);
|
std::unique_lock<std::mutex> lock(lock_);
|
||||||
table_[pst_hash] = entry;
|
table_[pst_hash] = entry;
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OldUsageTable::Clear() {
|
void OldUsageTable::Clear() {
|
||||||
wvcdm::AutoLock lock(lock_);
|
std::unique_lock<std::mutex> lock(lock_);
|
||||||
for (EntryMap::iterator i = table_.begin(); i != table_.end(); ++i) {
|
for (EntryMap::iterator i = table_.begin(); i != table_.end(); ++i) {
|
||||||
if (i->second) delete i->second;
|
if (i->second) delete i->second;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,11 +12,11 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "OEMCryptoCENC.h"
|
#include "OEMCryptoCENC.h"
|
||||||
#include "lock.h"
|
|
||||||
#include "oemcrypto_types.h"
|
#include "oemcrypto_types.h"
|
||||||
#include "openssl/sha.h"
|
#include "openssl/sha.h"
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ class OldUsageTable {
|
|||||||
|
|
||||||
typedef std::map<std::vector<uint8_t>, OldUsageTableEntry *> EntryMap;
|
typedef std::map<std::vector<uint8_t>, OldUsageTableEntry *> EntryMap;
|
||||||
EntryMap table_;
|
EntryMap table_;
|
||||||
wvcdm::Lock lock_;
|
std::mutex lock_;
|
||||||
int64_t generation_;
|
int64_t generation_;
|
||||||
CryptoEngine *ce_;
|
CryptoEngine *ce_;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user