Reformat wv core/src files

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

Clang-format has been run on files in core/src. clang-format has been turned
off for some blocks but otherwise no other changes have been made.

Bug: 134365840
Test: WV unit/integration tests
Change-Id: I6e509f25136f84d37de3d920084302f0f2c23dc4
This commit is contained in:
Rahul Frias
2019-06-03 17:14:18 -07:00
parent 47c2068d6a
commit a178eed57d
20 changed files with 713 additions and 760 deletions

View File

@@ -8,6 +8,7 @@
#include "crypto_session.h"
#include <string.h>
#include <algorithm>
#include <iostream>
#include <memory>
@@ -129,17 +130,16 @@ OEMCrypto_LicenseType OEMCryptoLicenseType(CdmLicenseKeyType cdm_license_type) {
}
OEMCryptoCipherMode ToOEMCryptoCipherMode(CdmCipherMode cipher_mode) {
return cipher_mode == kCipherModeCtr
? OEMCrypto_CipherMode_CTR : OEMCrypto_CipherMode_CBC;
return cipher_mode == kCipherModeCtr ? OEMCrypto_CipherMode_CTR
: OEMCrypto_CipherMode_CBC;
}
// This maps a few common OEMCryptoResult to CdmResponseType. Many mappings
// are not universal but are OEMCrypto method specific. Those will be
// specified in the CryptoSession method rather than here.
CdmResponseType MapOEMCryptoResult(
OEMCryptoResult result,
CdmResponseType default_status,
const char* error_string) {
CdmResponseType MapOEMCryptoResult(OEMCryptoResult result,
CdmResponseType default_status,
const char* error_string) {
if (result != OEMCrypto_SUCCESS) {
LOGE("%s: error %d", error_string, result);
}
@@ -187,8 +187,7 @@ CryptoSession::~CryptoSession() {
}
CdmResponseType CryptoSession::GetProvisioningMethod(
SecurityLevel requested_security_level,
CdmClientTokenType* token_type) {
SecurityLevel requested_security_level, CdmClientTokenType* token_type) {
OEMCrypto_ProvisioningMethod method;
WithOecReadLock("GetProvisioningMethod", [&] {
method = OEMCrypto_GetProvisioningMethod(requested_security_level);
@@ -252,9 +251,7 @@ void CryptoSession::Terminate() {
}
if (session_count_ > 0 || !initialized_) return;
OEMCryptoResult sts;
WithOecWriteLock("Terminate", [&] {
sts = OEMCrypto_Terminate();
});
WithOecWriteLock("Terminate", [&] { sts = OEMCrypto_Terminate(); });
if (OEMCrypto_SUCCESS != sts) {
LOGE("OEMCrypto_Terminate failed: %d", sts);
}
@@ -283,19 +280,18 @@ CdmResponseType CryptoSession::GetTokenFromKeybox(std::string* token) {
OEMCryptoResult status;
WithOecReadLock("GetTokenFromKeybox", [&] {
M_TIME(
status =
OEMCrypto_GetKeyData(buf, &buf_size, requested_security_level_),
metrics_, oemcrypto_get_key_data_, status,
metrics::Pow2Bucket(buf_size));
M_TIME(status =
OEMCrypto_GetKeyData(buf, &buf_size, requested_security_level_),
metrics_, oemcrypto_get_key_data_, status,
metrics::Pow2Bucket(buf_size));
});
if (OEMCrypto_SUCCESS == status) {
token->swap(temp_buffer);
}
return MapOEMCryptoResult(
status, GET_TOKEN_FROM_KEYBOX_ERROR, "GetTokenFromKeybox");
return MapOEMCryptoResult(status, GET_TOKEN_FROM_KEYBOX_ERROR,
"GetTokenFromKeybox");
}
CdmResponseType CryptoSession::GetTokenFromOemCert(std::string* token) {
@@ -314,8 +310,8 @@ CdmResponseType CryptoSession::GetTokenFromOemCert(std::string* token) {
size_t buf_size = temp_buffer.size();
uint8_t* buf = reinterpret_cast<uint8_t*>(&temp_buffer[0]);
WithOecSessionLock("GetTokenFromOemCert", [&] {
status = OEMCrypto_GetOEMPublicCertificate(oec_session_id_, buf,
&buf_size);
status =
OEMCrypto_GetOEMPublicCertificate(oec_session_id_, buf, &buf_size);
});
metrics_->oemcrypto_get_oem_public_certificate_.Increment(status);
@@ -332,8 +328,8 @@ CdmResponseType CryptoSession::GetTokenFromOemCert(std::string* token) {
continue;
}
return MapOEMCryptoResult(
status, GET_TOKEN_FROM_OEM_CERT_ERROR, "GetTokenFromOemCert");
return MapOEMCryptoResult(status, GET_TOKEN_FROM_OEM_CERT_ERROR,
"GetTokenFromOemCert");
}
}
@@ -345,7 +341,8 @@ CdmResponseType CryptoSession::GetProvisioningToken(std::string* token) {
}
if (!IsInitialized()) {
metrics_->crypto_session_get_token_.Increment(CRYPTO_SESSION_NOT_INITIALIZED);
metrics_->crypto_session_get_token_.Increment(
CRYPTO_SESSION_NOT_INITIALIZED);
return CRYPTO_SESSION_NOT_INITIALIZED;
}
@@ -431,8 +428,8 @@ CdmResponseType CryptoSession::GetInternalDeviceUniqueId(
if (sts == OEMCrypto_ERROR_SHORT_BUFFER) {
id.resize(id_length);
WithOecReadLock("GetInternalDeviceUniqueId Attempt 2", [&] {
sts = OEMCrypto_GetDeviceID(&id[0], &id_length,
requested_security_level_);
sts =
OEMCrypto_GetDeviceID(&id[0], &id_length, requested_security_level_);
});
metrics_->oemcrypto_get_device_id_.Increment(sts);
}
@@ -451,8 +448,8 @@ CdmResponseType CryptoSession::GetInternalDeviceUniqueId(
device_id->assign(reinterpret_cast<char*>(&id[0]), id_length);
}
return MapOEMCryptoResult(
sts, GET_DEVICE_ID_ERROR, "GetInternalDeviceUniqueId");
return MapOEMCryptoResult(sts, GET_DEVICE_ID_ERROR,
"GetInternalDeviceUniqueId");
}
}
@@ -507,9 +504,8 @@ bool CryptoSession::GetApiVersion(SecurityLevel security_level,
return false;
}
WithOecReadLock("GetApiVersion", [&] {
*version = OEMCrypto_APIVersion(security_level);
});
WithOecReadLock("GetApiVersion",
[&] { *version = OEMCrypto_APIVersion(security_level); });
// Record the version into the metrics.
metrics_->oemcrypto_api_version_.Record(*version);
@@ -544,7 +540,7 @@ CdmResponseType CryptoSession::GetSystemIdInternal(uint32_t* system_id) {
if (status != NO_ERROR) return status;
if (token.size() < 2*sizeof(uint32_t)) {
if (token.size() < 2 * sizeof(uint32_t)) {
LOGE("CryptoSession::GetSystemIdInternal: Keybox token too small: %d",
token.size());
return KEYBOX_TOKEN_TOO_SHORT;
@@ -568,13 +564,15 @@ CdmResponseType CryptoSession::GetSystemIdInternal(uint32_t* system_id) {
return NO_ERROR;
// TODO(blueeyes): Support loading the system id from a pre-provisioned
// Drm certificate.
// TODO(blueeyes): Support loading the system id from a pre-provisioned
// Drm certificate.
} else if (pre_provision_token_type_ == kClientTokenDrmCert) {
return NO_ERROR;
} else {
LOGE("CryptoSession::GetSystemIdInternal: "
"Unsupported pre-provision token type %d", pre_provision_token_type_);
LOGE(
"CryptoSession::GetSystemIdInternal: "
"Unsupported pre-provision token type %d",
pre_provision_token_type_);
return UNKNOWN_CLIENT_TOKEN_TYPE;
}
}
@@ -647,9 +645,8 @@ CdmResponseType CryptoSession::Open(SecurityLevel requested_security_level) {
if (!IsInitialized()) return UNKNOWN_ERROR;
if (open_) return NO_ERROR;
CdmResponseType result =
GetProvisioningMethod(requested_security_level,
&pre_provision_token_type_);
CdmResponseType result = GetProvisioningMethod(requested_security_level,
&pre_provision_token_type_);
if (result != NO_ERROR) return result;
OEMCrypto_SESSION sid;
@@ -661,8 +658,7 @@ CdmResponseType CryptoSession::Open(SecurityLevel requested_security_level) {
if (sts != OEMCrypto_SUCCESS) {
WithStaticFieldReadLock(
"Open() reporting OEMCrypto_OpenSession Failure",
[&] {
"Open() reporting OEMCrypto_OpenSession Failure", [&] {
LOGE("OEMCrypto_Open failed: %d, open sessions: %ld, initialized: %d",
sts, session_count_, (int)initialized_);
});
@@ -757,9 +753,8 @@ void CryptoSession::Close() {
OEMCryptoResult close_sts;
bool update_usage_table = false;
WithOecWriteLock("Close", [&] {
close_sts = OEMCrypto_CloseSession(oec_session_id_);
});
WithOecWriteLock(
"Close", [&] { close_sts = OEMCrypto_CloseSession(oec_session_id_); });
metrics_->oemcrypto_close_session_.Increment(close_sts);
if (OEMCrypto_SUCCESS == close_sts) open_ = false;
update_usage_table = update_usage_table_after_close_session_;
@@ -816,9 +811,9 @@ CdmResponseType CryptoSession::LoadKeys(
}
LOGV("LoadKeys: id=%lu", oec_session_id_);
sts = key_session_->LoadKeys(
message, signature, mac_key_iv, mac_key, keys, provider_session_token,
&cipher_mode_, srm_requirement);
sts = key_session_->LoadKeys(message, signature, mac_key_iv, mac_key, keys,
provider_session_token, &cipher_mode_,
srm_requirement);
});
if (sts != OEMCrypto_SUCCESS) {
@@ -896,8 +891,7 @@ CdmResponseType CryptoSession::LoadCertificatePrivateKey(
LOGV("LoadDeviceRSAKey: id=%lu", oec_session_id_);
WithOecSessionLock(
"LoadCertificatePrivateKey() calling OEMCrypto_LoadDeviceRSAKey()",
[&] {
"LoadCertificatePrivateKey() calling OEMCrypto_LoadDeviceRSAKey()", [&] {
M_TIME(sts = OEMCrypto_LoadDeviceRSAKey(
oec_session_id_,
reinterpret_cast<const uint8_t*>(wrapped_key.data()),
@@ -905,8 +899,8 @@ CdmResponseType CryptoSession::LoadCertificatePrivateKey(
metrics_, oemcrypto_load_device_rsa_key_, sts);
});
return MapOEMCryptoResult(
sts, LOAD_DEVICE_RSA_KEY_ERROR, "LoadCertificatePrivateKey");
return MapOEMCryptoResult(sts, LOAD_DEVICE_RSA_KEY_ERROR,
"LoadCertificatePrivateKey");
}
CdmResponseType CryptoSession::RefreshKeys(const std::string& message,
@@ -937,16 +931,14 @@ CdmResponseType CryptoSession::RefreshKeys(const std::string& message,
if (refresh_sts == OEMCrypto_SUCCESS) return KEY_ADDED;
return MapOEMCryptoResult(
refresh_sts, REFRESH_KEYS_ERROR, "RefreshKeys");
return MapOEMCryptoResult(refresh_sts, REFRESH_KEYS_ERROR, "RefreshKeys");
}
CdmResponseType CryptoSession::SelectKey(const std::string& key_id,
CdmCipherMode cipher_mode) {
OEMCryptoResult sts;
WithOecSessionLock("SelectKey", [&] {
sts = key_session_->SelectKey(key_id, cipher_mode);
});
WithOecSessionLock(
"SelectKey", [&] { sts = key_session_->SelectKey(key_id, cipher_mode); });
switch (sts) {
case OEMCrypto_SUCCESS:
@@ -982,12 +974,11 @@ CdmResponseType CryptoSession::SelectKey(const std::string& key_id,
CdmResponseType CryptoSession::GenerateDerivedKeys(const std::string& message) {
OEMCryptoResult sts;
WithOecSessionLock("GenerateDerivedKeys without session_key", [&] {
sts = key_session_->GenerateDerivedKeys(message);
});
WithOecSessionLock("GenerateDerivedKeys without session_key",
[&] { sts = key_session_->GenerateDerivedKeys(message); });
return MapOEMCryptoResult(
sts, GENERATE_DERIVED_KEYS_ERROR_2, "GenerateDerivedKeys");
return MapOEMCryptoResult(sts, GENERATE_DERIVED_KEYS_ERROR_2,
"GenerateDerivedKeys");
}
CdmResponseType CryptoSession::GenerateDerivedKeys(
@@ -997,8 +988,8 @@ CdmResponseType CryptoSession::GenerateDerivedKeys(
sts = key_session_->GenerateDerivedKeys(message, session_key);
});
return MapOEMCryptoResult(
sts, GENERATE_DERIVED_KEYS_ERROR, "GenerateDerivedKeys");
return MapOEMCryptoResult(sts, GENERATE_DERIVED_KEYS_ERROR,
"GenerateDerivedKeys");
}
CdmResponseType CryptoSession::GenerateSignature(const std::string& message,
@@ -1016,15 +1007,14 @@ CdmResponseType CryptoSession::GenerateSignature(const std::string& message,
// The first attempt may fail due to buffer too short
for (int i = 0; i < 2; ++i) {
WithOecSessionLock("GenerateSignature", [&] {
M_TIME(sts = OEMCrypto_GenerateSignature(
oec_session_id_,
reinterpret_cast<const uint8_t*>(message.data()),
message.size(),
reinterpret_cast<uint8_t*>(
const_cast<char*>(signature->data())),
&length),
metrics_, oemcrypto_generate_signature_, sts,
metrics::Pow2Bucket(length));
M_TIME(
sts = OEMCrypto_GenerateSignature(
oec_session_id_, reinterpret_cast<const uint8_t*>(message.data()),
message.size(),
reinterpret_cast<uint8_t*>(const_cast<char*>(signature->data())),
&length),
metrics_, oemcrypto_generate_signature_, sts,
metrics::Pow2Bucket(length));
});
if (OEMCrypto_SUCCESS == sts) {
// Trim signature buffer and done
@@ -1039,8 +1029,7 @@ CdmResponseType CryptoSession::GenerateSignature(const std::string& message,
signature->resize(length);
}
return MapOEMCryptoResult(
sts, GENERATE_SIGNATURE_ERROR, "GenerateSignature");
return MapOEMCryptoResult(sts, GENERATE_SIGNATURE_ERROR, "GenerateSignature");
}
CdmResponseType CryptoSession::GenerateRsaSignature(const std::string& message,
@@ -1059,15 +1048,14 @@ CdmResponseType CryptoSession::GenerateRsaSignature(const std::string& message,
// The first attempt may fail due to buffer too short
for (int i = 0; i < 2; ++i) {
WithOecSessionLock("GenerateRsaSignature", [&] {
M_TIME(sts = OEMCrypto_GenerateRSASignature(
oec_session_id_,
reinterpret_cast<const uint8_t*>(message.data()),
message.size(),
reinterpret_cast<uint8_t*>(
const_cast<char*>(signature->data())),
&length, kSign_RSASSA_PSS),
metrics_, oemcrypto_generate_rsa_signature_, sts,
metrics::Pow2Bucket(length));
M_TIME(
sts = OEMCrypto_GenerateRSASignature(
oec_session_id_, reinterpret_cast<const uint8_t*>(message.data()),
message.size(),
reinterpret_cast<uint8_t*>(const_cast<char*>(signature->data())),
&length, kSign_RSASSA_PSS),
metrics_, oemcrypto_generate_rsa_signature_, sts,
metrics::Pow2Bucket(length));
});
if (OEMCrypto_SUCCESS == sts) {
@@ -1083,8 +1071,8 @@ CdmResponseType CryptoSession::GenerateRsaSignature(const std::string& message,
signature->resize(length);
}
return MapOEMCryptoResult(
sts, RSA_SIGNATURE_GENERATION_ERROR, "OEMCrypto_GenerateRSASignature");
return MapOEMCryptoResult(sts, RSA_SIGNATURE_GENERATION_ERROR,
"OEMCrypto_GenerateRSASignature");
}
CdmResponseType CryptoSession::Decrypt(const CdmDecryptionParameters& params) {
@@ -1125,10 +1113,9 @@ CdmResponseType CryptoSession::Decrypt(const CdmDecryptionParameters& params) {
params.subsample_flags ==
(OEMCrypto_FirstSubsample | OEMCrypto_LastSubsample)) {
WithOecSessionLock("Decrypt() calling CopyBuffer", [&] {
M_TIME(sts = OEMCrypto_CopyBuffer(oec_session_id_, params.encrypt_buffer,
params.encrypt_length,
&buffer_descriptor,
params.subsample_flags),
M_TIME(sts = OEMCrypto_CopyBuffer(
oec_session_id_, params.encrypt_buffer, params.encrypt_length,
&buffer_descriptor, params.subsample_flags),
metrics_, oemcrypto_copy_buffer_, sts,
metrics::Pow2Bucket(params.encrypt_length));
});
@@ -1157,8 +1144,8 @@ CdmResponseType CryptoSession::Decrypt(const CdmDecryptionParameters& params) {
}
WithOecSessionLock("Decrypt() calling key_session_->Decrypt()", [&] {
sts = key_session_->Decrypt(params, buffer_descriptor,
pattern_descriptor);
sts =
key_session_->Decrypt(params, buffer_descriptor, pattern_descriptor);
});
if (sts == OEMCrypto_ERROR_BUFFER_TOO_LARGE) {
@@ -1232,8 +1219,7 @@ bool CryptoSession::UsageInformationSupport(SecurityLevel security_level,
}
CdmResponseType CryptoSession::UpdateUsageInformation() {
LOGV("CryptoSession::UpdateUsageInformation: id=%lu",
oec_session_id_);
LOGV("CryptoSession::UpdateUsageInformation: id=%lu", oec_session_id_);
if (!IsInitialized()) return UNKNOWN_ERROR;
if (usage_table_header_ != NULL) {
@@ -1242,9 +1228,8 @@ CdmResponseType CryptoSession::UpdateUsageInformation() {
}
OEMCryptoResult status;
WithOecWriteLock("UpdateUsageInformation", [&] {
status = OEMCrypto_UpdateUsageTable();
});
WithOecWriteLock("UpdateUsageInformation",
[&] { status = OEMCrypto_UpdateUsageTable(); });
metrics_->oemcrypto_update_usage_table_.Increment(status);
if (status != OEMCrypto_SUCCESS) {
LOGE("CryptoSession::UpdateUsageInformation: error=%ld", status);
@@ -1263,8 +1248,8 @@ CdmResponseType CryptoSession::DeactivateUsageInformation(
// TODO(fredgc or rfrias): make sure oec_session_id_ is valid.
OEMCryptoResult status;
WithOecWriteLock("DeactivateUsageInformation", [&] {
status = OEMCrypto_DeactivateUsageEntry(
oec_session_id_, pst, provider_session_token.length());
status = OEMCrypto_DeactivateUsageEntry(oec_session_id_, pst,
provider_session_token.length());
});
metrics_->oemcrypto_deactivate_usage_entry_.Increment(status);
@@ -1303,15 +1288,15 @@ CdmResponseType CryptoSession::GenerateUsageReport(
size_t usage_length = 0;
OEMCryptoResult status;
WithOecWriteLock("GenerateUsageReport Attempt 1", [&] {
status = OEMCrypto_ReportUsage(
oec_session_id_, pst, provider_session_token.length(), NULL,
&usage_length);
status = OEMCrypto_ReportUsage(oec_session_id_, pst,
provider_session_token.length(), NULL,
&usage_length);
});
metrics_->oemcrypto_report_usage_.Increment(status);
if (status != OEMCrypto_SUCCESS && status != OEMCrypto_ERROR_SHORT_BUFFER) {
return MapOEMCryptoResult(
status, GENERATE_USAGE_REPORT_ERROR, "GenerateUsageReport");
return MapOEMCryptoResult(status, GENERATE_USAGE_REPORT_ERROR,
"GenerateUsageReport");
}
std::vector<uint8_t> buffer(usage_length);
@@ -1324,8 +1309,8 @@ CdmResponseType CryptoSession::GenerateUsageReport(
metrics_->oemcrypto_report_usage_.Increment(status);
if (status != OEMCrypto_SUCCESS) {
return MapOEMCryptoResult(
status, GENERATE_USAGE_REPORT_ERROR, "OEMCrypto_ReportUsage");
return MapOEMCryptoResult(status, GENERATE_USAGE_REPORT_ERROR,
"OEMCrypto_ReportUsage");
}
if (usage_length != buffer.size()) {
@@ -1458,9 +1443,8 @@ CdmResponseType CryptoSession::DeleteMultipleUsageInformation(
CdmResponseType CryptoSession::DeleteAllUsageReports() {
LOGV("DeleteAllUsageReports");
OEMCryptoResult status;
WithOecWriteLock("DeleteAllUsageReports", [&] {
status = OEMCrypto_DeleteOldUsageTable();
});
WithOecWriteLock("DeleteAllUsageReports",
[&] { status = OEMCrypto_DeleteOldUsageTable(); });
metrics_->oemcrypto_delete_usage_table_.Increment(status);
if (OEMCrypto_SUCCESS != status) {
LOGE(
@@ -1513,12 +1497,9 @@ bool CryptoSession::SetDestinationBufferType() {
}
CdmResponseType CryptoSession::RewrapCertificate(
const std::string& signed_message,
const std::string& signature,
const std::string& nonce,
const std::string& private_key,
const std::string& iv,
const std::string& wrapping_key,
const std::string& signed_message, const std::string& signature,
const std::string& nonce, const std::string& private_key,
const std::string& iv, const std::string& wrapping_key,
std::string* wrapped_private_key) {
LOGV("CryptoSession::RewrapCertificate, session id=%lu", oec_session_id_);
@@ -1540,12 +1521,9 @@ CdmResponseType CryptoSession::RewrapCertificate(
}
CdmResponseType CryptoSession::RewrapDeviceRSAKey(
const std::string& message,
const std::string& signature,
const std::string& nonce,
const std::string& enc_rsa_key,
const std::string& rsa_key_iv,
std::string* wrapped_rsa_key) {
const std::string& message, const std::string& signature,
const std::string& nonce, const std::string& enc_rsa_key,
const std::string& rsa_key_iv, std::string* wrapped_rsa_key) {
LOGV("CryptoSession::RewrapDeviceRSAKey, session id=%lu", oec_session_id_);
const uint8_t* signed_msg = reinterpret_cast<const uint8_t*>(message.data());
@@ -1573,37 +1551,33 @@ CdmResponseType CryptoSession::RewrapDeviceRSAKey(
});
if (status != OEMCrypto_ERROR_SHORT_BUFFER) {
return MapOEMCryptoResult(
status, REWRAP_DEVICE_RSA_KEY_ERROR, "RewrapDeviceRSAKey");
return MapOEMCryptoResult(status, REWRAP_DEVICE_RSA_KEY_ERROR,
"RewrapDeviceRSAKey");
}
wrapped_rsa_key->resize(wrapped_rsa_key_length);
WithOecSessionLock("RewrapDeviceRSAKey Attempt 2", [&] {
M_TIME(status = OEMCrypto_RewrapDeviceRSAKey(
oec_session_id_, signed_msg, message.size(),
reinterpret_cast<const uint8_t*>(signature.data()),
signature.size(), msg_nonce, msg_rsa_key, enc_rsa_key.size(),
msg_rsa_key_iv,
reinterpret_cast<uint8_t*>(&(*wrapped_rsa_key)[0]),
&wrapped_rsa_key_length),
metrics_, oemcrypto_rewrap_device_rsa_key_, status);
M_TIME(
status = OEMCrypto_RewrapDeviceRSAKey(
oec_session_id_, signed_msg, message.size(),
reinterpret_cast<const uint8_t*>(signature.data()),
signature.size(), msg_nonce, msg_rsa_key, enc_rsa_key.size(),
msg_rsa_key_iv, reinterpret_cast<uint8_t*>(&(*wrapped_rsa_key)[0]),
&wrapped_rsa_key_length),
metrics_, oemcrypto_rewrap_device_rsa_key_, status);
});
wrapped_rsa_key->resize(wrapped_rsa_key_length);
return MapOEMCryptoResult(
status, REWRAP_DEVICE_RSA_KEY_ERROR, "RewrapDeviceRSAKey");
return MapOEMCryptoResult(status, REWRAP_DEVICE_RSA_KEY_ERROR,
"RewrapDeviceRSAKey");
}
CdmResponseType CryptoSession::RewrapDeviceRSAKey30(
const std::string& message,
const std::string& nonce,
const std::string& private_key,
const std::string& iv,
const std::string& wrapping_key,
std::string* wrapped_private_key) {
LOGV("CryptoSession::RewrapDeviceRSAKey30, session id=%lu",
oec_session_id_);
const std::string& message, const std::string& nonce,
const std::string& private_key, const std::string& iv,
const std::string& wrapping_key, std::string* wrapped_private_key) {
LOGV("CryptoSession::RewrapDeviceRSAKey30, session id=%lu", oec_session_id_);
const uint8_t* signed_msg = reinterpret_cast<const uint8_t*>(message.data());
const uint8_t* msg_private_key = NULL;
@@ -1623,38 +1597,32 @@ CdmResponseType CryptoSession::RewrapDeviceRSAKey30(
size_t wrapped_private_key_length = 0;
OEMCryptoResult status;
WithOecSessionLock("RewrapDeviceRSAKey30 Attempt 1", [&] {
M_TIME(
status = OEMCrypto_RewrapDeviceRSAKey30(
oec_session_id_, msg_nonce, msg_wrapping_key, wrapping_key.size(),
msg_private_key, private_key.size(), msg_iv, NULL,
&wrapped_private_key_length),
metrics_,
oemcrypto_rewrap_device_rsa_key_30_,
status);
M_TIME(status = OEMCrypto_RewrapDeviceRSAKey30(
oec_session_id_, msg_nonce, msg_wrapping_key,
wrapping_key.size(), msg_private_key, private_key.size(), msg_iv,
NULL, &wrapped_private_key_length),
metrics_, oemcrypto_rewrap_device_rsa_key_30_, status);
});
if (status != OEMCrypto_ERROR_SHORT_BUFFER) {
return MapOEMCryptoResult(
status, REWRAP_DEVICE_RSA_KEY_30_ERROR, "RewrapDeviceRSAKey30");
return MapOEMCryptoResult(status, REWRAP_DEVICE_RSA_KEY_30_ERROR,
"RewrapDeviceRSAKey30");
}
wrapped_private_key->resize(wrapped_private_key_length);
WithOecSessionLock("RewrapDeviceRSAKey30 Attempt 2", [&] {
M_TIME(
status = OEMCrypto_RewrapDeviceRSAKey30(
oec_session_id_, msg_nonce, msg_wrapping_key, wrapping_key.size(),
msg_private_key, private_key.size(), msg_iv,
reinterpret_cast<uint8_t*>(&(*wrapped_private_key)[0]),
&wrapped_private_key_length),
metrics_,
oemcrypto_rewrap_device_rsa_key_30_,
status);
M_TIME(status = OEMCrypto_RewrapDeviceRSAKey30(
oec_session_id_, msg_nonce, msg_wrapping_key,
wrapping_key.size(), msg_private_key, private_key.size(), msg_iv,
reinterpret_cast<uint8_t*>(&(*wrapped_private_key)[0]),
&wrapped_private_key_length),
metrics_, oemcrypto_rewrap_device_rsa_key_30_, status);
});
wrapped_private_key->resize(wrapped_private_key_length);
return MapOEMCryptoResult(
status, REWRAP_DEVICE_RSA_KEY_30_ERROR, "RewrapDeviceRSAKey30");
return MapOEMCryptoResult(status, REWRAP_DEVICE_RSA_KEY_30_ERROR,
"RewrapDeviceRSAKey30");
}
CdmResponseType CryptoSession::GetHdcpCapabilities(HdcpCapability* current,
@@ -1694,8 +1662,8 @@ CdmResponseType CryptoSession::GetHdcpCapabilities(SecurityLevel security_level,
metrics_->oemcrypto_max_hdcp_capability_.SetError(status);
}
return MapOEMCryptoResult(
status, GET_HDCP_CAPABILITY_FAILED, "GetHDCPCapability");
return MapOEMCryptoResult(status, GET_HDCP_CAPABILITY_FAILED,
"GetHDCPCapability");
}
bool CryptoSession::GetSupportedCertificateTypes(
@@ -1726,17 +1694,15 @@ CdmResponseType CryptoSession::GetRandom(size_t data_length,
return PARAMETER_NULL;
}
OEMCryptoResult sts;
WithOecReadLock("GetRandom", [&] {
sts = OEMCrypto_GetRandom(random_data, data_length);
});
WithOecReadLock("GetRandom",
[&] { sts = OEMCrypto_GetRandom(random_data, data_length); });
metrics_->oemcrypto_get_random_.Increment(sts);
return MapOEMCryptoResult(sts, RANDOM_GENERATION_ERROR, "GetRandom");
}
CdmResponseType CryptoSession::GetNumberOfOpenSessions(
SecurityLevel security_level,
size_t* count) {
SecurityLevel security_level, size_t* count) {
LOGV("GetNumberOfOpenSessions");
if (!IsInitialized()) {
LOGW("CryptoSession::GetNumberOfOpenSessions: not initialized");
@@ -1760,13 +1726,12 @@ CdmResponseType CryptoSession::GetNumberOfOpenSessions(
metrics_->oemcrypto_number_of_open_sessions_.SetError(status);
}
return MapOEMCryptoResult(
status, GET_NUMBER_OF_OPEN_SESSIONS_ERROR, "GetNumberOfOpenSessions");
return MapOEMCryptoResult(status, GET_NUMBER_OF_OPEN_SESSIONS_ERROR,
"GetNumberOfOpenSessions");
}
CdmResponseType CryptoSession::GetMaxNumberOfSessions(
SecurityLevel security_level,
size_t* max) {
SecurityLevel security_level, size_t* max) {
LOGV("GetMaxNumberOfSessions");
if (!IsInitialized()) {
LOGW("CryptoSession::GetMaxNumberOfSessions: not initialized");
@@ -1811,21 +1776,21 @@ CdmResponseType CryptoSession::GetSrmVersion(uint16_t* srm_version) {
// SRM is an optional feature. Whether it is implemented is up to the
// discretion of OEMs
if (status == OEMCrypto_ERROR_NOT_IMPLEMENTED) {
LOGV("CryptoSession::GetSrmVersion: OEMCrypto_GetCurrentSRMVersion not "
"implemented");
LOGV(
"CryptoSession::GetSrmVersion: OEMCrypto_GetCurrentSRMVersion not "
"implemented");
return NOT_IMPLEMENTED_ERROR;
}
return MapOEMCryptoResult(
status, GET_SRM_VERSION_ERROR, "GetCurrentSRMVersion");
return MapOEMCryptoResult(status, GET_SRM_VERSION_ERROR,
"GetCurrentSRMVersion");
}
bool CryptoSession::IsSrmUpdateSupported() {
LOGV("IsSrmUpdateSupported");
if (!IsInitialized()) return false;
return WithOecReadLock("IsSrmUpdateSupported", [&] {
return OEMCrypto_IsSRMUpdateSupported();
});
return WithOecReadLock("IsSrmUpdateSupported",
[&] { return OEMCrypto_IsSRMUpdateSupported(); });
}
CdmResponseType CryptoSession::LoadSrm(const std::string& srm) {
@@ -1838,8 +1803,8 @@ CdmResponseType CryptoSession::LoadSrm(const std::string& srm) {
OEMCryptoResult status;
WithOecWriteLock("LoadSrm", [&] {
status = OEMCrypto_LoadSRM(
reinterpret_cast<const uint8_t*>(srm.data()), srm.size());
status = OEMCrypto_LoadSRM(reinterpret_cast<const uint8_t*>(srm.data()),
srm.size());
});
return MapOEMCryptoResult(status, LOAD_SRM_ERROR, "LoadSRM");
@@ -1938,9 +1903,8 @@ uint32_t CryptoSession::IsDecryptHashSupported(SecurityLevel security_level) {
return secure_decrypt_support;
}
CdmResponseType CryptoSession::SetDecryptHash(
uint32_t frame_number,
const std::string& hash) {
CdmResponseType CryptoSession::SetDecryptHash(uint32_t frame_number,
const std::string& hash) {
LOGV("SetDecryptHash");
OEMCryptoResult sts;
WithOecSessionLock("SetDecryptHash", [&] {
@@ -2486,9 +2450,9 @@ CdmResponseType CryptoSession::ShrinkUsageTableHeader(
size_t usage_table_header_len = 0;
OEMCryptoResult result;
WithOecWriteLock("ShrinkUsageTableHeader Attempt 1", [&] {
result = OEMCrypto_ShrinkUsageTableHeader(
requested_security_level_, new_entry_count, NULL,
&usage_table_header_len);
result = OEMCrypto_ShrinkUsageTableHeader(requested_security_level_,
new_entry_count, NULL,
&usage_table_header_len);
metrics_->oemcrypto_shrink_usage_table_header_.Increment(result);
});
@@ -2522,8 +2486,8 @@ CdmResponseType CryptoSession::MoveUsageEntry(uint32_t new_entry_number) {
metrics_->oemcrypto_move_entry_.Increment(result);
});
return MapOEMCryptoResult(
result, MOVE_USAGE_ENTRY_UNKNOWN_ERROR, "MoveUsageEntry");
return MapOEMCryptoResult(result, MOVE_USAGE_ENTRY_UNKNOWN_ERROR,
"MoveUsageEntry");
}
bool CryptoSession::CreateOldUsageEntry(
@@ -2592,8 +2556,8 @@ CdmResponseType CryptoSession::CopyOldUsageEntry(
metrics_->oemcrypto_copy_old_usage_entry_.Increment(result);
});
return MapOEMCryptoResult(
result, COPY_OLD_USAGE_ENTRY_UNKNOWN_ERROR, "CopyOldUsageEntry");
return MapOEMCryptoResult(result, COPY_OLD_USAGE_ENTRY_UNKNOWN_ERROR,
"CopyOldUsageEntry");
}
bool CryptoSession::GetAnalogOutputCapabilities(bool* can_support_output,