Generate key set ID on initialization and interface clean up
This is a merge of squashed CLs. * Cdm Session and Engine interface clean up [ Merge of http://go/wvgerrit/16387 ] Key Set Ids have been removed from the CdmSession interface (GenerateKeyRequest, Addkey) as they can be queried by an accessor. The CdmEngine interface now allows one to specify or retrieve a session ID, since both were not being used in a single call. Key set IDs are no longer returned though GenerateKeyRequest as they was not being used. * Generate key set ID when session is initialized [ Merge of http://go/wvgerrit/16370 ] Key set IDs are currently generated at different times in the CdmSession lifecycle. Android generates key set IDs when the license is received, while the CE CDM generates (or overrides them) when the session is constructed. The key set IDs are now generated when the session is initialized. Key set generation cannot occur earlier as it has a dependency on security level and in turn on crypto session initialization which occurs when the session is initialized. Depenencies on Session ID has caused other activities, construction of PolicyEngine, CdmLicense, setting property CDM client sets to be deferred from CdmSession constructor to Init(). Android will still retrieve the key set IDs after the offline license is processed. For streaming requests, the key set will be unreserved and discarded when the session is terminated. Change-Id: Ib802d1c043742d62efa9a2c901fcd113e836c33d
This commit is contained in:
@@ -25,48 +25,6 @@ const size_t kKeySetIdLength = 14;
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
CdmSession::CdmSession(CdmClientPropertySet* cdm_client_property_set,
|
||||
const std::string& origin,
|
||||
WvCdmEventListener* event_listener,
|
||||
const CdmSessionId* forced_session_id)
|
||||
: initialized_(false),
|
||||
session_id_(GenerateSessionId()),
|
||||
origin_(origin),
|
||||
crypto_session_(new CryptoSession),
|
||||
file_handle_(new DeviceFiles),
|
||||
license_received_(false),
|
||||
is_offline_(false),
|
||||
is_release_(false),
|
||||
is_temporary_(false),
|
||||
security_level_(kSecurityLevelUninitialized),
|
||||
requested_security_level_(kLevelDefault),
|
||||
is_initial_decryption_(true),
|
||||
has_decrypted_since_last_report_(false),
|
||||
is_initial_usage_update_(true),
|
||||
is_usage_update_needed_(false) {
|
||||
if (Properties::AlwaysUseKeySetIds()) {
|
||||
if (forced_session_id) {
|
||||
key_set_id_ = *forced_session_id;
|
||||
} else {
|
||||
bool ok = GenerateKeySetId(&key_set_id_);
|
||||
(void)ok; // ok is now used when assertions are turned off.
|
||||
assert(ok);
|
||||
}
|
||||
session_id_ = key_set_id_;
|
||||
}
|
||||
license_parser_.reset(new CdmLicense(session_id_));
|
||||
policy_engine_.reset(new PolicyEngine(
|
||||
session_id_, event_listener, crypto_session_.get()));
|
||||
if (cdm_client_property_set) {
|
||||
if (cdm_client_property_set->security_level() ==
|
||||
QUERY_VALUE_SECURITY_LEVEL_L3) {
|
||||
requested_security_level_ = kLevel3;
|
||||
security_level_ = kSecurityLevelL3;
|
||||
}
|
||||
Properties::AddSessionPropertySet(session_id_, cdm_client_property_set);
|
||||
}
|
||||
}
|
||||
|
||||
CdmSession::~CdmSession() {
|
||||
if (!key_set_id_.empty()) {
|
||||
// Unreserve the license ID.
|
||||
@@ -75,24 +33,37 @@ CdmSession::~CdmSession() {
|
||||
Properties::RemoveSessionPropertySet(session_id_);
|
||||
}
|
||||
|
||||
CdmResponseType CdmSession::Init() {
|
||||
if (session_id_.empty()) {
|
||||
LOGE("CdmSession::Init: Failed, session not properly constructed");
|
||||
return SESSION_INIT_ERROR_1;
|
||||
}
|
||||
CdmResponseType CdmSession::Init(
|
||||
CdmClientPropertySet* cdm_client_property_set) {
|
||||
return Init(cdm_client_property_set, NULL, NULL);
|
||||
}
|
||||
|
||||
CdmResponseType CdmSession::Init(CdmClientPropertySet* cdm_client_property_set,
|
||||
const CdmSessionId* forced_session_id,
|
||||
WvCdmEventListener* event_listener) {
|
||||
if (initialized_) {
|
||||
LOGE("CdmSession::Init: Failed due to previous initialization");
|
||||
return SESSION_INIT_ERROR_2;
|
||||
}
|
||||
if (cdm_client_property_set &&
|
||||
cdm_client_property_set->security_level() ==
|
||||
QUERY_VALUE_SECURITY_LEVEL_L3) {
|
||||
requested_security_level_ = kLevel3;
|
||||
security_level_ = kSecurityLevelL3;
|
||||
}
|
||||
CdmResponseType sts = crypto_session_->Open(requested_security_level_);
|
||||
if (NO_ERROR != sts) return sts;
|
||||
security_level_ = crypto_session_->GetSecurityLevel();
|
||||
|
||||
if (!file_handle_->Init(security_level_)) {
|
||||
LOGE("CdmSession::Init: Unable to initialize file handle");
|
||||
return SESSION_FILE_HANDLE_INIT_ERROR;
|
||||
}
|
||||
|
||||
std::string token;
|
||||
if (Properties::use_certificates_as_identification()) {
|
||||
std::string wrapped_key;
|
||||
if (!file_handle_->Init(security_level_) ||
|
||||
!file_handle_->RetrieveCertificate(origin_, &token, &wrapped_key) ||
|
||||
if (!file_handle_->RetrieveCertificate(origin_, &token, &wrapped_key) ||
|
||||
!crypto_session_->LoadCertificatePrivateKey(wrapped_key)) {
|
||||
return NEED_PROVISIONING;
|
||||
}
|
||||
@@ -101,6 +72,30 @@ CdmResponseType CdmSession::Init() {
|
||||
return SESSION_INIT_GET_KEYBOX_ERROR;
|
||||
}
|
||||
|
||||
if (forced_session_id) {
|
||||
key_set_id_ = *forced_session_id;
|
||||
} else {
|
||||
bool ok = GenerateKeySetId(&key_set_id_);
|
||||
(void)ok; // ok is now used when assertions are turned off.
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
session_id_ =
|
||||
Properties::AlwaysUseKeySetIds() ? key_set_id_ : GenerateSessionId();
|
||||
|
||||
if (session_id_.empty()) {
|
||||
LOGE("CdmSession::Init: empty session ID");
|
||||
return EMPTY_SESSION_ID;
|
||||
}
|
||||
if (cdm_client_property_set)
|
||||
Properties::AddSessionPropertySet(session_id_, cdm_client_property_set);
|
||||
|
||||
if (!mock_license_parser_in_use_)
|
||||
license_parser_.reset(new CdmLicense(session_id_));
|
||||
if (!mock_policy_engine_in_use_)
|
||||
policy_engine_.reset(new PolicyEngine(
|
||||
session_id_, event_listener, crypto_session_.get()));
|
||||
|
||||
if (!license_parser_->Init(token, crypto_session_.get(),
|
||||
policy_engine_.get()))
|
||||
return LICENSE_PARSER_INIT_ERROR;
|
||||
@@ -115,10 +110,6 @@ CdmResponseType CdmSession::RestoreOfflineSession(
|
||||
const CdmKeySetId& key_set_id, const CdmLicenseType license_type) {
|
||||
key_set_id_ = key_set_id;
|
||||
|
||||
// Retrieve license information from persistent store
|
||||
if (!file_handle_->Reset(security_level_))
|
||||
return RESTORE_OFFLINE_LICENSE_ERROR_1;
|
||||
|
||||
DeviceFiles::LicenseState license_state;
|
||||
int64_t playback_start_time;
|
||||
int64_t last_playback_time;
|
||||
@@ -178,8 +169,7 @@ CdmResponseType CdmSession::RestoreUsageSession(
|
||||
CdmResponseType CdmSession::GenerateKeyRequest(
|
||||
const InitializationData& init_data, CdmLicenseType license_type,
|
||||
const CdmAppParameterMap& app_parameters, CdmKeyMessage* key_request,
|
||||
CdmKeyRequestType* key_request_type, std::string* server_url,
|
||||
CdmKeySetId* key_set_id) {
|
||||
CdmKeyRequestType* key_request_type, std::string* server_url) {
|
||||
if (crypto_session_.get() == NULL) {
|
||||
LOGW("CdmSession::GenerateKeyRequest: Invalid crypto session");
|
||||
return INVALID_CRYPTO_SESSION_1;
|
||||
@@ -248,8 +238,7 @@ CdmResponseType CdmSession::GenerateKeyRequest(
|
||||
return INIT_DATA_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
if (is_offline_ && key_set_id_.empty() &&
|
||||
!GenerateKeySetId(&key_set_id_)) {
|
||||
if (is_offline_ && key_set_id_.empty()) {
|
||||
LOGE("CdmSession::GenerateKeyRequest: Unable to generate key set ID");
|
||||
return KEY_REQUEST_ERROR_1;
|
||||
}
|
||||
@@ -267,14 +256,12 @@ CdmResponseType CdmSession::GenerateKeyRequest(
|
||||
offline_release_server_url_ = *server_url;
|
||||
}
|
||||
|
||||
if (key_set_id) *key_set_id = key_set_id_;
|
||||
return KEY_MESSAGE;
|
||||
}
|
||||
}
|
||||
|
||||
// AddKey() - Accept license response and extract key info.
|
||||
CdmResponseType CdmSession::AddKey(const CdmKeyResponse& key_response,
|
||||
CdmKeySetId* key_set_id) {
|
||||
CdmResponseType CdmSession::AddKey(const CdmKeyResponse& key_response) {
|
||||
if (crypto_session_.get() == NULL) {
|
||||
LOGW("CdmSession::AddKey: Invalid crypto session");
|
||||
return INVALID_CRYPTO_SESSION_2;
|
||||
@@ -303,7 +290,6 @@ CdmResponseType CdmSession::AddKey(const CdmKeyResponse& key_response,
|
||||
if (sts != NO_ERROR) return sts;
|
||||
}
|
||||
|
||||
if (key_set_id) *key_set_id = key_set_id_;
|
||||
return KEY_ADDED;
|
||||
}
|
||||
}
|
||||
@@ -477,8 +463,6 @@ 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;
|
||||
|
||||
while (key_set_id->empty()) {
|
||||
if (!crypto_session_->GetRandom(random_data.size(), &random_data[0]))
|
||||
return false;
|
||||
@@ -514,13 +498,6 @@ CdmResponseType CdmSession::StoreLicense() {
|
||||
|
||||
if (!StoreLicense(DeviceFiles::kLicenseStateActive)) {
|
||||
LOGE("CdmSession::StoreLicense: Unable to store license");
|
||||
CdmResponseType sts = Init();
|
||||
if (sts != NO_ERROR) {
|
||||
LOGW("CdmSession::StoreLicense: Reinitialization failed");
|
||||
return sts;
|
||||
}
|
||||
|
||||
key_set_id_.clear();
|
||||
return STORE_LICENSE_ERROR_1;
|
||||
}
|
||||
return NO_ERROR;
|
||||
@@ -533,11 +510,6 @@ CdmResponseType CdmSession::StoreLicense() {
|
||||
return STORE_LICENSE_ERROR_2;
|
||||
}
|
||||
|
||||
if (!file_handle_->Reset(security_level_)) {
|
||||
LOGE("CdmSession::StoreLicense: Unable to initialize device files");
|
||||
return STORE_LICENSE_ERROR_3;
|
||||
}
|
||||
|
||||
std::string app_id;
|
||||
GetApplicationId(&app_id);
|
||||
if (!file_handle_->StoreUsageInfo(provider_session_token, key_request_,
|
||||
@@ -549,8 +521,6 @@ CdmResponseType CdmSession::StoreLicense() {
|
||||
}
|
||||
|
||||
bool CdmSession::StoreLicense(DeviceFiles::LicenseState state) {
|
||||
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_,
|
||||
@@ -562,10 +532,6 @@ bool CdmSession::DeleteLicense() {
|
||||
if (!is_offline_ && license_parser_->provider_session_token().empty())
|
||||
return false;
|
||||
|
||||
if (!file_handle_->Reset(security_level_)) {
|
||||
LOGE("CdmSession::DeleteLicense: Unable to initialize device files");
|
||||
return false;
|
||||
}
|
||||
if (is_offline_) {
|
||||
return file_handle_->DeleteLicense(key_set_id_);
|
||||
} else {
|
||||
@@ -620,6 +586,7 @@ CdmResponseType CdmSession::ReleaseCrypto() {
|
||||
|
||||
void CdmSession::set_license_parser(CdmLicense* license_parser) {
|
||||
license_parser_.reset(license_parser);
|
||||
mock_license_parser_in_use_ = true;
|
||||
}
|
||||
|
||||
void CdmSession::set_crypto_session(CryptoSession* crypto_session) {
|
||||
@@ -628,6 +595,7 @@ void CdmSession::set_crypto_session(CryptoSession* crypto_session) {
|
||||
|
||||
void CdmSession::set_policy_engine(PolicyEngine* policy_engine) {
|
||||
policy_engine_.reset(policy_engine);
|
||||
mock_policy_engine_in_use_ = true;
|
||||
}
|
||||
|
||||
void CdmSession::set_file_handle(DeviceFiles* file_handle) {
|
||||
|
||||
Reference in New Issue
Block a user