Replace PST Report with buffer

Merge from Widevine repo of http://go/wvgerrit/23044

On some platforms, the compiler will not pack structures.  This CL
replaces the OECrypto_PST_Report packed structure with a simple buffer
of uint8_t.  This changes the signature of OEMCrypto_ReportUsage as
part of OEMCrypto v13.

There is also a new wrapper class that test code, the mock, and debug
code can use to access data in the report.

The old packed structure definition is moved to the level 3, where we
use a compiler that packs sructs when asked nicely.

arm/libwvlevel3.a  Level3 Library 4445 Jan 20 2017 11:29:15
x86/libwvlevel3.a  Level3 Library 4464 Jan 20 2017 11:10:49
mips/libwvlevel3.a  Level3 Library 4465 Jan 20 2017 10:56:08

b/32180083

Change-Id: Ie138f034cb12780a2f8636888cebf022c52169e5
This commit is contained in:
Fred Gylys-Colwell
2017-01-20 19:02:20 -08:00
parent a494eeafdc
commit 7152957e42
15 changed files with 341 additions and 230 deletions

View File

@@ -1691,7 +1691,7 @@ extern "C"
OEMCryptoResult OEMCrypto_ReportUsage(OEMCrypto_SESSION session,
const uint8_t *pst,
size_t pst_length,
OEMCrypto_PST_Report *buffer,
uint8_t *buffer,
size_t *buffer_length) {
if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) {
LOGI("-- OEMCryptoResult OEMCrypto_ReportUsage(\n");
@@ -1722,8 +1722,7 @@ OEMCryptoResult OEMCrypto_ReportUsage(OEMCrypto_SESSION session,
crypto_engine->usage_table()->UpdateTable();
if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) {
if (wvcdm::g_cutoff >= wvcdm::LOG_VERBOSE) {
dump_hex("usage buffer", reinterpret_cast<uint8_t*>(buffer),
*buffer_length);
dump_hex("usage buffer", buffer, *buffer_length);
}
}
return sts;

View File

@@ -20,6 +20,7 @@
#include "oemcrypto_engine_mock.h"
#include "oemcrypto_logging.h"
#include "properties.h"
#include "pst_report.h"
#include "string_conversions.h"
#include "wv_cdm_constants.h"
@@ -98,9 +99,9 @@ bool UsageTableEntry::UpdateTime() {
OEMCryptoResult UsageTableEntry::ReportUsage(SessionContext *session,
const std::vector<uint8_t> &pst,
OEMCrypto_PST_Report *buffer,
uint8_t *buffer,
size_t *buffer_length) {
size_t length_needed = sizeof(OEMCrypto_PST_Report) + pst.size();
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;
@@ -109,21 +110,19 @@ OEMCryptoResult UsageTableEntry::ReportUsage(SessionContext *session,
LOGE("ReportUsage: buffer was null pointer.");
return OEMCrypto_ERROR_INVALID_CONTEXT;
}
wvcdm::Unpacked_PST_Report pst_report(buffer);
int64_t now = time(NULL);
buffer->seconds_since_license_received =
wvcdm::htonll64(now - time_of_license_received_);
buffer->seconds_since_first_decrypt =
wvcdm::htonll64(now - time_of_first_decrypt_);
buffer->seconds_since_last_decrypt =
wvcdm::htonll64(now - time_of_last_decrypt_);
buffer->status = status_;
buffer->clock_security_level = kSecureTimer;
buffer->pst_length = static_cast<uint8_t>(pst.size());
memcpy(buffer->pst, &pst[0], length_needed - sizeof(OEMCrypto_PST_Report));
unsigned int md_len = sizeof(buffer->signature);
pst_report.set_seconds_since_license_received(now - time_of_license_received_);
pst_report.set_seconds_since_first_decrypt(now - time_of_first_decrypt_);
pst_report.set_seconds_since_last_decrypt(now - time_of_last_decrypt_);
pst_report.set_status(status_);
pst_report.set_clock_security_level(kSecureTimer);
pst_report.set_pst_length(static_cast<uint8_t>(pst.size()));
memcpy(pst_report.pst(), &pst[0], pst.size());
unsigned int md_len = SHA_DIGEST_LENGTH;
if (!HMAC(EVP_sha1(), &mac_key_client_[0], mac_key_client_.size(),
reinterpret_cast<uint8_t *>(buffer) + SHA_DIGEST_LENGTH,
length_needed - SHA_DIGEST_LENGTH, buffer->signature, &md_len)) {
buffer + SHA_DIGEST_LENGTH, length_needed - SHA_DIGEST_LENGTH,
pst_report.signature(), &md_len)) {
LOGE("UsageTableEntry: could not compute signature.");
return OEMCrypto_ERROR_UNKNOWN_FAILURE;
}

View File

@@ -55,7 +55,7 @@ class UsageTableEntry {
bool UpdateTime();
OEMCryptoResult ReportUsage(SessionContext *session,
const std::vector<uint8_t> &pst,
OEMCrypto_PST_Report *buffer,
uint8_t *buffer,
size_t *buffer_length);
// Set them if not set, verify if already set.
bool VerifyOrSetMacKeys(const std::vector<uint8_t> &server,