From f22cd204663fdb3990ee4620a9180e67df5f3ff0 Mon Sep 17 00:00:00 2001 From: Alex Dale Date: Fri, 21 Aug 2020 18:23:44 -0700 Subject: [PATCH] Enabled log formatting warnings. [ Merge of http://go/wvgerrit/105025 ] Clang and GCC allow for warnings against the arguments for printf-like functions (e.i. LOGx). These validate that the format type specified in the format string match the corresponding argument type. Most of the time, format specifer errors are benign; hence why they haven't been seen as an error so far. However, with the enabling of specifier warnings and the enabling of warnings as errors on certain platforms, these existing errors need to be addressed. This CL enables format specifier warnings for most of the Widevine code, with the OEMCrypto L3 implementation which has a single error which requires a fix in the haystack code before being fixed in the Widevine branch. Strict format string warnings are not enabled for non-LP64 systems. Bug: 137583127 Test: Compiled for Linux and Android Change-Id: I051398332d31a20457b86563a90ad8f6d428445f --- libwvdrmengine/cdm/core/src/license.cpp | 14 ++-- .../core/src/oemcrypto_adapter_dynamic.cpp | 4 +- .../cdm/core/src/usage_table_header.cpp | 8 +-- .../cdm/core/test/cdm_engine_test.cpp | 4 +- libwvdrmengine/cdm/core/test/url_request.cpp | 13 ++-- .../cdm/metrics/src/metrics_collections.cpp | 4 +- .../cdm/test/cdm_extended_duration_test.cpp | 6 +- libwvdrmengine/cdm/test/cdm_feature_test.cpp | 10 +-- .../cdm/test/request_license_test.cpp | 12 ++-- libwvdrmengine/cdm/util/include/log.h | 10 +++ .../ref/src/oemcrypto_engine_ref.cpp | 2 +- .../oemcrypto/ref/src/oemcrypto_key_ref.cpp | 2 +- .../oemcrypto/ref/src/oemcrypto_session.cpp | 68 ++++++++++--------- .../ref/src/oemcrypto_usage_table_ref.cpp | 35 +++++----- .../oemcrypto/test/oemcrypto_test.cpp | 4 +- 15 files changed, 105 insertions(+), 91 deletions(-) diff --git a/libwvdrmengine/cdm/core/src/license.cpp b/libwvdrmengine/cdm/core/src/license.cpp index a934571c..d0c0eca5 100644 --- a/libwvdrmengine/cdm/core/src/license.cpp +++ b/libwvdrmengine/cdm/core/src/license.cpp @@ -23,7 +23,6 @@ #include "wv_cdm_constants.h" namespace { - const uint32_t kFourCcCbc1 = 0x63626331; const uint32_t kFourCcCbcs = 0x63626373; const uint32_t kFourCcLittleEndianCbc1 = 0x31636263; @@ -32,10 +31,11 @@ const uint32_t kFourCcCenc = 0x63656e63; const std::string kEmptyString; +// MAC key in the license are two separate MAC keys (client and server). +constexpr size_t kLicenseMacKeySize = wvcdm::MAC_KEY_SIZE * 2; } // namespace namespace wvcdm { - // Protobuf generated classes. using video_widevine::EncryptedClientIdentification; using video_widevine::License; @@ -596,17 +596,17 @@ CdmResponseType CdmLicense::HandleKeyResponse( mac_key_iv.assign(license.key(i).iv()); // Strip off PKCS#5 padding - mac_keys.assign(license.key(i).key().data(), 2 * MAC_KEY_SIZE); + mac_keys.assign(license.key(i).key().data(), kLicenseMacKeySize); } } if (license.policy().can_renew() || (mac_key_iv.size() != 0 || mac_keys.size() != 0)) { if (mac_key_iv.size() != KEY_IV_SIZE || - mac_keys.size() != 2 * MAC_KEY_SIZE) { + mac_keys.size() != kLicenseMacKeySize) { LOGE( - "MAC key/IV size error: expected = %lu/%lu, " + "MAC key/IV size error: expected = %zu/%zu, " "actual = %zu/%zu (key/iv)", - 2 * MAC_KEY_SIZE, KEY_IV_SIZE, mac_keys.size(), mac_key_iv.size()); + kLicenseMacKeySize, KEY_IV_SIZE, mac_keys.size(), mac_key_iv.size()); return KEY_SIZE_ERROR_1; } } @@ -1177,7 +1177,7 @@ CdmResponseType CdmLicense::HandleNewEntitledKeys( if (content_key.size() < CONTENT_KEY_SIZE) { LOGE( "Entitled content key too small: " - "expected = %lu, actual = %zu (bytes)", + "expected = %zu, actual = %zu (bytes)", CONTENT_KEY_SIZE, content_key.size()); return KEY_SIZE_ERROR_2; } else if (content_key.size() > CONTENT_KEY_SIZE) { diff --git a/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp b/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp index 9c847cdb..37fd1d7d 100644 --- a/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp +++ b/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp @@ -507,10 +507,10 @@ class WatchDog { ssize_t size = sizeof(flag); ssize_t size_written = file->Write(reinterpret_cast(&flag), size); if (size != size_written) { - LOGE("Wrote %d bytes, not %d, to file %s", size_written, size, + LOGE("Wrote %zd bytes, not %zd, to file %s", size_written, size, filename.c_str()); } else { - LOGE("I wrote %d to %s", size_written, filename.c_str()); + LOGE("I wrote %zd to %s", size_written, filename.c_str()); } } diff --git a/libwvdrmengine/cdm/core/src/usage_table_header.cpp b/libwvdrmengine/cdm/core/src/usage_table_header.cpp index c0a9ada9..ecbcecfe 100644 --- a/libwvdrmengine/cdm/core/src/usage_table_header.cpp +++ b/libwvdrmengine/cdm/core/src/usage_table_header.cpp @@ -1055,7 +1055,7 @@ bool UsageTableHeader::LruUpgradeAllUsageEntries() { bad_license_file_entries.push_back(usage_entry_number); continue; default: { - LOGW("Unknown usage entry storage type: %d, usage_entry_number = %u", + LOGW("Unknown usage entry storage type: %d, usage_entry_number = %zu", static_cast(usage_entry_info.storage_type), usage_entry_number); bad_license_file_entries.push_back(usage_entry_number); @@ -1063,7 +1063,7 @@ bool UsageTableHeader::LruUpgradeAllUsageEntries() { } } if (!retrieve_response) { - LOGW("Could not retrieve license message: usage_entry_number = %u", + LOGW("Could not retrieve license message: usage_entry_number = %zu", usage_entry_number); bad_license_file_entries.push_back(usage_entry_number); continue; @@ -1071,7 +1071,7 @@ bool UsageTableHeader::LruUpgradeAllUsageEntries() { if (retrieved_entry_number != usage_entry_number) { LOGW( - "Usage entry number mismatched: usage_entry_number = %u, " + "Usage entry number mismatched: usage_entry_number = %zu, " "retrieved_entry_number = %u", usage_entry_number, retrieved_entry_number); bad_license_file_entries.push_back(usage_entry_number); @@ -1080,7 +1080,7 @@ bool UsageTableHeader::LruUpgradeAllUsageEntries() { video_widevine::License license; if (!ParseLicenseFromLicenseMessage(license_message, &license)) { - LOGW("Could not parse license: usage_entry_number = %u", + LOGW("Could not parse license: usage_entry_number = %zu", usage_entry_number); bad_license_file_entries.push_back(usage_entry_number); continue; diff --git a/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp b/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp index 080748d5..dcaaff3c 100644 --- a/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp +++ b/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp @@ -109,7 +109,7 @@ class WvCdmEnginePreProvTest : public WvCdmTestBase { LicenseRequest license_request; license_request.GetDrmMessage(http_response, *response); - LOGV("response: size=%u, string:\n%s\n", response->size(), + LOGV("response: size = %zu, string =\n%s\n", response->size(), Base64SafeEncode( std::vector(response->begin(), response->end())) .c_str()); @@ -239,7 +239,7 @@ class WvCdmEngineTest : public WvCdmEnginePreProvTest { std::string drm_msg; LicenseRequest lic_request; lic_request.GetDrmMessage(response, drm_msg); - LOGV("drm msg: %u bytes\r\n%s", drm_msg.size(), + LOGV("drm msg: %zu bytes\r\n%s", drm_msg.size(), HexEncode(reinterpret_cast(drm_msg.data()), drm_msg.size()) .c_str()); diff --git a/libwvdrmengine/cdm/core/test/url_request.cpp b/libwvdrmengine/cdm/core/test/url_request.cpp index 7978ef3d..ba7f7ef1 100644 --- a/libwvdrmengine/cdm/core/test/url_request.cpp +++ b/libwvdrmengine/cdm/core/test/url_request.cpp @@ -41,7 +41,7 @@ void ConcatenateChunkedResponse(const std::string http_response, sscanf(&http_response[chunk_size_pos], "%zx", &chunk_size); if (chunk_size > http_response.size()) { // precaution, in case we misread chunk size - LOGE("invalid chunk size %u", chunk_size); + LOGE("Invalid chunk size %zu", chunk_size); return; } @@ -64,7 +64,7 @@ void ConcatenateChunkedResponse(const std::string http_response, sscanf(&http_response[chunk_size_pos], "%zx", &chunk_size); if (chunk_size > http_response.size()) { // precaution, in case we misread chunk size - LOGE("invalid chunk size %u", chunk_size); + LOGE("Invalid chunk size %zu", chunk_size); break; } chunk_pos = http_response.find(kCrLf, chunk_size_pos); @@ -104,11 +104,12 @@ bool UrlRequest::GetResponse(std::string* message) { // non-blocking mode. while (true) { char read_buffer[kReadBufferSize]; - int bytes = socket_.Read(read_buffer, sizeof(read_buffer), kReadTimeoutMs); + const int bytes = + socket_.Read(read_buffer, sizeof(read_buffer), kReadTimeoutMs); if (bytes > 0) { response.append(read_buffer, bytes); } else if (bytes < 0) { - LOGE("read error, errno = %d", errno); + LOGE("Read error, errno = %d", errno); return false; } else { // end of stream. @@ -117,7 +118,7 @@ bool UrlRequest::GetResponse(std::string* message) { } ConcatenateChunkedResponse(response, message); - LOGV("HTTP response from %s://%s:%d%s: (%zd): %s", socket_.scheme().c_str(), + LOGV("HTTP response from %s://%s:%d%s: (%zu): %s", socket_.scheme().c_str(), socket_.domain_name().c_str(), socket_.port(), socket_.resource_path().c_str(), message->size(), message->c_str()); return true; @@ -204,7 +205,7 @@ bool UrlRequest::PostRequestWithPath(const std::string& path, const int ret = socket_.Write(request.c_str(), request.size(), kWriteTimeoutMs); - LOGV("HTTP request: (%d): %s", request.size(), b2a_hex(request).c_str()); + LOGV("HTTP request: (%zu): %s", request.size(), b2a_hex(request).c_str()); return ret != -1; } diff --git a/libwvdrmengine/cdm/metrics/src/metrics_collections.cpp b/libwvdrmengine/cdm/metrics/src/metrics_collections.cpp index 956266fa..da7e5c21 100644 --- a/libwvdrmengine/cdm/metrics/src/metrics_collections.cpp +++ b/libwvdrmengine/cdm/metrics/src/metrics_collections.cpp @@ -327,8 +327,8 @@ EngineMetrics::~EngineMetrics() { std::unique_lock lock(session_metrics_lock_); if (!active_session_metrics_list_.empty() || !completed_session_metrics_list_.empty()) { - LOGV("EngineMetrics::~EngineMetrics. Session counts: " - "active %d. completed %d.", active_session_metrics_list_.size(), + LOGV("Session counts: active = %zu, completed = %zu.", + active_session_metrics_list_.size(), completed_session_metrics_list_.size()); } } diff --git a/libwvdrmengine/cdm/test/cdm_extended_duration_test.cpp b/libwvdrmengine/cdm/test/cdm_extended_duration_test.cpp index d7fd97ba..bbc19d9b 100644 --- a/libwvdrmengine/cdm/test/cdm_extended_duration_test.cpp +++ b/libwvdrmengine/cdm/test/cdm_extended_duration_test.cpp @@ -336,7 +336,7 @@ class WvCdmExtendedDurationTest : public WvCdmTestBase { void LogResponseError(const std::string& message, int http_status_code) { LOGD("HTTP Status code = %d", http_status_code); - LOGD("HTTP response(%d): %s", message.size(), b2a_hex(message).c_str()); + LOGD("HTTP response(%zu): %s", message.size(), b2a_hex(message).c_str()); } // Post a request and extract the drm message from the response @@ -360,7 +360,7 @@ class WvCdmExtendedDurationTest : public WvCdmTestBase { if (kHttpOk == http_status_code) { LicenseRequest lic_request; lic_request.GetDrmMessage(message, drm_msg); - LOGV("HTTP response body: (%u bytes)", drm_msg.size()); + LOGV("HTTP response body: (%zu bytes)", drm_msg.size()); } key_response_ = drm_msg; return drm_msg; @@ -408,7 +408,7 @@ class WvCdmExtendedDurationTest : public WvCdmTestBase { if (kHttpOk == http_status_code) { LicenseRequest license; license.GetDrmMessage(message, usage_info); - LOGV("HTTP response body: (%u bytes)", usage_info.size()); + LOGV("HTTP response body: (%zu bytes)", usage_info.size()); } return usage_info; } diff --git a/libwvdrmengine/cdm/test/cdm_feature_test.cpp b/libwvdrmengine/cdm/test/cdm_feature_test.cpp index 254848dd..d4d21617 100644 --- a/libwvdrmengine/cdm/test/cdm_feature_test.cpp +++ b/libwvdrmengine/cdm/test/cdm_feature_test.cpp @@ -242,7 +242,7 @@ class WvCdmFeatureTest : public WvCdmTestBase { void LogResponseError(const std::string& message, int http_status_code) { LOGD("HTTP Status code = %d", http_status_code); - LOGD("HTTP response(%d): %s", message.size(), b2a_hex(message).c_str()); + LOGD("HTTP response(%zu): %s", message.size(), b2a_hex(message).c_str()); } // Post a request and extract the signed provisioning message from @@ -268,13 +268,13 @@ class WvCdmFeatureTest : public WvCdmTestBase { bool ExtractTokenType(const std::string& b64_provisioning_request_no_pad, ClientIdentification_TokenType* token_type) { std::string b64_provisioning_request = b64_provisioning_request_no_pad; - size_t binary_size = b64_provisioning_request.size() * 3 / 4; + const size_t binary_size = b64_provisioning_request.size() * 3 / 4; // base64 message with pad = 4*ceil[n/3] - size_t pad_size = + const size_t pad_size = ((binary_size + 2) / 3) * 4 - b64_provisioning_request.size(); if (pad_size >= 3) return false; b64_provisioning_request.append(pad_size, '='); - LOGW("ExtractTokenType: pad_size: %d", pad_size); + LOGW("ExtractTokenType: pad_size: %zu", pad_size); std::vector bin_provisioning_request = Base64SafeDecode(b64_provisioning_request); @@ -360,7 +360,7 @@ class WvCdmFeatureTest : public WvCdmTestBase { if (kHttpOk == http_status_code) { LicenseRequest lic_request; lic_request.GetDrmMessage(message, drm_msg); - LOGV("HTTP response body: (%u bytes)", drm_msg.size()); + LOGV("HTTP response body: (%zu bytes)", drm_msg.size()); } return drm_msg; } diff --git a/libwvdrmengine/cdm/test/request_license_test.cpp b/libwvdrmengine/cdm/test/request_license_test.cpp index 11f36f7b..6d612707 100644 --- a/libwvdrmengine/cdm/test/request_license_test.cpp +++ b/libwvdrmengine/cdm/test/request_license_test.cpp @@ -1865,7 +1865,7 @@ class WvCdmRequestLicenseTest : public WvCdmTestBase { void LogResponseError(const std::string& message, int http_status_code) { LOGD("HTTP Status code = %d", http_status_code); - LOGD("HTTP response(%d): %s", message.size(), b2a_hex(message).c_str()); + LOGD("HTTP response(%zu): %s", message.size(), b2a_hex(message).c_str()); } // Post a request and extract the drm message from the response @@ -1879,7 +1879,7 @@ class WvCdmRequestLicenseTest : public WvCdmTestBase { std::string message; EXPECT_TRUE(url_request.GetResponse(&message)); - int http_status_code = url_request.GetStatusCode(message); + const int http_status_code = url_request.GetStatusCode(message); if (kHttpOk != http_status_code) { LogResponseError(message, http_status_code); } @@ -1890,7 +1890,7 @@ class WvCdmRequestLicenseTest : public WvCdmTestBase { if (kHttpOk == http_status_code) { LicenseRequest lic_request; lic_request.GetDrmMessage(message, drm_msg); - LOGV("HTTP response body: (%u bytes)", drm_msg.size()); + LOGV("HTTP response body: (%zu bytes)", drm_msg.size()); } return drm_msg; } @@ -1927,7 +1927,7 @@ class WvCdmRequestLicenseTest : public WvCdmTestBase { std::string message; EXPECT_TRUE(url_request.GetResponse(&message)); - int http_status_code = url_request.GetStatusCode(message); + const int http_status_code = url_request.GetStatusCode(message); if (kHttpOk != http_status_code) { LogResponseError(message, http_status_code); } @@ -1937,7 +1937,7 @@ class WvCdmRequestLicenseTest : public WvCdmTestBase { if (kHttpOk == http_status_code) { LicenseRequest license; license.GetDrmMessage(message, usage_info); - LOGV("HTTP response body: (%u bytes)", usage_info.size()); + LOGV("HTTP response body: (%zu bytes)", usage_info.size()); } return usage_info; } @@ -6167,7 +6167,7 @@ class WvCdmRequestLicenseRollbackTest protected: void RollbackSystemTime(time_t rollback_time_ms) { if (!in_rollback_state_) { - LOGW("Rolling back system time %d ms.", rollback_time_ms); + LOGW("Rolling back system time %ld ms.", rollback_time_ms); wall_time_before_rollback_ = std::chrono::system_clock::now(); monotonic_time_before_rollback_ = std::chrono::steady_clock::now(); auto modified_wall_time = wall_time_before_rollback_ - diff --git a/libwvdrmengine/cdm/util/include/log.h b/libwvdrmengine/cdm/util/include/log.h index 37706fa0..abc2829d 100644 --- a/libwvdrmengine/cdm/util/include/log.h +++ b/libwvdrmengine/cdm/util/include/log.h @@ -33,8 +33,18 @@ extern LogPriority g_cutoff; // unit tests. CORE_UTIL_EXPORT void InitLogging(); +// Only enable format specifier warnings on LP64 systems. There is +// no easy portable method to handle format specifiers for int64_t. +#if (defined(__gnuc__) || defined(__clang__)) && defined(__LP64__) +[[gnu::format(printf, 5, 6)]] CORE_UTIL_EXPORT void Log(const char* file, + const char* function, + int line, + LogPriority level, + const char* fmt, ...); +#else CORE_UTIL_EXPORT void Log(const char* file, const char* function, int line, LogPriority level, const char* fmt, ...); +#endif // Log APIs #ifndef LOGE diff --git a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_ref.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_ref.cpp index f689739f..c1b7941a 100644 --- a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_ref.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_ref.cpp @@ -102,7 +102,7 @@ int64_t CryptoEngine::MonotonicTime() { wvcdm::Clock().GetCurrentTime() + offline_time_info_.rollback_offset; static int64_t then = now; if (now < then) { - LOGW("Clock rollback detected: %lld seconds", then - now); + LOGW("Clock rollback detected: %ld seconds", then - now); offline_time_info_.rollback_offset += then - now; now = then; } diff --git a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_key_ref.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_key_ref.cpp index feb23740..9d28eec5 100644 --- a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_key_ref.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_key_ref.cpp @@ -47,7 +47,7 @@ uint32_t KeyControlBlock::ExtractField(const std::vector& str, KeyControlBlock::KeyControlBlock( const std::vector& key_control_string) { if (key_control_string.size() < wvoec::KEY_CONTROL_SIZE) { - LOGE("KCB: BAD Size: %d (not %d)", key_control_string.size(), + LOGE("KCB: BAD Size: %zu (not %zu)", key_control_string.size(), wvoec::KEY_CONTROL_SIZE); return; } diff --git a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_session.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_session.cpp index 173bfda1..4d768ab8 100644 --- a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_session.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_session.cpp @@ -313,7 +313,7 @@ bool SessionContext::RSADeriveKeys( return false; } session_key_.resize(RSA_size(rsa_key())); - int decrypted_size = + const int decrypted_size = RSA_private_decrypt(enc_session_key.size(), &enc_session_key[0], &session_key_[0], rsa_key(), RSA_PKCS1_OAEP_PADDING); if (-1 == decrypted_size) { @@ -347,7 +347,7 @@ OEMCryptoResult SessionContext::PrepAndSignLicenseRequest( return OEMCrypto_ERROR_SHORT_BUFFER; } if (result != OEMCrypto_SUCCESS) { - LOGE("ODK error: %d", result); + LOGE("ODK error: %d", static_cast(result)); return result; } if (message == nullptr || message_length < *core_message_length || @@ -395,7 +395,7 @@ OEMCryptoResult SessionContext::PrepAndSignRenewalRequest( return OEMCrypto_ERROR_SHORT_BUFFER; } if (result != OEMCrypto_SUCCESS) { - LOGE("ODK error: %d", result); + LOGE("ODK error: %d", static_cast(result)); return result; } if (message == nullptr || message_length < *core_message_length || @@ -438,7 +438,7 @@ OEMCryptoResult SessionContext::PrepAndSignProvisioningRequest( return OEMCrypto_ERROR_SHORT_BUFFER; } if (result != OEMCrypto_SUCCESS) { - LOGE("ODK error: %d", result); + LOGE("ODK error: %d", static_cast(result)); return result; } if (message == nullptr || message_length == 0 || signature == nullptr) { @@ -452,7 +452,8 @@ OEMCryptoResult SessionContext::PrepAndSignProvisioningRequest( result = GenerateCertSignature(message, message_length, signature, signature_length); } else { - LOGE("Bad prov method = %d", ce_->config_provisioning_method()); + LOGE("Bad prov method = %d", + static_cast(ce_->config_provisioning_method())); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } if (result == OEMCrypto_SUCCESS) state_request_signed_ = true; @@ -508,7 +509,8 @@ size_t SessionContext::ROTSignatureSize() { return SHA256_DIGEST_LENGTH; if (ce_->config_provisioning_method() == OEMCrypto_OEMCertificate) return CertSignatureSize(); - LOGE("Bad prov method = %d", ce_->config_provisioning_method()); + LOGE("Bad prov method = %d", + static_cast(ce_->config_provisioning_method())); return 0; } @@ -522,7 +524,7 @@ OEMCryptoResult SessionContext::GenerateCertSignature( return OEMCrypto_ERROR_INVALID_CONTEXT; } if (!rsa_key()) { - LOGE("no RSA key set"); + LOGE("No RSA key set"); return OEMCrypto_ERROR_INVALID_RSA_KEY; } if (*signature_length < static_cast(RSA_size(rsa_key()))) { @@ -530,7 +532,7 @@ OEMCryptoResult SessionContext::GenerateCertSignature( return OEMCrypto_ERROR_SHORT_BUFFER; } if (allowed_schemes_ != kSign_RSASSA_PSS) { - LOGE("message signing not allowed"); + LOGE("Message signing not allowed"); return OEMCrypto_ERROR_INVALID_RSA_KEY; } @@ -572,7 +574,7 @@ OEMCryptoResult SessionContext::GenerateRSASignature( return OEMCrypto_ERROR_INVALID_CONTEXT; } if (!rsa_key()) { - LOGE("no RSA key set"); + LOGE("No RSA key set"); return OEMCrypto_ERROR_INVALID_RSA_KEY; } if (*signature_length < static_cast(RSA_size(rsa_key()))) { @@ -592,10 +594,10 @@ OEMCryptoResult SessionContext::GenerateRSASignature( return OEMCrypto_ERROR_SIGNATURE_FAILURE; } // Pad the message with PKCS1 padding, and then encrypt. - int status = RSA_private_encrypt(message_length, message, signature, - rsa_key(), RSA_PKCS1_PADDING); + const int status = RSA_private_encrypt(message_length, message, signature, + rsa_key(), RSA_PKCS1_PADDING); if (status < 0) { - LOGE("error in RSA private encrypt. status=%d", status); + LOGE("Error in RSA private encrypt. status = %d", status); dump_boringssl_error(); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } @@ -710,7 +712,7 @@ OEMCryptoResult SessionContext::LoadLicense(const uint8_t* message, usage_entry_present(), license_request_hash_, &timer_limits_, &clock_values_, &nonce_values_, &parsed_response); if (result != OEMCrypto_SUCCESS) { - LOGE("ODK Error %d", result); + LOGE("ODK Error %d", static_cast(result)); return result; } // Validate message signature @@ -793,21 +795,21 @@ OEMCryptoResult SessionContext::LoadKeysNoSignature( message + srm_restriction_data.offset); return OEMCrypto_ERROR_INVALID_CONTEXT; } - uint32_t minimum_version = htonl(*reinterpret_cast( + const uint32_t minimum_version = htonl(*reinterpret_cast( message + srm_restriction_data.offset + 8)); uint16_t current_version = 0; if (OEMCrypto_SUCCESS != ce_->current_srm_version(¤t_version)) { LOGW("[LoadKeys: SRM Version not available"); srm_requirements_status_ = InvalidSRMVersion; } else if (current_version < minimum_version) { - LOGW("[LoadKeys: SRM Version is too small %d, required: %d", + LOGW("[LoadKeys: SRM Version is too small %u, required: %u", current_version, minimum_version); srm_requirements_status_ = InvalidSRMVersion; } else if (ce_->srm_blacklisted_device_attached()) { LOGW("[LoadKeys: SRM blacklisted device attached]"); srm_requirements_status_ = InvalidSRMVersion; } else { - LOGI("[LoadKeys: SRM Versions is %d, required: %d]", current_version, + LOGI("[LoadKeys: SRM Versions is %u, required: %u]", current_version, minimum_version); srm_requirements_status_ = ValidSRMVersion; } @@ -863,7 +865,7 @@ OEMCryptoResult SessionContext::LoadKeysNoSignature( message + enc_mac_keys_iv.offset + wvoec::KEY_IV_SIZE); if (!UpdateMacKeys(enc_mac_keys_str, enc_mac_key_iv_str)) { - LOGE("Failed to update mac keys.\n"); + LOGE("Failed to update mac keys."); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } } @@ -882,7 +884,7 @@ OEMCryptoResult SessionContext::LoadKeysNoSignature( return result; } if (!usage_entry_->SetMacKeys(mac_key_server_, mac_key_client_)) { - LOGE("LoadKeys: Usage table can't set keys.\n"); + LOGE("LoadKeys: Usage table can't set keys."); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } break; @@ -891,7 +893,7 @@ OEMCryptoResult SessionContext::LoadKeysNoSignature( return OEMCrypto_ERROR_WRONG_PST; } if (!usage_entry_->VerifyMacKeys(mac_key_server_, mac_key_client_)) { - LOGE("LoadKeys: Usage table entry mac keys do not match.\n"); + LOGE("LoadKeys: Usage table entry mac keys do not match."); return OEMCrypto_ERROR_WRONG_KEYS; } if (usage_entry_->Inactive()) return OEMCrypto_ERROR_LICENSE_INACTIVE; @@ -991,11 +993,11 @@ OEMCryptoResult SessionContext::InstallKey( LOGE("Anti-rollback hardware is required but hardware not present"); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } - uint8_t minimum_patch_level = (key_control_block.control_bits() & - wvoec::kControlSecurityPatchLevelMask) >> - wvoec::kControlSecurityPatchLevelShift; + const uint8_t minimum_patch_level = (key_control_block.control_bits() & + wvoec::kControlSecurityPatchLevelMask) >> + wvoec::kControlSecurityPatchLevelShift; if (minimum_patch_level > OEMCrypto_Security_Patch_Level()) { - LOGE("[InstallKey(): security patch level: %d. Minimum:%d]", + LOGE("[InstallKey(): security_patch_level = %u, minimum_patch_level = %u]", OEMCrypto_Security_Patch_Level(), minimum_patch_level); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } @@ -1026,7 +1028,7 @@ OEMCryptoResult SessionContext::InstallKey( bool SessionContext::InstallRSAEncryptedKey( const uint8_t* encrypted_message_key, size_t encrypted_message_key_length) { encryption_key_.resize(RSA_size(rsa_key())); - int decrypted_size = RSA_private_decrypt( + const int decrypted_size = RSA_private_decrypt( encrypted_message_key_length, encrypted_message_key, &encryption_key_[0], rsa_key(), RSA_PKCS1_OAEP_PADDING); if (-1 == decrypted_size) { @@ -1054,7 +1056,7 @@ OEMCryptoResult SessionContext::LoadRenewal(const uint8_t* message, return OEMCrypto_ERROR_INVALID_CONTEXT; } if (!ValidateMessage(message, message_length, signature, signature_length)) { - LOGE("signature was invalid"); + LOGE("Signature was invalid"); return OEMCrypto_ERROR_SIGNATURE_FAILURE; } @@ -1247,7 +1249,7 @@ OEMCryptoResult SessionContext::Generic_Encrypt(const uint8_t* in_buffer, const std::vector& key = current_content_key()->value(); // Set the AES key. if (static_cast(key.size()) != AES_BLOCK_SIZE) { - LOGE("[Generic_Encrypt(): CONTENT_KEY has wrong size: %d", key.size()); + LOGE("[Generic_Encrypt(): CONTENT_KEY has wrong size: %zu", key.size()); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } OEMCryptoResult result = CheckKeyUse("Generic_Encrypt", wvoec::kControlAllowEncrypt, @@ -1332,7 +1334,7 @@ OEMCryptoResult SessionContext::Generic_Sign(const uint8_t* in_buffer, } const std::vector& key = current_content_key()->value(); if (static_cast(key.size()) != SHA256_DIGEST_LENGTH) { - LOGE("[Generic_Sign(): CONTENT_KEY has wrong size; %d", key.size()); + LOGE("[Generic_Sign(): CONTENT_KEY has wrong size: %zu", key.size()); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } OEMCryptoResult result = CheckKeyUse("Generic_Sign", wvoec::kControlAllowSign, @@ -1368,7 +1370,7 @@ OEMCryptoResult SessionContext::Generic_Verify(const uint8_t* in_buffer, } const std::vector& key = current_content_key()->value(); if (static_cast(key.size()) != SHA256_DIGEST_LENGTH) { - LOGE("[Generic_Verify(): CONTENT_KEY has wrong size: %d", key.size()); + LOGE("[Generic_Verify(): CONTENT_KEY has wrong size: %zu", key.size()); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } OEMCryptoResult result = CheckKeyUse("Generic_Verify", wvoec::kControlAllowVerify, @@ -1558,20 +1560,20 @@ OEMCryptoResult SessionContext::DecryptSamples( OEMCryptoResult result = ce_->SetDestination( subsample_dest, subsample_length, subsample.subsample_flags); if (result != OEMCrypto_SUCCESS) { - LOGE("SetDestination status: %d", result); + LOGE("SetDestination status: %d", static_cast(result)); return result; } result = DecryptSubsample(subsample, subsample_source, ce_->destination(), subsample_dest.type, subsample_iv, pattern); if (result != OEMCrypto_SUCCESS) { - LOGE("DecryptSubsample status: %d", result); + LOGE("DecryptSubsample status: %d", static_cast(result)); return result; } result = ce_->PushDestination(subsample_dest, subsample.subsample_flags); if (result != OEMCrypto_SUCCESS) { - LOGE("PushDestination status: %d", result); + LOGE("PushDestination status: %d", static_cast(result)); return result; } @@ -1630,7 +1632,7 @@ OEMCryptoResult SessionContext::DecryptSubsample( current_hash_); if (OEMCrypto_LastSubsample & subsample.subsample_flags) { if (current_hash_ != given_hash_) { - LOGE("CRC for frame %d is %08x, should be %08x\n", + LOGE("CRC for frame %u is %08x, should be %08x\n", current_frame_number_, current_hash_, given_hash_); // Update bad_frame_number_ only if this is the first bad frame. if (hash_error_ == OEMCrypto_SUCCESS) { @@ -1666,7 +1668,7 @@ OEMCryptoResult SessionContext::ChooseDecrypt( // Set the AES key. if (static_cast(content_key.size()) != AES_BLOCK_SIZE) { - LOGE("[DecryptCTR(): CONTENT_KEY has wrong size: %d", content_key.size()); + LOGE("[DecryptCTR(): CONTENT_KEY has wrong size: %zu", content_key.size()); return OEMCrypto_ERROR_DECRYPT_FAILED; } const uint8_t* key_u8 = &content_key[0]; diff --git a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_usage_table_ref.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_usage_table_ref.cpp index 99e5f7e9..08ea1e33 100644 --- a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_usage_table_ref.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_usage_table_ref.cpp @@ -116,7 +116,7 @@ OEMCryptoResult UsageTableEntry::ReportUsage(const std::vector& pst, if (recent_decrypt_) return OEMCrypto_ERROR_ENTRY_NEEDS_UPDATE; if (pst.size() == 0 || pst.size() > kMaxPSTLength || pst.size() != data_.pst_length) { - LOGE("ReportUsage: bad pst length = %d, should be %d.", pst.size(), + LOGE("ReportUsage: bad pst length = %zu, should be %u.", pst.size(), data_.pst_length); return OEMCrypto_ERROR_WRONG_PST; } @@ -125,7 +125,8 @@ OEMCryptoResult UsageTableEntry::ReportUsage(const std::vector& pst, wvcdm::HexEncode(data_.pst, data_.pst_length).c_str()); return OEMCrypto_ERROR_WRONG_PST; } - size_t length_needed = wvcdm::Unpacked_PST_Report::report_size(pst.size()); + const size_t length_needed = + wvcdm::Unpacked_PST_Report::report_size(pst.size()); if (*buffer_length < length_needed) { *buffer_length = length_needed; return OEMCrypto_ERROR_SHORT_BUFFER; @@ -135,7 +136,7 @@ OEMCryptoResult UsageTableEntry::ReportUsage(const std::vector& pst, return OEMCrypto_ERROR_INVALID_CONTEXT; } wvcdm::Unpacked_PST_Report pst_report(buffer); - int64_t now = usage_table_->ce_->SystemTime(); + const int64_t now = usage_table_->ce_->SystemTime(); pst_report.set_seconds_since_license_received(now - data_.time_of_license_received); pst_report.set_seconds_since_first_decrypt(now - data_.time_of_first_decrypt); @@ -233,7 +234,7 @@ OEMCryptoResult UsageTableEntry::LoadData(CryptoEngine* ce, uint32_t index, ODK_ClockValues* clock_values) { if (buffer.size() < SignedEntrySize()) return OEMCrypto_ERROR_SHORT_BUFFER; if (buffer.size() > SignedEntrySize()) - LOGW("LoadUsageTableEntry: buffer is large. %d > %d", buffer.size(), + LOGW("LoadUsageTableEntry: buffer is large. %zu > %zu", buffer.size(), SignedEntrySize()); std::vector clear_buffer(buffer.size()); SignedEntryBlock* clear = @@ -357,10 +358,10 @@ OEMCryptoResult UsageTable::CreateNewUsageEntry( } if (!entry) return OEMCrypto_ERROR_UNKNOWN_FAILURE; if (!usage_entry_number) return OEMCrypto_ERROR_UNKNOWN_FAILURE; - uint32_t index = generation_numbers_.size(); - size_t max = ce_->max_usage_table_size(); + const size_t index = generation_numbers_.size(); + const size_t max = ce_->max_usage_table_size(); if (max > 0 && index >= max) { - LOGE("Too many usage entries: %d/%d", index, max); + LOGE("Too many usage entries: %zu/%zu", index, max); return OEMCrypto_ERROR_INSUFFICIENT_RESOURCES; } UsageTableEntry* new_entry = MakeEntry(index); @@ -387,9 +388,9 @@ OEMCryptoResult UsageTable::LoadUsageEntry( LOGE("LoadUsageEntry: index %d used by other session.", index); return OEMCrypto_ERROR_INVALID_SESSION; } - size_t max = ce_->max_usage_table_size(); + const size_t max = ce_->max_usage_table_size(); if (max > 0 && index >= max) { - LOGE("Too many usage entries: %d/%d", index, max); + LOGE("Too many usage entries: %u/%zu", index, max); return OEMCrypto_ERROR_INSUFFICIENT_RESOURCES; } std::unique_ptr new_entry(MakeEntry(index)); @@ -417,7 +418,7 @@ OEMCryptoResult UsageTable::ShrinkUsageTableHeader( uint32_t new_table_size, uint8_t* header_buffer, size_t* header_buffer_length) { if (new_table_size > generation_numbers_.size()) { - LOGE("OEMCrypto_ShrinkUsageTableHeader: %d > %zd.", new_table_size, + LOGE("OEMCrypto_ShrinkUsageTableHeader: %u > %zu", new_table_size, generation_numbers_.size()); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } @@ -433,7 +434,7 @@ OEMCryptoResult UsageTable::ShrinkUsageTableHeader( } for (size_t i = new_table_size; i < sessions_.size(); ++i) { if (sessions_[i]) { - LOGE("ShrinkUsageTableHeader: session open for %d", i); + LOGE("ShrinkUsageTableHeader: session open for %zu", i); return OEMCrypto_ERROR_ENTRY_IN_USE; } } @@ -505,8 +506,8 @@ OEMCryptoResult UsageTable::LoadUsageTableHeader( if (buffer.size() < SignedHeaderSize(0)) return OEMCrypto_ERROR_SHORT_BUFFER; size_t max = ce_->max_usage_table_size(); if (max > 0 && buffer.size() > SignedHeaderSize(max)) { - LOGE("Header too big: %zd bytes/%zd bytes", - buffer.size(), SignedHeaderSize(max)); + LOGE("Header too big: %zu bytes/%zu bytes", buffer.size(), + SignedHeaderSize(max)); return OEMCrypto_ERROR_INSUFFICIENT_RESOURCES; } std::vector clear_buffer(buffer.size()); @@ -567,7 +568,7 @@ OEMCryptoResult UsageTable::LoadUsageTableHeader( return OEMCrypto_ERROR_SHORT_BUFFER; } if (buffer.size() > SignedHeaderSize(clear->count)) { - LOGW("LoadUsageTableHeader: buffer is large. %d > %d", buffer.size(), + LOGW("LoadUsageTableHeader: buffer is large. %zu > %zu", buffer.size(), SignedHeaderSize(clear->count)); } @@ -594,12 +595,12 @@ OEMCryptoResult UsageTable::LoadUsageTableHeader( OEMCryptoResult UsageTable::MoveEntry(UsageTableEntry* entry, uint32_t new_index) { if (new_index >= generation_numbers_.size()) { - LOGE("MoveEntry: index beyond end of usage table %d >= %d", new_index, + LOGE("MoveEntry: index beyond end of usage table %u >= %zu", new_index, generation_numbers_.size()); return OEMCrypto_ERROR_INVALID_CONTEXT; } if (sessions_[new_index]) { - LOGE("MoveEntry: session open for %d", new_index); + LOGE("MoveEntry: session open for %u", new_index); return OEMCrypto_ERROR_ENTRY_IN_USE; } if (!entry) { @@ -690,7 +691,7 @@ OEMCryptoResult UsageTable::CreateUsageTableHeader( // Make sure there are no entries that are currently tied to an open session. for (size_t i = 0; i < sessions_.size(); ++i) { if (sessions_[i] != nullptr) { - LOGE("CreateUsageTableHeader: index %d used by session.", i); + LOGE("CreateUsageTableHeader: index %zu used by session.", i); return OEMCrypto_ERROR_INVALID_SESSION; } } diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp index b04eba28..2d845f48 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp @@ -5883,7 +5883,7 @@ TEST_P(OEMCryptoUsageTableDefragTest, ManyUsageEntries) { OEMCryptoResult status = OEMCrypto_SUCCESS; while (successful_count < attempt_count && status == OEMCrypto_SUCCESS) { wvcdm::TestSleep::SyncFakeClock(); - LOGD("Creating license for entry %zd", successful_count); + LOGD("Creating license for entry %zu", successful_count); entries.push_back( std::unique_ptr(new LicenseWithUsageEntry())); entries.back()->set_pst("pst " + std::to_string(successful_count)); @@ -5909,7 +5909,7 @@ TEST_P(OEMCryptoUsageTableDefragTest, ManyUsageEntries) { successful_count++; } } - LOGD("successful_count = %d", successful_count); + LOGD("successful_count = %zu", successful_count); if (status != OEMCrypto_SUCCESS) { // If we failed to create this many entries because of limited resources, // then the error returned should be insufficient resources.