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:
@@ -75,7 +75,7 @@ void DeleteX509Stack(STACK_OF(X509)* stack) {
|
||||
}
|
||||
|
||||
namespace wvcdm {
|
||||
Lock CryptoSession::crypto_lock_;
|
||||
std::mutex CryptoSession::crypto_lock_;
|
||||
bool CryptoSession::initialized_ = false;
|
||||
int CryptoSession::session_count_ = 0;
|
||||
uint64_t CryptoSession::request_id_index_ = 0;
|
||||
@@ -212,7 +212,7 @@ CdmResponseType CryptoSession::GetProvisioningMethod(
|
||||
|
||||
void CryptoSession::Init() {
|
||||
LOGV("CryptoSession::Init");
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||
session_count_ += 1;
|
||||
if (!initialized_) {
|
||||
std::string sandbox_id;
|
||||
@@ -235,7 +235,7 @@ void CryptoSession::Init() {
|
||||
void CryptoSession::Terminate() {
|
||||
LOGV("CryptoSession::Terminate: initialized_=%d, session_count_=%d",
|
||||
initialized_, session_count_);
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||
if (session_count_ > 0) {
|
||||
session_count_ -= 1;
|
||||
} else {
|
||||
@@ -322,7 +322,7 @@ bool CryptoSession::GetProvisioningToken(std::string* token) {
|
||||
return false;
|
||||
}
|
||||
LOGV("CryptoSession::GetProvisioningToken: Lock");
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||
|
||||
if (!initialized_) {
|
||||
metrics_->crypto_session_get_token_.Increment(false);
|
||||
@@ -380,7 +380,7 @@ bool CryptoSession::GetInternalDeviceUniqueId(std::string* device_id) {
|
||||
}
|
||||
|
||||
LOGV("CryptoSession::GetInternalDeviceUniqueId: Lock");
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||
if (!initialized_) {
|
||||
return false;
|
||||
}
|
||||
@@ -473,7 +473,7 @@ bool CryptoSession::GetSystemId(uint32_t* system_id) {
|
||||
}
|
||||
|
||||
LOGV("CryptoSession::GetSystemId: Lock");
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||
if (!initialized_ || !open_) {
|
||||
return false;
|
||||
}
|
||||
@@ -642,7 +642,7 @@ bool CryptoSession::GetProvisioningId(std::string* provisioning_id) {
|
||||
|
||||
{
|
||||
LOGV("CryptoSession::GetProvisioningId: Lock");
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||
if (!initialized_) {
|
||||
return false;
|
||||
}
|
||||
@@ -663,7 +663,7 @@ bool CryptoSession::GetProvisioningId(std::string* provisioning_id) {
|
||||
} else {
|
||||
OEMCryptoResult sts;
|
||||
LOGV("CryptoSession::GetProvisioningId: Lock");
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||
M_TIME(
|
||||
sts = OEMCrypto_GetKeyData(buf, &buf_size, requested_security_level_),
|
||||
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
|
||||
? QUERY_VALUE_SECURITY_LEVEL_L3.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 (open_) return NO_ERROR;
|
||||
}
|
||||
@@ -699,7 +699,7 @@ CdmResponseType CryptoSession::Open(SecurityLevel requested_security_level) {
|
||||
if (result != NO_ERROR) return result;
|
||||
|
||||
LOGV("CryptoSession::Open: Lock");
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||
OEMCrypto_SESSION sid;
|
||||
requested_security_level_ = 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,
|
||||
// if it is intended to be used for offline/usage session related
|
||||
// or otherwise.
|
||||
crypto_lock_.Release();
|
||||
auto_lock.unlock();
|
||||
bool is_usage_table_header_inited =
|
||||
(*header)->Init(security_level, this);
|
||||
crypto_lock_.Acquire();
|
||||
auto_lock.lock();
|
||||
if (!is_usage_table_header_inited) {
|
||||
delete *header;
|
||||
*header = NULL;
|
||||
@@ -783,7 +783,7 @@ void CryptoSession::Close() {
|
||||
OEMCryptoResult close_sts;
|
||||
bool update_usage_table = false;
|
||||
{
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||
if (!open_) return;
|
||||
|
||||
close_sts = OEMCrypto_CloseSession(oec_session_id_);
|
||||
@@ -799,7 +799,7 @@ void CryptoSession::Close() {
|
||||
|
||||
bool CryptoSession::GenerateRequestId(std::string* req_id_str) {
|
||||
LOGV("CryptoSession::GenerateRequestId: Lock");
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||
if (!req_id_str) {
|
||||
LOGE("CryptoSession::GenerateRequestId: No output destination provided.");
|
||||
return false;
|
||||
@@ -816,7 +816,7 @@ bool CryptoSession::PrepareRequest(const std::string& message,
|
||||
bool is_provisioning,
|
||||
std::string* signature) {
|
||||
LOGV("CryptoSession::PrepareRequest: Lock");
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||
|
||||
if (!signature) {
|
||||
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,
|
||||
std::string* signature) {
|
||||
LOGV("CryptoSession::PrepareRenewalRequest: Lock");
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||
|
||||
if (!signature) {
|
||||
LOGE(
|
||||
@@ -862,7 +862,7 @@ CdmResponseType CryptoSession::LoadKeys(
|
||||
CdmResponseType result = KEY_ADDED;
|
||||
{
|
||||
LOGV("CryptoSession::LoadKeys: Lock");
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||
|
||||
if (key_type == kLicenseKeyTypeEntitlement &&
|
||||
key_session_->Type() != KeySession::kEntitlement) {
|
||||
@@ -901,7 +901,7 @@ CdmResponseType CryptoSession::LoadKeys(
|
||||
CdmResponseType CryptoSession::LoadEntitledContentKeys(
|
||||
const std::vector<CryptoKey>& key_array) {
|
||||
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);
|
||||
|
||||
@@ -920,7 +920,7 @@ CdmResponseType CryptoSession::LoadEntitledContentKeys(
|
||||
|
||||
bool CryptoSession::LoadCertificatePrivateKey(std::string& wrapped_key) {
|
||||
LOGV("CryptoSession::LoadCertificatePrivateKey: Lock");
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||
|
||||
// Call OEMCrypto_GetOEMPublicCertificate before OEMCrypto_LoadDeviceRSAKey
|
||||
// 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 CryptoKey* key_array) {
|
||||
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());
|
||||
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.skip = params.pattern_descriptor.skip_blocks;
|
||||
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
|
||||
if (params.is_encrypted) {
|
||||
CdmResponseType result = SelectKey(*params.key_id, params.cipher_mode);
|
||||
@@ -1216,7 +1216,7 @@ bool CryptoSession::UsageInformationSupport(bool* has_support) {
|
||||
CdmResponseType CryptoSession::UpdateUsageInformation() {
|
||||
LOGV("CryptoSession::UpdateUsageInformation: id=%lu",
|
||||
oec_session_id_);
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||
if (!initialized_) return UNKNOWN_ERROR;
|
||||
|
||||
if (usage_table_header_ != NULL) {
|
||||
@@ -1237,7 +1237,7 @@ CdmResponseType CryptoSession::DeactivateUsageInformation(
|
||||
const std::string& provider_session_token) {
|
||||
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*>(
|
||||
const_cast<char*>(provider_session_token.data()));
|
||||
|
||||
@@ -1269,7 +1269,7 @@ CdmResponseType CryptoSession::GenerateUsageReport(
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||
uint8_t* pst = reinterpret_cast<uint8_t*>(
|
||||
const_cast<char*>(provider_session_token.data()));
|
||||
|
||||
@@ -1355,7 +1355,7 @@ CdmResponseType CryptoSession::ReleaseUsageInformation(
|
||||
const std::string& provider_session_token) {
|
||||
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) {
|
||||
LOGW("ReleaseUsageInformation: deprecated for OEMCrypto v13+");
|
||||
return NO_ERROR;
|
||||
@@ -1387,7 +1387,7 @@ CdmResponseType CryptoSession::DeleteUsageInformation(
|
||||
LOGV("CryptoSession::DeleteUsageInformation");
|
||||
OEMCryptoResult status;
|
||||
{
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||
status = OEMCrypto_ForceDeleteUsageEntry(
|
||||
reinterpret_cast<const uint8_t*>(provider_session_token.c_str()),
|
||||
provider_session_token.length());
|
||||
@@ -1409,7 +1409,7 @@ CdmResponseType CryptoSession::DeleteMultipleUsageInformation(
|
||||
LOGV("CryptoSession::DeleteMultipleUsageInformation");
|
||||
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) {
|
||||
OEMCryptoResult status = OEMCrypto_ForceDeleteUsageEntry(
|
||||
reinterpret_cast<const uint8_t*>(provider_session_tokens[i].c_str()),
|
||||
@@ -1432,7 +1432,7 @@ CdmResponseType CryptoSession::DeleteAllUsageReports() {
|
||||
LOGV("DeleteAllUsageReports");
|
||||
OEMCryptoResult status;
|
||||
{
|
||||
AutoLock auto_lock(crypto_lock_);
|
||||
std::unique_lock<std::mutex> auto_lock(crypto_lock_);
|
||||
status = OEMCrypto_DeleteOldUsageTable();
|
||||
metrics_->oemcrypto_delete_usage_table_.Increment(status);
|
||||
if (OEMCrypto_SUCCESS != status) {
|
||||
@@ -1461,7 +1461,7 @@ bool CryptoSession::GenerateNonce(uint32_t* nonce) {
|
||||
}
|
||||
|
||||
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);
|
||||
metrics_->oemcrypto_generate_nonce_.Increment(result);
|
||||
@@ -1831,7 +1831,7 @@ CdmResponseType CryptoSession::GenericEncrypt(const std::string& in_buffer,
|
||||
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
|
||||
// doesn't seem to fit. Is it ok to just use a default value here?
|
||||
// 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());
|
||||
}
|
||||
|
||||
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
|
||||
// doesn't seem to fit. Is it ok to just use a default value here?
|
||||
// Or do we need to pass it in?
|
||||
@@ -1934,7 +1934,7 @@ CdmResponseType CryptoSession::GenericSign(const std::string& message,
|
||||
OEMCryptoResult sts;
|
||||
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
|
||||
// doesn't seem to fit. Is it ok to just use a default value here?
|
||||
// Or do we need to pass it in?
|
||||
@@ -1988,7 +1988,7 @@ CdmResponseType CryptoSession::GenericVerify(const std::string& message,
|
||||
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
|
||||
// doesn't seem to fit. Is it ok to just use a default value here?
|
||||
// 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& provider_session_token) {
|
||||
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 ||
|
||||
client_mac_key.size() < MAC_KEY_SIZE) {
|
||||
|
||||
Reference in New Issue
Block a user