In the android media DRM api test, provisioning is indicated, when a generate license request command is issued after a switch between L1 and L3. This is as expected as oemcrypto is unable to decrypt the key wrapped earlier (bad padding). Subsequent provisioning request and storage of wrapped keys complete successfully. If the same session is used to reissue a generate license request command, the wrapped keys and cert used are those present in memory from the initial retrival, rather than rereading the new ones from persistent storage. This results in a cycle of successful provisioning attempts followed by generation of license requests commands which return a provisioning needed error. A change has been added to reinitialize the session and reload the wrapped keys. b/8878324 Merge of https://widevine-internal-review.googlesource.com/#/c/5600/ from the Widevine CDM repository. Change-Id: Iaf47d15d104fd681706df5f64be583af24186abe
116 lines
3.4 KiB
C++
116 lines
3.4 KiB
C++
// Copyright 2012 Google Inc. All Rights Reserved.
|
|
|
|
#ifndef CDM_BASE_CDM_SESSION_H_
|
|
#define CDM_BASE_CDM_SESSION_H_
|
|
|
|
#include <set>
|
|
|
|
#include "crypto_session.h"
|
|
#include "license.h"
|
|
#include "policy_engine.h"
|
|
#include "wv_cdm_event_listener.h"
|
|
#include "wv_cdm_types.h"
|
|
|
|
namespace wvcdm {
|
|
|
|
// TODO(kqyang): Do we need it? CdmKey not defined yet
|
|
// typedef std::map<KeyId, CdmKey*> CdmSessionKeys;
|
|
|
|
class CdmSession {
|
|
public:
|
|
CdmSession() : session_id_(GenerateSessionId()), license_received_(false),
|
|
reinitialize_session_(false) {}
|
|
~CdmSession() {}
|
|
|
|
CdmResponseType Init();
|
|
CdmResponseType ReInit();
|
|
|
|
bool DestroySession();
|
|
|
|
void set_key_system(const CdmKeySystem& ksystem) { key_system_ = ksystem; }
|
|
const CdmKeySystem& key_system() { return key_system_; }
|
|
|
|
const CdmSessionId& session_id() { return session_id_; }
|
|
|
|
bool VerifySession(const CdmKeySystem& key_system,
|
|
const CdmInitData& init_data);
|
|
|
|
CdmResponseType GenerateKeyRequest(const CdmInitData& init_data,
|
|
const CdmLicenseType license_type,
|
|
CdmAppParameterMap& app_parameters,
|
|
CdmKeyMessage* key_request,
|
|
std::string* server_url);
|
|
|
|
// AddKey() - Accept license response and extract key info.
|
|
CdmResponseType AddKey(const CdmKeyResponse& key_response);
|
|
|
|
// CancelKeyRequest() - Cancel session.
|
|
CdmResponseType CancelKeyRequest();
|
|
|
|
// Query license information
|
|
CdmResponseType QueryKeyStatus(CdmQueryMap* key_info);
|
|
|
|
// Query session control info
|
|
CdmResponseType QueryKeyControlInfo(CdmQueryMap* key_info);
|
|
|
|
// Decrypt() - Accept encrypted buffer and return decrypted data.
|
|
CdmResponseType Decrypt(bool is_encrypted,
|
|
bool is_secure,
|
|
const KeyId& key_id,
|
|
const uint8_t* encrypt_buffer,
|
|
size_t encrypt_length,
|
|
const std::vector<uint8_t>& iv,
|
|
size_t block_offset,
|
|
void* decrypt_buffer,
|
|
size_t decrypt_buffer_offset,
|
|
bool is_video);
|
|
|
|
// License renewal
|
|
// GenerateRenewalRequest() - Construct valid renewal request for the current
|
|
// session keys.
|
|
CdmResponseType GenerateRenewalRequest(CdmKeyMessage* key_request,
|
|
std::string* server_url);
|
|
|
|
// RenewKey() - Accept renewal response and update key info.
|
|
CdmResponseType RenewKey(const CdmKeyResponse& key_response);
|
|
|
|
bool IsKeyValid(const KeyId& key_id);
|
|
|
|
bool AttachEventListener(WvCdmEventListener* listener);
|
|
bool DetachEventListener(WvCdmEventListener* listener);
|
|
|
|
void OnTimerEvent();
|
|
|
|
private:
|
|
|
|
// Generate unique ID for each new session.
|
|
CdmSessionId GenerateSessionId();
|
|
|
|
bool LoadDeviceCertificate(std::string* cert, std::string* wrapped_key);
|
|
|
|
// instance variables
|
|
const CdmSessionId session_id_;
|
|
CdmKeySystem key_system_;
|
|
CdmLicense license_parser_;
|
|
CryptoSession* crypto_session_;
|
|
PolicyEngine policy_engine_;
|
|
bool license_received_;
|
|
bool reinitialize_session_;
|
|
|
|
KeyId key_id_;
|
|
|
|
// Used for certificate based licensing
|
|
std::string wrapped_key_;
|
|
|
|
std::set<WvCdmEventListener*> listeners_;
|
|
|
|
// TODO(kqyang): CdmKey not defined yet
|
|
// CdmSessionKeys session_keys_;
|
|
|
|
CORE_DISALLOW_COPY_AND_ASSIGN(CdmSession);
|
|
};
|
|
|
|
} // namespace wvcdm
|
|
|
|
#endif // CDM_BASE_CDM_SESSION_H_
|