Add clang-tidy support for the OPK Linux port

Bug: 256230932
Change-Id: I4f46e285376101ff129c1fca5c80a259c70cc0c7
This commit is contained in:
Ian Benz
2023-04-04 15:38:26 +00:00
committed by Robert Shih
parent 44e21cb9c2
commit b9d857649e
10 changed files with 27 additions and 38 deletions

View File

@@ -60,17 +60,12 @@ void DeviceFeatures::Initialize() {
printf("--- ERROR: Could not open session: %d ----\n", result); printf("--- ERROR: Could not open session: %d ----\n", result);
} }
// If the device uses a keybox, check to see if loading a certificate is // If the device uses a keybox, check to see if loading a certificate is
// installed. // installed. Devices with a keybox or OEM Certificate are required to support
if (provisioning_method == OEMCrypto_Keybox || // loading a DRM certificate. Other devices are either broken, or they have a
provisioning_method == OEMCrypto_OEMCertificate || // baked in certificate.
provisioning_method == OEMCrypto_BootCertificateChain) { loads_certificate = provisioning_method == OEMCrypto_Keybox ||
// Devices with a keybox or OEM Certificate are required to support loading provisioning_method == OEMCrypto_OEMCertificate ||
// a DRM certificate. provisioning_method == OEMCrypto_BootCertificateChain;
loads_certificate = true;
} else {
// Other devices are either broken, or they have a baked in certificate.
loads_certificate = false;
}
printf("loads_certificate = %s.\n", loads_certificate ? "true" : "false"); printf("loads_certificate = %s.\n", loads_certificate ? "true" : "false");
generic_crypto = generic_crypto =
(OEMCrypto_ERROR_NOT_IMPLEMENTED != (OEMCrypto_ERROR_NOT_IMPLEMENTED !=

View File

@@ -685,11 +685,9 @@ void LicenseRoundTrip::CreateDefaultResponse() {
// Fill in the default core_response_ fields, except the substrings, which are // Fill in the default core_response_ fields, except the substrings, which are
// filled in the next function. // filled in the next function.
core_response_.nonce_required = core_response_.nonce_required =
((wvoec::kControlNonceEnabled | wvoec::kControlNonceOrEntry | (wvoec::kControlNonceEnabled | wvoec::kControlNonceOrEntry |
wvoec::kControlNonceRequired) & wvoec::kControlNonceRequired) &
control_) control_;
? 1
: 0;
core_response_.license_type = license_type_; core_response_.license_type = license_type_;
FillCoreResponseSubstrings(); FillCoreResponseSubstrings();
} }
@@ -1866,10 +1864,7 @@ bool Session::GenerateRsaSessionKey(vector<uint8_t>* session_key,
} }
*session_key = wvutil::a2b_hex("6fa479c731d2770b6a61a5d1420bb9d1"); *session_key = wvutil::a2b_hex("6fa479c731d2770b6a61a5d1420bb9d1");
*enc_session_key = public_rsa_->EncryptSessionKey(*session_key); *enc_session_key = public_rsa_->EncryptSessionKey(*session_key);
if (enc_session_key->empty()) { return !enc_session_key->empty();
return false;
}
return true;
} }
bool Session::GenerateEccSessionKey(vector<uint8_t>* session_key, bool Session::GenerateEccSessionKey(vector<uint8_t>* session_key,

View File

@@ -27,8 +27,6 @@
#include "oemcrypto_types.h" #include "oemcrypto_types.h"
#include "pst_report.h" #include "pst_report.h"
using namespace std;
// GTest requires PrintTo to be in the same namespace as the thing it prints, // GTest requires PrintTo to be in the same namespace as the thing it prints,
// which is std::vector in this case. // which is std::vector in this case.
namespace std { namespace std {
@@ -38,13 +36,15 @@ void PrintTo(const vector<uint8_t>& value, ostream* os);
} // namespace std } // namespace std
namespace wvoec { namespace wvoec {
using namespace std;
// OEMCrypto Fuzzing: Set max signture length to 1mb. // OEMCrypto Fuzzing: Set max signture length to 1mb.
const size_t MB = 1024 * 1024; const size_t MB = 1024 * 1024;
// Make sure this is larger than kMaxKeysPerSession. // Make sure this is larger than kMaxKeysPerSession.
constexpr size_t kMaxNumKeys = 30; constexpr size_t kMaxNumKeys = 30;
namespace {
#if defined(TEST_SPEED_MULTIPLIER) // Can slow test time limits when #if defined(TEST_SPEED_MULTIPLIER) // Can slow test time limits when
// debugging is slowing everything. // debugging is slowing everything.
constexpr int kSpeedMultiplier = TEST_SPEED_MULTIPLIER; constexpr int kSpeedMultiplier = TEST_SPEED_MULTIPLIER;
@@ -57,7 +57,6 @@ constexpr uint32_t kDuration = 2 * kSpeedMultiplier;
constexpr uint32_t kLongDuration = 5 * kSpeedMultiplier; constexpr uint32_t kLongDuration = 5 * kSpeedMultiplier;
constexpr int32_t kTimeTolerance = 3 * kSpeedMultiplier; constexpr int32_t kTimeTolerance = 3 * kSpeedMultiplier;
constexpr int64_t kUsageTableTimeTolerance = 10 * kSpeedMultiplier; constexpr int64_t kUsageTableTimeTolerance = 10 * kSpeedMultiplier;
} // namespace
// Note: The API does not specify a maximum key id length. We specify a // Note: The API does not specify a maximum key id length. We specify a
// maximum just for these tests, so that we have a fixed message size. // maximum just for these tests, so that we have a fixed message size.
@@ -158,7 +157,7 @@ class RoundTrip {
required_request_signature_size_(0), required_request_signature_size_(0),
encrypted_response_length_(0), encrypted_response_length_(0),
response_signature_length_(0) {} response_signature_length_(0) {}
virtual ~RoundTrip() {} virtual ~RoundTrip() = default;
// Have OEMCrypto sign a request message and then verify the signature and the // Have OEMCrypto sign a request message and then verify the signature and the
// core message. // core message.
@@ -380,7 +379,7 @@ class LicenseRoundTrip
: RoundTrip(session), : RoundTrip(session),
control_(wvoec::kControlNonceEnabled), control_(wvoec::kControlNonceEnabled),
num_keys_(4), num_keys_(4),
pst_(""), pst_(),
minimum_srm_version_(0), minimum_srm_version_(0),
update_mac_keys_(true), update_mac_keys_(true),
api_version_(kCurrentAPI), api_version_(kCurrentAPI),
@@ -519,7 +518,7 @@ class RenewalRoundTrip
void EncryptAndSignResponse() override; void EncryptAndSignResponse() override;
void InjectFuzzedResponseData(OEMCrypto_Renewal_Response_Fuzz& fuzzed_data, void InjectFuzzedResponseData(OEMCrypto_Renewal_Response_Fuzz& fuzzed_data,
const uint8_t* renewal_response, const uint8_t* renewal_response,
const size_t renewal_response_size); size_t renewal_response_size);
OEMCryptoResult LoadResponse() override { return LoadResponse(session_); } OEMCryptoResult LoadResponse() override { return LoadResponse(session_); }
OEMCryptoResult LoadResponse(Session* session) override; OEMCryptoResult LoadResponse(Session* session) override;
uint64_t renewal_duration_seconds() const { uint64_t renewal_duration_seconds() const {
@@ -852,6 +851,7 @@ OEMCryptoResult GetKeyHandleIntoVector(OEMCrypto_SESSION session,
size_t key_id_length, size_t key_id_length,
OEMCryptoCipherMode cipher_mode, OEMCryptoCipherMode cipher_mode,
vector<uint8_t>& key_handle); vector<uint8_t>& key_handle);
} // namespace wvoec } // namespace wvoec
#endif // CDM_OEC_SESSION_UTIL_H_ #endif // CDM_OEC_SESSION_UTIL_H_

View File

@@ -189,7 +189,6 @@ TEST_F(OEMCryptoClientTest, VersionNumber) {
if (sts != OEMCrypto_SUCCESS) { if (sts != OEMCrypto_SUCCESS) {
LOGW("Device is not production ready, returns %d", sts); LOGW("Device is not production ready, returns %d", sts);
} }
sts = OEMCrypto_SUCCESS;
std::string build_info; std::string build_info;
size_t buf_length = 0; size_t buf_length = 0;
sts = OEMCrypto_BuildInformation(&build_info[0], &buf_length); sts = OEMCrypto_BuildInformation(&build_info[0], &buf_length);

View File

@@ -14,7 +14,7 @@ namespace wvoec {
const uint8_t kFuzzDataSeparator[] = {'-', '_', '^', '_'}; const uint8_t kFuzzDataSeparator[] = {'-', '_', '^', '_'};
void AppendToFile(const std::string& file_name, const char* message, void AppendToFile(const std::string& file_name, const char* message,
const size_t message_size); size_t message_size);
// Function to append separator "-_^_" between contents of corpus file. // Function to append separator "-_^_" between contents of corpus file.
void AppendSeparator(const std::string& file_name); void AppendSeparator(const std::string& file_name);

View File

@@ -960,7 +960,6 @@ TEST_P(OEMCryptoRefreshTest, RenewLicenseLoadOutsideRentalDuration) {
// failure. // failure.
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(
session_.TestDecryptCTR(false, OEMCrypto_ERROR_UNKNOWN_FAILURE)); session_.TestDecryptCTR(false, OEMCrypto_ERROR_UNKNOWN_FAILURE));
return;
} }
INSTANTIATE_TEST_SUITE_P(TestAll, OEMCryptoRefreshTest, INSTANTIATE_TEST_SUITE_P(TestAll, OEMCryptoRefreshTest,

View File

@@ -17,10 +17,10 @@
#include "oemcrypto_resource_test.h" #include "oemcrypto_resource_test.h"
#include "wvcrc32.h" #include "wvcrc32.h"
using ::testing::WithParamInterface;
namespace wvoec { namespace wvoec {
using ::testing::WithParamInterface;
// Used for testing oemcrypto APIs with huge buffers. // Used for testing oemcrypto APIs with huge buffers.
typedef const std::function<OEMCryptoResult(size_t)> oemcrypto_function; typedef const std::function<OEMCryptoResult(size_t)> oemcrypto_function;
void TestHugeLengthDoesNotCrashAPI(oemcrypto_function f, void TestHugeLengthDoesNotCrashAPI(oemcrypto_function f,

View File

@@ -87,11 +87,8 @@
#include "test_sleep.h" #include "test_sleep.h"
#include "wvcrc32.h" #include "wvcrc32.h"
using ::testing::Bool;
using ::testing::Combine;
using ::testing::Range; using ::testing::Range;
using ::testing::tuple; using ::testing::tuple;
using ::testing::Values;
using ::testing::WithParamInterface; using ::testing::WithParamInterface;
using namespace std; using namespace std;

View File

@@ -207,7 +207,9 @@ OEMCryptoResult OemCertificate::GetPublicCertificate(
return OEMCrypto_ERROR_SHORT_BUFFER; return OEMCrypto_ERROR_SHORT_BUFFER;
} }
*public_cert_length = cert_data.size(); *public_cert_length = cert_data.size();
memcpy(public_cert, cert_data.data(), cert_data.size()); if (public_cert != nullptr) {
memcpy(public_cert, cert_data.data(), cert_data.size());
}
return OEMCrypto_SUCCESS; return OEMCrypto_SUCCESS;
} }

View File

@@ -92,7 +92,7 @@ bool ParseRsaPrivateKeyInfo(const uint8_t* buffer, size_t length,
} }
ScopedBio bio; ScopedBio bio;
// Check allowed scheme type. // Check allowed scheme type.
if (!memcmp("SIGN", buffer, 4)) { if (memcmp("SIGN", buffer, 4) == 0) {
uint32_t allowed_schemes_bno; uint32_t allowed_schemes_bno;
memcpy(&allowed_schemes_bno, reinterpret_cast<const uint8_t*>(&buffer[4]), memcpy(&allowed_schemes_bno, reinterpret_cast<const uint8_t*>(&buffer[4]),
4); 4);
@@ -811,7 +811,9 @@ OEMCryptoResult RsaPublicKey::EncryptOaep(const uint8_t* message,
return OEMCrypto_ERROR_SHORT_BUFFER; return OEMCrypto_ERROR_SHORT_BUFFER;
} }
*enc_message_length = enc_size; *enc_message_length = enc_size;
memcpy(enc_message, encrypt_buffer.data(), enc_size); if (enc_message != nullptr) {
memcpy(enc_message, encrypt_buffer.data(), enc_size);
}
return OEMCrypto_SUCCESS; return OEMCrypto_SUCCESS;
} }