Modify Code to Work with Clang/C++11

Merge from widevine repo of http://go/wvgerrit/15659

The clang compiler is more strict about C++11. This is needed for
future Android work.

In particular, iostream no longer converts to bool automtically, so
those instances were replaced with ss.fail().

Arrays or structures that appear to be variable length need to be
placed last in a structure.  In oemcrypto_test a variable size
structure was replaced with an explicit buffer size, and a check was
added to make sure the buffer is not exceeded.

bug: 20893039
Change-Id: I5e25fc618dcf68262079c15554ee4ceae1858b8b
This commit is contained in:
Fred Gylys-Colwell
2015-09-16 13:26:04 -07:00
parent ff6b79d945
commit bf0c87e734
5 changed files with 35 additions and 30 deletions

View File

@@ -2,8 +2,6 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CLANG := false
LOCAL_MODULE:=oemcrypto_test
LOCAL_MODULE_TAGS := tests

View File

@@ -98,11 +98,6 @@ struct RSAPrivateKeyMessage {
uint32_t nonce;
};
struct PaddedPSTReport {
OEMCrypto_PST_Report report;
uint8_t padding[256];
};
// These are test keyboxes. They will not be accepted by production systems.
// By using known keyboxes for these tests, the results for a given set of
// inputs to a test are predictable and can be compared to the actual results.
@@ -1400,16 +1395,17 @@ class Session {
size_t length = 0;
OEMCryptoResult sts = OEMCrypto_ReportUsage(
session_id(), reinterpret_cast<const uint8_t*>(pst.c_str()),
pst.length(), &pst_report_.report, &length);
pst.length(), pst_report(), &length);
if (expect_success) {
ASSERT_EQ(OEMCrypto_ERROR_SHORT_BUFFER, sts);
}
if (sts == OEMCrypto_ERROR_SHORT_BUFFER) {
ASSERT_GE(sizeof(PaddedPSTReport), length);
ASSERT_LE(sizeof(OEMCrypto_PST_Report), length);
pst_report_buffer_.resize(length);
}
sts = OEMCrypto_ReportUsage(session_id(),
reinterpret_cast<const uint8_t*>(pst.c_str()),
pst.length(), &pst_report_.report, &length);
pst.length(), pst_report(), &length);
if (!expect_success) {
ASSERT_NE(OEMCrypto_SUCCESS, sts);
return;
@@ -1418,16 +1414,19 @@ class Session {
vector<uint8_t> computed_signature(SHA_DIGEST_LENGTH);
unsigned int sig_len = SHA_DIGEST_LENGTH;
HMAC(EVP_sha1(), &mac_key_client_[0], mac_key_client_.size(),
reinterpret_cast<uint8_t*>(&pst_report_.report) + SHA_DIGEST_LENGTH,
reinterpret_cast<uint8_t*>(pst_report()) + SHA_DIGEST_LENGTH,
length - SHA_DIGEST_LENGTH, &computed_signature[0], &sig_len);
EXPECT_EQ(0, memcmp(&computed_signature[0], pst_report_.report.signature,
EXPECT_EQ(0, memcmp(&computed_signature[0], pst_report()->signature,
SHA_DIGEST_LENGTH));
EXPECT_GE(kInactive, pst_report_.report.status);
EXPECT_GE(kHardwareSecureClock, pst_report_.report.clock_security_level);
EXPECT_EQ(pst.length(), pst_report_.report.pst_length);
EXPECT_EQ(0, memcmp(pst.c_str(), pst_report_.report.pst, pst.length()));
EXPECT_GE(kInactive, pst_report()->status);
EXPECT_GE(kHardwareSecureClock, pst_report()->clock_security_level);
EXPECT_EQ(pst.length(), pst_report()->pst_length);
EXPECT_EQ(0, memcmp(pst.c_str(), pst_report()->pst, pst.length()));
}
OEMCrypto_PST_Report* pst_report() {
return reinterpret_cast<OEMCrypto_PST_Report*>(&pst_report_buffer_[0]);
}
OEMCrypto_PST_Report* pst_report() { return &pst_report_.report; }
void DeleteEntry(const std::string& pst) {
uint8_t* pst_ptr = encrypted_license_.pst;
@@ -1462,7 +1461,7 @@ class Session {
vector<uint8_t> enc_key_;
uint32_t nonce_;
RSA* public_rsa_;
PaddedPSTReport pst_report_;
vector<uint8_t> pst_report_buffer_;
MessageData license_;
MessageData encrypted_license_;
OEMCrypto_KeyObject key_array_[kNumKeys];