These are a set of CLs merged from the wv cdm repo to the android repo. * Android build fixes Author: Rahul Frias <rfrias@google.com> [ Merge of http://go/wvgerrit/36322 ] * Address android compilation errors and warnings Author: Rahul Frias <rfrias@google.com> [ Merge of http://go/wvgerrit/36300 ] * Gyp cleanup and OpenSSL v10.1 support. Author: Gene Morgan <gmorgan@google.com> [ Merge of http://go/wvgerrit/36001 ] OpenSSL 10.1 has a small number of incompatible changes. A desktop system upgrade exposed some issue in the build scripts. Specifically, the linux build was using both third_party/protobufs (2.6.1) and the version installed on the system (3.0 in this case). The linux cdm.gyp depended on cdm/cdm.gyp which caused that plus some additional issues. These changes are necessary to support g++ version: g++ (Debian 6.3.0-18) 6.3.0 20170516 Also did some cosmetic rework on run_current_tests to make it easier to figure out what is going on when something fails. Also tweaked some of the compiler settings for g++ support (revisit this later). * Refactored Service Certificate encryption to allow encryption of arbitrary data. Author: Thomas Inskip <tinskip@google.com> [ Merge of http://go/wvgerrit/36141 ] * Send cdm test requests to UAT. Author: Jeff Fore <jfore@google.com> [ Merge of http://go/wvgerrit/36221 ] This change resolves the all of the CdmDecryptTest/CdmTestWithDecryptParam.DecryptToClearBuffer tests. The license servers will return different keys and keyids. Sending the request to staging returned key ids and keys that were not matching what was expected in the unit tests. * Fix for building L3 OEMCrypto with clang and libc++ Author: yucliu <yucliu@google.com> [ Merge of http://go/wvgerrit/35740 ] 1. Include <time.h> for time(time_t*). 2. Create endian check union on stack. Clang may create const union somewhere else, which may cause crash. * Remove error result when a sublicense session does not exist. This is not considered an error. Author: Jeff Fore <jfore@google.com> [ Merge of http://go/wvgerrit/36080 ] * Set default mock handler for GetSupportedCertificateTypes for all unit tests and removed the use of StrictMock from MockCryptoSession. Author: Jeff Fore <jfore@google.com> [ Merge of http://go/wvgerrit/35922 ] The handler for this was only set for one test and resulted in a number of failures. * Set default handler for GetHdcpCapabilities. For now the default action is to call the real GetHdcpCapabilities of crypto_session. Author: Jeff Fore <jfore@google.com> [ Merge of http://go/wvgerrit/36140 ] I also changed the mock to a NiceMock to silence responses to unexpected calls to GetHdcpCapabilities. The default handler can be overridden as needed in the individual tests. This resolves the policy engine test failures. * Finalize merge of cdm_partner_3.4 to master. Author: Gene Morgan <gmorgan@google.com> [ Merge of http://go/wvgerrit/35360 ] This is the final set of updates to merge all v3.4.1 changes into master. * Embedded license: Sublicense rotation. Author: Jeff Fore <jfore@google.com> [ Merge of http://go/wvgerrit/35360 ] Handle sublicense rotation event. * Embedded license: Initial license phase. Author: Jeff Fore <jfore@google.com> [ Merge of http://go/wvgerrit/34280 ] Initial license phase - key loading subsession. * Embedded license: generate session data. Author: Jeff Fore <jfore@google.com> [ Merge of http://go/wvgerrit/33722 ] Generate session data and add it to the license request for any embedded license material. * Resolve missing symbol when building cd-cdm Author: Jeff Fore <jfore@google.com> [ Merge of http://go/wvgerrit/35840 ] * C++11: Replace OVERRIDE def with override keyword Author: Gene Morgan <gmorgan@google.com> [ Merge of http://go/wvgerrit/35400 ] BUG: 71650075 Test: Not currently passing. Will be addressed in a subsequent commit in the chain. Change-Id: I37d0cb17f255ac6389030047d616ad69f895748c
181 lines
7.1 KiB
C++
181 lines
7.1 KiB
C++
// Copyright 2013 Google Inc. All Rights Reserved.
|
|
|
|
#ifndef CDM_BASE_WV_CONTENT_DECRYPTION_MODULE_H_
|
|
#define CDM_BASE_WV_CONTENT_DECRYPTION_MODULE_H_
|
|
|
|
#include <map>
|
|
|
|
#include <UniquePtr.h>
|
|
#include <utils/RefBase.h>
|
|
|
|
#include "cdm_identifier.h"
|
|
#include "file_store.h"
|
|
#include "lock.h"
|
|
#include "metrics.pb.h"
|
|
#include "timer.h"
|
|
#include "wv_cdm_types.h"
|
|
|
|
namespace wvcdm {
|
|
|
|
class CdmClientPropertySet;
|
|
class CdmEngine;
|
|
class WvCdmEventListener;
|
|
|
|
class WvContentDecryptionModule : public android::RefBase, public TimerHandler {
|
|
public:
|
|
WvContentDecryptionModule();
|
|
virtual ~WvContentDecryptionModule();
|
|
|
|
// Static methods
|
|
static bool IsSupported(const std::string& init_data_type);
|
|
static bool IsCenc(const std::string& init_data_type);
|
|
static bool IsWebm(const std::string& init_data_type);
|
|
static bool IsHls(const std::string& init_data_type);
|
|
|
|
// Session related methods
|
|
virtual CdmResponseType OpenSession(const CdmKeySystem& key_system,
|
|
CdmClientPropertySet* property_set,
|
|
const CdmIdentifier& identifier,
|
|
WvCdmEventListener* event_listener,
|
|
CdmSessionId* session_id);
|
|
virtual CdmResponseType CloseSession(const CdmSessionId& session_id);
|
|
virtual bool IsOpenSession(const CdmSessionId& session_id);
|
|
|
|
// Construct a valid license request.
|
|
virtual CdmResponseType GenerateKeyRequest(const CdmSessionId& session_id,
|
|
const CdmKeySetId& key_set_id,
|
|
const std::string& init_data_type,
|
|
const CdmInitData& init_data,
|
|
const CdmLicenseType license_type,
|
|
CdmAppParameterMap& app_parameters,
|
|
CdmClientPropertySet* property_set,
|
|
const CdmIdentifier& identifier,
|
|
CdmKeyRequest* key_request);
|
|
|
|
// Accept license response and extract key info.
|
|
virtual CdmResponseType AddKey(const CdmSessionId& session_id,
|
|
const CdmKeyResponse& key_data,
|
|
CdmKeySetId* key_set_id);
|
|
|
|
// Setup keys for offline usage which were retrived in an earlier key request
|
|
virtual CdmResponseType RestoreKey(const CdmSessionId& session_id,
|
|
const CdmKeySetId& key_set_id);
|
|
|
|
// Cancel session
|
|
virtual CdmResponseType RemoveKeys(const CdmSessionId& session_id);
|
|
|
|
// Query system information
|
|
virtual CdmResponseType QueryStatus(SecurityLevel security_level,
|
|
const std::string& key,
|
|
std::string* value);
|
|
// Query session information
|
|
virtual CdmResponseType QuerySessionStatus(const CdmSessionId& session_id,
|
|
CdmQueryMap* key_info);
|
|
|
|
// Query license information
|
|
virtual CdmResponseType QueryKeyStatus(const CdmSessionId& session_id,
|
|
CdmQueryMap* key_info);
|
|
|
|
// Query OEMCrypto session ID
|
|
virtual CdmResponseType QueryOemCryptoSessionId(const CdmSessionId& session_id,
|
|
CdmQueryMap* response);
|
|
|
|
// Provisioning related methods
|
|
virtual CdmResponseType GetProvisioningRequest(
|
|
CdmCertificateType cert_type,
|
|
const std::string& cert_authority,
|
|
const CdmIdentifier& identifier,
|
|
CdmProvisioningRequest* request,
|
|
std::string* default_url);
|
|
|
|
virtual CdmResponseType HandleProvisioningResponse(
|
|
const CdmIdentifier& identifier,
|
|
CdmProvisioningResponse& response,
|
|
std::string* cert,
|
|
std::string* wrapped_key);
|
|
|
|
virtual CdmResponseType Unprovision(CdmSecurityLevel level,
|
|
const CdmIdentifier& identifier);
|
|
|
|
// Secure stop related methods
|
|
virtual CdmResponseType GetUsageInfo(const std::string& app_id,
|
|
const CdmIdentifier& identifier,
|
|
CdmUsageInfo* usage_info);
|
|
virtual CdmResponseType GetUsageInfo(const std::string& app_id,
|
|
const CdmSecureStopId& ssid,
|
|
const CdmIdentifier& identifier,
|
|
CdmUsageInfo* usage_info);
|
|
virtual CdmResponseType ReleaseAllUsageInfo(const std::string& app_id,
|
|
const CdmIdentifier& identifier);
|
|
virtual CdmResponseType ReleaseUsageInfo(
|
|
const CdmUsageInfoReleaseMessage& message,
|
|
const CdmIdentifier& identifier);
|
|
|
|
// Accept encrypted buffer and decrypt data.
|
|
// Decryption parameters that need to be specified are
|
|
// is_encrypted, is_secure, key_id, encrypt_buffer, encrypt_length,
|
|
// iv, block_offset, decrypt_buffer, decrypt_buffer_length,
|
|
// decrypt_buffer_offset and subsample_flags
|
|
virtual CdmResponseType Decrypt(const CdmSessionId& session_id,
|
|
bool validate_key_id,
|
|
const CdmDecryptionParameters& parameters);
|
|
|
|
virtual void NotifyResolution(const CdmSessionId& session_id, uint32_t width,
|
|
uint32_t height);
|
|
|
|
// Validate a passed-in service certificate
|
|
virtual bool IsValidServiceCertificate(const std::string& certificate);
|
|
|
|
// Retrieve the serialized metrics from CdmEngine and CdmSession instances
|
|
// that have been closed.
|
|
virtual void GetSerializedMetrics(std::string* serialized_metrics);
|
|
|
|
private:
|
|
struct CdmInfo {
|
|
CdmInfo();
|
|
|
|
FileSystem file_system;
|
|
UniquePtr<CdmEngine> cdm_engine;
|
|
};
|
|
|
|
// Finds the CdmEngine instance for the given identifier, creating one if
|
|
// needed.
|
|
CdmEngine* EnsureCdmForIdentifier(const CdmIdentifier& identifier);
|
|
// Finds the CdmEngine instance for the given session id, returning NULL if
|
|
// not found.
|
|
CdmEngine* GetCdmForSessionId(const std::string& session_id);
|
|
// Closes CdmEngine instances that don't have any open sessions. Also stores
|
|
// metrics data for closed CdmEngine instances.
|
|
// Callers must acquire the cdms_lock_ before calling this method.
|
|
void CloseCdmsWithoutSessions();
|
|
|
|
uint32_t GenerateSessionSharingId();
|
|
|
|
// timer related methods to drive policy decisions
|
|
void EnablePolicyTimer();
|
|
void DisablePolicyTimer(); // Disable if all cdm engines are closed.
|
|
void ForceDisablePolicyTimer(); // Force disable the policy timer.
|
|
void OnTimerEvent();
|
|
|
|
static Lock session_sharing_id_generation_lock_;
|
|
Lock policy_timer_lock_;
|
|
Timer policy_timer_;
|
|
|
|
// instance variables
|
|
// This manages the lifetime of the CDM instances.
|
|
std::map<CdmIdentifier, CdmInfo> cdms_;
|
|
Lock cdms_lock_;
|
|
|
|
// This contains weak pointers to the CDM instances contained in |cdms_|.
|
|
std::map<std::string, CdmEngine*> cdm_by_session_id_;
|
|
|
|
// The metrics for cdm engines and sessions that have been closed.
|
|
drm_metrics::MetricsGroup metrics_;
|
|
|
|
CORE_DISALLOW_COPY_AND_ASSIGN(WvContentDecryptionModule);
|
|
};
|
|
|
|
} // namespace wvcdm
|
|
|
|
#endif // CDM_BASE_WV_CONTENT_DECRYPTION_MODULE_H_
|