Remove dangerous logging from OEMCrypto Reference code
Merge from Widevine repo of http://go/wvgerrit/57584 This CL is part of the long slog to split the mock into safer reference code and dangerous test code. bug: 76393338 (Step 4) Split mock into reference code and testbed bug: 36515266 OEMCrypto Logging Cleanup test: unit tests Change-Id: Idbbf704a5947e2f161af7b71c328423f02982378
This commit is contained in:
@@ -28,7 +28,6 @@
|
||||
#include "log.h"
|
||||
#include "oemcrypto_engine_ref.h"
|
||||
#include "oemcrypto_key_ref.h"
|
||||
#include "oemcrypto_logging.h"
|
||||
#include "oemcrypto_rsa_key_shared.h"
|
||||
#include "oemcrypto_types.h"
|
||||
#include "disallow_copy_and_assign.h"
|
||||
@@ -248,14 +247,6 @@ bool SessionContext::DeriveKeys(const std::vector<uint8_t>& master_key,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (LogCategoryEnabled(kLoggingDumpDerivedKeys)) {
|
||||
LOGI((" mac_key_context = " + wvcdm::b2a_hex(mac_key_context)).c_str());
|
||||
LOGI((" enc_key_context = " + wvcdm::b2a_hex(enc_key_context)).c_str());
|
||||
LOGI((" mac_key_server = " + wvcdm::b2a_hex(mac_key_server)).c_str());
|
||||
LOGI((" mac_key_client = " + wvcdm::b2a_hex(mac_key_client)).c_str());
|
||||
LOGI((" enc_key = " + wvcdm::b2a_hex(enc_key)).c_str());
|
||||
}
|
||||
|
||||
set_mac_key_server(mac_key_server);
|
||||
set_mac_key_client(mac_key_client);
|
||||
set_encryption_key(enc_key);
|
||||
@@ -325,15 +316,6 @@ bool SessionContext::GenerateSignature(const uint8_t* message,
|
||||
using_usage_entry_mac_key_client =
|
||||
mac_key_client_ == usage_entry_mac_key_client;
|
||||
}
|
||||
if (using_usage_entry_mac_key_client &&
|
||||
LogCategoryEnabled(kLoggingDumpDerivedKeys)) {
|
||||
LOGI(("message signed with HMAC and usage_entry_'s mac_key_client, "
|
||||
"mac_key_client = " +
|
||||
wvcdm::b2a_hex(usage_entry_mac_key_client)).c_str());
|
||||
} else if (LogCategoryEnabled(kLoggingDumpDerivedKeys)) {
|
||||
LOGI(("message signed with HMAC and mac_key_client_, mac_key_client_ = " +
|
||||
wvcdm::b2a_hex(mac_key_client_)).c_str());
|
||||
}
|
||||
|
||||
unsigned int md_len = *signature_length;
|
||||
if (HMAC(EVP_sha256(), &mac_key_client_[0], wvoec::MAC_KEY_SIZE, message,
|
||||
@@ -432,10 +414,6 @@ bool SessionContext::ValidateMessage(const uint8_t* given_message,
|
||||
uint8_t computed_signature[SHA256_DIGEST_LENGTH];
|
||||
memset(computed_signature, 0, SHA256_DIGEST_LENGTH);
|
||||
unsigned int md_len = SHA256_DIGEST_LENGTH;
|
||||
if (LogCategoryEnabled(kLoggingDumpDerivedKeys)) {
|
||||
LOGI(("message verified with HMAC and mac_key_server, key = " +
|
||||
wvcdm::b2a_hex(mac_key_server_)).c_str());
|
||||
}
|
||||
if (!HMAC(EVP_sha256(), &mac_key_server_[0], mac_key_server_.size(),
|
||||
given_message, message_length, computed_signature, &md_len)) {
|
||||
LOGE("ValidateMessage: Could not compute signature.");
|
||||
@@ -652,10 +630,6 @@ OEMCryptoResult SessionContext::LoadKeys(
|
||||
LOGE("LoadKeys: Usage table can't set keys.\n");
|
||||
return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
}
|
||||
if (LogCategoryEnabled(kLoggingDumpDerivedKeys)) {
|
||||
LOGI(("usage_entry_'s mac_key_client_ has changed to = " +
|
||||
wvcdm::b2a_hex(mac_key_client_)).c_str());
|
||||
}
|
||||
break;
|
||||
case kUsageEntryLoaded:
|
||||
if (!usage_entry_->VerifyPST(pst, pst_length)) {
|
||||
@@ -732,14 +706,6 @@ OEMCryptoResult SessionContext::InstallKey(
|
||||
return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
}
|
||||
|
||||
if (LogCategoryEnabled(kLoggingDumpContentKeys)) {
|
||||
LOGI((" InstallKey: key_id = " + wvcdm::b2a_hex(key_id)).c_str());
|
||||
LOGI(
|
||||
(" InstallKey: content_key = " + wvcdm::b2a_hex(content_key)).c_str());
|
||||
LOGI((" InstallKey: key_control = " + wvcdm::b2a_hex(key_control_str))
|
||||
.c_str());
|
||||
}
|
||||
|
||||
// Key control must be supplied by license server
|
||||
if (key_control.empty()) {
|
||||
LOGE("[Installkey(): WARNING: No Key Control]");
|
||||
@@ -755,9 +721,6 @@ OEMCryptoResult SessionContext::InstallKey(
|
||||
return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
}
|
||||
|
||||
if (LogCategoryEnabled(kLoggingDumpKeyControlBlocks)) {
|
||||
LOGD("Key ID: %s", wvcdm::b2a_hex(key_id).c_str());
|
||||
}
|
||||
KeyControlBlock key_control_block(key_control_str);
|
||||
if (!key_control_block.valid()) {
|
||||
LOGE("Error parsing key control.");
|
||||
@@ -855,16 +818,10 @@ OEMCryptoResult SessionContext::RefreshKey(
|
||||
Key* content_key = session_keys_->Find(key_id);
|
||||
|
||||
if (NULL == content_key) {
|
||||
if (LogCategoryEnabled(kLoggingDumpKeyControlBlocks)) {
|
||||
LOGD("Error: no matching content key.");
|
||||
}
|
||||
return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
}
|
||||
|
||||
if (key_control.empty()) {
|
||||
if (LogCategoryEnabled(kLoggingDumpKeyControlBlocks)) {
|
||||
LOGD("Error: no key_control.");
|
||||
}
|
||||
return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
}
|
||||
|
||||
@@ -873,33 +830,20 @@ OEMCryptoResult SessionContext::RefreshKey(
|
||||
// Decrypt encrypted key control block
|
||||
std::vector<uint8_t> control;
|
||||
if (key_control_iv.empty()) {
|
||||
if (LogCategoryEnabled(kLoggingDumpKeyControlBlocks)) {
|
||||
LOGD("Key control block is NOT encrypted.");
|
||||
}
|
||||
control = key_control;
|
||||
} else {
|
||||
if (LogCategoryEnabled(kLoggingDumpKeyControlBlocks)) {
|
||||
LOGD("Key control block is encrypted.");
|
||||
}
|
||||
if (!DecryptMessage(content_key_value, key_control_iv, key_control,
|
||||
&control, 128 /* key size */)) {
|
||||
if (LogCategoryEnabled(kLoggingDumpKeyControlBlocks)) {
|
||||
LOGD("Error decrypting key control block.");
|
||||
}
|
||||
return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
KeyControlBlock key_control_block(control);
|
||||
if (!key_control_block.valid()) {
|
||||
if (LogCategoryEnabled(kLoggingDumpKeyControlBlocks)) {
|
||||
LOGD("Parse key control error.");
|
||||
}
|
||||
return OEMCrypto_ERROR_INVALID_CONTEXT;
|
||||
}
|
||||
if ((key_control_block.control_bits() & wvoec::kControlNonceEnabled) &&
|
||||
(!CheckNonce(key_control_block.nonce()))) {
|
||||
LOGE("KCB: BAD Nonce");
|
||||
return OEMCrypto_ERROR_INVALID_NONCE;
|
||||
}
|
||||
content_key->UpdateDuration(key_control_block);
|
||||
@@ -1179,10 +1123,6 @@ bool SessionContext::UpdateMacKeys(const std::vector<uint8_t>& enc_mac_keys,
|
||||
mac_keys.begin(), mac_keys.begin() + wvoec::MAC_KEY_SIZE);
|
||||
mac_key_client_ = std::vector<uint8_t>(mac_keys.begin() + wvoec::MAC_KEY_SIZE,
|
||||
mac_keys.end());
|
||||
if (LogCategoryEnabled(kLoggingDumpDerivedKeys)) {
|
||||
LOGI(("mac_key_client_ has been updated to = " +
|
||||
wvcdm::b2a_hex(mac_key_client_)).c_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1191,15 +1131,6 @@ bool SessionContext::QueryKeyControlBlock(const KeyId& key_id, uint32_t* data) {
|
||||
return false;
|
||||
}
|
||||
const Key* content_key = session_keys_->Find(key_id);
|
||||
if (LogCategoryEnabled(kLoggingTraceDecryption)) {
|
||||
LOGI(("Select Key: key_id = " + wvcdm::b2a_hex(key_id)).c_str());
|
||||
if (content_key) {
|
||||
LOGI(("Select Key: key = " + wvcdm::b2a_hex(content_key->value()))
|
||||
.c_str());
|
||||
} else {
|
||||
LOGI("Select Key: key = null.");
|
||||
}
|
||||
}
|
||||
if (NULL == content_key) {
|
||||
LOGE("[QueryKeyControlBlock(): No key matches key id]");
|
||||
return false;
|
||||
@@ -1213,11 +1144,6 @@ bool SessionContext::QueryKeyControlBlock(const KeyId& key_id, uint32_t* data) {
|
||||
|
||||
OEMCryptoResult SessionContext::SelectContentKey(
|
||||
const KeyId& key_id, OEMCryptoCipherMode cipher_mode) {
|
||||
if (LogCategoryEnabled(kLoggingTraceDecryption)) {
|
||||
LOGI(" Select Key: key_id = %s", wvcdm::b2a_hex(key_id).c_str());
|
||||
LOGI(" Select Key: cipher_mode = %s",
|
||||
(cipher_mode == OEMCrypto_CipherMode_CTR) ? "CTR" : "CBC");
|
||||
}
|
||||
if (!session_keys_) {
|
||||
LOGE("Select Key: no session keys.");
|
||||
return OEMCrypto_ERROR_INVALID_CONTEXT;
|
||||
@@ -1227,10 +1153,6 @@ OEMCryptoResult SessionContext::SelectContentKey(
|
||||
LOGE("No key matches key id");
|
||||
return OEMCrypto_KEY_NOT_LOADED;
|
||||
}
|
||||
if (LogCategoryEnabled(kLoggingTraceDecryption)) {
|
||||
LOGI((" Select Key: key = " + wvcdm::b2a_hex(content_key->value()))
|
||||
.c_str());
|
||||
}
|
||||
content_key->set_ctr_mode(cipher_mode == OEMCrypto_CipherMode_CTR);
|
||||
current_content_key_ = content_key;
|
||||
const KeyControlBlock& control = current_content_key()->control();
|
||||
@@ -1281,10 +1203,6 @@ OEMCryptoResult SessionContext::LoadUsageEntry(
|
||||
mac_key_client_ = std::vector<uint8_t>(
|
||||
usage_entry_->mac_key_client(),
|
||||
usage_entry_->mac_key_client() + wvoec::MAC_KEY_SIZE);
|
||||
if (LogCategoryEnabled(kLoggingDumpDerivedKeys)) {
|
||||
LOGI(("mac_key_client_ has been updated to = " +
|
||||
wvcdm::b2a_hex(mac_key_client_)).c_str());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user