Fixes for query information and usage reporting
* The Usage APIs return usage reports from either L1 or L3 (if available). * Correction to when usage reports are saved. In addition to other events they are now saved when keys are loaded, usage reports are released and soon after first decryption and periodically (60 seconds) after that, if decryption takes place. * Usage reports now get deleted on an unprovision request. * Policy timer is now started when offline licenses are restored. * Usage session is now released, when a usage response is received. * Usage tests ahev been enabled. * Added CDM extended duration (integration) tests to test usage reporting and querying. These need to be run manually as they take a while (currently half an hour). b/15592374 [ Merge of https://widevine-internal-review.googlesource.com/#/c/10800 from the Widevine CDM repo ] Change-Id: Ia817e03ebbe880e08ba7b4a235ecb82b3ff35fbf
This commit is contained in:
@@ -421,10 +421,19 @@ CdmResponseType CryptoSession::LoadKeys(
|
||||
provider_session_token.length());
|
||||
|
||||
if (OEMCrypto_SUCCESS == sts) {
|
||||
if (!provider_session_token.empty()) {
|
||||
sts = OEMCrypto_UpdateUsageTable();
|
||||
if (sts != OEMCrypto_SUCCESS) {
|
||||
LOGW("CryptoSession::LoadKeys: OEMCrypto_UpdateUsageTable error=%ld",
|
||||
sts);
|
||||
}
|
||||
}
|
||||
return KEY_ADDED;
|
||||
} else if (OEMCrypto_ERROR_TOO_MANY_KEYS == sts) {
|
||||
LOGE("CryptoSession::LoadKeys: OEMCrypto_LoadKeys error=%d", sts);
|
||||
return INSUFFICIENT_CRYPTO_RESOURCES;
|
||||
} else {
|
||||
LOGE("CryptoSession::LoadKeys: OEMCrypto_LoadKeys error=%d", sts);
|
||||
return KEY_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -439,7 +448,7 @@ bool CryptoSession::LoadCertificatePrivateKey(std::string& wrapped_key) {
|
||||
wrapped_key.size());
|
||||
|
||||
if (OEMCrypto_SUCCESS != sts) {
|
||||
LOGD("LoadCertificatePrivateKey: OEMCrypto_LoadDeviceRSAKey error=%d", sts);
|
||||
LOGE("LoadCertificatePrivateKey: OEMCrypto_LoadDeviceRSAKey error=%d", sts);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -509,7 +518,7 @@ bool CryptoSession::GenerateDerivedKeys(const std::string& message) {
|
||||
enc_deriv_message.size());
|
||||
|
||||
if (OEMCrypto_SUCCESS != sts) {
|
||||
LOGD("GenerateDerivedKeys: OEMCrypto_GenerateDerivedKeys error=%d", sts);
|
||||
LOGE("GenerateDerivedKeys: OEMCrypto_GenerateDerivedKeys error=%d", sts);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -533,7 +542,7 @@ bool CryptoSession::GenerateDerivedKeys(const std::string& message,
|
||||
enc_deriv_message.size());
|
||||
|
||||
if (OEMCrypto_SUCCESS != sts) {
|
||||
LOGD("GenerateDerivedKeys: OEMCrypto_DeriveKeysFromSessionKey err=%d", sts);
|
||||
LOGE("GenerateDerivedKeys: OEMCrypto_DeriveKeysFromSessionKey err=%d", sts);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -554,7 +563,7 @@ bool CryptoSession::GenerateSignature(const std::string& message,
|
||||
|
||||
if (OEMCrypto_SUCCESS != sts) {
|
||||
if (OEMCrypto_ERROR_SHORT_BUFFER != sts) {
|
||||
LOGD("GenerateSignature: OEMCrypto_GenerateSignature err=%d", sts);
|
||||
LOGE("GenerateSignature: OEMCrypto_GenerateSignature err=%d", sts);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -567,7 +576,7 @@ bool CryptoSession::GenerateSignature(const std::string& message,
|
||||
&length);
|
||||
|
||||
if (OEMCrypto_SUCCESS != sts) {
|
||||
LOGD("GenerateSignature: OEMCrypto_GenerateSignature err=%d", sts);
|
||||
LOGE("GenerateSignature: OEMCrypto_GenerateSignature err=%d", sts);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -593,7 +602,7 @@ bool CryptoSession::GenerateRsaSignature(const std::string& message,
|
||||
|
||||
if (OEMCrypto_SUCCESS != sts) {
|
||||
if (OEMCrypto_ERROR_SHORT_BUFFER != sts) {
|
||||
LOGD("GenerateRsaSignature: OEMCrypto_GenerateRSASignature err=%d", sts);
|
||||
LOGE("GenerateRsaSignature: OEMCrypto_GenerateRSASignature err=%d", sts);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -606,7 +615,7 @@ bool CryptoSession::GenerateRsaSignature(const std::string& message,
|
||||
&length, kSign_RSASSA_PSS);
|
||||
|
||||
if (OEMCrypto_SUCCESS != sts) {
|
||||
LOGD("GenerateRsaSignature: OEMCrypto_GenerateRSASignature err=%d", sts);
|
||||
LOGE("GenerateRsaSignature: OEMCrypto_GenerateRSASignature err=%d", sts);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -774,10 +783,32 @@ CdmResponseType CryptoSession::GenerateUsageReport(
|
||||
*usage_duration_status = kUsageDurationPlaybackNotBegun;
|
||||
return NO_ERROR;
|
||||
}
|
||||
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);
|
||||
LOGV("OEMCrypto_PST_Report.seconds_since_license_received: %lld\n",
|
||||
ntohll64(pst_report.seconds_since_license_received));
|
||||
LOGV("OEMCrypto_PST_Report.seconds_since_first_decrypt: %lld\n",
|
||||
ntohll64(pst_report.seconds_since_first_decrypt));
|
||||
LOGV("OEMCrypto_PST_Report.seconds_since_last_decrypt: %lld\n",
|
||||
ntohll64(pst_report.seconds_since_last_decrypt));
|
||||
LOGV("OEMCrypto_PST_Report: %s\n", b2a_hex(*usage_report).c_str());
|
||||
|
||||
// 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))) {
|
||||
*usage_duration_status = kUsageDurationPlaybackNotBegun;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
*usage_duration_status = kUsageDurationsValid;
|
||||
*seconds_since_started = pst_report.seconds_since_first_decrypt;
|
||||
*seconds_since_last_played = pst_report.seconds_since_last_decrypt;
|
||||
*seconds_since_started = ntohll64(pst_report.seconds_since_first_decrypt);
|
||||
*seconds_since_last_played = ntohll64(pst_report.seconds_since_last_decrypt);
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -799,6 +830,31 @@ CdmResponseType CryptoSession::ReleaseUsageInformation(
|
||||
status);
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
status = OEMCrypto_UpdateUsageTable();
|
||||
if (status != OEMCrypto_SUCCESS) {
|
||||
LOGW("CryptoSession::ReleaseUsageInformation: OEMCrypto_UpdateUsageTable: "
|
||||
"error=%ld",
|
||||
status);
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
CdmResponseType CryptoSession::DeleteAllUsageReports() {
|
||||
LOGV("DeleteAllUsageReports");
|
||||
OEMCryptoResult status = OEMCrypto_DeleteUsageTable();
|
||||
|
||||
if (OEMCrypto_SUCCESS != status) {
|
||||
LOGE("CryptoSession::DeleteAllUsageReports: Delete Usage Table error =%ld",
|
||||
status);
|
||||
}
|
||||
|
||||
status = OEMCrypto_UpdateUsageTable();
|
||||
if (status != OEMCrypto_SUCCESS) {
|
||||
LOGE("CryptoSession::ReleaseUsageInformation: OEMCrypto_UpdateUsageTable: "
|
||||
"error=%ld",
|
||||
status);
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
@@ -840,7 +896,7 @@ bool CryptoSession::RewrapDeviceRSAKey(const std::string& message,
|
||||
const std::string& enc_rsa_key,
|
||||
const std::string& rsa_key_iv,
|
||||
std::string* wrapped_rsa_key) {
|
||||
LOGD("CryptoSession::RewrapDeviceRSAKey, session id=%ld",
|
||||
LOGV("CryptoSession::RewrapDeviceRSAKey, session id=%ld",
|
||||
static_cast<uint32_t>(oec_session_id_));
|
||||
|
||||
const uint8_t* signed_msg = reinterpret_cast<const uint8_t*>(message.data());
|
||||
|
||||
Reference in New Issue
Block a user