Add InactiveUnused to Usage Report status

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

This change kInactive to kInactiveUsed and adds kInactiveUnused to the
possible values for the status field in the Usage Report.  This CL
updates the header, the unit tests, and haystack and reference code.

b/32714323

Change-Id: If8d8e32ea1e3dc18da34e5fae35f578b027de9c7
This commit is contained in:
Fred Gylys-Colwell
2017-01-20 18:52:02 -08:00
parent b2a3921b37
commit a494eeafdc
8 changed files with 36 additions and 22 deletions

View File

@@ -877,8 +877,12 @@ CdmResponseType CryptoSession::GenerateUsageReport(
ntohll64(pst_report.seconds_since_last_decrypt)); ntohll64(pst_report.seconds_since_last_decrypt));
LOGV("OEMCrypto_PST_Report: %s\n", b2a_hex(*usage_report).c_str()); LOGV("OEMCrypto_PST_Report: %s\n", b2a_hex(*usage_report).c_str());
// When usage report state is inactive, we have to deduce whether the if (kInactiveUnused == pst_report.status) {
// license was ever used. *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 && if (kInactive == pst_report.status &&
(0 > ntohll64(pst_report.seconds_since_first_decrypt) || (0 > ntohll64(pst_report.seconds_since_first_decrypt) ||
ntohll64(pst_report.seconds_since_license_received) < ntohll64(pst_report.seconds_since_license_received) <

View File

@@ -571,7 +571,7 @@ class WvCdmExtendedDurationTest : public WvCdmTestBase {
sizeof(usage_report)); sizeof(usage_report));
EXPECT_EQ(sizeof(usage_report) + usage_report.pst_length, EXPECT_EQ(sizeof(usage_report) + usage_report.pst_length,
existing_license.session_usage_table_entry().size()); existing_license.session_usage_table_entry().size());
EXPECT_EQ(kInactive, usage_report.status); EXPECT_EQ(kInactiveUsed, usage_report.status);
EXPECT_EQ(id.provider_session_token().size(), usage_report.pst_length); EXPECT_EQ(id.provider_session_token().size(), usage_report.pst_length);
std::string pst(existing_license.session_usage_table_entry().data() + std::string pst(existing_license.session_usage_table_entry().data() +
sizeof(OEMCrypto_PST_Report), sizeof(OEMCrypto_PST_Report),

View File

@@ -242,7 +242,9 @@ typedef struct {
typedef enum OEMCrypto_Usage_Entry_Status { typedef enum OEMCrypto_Usage_Entry_Status {
kUnused = 0, kUnused = 0,
kActive = 1, kActive = 1,
kInactive = 2 // TODO(fredgc): http://b/32714323. used and unused. kInactive = 2, // Deprecated. Used kInactiveUsed or kInactiveUnused.
kInactiveUsed = 3,
kInactiveUnused = 4,
} OEMCrypto_Usage_Entry_Status; } OEMCrypto_Usage_Entry_Status;
/* /*
@@ -2631,8 +2633,9 @@ OEMCryptoResult OEMCrypto_DeactivateUsageEntry(OEMCrypto_SESSION session,
* Valid values for status are: * Valid values for status are:
* 0 = kUnused -- the keys have not been used to decrypt. * 0 = kUnused -- the keys have not been used to decrypt.
* 1 = kActive -- the keys have been used, and have not been deactivated. * 1 = kActive -- the keys have been used, and have not been deactivated.
* 2 = kInactiveUsed -- the keys have been marked inactive after a decrypt. * 2 = kInactive -- deprecated. Use kInactiveUsed or kInactiveUnused.
* 3 = kInactiveUnused -- the keys have been marked inactive, no decrypt. * 3 = kInactiveUsed -- the keys have been marked inactive after a decrypt.
* 4 = kInactiveUnused -- the keys have been marked inactive, no decrypt.
* *
* The clock_security_level is reported as follows: * The clock_security_level is reported as follows:
* 0 = Insecure Clock - clock just uses system time. * 0 = Insecure Clock - clock just uses system time.

View File

@@ -381,13 +381,13 @@ bool SessionContext::CheckNonceOrEntry(const KeyControlBlock& key_control_block,
if (!usage_entry_) { if (!usage_entry_) {
usage_entry_ = ce_->usage_table()->FindEntry(pst); usage_entry_ = ce_->usage_table()->FindEntry(pst);
if (usage_entry_) { if (usage_entry_) {
if (usage_entry_->status() == kInactive) return false; if (usage_entry_->inactive()) return false;
} else { } else {
if (!CheckNonce(key_control_block.nonce())) return false; if (!CheckNonce(key_control_block.nonce())) return false;
usage_entry_ = ce_->usage_table()->CreateEntry(pst, this); usage_entry_ = ce_->usage_table()->CreateEntry(pst, this);
} }
} else { } else {
if (usage_entry_->status() == kInactive) return false; if (usage_entry_->inactive()) return false;
} }
break; // Usage table not required. Look at nonce enabled bit. break; // Usage table not required. Look at nonce enabled bit.
default: default:

View File

@@ -66,7 +66,11 @@ void UsageTableEntry::SaveToBuffer(StoredUsageEntry *buffer) {
} }
void UsageTableEntry::Deactivate() { void UsageTableEntry::Deactivate() {
status_ = kInactive; if (status_ == kUnused) {
status_ = kInactiveUnused;
} else if (status_ == kActive) {
status_ = kInactiveUsed;
}
if (session_) { if (session_) {
session_->ReleaseUsageEntry(); session_->ReleaseUsageEntry();
session_ = NULL; session_ = NULL;
@@ -85,6 +89,8 @@ bool UsageTableEntry::UpdateTime() {
time_of_last_decrypt_ = now; time_of_last_decrypt_ = now;
return true; return true;
case kInactive: case kInactive:
case kInactiveUsed:
case kInactiveUnused:
return false; return false;
} }
return false; return false;

View File

@@ -50,6 +50,7 @@ class UsageTableEntry {
~UsageTableEntry(); ~UsageTableEntry();
void SaveToBuffer(StoredUsageEntry *buffer); void SaveToBuffer(StoredUsageEntry *buffer);
OEMCrypto_Usage_Entry_Status status() const { return status_; } OEMCrypto_Usage_Entry_Status status() const { return status_; }
bool inactive() const { return status_ >= kInactive; }
void Deactivate(); void Deactivate();
bool UpdateTime(); bool UpdateTime();
OEMCryptoResult ReportUsage(SessionContext *session, OEMCryptoResult ReportUsage(SessionContext *session,

View File

@@ -842,7 +842,7 @@ void Session::GenerateReport(const std::string& pst, bool expect_success,
length - SHA_DIGEST_LENGTH, &computed_signature[0], &sig_len); length - SHA_DIGEST_LENGTH, &computed_signature[0], &sig_len);
EXPECT_EQ(0, memcmp(&computed_signature[0], pst_report()->signature, EXPECT_EQ(0, memcmp(&computed_signature[0], pst_report()->signature,
SHA_DIGEST_LENGTH)); SHA_DIGEST_LENGTH));
EXPECT_GE(kInactive, pst_report()->status); EXPECT_GE(kInactiveUnused, pst_report()->status);
EXPECT_GE(kHardwareSecureClock, pst_report()->clock_security_level); EXPECT_GE(kHardwareSecureClock, pst_report()->clock_security_level);
EXPECT_EQ(pst.length(), pst_report()->pst_length); EXPECT_EQ(pst.length(), pst_report()->pst_length);
EXPECT_EQ(0, memcmp(pst.c_str(), pst_report()->pst, pst.length())); EXPECT_EQ(0, memcmp(pst.c_str(), pst_report()->pst, pst.length()));

View File

@@ -4405,7 +4405,7 @@ TEST_P(UsageTableTestWithMAC, OnlineLicense) {
kTimeTolerance); kTimeTolerance);
ASSERT_NO_FATAL_FAILURE(DeactivatePST(pst)); ASSERT_NO_FATAL_FAILURE(DeactivatePST(pst));
ASSERT_NO_FATAL_FAILURE(s.GenerateReport(pst)); ASSERT_NO_FATAL_FAILURE(s.GenerateReport(pst));
EXPECT_EQ(kInactive, s.pst_report()->status); EXPECT_EQ(kInactiveUsed, s.pst_report()->status);
EXPECT_NEAR(0, EXPECT_NEAR(0,
wvcdm::htonll64(s.pst_report()->seconds_since_license_received), wvcdm::htonll64(s.pst_report()->seconds_since_license_received),
kTimeTolerance); kTimeTolerance);
@@ -4696,7 +4696,7 @@ TEST_P(UsageTableTestWithMAC, DeleteInactiveEntry) {
Session s2; Session s2;
ASSERT_NO_FATAL_FAILURE(s2.open()); ASSERT_NO_FATAL_FAILURE(s2.open());
s2.GenerateReport(pst, true, &s); s2.GenerateReport(pst, true, &s);
EXPECT_EQ(kInactive, s2.pst_report()->status); EXPECT_EQ(kInactiveUsed, s2.pst_report()->status);
ASSERT_NO_FATAL_FAILURE(s2.DeleteEntry(pst)); ASSERT_NO_FATAL_FAILURE(s2.DeleteEntry(pst));
ASSERT_NO_FATAL_FAILURE(s2.close()); ASSERT_NO_FATAL_FAILURE(s2.close());
@@ -4868,7 +4868,7 @@ TEST_P(UsageTableTestWithMAC, GenericCryptoEncrypt) {
kTimeTolerance); kTimeTolerance);
ASSERT_NO_FATAL_FAILURE(DeactivatePST(pst)); ASSERT_NO_FATAL_FAILURE(DeactivatePST(pst));
ASSERT_NO_FATAL_FAILURE(session_.GenerateReport(pst)); ASSERT_NO_FATAL_FAILURE(session_.GenerateReport(pst));
EXPECT_EQ(kInactive, session_.pst_report()->status); EXPECT_EQ(kInactiveUsed, session_.pst_report()->status);
EXPECT_NEAR( EXPECT_NEAR(
0, wvcdm::htonll64(session_.pst_report()->seconds_since_license_received), 0, wvcdm::htonll64(session_.pst_report()->seconds_since_license_received),
kTimeTolerance); kTimeTolerance);
@@ -4916,7 +4916,7 @@ TEST_P(UsageTableTestWithMAC, GenericCryptoDecrypt) {
kTimeTolerance); kTimeTolerance);
ASSERT_NO_FATAL_FAILURE(DeactivatePST(pst)); ASSERT_NO_FATAL_FAILURE(DeactivatePST(pst));
session_.GenerateReport(pst); session_.GenerateReport(pst);
EXPECT_EQ(kInactive, session_.pst_report()->status); EXPECT_EQ(kInactiveUsed, session_.pst_report()->status);
EXPECT_NEAR( EXPECT_NEAR(
0, wvcdm::htonll64(session_.pst_report()->seconds_since_license_received), 0, wvcdm::htonll64(session_.pst_report()->seconds_since_license_received),
kTimeTolerance); kTimeTolerance);
@@ -4973,7 +4973,7 @@ TEST_P(UsageTableTestWithMAC, GenericCryptoSign) {
kTimeTolerance); kTimeTolerance);
ASSERT_NO_FATAL_FAILURE(DeactivatePST(pst)); ASSERT_NO_FATAL_FAILURE(DeactivatePST(pst));
ASSERT_NO_FATAL_FAILURE(session_.GenerateReport(pst)); ASSERT_NO_FATAL_FAILURE(session_.GenerateReport(pst));
EXPECT_EQ(kInactive, session_.pst_report()->status); EXPECT_EQ(kInactiveUsed, session_.pst_report()->status);
EXPECT_NEAR( EXPECT_NEAR(
0, wvcdm::htonll64(session_.pst_report()->seconds_since_license_received), 0, wvcdm::htonll64(session_.pst_report()->seconds_since_license_received),
kTimeTolerance); kTimeTolerance);
@@ -5024,7 +5024,7 @@ TEST_P(UsageTableTestWithMAC, GenericCryptoVerify) {
kTimeTolerance); kTimeTolerance);
ASSERT_NO_FATAL_FAILURE(DeactivatePST(pst)); ASSERT_NO_FATAL_FAILURE(DeactivatePST(pst));
ASSERT_NO_FATAL_FAILURE(session_.GenerateReport(pst)); ASSERT_NO_FATAL_FAILURE(session_.GenerateReport(pst));
EXPECT_EQ(kInactive, session_.pst_report()->status); EXPECT_EQ(kInactiveUsed, session_.pst_report()->status);
EXPECT_NEAR( EXPECT_NEAR(
0, wvcdm::htonll64(session_.pst_report()->seconds_since_license_received), 0, wvcdm::htonll64(session_.pst_report()->seconds_since_license_received),
kTimeTolerance); kTimeTolerance);
@@ -5247,7 +5247,7 @@ TEST_P(UsageTableTestWithMAC, DeactivateOfflineLicense) {
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(
s.TestDecryptCTR(false, OEMCrypto_ERROR_UNKNOWN_FAILURE)); s.TestDecryptCTR(false, OEMCrypto_ERROR_UNKNOWN_FAILURE));
s.GenerateReport(pst); s.GenerateReport(pst);
EXPECT_EQ(kInactive, s.pst_report()->status); EXPECT_EQ(kInactiveUsed, s.pst_report()->status);
EXPECT_NEAR(0, EXPECT_NEAR(0,
wvcdm::htonll64(s.pst_report()->seconds_since_license_received), wvcdm::htonll64(s.pst_report()->seconds_since_license_received),
kTimeTolerance); kTimeTolerance);
@@ -5270,7 +5270,7 @@ TEST_P(UsageTableTestWithMAC, DeactivateOfflineLicense) {
Session s3; Session s3;
ASSERT_NO_FATAL_FAILURE(s3.open()); ASSERT_NO_FATAL_FAILURE(s3.open());
s3.GenerateReport(pst, true, &s); s3.GenerateReport(pst, true, &s);
EXPECT_EQ(kInactive, s3.pst_report()->status); EXPECT_EQ(kInactiveUsed, s3.pst_report()->status);
} }
TEST_P(UsageTableTestWithMAC, BadRange) { TEST_P(UsageTableTestWithMAC, BadRange) {
@@ -5362,7 +5362,7 @@ TEST_F(UsageTableTest, TimingTest) {
time_t report_generated3 = time(NULL); time_t report_generated3 = time(NULL);
s3.GenerateReport(pst3); s3.GenerateReport(pst3);
EXPECT_EQ(kInactive, s1.pst_report()->status); EXPECT_EQ(kInactiveUsed, s1.pst_report()->status);
EXPECT_NEAR(report_generated1 - loaded1, EXPECT_NEAR(report_generated1 - loaded1,
wvcdm::htonll64(s1.pst_report()->seconds_since_license_received), wvcdm::htonll64(s1.pst_report()->seconds_since_license_received),
kTimeTolerance); kTimeTolerance);
@@ -5485,7 +5485,7 @@ TEST_F(UsageTableTest, VerifyUsageTimes) {
ASSERT_NO_FATAL_FAILURE(DeactivatePST(pst)); ASSERT_NO_FATAL_FAILURE(DeactivatePST(pst));
ASSERT_NO_FATAL_FAILURE(s.GenerateReport(pst)); ASSERT_NO_FATAL_FAILURE(s.GenerateReport(pst));
EXPECT_EQ(kInactive, s.pst_report()->status); EXPECT_EQ(kInactiveUsed, s.pst_report()->status);
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(
s.TestDecryptCTR(false, OEMCrypto_ERROR_UNKNOWN_FAILURE)); s.TestDecryptCTR(false, OEMCrypto_ERROR_UNKNOWN_FAILURE));
} }
@@ -5538,7 +5538,7 @@ TEST_F(UsageTableTest, PSTLargeBuffer) {
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(
s.TestDecryptCTR(false, OEMCrypto_ERROR_UNKNOWN_FAILURE)); s.TestDecryptCTR(false, OEMCrypto_ERROR_UNKNOWN_FAILURE));
ASSERT_NO_FATAL_FAILURE(s.GenerateReport(pst)); ASSERT_NO_FATAL_FAILURE(s.GenerateReport(pst));
EXPECT_EQ(kInactive, s.pst_report()->status); EXPECT_EQ(kInactiveUsed, s.pst_report()->status);
EXPECT_NEAR(0, EXPECT_NEAR(0,
wvcdm::htonll64(s.pst_report()->seconds_since_license_received), wvcdm::htonll64(s.pst_report()->seconds_since_license_received),
kTimeTolerance); kTimeTolerance);
@@ -5561,7 +5561,7 @@ TEST_F(UsageTableTest, PSTLargeBuffer) {
Session s3; Session s3;
ASSERT_NO_FATAL_FAILURE(s3.open()); ASSERT_NO_FATAL_FAILURE(s3.open());
ASSERT_NO_FATAL_FAILURE(s3.GenerateReport(pst, true, &s)); ASSERT_NO_FATAL_FAILURE(s3.GenerateReport(pst, true, &s));
EXPECT_EQ(kInactive, s3.pst_report()->status); EXPECT_EQ(kInactiveUsed, s3.pst_report()->status);
} }
TEST_F(UsageTableTest, DeleteEntryLargeBuffer) { TEST_F(UsageTableTest, DeleteEntryLargeBuffer) {