Run clang-format on Core
This copies over formatting changes from the Widevine CDM repository that resulted from running clang-format with Google style on the shared core/ directory. It also copies over some rewordings of log messages that were made at the same time. Aside from the changed log messages, this should not affect behavior or functionality. Change-Id: I69c57c188f7a79f30fa3517afeed17365929b6b6
This commit is contained in:
@@ -17,7 +17,8 @@ bool BufferReader::Read1(uint8_t* v) {
|
||||
}
|
||||
|
||||
// Internal implementation of multi-byte reads
|
||||
template<typename T> bool BufferReader::Read(T* v) {
|
||||
template <typename T>
|
||||
bool BufferReader::Read(T* v) {
|
||||
if (!HasBytes(sizeof(T))) {
|
||||
LOGW("BufferReader::Read<T> : Failure during parse: Not enough bytes (%u)",
|
||||
sizeof(T));
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
#include "wv_cdm_event_listener.h"
|
||||
|
||||
namespace {
|
||||
const uint32_t kUpdateUsageInformationPeriod = 60; // seconds
|
||||
const size_t kUsageReportsPerRequest = 1;
|
||||
const uint32_t kUpdateUsageInformationPeriod = 60; // seconds
|
||||
const size_t kUsageReportsPerRequest = 1;
|
||||
} // unnamed namespace
|
||||
|
||||
namespace wvcdm {
|
||||
@@ -77,10 +77,9 @@ CdmEngine::~CdmEngine() {
|
||||
sessions_.clear();
|
||||
}
|
||||
|
||||
CdmResponseType CdmEngine::OpenSession(
|
||||
const CdmKeySystem& key_system,
|
||||
const CdmClientPropertySet* property_set,
|
||||
CdmSessionId* session_id) {
|
||||
CdmResponseType CdmEngine::OpenSession(const CdmKeySystem& key_system,
|
||||
const CdmClientPropertySet* property_set,
|
||||
CdmSessionId* session_id) {
|
||||
LOGI("CdmEngine::OpenSession");
|
||||
|
||||
if (!ValidateKeySystem(key_system)) {
|
||||
@@ -116,8 +115,7 @@ CdmResponseType CdmEngine::OpenSession(
|
||||
}
|
||||
|
||||
CdmResponseType CdmEngine::OpenKeySetSession(
|
||||
const CdmKeySetId& key_set_id,
|
||||
const CdmClientPropertySet* property_set) {
|
||||
const CdmKeySetId& key_set_id, const CdmClientPropertySet* property_set) {
|
||||
LOGI("CdmEngine::OpenKeySetSession");
|
||||
|
||||
if (key_set_id.empty()) {
|
||||
@@ -128,8 +126,7 @@ CdmResponseType CdmEngine::OpenKeySetSession(
|
||||
CdmSessionId session_id;
|
||||
CdmResponseType sts = OpenSession(KEY_SYSTEM, property_set, &session_id);
|
||||
|
||||
if (sts != NO_ERROR)
|
||||
return sts;
|
||||
if (sts != NO_ERROR) return sts;
|
||||
|
||||
release_key_sets_[key_set_id] = session_id;
|
||||
return NO_ERROR;
|
||||
@@ -147,8 +144,11 @@ CdmResponseType CdmEngine::CloseSession(const CdmSessionId& session_id) {
|
||||
CdmSession* session = iter->second;
|
||||
sessions_.erase(session_id);
|
||||
// If the event timer is active, it will delete this session when it's done.
|
||||
if (timer_event_active_) dead_sessions_.push_back(session);
|
||||
else delete session;
|
||||
if (timer_event_active_) {
|
||||
dead_sessions_.push_back(session);
|
||||
} else {
|
||||
delete session;
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ CdmResponseType CdmEngine::CloseKeySetSession(const CdmKeySetId& key_set_id) {
|
||||
CdmReleaseKeySetMap::iterator iter = release_key_sets_.find(key_set_id);
|
||||
if (iter == release_key_sets_.end()) {
|
||||
LOGE("CdmEngine::CloseKeySetSession: key set id not found = %s",
|
||||
key_set_id.c_str());
|
||||
key_set_id.c_str());
|
||||
return KEY_ERROR;
|
||||
}
|
||||
|
||||
@@ -168,14 +168,10 @@ CdmResponseType CdmEngine::CloseKeySetSession(const CdmKeySetId& key_set_id) {
|
||||
}
|
||||
|
||||
CdmResponseType CdmEngine::GenerateKeyRequest(
|
||||
const CdmSessionId& session_id,
|
||||
const CdmKeySetId& key_set_id,
|
||||
const InitializationData& init_data,
|
||||
const CdmLicenseType license_type,
|
||||
CdmAppParameterMap& app_parameters,
|
||||
CdmKeyMessage* key_request,
|
||||
std::string* server_url,
|
||||
CdmKeySetId* key_set_id_out) {
|
||||
const CdmSessionId& session_id, const CdmKeySetId& key_set_id,
|
||||
const InitializationData& init_data, const CdmLicenseType license_type,
|
||||
CdmAppParameterMap& app_parameters, CdmKeyMessage* key_request,
|
||||
std::string* server_url, CdmKeySetId* key_set_id_out) {
|
||||
LOGI("CdmEngine::GenerateKeyRequest");
|
||||
|
||||
CdmSessionId id = session_id;
|
||||
@@ -189,14 +185,14 @@ CdmResponseType CdmEngine::GenerateKeyRequest(
|
||||
|
||||
if (!session_id.empty()) {
|
||||
LOGE("CdmEngine::GenerateKeyRequest: invalid session ID = %s",
|
||||
session_id.c_str());
|
||||
session_id.c_str());
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
CdmReleaseKeySetMap::iterator iter = release_key_sets_.find(key_set_id);
|
||||
if (iter == release_key_sets_.end()) {
|
||||
LOGE("CdmEngine::GenerateKeyRequest: key set ID not found = %s",
|
||||
key_set_id.c_str());
|
||||
key_set_id.c_str());
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
@@ -206,7 +202,7 @@ CdmResponseType CdmEngine::GenerateKeyRequest(
|
||||
CdmSessionMap::iterator iter = sessions_.find(id);
|
||||
if (iter == sessions_.end()) {
|
||||
LOGE("CdmEngine::GenerateKeyRequest: session_id not found = %s",
|
||||
id.c_str());
|
||||
id.c_str());
|
||||
return KEY_ERROR;
|
||||
}
|
||||
|
||||
@@ -220,22 +216,24 @@ CdmResponseType CdmEngine::GenerateKeyRequest(
|
||||
if (license_type == kLicenseTypeRelease) {
|
||||
sts = iter->second->RestoreOfflineSession(key_set_id, kLicenseTypeRelease);
|
||||
if (sts != KEY_ADDED) {
|
||||
LOGE("CdmEngine::GenerateKeyRequest: key release restoration failed,"
|
||||
LOGE(
|
||||
"CdmEngine::GenerateKeyRequest: key release restoration failed,"
|
||||
"sts = %d", sts);
|
||||
return sts;
|
||||
}
|
||||
}
|
||||
|
||||
sts = iter->second->GenerateKeyRequest(init_data, license_type,
|
||||
app_parameters, key_request,
|
||||
server_url, key_set_id_out);
|
||||
sts =
|
||||
iter->second->GenerateKeyRequest(init_data, license_type, app_parameters,
|
||||
key_request, server_url, key_set_id_out);
|
||||
|
||||
if (KEY_MESSAGE != sts) {
|
||||
if (sts == NEED_PROVISIONING) {
|
||||
cert_provisioning_requested_security_level_ =
|
||||
iter->second->GetRequestedSecurityLevel();
|
||||
}
|
||||
LOGE("CdmEngine::GenerateKeyRequest: key request generation failed, "
|
||||
LOGE(
|
||||
"CdmEngine::GenerateKeyRequest: key request generation failed, "
|
||||
"sts = %d", sts);
|
||||
return sts;
|
||||
}
|
||||
@@ -247,10 +245,9 @@ CdmResponseType CdmEngine::GenerateKeyRequest(
|
||||
return KEY_MESSAGE;
|
||||
}
|
||||
|
||||
CdmResponseType CdmEngine::AddKey(
|
||||
const CdmSessionId& session_id,
|
||||
const CdmKeyResponse& key_data,
|
||||
CdmKeySetId* key_set_id) {
|
||||
CdmResponseType CdmEngine::AddKey(const CdmSessionId& session_id,
|
||||
const CdmKeyResponse& key_data,
|
||||
CdmKeySetId* key_set_id) {
|
||||
LOGI("CdmEngine::AddKey");
|
||||
|
||||
CdmSessionId id = session_id;
|
||||
@@ -298,9 +295,8 @@ CdmResponseType CdmEngine::AddKey(
|
||||
return KEY_ADDED;
|
||||
}
|
||||
|
||||
CdmResponseType CdmEngine::RestoreKey(
|
||||
const CdmSessionId& session_id,
|
||||
const CdmKeySetId& key_set_id) {
|
||||
CdmResponseType CdmEngine::RestoreKey(const CdmSessionId& session_id,
|
||||
const CdmKeySetId& key_set_id) {
|
||||
LOGI("CdmEngine::RestoreKey");
|
||||
|
||||
if (key_set_id.empty()) {
|
||||
@@ -311,7 +307,7 @@ CdmResponseType CdmEngine::RestoreKey(
|
||||
CdmSessionMap::iterator iter = sessions_.find(session_id);
|
||||
if (iter == sessions_.end()) {
|
||||
LOGE("CdmEngine::RestoreKey: session_id not found = %s ",
|
||||
session_id.c_str());
|
||||
session_id.c_str());
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
@@ -322,7 +318,7 @@ CdmResponseType CdmEngine::RestoreKey(
|
||||
iter->second->GetRequestedSecurityLevel();
|
||||
}
|
||||
if (KEY_ADDED != sts) {
|
||||
LOGE("CdmEngine::RestoreKey: restore offline session error = %d", sts);
|
||||
LOGE("CdmEngine::RestoreKey: restore offline session failed = %d", sts);
|
||||
}
|
||||
return sts;
|
||||
}
|
||||
@@ -342,8 +338,7 @@ CdmResponseType CdmEngine::RemoveKeys(const CdmSessionId& session_id) {
|
||||
}
|
||||
|
||||
CdmResponseType CdmEngine::GenerateRenewalRequest(
|
||||
const CdmSessionId& session_id,
|
||||
CdmKeyMessage* key_request,
|
||||
const CdmSessionId& session_id, CdmKeyMessage* key_request,
|
||||
std::string* server_url) {
|
||||
LOGI("CdmEngine::GenerateRenewalRequest");
|
||||
|
||||
@@ -361,8 +356,8 @@ CdmResponseType CdmEngine::GenerateRenewalRequest(
|
||||
|
||||
key_request->clear();
|
||||
|
||||
CdmResponseType sts = iter->second->GenerateRenewalRequest(key_request,
|
||||
server_url);
|
||||
CdmResponseType sts =
|
||||
iter->second->GenerateRenewalRequest(key_request, server_url);
|
||||
|
||||
if (KEY_MESSAGE != sts) {
|
||||
LOGE("CdmEngine::GenerateRenewalRequest: key request gen. failed, sts=%d",
|
||||
@@ -373,9 +368,8 @@ CdmResponseType CdmEngine::GenerateRenewalRequest(
|
||||
return KEY_MESSAGE;
|
||||
}
|
||||
|
||||
CdmResponseType CdmEngine::RenewKey(
|
||||
const CdmSessionId& session_id,
|
||||
const CdmKeyResponse& key_data) {
|
||||
CdmResponseType CdmEngine::RenewKey(const CdmSessionId& session_id,
|
||||
const CdmKeyResponse& key_data) {
|
||||
LOGI("CdmEngine::RenewKey");
|
||||
|
||||
CdmSessionMap::iterator iter = sessions_.find(session_id);
|
||||
@@ -470,9 +464,8 @@ CdmResponseType CdmEngine::QuerySessionStatus(const CdmSessionId& session_id,
|
||||
return iter->second->QueryStatus(key_info);
|
||||
}
|
||||
|
||||
CdmResponseType CdmEngine::QueryKeyStatus(
|
||||
const CdmSessionId& session_id,
|
||||
CdmQueryMap* key_info) {
|
||||
CdmResponseType CdmEngine::QueryKeyStatus(const CdmSessionId& session_id,
|
||||
CdmQueryMap* key_info) {
|
||||
LOGI("CdmEngine::QueryKeyStatus");
|
||||
CdmSessionMap::iterator iter = sessions_.find(session_id);
|
||||
if (iter == sessions_.end()) {
|
||||
@@ -483,9 +476,8 @@ CdmResponseType CdmEngine::QueryKeyStatus(
|
||||
return iter->second->QueryKeyStatus(key_info);
|
||||
}
|
||||
|
||||
CdmResponseType CdmEngine::QueryKeyControlInfo(
|
||||
const CdmSessionId& session_id,
|
||||
CdmQueryMap* key_info) {
|
||||
CdmResponseType CdmEngine::QueryKeyControlInfo(const CdmSessionId& session_id,
|
||||
CdmQueryMap* key_info) {
|
||||
LOGI("CdmEngine::QueryKeyControlInfo");
|
||||
CdmSessionMap::iterator iter = sessions_.find(session_id);
|
||||
if (iter == sessions_.end()) {
|
||||
@@ -504,10 +496,8 @@ CdmResponseType CdmEngine::QueryKeyControlInfo(
|
||||
* Returns NO_ERROR for success and UNKNOWN_ERROR if fails.
|
||||
*/
|
||||
CdmResponseType CdmEngine::GetProvisioningRequest(
|
||||
CdmCertificateType cert_type,
|
||||
const std::string& cert_authority,
|
||||
CdmProvisioningRequest* request,
|
||||
std::string* default_url) {
|
||||
CdmCertificateType cert_type, const std::string& cert_authority,
|
||||
CdmProvisioningRequest* request, std::string* default_url) {
|
||||
if (!request || !default_url) {
|
||||
LOGE("CdmEngine::GetProvisioningRequest: invalid input parameters");
|
||||
return UNKNOWN_ERROR;
|
||||
@@ -516,11 +506,8 @@ CdmResponseType CdmEngine::GetProvisioningRequest(
|
||||
cert_provisioning_.reset(new CertificateProvisioning());
|
||||
}
|
||||
CdmResponseType ret = cert_provisioning_->GetProvisioningRequest(
|
||||
cert_provisioning_requested_security_level_,
|
||||
cert_type,
|
||||
cert_authority,
|
||||
request,
|
||||
default_url);
|
||||
cert_provisioning_requested_security_level_, cert_type, cert_authority,
|
||||
request, default_url);
|
||||
if (ret != NO_ERROR) {
|
||||
cert_provisioning_.reset(NULL); // Release resources.
|
||||
}
|
||||
@@ -535,8 +522,7 @@ CdmResponseType CdmEngine::GetProvisioningRequest(
|
||||
* Returns NO_ERROR for success and UNKNOWN_ERROR if fails.
|
||||
*/
|
||||
CdmResponseType CdmEngine::HandleProvisioningResponse(
|
||||
CdmProvisioningResponse& response,
|
||||
std::string* cert,
|
||||
CdmProvisioningResponse& response, std::string* cert,
|
||||
std::string* wrapped_key) {
|
||||
if (response.empty()) {
|
||||
LOGE("CdmEngine::HandleProvisioningResponse: Empty provisioning response.");
|
||||
@@ -544,8 +530,9 @@ CdmResponseType CdmEngine::HandleProvisioningResponse(
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
if (NULL == cert) {
|
||||
LOGE("CdmEngine::HandleProvisioningResponse: invalid certificate "
|
||||
"destination");
|
||||
LOGE(
|
||||
"CdmEngine::HandleProvisioningResponse: invalid certificate "
|
||||
"destination");
|
||||
cert_provisioning_.reset(NULL);
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
@@ -559,9 +546,8 @@ CdmResponseType CdmEngine::HandleProvisioningResponse(
|
||||
LOGE("CdmEngine::HandleProvisioningResponse: provisioning object missing.");
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
CdmResponseType ret =
|
||||
cert_provisioning_->HandleProvisioningResponse(response, cert,
|
||||
wrapped_key);
|
||||
CdmResponseType ret = cert_provisioning_->HandleProvisioningResponse(
|
||||
response, cert, wrapped_key);
|
||||
cert_provisioning_.reset(NULL); // Release resources.
|
||||
return ret;
|
||||
}
|
||||
@@ -664,11 +650,9 @@ CdmResponseType CdmEngine::GetUsageInfo(const std::string& app_id,
|
||||
do {
|
||||
status = GetUsageInfo(app_id, security_level, usage_info);
|
||||
|
||||
if (KEY_MESSAGE == status && !usage_info->empty())
|
||||
return status;
|
||||
if (KEY_MESSAGE == status && !usage_info->empty()) return status;
|
||||
} while (KEY_CANCELED == status);
|
||||
|
||||
|
||||
security_level = (kLevel3 == security_level) ? kLevelDefault : kLevel3;
|
||||
do {
|
||||
status = GetUsageInfo(app_id, security_level, usage_info);
|
||||
@@ -720,13 +704,14 @@ CdmResponseType CdmEngine::GetUsageInfo(const std::string& app_id,
|
||||
status = usage_session_->RestoreUsageSession(license_info[index].first,
|
||||
license_info[index].second);
|
||||
if (KEY_ADDED != status) {
|
||||
LOGE("CdmEngine::GetUsageInfo: restore usage session (%u) error %d",
|
||||
index, status);
|
||||
LOGE("CdmEngine::GetUsageInfo: restore usage session (%d) error %ld", index,
|
||||
status);
|
||||
usage_info->clear();
|
||||
return status;
|
||||
}
|
||||
|
||||
status = usage_session_->GenerateReleaseRequest(&(*usage_info)[0], &server_url);
|
||||
status =
|
||||
usage_session_->GenerateReleaseRequest(&(*usage_info)[0], &server_url);
|
||||
|
||||
switch (status) {
|
||||
case KEY_MESSAGE:
|
||||
@@ -750,11 +735,13 @@ CdmResponseType CdmEngine::ReleaseAllUsageInfo(const std::string& app_id) {
|
||||
for (int i = 0, j = kSecurityLevelL1; j < kSecurityLevelUnknown; ++i, ++j) {
|
||||
if (handle[i].Init(static_cast<CdmSecurityLevel>(j))) {
|
||||
if (!handle[i].DeleteAllUsageInfoForApp(app_id)) {
|
||||
LOGE("CdmEngine::ReleaseAllUsageInfo: failed to delete L%d secure stops", j);
|
||||
LOGE("CdmEngine::ReleaseAllUsageInfo: failed to delete L%d secure"
|
||||
"stops", j);
|
||||
status = UNKNOWN_ERROR;
|
||||
}
|
||||
} else {
|
||||
LOGE("CdmEngine::ReleaseAllUsageInfo: failed to initialize L%d device files", j);
|
||||
LOGE("CdmEngine::ReleaseAllUsageInfo: failed to initialize L%d device"
|
||||
"files", j);
|
||||
status = UNKNOWN_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -776,9 +763,8 @@ CdmResponseType CdmEngine::ReleaseUsageInfo(
|
||||
return status;
|
||||
}
|
||||
|
||||
CdmResponseType CdmEngine::Decrypt(
|
||||
const CdmSessionId& session_id,
|
||||
const CdmDecryptionParameters& parameters) {
|
||||
CdmResponseType CdmEngine::Decrypt(const CdmSessionId& session_id,
|
||||
const CdmDecryptionParameters& parameters) {
|
||||
if (parameters.key_id == NULL) {
|
||||
LOGE("CdmEngine::Decrypt: no key_id");
|
||||
return KEY_ERROR;
|
||||
@@ -799,7 +785,8 @@ CdmResponseType CdmEngine::Decrypt(
|
||||
!Properties::Properties::oem_crypto_use_fifo()) {
|
||||
LOGE("CdmEngine::Decrypt: no dest decrypt buffer");
|
||||
return KEY_ERROR;
|
||||
} // else we must be level 1 direct and we don't need to return a buffer.
|
||||
}
|
||||
// else we must be level 1 direct and we don't need to return a buffer.
|
||||
}
|
||||
|
||||
CdmSessionMap::iterator iter;
|
||||
@@ -815,8 +802,7 @@ CdmResponseType CdmEngine::Decrypt(
|
||||
}
|
||||
if (iter == sessions_.end()) {
|
||||
LOGE("CdmEngine::Decrypt: session not found: id=%s, id size=%d",
|
||||
session_id.c_str(),
|
||||
session_id.size());
|
||||
session_id.c_str(), session_id.size());
|
||||
return KEY_ERROR;
|
||||
}
|
||||
|
||||
@@ -833,9 +819,8 @@ bool CdmEngine::IsKeyLoaded(const KeyId& key_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CdmEngine::FindSessionForKey(
|
||||
const KeyId& key_id,
|
||||
CdmSessionId* session_id) {
|
||||
bool CdmEngine::FindSessionForKey(const KeyId& key_id,
|
||||
CdmSessionId* session_id) {
|
||||
if (NULL == session_id) {
|
||||
LOGE("CdmEngine::FindSessionForKey: session id not provided");
|
||||
return false;
|
||||
@@ -863,9 +848,8 @@ bool CdmEngine::FindSessionForKey(
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CdmEngine::AttachEventListener(
|
||||
const CdmSessionId& session_id,
|
||||
WvCdmEventListener* listener) {
|
||||
bool CdmEngine::AttachEventListener(const CdmSessionId& session_id,
|
||||
WvCdmEventListener* listener) {
|
||||
CdmSessionMap::iterator iter = sessions_.find(session_id);
|
||||
if (iter == sessions_.end()) {
|
||||
return false;
|
||||
@@ -874,9 +858,8 @@ bool CdmEngine::AttachEventListener(
|
||||
return iter->second->AttachEventListener(listener);
|
||||
}
|
||||
|
||||
bool CdmEngine::DetachEventListener(
|
||||
const CdmSessionId& session_id,
|
||||
WvCdmEventListener* listener) {
|
||||
bool CdmEngine::DetachEventListener(const CdmSessionId& session_id,
|
||||
WvCdmEventListener* listener) {
|
||||
CdmSessionMap::iterator iter = sessions_.find(session_id);
|
||||
if (iter == sessions_.end()) {
|
||||
return false;
|
||||
@@ -964,7 +947,6 @@ void CdmEngine::OnTimerEvent() {
|
||||
}
|
||||
|
||||
void CdmEngine::OnKeyReleaseEvent(const CdmKeySetId& key_set_id) {
|
||||
|
||||
for (CdmSessionMap::iterator iter = sessions_.begin();
|
||||
iter != sessions_.end(); ++iter) {
|
||||
iter->second->OnKeyReleaseEvent(key_set_id);
|
||||
|
||||
@@ -31,22 +31,18 @@ CdmSession::CdmSession(const CdmClientPropertySet* cdm_client_property_set) {
|
||||
new DeviceFiles(), cdm_client_property_set);
|
||||
}
|
||||
|
||||
CdmSession::CdmSession(
|
||||
CdmLicense* license_parser,
|
||||
CryptoSession* crypto_session,
|
||||
PolicyEngine* policy_engine,
|
||||
DeviceFiles* file_handle,
|
||||
const CdmClientPropertySet* cdm_client_property_set) {
|
||||
CdmSession::CdmSession(CdmLicense* license_parser,
|
||||
CryptoSession* crypto_session,
|
||||
PolicyEngine* policy_engine, DeviceFiles* file_handle,
|
||||
const CdmClientPropertySet* cdm_client_property_set) {
|
||||
Create(license_parser, crypto_session, policy_engine, file_handle,
|
||||
cdm_client_property_set);
|
||||
}
|
||||
|
||||
void CdmSession::Create(
|
||||
CdmLicense* license_parser,
|
||||
CryptoSession* crypto_session,
|
||||
PolicyEngine* policy_engine,
|
||||
DeviceFiles* file_handle,
|
||||
const CdmClientPropertySet* cdm_client_property_set) {
|
||||
void CdmSession::Create(CdmLicense* license_parser,
|
||||
CryptoSession* crypto_session,
|
||||
PolicyEngine* policy_engine, DeviceFiles* file_handle,
|
||||
const CdmClientPropertySet* cdm_client_property_set) {
|
||||
// Just return on failures. Failures will be signaled in Init.
|
||||
if (NULL == license_parser) {
|
||||
LOGE("CdmSession::Create: License parser not provided");
|
||||
@@ -80,8 +76,8 @@ void CdmSession::Create(
|
||||
if (cdm_client_property_set) {
|
||||
Properties::AddSessionPropertySet(session_id_, cdm_client_property_set);
|
||||
}
|
||||
security_level_ = GetRequestedSecurityLevel() == kLevel3
|
||||
? kSecurityLevelL3 : GetSecurityLevel();
|
||||
security_level_ = GetRequestedSecurityLevel() == kLevel3 ? kSecurityLevelL3
|
||||
: GetSecurityLevel();
|
||||
app_id_.clear();
|
||||
}
|
||||
|
||||
@@ -126,21 +122,17 @@ CdmResponseType CdmSession::RestoreOfflineSession(
|
||||
key_set_id_ = key_set_id;
|
||||
|
||||
// Retrieve license information from persistent store
|
||||
if (!file_handle_->Reset(security_level_))
|
||||
return UNKNOWN_ERROR;
|
||||
if (!file_handle_->Reset(security_level_)) return UNKNOWN_ERROR;
|
||||
|
||||
DeviceFiles::LicenseState license_state;
|
||||
int64_t playback_start_time;
|
||||
int64_t last_playback_time;
|
||||
|
||||
if (!file_handle_->RetrieveLicense(key_set_id, &license_state,
|
||||
&offline_init_data_,
|
||||
&key_request_, &key_response_,
|
||||
&offline_key_renewal_request_,
|
||||
&offline_key_renewal_response_,
|
||||
&offline_release_server_url_,
|
||||
&playback_start_time,
|
||||
&last_playback_time)) {
|
||||
if (!file_handle_->RetrieveLicense(
|
||||
key_set_id, &license_state, &offline_init_data_, &key_request_,
|
||||
&key_response_, &offline_key_renewal_request_,
|
||||
&offline_key_renewal_response_, &offline_release_server_url_,
|
||||
&playback_start_time, &last_playback_time)) {
|
||||
LOGE("CdmSession::Init failed to retrieve license. key set id = %s",
|
||||
key_set_id.c_str());
|
||||
return UNKNOWN_ERROR;
|
||||
@@ -148,10 +140,9 @@ CdmResponseType CdmSession::RestoreOfflineSession(
|
||||
|
||||
// Do not restore a released offline license, unless a release retry
|
||||
if (!(license_type == kLicenseTypeRelease ||
|
||||
license_state == DeviceFiles::kLicenseStateActive)) {
|
||||
license_state == DeviceFiles::kLicenseStateActive)) {
|
||||
LOGE("CdmSession::Init invalid offline license state = %d, type = %d",
|
||||
license_state,
|
||||
license_type);
|
||||
license_state, license_type);
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
@@ -161,10 +152,9 @@ CdmResponseType CdmSession::RestoreOfflineSession(
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
} else {
|
||||
if (!license_parser_->RestoreOfflineLicense(key_request_, key_response_,
|
||||
offline_key_renewal_response_,
|
||||
playback_start_time,
|
||||
last_playback_time)) {
|
||||
if (!license_parser_->RestoreOfflineLicense(
|
||||
key_request_, key_response_, offline_key_renewal_response_,
|
||||
playback_start_time, last_playback_time)) {
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -176,8 +166,7 @@ CdmResponseType CdmSession::RestoreOfflineSession(
|
||||
}
|
||||
|
||||
CdmResponseType CdmSession::RestoreUsageSession(
|
||||
const CdmKeyMessage& key_request,
|
||||
const CdmKeyResponse& key_response) {
|
||||
const CdmKeyMessage& key_request, const CdmKeyResponse& key_response) {
|
||||
key_request_ = key_request;
|
||||
key_response_ = key_response;
|
||||
|
||||
@@ -206,9 +195,15 @@ CdmResponseType CdmSession::GenerateKeyRequest(
|
||||
}
|
||||
|
||||
switch (license_type) {
|
||||
case kLicenseTypeStreaming: is_offline_ = false; break;
|
||||
case kLicenseTypeOffline: is_offline_ = true; break;
|
||||
case kLicenseTypeRelease: is_release_ = true; break;
|
||||
case kLicenseTypeStreaming:
|
||||
is_offline_ = false;
|
||||
break;
|
||||
case kLicenseTypeOffline:
|
||||
is_offline_ = true;
|
||||
break;
|
||||
case kLicenseTypeRelease:
|
||||
is_release_ = true;
|
||||
break;
|
||||
default:
|
||||
LOGE("CdmSession::GenerateKeyRequest: unrecognized license type: %ld",
|
||||
license_type);
|
||||
@@ -352,7 +347,7 @@ CdmResponseType CdmSession::Decrypt(const CdmDecryptionParameters& params) {
|
||||
CdmResponseType status = crypto_session_->Decrypt(params);
|
||||
|
||||
switch (status) {
|
||||
case NO_ERROR:
|
||||
case NO_ERROR: {
|
||||
if (is_initial_decryption_) {
|
||||
policy_engine_->BeginDecryption();
|
||||
is_initial_decryption_ = false;
|
||||
@@ -360,9 +355,10 @@ CdmResponseType CdmSession::Decrypt(const CdmDecryptionParameters& params) {
|
||||
has_decrypted_recently_ = true;
|
||||
if (!is_usage_update_needed_) {
|
||||
is_usage_update_needed_ =
|
||||
!license_parser_->provider_session_token().empty();
|
||||
!license_parser_->provider_session_token().empty();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case UNKNOWN_ERROR: {
|
||||
Clock clock;
|
||||
int64_t current_time = clock.GetCurrentTime();
|
||||
@@ -372,8 +368,9 @@ CdmResponseType CdmSession::Decrypt(const CdmDecryptionParameters& params) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: //Ignore
|
||||
default: { //Ignore
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -387,8 +384,7 @@ CdmResponseType CdmSession::GenerateRenewalRequest(CdmKeyMessage* key_request,
|
||||
CdmResponseType status =
|
||||
license_parser_->PrepareKeyUpdateRequest(true, key_request, server_url);
|
||||
|
||||
if (KEY_MESSAGE != status)
|
||||
return status;
|
||||
if (KEY_MESSAGE != status) return status;
|
||||
|
||||
if (is_offline_) {
|
||||
offline_key_renewal_request_ = *key_request;
|
||||
@@ -415,8 +411,7 @@ CdmResponseType CdmSession::GenerateReleaseRequest(CdmKeyMessage* key_request,
|
||||
CdmResponseType status =
|
||||
license_parser_->PrepareKeyUpdateRequest(false, key_request, server_url);
|
||||
|
||||
if (KEY_MESSAGE != status)
|
||||
return status;
|
||||
if (KEY_MESSAGE != status) return status;
|
||||
|
||||
if (is_offline_) { // Mark license as being released
|
||||
if (!StoreLicense(DeviceFiles::kLicenseStateReleasing))
|
||||
@@ -427,10 +422,9 @@ CdmResponseType CdmSession::GenerateReleaseRequest(CdmKeyMessage* key_request,
|
||||
|
||||
// ReleaseKey() - Accept release response and release license.
|
||||
CdmResponseType CdmSession::ReleaseKey(const CdmKeyResponse& key_response) {
|
||||
CdmResponseType sts = license_parser_->HandleKeyUpdateResponse(false,
|
||||
key_response);
|
||||
if (KEY_ADDED != sts)
|
||||
return sts;
|
||||
CdmResponseType sts =
|
||||
license_parser_->HandleKeyUpdateResponse(false, key_response);
|
||||
if (KEY_ADDED != sts) return sts;
|
||||
|
||||
if (is_offline_ || !license_parser_->provider_session_token().empty()) {
|
||||
DeleteLicense();
|
||||
@@ -456,8 +450,7 @@ bool CdmSession::GenerateKeySetId(CdmKeySetId* key_set_id) {
|
||||
std::vector<uint8_t> random_data(
|
||||
(kKeySetIdLength - sizeof(KEY_SET_ID_PREFIX)) / 2, 0);
|
||||
|
||||
if (!file_handle_->Reset(security_level_))
|
||||
return false;
|
||||
if (!file_handle_->Reset(security_level_)) return false;
|
||||
|
||||
while (key_set_id->empty()) {
|
||||
if (!crypto_session_->GetRandom(random_data.size(), &random_data[0]))
|
||||
@@ -519,14 +512,12 @@ CdmResponseType CdmSession::StoreLicense() {
|
||||
}
|
||||
|
||||
bool CdmSession::StoreLicense(DeviceFiles::LicenseState state) {
|
||||
if (!file_handle_->Reset(security_level_))
|
||||
return false;
|
||||
if (!file_handle_->Reset(security_level_)) return false;
|
||||
|
||||
return file_handle_->StoreLicense(
|
||||
key_set_id_, state, offline_init_data_, key_request_,
|
||||
key_response_, offline_key_renewal_request_,
|
||||
offline_key_renewal_response_, offline_release_server_url_,
|
||||
policy_engine_->GetPlaybackStartTime(),
|
||||
key_set_id_, state, offline_init_data_, key_request_, key_response_,
|
||||
offline_key_renewal_request_, offline_key_renewal_response_,
|
||||
offline_release_server_url_, policy_engine_->GetPlaybackStartTime(),
|
||||
policy_engine_->GetLastPlaybackTime());
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ namespace {
|
||||
// The provisioning server supplies the certificate that is needed
|
||||
// to communicate with the License Server.
|
||||
const std::string kProvisioningServerUrl =
|
||||
"https://www.googleapis.com/"
|
||||
"certificateprovisioning/v1/devicecertificates/create"
|
||||
"?key=AIzaSyB-5OLKTx2iU5mko18DfdwK5611JIjbUhE";
|
||||
"https://www.googleapis.com/"
|
||||
"certificateprovisioning/v1/devicecertificates/create"
|
||||
"?key=AIzaSyB-5OLKTx2iU5mko18DfdwK5611JIjbUhE";
|
||||
}
|
||||
|
||||
namespace wvcdm {
|
||||
@@ -41,9 +41,7 @@ using video_widevine_server::sdk::SignedProvisioningMessage;
|
||||
* base64 encoded message
|
||||
*/
|
||||
void CertificateProvisioning::ComposeJsonRequestAsQueryString(
|
||||
const std::string& message,
|
||||
CdmProvisioningRequest* request) {
|
||||
|
||||
const std::string& message, CdmProvisioningRequest* request) {
|
||||
// Performs base64 encoding for message
|
||||
std::vector<uint8_t> message_vector(message.begin(), message.end());
|
||||
std::string message_b64 = Base64SafeEncodeNoPad(message_vector);
|
||||
@@ -58,10 +56,8 @@ void CertificateProvisioning::ComposeJsonRequestAsQueryString(
|
||||
* Returns NO_ERROR for success and UNKNOWN_ERROR if fails.
|
||||
*/
|
||||
CdmResponseType CertificateProvisioning::GetProvisioningRequest(
|
||||
SecurityLevel requested_security_level,
|
||||
CdmCertificateType cert_type,
|
||||
const std::string& cert_authority,
|
||||
CdmProvisioningRequest* request,
|
||||
SecurityLevel requested_security_level, CdmCertificateType cert_type,
|
||||
const std::string& cert_authority, CdmProvisioningRequest* request,
|
||||
std::string* default_url) {
|
||||
if (!default_url) {
|
||||
LOGE("GetProvisioningRequest: pointer for returning URL is NULL");
|
||||
@@ -123,7 +119,7 @@ CdmResponseType CertificateProvisioning::GetProvisioningRequest(
|
||||
// Derives signing and encryption keys and constructs signature.
|
||||
std::string request_signature;
|
||||
if (!crypto_session_.PrepareRequest(serialized_message, true,
|
||||
&request_signature)) {
|
||||
&request_signature)) {
|
||||
LOGE("GetProvisioningRequest: fails to prepare request");
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
@@ -152,10 +148,8 @@ CdmResponseType CertificateProvisioning::GetProvisioningRequest(
|
||||
* Returns true for success and false if fails.
|
||||
*/
|
||||
bool CertificateProvisioning::ParseJsonResponse(
|
||||
const CdmProvisioningResponse& json_str,
|
||||
const std::string& start_substr,
|
||||
const std::string& end_substr,
|
||||
std::string* result) {
|
||||
const CdmProvisioningResponse& json_str, const std::string& start_substr,
|
||||
const std::string& end_substr, std::string* result) {
|
||||
std::string b64_string;
|
||||
size_t start = json_str.find(start_substr);
|
||||
if (start == json_str.npos) {
|
||||
@@ -186,10 +180,8 @@ bool CertificateProvisioning::ParseJsonResponse(
|
||||
* Returns NO_ERROR for success and UNKNOWN_ERROR if fails.
|
||||
*/
|
||||
CdmResponseType CertificateProvisioning::HandleProvisioningResponse(
|
||||
CdmProvisioningResponse& response,
|
||||
std::string* cert,
|
||||
CdmProvisioningResponse& response, std::string* cert,
|
||||
std::string* wrapped_key) {
|
||||
|
||||
// Extracts signed response from JSON string, decodes base64 signed response
|
||||
const std::string kMessageStart = "\"signedResponse\": \"";
|
||||
const std::string kMessageEnd = "\"";
|
||||
@@ -220,8 +212,7 @@ CdmResponseType CertificateProvisioning::HandleProvisioningResponse(
|
||||
error = true;
|
||||
}
|
||||
|
||||
if (error)
|
||||
return UNKNOWN_ERROR;
|
||||
if (error) return UNKNOWN_ERROR;
|
||||
|
||||
const std::string& signed_message = signed_response.message();
|
||||
ProvisioningResponse provisioning_response;
|
||||
@@ -241,12 +232,9 @@ CdmResponseType CertificateProvisioning::HandleProvisioningResponse(
|
||||
const std::string& rsa_key_iv = provisioning_response.device_rsa_key_iv();
|
||||
const std::string& signature = signed_response.signature();
|
||||
std::string wrapped_rsa_key;
|
||||
if (!crypto_session_.RewrapDeviceRSAKey(signed_message,
|
||||
signature,
|
||||
nonce,
|
||||
enc_rsa_key,
|
||||
rsa_key_iv,
|
||||
&wrapped_rsa_key)){
|
||||
if (!crypto_session_.RewrapDeviceRSAKey(signed_message, signature, nonce,
|
||||
enc_rsa_key, rsa_key_iv,
|
||||
&wrapped_rsa_key)) {
|
||||
LOGE("HandleProvisioningResponse: RewrapDeviceRSAKey fails");
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
@@ -245,16 +245,16 @@ CdmResponseType CryptoSession::Open(SecurityLevel requested_security_level) {
|
||||
OEMCryptoResult sts = OEMCrypto_OpenSession(&sid, requested_security_level);
|
||||
if (OEMCrypto_SUCCESS == sts) {
|
||||
oec_session_id_ = static_cast<CryptoSessionId>(sid);
|
||||
LOGV("OpenSession: id= %d", (uint32_t)oec_session_id_);
|
||||
LOGV("OpenSession: id= %ld", (uint32_t)oec_session_id_);
|
||||
open_ = true;
|
||||
} else if (OEMCrypto_ERROR_TOO_MANY_SESSIONS == sts) {
|
||||
LOGE("OEMCrypto_Open failed: %d, open sessions: %ld, initialized: %d",
|
||||
sts, session_count_, (int)initialized_);
|
||||
LOGE("OEMCrypto_Open failed: %d, open sessions: %ld, initialized: %d", sts,
|
||||
session_count_, (int)initialized_);
|
||||
return INSUFFICIENT_CRYPTO_RESOURCES;
|
||||
}
|
||||
if (!open_) {
|
||||
LOGE("OEMCrypto_Open failed: %d, open sessions: %ld, initialized: %d",
|
||||
sts, session_count_, (int)initialized_);
|
||||
LOGE("OEMCrypto_Open failed: %d, open sessions: %ld, initialized: %d", sts,
|
||||
session_count_, (int)initialized_);
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
@@ -432,7 +432,7 @@ CdmResponseType CryptoSession::LoadKeys(
|
||||
sts = OEMCrypto_UpdateUsageTable();
|
||||
if (sts != OEMCrypto_SUCCESS) {
|
||||
LOGW("CryptoSession::LoadKeys: OEMCrypto_UpdateUsageTable error=%ld",
|
||||
sts);
|
||||
sts);
|
||||
}
|
||||
}
|
||||
return KEY_ADDED;
|
||||
@@ -604,8 +604,8 @@ bool CryptoSession::GenerateRsaSignature(const std::string& message,
|
||||
OEMCryptoResult sts = OEMCrypto_GenerateRSASignature(
|
||||
oec_session_id_, reinterpret_cast<const uint8_t*>(message.data()),
|
||||
message.size(),
|
||||
reinterpret_cast<uint8_t*>(const_cast<char*>(signature->data())),
|
||||
&length, kSign_RSASSA_PSS);
|
||||
reinterpret_cast<uint8_t*>(const_cast<char*>(signature->data())), &length,
|
||||
kSign_RSASSA_PSS);
|
||||
|
||||
if (OEMCrypto_SUCCESS != sts) {
|
||||
if (OEMCrypto_ERROR_SHORT_BUFFER != sts) {
|
||||
@@ -723,18 +723,15 @@ CdmResponseType CryptoSession::DeactivateUsageInformation(
|
||||
OEMCryptoResult status =
|
||||
OEMCrypto_DeactivateUsageEntry(pst, provider_session_token.length());
|
||||
|
||||
switch(status) {
|
||||
switch (status) {
|
||||
case OEMCrypto_SUCCESS:
|
||||
return NO_ERROR;
|
||||
case OEMCrypto_ERROR_INVALID_CONTEXT:
|
||||
LOGE("CryptoSession::DeactivateUsageInformation: Deactivate Usage Entry "
|
||||
" invalid context error");
|
||||
LOGE("CryptoSession::DeactivateUsageInformation: invalid context error");
|
||||
return KEY_CANCELED;
|
||||
default:
|
||||
LOGE("CryptoSession::DeactivateUsageInformation: Deactivate Usage Entry "
|
||||
" error=%ld",
|
||||
status);
|
||||
return UNKNOWN_ERROR;
|
||||
LOGE("CryptoSession::DeactivateUsageInformation: error=%ld", status);
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -754,15 +751,14 @@ CdmResponseType CryptoSession::GenerateUsageReport(
|
||||
const_cast<char*>(provider_session_token.data()));
|
||||
|
||||
size_t usage_length = 0;
|
||||
OEMCryptoResult status =
|
||||
OEMCrypto_ReportUsage(oec_session_id_, pst,
|
||||
provider_session_token.length(), NULL,
|
||||
&usage_length);
|
||||
OEMCryptoResult status = OEMCrypto_ReportUsage(
|
||||
oec_session_id_, pst, provider_session_token.length(), NULL,
|
||||
&usage_length);
|
||||
|
||||
if (OEMCrypto_SUCCESS != status) {
|
||||
if (OEMCrypto_ERROR_SHORT_BUFFER != status) {
|
||||
LOGE("CryptoSession::GenerateUsageReport: Report Usage error=%ld",
|
||||
status);
|
||||
status);
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -787,7 +783,7 @@ CdmResponseType CryptoSession::GenerateUsageReport(
|
||||
*usage_duration_status = kUsageDurationsInvalid;
|
||||
if (usage_length < sizeof(pst_report)) {
|
||||
LOGE("CryptoSession::GenerateUsageReport: usage report too small=%ld",
|
||||
usage_length);
|
||||
usage_length);
|
||||
return NO_ERROR; // usage report available but no duration information
|
||||
}
|
||||
|
||||
@@ -798,15 +794,15 @@ CdmResponseType CryptoSession::GenerateUsageReport(
|
||||
}
|
||||
LOGV("OEMCrypto_PST_Report.status: %d\n", pst_report.status);
|
||||
LOGV("OEMCrypto_PST_Report.clock_security_level: %d\n",
|
||||
pst_report.clock_security_level);
|
||||
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));
|
||||
ntohll64(pst_report.seconds_since_license_received));
|
||||
LOGV("OEMCrypto_PST_Report.seconds_since_first_decrypt: %lld\n",
|
||||
ntohll64(pst_report.seconds_since_first_decrypt));
|
||||
ntohll64(pst_report.seconds_since_first_decrypt));
|
||||
LOGV("OEMCrypto_PST_Report.seconds_since_last_decrypt: %lld\n",
|
||||
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());
|
||||
|
||||
// When usage report state is inactive, we have to deduce whether the
|
||||
@@ -845,9 +841,8 @@ CdmResponseType CryptoSession::ReleaseUsageInformation(
|
||||
}
|
||||
status = OEMCrypto_UpdateUsageTable();
|
||||
if (status != OEMCrypto_SUCCESS) {
|
||||
LOGW("CryptoSession::ReleaseUsageInformation: OEMCrypto_UpdateUsageTable: "
|
||||
"error=%ld",
|
||||
status);
|
||||
LOGW("CryptoSession::ReleaseUsageInformation: update table error=%ld",
|
||||
status);
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
@@ -864,9 +859,8 @@ CdmResponseType CryptoSession::DeleteAllUsageReports() {
|
||||
|
||||
status = OEMCrypto_UpdateUsageTable();
|
||||
if (status != OEMCrypto_SUCCESS) {
|
||||
LOGE("CryptoSession::ReleaseUsageInformation: OEMCrypto_UpdateUsageTable: "
|
||||
"error=%ld",
|
||||
status);
|
||||
LOGE("CryptoSession::DeletaAllUsageReports: update table error=%ld",
|
||||
status);
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
@@ -954,9 +948,8 @@ bool CryptoSession::RewrapDeviceRSAKey(const std::string& message,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CryptoSession::GetHdcpCapabilities(
|
||||
OemCryptoHdcpVersion* current_version,
|
||||
OemCryptoHdcpVersion* max_version) {
|
||||
bool CryptoSession::GetHdcpCapabilities(OemCryptoHdcpVersion* current_version,
|
||||
OemCryptoHdcpVersion* max_version) {
|
||||
LOGV("GetHdcpCapabilities: id=%ld", (uint32_t)oec_session_id_);
|
||||
if (!initialized_) return UNKNOWN_ERROR;
|
||||
OEMCrypto_HDCP_Capability current, max;
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
#include "device_files.h"
|
||||
|
||||
#if defined(__APPLE__)
|
||||
# include <CommonCrypto/CommonDigest.h>
|
||||
# define SHA256 CC_SHA256
|
||||
# define SHA256_DIGEST_LENGTH CC_SHA256_DIGEST_LENGTH
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
#define SHA256 CC_SHA256
|
||||
#define SHA256_DIGEST_LENGTH CC_SHA256_DIGEST_LENGTH
|
||||
#else
|
||||
# include <openssl/sha.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/md5.h>
|
||||
#endif
|
||||
|
||||
@@ -49,7 +49,7 @@ bool Hash(const std::string& data, std::string* hash) {
|
||||
hash->resize(SHA256_DIGEST_LENGTH);
|
||||
|
||||
const unsigned char* input =
|
||||
reinterpret_cast<const unsigned char*>(data.data());
|
||||
reinterpret_cast<const unsigned char*>(data.data());
|
||||
unsigned char* output = reinterpret_cast<unsigned char*>(&(*hash)[0]);
|
||||
SHA256(input, data.size(), output);
|
||||
return true;
|
||||
@@ -60,9 +60,10 @@ bool Hash(const std::string& data, std::string* hash) {
|
||||
namespace wvcdm {
|
||||
|
||||
DeviceFiles::DeviceFiles()
|
||||
: file_(NULL), security_level_(kSecurityLevelUninitialized),
|
||||
initialized_(false), test_file_(false) {
|
||||
}
|
||||
: file_(NULL),
|
||||
security_level_(kSecurityLevelUninitialized),
|
||||
initialized_(false),
|
||||
test_file_(false) {}
|
||||
|
||||
DeviceFiles::~DeviceFiles() {
|
||||
if (test_file_) file_.release();
|
||||
@@ -119,8 +120,7 @@ bool DeviceFiles::RetrieveCertificate(std::string* certificate,
|
||||
}
|
||||
|
||||
std::string serialized_file;
|
||||
if (!RetrieveHashedFile(kCertificateFileName, &serialized_file))
|
||||
return false;
|
||||
if (!RetrieveHashedFile(kCertificateFileName, &serialized_file)) return false;
|
||||
|
||||
video_widevine_client::sdk::File file;
|
||||
if (!file.ParseFromString(serialized_file)) {
|
||||
@@ -200,15 +200,12 @@ bool DeviceFiles::StoreLicense(const std::string& key_set_id,
|
||||
return StoreFileWithHash(file_name.c_str(), serialized_file);
|
||||
}
|
||||
|
||||
bool DeviceFiles::RetrieveLicense(const std::string& key_set_id,
|
||||
LicenseState* state, CdmInitData* pssh_data,
|
||||
CdmKeyMessage* license_request,
|
||||
CdmKeyResponse* license_message,
|
||||
CdmKeyMessage* license_renewal_request,
|
||||
CdmKeyResponse* license_renewal,
|
||||
std::string* release_server_url,
|
||||
int64_t* playback_start_time,
|
||||
int64_t* last_playback_time) {
|
||||
bool DeviceFiles::RetrieveLicense(
|
||||
const std::string& key_set_id, LicenseState* state, CdmInitData* pssh_data,
|
||||
CdmKeyMessage* license_request, CdmKeyResponse* license_message,
|
||||
CdmKeyMessage* license_renewal_request, CdmKeyResponse* license_renewal,
|
||||
std::string* release_server_url, int64_t* playback_start_time,
|
||||
int64_t* last_playback_time) {
|
||||
if (!initialized_) {
|
||||
LOGW("DeviceFiles::RetrieveLicense: not initialized");
|
||||
return false;
|
||||
@@ -368,10 +365,8 @@ bool DeviceFiles::StoreUsageInfo(const std::string& provider_session_token,
|
||||
|
||||
provider_session->set_token(provider_session_token.data(),
|
||||
provider_session_token.size());
|
||||
provider_session->set_license_request(key_request.data(),
|
||||
key_request.size());
|
||||
provider_session->set_license(key_response.data(),
|
||||
key_response.size());
|
||||
provider_session->set_license_request(key_request.data(), key_request.size());
|
||||
provider_session->set_license(key_response.data(), key_response.size());
|
||||
|
||||
file.SerializeToString(&serialized_file);
|
||||
return StoreFileWithHash(file_name.c_str(), serialized_file);
|
||||
@@ -398,15 +393,18 @@ bool DeviceFiles::DeleteUsageInfo(const std::string& app_id,
|
||||
int index = 0;
|
||||
bool found = false;
|
||||
for (; index < usage_info->sessions_size(); ++index) {
|
||||
if (usage_info->sessions(index).token().compare(provider_session_token) == 0) {
|
||||
if (usage_info->sessions(index).token().compare(provider_session_token) ==
|
||||
0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
LOGW("DeviceFiles::DeleteUsageInfo: Unable to find provider session "
|
||||
"token: %s", b2a_hex(provider_session_token).c_str());
|
||||
LOGW(
|
||||
"DeviceFiles::DeleteUsageInfo: Unable to find provider session "
|
||||
"token: %s",
|
||||
b2a_hex(provider_session_token).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -439,7 +437,7 @@ bool DeviceFiles::DeleteAllUsageInfoForApp(const std::string& app_id) {
|
||||
}
|
||||
|
||||
bool DeviceFiles::RetrieveUsageInfo(
|
||||
const std::string &app_id,
|
||||
const std::string& app_id,
|
||||
std::vector<std::pair<CdmKeyMessage, CdmKeyResponse> >* usage_info) {
|
||||
if (!initialized_) {
|
||||
LOGW("DeviceFiles::RetrieveUsageInfo: not initialized");
|
||||
@@ -447,7 +445,8 @@ bool DeviceFiles::RetrieveUsageInfo(
|
||||
}
|
||||
|
||||
if (NULL == usage_info) {
|
||||
LOGW("DeviceFiles::RetrieveUsageInfo: license destination not "
|
||||
LOGW(
|
||||
"DeviceFiles::RetrieveUsageInfo: license destination not "
|
||||
"provided");
|
||||
return false;
|
||||
}
|
||||
@@ -581,24 +580,24 @@ bool DeviceFiles::StoreFileRaw(const char* name,
|
||||
return false;
|
||||
}
|
||||
|
||||
ssize_t bytes = file_->Write(serialized_file.data(),
|
||||
serialized_file.size());
|
||||
ssize_t bytes = file_->Write(serialized_file.data(), serialized_file.size());
|
||||
file_->Close();
|
||||
|
||||
if (bytes != static_cast<ssize_t>(serialized_file.size())) {
|
||||
LOGW("DeviceFiles::StoreFileRaw: write failed: (actual: %d, expected: %d)",
|
||||
bytes,
|
||||
serialized_file.size());
|
||||
LOGW(
|
||||
"DeviceFiles::StoreFileRaw: write failed: (actual: %d, "
|
||||
"expected: %d)",
|
||||
bytes, serialized_file.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
LOGV("DeviceFiles::StoreFileRaw: success: %s (%db)",
|
||||
path.c_str(),
|
||||
serialized_file.size());
|
||||
LOGV("DeviceFiles::StoreFileRaw: success: %s (%db)", path.c_str(),
|
||||
serialized_file.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeviceFiles::RetrieveHashedFile(const char* name, std::string* serialized_file) {
|
||||
bool DeviceFiles::RetrieveHashedFile(const char* name,
|
||||
std::string* serialized_file) {
|
||||
if (!file_.get()) {
|
||||
LOGW("DeviceFiles::RetrieveHashedFile: Invalid file handle");
|
||||
return false;
|
||||
@@ -610,13 +609,15 @@ bool DeviceFiles::RetrieveHashedFile(const char* name, std::string* serialized_f
|
||||
}
|
||||
|
||||
if (!serialized_file) {
|
||||
LOGW("DeviceFiles::RetrieveHashedFile: Unspecified serialized_file parameter");
|
||||
LOGW(
|
||||
"DeviceFiles::RetrieveHashedFile: Unspecified serialized_file "
|
||||
"parameter");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string path;
|
||||
if (!Properties::GetDeviceFilesBasePath(security_level_, &path)) {
|
||||
LOGW("DeviceFiles::StoreFile: Unable to get base path");
|
||||
LOGW("DeviceFiles::StoreFileWithHash: Unable to get base path");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -629,7 +630,8 @@ bool DeviceFiles::RetrieveHashedFile(const char* name, std::string* serialized_f
|
||||
|
||||
ssize_t bytes = file_->FileSize(path);
|
||||
if (bytes <= 0) {
|
||||
LOGW("DeviceFiles::RetrieveHashedFile: File size invalid: %s", path.c_str());
|
||||
LOGW("DeviceFiles::RetrieveHashedFile: File size invalid: %s",
|
||||
path.c_str());
|
||||
// Remove the corrupted file so the caller will not get the same error
|
||||
// when trying to access the file repeatedly, causing the system to stall.
|
||||
file_->Remove(path);
|
||||
@@ -750,8 +752,10 @@ std::string DeviceFiles::GetLicenseFileNameExtension() {
|
||||
}
|
||||
|
||||
std::string DeviceFiles::GetUsageInfoFileName(const std::string& app_id) {
|
||||
if (app_id == "") return std::string(kUsageInfoFileNamePrefix)
|
||||
+ std::string(kUsageInfoFileNameExt);
|
||||
if (app_id == "") {
|
||||
return std::string(kUsageInfoFileNamePrefix) +
|
||||
std::string(kUsageInfoFileNameExt);
|
||||
}
|
||||
std::vector<uint8_t> hash(MD5_DIGEST_LENGTH);
|
||||
const unsigned char* input =
|
||||
reinterpret_cast<const unsigned char*>(app_id.data());
|
||||
|
||||
@@ -27,56 +27,40 @@ std::string kBuildInfoKey = "build_info";
|
||||
std::string kDeviceIdKey = "device_id";
|
||||
std::string kOsVersionKey = "os_version";
|
||||
const unsigned char kServiceCertificateCAPublicKey[] = {
|
||||
0x30, 0x82, 0x01, 0x8a, 0x02, 0x82, 0x01, 0x81,
|
||||
0x00, 0xb4, 0xfe, 0x39, 0xc3, 0x65, 0x90, 0x03,
|
||||
0xdb, 0x3c, 0x11, 0x97, 0x09, 0xe8, 0x68, 0xcd,
|
||||
0xf2, 0xc3, 0x5e, 0x9b, 0xf2, 0xe7, 0x4d, 0x23,
|
||||
0xb1, 0x10, 0xdb, 0x87, 0x65, 0xdf, 0xdc, 0xfb,
|
||||
0x9f, 0x35, 0xa0, 0x57, 0x03, 0x53, 0x4c, 0xf6,
|
||||
0x6d, 0x35, 0x7d, 0xa6, 0x78, 0xdb, 0xb3, 0x36,
|
||||
0xd2, 0x3f, 0x9c, 0x40, 0xa9, 0x95, 0x26, 0x72,
|
||||
0x7f, 0xb8, 0xbe, 0x66, 0xdf, 0xc5, 0x21, 0x98,
|
||||
0x78, 0x15, 0x16, 0x68, 0x5d, 0x2f, 0x46, 0x0e,
|
||||
0x43, 0xcb, 0x8a, 0x84, 0x39, 0xab, 0xfb, 0xb0,
|
||||
0x35, 0x80, 0x22, 0xbe, 0x34, 0x23, 0x8b, 0xab,
|
||||
0x53, 0x5b, 0x72, 0xec, 0x4b, 0xb5, 0x48, 0x69,
|
||||
0x53, 0x3e, 0x47, 0x5f, 0xfd, 0x09, 0xfd, 0xa7,
|
||||
0x76, 0x13, 0x8f, 0x0f, 0x92, 0xd6, 0x4c, 0xdf,
|
||||
0xae, 0x76, 0xa9, 0xba, 0xd9, 0x22, 0x10, 0xa9,
|
||||
0x9d, 0x71, 0x45, 0xd6, 0xd7, 0xe1, 0x19, 0x25,
|
||||
0x85, 0x9c, 0x53, 0x9a, 0x97, 0xeb, 0x84, 0xd7,
|
||||
0xcc, 0xa8, 0x88, 0x82, 0x20, 0x70, 0x26, 0x20,
|
||||
0xfd, 0x7e, 0x40, 0x50, 0x27, 0xe2, 0x25, 0x93,
|
||||
0x6f, 0xbc, 0x3e, 0x72, 0xa0, 0xfa, 0xc1, 0xbd,
|
||||
0x29, 0xb4, 0x4d, 0x82, 0x5c, 0xc1, 0xb4, 0xcb,
|
||||
0x9c, 0x72, 0x7e, 0xb0, 0xe9, 0x8a, 0x17, 0x3e,
|
||||
0x19, 0x63, 0xfc, 0xfd, 0x82, 0x48, 0x2b, 0xb7,
|
||||
0xb2, 0x33, 0xb9, 0x7d, 0xec, 0x4b, 0xba, 0x89,
|
||||
0x1f, 0x27, 0xb8, 0x9b, 0x88, 0x48, 0x84, 0xaa,
|
||||
0x18, 0x92, 0x0e, 0x65, 0xf5, 0xc8, 0x6c, 0x11,
|
||||
0xff, 0x6b, 0x36, 0xe4, 0x74, 0x34, 0xca, 0x8c,
|
||||
0x33, 0xb1, 0xf9, 0xb8, 0x8e, 0xb4, 0xe6, 0x12,
|
||||
0xe0, 0x02, 0x98, 0x79, 0x52, 0x5e, 0x45, 0x33,
|
||||
0xff, 0x11, 0xdc, 0xeb, 0xc3, 0x53, 0xba, 0x7c,
|
||||
0x60, 0x1a, 0x11, 0x3d, 0x00, 0xfb, 0xd2, 0xb7,
|
||||
0xaa, 0x30, 0xfa, 0x4f, 0x5e, 0x48, 0x77, 0x5b,
|
||||
0x17, 0xdc, 0x75, 0xef, 0x6f, 0xd2, 0x19, 0x6d,
|
||||
0xdc, 0xbe, 0x7f, 0xb0, 0x78, 0x8f, 0xdc, 0x82,
|
||||
0x60, 0x4c, 0xbf, 0xe4, 0x29, 0x06, 0x5e, 0x69,
|
||||
0x8c, 0x39, 0x13, 0xad, 0x14, 0x25, 0xed, 0x19,
|
||||
0xb2, 0xf2, 0x9f, 0x01, 0x82, 0x0d, 0x56, 0x44,
|
||||
0x88, 0xc8, 0x35, 0xec, 0x1f, 0x11, 0xb3, 0x24,
|
||||
0xe0, 0x59, 0x0d, 0x37, 0xe4, 0x47, 0x3c, 0xea,
|
||||
0x4b, 0x7f, 0x97, 0x31, 0x1c, 0x81, 0x7c, 0x94,
|
||||
0x8a, 0x4c, 0x7d, 0x68, 0x15, 0x84, 0xff, 0xa5,
|
||||
0x08, 0xfd, 0x18, 0xe7, 0xe7, 0x2b, 0xe4, 0x47,
|
||||
0x27, 0x12, 0x11, 0xb8, 0x23, 0xec, 0x58, 0x93,
|
||||
0x3c, 0xac, 0x12, 0xd2, 0x88, 0x6d, 0x41, 0x3d,
|
||||
0xc5, 0xfe, 0x1c, 0xdc, 0xb9, 0xf8, 0xd4, 0x51,
|
||||
0x3e, 0x07, 0xe5, 0x03, 0x6f, 0xa7, 0x12, 0xe8,
|
||||
0x12, 0xf7, 0xb5, 0xce, 0xa6, 0x96, 0x55, 0x3f,
|
||||
0x78, 0xb4, 0x64, 0x82, 0x50, 0xd2, 0x33, 0x5f,
|
||||
0x91, 0x02, 0x03, 0x01, 0x00, 0x01};
|
||||
0x30, 0x82, 0x01, 0x8a, 0x02, 0x82, 0x01, 0x81, 0x00, 0xb4, 0xfe, 0x39,
|
||||
0xc3, 0x65, 0x90, 0x03, 0xdb, 0x3c, 0x11, 0x97, 0x09, 0xe8, 0x68, 0xcd,
|
||||
0xf2, 0xc3, 0x5e, 0x9b, 0xf2, 0xe7, 0x4d, 0x23, 0xb1, 0x10, 0xdb, 0x87,
|
||||
0x65, 0xdf, 0xdc, 0xfb, 0x9f, 0x35, 0xa0, 0x57, 0x03, 0x53, 0x4c, 0xf6,
|
||||
0x6d, 0x35, 0x7d, 0xa6, 0x78, 0xdb, 0xb3, 0x36, 0xd2, 0x3f, 0x9c, 0x40,
|
||||
0xa9, 0x95, 0x26, 0x72, 0x7f, 0xb8, 0xbe, 0x66, 0xdf, 0xc5, 0x21, 0x98,
|
||||
0x78, 0x15, 0x16, 0x68, 0x5d, 0x2f, 0x46, 0x0e, 0x43, 0xcb, 0x8a, 0x84,
|
||||
0x39, 0xab, 0xfb, 0xb0, 0x35, 0x80, 0x22, 0xbe, 0x34, 0x23, 0x8b, 0xab,
|
||||
0x53, 0x5b, 0x72, 0xec, 0x4b, 0xb5, 0x48, 0x69, 0x53, 0x3e, 0x47, 0x5f,
|
||||
0xfd, 0x09, 0xfd, 0xa7, 0x76, 0x13, 0x8f, 0x0f, 0x92, 0xd6, 0x4c, 0xdf,
|
||||
0xae, 0x76, 0xa9, 0xba, 0xd9, 0x22, 0x10, 0xa9, 0x9d, 0x71, 0x45, 0xd6,
|
||||
0xd7, 0xe1, 0x19, 0x25, 0x85, 0x9c, 0x53, 0x9a, 0x97, 0xeb, 0x84, 0xd7,
|
||||
0xcc, 0xa8, 0x88, 0x82, 0x20, 0x70, 0x26, 0x20, 0xfd, 0x7e, 0x40, 0x50,
|
||||
0x27, 0xe2, 0x25, 0x93, 0x6f, 0xbc, 0x3e, 0x72, 0xa0, 0xfa, 0xc1, 0xbd,
|
||||
0x29, 0xb4, 0x4d, 0x82, 0x5c, 0xc1, 0xb4, 0xcb, 0x9c, 0x72, 0x7e, 0xb0,
|
||||
0xe9, 0x8a, 0x17, 0x3e, 0x19, 0x63, 0xfc, 0xfd, 0x82, 0x48, 0x2b, 0xb7,
|
||||
0xb2, 0x33, 0xb9, 0x7d, 0xec, 0x4b, 0xba, 0x89, 0x1f, 0x27, 0xb8, 0x9b,
|
||||
0x88, 0x48, 0x84, 0xaa, 0x18, 0x92, 0x0e, 0x65, 0xf5, 0xc8, 0x6c, 0x11,
|
||||
0xff, 0x6b, 0x36, 0xe4, 0x74, 0x34, 0xca, 0x8c, 0x33, 0xb1, 0xf9, 0xb8,
|
||||
0x8e, 0xb4, 0xe6, 0x12, 0xe0, 0x02, 0x98, 0x79, 0x52, 0x5e, 0x45, 0x33,
|
||||
0xff, 0x11, 0xdc, 0xeb, 0xc3, 0x53, 0xba, 0x7c, 0x60, 0x1a, 0x11, 0x3d,
|
||||
0x00, 0xfb, 0xd2, 0xb7, 0xaa, 0x30, 0xfa, 0x4f, 0x5e, 0x48, 0x77, 0x5b,
|
||||
0x17, 0xdc, 0x75, 0xef, 0x6f, 0xd2, 0x19, 0x6d, 0xdc, 0xbe, 0x7f, 0xb0,
|
||||
0x78, 0x8f, 0xdc, 0x82, 0x60, 0x4c, 0xbf, 0xe4, 0x29, 0x06, 0x5e, 0x69,
|
||||
0x8c, 0x39, 0x13, 0xad, 0x14, 0x25, 0xed, 0x19, 0xb2, 0xf2, 0x9f, 0x01,
|
||||
0x82, 0x0d, 0x56, 0x44, 0x88, 0xc8, 0x35, 0xec, 0x1f, 0x11, 0xb3, 0x24,
|
||||
0xe0, 0x59, 0x0d, 0x37, 0xe4, 0x47, 0x3c, 0xea, 0x4b, 0x7f, 0x97, 0x31,
|
||||
0x1c, 0x81, 0x7c, 0x94, 0x8a, 0x4c, 0x7d, 0x68, 0x15, 0x84, 0xff, 0xa5,
|
||||
0x08, 0xfd, 0x18, 0xe7, 0xe7, 0x2b, 0xe4, 0x47, 0x27, 0x12, 0x11, 0xb8,
|
||||
0x23, 0xec, 0x58, 0x93, 0x3c, 0xac, 0x12, 0xd2, 0x88, 0x6d, 0x41, 0x3d,
|
||||
0xc5, 0xfe, 0x1c, 0xdc, 0xb9, 0xf8, 0xd4, 0x51, 0x3e, 0x07, 0xe5, 0x03,
|
||||
0x6f, 0xa7, 0x12, 0xe8, 0x12, 0xf7, 0xb5, 0xce, 0xa6, 0x96, 0x55, 0x3f,
|
||||
0x78, 0xb4, 0x64, 0x82, 0x50, 0xd2, 0x33, 0x5f, 0x91, 0x02, 0x03, 0x01,
|
||||
0x00, 0x01};
|
||||
}
|
||||
|
||||
namespace wvcdm {
|
||||
@@ -145,14 +129,9 @@ static std::vector<CryptoKey> ExtractContentKeys(const License& license) {
|
||||
}
|
||||
|
||||
CdmLicense::CdmLicense()
|
||||
: session_(NULL),
|
||||
initialized_(false),
|
||||
clock_(new Clock()) {
|
||||
}
|
||||
: session_(NULL), initialized_(false), clock_(new Clock()) {}
|
||||
|
||||
CdmLicense::CdmLicense(Clock* clock)
|
||||
: session_(NULL),
|
||||
initialized_(false) {
|
||||
CdmLicense::CdmLicense(Clock* clock) : session_(NULL), initialized_(false) {
|
||||
if (NULL == clock) {
|
||||
LOGE("CdmLicense::CdmLicense: clock parameter not provided");
|
||||
return;
|
||||
@@ -481,9 +460,7 @@ bool CdmLicense::PrepareKeyRequest(const InitializationData& init_data,
|
||||
}
|
||||
|
||||
CdmResponseType CdmLicense::PrepareKeyUpdateRequest(
|
||||
bool is_renewal,
|
||||
CdmKeyMessage* signed_request,
|
||||
std::string* server_url) {
|
||||
bool is_renewal, CdmKeyMessage* signed_request, std::string* server_url) {
|
||||
if (!initialized_) {
|
||||
LOGE("CdmLicense::PrepareKeyUpdateRequest: not initialized");
|
||||
return UNKNOWN_ERROR;
|
||||
@@ -512,21 +489,18 @@ CdmResponseType CdmLicense::PrepareKeyUpdateRequest(
|
||||
|
||||
int64_t seconds_since_started, seconds_since_last_played;
|
||||
CryptoSession::UsageDurationStatus usage_duration_status =
|
||||
CryptoSession::kUsageDurationsInvalid;
|
||||
CryptoSession::kUsageDurationsInvalid;
|
||||
if (!provider_session_token_.empty()) {
|
||||
if (!is_renewal) {
|
||||
CdmResponseType status =
|
||||
session_->DeactivateUsageInformation(provider_session_token_);
|
||||
if (NO_ERROR != status)
|
||||
return status;
|
||||
if (NO_ERROR != status) return status;
|
||||
}
|
||||
|
||||
std::string usage_report;
|
||||
CdmResponseType status =
|
||||
session_->GenerateUsageReport(provider_session_token_,
|
||||
&usage_report, &usage_duration_status,
|
||||
&seconds_since_started,
|
||||
&seconds_since_last_played);
|
||||
CdmResponseType status = session_->GenerateUsageReport(
|
||||
provider_session_token_, &usage_report, &usage_duration_status,
|
||||
&seconds_since_started, &seconds_since_last_played);
|
||||
if (!is_renewal) {
|
||||
if (NO_ERROR == status)
|
||||
current_license->set_session_usage_table_entry(usage_report);
|
||||
@@ -611,8 +585,9 @@ CdmResponseType CdmLicense::HandleKeyResponse(
|
||||
case SignedMessage::ERROR_RESPONSE:
|
||||
return HandleKeyErrorResponse(signed_response);
|
||||
default:
|
||||
LOGE("CdmLicense::HandleKeyResponse: unrecognized signed message type: %d"
|
||||
, signed_response.type());
|
||||
LOGE(
|
||||
"CdmLicense::HandleKeyResponse: unrecognized signed message type: %d",
|
||||
signed_response.type());
|
||||
return KEY_ERROR;
|
||||
}
|
||||
|
||||
@@ -675,18 +650,14 @@ CdmResponseType CdmLicense::HandleKeyResponse(
|
||||
|
||||
policy_engine_->SetLicense(license);
|
||||
|
||||
CdmResponseType resp = session_->LoadKeys(signed_response.msg(),
|
||||
signed_response.signature(),
|
||||
mac_key_iv,
|
||||
mac_key,
|
||||
key_array,
|
||||
provider_session_token_);
|
||||
CdmResponseType resp = session_->LoadKeys(
|
||||
signed_response.msg(), signed_response.signature(), mac_key_iv, mac_key,
|
||||
key_array, provider_session_token_);
|
||||
|
||||
if (KEY_ADDED == resp) {
|
||||
loaded_keys_.clear();
|
||||
for (std::vector<CryptoKey>::iterator it = key_array.begin();
|
||||
it != key_array.end();
|
||||
++it) {
|
||||
it != key_array.end(); ++it) {
|
||||
loaded_keys_.insert(it->key_id());
|
||||
}
|
||||
}
|
||||
@@ -738,10 +709,9 @@ CdmResponseType CdmLicense::HandleKeyUpdateResponse(
|
||||
if (!license.id().has_provider_session_token()) return KEY_ADDED;
|
||||
|
||||
provider_session_token_ = license.id().provider_session_token();
|
||||
CdmResponseType status =
|
||||
session_->ReleaseUsageInformation(signed_response.msg(),
|
||||
signed_response.signature(),
|
||||
provider_session_token_);
|
||||
CdmResponseType status = session_->ReleaseUsageInformation(
|
||||
signed_response.msg(), signed_response.signature(),
|
||||
provider_session_token_);
|
||||
return (NO_ERROR == status) ? KEY_ADDED : status;
|
||||
}
|
||||
|
||||
@@ -763,8 +733,7 @@ CdmResponseType CdmLicense::HandleKeyUpdateResponse(
|
||||
bool CdmLicense::RestoreOfflineLicense(
|
||||
const CdmKeyMessage& license_request,
|
||||
const CdmKeyResponse& license_response,
|
||||
const CdmKeyResponse& license_renewal_response,
|
||||
int64_t playback_start_time,
|
||||
const CdmKeyResponse& license_renewal_response, int64_t playback_start_time,
|
||||
int64_t last_playback_time) {
|
||||
if (license_request.empty() || license_response.empty()) {
|
||||
LOGE(
|
||||
@@ -810,8 +779,8 @@ bool CdmLicense::RestoreOfflineLicense(
|
||||
CryptoSession::kUsageDurationsInvalid;
|
||||
int64_t seconds_since_started, seconds_since_last_played;
|
||||
sts = session_->GenerateUsageReport(
|
||||
provider_session_token_, &usage_report, &usage_duration_status,
|
||||
&seconds_since_started, &seconds_since_last_played);
|
||||
provider_session_token_, &usage_report, &usage_duration_status,
|
||||
&seconds_since_started, &seconds_since_last_played);
|
||||
|
||||
if (NO_ERROR == sts) {
|
||||
switch (usage_duration_status) {
|
||||
@@ -840,7 +809,6 @@ bool CdmLicense::RestoreOfflineLicense(
|
||||
bool CdmLicense::RestoreLicenseForRelease(
|
||||
const CdmKeyMessage& license_request,
|
||||
const CdmKeyResponse& license_response) {
|
||||
|
||||
if (license_request.empty() || license_response.empty()) {
|
||||
LOGE(
|
||||
"CdmLicense::RestoreLicenseForRelease: key_request or response empty:"
|
||||
@@ -872,27 +840,26 @@ bool CdmLicense::RestoreLicenseForRelease(
|
||||
SignedMessage signed_response;
|
||||
if (!signed_response.ParseFromString(license_response)) {
|
||||
LOGE("CdmLicense::RestoreLicenseForRelease: unable to parse signed license"
|
||||
" response");
|
||||
" response");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (SignedMessage::LICENSE != signed_response.type()) {
|
||||
LOGE("CdmLicense::RestoreLicenseForRelease: unrecognized signed message "
|
||||
"type: %d"
|
||||
, signed_response.type());
|
||||
"type: %d", signed_response.type());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!signed_response.has_signature()) {
|
||||
LOGE("CdmLicense::RestoreLicenseForRelease: license response is not"
|
||||
" signed");
|
||||
" signed");
|
||||
return false;
|
||||
}
|
||||
|
||||
License license;
|
||||
if (!license.ParseFromString(signed_response.msg())) {
|
||||
LOGE("CdmLicense::RestoreLicenseForRelease: unable to parse license"
|
||||
" response");
|
||||
" response");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -953,7 +920,6 @@ bool CdmLicense::PrepareServiceCertificateRequest(CdmKeyMessage* signed_request,
|
||||
|
||||
CdmResponseType CdmLicense::HandleServiceCertificateResponse(
|
||||
const video_widevine_server::sdk::SignedMessage& signed_response) {
|
||||
|
||||
SignedDeviceCertificate signed_service_certificate;
|
||||
if (!signed_service_certificate.ParseFromString(signed_response.msg())) {
|
||||
LOGE(
|
||||
@@ -1006,7 +972,6 @@ CdmResponseType CdmLicense::HandleServiceCertificateResponse(
|
||||
|
||||
CdmResponseType CdmLicense::HandleKeyErrorResponse(
|
||||
const SignedMessage& signed_message) {
|
||||
|
||||
LicenseError license_error;
|
||||
if (!license_error.ParseFromString(signed_message.msg())) {
|
||||
LOGE("CdmLicense::HandleKeyErrorResponse: Unable to parse license error");
|
||||
@@ -1026,7 +991,7 @@ CdmResponseType CdmLicense::HandleKeyErrorResponse(
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
bool CdmLicense::PrepareContentId(const CdmLicenseType license_type,
|
||||
const std::string& request_id,
|
||||
T* content_id) {
|
||||
@@ -1035,8 +1000,7 @@ bool CdmLicense::PrepareContentId(const CdmLicenseType license_type,
|
||||
content_id->set_license_type(video_widevine_server::sdk::OFFLINE);
|
||||
break;
|
||||
case kLicenseTypeStreaming:
|
||||
content_id->set_license_type(
|
||||
video_widevine_server::sdk::STREAMING);
|
||||
content_id->set_license_type(video_widevine_server::sdk::STREAMING);
|
||||
break;
|
||||
default:
|
||||
LOGD("CdmLicense::PrepareKeyRequest: Unknown license type = %d",
|
||||
|
||||
@@ -11,15 +11,16 @@
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "level3.h"
|
||||
#include "log.h"
|
||||
#include "lock.h"
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "file_store.h"
|
||||
#include "level3.h"
|
||||
#include "lock.h"
|
||||
#include "log.h"
|
||||
#include "properties.h"
|
||||
|
||||
using namespace wvoec3;
|
||||
@@ -45,8 +46,8 @@ typedef OEMCryptoResult (*L1_LoadKeys_t)(
|
||||
OEMCrypto_SESSION session, const uint8_t* message, size_t message_length,
|
||||
const uint8_t* signature, size_t signature_length,
|
||||
const uint8_t* enc_mac_key_iv, const uint8_t* enc_mac_key, size_t num_keys,
|
||||
const OEMCrypto_KeyObject* key_array,
|
||||
const uint8_t* pst, size_t pst_length);
|
||||
const OEMCrypto_KeyObject* key_array, const uint8_t* pst,
|
||||
size_t pst_length);
|
||||
typedef OEMCryptoResult (*L1_LoadKeys_V8_t)(
|
||||
OEMCrypto_SESSION session, const uint8_t* message, size_t message_length,
|
||||
const uint8_t* signature, size_t signature_length,
|
||||
@@ -87,17 +88,13 @@ typedef OEMCryptoResult (*L1_RewrapDeviceRSAKey_t)(
|
||||
typedef OEMCryptoResult (*L1_LoadDeviceRSAKey_t)(OEMCrypto_SESSION session,
|
||||
const uint8_t* wrapped_rsa_key,
|
||||
size_t wrapped_rsa_key_length);
|
||||
typedef OEMCryptoResult (*L1_GenerateRSASignature_t)(OEMCrypto_SESSION session,
|
||||
const uint8_t* message,
|
||||
size_t message_length,
|
||||
uint8_t* signature,
|
||||
size_t* signature_length,
|
||||
RSA_Padding_Scheme padding_scheme);
|
||||
typedef OEMCryptoResult (*L1_GenerateRSASignature_V8_t)(OEMCrypto_SESSION session,
|
||||
const uint8_t* message,
|
||||
size_t message_length,
|
||||
uint8_t* signature,
|
||||
size_t* signature_length);
|
||||
typedef OEMCryptoResult (*L1_GenerateRSASignature_t)(
|
||||
OEMCrypto_SESSION session, const uint8_t* message, size_t message_length,
|
||||
uint8_t* signature, size_t* signature_length,
|
||||
RSA_Padding_Scheme padding_scheme);
|
||||
typedef OEMCryptoResult (*L1_GenerateRSASignature_V8_t)(
|
||||
OEMCrypto_SESSION session, const uint8_t* message, size_t message_length,
|
||||
uint8_t* signature, size_t* signature_length);
|
||||
typedef OEMCryptoResult (*L1_DeriveKeysFromSessionKey_t)(
|
||||
OEMCrypto_SESSION session, const uint8_t* enc_session_key,
|
||||
size_t enc_session_key_length, const uint8_t* mac_key_context,
|
||||
@@ -125,24 +122,21 @@ typedef OEMCryptoResult (*L1_Generic_Verify_t)(OEMCrypto_SESSION session,
|
||||
size_t signature_length);
|
||||
typedef uint32_t (*L1_APIVersion_t)();
|
||||
typedef const char* (*L1_SecurityLevel_t)();
|
||||
typedef OEMCryptoResult (*L1_GetHDCPCapability_t)(OEMCrypto_HDCP_Capability *current,
|
||||
OEMCrypto_HDCP_Capability *maximum);
|
||||
typedef OEMCryptoResult (*L1_GetHDCPCapability_t)(
|
||||
OEMCrypto_HDCP_Capability* current, OEMCrypto_HDCP_Capability* maximum);
|
||||
typedef bool (*L1_SupportsUsageTable_t)();
|
||||
typedef OEMCryptoResult (*L1_UpdateUsageTable_t)();
|
||||
typedef OEMCryptoResult (*L1_DeactivateUsageEntry_t)(const uint8_t *pst,
|
||||
size_t pst_length);
|
||||
typedef OEMCryptoResult (*L1_DeactivateUsageEntry_t)(const uint8_t* pst,
|
||||
size_t pst_length);
|
||||
typedef OEMCryptoResult (*L1_ReportUsage_t)(OEMCrypto_SESSION session,
|
||||
const uint8_t *pst,
|
||||
size_t pst_length,
|
||||
OEMCrypto_PST_Report *buffer,
|
||||
size_t *buffer_length);
|
||||
typedef OEMCryptoResult (*L1_DeleteUsageEntry_t)(OEMCrypto_SESSION session,
|
||||
const uint8_t* pst,
|
||||
size_t pst_length,
|
||||
const uint8_t *message,
|
||||
size_t message_length,
|
||||
const uint8_t *signature,
|
||||
size_t signature_length);
|
||||
const uint8_t* pst,
|
||||
size_t pst_length,
|
||||
OEMCrypto_PST_Report* buffer,
|
||||
size_t* buffer_length);
|
||||
typedef OEMCryptoResult (*L1_DeleteUsageEntry_t)(
|
||||
OEMCrypto_SESSION session, const uint8_t* pst, size_t pst_length,
|
||||
const uint8_t* message, size_t message_length, const uint8_t* signature,
|
||||
size_t signature_length);
|
||||
typedef OEMCryptoResult (*L1_DeleteUsageTable_t)();
|
||||
|
||||
struct FunctionPointers {
|
||||
@@ -194,13 +188,12 @@ struct LevelSession {
|
||||
|
||||
#define QUOTE_DEFINE(A) #A
|
||||
#define QUOTE(A) QUOTE_DEFINE(A)
|
||||
#define LOOKUP(Name, Function) \
|
||||
level1_.Name = \
|
||||
(L1_##Name##_t)dlsym(level1_library_, QUOTE(Function)); \
|
||||
if (!level1_.Name) { \
|
||||
LOGW("Could not load L1 %s. Falling Back to L3.", \
|
||||
QUOTE(OEMCrypto_##Name)); \
|
||||
return false; \
|
||||
#define LOOKUP(Name, Function) \
|
||||
level1_.Name = (L1_##Name##_t)dlsym(level1_library_, QUOTE(Function)); \
|
||||
if (!level1_.Name) { \
|
||||
LOGW("Could not load L1 %s. Falling Back to L3.", \
|
||||
QUOTE(OEMCrypto_##Name)); \
|
||||
return false; \
|
||||
}
|
||||
|
||||
class Adapter {
|
||||
@@ -283,19 +276,19 @@ class Adapter {
|
||||
level1_.Terminate();
|
||||
return false;
|
||||
}
|
||||
if( level1_.version == 8 ) {
|
||||
LOOKUP(LoadKeys_V8, OEMCrypto_LoadKeys_V8);
|
||||
LOOKUP(GenerateRSASignature_V8, OEMCrypto_GenerateRSASignature_V8);
|
||||
if (level1_.version == 8) {
|
||||
LOOKUP(LoadKeys_V8, OEMCrypto_LoadKeys_V8);
|
||||
LOOKUP(GenerateRSASignature_V8, OEMCrypto_GenerateRSASignature_V8);
|
||||
} else {
|
||||
LOOKUP(LoadKeys, OEMCrypto_LoadKeys);
|
||||
LOOKUP(GenerateRSASignature, OEMCrypto_GenerateRSASignature);
|
||||
LOOKUP(GetHDCPCapability, OEMCrypto_GetHDCPCapability);
|
||||
LOOKUP(SupportsUsageTable, OEMCrypto_SupportsUsageTable);
|
||||
LOOKUP(UpdateUsageTable, OEMCrypto_UpdateUsageTable);
|
||||
LOOKUP(DeactivateUsageEntry, OEMCrypto_DeactivateUsageEntry);
|
||||
LOOKUP(ReportUsage, OEMCrypto_ReportUsage);
|
||||
LOOKUP(DeleteUsageEntry, OEMCrypto_DeleteUsageEntry);
|
||||
LOOKUP(DeleteUsageTable, OEMCrypto_DeleteUsageTable);
|
||||
LOOKUP(LoadKeys, OEMCrypto_LoadKeys);
|
||||
LOOKUP(GenerateRSASignature, OEMCrypto_GenerateRSASignature);
|
||||
LOOKUP(GetHDCPCapability, OEMCrypto_GetHDCPCapability);
|
||||
LOOKUP(SupportsUsageTable, OEMCrypto_SupportsUsageTable);
|
||||
LOOKUP(UpdateUsageTable, OEMCrypto_UpdateUsageTable);
|
||||
LOOKUP(DeactivateUsageEntry, OEMCrypto_DeactivateUsageEntry);
|
||||
LOOKUP(ReportUsage, OEMCrypto_ReportUsage);
|
||||
LOOKUP(DeleteUsageEntry, OEMCrypto_DeleteUsageEntry);
|
||||
LOOKUP(DeleteUsageTable, OEMCrypto_DeleteUsageTable);
|
||||
}
|
||||
if (OEMCrypto_SUCCESS == level1_.IsKeyboxValid()) {
|
||||
return true;
|
||||
@@ -434,6 +427,7 @@ class Adapter {
|
||||
// id will match the internal session id in the last two digits.
|
||||
static const OEMCrypto_SESSION kLevel3Offset = 25600;
|
||||
};
|
||||
|
||||
static Adapter* kAdapter = 0;
|
||||
|
||||
extern "C" OEMCryptoResult OEMCrypto_Initialize(void) {
|
||||
@@ -503,15 +497,15 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys(
|
||||
OEMCrypto_SESSION session, const uint8_t* message, size_t message_length,
|
||||
const uint8_t* signature, size_t signature_length,
|
||||
const uint8_t* enc_mac_key_iv, const uint8_t* enc_mac_key, size_t num_keys,
|
||||
const OEMCrypto_KeyObject* key_array,
|
||||
const uint8_t* pst, size_t pst_length) {
|
||||
const OEMCrypto_KeyObject* key_array, const uint8_t* pst,
|
||||
size_t pst_length) {
|
||||
if (!kAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
LevelSession pair = kAdapter->get(session);
|
||||
if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION;
|
||||
if (pair.fcn->version == 8) {
|
||||
return pair.fcn->LoadKeys_V8(pair.session, message, message_length, signature,
|
||||
signature_length, enc_mac_key_iv, enc_mac_key,
|
||||
num_keys, key_array);
|
||||
return pair.fcn->LoadKeys_V8(pair.session, message, message_length,
|
||||
signature, signature_length, enc_mac_key_iv,
|
||||
enc_mac_key, num_keys, key_array);
|
||||
} else {
|
||||
return pair.fcn->LoadKeys(pair.session, message, message_length, signature,
|
||||
signature_length, enc_mac_key_iv, enc_mac_key,
|
||||
@@ -644,19 +638,20 @@ extern "C" OEMCryptoResult OEMCrypto_LoadDeviceRSAKey(
|
||||
if (!kAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
LevelSession pair = kAdapter->get(session);
|
||||
if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION;
|
||||
return pair.fcn
|
||||
->LoadDeviceRSAKey(pair.session, wrapped_rsa_key, wrapped_rsa_key_length);
|
||||
return pair.fcn->LoadDeviceRSAKey(pair.session, wrapped_rsa_key,
|
||||
wrapped_rsa_key_length);
|
||||
}
|
||||
|
||||
extern "C" OEMCryptoResult OEMCrypto_GenerateRSASignature(
|
||||
OEMCrypto_SESSION session, const uint8_t* message, size_t message_length,
|
||||
uint8_t* signature, size_t* signature_length, RSA_Padding_Scheme padding_scheme) {
|
||||
uint8_t* signature, size_t* signature_length,
|
||||
RSA_Padding_Scheme padding_scheme) {
|
||||
if (!kAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
LevelSession pair = kAdapter->get(session);
|
||||
if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION;
|
||||
if (pair.fcn->version == 8) {
|
||||
return pair.fcn->GenerateRSASignature_V8(pair.session, message, message_length,
|
||||
signature, signature_length);
|
||||
return pair.fcn->GenerateRSASignature_V8(
|
||||
pair.session, message, message_length, signature, signature_length);
|
||||
} else {
|
||||
return pair.fcn->GenerateRSASignature(pair.session, message, message_length,
|
||||
signature, signature_length,
|
||||
@@ -702,7 +697,6 @@ const char* OEMCrypto_SecurityLevel(SecurityLevel level) {
|
||||
extern "C" OEMCryptoResult OEMCrypto_Generic_Encrypt(
|
||||
OEMCrypto_SESSION session, const uint8_t* in_buffer, size_t buffer_length,
|
||||
const uint8_t* iv, OEMCrypto_Algorithm algorithm, uint8_t* out_buffer) {
|
||||
|
||||
if (!kAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
LevelSession pair = kAdapter->get(session);
|
||||
if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION;
|
||||
@@ -744,13 +738,12 @@ extern "C" OEMCryptoResult OEMCrypto_Generic_Verify(
|
||||
algorithm, signature, signature_length);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
OEMCryptoResult OEMCrypto_GetHDCPCapability(OEMCrypto_HDCP_Capability *current,
|
||||
OEMCrypto_HDCP_Capability *maximum) {
|
||||
extern "C" OEMCryptoResult OEMCrypto_GetHDCPCapability(
|
||||
OEMCrypto_HDCP_Capability* current, OEMCrypto_HDCP_Capability* maximum) {
|
||||
if (!kAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
const FunctionPointers* fcn = kAdapter->get(kLevelDefault);
|
||||
if (!fcn) return OEMCrypto_ERROR_INVALID_SESSION;
|
||||
if( fcn->version == 8 ) return OEMCrypto_ERROR_NOT_IMPLEMENTED;
|
||||
if (fcn->version == 8) return OEMCrypto_ERROR_NOT_IMPLEMENTED;
|
||||
return fcn->GetHDCPCapability(current, maximum);
|
||||
}
|
||||
|
||||
@@ -776,7 +769,7 @@ extern "C" OEMCryptoResult OEMCrypto_UpdateUsageTable() {
|
||||
return sts;
|
||||
}
|
||||
|
||||
extern "C" OEMCryptoResult OEMCrypto_DeactivateUsageEntry(const uint8_t *pst,
|
||||
extern "C" OEMCryptoResult OEMCrypto_DeactivateUsageEntry(const uint8_t* pst,
|
||||
size_t pst_length) {
|
||||
if (!kAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
const FunctionPointers* fcn1 = kAdapter->get(kLevelDefault);
|
||||
@@ -794,32 +787,29 @@ extern "C" OEMCryptoResult OEMCrypto_DeactivateUsageEntry(const uint8_t *pst,
|
||||
}
|
||||
|
||||
extern "C" OEMCryptoResult OEMCrypto_ReportUsage(OEMCrypto_SESSION session,
|
||||
const uint8_t *pst,
|
||||
const uint8_t* pst,
|
||||
size_t pst_length,
|
||||
OEMCrypto_PST_Report *buffer,
|
||||
size_t *buffer_length) {
|
||||
OEMCrypto_PST_Report* buffer,
|
||||
size_t* buffer_length) {
|
||||
if (!kAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
LevelSession pair = kAdapter->get(session);
|
||||
if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION;
|
||||
if( pair.fcn->version > 8 ) {
|
||||
return pair.fcn->ReportUsage(pair.session, pst, pst_length,buffer,
|
||||
if (pair.fcn->version > 8) {
|
||||
return pair.fcn->ReportUsage(pair.session, pst, pst_length, buffer,
|
||||
buffer_length);
|
||||
} else {
|
||||
return OEMCrypto_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" OEMCryptoResult OEMCrypto_DeleteUsageEntry(OEMCrypto_SESSION session,
|
||||
const uint8_t* pst,
|
||||
size_t pst_length,
|
||||
const uint8_t *message,
|
||||
size_t message_length,
|
||||
const uint8_t *signature,
|
||||
size_t signature_length) {
|
||||
extern "C" OEMCryptoResult OEMCrypto_DeleteUsageEntry(
|
||||
OEMCrypto_SESSION session, const uint8_t* pst, size_t pst_length,
|
||||
const uint8_t* message, size_t message_length, const uint8_t* signature,
|
||||
size_t signature_length) {
|
||||
if (!kAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
||||
LevelSession pair = kAdapter->get(session);
|
||||
if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION;
|
||||
if( pair.fcn->version > 8 ) {
|
||||
if (pair.fcn->version > 8) {
|
||||
return pair.fcn->DeleteUsageEntry(pair.session, pst, pst_length, message,
|
||||
message_length, signature,
|
||||
signature_length);
|
||||
|
||||
@@ -27,8 +27,7 @@ PolicyEngine::PolicyEngine(CryptoSession* crypto_session, Clock* clock)
|
||||
}
|
||||
|
||||
PolicyEngine::~PolicyEngine() {
|
||||
if (clock_)
|
||||
delete clock_;
|
||||
if (clock_) delete clock_;
|
||||
}
|
||||
|
||||
void PolicyEngine::Init(Clock* clock) {
|
||||
@@ -52,7 +51,7 @@ void PolicyEngine::OnTimerEvent(bool* event_occurred, CdmEventType* event) {
|
||||
|
||||
// License expiration trumps all.
|
||||
if ((IsLicenseDurationExpired(current_time) ||
|
||||
IsPlaybackDurationExpired(current_time)) &&
|
||||
IsPlaybackDurationExpired(current_time)) &&
|
||||
license_state_ != kLicenseStateExpired) {
|
||||
license_state_ = kLicenseStateExpired;
|
||||
can_decrypt_ = false;
|
||||
@@ -66,8 +65,7 @@ void PolicyEngine::OnTimerEvent(bool* event_occurred, CdmEventType* event) {
|
||||
// Test to determine if renewal should be attempted.
|
||||
switch (license_state_) {
|
||||
case kLicenseStateCanPlay: {
|
||||
if (IsRenewalDelayExpired(current_time))
|
||||
renewal_needed = true;
|
||||
if (IsRenewalDelayExpired(current_time)) renewal_needed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -77,8 +75,7 @@ void PolicyEngine::OnTimerEvent(bool* event_occurred, CdmEventType* event) {
|
||||
}
|
||||
|
||||
case kLicenseStateWaitingLicenseUpdate: {
|
||||
if (IsRenewalRetryIntervalExpired(current_time))
|
||||
renewal_needed = true;
|
||||
if (IsRenewalRetryIntervalExpired(current_time)) renewal_needed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -122,8 +119,7 @@ void PolicyEngine::SetLicense(
|
||||
|
||||
void PolicyEngine::UpdateLicense(
|
||||
const video_widevine_server::sdk::License& license) {
|
||||
if (!license.has_policy())
|
||||
return;
|
||||
if (!license.has_policy()) return;
|
||||
|
||||
if (kLicenseStateExpired == license_state_) {
|
||||
LOGD("PolicyEngine::UpdateLicense: updating an expired license");
|
||||
@@ -157,15 +153,13 @@ void PolicyEngine::UpdateLicense(
|
||||
policy_max_duration_seconds_ = policy_.rental_duration_seconds();
|
||||
|
||||
if ((policy_.license_duration_seconds() > 0) &&
|
||||
((policy_.license_duration_seconds() <
|
||||
policy_max_duration_seconds_) ||
|
||||
((policy_.license_duration_seconds() < policy_max_duration_seconds_) ||
|
||||
policy_max_duration_seconds_ == 0)) {
|
||||
policy_max_duration_seconds_ = policy_.license_duration_seconds();
|
||||
}
|
||||
|
||||
int64_t current_time = clock_->GetCurrentTime();
|
||||
if (!policy_.can_play() ||
|
||||
IsLicenseDurationExpired(current_time) ||
|
||||
if (!policy_.can_play() || IsLicenseDurationExpired(current_time) ||
|
||||
IsPlaybackDurationExpired(current_time)) {
|
||||
license_state_ = kLicenseStateExpired;
|
||||
return;
|
||||
@@ -221,14 +215,15 @@ CdmResponseType PolicyEngine::Query(CdmQueryMap* key_info) {
|
||||
}
|
||||
|
||||
(*key_info)[QUERY_KEY_LICENSE_TYPE] =
|
||||
license_id_.type() == video_widevine_server::sdk::STREAMING ?
|
||||
QUERY_VALUE_STREAMING : QUERY_VALUE_OFFLINE;
|
||||
(*key_info)[QUERY_KEY_PLAY_ALLOWED] = policy_.can_play() ?
|
||||
QUERY_VALUE_TRUE : QUERY_VALUE_FALSE;
|
||||
(*key_info)[QUERY_KEY_PERSIST_ALLOWED] = policy_.can_persist() ?
|
||||
QUERY_VALUE_TRUE : QUERY_VALUE_FALSE;
|
||||
(*key_info)[QUERY_KEY_RENEW_ALLOWED] = policy_.can_renew() ?
|
||||
QUERY_VALUE_TRUE : QUERY_VALUE_FALSE;
|
||||
license_id_.type() == video_widevine_server::sdk::STREAMING
|
||||
? QUERY_VALUE_STREAMING
|
||||
: QUERY_VALUE_OFFLINE;
|
||||
(*key_info)[QUERY_KEY_PLAY_ALLOWED] =
|
||||
policy_.can_play() ? QUERY_VALUE_TRUE : QUERY_VALUE_FALSE;
|
||||
(*key_info)[QUERY_KEY_PERSIST_ALLOWED] =
|
||||
policy_.can_persist() ? QUERY_VALUE_TRUE : QUERY_VALUE_FALSE;
|
||||
(*key_info)[QUERY_KEY_RENEW_ALLOWED] =
|
||||
policy_.can_renew() ? QUERY_VALUE_TRUE : QUERY_VALUE_FALSE;
|
||||
ss << GetLicenseDurationRemaining(current_time);
|
||||
(*key_info)[QUERY_KEY_LICENSE_DURATION_REMAINING] = ss.str();
|
||||
ss.str("");
|
||||
@@ -270,15 +265,14 @@ void PolicyEngine::UpdateRenewalRequest(int64_t current_time) {
|
||||
// will always return false if the value is 0.
|
||||
bool PolicyEngine::IsLicenseDurationExpired(int64_t current_time) {
|
||||
return policy_max_duration_seconds_ &&
|
||||
license_start_time_ + policy_max_duration_seconds_ <=
|
||||
current_time;
|
||||
license_start_time_ + policy_max_duration_seconds_ <= current_time;
|
||||
}
|
||||
|
||||
int64_t PolicyEngine::GetLicenseDurationRemaining(int64_t current_time) {
|
||||
if (0 == policy_max_duration_seconds_) return LLONG_MAX;
|
||||
|
||||
int64_t remaining_time = policy_max_duration_seconds_
|
||||
+ license_start_time_ - current_time;
|
||||
int64_t remaining_time =
|
||||
policy_max_duration_seconds_ + license_start_time_ - current_time;
|
||||
|
||||
if (remaining_time < 0)
|
||||
remaining_time = 0;
|
||||
@@ -288,43 +282,38 @@ int64_t PolicyEngine::GetLicenseDurationRemaining(int64_t current_time) {
|
||||
}
|
||||
|
||||
bool PolicyEngine::IsPlaybackDurationExpired(int64_t current_time) {
|
||||
return (policy_.playback_duration_seconds() > 0) &&
|
||||
playback_start_time_ &&
|
||||
playback_start_time_ + policy_.playback_duration_seconds() <=
|
||||
current_time;
|
||||
return (policy_.playback_duration_seconds() > 0) && playback_start_time_ &&
|
||||
playback_start_time_ + policy_.playback_duration_seconds() <=
|
||||
current_time;
|
||||
}
|
||||
|
||||
int64_t PolicyEngine::GetPlaybackDurationRemaining(int64_t current_time) {
|
||||
if (0 == policy_.playback_duration_seconds()) return LLONG_MAX;
|
||||
if (0 == playback_start_time_) return policy_.playback_duration_seconds();
|
||||
|
||||
int64_t remaining_time = policy_.playback_duration_seconds()
|
||||
+ playback_start_time_ - current_time;
|
||||
int64_t remaining_time =
|
||||
policy_.playback_duration_seconds() + playback_start_time_ - current_time;
|
||||
|
||||
if (remaining_time < 0) remaining_time = 0;
|
||||
return remaining_time;
|
||||
}
|
||||
|
||||
bool PolicyEngine::IsRenewalDelayExpired(int64_t current_time) {
|
||||
return policy_.can_renew() &&
|
||||
(policy_.renewal_delay_seconds() > 0) &&
|
||||
license_start_time_ + policy_.renewal_delay_seconds() <=
|
||||
current_time;
|
||||
return policy_.can_renew() && (policy_.renewal_delay_seconds() > 0) &&
|
||||
license_start_time_ + policy_.renewal_delay_seconds() <= current_time;
|
||||
}
|
||||
|
||||
bool PolicyEngine::IsRenewalRecoveryDurationExpired(
|
||||
int64_t current_time) {
|
||||
// NOTE: Renewal Recovery Duration is currently not used.
|
||||
bool PolicyEngine::IsRenewalRecoveryDurationExpired(int64_t current_time) {
|
||||
// NOTE: Renewal Recovery Duration is currently not used.
|
||||
return (policy_.renewal_recovery_duration_seconds() > 0) &&
|
||||
license_start_time_ + policy_.renewal_recovery_duration_seconds() <=
|
||||
current_time;
|
||||
license_start_time_ + policy_.renewal_recovery_duration_seconds() <=
|
||||
current_time;
|
||||
}
|
||||
|
||||
bool PolicyEngine::IsRenewalRetryIntervalExpired(
|
||||
int64_t current_time) {
|
||||
bool PolicyEngine::IsRenewalRetryIntervalExpired(int64_t current_time) {
|
||||
return policy_.can_renew() &&
|
||||
(policy_.renewal_retry_interval_seconds() > 0) &&
|
||||
next_renewal_time_ <= current_time;
|
||||
(policy_.renewal_retry_interval_seconds() > 0) &&
|
||||
next_renewal_time_ <= current_time;
|
||||
}
|
||||
|
||||
} // wvcdm
|
||||
|
||||
@@ -13,9 +13,7 @@ AesCbcKey::AesCbcKey() {}
|
||||
|
||||
AesCbcKey::~AesCbcKey() {}
|
||||
|
||||
bool AesCbcKey::Init(const std::string& key) {
|
||||
return false;
|
||||
}
|
||||
bool AesCbcKey::Init(const std::string& key) { return false; }
|
||||
|
||||
bool AesCbcKey::Encrypt(const std::string& in, std::string* out,
|
||||
std::string* iv) {
|
||||
@@ -26,9 +24,7 @@ RsaPublicKey::RsaPublicKey() {}
|
||||
|
||||
RsaPublicKey::~RsaPublicKey() {}
|
||||
|
||||
bool RsaPublicKey::Init(const std::string& serialized_key) {
|
||||
return false;
|
||||
}
|
||||
bool RsaPublicKey::Init(const std::string& serialized_key) { return false; }
|
||||
|
||||
bool RsaPublicKey::Encrypt(const std::string& clear_message,
|
||||
std::string* encrypted_message) {
|
||||
|
||||
@@ -43,7 +43,8 @@ std::vector<uint8_t> a2b_hex(const std::string& byte) {
|
||||
unsigned char lsb = 0; // least significant 4 bits
|
||||
if (!CharToDigit(byte[i * 2], &msb) ||
|
||||
!CharToDigit(byte[i * 2 + 1], &lsb)) {
|
||||
LOGE("Invalid hex value %c%c at index %d", byte[i*2], byte[i*2+1], i);
|
||||
LOGE("Invalid hex value %c%c at index %d", byte[i * 2], byte[i * 2 + 1],
|
||||
i);
|
||||
return array;
|
||||
}
|
||||
array.push_back((msb << 4) | lsb);
|
||||
@@ -53,10 +54,11 @@ std::vector<uint8_t> a2b_hex(const std::string& byte) {
|
||||
|
||||
// converts an ascii hex string(2 bytes per digit) into a decimal byte string
|
||||
// dump the string with the label.
|
||||
std::vector<uint8_t> a2b_hex(const std::string& label, const std::string& byte) {
|
||||
|
||||
std::cout << std::endl << "[[DUMP: " << label << " ]= \"" << byte << "\"]"
|
||||
<< std::endl << std::endl;
|
||||
std::vector<uint8_t> a2b_hex(const std::string& label,
|
||||
const std::string& byte) {
|
||||
std::cout << std::endl
|
||||
<< "[[DUMP: " << label << " ]= \"" << byte << "\"]" << std::endl
|
||||
<< std::endl;
|
||||
|
||||
return a2b_hex(byte);
|
||||
}
|
||||
@@ -71,7 +73,7 @@ std::string b2a_hex(const std::vector<uint8_t>& byte) {
|
||||
}
|
||||
|
||||
std::string b2a_hex(const std::string& byte) {
|
||||
return HexEncode(reinterpret_cast<const uint8_t *>(byte.data()),
|
||||
return HexEncode(reinterpret_cast<const uint8_t*>(byte.data()),
|
||||
byte.length());
|
||||
}
|
||||
|
||||
@@ -90,9 +92,8 @@ std::string Base64SafeEncode(const std::vector<uint8_t>& bin_input) {
|
||||
int in_size = bin_input.size();
|
||||
std::string b64_output(modp_b64w_encode_len(in_size), 0);
|
||||
|
||||
int out_size = modp_b64w_encode(&b64_output[0],
|
||||
reinterpret_cast<const char*>(&bin_input[0]),
|
||||
in_size);
|
||||
int out_size = modp_b64w_encode(
|
||||
&b64_output[0], reinterpret_cast<const char*>(&bin_input[0]), in_size);
|
||||
if (out_size == -1) {
|
||||
LOGE("Base64SafeEncode failed");
|
||||
return std::string();
|
||||
@@ -119,8 +120,7 @@ std::vector<uint8_t> Base64SafeDecode(const std::string& b64_input) {
|
||||
int in_size = b64_input.size();
|
||||
std::vector<uint8_t> bin_output(modp_b64w_decode_len(in_size), 0);
|
||||
int out_size = modp_b64w_decode(reinterpret_cast<char*>(&bin_output[0]),
|
||||
b64_input.data(),
|
||||
in_size);
|
||||
b64_input.data(), in_size);
|
||||
if (out_size == -1) {
|
||||
LOGE("Base64SafeDecode failed");
|
||||
return std::vector<uint8_t>(0);
|
||||
|
||||
Reference in New Issue
Block a user