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

@@ -13,6 +13,7 @@
#include "crypto_key.h"
#include "log.h"
#include "properties.h"
#include "pst_report.h"
#include "string_conversions.h"
#include "wv_cdm_constants.h"
@@ -835,65 +836,65 @@ CdmResponseType CryptoSession::GenerateUsageReport(
}
}
usage_report->resize(usage_length);
OEMCrypto_PST_Report* report = reinterpret_cast<OEMCrypto_PST_Report*>(
const_cast<char*>(usage_report->data()));
std::vector<uint8_t> buffer(usage_length);
status = OEMCrypto_ReportUsage(oec_session_id_, pst,
provider_session_token.length(), report,
&usage_length);
provider_session_token.length(),
&buffer[0], &usage_length);
if (OEMCrypto_SUCCESS != status) {
LOGE("CryptoSession::GenerateUsageReport: Report Usage error=%ld", status);
return UNKNOWN_ERROR;
}
if (usage_length != usage_report->length()) {
usage_report->resize(usage_length);
if (usage_length != buffer.size()) {
buffer.resize(usage_length);
}
(*usage_report) = std::string(reinterpret_cast<const char *>(&buffer[0]),
buffer.size());
OEMCrypto_PST_Report pst_report;
Unpacked_PST_Report pst_report(&buffer[0]);
*usage_duration_status = kUsageDurationsInvalid;
if (usage_length < sizeof(pst_report)) {
if (usage_length < pst_report.report_size()) {
LOGE("CryptoSession::GenerateUsageReport: usage report too small=%ld",
usage_length);
return NO_ERROR; // usage report available but no duration information
}
memcpy(&pst_report, usage_report->data(), sizeof(pst_report));
if (kUnused == pst_report.status) {
if (kUnused == pst_report.status()) {
*usage_duration_status = kUsageDurationPlaybackNotBegun;
return NO_ERROR;
}
LOGV("OEMCrypto_PST_Report.status: %d\n", pst_report.status);
LOGV("OEMCrypto_PST_Report.status: %d\n", pst_report.status());
LOGV("OEMCrypto_PST_Report.clock_security_level: %d\n",
pst_report.clock_security_level);
LOGV("OEMCrypto_PST_Report.pst_length: %d\n", pst_report.pst_length);
LOGV("OEMCrypto_PST_Report.padding: %d\n", pst_report.padding);
pst_report.clock_security_level());
LOGV("OEMCrypto_PST_Report.pst_length: %d\n",
pst_report.pst_length());
LOGV("OEMCrypto_PST_Report.padding: %d\n", pst_report.padding());
LOGV("OEMCrypto_PST_Report.seconds_since_license_received: %lld\n",
ntohll64(pst_report.seconds_since_license_received));
pst_report.seconds_since_license_received());
LOGV("OEMCrypto_PST_Report.seconds_since_first_decrypt: %lld\n",
ntohll64(pst_report.seconds_since_first_decrypt));
pst_report.seconds_since_first_decrypt());
LOGV("OEMCrypto_PST_Report.seconds_since_last_decrypt: %lld\n",
ntohll64(pst_report.seconds_since_last_decrypt));
pst_report.seconds_since_last_decrypt());
LOGV("OEMCrypto_PST_Report: %s\n", b2a_hex(*usage_report).c_str());
if (kInactiveUnused == pst_report.status) {
if (kInactiveUnused == pst_report.status()) {
*usage_duration_status = kUsageDurationPlaybackNotBegun;
return NO_ERROR;
}
// Before OEMCrypto v13, When usage report state is inactive, we have to
// deduce whether the license was ever used.
if (kInactive == pst_report.status &&
(0 > ntohll64(pst_report.seconds_since_first_decrypt) ||
ntohll64(pst_report.seconds_since_license_received) <
ntohll64(pst_report.seconds_since_first_decrypt))) {
if (kInactive == pst_report.status() &&
(0 > pst_report.seconds_since_first_decrypt() ||
pst_report.seconds_since_license_received() <
pst_report.seconds_since_first_decrypt())) {
*usage_duration_status = kUsageDurationPlaybackNotBegun;
return NO_ERROR;
}
*usage_duration_status = kUsageDurationsValid;
*seconds_since_started = ntohll64(pst_report.seconds_since_first_decrypt);
*seconds_since_last_played = ntohll64(pst_report.seconds_since_last_decrypt);
*seconds_since_started = pst_report.seconds_since_first_decrypt();
*seconds_since_last_played = pst_report.seconds_since_last_decrypt();
return NO_ERROR;
}

View File

@@ -184,7 +184,7 @@ typedef OEMCryptoResult (*L1_DeactivateUsageEntry_V12_t)(const uint8_t* pst,
typedef OEMCryptoResult (*L1_ReportUsage_t)(OEMCrypto_SESSION session,
const uint8_t* pst,
size_t pst_length,
OEMCrypto_PST_Report* buffer,
uint8_t* buffer,
size_t* buffer_length);
typedef OEMCryptoResult (*L1_DeleteUsageEntry_t)(
OEMCrypto_SESSION session, const uint8_t* pst, size_t pst_length,
@@ -1443,7 +1443,7 @@ extern "C" OEMCryptoResult OEMCrypto_DeactivateUsageEntry(OEMCrypto_SESSION sess
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 (!kAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE;
LevelSession pair = kAdapter->get(session);