Source release v2.1.3-2-789 + third_party libs

Change-Id: I8648756dab3fe1f53d6da18b83cd1294581d1abe
This commit is contained in:
Joey Parrish
2014-06-19 17:13:42 -07:00
parent 73445a920c
commit 84acd5a15e
32 changed files with 1340 additions and 1335 deletions

View File

@@ -91,12 +91,14 @@
'../core/src/privacy_crypto_dummy.cpp', '../core/src/privacy_crypto_dummy.cpp',
], ],
}], }],
], ['oemcrypto_v8=="true"', {
'direct_dependencies': [ 'sources!': [ # exclude
'device_files', '../core/src/oemcrypto_adapter_static.cpp',
'license_protocol', ],
], 'sources': [ # include
'conditions': [ '../core/src/oemcrypto_adapter_static_v8.cpp',
],
}],
['use_system_protobuf=="true"', { ['use_system_protobuf=="true"', {
'direct_dependent_settings': { 'direct_dependent_settings': {
'libraries': [ 'libraries': [

View File

@@ -21,6 +21,7 @@ class HostClock {
private: private:
static IClock* impl_; static IClock* impl_;
}; };
} // namspace wvcdm } // namspace wvcdm
#endif // WVCDM_CDM_CDM_HOST_CLOCK_H_ #endif // WVCDM_CDM_CDM_HOST_CLOCK_H_

View File

@@ -13,31 +13,37 @@ class IFileFactory;
class File::Impl { class File::Impl {
public: public:
explicit Impl(cdm::Host* const host) : host_(host) {} explicit Impl(cdm::Host* const host) : host_(host) {}
FILE* file_;
static void RegisterFileFactory(IFileFactory* factory) { static void RegisterFileFactory(IFileFactory* factory) {
factory_ = factory; factory_ = factory;
} }
static IFileFactory* factory_;
virtual bool Exists(const std::string& name); virtual bool Exists(const std::string& name);
virtual bool Open(const std::string& name); virtual bool Open(const std::string& name);
virtual bool Close(); virtual bool Close();
virtual bool Remove(const std::string& name); virtual bool Remove(const std::string& name);
virtual size_t Read(char* buffer, size_t bytes); virtual ssize_t Read(char* buffer, size_t bytes);
virtual size_t Write(const char* buffer, size_t bytes); virtual ssize_t Write(const char* buffer, size_t bytes);
virtual size_t FileSize(const std::string& name); virtual ssize_t FileSize(const std::string& name);
private: private:
static IFileFactory* factory_;
friend class File;
cdm::Host* const host_; cdm::Host* const host_;
std::string fname_; std::string fname_;
}; };
class IFileFactory { class IFileFactory {
protected: protected:
IFileFactory(){File::Impl::RegisterFileFactory(this);} IFileFactory() {
virtual ~IFileFactory(){} File::Impl::RegisterFileFactory(this);
}
virtual ~IFileFactory() {}
public: public:
virtual File::Impl* NewFileImpl () = 0; virtual File::Impl* NewFileImpl() = 0;
}; };
} // namespace wvcdm } // namespace wvcdm

View File

@@ -269,6 +269,9 @@ class ContentDecryptionModule_1 {
const uint8_t* key, int key_size, const uint8_t* key, int key_size,
const uint8_t* key_id, int key_id_size) = 0; const uint8_t* key_id, int key_id_size) = 0;
// Tests whether |key_id| is known to any current session.
virtual bool IsKeyValid(const uint8_t* key_id, int key_id_size) = 0;
// Cancels any pending key request made to the CDM for |session_id|. // Cancels any pending key request made to the CDM for |session_id|.
// //
// Returns kSuccess if all pending key requests for |session_id| were // Returns kSuccess if all pending key requests for |session_id| were
@@ -293,80 +296,6 @@ class ContentDecryptionModule_1 {
virtual Status Decrypt(const InputBuffer& encrypted_buffer, virtual Status Decrypt(const InputBuffer& encrypted_buffer,
DecryptedBlock* decrypted_buffer) = 0; DecryptedBlock* decrypted_buffer) = 0;
// Initializes the CDM audio decoder with |audio_decoder_config|.
// This function is only needed if DecryptAndDecodeSamples() or
// DecryptDecodeAndRenderSamples() is used. It must be called before either
// of these routines is called.
//
// Returns kSuccess if the |audio_decoder_config| is supported and the CDM
// audio decoder is successfully initialized.
// Returns kSessionError if |audio_decoder_config| is not supported. The CDM
// may still be able to do Decrypt().
//
virtual Status InitializeAudioDecoder(
const AudioDecoderConfig& audio_decoder_config) = 0;
// Initializes the CDM video decoder with |video_decoder_config|.
// This function is only needed if DecryptAndDecodeFrame() or
// DecryptDecodeAndRenderFrame() is used. It must be called before either
// of these routines is called.
//
// Returns kSuccess if the |video_decoder_config| is supported and the CDM
// video decoder is successfully initialized.
// Returns kSessionError if |video_decoder_config| is not supported. The CDM
// may still be able to do Decrypt().
//
virtual Status InitializeVideoDecoder(
const VideoDecoderConfig& video_decoder_config) = 0;
// De-initializes the CDM decoder and sets it to an uninitialized state. The
// caller can initialize the decoder again after this call to re-initialize
// it. This can be used to reconfigure the decoder if the configuration
// changes.
virtual void DeinitializeDecoder(StreamType decoder_type) = 0;
// Resets the CDM decoder to an initialized clean state. All internal buffers
// MUST be flushed.
virtual void ResetDecoder(StreamType decoder_type) = 0;
// Decrypts the |encrypted_buffer| and decodes the decrypted buffer into a
// |video_frame|. Upon end-of-stream, the caller should call this function
// repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
// |video_frame| (|format| == kEmptyVideoFrame) is produced.
//
// Returns kSuccess if decryption and decoding both succeeded, in which case
// the callee will have filled the |video_frame| and passed the ownership of
// |frame_buffer| in |video_frame| to the caller.
// Returns kNoKey if the CDM did not have the necessary decryption key
// to decrypt.
// Returns kNeedMoreData if more data was needed by the decoder to generate
// a decoded frame (e.g. during initialization and end-of-stream).
// Returns kDecryptError if any decryption error happened.
// Returns kDecodeError if any decoding error happened.
// If the return value is not kSuccess, |video_frame| should be ignored by
// the caller.
virtual Status DecryptAndDecodeFrame(const InputBuffer& encrypted_buffer,
VideoFrame* video_frame) = 0;
// Decrypts the |encrypted_buffer| and decodes the decrypted buffer into
// |audio_frames|. Upon end-of-stream, the caller should call this function
// repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
// |audio_frames| is produced.
//
// Returns kSuccess if decryption and decoding both succeeded, in which case
// the callee will have filled |audio_frames| and passed the ownership of
// |data| in |audio_frames| to the caller.
// Returns kNoKey if the CDM did not have the necessary decryption key
// to decrypt.
// Returns kNeedMoreData if more data was needed by the decoder to generate
// audio samples (e.g. during initialization and end-of-stream).
// Returns kDecryptError if any decryption error happened.
// Returns kDecodeError if any decoding error happened.
// If the return value is not kSuccess, |audio_frames| should be ignored by
// the caller.
virtual Status DecryptAndDecodeSamples(const InputBuffer& encrypted_buffer,
AudioFrames* audio_frames) = 0;
// Decrypts the |encrypted_buffer|, decodes the decrypted buffer into a // Decrypts the |encrypted_buffer|, decodes the decrypted buffer into a
// video frame, and passes the frame to the rendering FW/HW. No data // video frame, and passes the frame to the rendering FW/HW. No data
// is returned. // is returned.
@@ -471,28 +400,18 @@ class Host_1 {
MediaKeyError error_code, MediaKeyError error_code,
uint32_t system_code) = 0; uint32_t system_code) = 0;
// Get private data from the host. This function is limited to internal use. // Version 1.3:
typedef const void* (*GetPrivateInterface)(const char* interface_name); // These virtual member functions extend the cdm::Host interface to allow
virtual void GetPrivateData(int32_t* instance, // the CDM to query the host for various information.
GetPrivateInterface* get_interface) = 0;
//Version 1.3 // Asks the host to persist a name-value pair.
// These Virtual member functions extend the cdm::Host interface to allow virtual void SetPlatformString(const std::string& name,
// the sharing for platform specific information, between the cdm::Host and const std::string& value) = 0;
// the CDM.
virtual int GetPlatformString(const std::string& name, // Retrieves a value by name. If there is no such value, the Host should
std::string* value) = 0; // set value to an empty string.
virtual int SetPlatformString(const std::string& name, virtual void GetPlatformString(const std::string& name,
const std::string& value) = 0; std::string* value) = 0;
virtual int PersistPlatformString(const std::string& name,
const std::string& value) = 0;
virtual int GetPlatformByteArray(const std::string& name,
std::vector<uint8_t>* value) = 0;
virtual int SetPlatformByteArray(const std::string& name,
const std::vector<uint8_t>& value) = 0;
virtual int PersistPlatformByteArray(const std::string& name,
const std::vector<uint8_t>& value) = 0;
protected: protected:
Host_1() {} Host_1() {}

View File

@@ -1,3 +1,3 @@
// Widevine CDM Kit Version // Widevine CDM Kit Version
#define WV_CDM_VERSION "v2.1.2-0-773" #define WV_CDM_VERSION "v2.1.3-2-789"

View File

@@ -28,7 +28,7 @@ class WVClientPropertySet : public wvcdm::CdmClientPropertySet {
security_level_ = securityLevel; security_level_ = securityLevel;
} }
virtual std::string security_level() const { virtual const std::string& security_level() const {
return security_level_; return security_level_;
} }
@@ -40,11 +40,11 @@ class WVClientPropertySet : public wvcdm::CdmClientPropertySet {
return use_privacy_mode_; return use_privacy_mode_;
} }
void set_service_certificate(const std::vector<uint8_t>& serviceCertificate) { void set_service_certificate(const std::string& serviceCertificate) {
service_certificate_ = serviceCertificate; service_certificate_ = serviceCertificate;
} }
virtual std::vector<uint8_t> service_certificate() const { virtual const std::string& service_certificate() const {
return service_certificate_; return service_certificate_;
} }
@@ -67,24 +67,23 @@ class WVClientPropertySet : public wvcdm::CdmClientPropertySet {
return; // This is unused by common cdm but we need a return; // This is unused by common cdm but we need a
// definition for the pure virtual methods. // definition for the pure virtual methods.
} }
private: private:
CORE_DISALLOW_COPY_AND_ASSIGN(WVClientPropertySet); CORE_DISALLOW_COPY_AND_ASSIGN(WVClientPropertySet);
std::string security_level_; std::string security_level_;
bool use_privacy_mode_; bool use_privacy_mode_;
std::vector<uint8_t> service_certificate_; std::string service_certificate_;
}; };
class WvContentDecryptionModule : public cdm::ContentDecryptionModule, class WvContentDecryptionModule : public cdm::ContentDecryptionModule,
public IFileFactory, public IFileFactory,
public IClock { public IClock {
File::Impl* NewFileImpl() { return new File::Impl(host_); }
public: public:
explicit WvContentDecryptionModule(cdm::Host* host) explicit WvContentDecryptionModule(cdm::Host* host);
: host_(host), host_event_listener_(host, &cdm_engine_) {
HostClock::SetClockInterface(this);
}
virtual ~WvContentDecryptionModule(); virtual ~WvContentDecryptionModule();
// cdm::ContentDecryptionModule implementation. // cdm::ContentDecryptionModule implementation.
virtual cdm::Status GenerateKeyRequest(const char* type, int type_size, virtual cdm::Status GenerateKeyRequest(const char* type, int type_size,
const uint8_t* init_data, const uint8_t* init_data,
@@ -94,6 +93,8 @@ class WvContentDecryptionModule : public cdm::ContentDecryptionModule,
const uint8_t* key, int key_size, const uint8_t* key, int key_size,
const uint8_t* key_id, int key_id_size) OVERRIDE; const uint8_t* key_id, int key_id_size) OVERRIDE;
virtual bool IsKeyValid(const uint8_t* key_id, int key_id_size) OVERRIDE;
virtual cdm::Status CancelKeyRequest(const char* session_id, virtual cdm::Status CancelKeyRequest(const char* session_id,
int session_id_size) OVERRIDE; int session_id_size) OVERRIDE;
@@ -102,24 +103,6 @@ class WvContentDecryptionModule : public cdm::ContentDecryptionModule,
virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer, virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer,
cdm::DecryptedBlock* decrypted_buffer) OVERRIDE; cdm::DecryptedBlock* decrypted_buffer) OVERRIDE;
virtual cdm::Status InitializeAudioDecoder(
const cdm::AudioDecoderConfig& audio_decoder_config) OVERRIDE;
virtual cdm::Status InitializeVideoDecoder(
const cdm::VideoDecoderConfig& video_decoder_config) OVERRIDE;
virtual void DeinitializeDecoder(cdm::StreamType decoder_type) OVERRIDE;
virtual void ResetDecoder(cdm::StreamType decoder_type) OVERRIDE;
virtual cdm::Status DecryptAndDecodeFrame(
const cdm::InputBuffer& encrypted_buffer,
cdm::VideoFrame* video_frame) OVERRIDE;
virtual cdm::Status DecryptAndDecodeSamples(
const cdm::InputBuffer& encrypted_buffer,
cdm::AudioFrames* audio_frames) OVERRIDE;
virtual cdm::Status DecryptDecodeAndRenderFrame( virtual cdm::Status DecryptDecodeAndRenderFrame(
const cdm::InputBuffer& encrypted_buffer) OVERRIDE; const cdm::InputBuffer& encrypted_buffer) OVERRIDE;
@@ -128,29 +111,30 @@ class WvContentDecryptionModule : public cdm::ContentDecryptionModule,
virtual void Destroy() OVERRIDE; virtual void Destroy() OVERRIDE;
// Provisioning related methods
virtual cdm::Status GetProvisioningRequest( virtual cdm::Status GetProvisioningRequest(
std::string* request, std::string* default_url); std::string* request, std::string* default_url) OVERRIDE;
virtual cdm::Status HandleProvisioningResponse( virtual cdm::Status HandleProvisioningResponse(
std::string& response); std::string& response) OVERRIDE;
void EnablePolicyTimer();
void DisablePolicyTimer();
void OnTimerEvent();
private: private:
virtual int64_t GetCurrentTimeInSeconds() { void EnablePolicyTimer();
return host_->GetCurrentWallTimeInSeconds(); void DisablePolicyTimer();
}
virtual File::Impl* NewFileImpl() OVERRIDE;
virtual int64_t GetCurrentTimeInSeconds() OVERRIDE;
cdm::Status DoSubsampleDecrypt(CdmDecryptionParameters& parameters, cdm::Status DoSubsampleDecrypt(CdmDecryptionParameters& parameters,
std::vector<uint8_t>& iv, std::vector<uint8_t>& iv,
const cdm::InputBuffer& encrypted_buffer, const cdm::InputBuffer& encrypted_buffer,
cdm::DecryptedBlock* decrypted_block); cdm::DecryptedBlock* decrypted_block);
CdmEngine cdm_engine_; CdmEngine cdm_engine_;
cdm::Host* const host_; cdm::Host* const host_;
HostEventListener host_event_listener_; HostEventListener host_event_listener_;
WVClientPropertySet property_set_; WVClientPropertySet property_set_;
bool timer_enabled_;
CORE_DISALLOW_COPY_AND_ASSIGN(WvContentDecryptionModule); CORE_DISALLOW_COPY_AND_ASSIGN(WvContentDecryptionModule);
}; };

View File

@@ -6,7 +6,7 @@
namespace wvcdm { namespace wvcdm {
IFileFactory* File::Impl::factory_ = NULL; IFileFactory* File::Impl::factory_ = NULL;
// File::Impl() Section // File::Impl() Section
// The file handler for cert.bin, aka DeviceCertificate is all we're // The file handler for cert.bin, aka DeviceCertificate is all we're
@@ -14,68 +14,60 @@ IFileFactory* File::Impl::factory_ = NULL;
bool File::Impl::Exists(const std::string& name) { bool File::Impl::Exists(const std::string& name) {
if (name == "cert.bin") { if (name == "cert.bin") {
std::vector<uint8_t> value; std::string value;
if (host_->GetPlatformByteArray("DeviceCertificate", &value)) { host_->GetPlatformString("DeviceCertificate", &value);
return true; return !value.empty();
}
} }
return false; return false;
} }
bool File::Impl::Open(const std::string& name) { bool File::Impl::Open(const std::string& name) {
if (name == "cert.bin") { if (name == "cert.bin") {
fname_= name; fname_ = name;
return true; return true;
} }
return false; return false;
} }
bool File::Impl::Close() { bool File::Impl::Close() {
fname_ = ""; fname_.clear();
return true; return true;
} }
bool File::Impl::Remove(const std::string& name) { bool File::Impl::Remove(const std::string& name) {
if (Exists(name)) { if (name == "cert.bin") {
std::vector<uint8_t> value(0); host_->SetPlatformString("DeviceCertificate", "");
if (host_->SetPlatformByteArray("DeviceCertificate", value)) { return true;
return true;
}
} }
return false; return false;
} }
size_t File::Impl::Read(char* buffer, size_t bytes) { ssize_t File::Impl::Read(char* buffer, size_t bytes) {
if (fname_ == "cert.bin") {
std::vector<uint8_t> value;
if (host_->GetPlatformByteArray("DeviceCertificate", &value)) {
memcpy(buffer, &value[0], bytes);
return bytes;
}
}
return 0;
}
size_t File::Impl::Write(const char* buffer, size_t bytes) {
if (fname_ == "cert.bin") { if (fname_ == "cert.bin") {
std::vector<uint8_t> value; std::string value;
value.resize(bytes); host_->GetPlatformString("DeviceCertificate", &value);
memcpy(&value[0], buffer, bytes); memcpy(buffer, value.data(), std::min(bytes, value.size()));
if (host_->PersistPlatformByteArray("DeviceCertificate", value)) { return value.size() ? value.size() : -1;
return bytes;
}
} }
return 0; return -1;
} }
size_t File::Impl::FileSize(const std::string& name) { ssize_t File::Impl::Write(const char* buffer, size_t bytes) {
if (name == "cert.bin") { if (fname_ == "cert.bin") {
std::vector<uint8_t> value; std::string value(buffer, bytes);
if (host_->GetPlatformByteArray("DeviceCertificate", &value)) { host_->SetPlatformString("DeviceCertificate", value);
return value.size(); return bytes;
}
} }
return 0; return -1;
}
ssize_t File::Impl::FileSize(const std::string& name) {
if (name == "cert.bin") {
std::string value;
host_->GetPlatformString("DeviceCertificate", &value);
return value.size() ? value.size() : -1;
}
return -1;
} }
File::File() : impl_(File::Impl::factory_->NewFileImpl()) {} File::File() : impl_(File::Impl::factory_->NewFileImpl()) {}
@@ -91,7 +83,6 @@ bool File::Open(const std::string& name, int flags) {
void File::Close() { void File::Close() {
impl_->Close(); impl_->Close();
return;
} }
ssize_t File::Read(char* buffer, size_t bytes) { ssize_t File::Read(char* buffer, size_t bytes) {
@@ -136,11 +127,7 @@ bool File::IsRegularFile(const std::string& path) {
} }
ssize_t File::FileSize(const std::string& path) { ssize_t File::FileSize(const std::string& path) {
size_t size = impl_->FileSize(path); return impl_->FileSize(path);
if (size > 0) {
return size;
}
return -1;
} }
} // namespace wvcdm } // namespace wvcdm

View File

@@ -3,7 +3,6 @@
#include "properties.h" #include "properties.h"
#include <string> #include <string>
#include <sys/utsname.h>
#include "log.h" #include "log.h"

View File

@@ -1,76 +0,0 @@
// Copyright 2013 Google Inc. All Rights Reserved.
//
// Timer class - provides a simple timer implementation
//
#include "cdm_host_timer.h"
#include "scoped_ptr.h"
#include "timer.h"
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
namespace wvcdm {
ITimerFactory* Timer::Impl::factory_ = NULL;
Timer::Impl::Impl(cdm::Host* const host)
: host_(host), handler_(NULL), delay_ms_(0),
state_(kIdle) {
}
void Timer::Impl::RegisterTimerFactory(ITimerFactory* factory) {
factory_ = factory;
}
void Timer::Impl::Start(TimerHandler* handler, uint32_t time_in_secs) {
handler_ = handler;
delay_ms_ = time_in_secs * 1000;
state_ = kRunning;
host_->SetTimer(delay_ms_, this);
}
void Timer::Impl::OnTimerEvent() {
if (kRunning == state_) {
handler_->OnTimerEvent();
host_->SetTimer(delay_ms_, this);
}
}
void Timer::Impl::Stop() {
state_ = kIdle;
}
Timer::Timer() : impl_(NULL) {}
Timer::~Timer() {
if (impl_)
delete impl_;
}
bool Timer::Start(TimerHandler* handler, uint32_t time_in_secs) {
if (!handler || 0 == time_in_secs)
return false;
if (!impl_ && Impl::factory_)
impl_ = Impl::factory_->NewTimerImpl();
if(!impl_)
return false;
impl_->Start(handler, time_in_secs);
return IsRunning();
}
void Timer::Stop() {
if (impl_)
impl_->Stop();
}
bool Timer::IsRunning() {
if (!impl_)
return false;
return impl_->IsRunning();
}
} // namespace wvcdm

View File

@@ -2,17 +2,14 @@
#include "wv_content_decryption_module.h" #include "wv_content_decryption_module.h"
#include <iostream>
#include <string.h> #include <string.h>
#include "cdm_client_property_set.h" #include <iostream>
#include "content_decryption_module.h"
#include "initialization_data.h"
#include "initialization_data.h"
#include "log.h" #include "log.h"
#include "OEMCryptoCENC.h" #include "OEMCryptoCENC.h"
#include "properties.h" #include "properties.h"
#include "wv_cdm_constants.h" #include "wv_cdm_constants.h"
#include "wv_cdm_types.h" #include "wv_cdm_types.h"
#include "wv_cdm_version.h" #include "wv_cdm_version.h"
@@ -38,10 +35,10 @@ void* CreateCdmInstance(int cdm_interface_version, const char* key_system,
int GetCdmVersion() { return cdm::kCdmInterfaceVersion; } int GetCdmVersion() { return cdm::kCdmInterfaceVersion; }
namespace { namespace {
static const std::string kWvCdmVersionString(WV_CDM_VERSION); static const std::string kWvCdmVersionString(WV_CDM_VERSION);
const int kCdmPolicyTimerDurationSeconds = 1; const int kCdmPolicyTimerDurationSeconds = 5;
const int kCdmPolicyTimerCancel = 0;
// The iso spec only uses the lower 8 bytes of the iv as // The iso spec only uses the lower 8 bytes of the iv as
// the counter. // the counter.
@@ -69,6 +66,7 @@ bool Ctr128Add(size_t block_count, uint8_t* counter) {
} }
return true; return true;
} }
} // namespace } // namespace
namespace wvcdm { namespace wvcdm {
@@ -80,6 +78,13 @@ bool IsBufferEncrypted(const cdm::InputBuffer& input_buffer) {
// cdm::ContentDecryptionModule implementation. // cdm::ContentDecryptionModule implementation.
WvContentDecryptionModule::WvContentDecryptionModule(cdm::Host* host)
: host_(host),
host_event_listener_(host, &cdm_engine_),
timer_enabled_(false) {
HostClock::SetClockInterface(this);
}
WvContentDecryptionModule::~WvContentDecryptionModule() { WvContentDecryptionModule::~WvContentDecryptionModule() {
DisablePolicyTimer(); DisablePolicyTimer();
} }
@@ -87,7 +92,7 @@ WvContentDecryptionModule::~WvContentDecryptionModule() {
cdm::Status WvContentDecryptionModule::GenerateKeyRequest( cdm::Status WvContentDecryptionModule::GenerateKeyRequest(
const char* type, int type_size, const uint8_t* init_data, const char* type, int type_size, const uint8_t* init_data,
int init_data_size) { int init_data_size) {
LOGI("Enter WvContentDecryptionModule::GenerateKeyRequest()"); LOGI("WvContentDecryptionModule::GenerateKeyRequest()");
CdmInitData init_data_internal(reinterpret_cast<const char*>(init_data), CdmInitData init_data_internal(reinterpret_cast<const char*>(init_data),
init_data_size); init_data_size);
InitializationData initialization_data(ISO_BMFF_VIDEO_MIME_TYPE, InitializationData initialization_data(ISO_BMFF_VIDEO_MIME_TYPE,
@@ -97,14 +102,14 @@ cdm::Status WvContentDecryptionModule::GenerateKeyRequest(
std::string security_level; std::string security_level;
std::string privacy_mode; std::string privacy_mode;
VectorBytes service_certificate; std::string service_certificate;
host_->GetPlatformString("SecurityLevel", &security_level); host_->GetPlatformString("SecurityLevel", &security_level);
host_->GetPlatformString("PrivacyOn", &privacy_mode); host_->GetPlatformString("PrivacyOn", &privacy_mode);
host_->GetPlatformByteArray("ServiceCertificate", &service_certificate); host_->GetPlatformString("ServiceCertificate", &service_certificate);
property_set_.set_security_level(security_level); property_set_.set_security_level(security_level);
property_set_.set_use_privacy_mode(privacy_mode == "True" ? 1 : 0 ); property_set_.set_use_privacy_mode(privacy_mode == "True" ? 1 : 0);
property_set_.set_service_certificate(service_certificate); property_set_.set_service_certificate(service_certificate);
CdmResponseType result = CdmResponseType result =
@@ -146,7 +151,7 @@ cdm::Status WvContentDecryptionModule::AddKey(const char* session_id,
const uint8_t* key, int key_size, const uint8_t* key, int key_size,
const uint8_t* key_id, const uint8_t* key_id,
int key_id_size) { int key_id_size) {
LOGI("Enter WvContentDecryptionModule::AddKey()\n"); LOGI("WvContentDecryptionModule::AddKey()");
CdmSessionId session_id_internal(session_id, session_id_size); CdmSessionId session_id_internal(session_id, session_id_size);
CdmKeyResponse key_data((const char*)key, key_size); CdmKeyResponse key_data((const char*)key, key_size);
CdmKeySetId key_set_id; CdmKeySetId key_set_id;
@@ -160,12 +165,17 @@ cdm::Status WvContentDecryptionModule::AddKey(const char* session_id,
} else { } else {
return cdm::kSessionError; return cdm::kSessionError;
} }
}
bool WvContentDecryptionModule::IsKeyValid(const uint8_t* key_id,
int key_id_size) {
KeyId key(reinterpret_cast<const char*>(key_id), key_id_size);
return cdm_engine_.IsKeyLoaded(key);
} }
cdm::Status WvContentDecryptionModule::CancelKeyRequest(const char* session_id, cdm::Status WvContentDecryptionModule::CancelKeyRequest(const char* session_id,
int session_id_size) { int session_id_size) {
LOGI("Enter WvContentDecryptionModule::CancelKeyRequest()\n"); LOGI("WvContentDecryptionModule::CancelKeyRequest()");
CdmSessionId session_id_internal(session_id, session_id_size); CdmSessionId session_id_internal(session_id, session_id_size);
return cdm_engine_.CancelKeyRequest(session_id_internal) == NO_ERROR return cdm_engine_.CancelKeyRequest(session_id_internal) == NO_ERROR
? cdm::kSuccess ? cdm::kSuccess
@@ -173,18 +183,17 @@ cdm::Status WvContentDecryptionModule::CancelKeyRequest(const char* session_id,
} }
void WvContentDecryptionModule::TimerExpired(void* context) { void WvContentDecryptionModule::TimerExpired(void* context) {
LOGI("Timer expired, send cdm_engine OnTimerEvent"); LOGI("WvContentDecryptionModule::TimerExpired()");
if (this != context) { if (timer_enabled_) {
LOGD("Context should have been set, Timer Expired Error\n"); cdm_engine_.OnTimerEvent();
return; host_->SetTimer(kCdmPolicyTimerDurationSeconds * 1000, NULL);
} }
OnTimerEvent();
} }
cdm::Status WvContentDecryptionModule::Decrypt( cdm::Status WvContentDecryptionModule::Decrypt(
const cdm::InputBuffer& encrypted_buffer, const cdm::InputBuffer& encrypted_buffer,
cdm::DecryptedBlock* decrypted_block) { cdm::DecryptedBlock* decrypted_block) {
LOGI("=>Enter WvContentDecryptionModule::Decrypt()\n"); LOGI("WvContentDecryptionModule::Decrypt()");
if (static_cast<size_t>(encrypted_buffer.iv_size) != KEY_IV_SIZE) if (static_cast<size_t>(encrypted_buffer.iv_size) != KEY_IV_SIZE)
return cdm::kDecryptError; return cdm::kDecryptError;
std::vector < uint8_t > iv(KEY_IV_SIZE); std::vector < uint8_t > iv(KEY_IV_SIZE);
@@ -210,47 +219,13 @@ cdm::Status WvContentDecryptionModule::Decrypt(
decrypted_block); decrypted_block);
} }
cdm::Status WvContentDecryptionModule::InitializeAudioDecoder(
const cdm::AudioDecoderConfig& audio_decoder_config) {
LOGI("WvContentDecryptionModule::InitializeAudioDecoder() Not implemented\n");
return cdm::kDecodeError;
}
cdm::Status WvContentDecryptionModule::InitializeVideoDecoder(
const cdm::VideoDecoderConfig& video_decoder_config) {
LOGI("WvContentDecryptionModule::InitializeVideoDecoder() Not implemented\n");
return cdm::kDecodeError;
}
void WvContentDecryptionModule::DeinitializeDecoder(
cdm::StreamType decoder_type) {
LOGI("WvContentDecryptionModule::DeInitializeDecoder() Not implemented\n");
}
void WvContentDecryptionModule::ResetDecoder(cdm::StreamType decoder_type) {
LOGI("WvContentDecryptionModule::ResetDecoder() Not implemented\n");
}
cdm::Status WvContentDecryptionModule::DecryptAndDecodeFrame(
const cdm::InputBuffer& encrypted_buffer, cdm::VideoFrame* video_frame) {
LOGI("WvContentDecryptionModule::DecryptAndDecodeFrame() Not implemented\n");
return cdm::kDecodeError;
}
cdm::Status WvContentDecryptionModule::DecryptAndDecodeSamples(
const cdm::InputBuffer& encrypted_buffer, cdm::AudioFrames* audio_frames) {
LOGI(
"WvContentDecryptionModule::DecryptAndDecodeSamples() Not implemented\n");
return cdm::kDecodeError;
}
// This is the Level 1 API. When the host application calls the CDM's // This is the Level 1 API. When the host application calls the CDM's
// DecryptDecodeAndRenderFrame(), rather than the CDM's Decrypt(), // DecryptDecodeAndRenderFrame(), rather than the CDM's Decrypt(),
// OEMCrypto_DecryptCTR() will be told to use direct rendering with no // OEMCrypto_DecryptCTR() will be told to use direct rendering with no
// cleartext in the return. // cleartext in the return.
cdm::Status WvContentDecryptionModule::DecryptDecodeAndRenderFrame( cdm::Status WvContentDecryptionModule::DecryptDecodeAndRenderFrame(
const cdm::InputBuffer& encrypted_buffer) { const cdm::InputBuffer& encrypted_buffer) {
LOGI("WvContentDecryptionModule::DecryptDecodeAndRenderFrame()\n"); LOGI("WvContentDecryptionModule::DecryptDecodeAndRenderFrame()");
if (static_cast<size_t>(encrypted_buffer.iv_size) != KEY_IV_SIZE) if (static_cast<size_t>(encrypted_buffer.iv_size) != KEY_IV_SIZE)
return cdm::kDecryptError; return cdm::kDecryptError;
@@ -276,7 +251,7 @@ cdm::Status WvContentDecryptionModule::DecryptDecodeAndRenderFrame(
// in the return. // in the return.
cdm::Status WvContentDecryptionModule::DecryptDecodeAndRenderSamples( cdm::Status WvContentDecryptionModule::DecryptDecodeAndRenderSamples(
const cdm::InputBuffer& encrypted_buffer) { const cdm::InputBuffer& encrypted_buffer) {
LOGI("WvContentDecryptionModule::DecryptDecodeAndRenderSamples()\n"); LOGI("WvContentDecryptionModule::DecryptDecodeAndRenderSamples()");
if (static_cast<size_t>(encrypted_buffer.iv_size) != KEY_IV_SIZE) if (static_cast<size_t>(encrypted_buffer.iv_size) != KEY_IV_SIZE)
return cdm::kDecryptError; return cdm::kDecryptError;
@@ -324,19 +299,16 @@ cdm::Status WvContentDecryptionModule::HandleProvisioningResponse(
} }
void WvContentDecryptionModule::EnablePolicyTimer() { void WvContentDecryptionModule::EnablePolicyTimer() {
LOGI("WvContentDecryptionModule::EnablePolicyTimer()\n"); LOGI("WvContentDecryptionModule::EnablePolicyTimer()");
host_->SetTimer(kCdmPolicyTimerDurationSeconds * 1000, this); if (!timer_enabled_) {
timer_enabled_ = true;
host_->SetTimer(kCdmPolicyTimerDurationSeconds * 1000, NULL);
}
} }
void WvContentDecryptionModule::DisablePolicyTimer() { void WvContentDecryptionModule::DisablePolicyTimer() {
LOGI("WvContentDecryptionModule::DisablePolicyTimer()\n"); LOGI("WvContentDecryptionModule::DisablePolicyTimer()");
host_->SetTimer(kCdmPolicyTimerCancel, NULL); timer_enabled_ = false;
}
void WvContentDecryptionModule::OnTimerEvent() {
LOGI("WvContentDecryptionModule::OnTimerEvent()\n");
cdm_engine_.OnTimerEvent();
} }
cdm::Status WvContentDecryptionModule::DoSubsampleDecrypt( cdm::Status WvContentDecryptionModule::DoSubsampleDecrypt(
@@ -385,7 +357,7 @@ cdm::Status WvContentDecryptionModule::DoSubsampleDecrypt(
continue; continue;
if (is_encrypted) { if (is_encrypted) {
uint32_t counter = encrypted_offset / kIvSize; uint32_t counter = encrypted_offset / kIvSize;
::Ctr128Add(counter - block_ctr, &iv[0]); Ctr128Add(counter - block_ctr, &iv[0]);
block_ctr = counter; block_ctr = counter;
} }
@@ -413,16 +385,22 @@ cdm::Status WvContentDecryptionModule::DoSubsampleDecrypt(
switch (status) { switch (status) {
case wvcdm::NEED_KEY: case wvcdm::NEED_KEY:
return cdm::kNoKey; return cdm::kNoKey;
break;
case wvcdm::NO_ERROR: case wvcdm::NO_ERROR:
break; break;
default: default:
return cdm::kDecryptError; return cdm::kDecryptError;
break;
} }
} }
} }
return cdm::kSuccess; return cdm::kSuccess;
} }
int64_t WvContentDecryptionModule::GetCurrentTimeInSeconds() {
return host_->GetCurrentWallTimeInSeconds();
}
File::Impl* WvContentDecryptionModule::NewFileImpl() {
return new File::Impl(host_);
}
} // namespace wvcdm } // namespace wvcdm

View File

@@ -7,49 +7,37 @@
// Review the TestHost class below to observe how the CDM interfaces with // Review the TestHost class below to observe how the CDM interfaces with
// the host application. // the host application.
//
#include <set> #include <queue>
#include <errno.h> #include <errno.h>
#include <getopt.h> #include <getopt.h>
#include <pthread.h>
#include <unistd.h> #include <unistd.h>
#include <gtest/gtest.h>
#include "clock.h" #include "clock.h"
#include "config_test_env.h" #include "config_test_env.h"
#include "content_decryption_module.h" #include "content_decryption_module.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "license_request.h" #include "license_request.h"
#include "log.h" #include "log.h"
#include "scoped_ptr.h" #include "scoped_ptr.h"
#include "string_conversions.h" #include "string_conversions.h"
#include "url_request.h" #include "url_request.h"
#include "wv_cdm_types.h"
#include "wv_cdm_common.h" #include "wv_cdm_common.h"
using ::testing::_;
using ::testing::AtLeast;
using ::testing::Invoke;
using ::testing::Return;
using wvcdm::scoped_ptr; using wvcdm::scoped_ptr;
static const int kTestPolicyRenewalDelaySeconds = 60; static const int kTestPolicyRenewalDelaySeconds = 60;
static const int kDelayWaitToForRenewalMessageSeconds = 2; static const int kDelayWaitToForRenewalMessageSeconds = 2;
// Linux based get time for host.
// This can be tailored if required. static double GetCurrentTime() {
double GetCurrentTestTime() {
struct timeval tv; struct timeval tv;
tv.tv_sec = tv.tv_usec = 0; tv.tv_sec = tv.tv_usec = 0;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
return tv.tv_sec; return tv.tv_sec;
} }
using wvcdm::StringPairs;
using wvcdm::VectorPairs;
// These classes below are naive implementation of the abstract classes defined // These classes below are naive implementation of the abstract classes defined
// in the CDM interface (content_decryptiom_module.h), which are used for tests // in the CDM interface (content_decryptiom_module.h), which are used for tests
// only. // only.
@@ -77,192 +65,11 @@ class TestBuffer : public cdm::Buffer {
CORE_DISALLOW_COPY_AND_ASSIGN(TestBuffer); CORE_DISALLOW_COPY_AND_ASSIGN(TestBuffer);
}; };
class TestHostFile { class TestHost : public cdm::Host {
public:
TestHostFile() : fname_(""), file_(NULL) {}
virtual ~TestHostFile() { if (file_) fclose(file_); }
virtual bool Init(const std::string& name);
virtual bool Exists();
virtual bool Remove();
virtual size_t Size();
virtual size_t Read(char* buffer, size_t bytes);
virtual size_t Write(const char* buffer, size_t bytes);
virtual std::string GetFileName() { return fname_;}
private:
std::string fname_;
FILE* file_;
CORE_DISALLOW_COPY_AND_ASSIGN(TestHostFile);
};
bool TestHostFile::Init(const std::string& name) {
fname_ = name;
return true;
}
bool TestHostFile::Exists() {
file_ = fopen(fname_.c_str(), "rb");
bool exists = file_;
if (file_) {
fclose(file_);
file_ = NULL;
}
return (exists);
}
bool TestHostFile::Remove() {
if (Exists()) {
if (remove(fname_.c_str())) {
return true;
}
}
return false;
}
size_t TestHostFile::Size() {
file_ = fopen(fname_.c_str(), "rb");
if (file_) {
fseek (file_, 0, SEEK_END);
size_t size = ftell (file_);
rewind (file_);
if (file_) {
fclose(file_);
file_ = NULL;
}
return size;
}
return 0;
}
size_t TestHostFile::Read(char* buffer, size_t bytes) {
file_ = fopen(fname_.c_str(), "rb");
if (file_) {
fseek (file_, 0, SEEK_END);
size_t size = ftell (file_);
rewind (file_);
size_t check = fread (buffer,1,size,file_);
if (file_) {
fclose(file_);
file_ = NULL;
}
return check;
}
return 0;
}
size_t TestHostFile::Write(const char* buffer, size_t bytes) {
FILE* file_ = fopen(fname_.c_str(), "w+");
if (file_) {
size_t check = fwrite (buffer,1,bytes,file_);
if (file_) {
fclose(file_);
file_ = NULL;
}
return check;
}
return 0;
}
class IHostTime {
public:
virtual double GetCurrentTestTime() = 0;
};
class SimplePThread {
public:
SimplePThread();
~SimplePThread();
void Start(uint64_t periodicity, void* host_ptr, void* context);
void Stop();
uint32_t GetTickCount();
private:
static bool is_running_;
pthread_t simple_timer_thread_;
typedef void* (*TimeThreadFunc)(void *arg_list);
static void* Tthread_function(void *arg_list);
TimeThreadFunc time_thread_function_;
struct arg_list_struct {
uint64_t periodicity;
void* host_ptr;
void* context;
};
static uint32_t tick_count_;
};
bool SimplePThread::is_running_ = false;
uint32_t SimplePThread::tick_count_ = 0;
SimplePThread::SimplePThread() : simple_timer_thread_(0) {
}
SimplePThread::~SimplePThread() {
LOGI("SimplePThread DTOR: calling Stop() to shutdown thread.");
Stop();
}
void SimplePThread::Stop() {
if (is_running_) {
void* result = NULL;
LOGI("SimplePThread is running and now it will be cancelled\n");
pthread_cancel(simple_timer_thread_);
pthread_join(simple_timer_thread_, &result);
is_running_ = false;
tick_count_ = 0;
}
}
void SimplePThread::Start(uint64_t periodicity, void* host_ptr, void* context) {
struct arg_list_struct* arg_list = new(struct arg_list_struct);
arg_list->periodicity = periodicity;
arg_list->host_ptr = host_ptr;
arg_list->context = context;
time_thread_function_ = &Tthread_function;
Stop();
is_running_ = true;
if(pthread_create(&simple_timer_thread_, NULL, time_thread_function_,
arg_list)) {
LOGI("Error creating pthread\n");
return;
}
LOGI("Created the Simple thread to support the timer callback\n");
}
void* SimplePThread::Tthread_function(void *arg_list) {
LOGI("Entered the SimplePThread::Tthread_function\n");
uint64_t periodicity = (static_cast<arg_list_struct*>(arg_list))->periodicity;
void* host_ptr = (static_cast<arg_list_struct*>(arg_list))->host_ptr;
void* context = (static_cast<arg_list_struct*>(arg_list))->context;
delete static_cast<struct arg_list_struct*>(arg_list);
LOGI("starting the while loop in the secondary thread\n");
while (is_running_) {
usleep(static_cast<uint64_t>(periodicity * 1000));
if (is_running_) {
((cdm::ContentDecryptionModule*)host_ptr)->TimerExpired(context);
tick_count_++;
}
}
return NULL;
}
uint32_t SimplePThread::GetTickCount() {
return tick_count_;
}
class TestHost : public cdm::Host, public IHostTime {
public: public:
// These structs are used to store the KeyMessages and KeyErrors passed to // These structs are used to store the KeyMessages and KeyErrors passed to
// this class' objects. // this class' objects.
struct KeyMessage { struct KeyMessage {
KeyMessage() {}
std::string session_id; std::string session_id;
std::string message; std::string message;
std::string default_url; std::string default_url;
@@ -281,11 +88,9 @@ class TestHost : public cdm::Host, public IHostTime {
// cdm::Host implementation. // cdm::Host implementation.
virtual cdm::Buffer* Allocate(int32_t capacity) OVERRIDE; virtual cdm::Buffer* Allocate(int32_t capacity) OVERRIDE;
MOCK_METHOD2(SetTimer, void(int64_t, void*)); virtual void SetTimer(int64_t delay_ms, void* context) OVERRIDE;
virtual void DoSetTimer(int64_t delay_ms, void* context);
// Returns the current "global" time from the GetCurrentTestTime() function virtual double GetCurrentWallTimeInSeconds() OVERRIDE;
// unless the time is manually set using TestHost::SetCurrentTime()().
MOCK_METHOD0(GetCurrentWallTimeInSeconds, double(void));
virtual void SendKeyMessage(const char* session_id, int32_t session_id_length, virtual void SendKeyMessage(const char* session_id, int32_t session_id_length,
const char* message, int32_t message_length, const char* message, int32_t message_length,
@@ -296,30 +101,14 @@ class TestHost : public cdm::Host, public IHostTime {
cdm::MediaKeyError error_code, cdm::MediaKeyError error_code,
uint32_t system_code) OVERRIDE; uint32_t system_code) OVERRIDE;
virtual void GetPrivateData(int32_t* instance, virtual void GetPlatformString(const std::string& name,
GetPrivateInterface* get_interface) OVERRIDE; std::string* value) OVERRIDE;
virtual int GetPlatformString(const std::string& name, virtual void SetPlatformString(const std::string& name,
std::string* value) OVERRIDE; const std::string& value) OVERRIDE;
virtual int SetPlatformString(const std::string& name,
const std::string& value) OVERRIDE;;
virtual int PersistPlatformString(const std::string& name,
const std::string& value) OVERRIDE;;
virtual int GetPlatformByteArray(const std::string& name,
std::vector<uint8_t>* value) OVERRIDE;
virtual int SetPlatformByteArray(const std::string& name,
const std::vector<uint8_t>& value) OVERRIDE;
virtual int PersistPlatformByteArray(const std::string& name,
const std::vector<uint8_t>& value) OVERRIDE;
// Methods only for this test. // Methods only for this test.
void SetCurrentTime(double current_time); void FastForwardTime(double seconds);
void FastForwardTimeForNextTimerEvent();
int KeyMessagesSize() const; int KeyMessagesSize() const;
int KeyErrorsSize() const; int KeyErrorsSize() const;
@@ -333,17 +122,23 @@ class TestHost : public cdm::Host, public IHostTime {
KeyMessage GetKeyMessage(int index) const; KeyMessage GetKeyMessage(int index) const;
KeyError GetKeyError(int index) const; KeyError GetKeyError(int index) const;
void* context() { return context_; } void SetCdmPtr(cdm::ContentDecryptionModule* cdm);
void SetCdmPtr(cdm::ContentDecryptionModule* host_cdm_ptr);
virtual double GetCurrentTestTime();
uint32_t GetTickCount();
private: private:
// This is used in GetCurrentWallTimeInSeconds(). This field is used to struct Timer {
// control the "current time". Timer(double expiry_time, void* context)
: expiry_time(expiry_time), context(context) {}
bool operator<(const Timer& other) const {
return expiry_time < other.expiry_time;
}
double expiry_time;
void* context;
};
double current_time_; double current_time_;
bool current_time_is_set_; std::priority_queue<Timer> timers_;
std::vector<KeyMessage> key_messages_; std::vector<KeyMessage> key_messages_;
std::vector<KeyError> key_errors_; std::vector<KeyError> key_errors_;
@@ -351,29 +146,13 @@ class TestHost : public cdm::Host, public IHostTime {
bool has_new_key_message_; bool has_new_key_message_;
bool has_new_key_error_; bool has_new_key_error_;
void* context_; std::map<std::string, std::string> platform_strings_;
int64_t delay_ms_;
cdm::ContentDecryptionModule* host_cdm_ptr_; cdm::ContentDecryptionModule* cdm_;
// These are containers for the platform sharing data.
std::set<StringPairs> platform_strings_set_;
std::set<VectorPairs> platform_vectors_set_;
TestHostFile test_host_file_;
void LoadPersistentValues();
SimplePThread simple_thread_;
CORE_DISALLOW_COPY_AND_ASSIGN(TestHost); CORE_DISALLOW_COPY_AND_ASSIGN(TestHost);
}; };
class TestHostFactory {
public:
TestHost* GetTestHost();
private:
scoped_ptr<TestHost> test_host_;
};
TestBuffer* TestBuffer::Create(uint32_t capacity) { TestBuffer* TestBuffer::Create(uint32_t capacity) {
return new TestBuffer(capacity); return new TestBuffer(capacity);
} }
@@ -395,37 +174,34 @@ void TestBuffer::SetSize(int32_t size) { size_ = size; }
int32_t TestBuffer::Size() const { return size_; } int32_t TestBuffer::Size() const { return size_; }
TestBuffer::TestBuffer(uint32_t capacity) TestBuffer::TestBuffer(uint32_t capacity)
: buffer_(new uint8_t[capacity]), capacity_(capacity) {} : buffer_(new uint8_t[capacity]),
capacity_(capacity) {}
TestBuffer::~TestBuffer() {} TestBuffer::~TestBuffer() {}
TestHost::TestHost() TestHost::TestHost()
: current_time_(::GetCurrentTestTime()), : current_time_(GetCurrentTime()),
current_time_is_set_(false),
has_new_key_message_(false), has_new_key_message_(false),
has_new_key_error_(false), has_new_key_error_(false),
context_(NULL), cdm_(NULL) {
delay_ms_(0),
host_cdm_ptr_(NULL) {
LoadPersistentValues();
} }
TestHost::~TestHost() {} TestHost::~TestHost() {
if (cdm_)
cdm_->Destroy();
}
cdm::Buffer* TestHost::Allocate(int32_t capacity) { cdm::Buffer* TestHost::Allocate(int32_t capacity) {
return TestBuffer::Create(capacity); return TestBuffer::Create(capacity);
} }
// SetTimer is a mock method mapping to DoSetTimer(). The cdm::Host void TestHost::SetTimer(int64_t delay_ms, void* context) {
// calls back to the TimerExpired callback double expiry_time = current_time_ + (delay_ms / 1000.0);
// every delay_ms. Zero delay_ms means WV is requesting timers_.push(Timer(expiry_time, context));
// termination of timer services. }
void TestHost::DoSetTimer(int64_t delay_ms, void* context) {
if (delay_ms == 0) { double TestHost::GetCurrentWallTimeInSeconds() {
simple_thread_.Stop(); return current_time_;
return;
}
simple_thread_.Start(delay_ms, (void*)host_cdm_ptr_, context);
} }
void TestHost::SendKeyMessage(const char* session_id, int32_t session_id_length, void TestHost::SendKeyMessage(const char* session_id, int32_t session_id_length,
@@ -451,131 +227,34 @@ void TestHost::SendKeyError(const char* session_id, int32_t session_id_length,
has_new_key_error_ = true; has_new_key_error_ = true;
} }
void TestHost::SetCurrentTime(double current_time) { void TestHost::FastForwardTime(double seconds) {
current_time_is_set_ = true; double goal_time = current_time_ + seconds;
current_time_ = current_time; while (current_time_ < goal_time) {
} if (timers_.empty()) {
current_time_ = goal_time;
void TestHost::FastForwardTimeForNextTimerEvent() { } else {
current_time_is_set_ = true; Timer t = timers_.top();
current_time_ += (delay_ms_ / 1000.0); timers_.pop();
delay_ms_ = 0; current_time_ = t.expiry_time;
} cdm_->TimerExpired(t.context);
void TestHost::GetPrivateData(int32_t* instance,
GetPrivateInterface* get_interface) {
LOGI("NOTIMPLEMENTED()");
}
// The Platform methods below are implemented to fill and retrieve
// platform specific information. The host application takes responsibility for
// this interface.
int TestHost::GetPlatformString(const std::string& name,
std::string* value) {
std::set<StringPairs>::iterator it;
for (it = platform_strings_set_.begin();
it != platform_strings_set_.end(); ++it) {
StringPairs sp = *it;
std::string x = sp.first;
std::string y = sp.second;
if (x == name) {
*value = y;
return 1;
} }
} }
*value = "Not Found!";
return 0;
} }
int TestHost::SetPlatformString(const std::string& name, void TestHost::GetPlatformString(const std::string& name,
const std::string& value) { std::string* value) {
StringPairs sp(name, value); *value = platform_strings_[name];
platform_strings_set_.insert(sp);
return 1;
} }
int TestHost::PersistPlatformString(const std::string& name, void TestHost::SetPlatformString(const std::string& name,
const std::string& value) { const std::string& value) {
StringPairs sp(name, value); platform_strings_[name] = value;
// Write the pairs to a file such that they can be retrieved by
// GetPlatformString() even after a power cycle.
return 1;
}
int TestHost::SetPlatformByteArray(const std::string& name,
const std::vector<uint8_t>& value) {
// A zero value pair is an erase only.
std::set<VectorPairs>::iterator it;
for (it = platform_vectors_set_.begin();
it != platform_vectors_set_.end(); ++it) {
VectorPairs vp = *it;
if (vp.first == name) {
platform_vectors_set_.erase(vp);
}
}
if (value.size() > 0) {
VectorPairs vp(name, value);
platform_vectors_set_.insert(vp);
}
return 1;
}
int TestHost::PersistPlatformByteArray(const std::string& name,
const std::vector<uint8_t>& value) {
// Assume input name = "DeviceCertificate" and
// test_host_file.fname_ == "cert.bin"
// No other cases are currently needed or supported.
if (value.size() == 0) {
remove(test_host_file_.GetFileName().c_str());
} else {
std::string string_buffer;
string_buffer.resize(value.size());
memcpy(&string_buffer[0], &value[0], value.size());
test_host_file_.Write(&string_buffer[0], value.size());
}
VectorPairs vp(name, value);
SetPlatformByteArray(name, value);
// open file and persist this so that it can be retrieved as a string/vector
// correlated pair. Vendor needs to implement this!
return 1;
}
int TestHost::GetPlatformByteArray(const std::string& name,
std::vector<uint8_t>* value) {
std::set<VectorPairs>::iterator it;
for (it = platform_vectors_set_.begin();
it != platform_vectors_set_.end(); ++it) {
VectorPairs vp = *it;
std::string x = vp.first;
if (x == name) {
*value = vp.second;
return 1;
}
}
value = NULL;
return 0;
} }
int TestHost::KeyMessagesSize() const { return key_messages_.size(); } int TestHost::KeyMessagesSize() const { return key_messages_.size(); }
int TestHost::KeyErrorsSize() const { return key_errors_.size(); } int TestHost::KeyErrorsSize() const { return key_errors_.size(); }
double TestHost::GetCurrentTestTime() {
current_time_is_set_ = true;
FastForwardTimeForNextTimerEvent();
return current_time_;
}
TestHost::KeyMessage TestHost::GetLastKeyMessage() { TestHost::KeyMessage TestHost::GetLastKeyMessage() {
if (!has_new_key_message_) { if (!has_new_key_message_) {
LOGD("No NEW"); LOGD("No NEW");
@@ -609,40 +288,8 @@ TestHost::KeyError TestHost::GetKeyError(int index) const {
return key_errors_[index]; return key_errors_[index];
} }
void TestHost::SetCdmPtr(cdm::ContentDecryptionModule* host_cdm_ptr) { void TestHost::SetCdmPtr(cdm::ContentDecryptionModule* cdm) {
host_cdm_ptr_ = host_cdm_ptr; cdm_ = cdm;
}
uint32_t TestHost::GetTickCount() {
return simple_thread_.GetTickCount();
}
TestHost* TestHostFactory::GetTestHost() {
if (!test_host_.get()) test_host_.reset(new TestHost());
return test_host_.get();
return NULL;
}
// The CDM::Host object is responsible for storing and retrieving items
// that are accessed via GetPlatformByteArray. Currently, support for
// the device certificate is all that is required.
void TestHost::LoadPersistentValues() {
test_host_file_.Init("cert.bin");
if (test_host_file_.Exists()) {
size_t size = test_host_file_.Size();
std::string string_buffer;
string_buffer.resize(size);
test_host_file_.Read(&string_buffer[0], size);
std::vector<uint8_t> vector_buffer(size);
memcpy(&vector_buffer[0], &string_buffer[0], size);
SetPlatformByteArray("DeviceCertificate", vector_buffer);
}
} }
class TestDecryptedBlock : public cdm::DecryptedBlock { class TestDecryptedBlock : public cdm::DecryptedBlock {
@@ -686,6 +333,7 @@ void TestDecryptedBlock::SetTimestamp(int64_t timestamp) {
int64_t TestDecryptedBlock::Timestamp() const { return timestamp_; } int64_t TestDecryptedBlock::Timestamp() const { return timestamp_; }
namespace { namespace {
// Default license server, can be configured using --server command line option // Default license server, can be configured using --server command line option
// Default key id (pssh), can be configured using --keyid command line option // Default key id (pssh), can be configured using --keyid command line option
const char kKeySystemWidevine[] = "com.widevine.alpha"; const char kKeySystemWidevine[] = "com.widevine.alpha";
@@ -694,53 +342,49 @@ wvcdm::KeyId g_key_id;
wvcdm::CdmKeySystem g_key_system; wvcdm::CdmKeySystem g_key_system;
std::string g_license_server; std::string g_license_server;
wvcdm::KeyId g_wrong_key_id; wvcdm::KeyId g_wrong_key_id;
int g_use_full_path = 0; // cannot use boolean in getopt_long
void* GetCdmHost(int host_interface_version, void* user_data) {
if (host_interface_version != cdm::kHostInterfaceVersion)
return NULL;
return user_data;
}
} // namespace } // namespace
namespace wvcdm { namespace wvcdm {
void* GetCdmHost(int host_interface_version, void* user_data);
class WvCdmApiTest : public testing::Test { class WvCdmApiTest : public testing::Test {
public: public:
WvCdmApiTest() : cdm_(NULL) {} WvCdmApiTest() : cdm_(NULL) {}
~WvCdmApiTest() { ~WvCdmApiTest() {}
if (cdm_) cdm_->Destroy();
}
protected: protected:
virtual void SetUp() { virtual void SetUp() {
cdm_ = reinterpret_cast<cdm::ContentDecryptionModule*>(::CreateCdmInstance( // Create the Host.
cdm::kCdmInterfaceVersion, kKeySystemWidevine, host_.reset(new TestHost());
strlen(kKeySystemWidevine), GetCdmHost, &host_factory_));
host_ = host_factory_.GetTestHost();
host_->SetCdmPtr(cdm_);
// Set various parameters that the CDM will query.
host_->SetPlatformString("SecurityLevel", "L1"); host_->SetPlatformString("SecurityLevel", "L1");
host_->SetPlatformString("PrivacyOn", "False"); host_->SetPlatformString("PrivacyOn", "False");
host_->SetPlatformString("UsesServiceCertificates", "False");
// By default we allow the timer to fire twice; once // Put a phony service certificate into persistent storage.
// when the addkey comes, and once when the wvcdm destructs and
// disables the timer.
EXPECT_CALL(*host_, SetTimer(_,_))
.Times(AtLeast(2))
.WillRepeatedly(Invoke(host_, &TestHost::DoSetTimer));
EXPECT_CALL(*host_, GetCurrentWallTimeInSeconds())
.Times(AtLeast(1))
.WillRepeatedly(Invoke(host_, &TestHost::GetCurrentTestTime));
// emulate pulling a certificate out of persistent storage.
static const size_t kPrivacyCertSize = 256; static const size_t kPrivacyCertSize = 256;
VectorBytes cert(kPrivacyCertSize); std::string cert(kPrivacyCertSize, '\0');
for (size_t i = 0; i < cert.size(); i++) { for (size_t i = 0; i < cert.size(); i++) {
cert[i] = i; cert[i] = i;
} }
host_->SetPlatformString("ServiceCertificate", cert);
host_->SetPlatformByteArray("ServiceCertificate", cert); // Initialize the CDM module before creating a CDM instance.
INITIALIZE_CDM_MODULE(); INITIALIZE_CDM_MODULE();
// Create the CDM.
cdm_ = reinterpret_cast<cdm::ContentDecryptionModule*>(::CreateCdmInstance(
cdm::kCdmInterfaceVersion, kKeySystemWidevine,
strlen(kKeySystemWidevine), GetCdmHost, host_.get()));
// Tell the Host about the CDM.
host_->SetCdmPtr(cdm_);
} }
void GenerateKeyRequest(const std::string& key_system, void GenerateKeyRequest(const std::string& key_system,
@@ -781,7 +425,6 @@ class WvCdmApiTest : public testing::Test {
std::string GetKeyRequestResponse(const std::string& server_url, std::string GetKeyRequestResponse(const std::string& server_url,
const std::string& client_auth, const std::string& client_auth,
int expected_response) { int expected_response) {
// Use secure connection and chunk transfer coding.
UrlRequest url_request(server_url + client_auth); UrlRequest url_request(server_url + client_auth);
if (!url_request.is_connected()) { if (!url_request.is_connected()) {
return ""; return "";
@@ -790,8 +433,6 @@ class WvCdmApiTest : public testing::Test {
url_request.PostRequest(key_msg_); url_request.PostRequest(key_msg_);
std::string response; std::string response;
int resp_bytes = url_request.GetResponse(&response); int resp_bytes = url_request.GetResponse(&response);
LOGD("response:\r\n%s", response.c_str());
LOGD("end %d bytes response dump", resp_bytes);
// Some license servers return 400 for invalid message, some // Some license servers return 400 for invalid message, some
// return 500; treat anything other than 200 as an invalid message. // return 500; treat anything other than 200 as an invalid message.
@@ -809,7 +450,7 @@ class WvCdmApiTest : public testing::Test {
std::string drm_msg; std::string drm_msg;
LicenseRequest lic_request; LicenseRequest lic_request;
lic_request.GetDrmMessage(response, drm_msg); lic_request.GetDrmMessage(response, drm_msg);
LOGV("drm msg: %u bytes\r\n%s", drm_msg.size(), LOGV("drm msg: %u bytes\n%s", drm_msg.size(),
HexEncode(reinterpret_cast<const uint8_t*>(drm_msg.data()), HexEncode(reinterpret_cast<const uint8_t*>(drm_msg.data()),
drm_msg.size()).c_str()); drm_msg.size()).c_str());
return drm_msg; return drm_msg;
@@ -1310,15 +951,12 @@ class WvCdmApiTest : public testing::Test {
EXPECT_EQ(cdm::kDecryptError, status); EXPECT_EQ(cdm::kDecryptError, status);
} }
void TimerTest(void* session_id) { host_->SetTimer(1000, session_id); }
std::string key_msg_; std::string key_msg_;
std::string session_id_; std::string session_id_;
std::string server_url_; std::string server_url_;
cdm::ContentDecryptionModule* cdm_; cdm::ContentDecryptionModule* cdm_; // owned by host_
TestHostFactory host_factory_; scoped_ptr<TestHost> host_;
TestHost* host_;
}; };
// Note that these tests, BaseMessageTest, NormalDecryption and TimeTest, // Note that these tests, BaseMessageTest, NormalDecryption and TimeTest,
@@ -1328,8 +966,7 @@ class WvCdmApiTest : public testing::Test {
// and works in your test environment. // and works in your test environment.
TEST_F(WvCdmApiTest, DeviceCertificateTest) { TEST_F(WvCdmApiTest, DeviceCertificateTest) {
std::vector<uint8_t> value(0); host_->SetPlatformString("DeviceCertificate", "");
host_->PersistPlatformByteArray("DeviceCertificate", value);
GenerateKeyRequest(g_key_system, g_key_id); // It will have to provision - GenerateKeyRequest(g_key_system, g_key_id); // It will have to provision -
// in here. // in here.
TestHost::KeyMessage key_msg = host_->GetLastKeyMessage(); TestHost::KeyMessage key_msg = host_->GetLastKeyMessage();
@@ -1352,25 +989,6 @@ TEST_F(WvCdmApiTest, BaseMessageTest) {
CancelKeyRequest(session_id_); CancelKeyRequest(session_id_);
} }
TEST_F(WvCdmApiTest, BaseTimerTest) {
GenerateKeyRequest(g_key_system, g_key_id);
TestHost::KeyMessage key_msg = host_->GetLastKeyMessage();
session_id_ = key_msg.session_id;
key_msg_ = key_msg.message;
std::string drm_msg = GetKeyRequestResponse(g_license_server,
g_client_auth, 200);
AddKey(key_msg.session_id, drm_msg);
LOGI("Sleeping and allowing the time expirations to increment");
uint32_t sleep_period = static_cast<uint32_t>(12000 / 1000);
sleep(sleep_period);
LOGI("Tick count is %ld\n", host_->GetTickCount());
// We should have close to, maybe slightly less than sleep_period ticks.
// If it ticked at all then we pass as the timer must be expriring.
EXPECT_GE(host_->GetTickCount(), 1U);
CancelKeyRequest(session_id_);
}
TEST_F(WvCdmApiTest, NormalDecryption) { TEST_F(WvCdmApiTest, NormalDecryption) {
GenerateKeyRequest(g_key_system, g_key_id); GenerateKeyRequest(g_key_system, g_key_id);
TestHost::KeyMessage key_msg = host_->GetLastKeyMessage(); TestHost::KeyMessage key_msg = host_->GetLastKeyMessage();
@@ -1410,8 +1028,8 @@ TEST_F(WvCdmApiTest, TimeTest) {
g_client_auth, 200); g_client_auth, 200);
AddKey(key_msg.session_id, drm_msg); AddKey(key_msg.session_id, drm_msg);
host_->SetCurrentTime(host_->GetCurrentTestTime() + kTestPolicyRenewalDelaySeconds); host_->FastForwardTime(kTestPolicyRenewalDelaySeconds +
sleep(kDelayWaitToForRenewalMessageSeconds); kDelayWaitToForRenewalMessageSeconds);
// When the timer expired, we should have sent a renewal, so we can // When the timer expired, we should have sent a renewal, so we can
// add this renewed key now, assuming things are working as expected. // add this renewed key now, assuming things are working as expected.
@@ -1419,7 +1037,10 @@ TEST_F(WvCdmApiTest, TimeTest) {
session_id_ = key_msg2.session_id; session_id_ = key_msg2.session_id;
key_msg_ = key_msg2.message; key_msg_ = key_msg2.message;
drm_msg = GetKeyRequestResponse(key_msg2.default_url, g_client_auth, 200); // Note that the client auth string is not appended when the CDM tells
// us what URL to use.
EXPECT_FALSE(key_msg2.default_url.empty());
drm_msg = GetKeyRequestResponse(key_msg2.default_url, "", 200);
AddKey(key_msg2.session_id, drm_msg); AddKey(key_msg2.session_id, drm_msg);
} }
@@ -1453,15 +1074,6 @@ TEST_F(WvCdmApiTest, SecureDecryptionLevel1WithMissingSubsampleInfo) {
WithMissingSubsampleInfoTest(); WithMissingSubsampleInfoTest();
} }
void* GetCdmHost(int host_interface_version, void* user_data) {
if (!host_interface_version || !user_data) return NULL;
if (host_interface_version != cdm::kHostInterfaceVersion) return NULL;
TestHostFactory* host_factory = reinterpret_cast<TestHostFactory*>(user_data);
return host_factory->GetTestHost();
}
} // namespace wvcdm } // namespace wvcdm
int main(int argc, char** argv) { int main(int argc, char** argv) {
@@ -1480,16 +1092,13 @@ int main(int argc, char** argv) {
int show_usage = 0; int show_usage = 0;
static const struct option long_options[] = { static const struct option long_options[] = {
{"use_full_path", no_argument, &g_use_full_path, 0},
{"keyid", required_argument, NULL, 'k'}, {"keyid", required_argument, NULL, 'k'},
{"server", required_argument, NULL, 's'}, {"server", required_argument, NULL, 's'},
{"vmodule", required_argument, NULL, 0},
{"v", required_argument, NULL, 0},
{NULL, 0, NULL, '\0'}}; {NULL, 0, NULL, '\0'}};
int option_index = 0; int option_index = 0;
int opt = 0; int opt = 0;
while ((opt = getopt_long(argc, argv, "k:p:s:u:v", long_options, while ((opt = getopt_long(argc, argv, "k:s:v", long_options,
&option_index)) != -1) { &option_index)) != -1) {
switch (opt) { switch (opt) {
case 'k': { case 'k': {
@@ -1502,15 +1111,19 @@ int main(int argc, char** argv) {
g_license_server.assign(optarg); g_license_server.assign(optarg);
break; break;
} }
case 'u': { case 'v': {
g_use_full_path = 1; // This option has already been consumed by wvcdm::InitLogging() above.
// We only tell getopt about it so that it is not an error. We ignore
// the option here when seen.
// TODO: Stop passing argv to InitLogging, and instead set the log
// level here through the logging API. We should keep all command-line
// parsing at the application level, rather than split between various
// apps and various platform-specific logging implementations.
break; break;
} }
case '?': { case '?': {
show_usage = 1; show_usage = 1;
break; break;
case 'v':
break;
} }
} }
} }
@@ -1518,10 +1131,6 @@ int main(int argc, char** argv) {
if (show_usage) { if (show_usage) {
std::cout << std::endl; std::cout << std::endl;
std::cout << "usage: " << argv[0] << " [options]" << std::endl << std::endl; std::cout << "usage: " << argv[0] << " [options]" << std::endl << std::endl;
std::cout << " enclose multiple arguments in '' when using adb shell"
<< std::endl;
std::cout << " e.g. adb shell '" << argv[0] << " --server=\"url\"'"
<< std::endl << std::endl;
std::cout << std::setw(30) << std::left << " --server=<server_url>"; std::cout << std::setw(30) << std::left << " --server=<server_url>";
std::cout std::cout
@@ -1534,10 +1143,6 @@ int main(int argc, char** argv) {
std::cout << "configure the key id or pssh, in hex format" << std::endl; std::cout << "configure the key id or pssh, in hex format" << std::endl;
std::cout << std::setw(30) << std::left << " default keyid:"; std::cout << std::setw(30) << std::left << " default keyid:";
std::cout << g_key_id << std::endl; std::cout << g_key_id << std::endl;
std::cout << std::setw(30) << std::left << " --use_full_path";
std::cout << "specify server url is not a proxy server" << std::endl;
std::cout << std::endl;
return 0; return 0;
} }

View File

@@ -13,9 +13,9 @@ class CdmClientPropertySet {
public: public:
virtual ~CdmClientPropertySet() {} virtual ~CdmClientPropertySet() {}
virtual std::string security_level() const = 0; virtual const std::string& security_level() const = 0;
virtual bool use_privacy_mode() const = 0; virtual bool use_privacy_mode() const = 0;
virtual std::vector<uint8_t> service_certificate() const = 0; virtual const std::string& service_certificate() const = 0;
virtual bool is_session_sharing_enabled() const = 0; virtual bool is_session_sharing_enabled() const = 0;
virtual uint32_t session_sharing_id() const = 0; virtual uint32_t session_sharing_id() const = 0;
virtual void set_session_sharing_id(uint32_t id) = 0; virtual void set_session_sharing_id(uint32_t id) = 0;

View File

@@ -24,95 +24,91 @@ class CdmEngine {
virtual ~CdmEngine(); virtual ~CdmEngine();
// Session related methods // Session related methods
CdmResponseType OpenSession(const CdmKeySystem& key_system, virtual CdmResponseType OpenSession(const CdmKeySystem& key_system,
const CdmClientPropertySet* property_set, const CdmClientPropertySet* property_set,
CdmSessionId* session_id); CdmSessionId* session_id);
CdmResponseType CloseSession(const CdmSessionId& session_id); virtual CdmResponseType CloseSession(const CdmSessionId& session_id);
CdmResponseType OpenKeySetSession(const CdmKeySetId& key_set_id); virtual CdmResponseType OpenKeySetSession(const CdmKeySetId& key_set_id);
CdmResponseType CloseKeySetSession(const CdmKeySetId& key_set_id); virtual CdmResponseType CloseKeySetSession(const CdmKeySetId& key_set_id);
// License related methods // License related methods
// Construct a valid license request // Construct a valid license request
CdmResponseType GenerateKeyRequest(const CdmSessionId& session_id, virtual CdmResponseType GenerateKeyRequest(
const CdmKeySetId& key_set_id, const CdmSessionId& session_id, const CdmKeySetId& key_set_id,
const InitializationData& init_data, const InitializationData& init_data, const CdmLicenseType license_type,
const CdmLicenseType license_type, CdmAppParameterMap& app_parameters, CdmKeyMessage* key_request,
CdmAppParameterMap& app_parameters, std::string* server_url);
CdmKeyMessage* key_request,
std::string* server_url);
// Accept license response and extract key info. // Accept license response and extract key info.
CdmResponseType AddKey(const CdmSessionId& session_id, virtual CdmResponseType AddKey(const CdmSessionId& session_id,
const CdmKeyResponse& key_data, const CdmKeyResponse& key_data,
CdmKeySetId* key_set_id); CdmKeySetId* key_set_id);
CdmResponseType RestoreKey(const CdmSessionId& session_id, virtual CdmResponseType RestoreKey(const CdmSessionId& session_id,
const CdmKeySetId& key_set_id); const CdmKeySetId& key_set_id);
CdmResponseType CancelKeyRequest(const CdmSessionId& session_id); virtual CdmResponseType CancelKeyRequest(const CdmSessionId& session_id);
// Construct valid renewal request for the current session keys. // Construct valid renewal request for the current session keys.
CdmResponseType GenerateRenewalRequest(const CdmSessionId& session_id, virtual CdmResponseType GenerateRenewalRequest(const CdmSessionId& session_id,
CdmKeyMessage* key_request, CdmKeyMessage* key_request,
std::string* server_url); std::string* server_url);
// Accept renewal response and update key info. // Accept renewal response and update key info.
CdmResponseType RenewKey(const CdmSessionId& session_id, virtual CdmResponseType RenewKey(const CdmSessionId& session_id,
const CdmKeyResponse& key_data); const CdmKeyResponse& key_data);
// Query system information // Query system information
CdmResponseType QueryStatus(CdmQueryMap* info); virtual CdmResponseType QueryStatus(CdmQueryMap* info);
// Query session information // Query session information
virtual CdmResponseType QuerySessionStatus(const CdmSessionId& session_id, virtual CdmResponseType QuerySessionStatus(const CdmSessionId& session_id,
CdmQueryMap* key_info); CdmQueryMap* key_info);
// Query license information // Query license information
CdmResponseType QueryKeyStatus(const CdmSessionId& session_id, virtual CdmResponseType QueryKeyStatus(const CdmSessionId& session_id,
CdmQueryMap* key_info); CdmQueryMap* key_info);
// Query seesion control information // Query seesion control information
CdmResponseType QueryKeyControlInfo(const CdmSessionId& session_id, virtual CdmResponseType QueryKeyControlInfo(const CdmSessionId& session_id,
CdmQueryMap* key_info); CdmQueryMap* key_info);
// Provisioning related methods // Provisioning related methods
CdmResponseType GetProvisioningRequest( virtual CdmResponseType GetProvisioningRequest(
CdmCertificateType cert_type, CdmCertificateType cert_type, const std::string& cert_authority,
const std::string& cert_authority, CdmProvisioningRequest* request, std::string* default_url);
CdmProvisioningRequest* request,
std::string* default_url);
CdmResponseType HandleProvisioningResponse( virtual CdmResponseType HandleProvisioningResponse(
CdmProvisioningResponse& response, CdmProvisioningResponse& response, std::string* cert,
std::string* cert,
std::string* wrapped_key); std::string* wrapped_key);
CdmResponseType Unprovision(CdmSecurityLevel security_level); virtual CdmResponseType Unprovision(CdmSecurityLevel security_level);
// Usage related methods for streaming licenses // Usage related methods for streaming licenses
CdmResponseType GetUsageInfo(CdmUsageInfo* usage_info); virtual CdmResponseType GetUsageInfo(CdmUsageInfo* usage_info);
CdmResponseType ReleaseUsageInfo(const CdmUsageInfoReleaseMessage& message); virtual CdmResponseType ReleaseUsageInfo(
const CdmUsageInfoReleaseMessage& message);
// Decryption and key related methods // Decryption and key related methods
// Accept encrypted buffer and return decrypted data. // Accept encrypted buffer and return decrypted data.
CdmResponseType Decrypt(const CdmSessionId& session_id, virtual CdmResponseType Decrypt(const CdmSessionId& session_id,
const CdmDecryptionParameters& parameters); const CdmDecryptionParameters& parameters);
size_t SessionSize() const { return sessions_.size(); } virtual size_t SessionSize() const { return sessions_.size(); }
// Is the key known to any session? // Is the key known to any session?
bool IsKeyLoaded(const KeyId& key_id); virtual bool IsKeyLoaded(const KeyId& key_id);
bool FindSessionForKey(const KeyId& key_id, CdmSessionId* sessionId); virtual bool FindSessionForKey(const KeyId& key_id, CdmSessionId* sessionId);
// Event listener related methods // Event listener related methods
bool AttachEventListener(const CdmSessionId& session_id, virtual bool AttachEventListener(const CdmSessionId& session_id,
WvCdmEventListener* listener); WvCdmEventListener* listener);
bool DetachEventListener(const CdmSessionId& session_id, virtual bool DetachEventListener(const CdmSessionId& session_id,
WvCdmEventListener* listener); WvCdmEventListener* listener);
// Timer expiration method // Timer expiration method
void OnTimerEvent(); virtual void OnTimerEvent();
private: private:
// private methods // private methods

View File

@@ -22,81 +22,83 @@ class WvCdmEventListener;
class CdmSession { class CdmSession {
public: public:
explicit CdmSession(const CdmClientPropertySet* cdm_client_property_set); explicit CdmSession(const CdmClientPropertySet* cdm_client_property_set);
~CdmSession(); virtual ~CdmSession();
CdmResponseType Init(); virtual CdmResponseType Init();
CdmResponseType RestoreOfflineSession(const CdmKeySetId& key_set_id, virtual CdmResponseType RestoreOfflineSession(
const CdmLicenseType license_type); const CdmKeySetId& key_set_id, const CdmLicenseType license_type);
CdmResponseType RestoreUsageSession(const CdmKeyMessage& key_request, virtual CdmResponseType RestoreUsageSession(
const CdmKeyResponse& key_response); const CdmKeyMessage& key_request, const CdmKeyResponse& key_response);
void set_key_system(const CdmKeySystem& ksystem) { key_system_ = ksystem; } virtual void set_key_system(const CdmKeySystem& ksystem) {
const CdmKeySystem& key_system() { return key_system_; } key_system_ = ksystem;
}
virtual const CdmKeySystem& key_system() { return key_system_; }
const CdmSessionId& session_id() { return session_id_; } virtual const CdmSessionId& session_id() { return session_id_; }
CdmResponseType GenerateKeyRequest(const InitializationData& init_data, virtual CdmResponseType GenerateKeyRequest(
const CdmLicenseType license_type, const InitializationData& init_data, const CdmLicenseType license_type,
const CdmAppParameterMap& app_parameters, const CdmAppParameterMap& app_parameters, CdmKeyMessage* key_request,
CdmKeyMessage* key_request, std::string* server_url);
std::string* server_url);
// AddKey() - Accept license response and extract key info. // AddKey() - Accept license response and extract key info.
CdmResponseType AddKey(const CdmKeyResponse& key_response, virtual CdmResponseType AddKey(const CdmKeyResponse& key_response,
CdmKeySetId* key_set_id); CdmKeySetId* key_set_id);
// CancelKeyRequest() - Cancel session. // CancelKeyRequest() - Cancel session.
CdmResponseType CancelKeyRequest(); virtual CdmResponseType CancelKeyRequest();
// Query session status // Query session status
CdmResponseType QueryStatus(CdmQueryMap* key_info); virtual CdmResponseType QueryStatus(CdmQueryMap* key_info);
// Query license information // Query license information
CdmResponseType QueryKeyStatus(CdmQueryMap* key_info); virtual CdmResponseType QueryKeyStatus(CdmQueryMap* key_info);
// Query session control info // Query session control info
CdmResponseType QueryKeyControlInfo(CdmQueryMap* key_info); virtual CdmResponseType QueryKeyControlInfo(CdmQueryMap* key_info);
// Decrypt() - Accept encrypted buffer and return decrypted data. // Decrypt() - Accept encrypted buffer and return decrypted data.
CdmResponseType Decrypt(const CdmDecryptionParameters& parameters); virtual CdmResponseType Decrypt(const CdmDecryptionParameters& parameters);
// License renewal // License renewal
// GenerateRenewalRequest() - Construct valid renewal request for the current // GenerateRenewalRequest() - Construct valid renewal request for the current
// session keys. // session keys.
CdmResponseType GenerateRenewalRequest(CdmKeyMessage* key_request, virtual CdmResponseType GenerateRenewalRequest(CdmKeyMessage* key_request,
std::string* server_url); std::string* server_url);
// RenewKey() - Accept renewal response and update key info. // RenewKey() - Accept renewal response and update key info.
CdmResponseType RenewKey(const CdmKeyResponse& key_response); virtual CdmResponseType RenewKey(const CdmKeyResponse& key_response);
// License release // License release
// GenerateReleaseRequest() - Construct valid release request for the current // GenerateReleaseRequest() - Construct valid release request for the current
// session keys. // session keys.
CdmResponseType GenerateReleaseRequest(CdmKeyMessage* key_request, virtual CdmResponseType GenerateReleaseRequest(CdmKeyMessage* key_request,
std::string* server_url); std::string* server_url);
// ReleaseKey() - Accept response and release key. // ReleaseKey() - Accept response and release key.
CdmResponseType ReleaseKey(const CdmKeyResponse& key_response); virtual CdmResponseType ReleaseKey(const CdmKeyResponse& key_response);
bool IsKeyLoaded(const KeyId& key_id); virtual bool IsKeyLoaded(const KeyId& key_id);
bool AttachEventListener(WvCdmEventListener* listener); virtual bool AttachEventListener(WvCdmEventListener* listener);
bool DetachEventListener(WvCdmEventListener* listener); virtual bool DetachEventListener(WvCdmEventListener* listener);
void OnTimerEvent(); virtual void OnTimerEvent();
void OnKeyReleaseEvent(const CdmKeySetId& key_set_id); virtual void OnKeyReleaseEvent(const CdmKeySetId& key_set_id);
SecurityLevel GetRequestedSecurityLevel(); virtual SecurityLevel GetRequestedSecurityLevel();
CdmSecurityLevel GetSecurityLevel(); virtual CdmSecurityLevel GetSecurityLevel();
CdmResponseType UpdateUsageInformation(); virtual CdmResponseType UpdateUsageInformation();
bool is_usage_update_needed() { return is_usage_update_needed_; } virtual bool is_usage_update_needed() { return is_usage_update_needed_; }
void reset_is_usage_update_needed() { is_usage_update_needed_ = false; } virtual void reset_is_usage_update_needed() {
is_usage_update_needed_ = false;
}
private: private:
// Generate unique ID for each new session. // Generate unique ID for each new session.
CdmSessionId GenerateSessionId(); CdmSessionId GenerateSessionId();
bool GenerateKeySetId(CdmKeySetId* key_set_id); bool GenerateKeySetId(CdmKeySetId* key_set_id);
@@ -116,6 +118,7 @@ class CdmSession {
bool is_offline_; bool is_offline_;
bool is_release_; bool is_release_;
bool is_usage_update_needed_; bool is_usage_update_needed_;
bool is_initial_decryption_;
// information useful for offline and usage scenarios // information useful for offline and usage scenarios
CdmKeyMessage key_request_; CdmKeyMessage key_request_;

View File

@@ -19,61 +19,60 @@ typedef std::map<CryptoKeyId, CryptoKey*> CryptoKeyMap;
class CryptoSession { class CryptoSession {
public: public:
CryptoSession(); CryptoSession();
~CryptoSession(); virtual ~CryptoSession();
bool ValidateKeybox(); virtual bool ValidateKeybox();
bool GetToken(std::string* token); virtual bool GetToken(std::string* token);
CdmSecurityLevel GetSecurityLevel(); virtual CdmSecurityLevel GetSecurityLevel();
bool GetDeviceUniqueId(std::string* device_id); virtual bool GetDeviceUniqueId(std::string* device_id);
bool GetSystemId(uint32_t* system_id); virtual bool GetSystemId(uint32_t* system_id);
bool GetProvisioningId(std::string* provisioning_id); virtual bool GetProvisioningId(std::string* provisioning_id);
CdmResponseType Open() { return Open(kLevelDefault); } virtual CdmResponseType Open() { return Open(kLevelDefault); }
CdmResponseType Open(SecurityLevel requested_security_level); virtual CdmResponseType Open(SecurityLevel requested_security_level);
void Close(); virtual void Close();
bool IsOpen() { return open_; } virtual bool IsOpen() { return open_; }
CryptoSessionId oec_session_id() { return oec_session_id_; } virtual CryptoSessionId oec_session_id() { return oec_session_id_; }
// Key request/response // Key request/response
void GenerateRequestId(std::string& req_id_str); virtual void GenerateRequestId(std::string& req_id_str);
bool PrepareRequest(const std::string& key_deriv_message, virtual bool PrepareRequest(const std::string& key_deriv_message,
bool is_provisioning, std::string* signature); bool is_provisioning, std::string* signature);
bool PrepareRenewalRequest(const std::string& message, virtual bool PrepareRenewalRequest(const std::string& message,
std::string* signature); std::string* signature);
CdmResponseType LoadKeys(const std::string& message, virtual CdmResponseType LoadKeys(const std::string& message,
const std::string& signature, const std::string& signature,
const std::string& mac_key_iv, const std::string& mac_key_iv,
const std::string& mac_key, const std::string& mac_key,
const std::vector<CryptoKey>& key_array, const std::vector<CryptoKey>& key_array,
const std::string& provider_session_token); const std::string& provider_session_token);
bool LoadCertificatePrivateKey(std::string& wrapped_key); virtual bool LoadCertificatePrivateKey(std::string& wrapped_key);
bool RefreshKeys(const std::string& message, const std::string& signature, virtual bool RefreshKeys(const std::string& message,
int num_keys, const CryptoKey* key_array); const std::string& signature, int num_keys,
bool GenerateNonce(uint32_t* nonce); const CryptoKey* key_array);
bool GenerateDerivedKeys(const std::string& message); virtual bool GenerateNonce(uint32_t* nonce);
bool GenerateDerivedKeys(const std::string& message, virtual bool GenerateDerivedKeys(const std::string& message);
const std::string& session_key); virtual bool GenerateDerivedKeys(const std::string& message,
bool RewrapDeviceRSAKey(const std::string& message, const std::string& session_key);
const std::string& signature, virtual bool RewrapDeviceRSAKey(const std::string& message,
const std::string& nonce, const std::string& signature,
const std::string& enc_rsa_key, const std::string& nonce,
const std::string& rsa_key_iv, const std::string& enc_rsa_key,
std::string* wrapped_rsa_key); const std::string& rsa_key_iv,
std::string* wrapped_rsa_key);
// Media data path // Media data path
CdmResponseType Decrypt(const CdmDecryptionParameters& parameters); virtual CdmResponseType Decrypt(const CdmDecryptionParameters& parameters);
CdmResponseType UpdateUsageInformation(); virtual CdmResponseType UpdateUsageInformation();
CdmResponseType GenerateUsageReport( virtual CdmResponseType GenerateUsageReport(
const std::string& provider_session_token, const std::string& provider_session_token, std::string* usage_report);
std::string* usage_report); virtual CdmResponseType ReleaseUsageInformation(
CdmResponseType ReleaseUsageInformation( const std::string& message, const std::string& signature,
const std::string& message,
const std::string& signature,
const std::string& provider_session_token); const std::string& provider_session_token);
bool GetRandom(size_t data_length, uint8_t* random_data); virtual bool GetRandom(size_t data_length, uint8_t* random_data);
private: private:
void Init(); void Init();

View File

@@ -23,32 +23,32 @@ class CdmLicense {
public: public:
CdmLicense() : session_(NULL), initialized_(false) {} CdmLicense() : session_(NULL), initialized_(false) {}
~CdmLicense() {} virtual ~CdmLicense() {}
bool Init(const std::string& token, CryptoSession* session, virtual bool Init(const std::string& token, CryptoSession* session,
PolicyEngine* policy_engine); PolicyEngine* policy_engine);
bool PrepareKeyRequest(const InitializationData& init_data, virtual bool PrepareKeyRequest(const InitializationData& init_data,
const CdmLicenseType license_type, const CdmLicenseType license_type,
const CdmAppParameterMap& app_parameters, const CdmAppParameterMap& app_parameters,
const CdmSessionId& session_id, const CdmSessionId& session_id,
CdmKeyMessage* signed_request, CdmKeyMessage* signed_request,
std::string* server_url); std::string* server_url);
bool PrepareKeyUpdateRequest(bool is_renewal, CdmKeyMessage* signed_request, virtual bool PrepareKeyUpdateRequest(bool is_renewal, CdmKeyMessage* signed_request,
std::string* server_url); std::string* server_url);
CdmResponseType HandleKeyResponse(const CdmKeyResponse& license_response); virtual CdmResponseType HandleKeyResponse(const CdmKeyResponse& license_response);
CdmResponseType HandleKeyUpdateResponse( virtual CdmResponseType HandleKeyUpdateResponse(
bool is_renewal, const CdmKeyResponse& license_response); bool is_renewal, const CdmKeyResponse& license_response);
bool RestoreOfflineLicense(const CdmKeyMessage& license_request, virtual bool RestoreOfflineLicense(const CdmKeyMessage& license_request,
const CdmKeyResponse& license_response, const CdmKeyResponse& license_response,
const CdmKeyResponse& license_renewal_response); const CdmKeyResponse& license_renewal_response);
bool RestoreUsageLicense(const CdmKeyMessage& license_request, virtual bool RestoreUsageLicense(const CdmKeyMessage& license_request,
const CdmKeyResponse& license_response); const CdmKeyResponse& license_response);
bool HasInitData() { return !stored_init_data_.empty(); } virtual bool HasInitData() { return !stored_init_data_.empty(); }
bool IsKeyLoaded(const KeyId& key_id); virtual bool IsKeyLoaded(const KeyId& key_id);
std::string provider_session_token() { return provider_session_token_; } virtual std::string provider_session_token() { return provider_session_token_; }
private: private:
bool PrepareServiceCertificateRequest(CdmKeyMessage* signed_request, bool PrepareServiceCertificateRequest(CdmKeyMessage* signed_request,

View File

@@ -10,6 +10,8 @@
namespace wvcdm { namespace wvcdm {
using video_widevine_server::sdk::LicenseIdentification;
class Clock; class Clock;
class PolicyEngineTest; class PolicyEngineTest;
@@ -18,53 +20,46 @@ class PolicyEngineTest;
class PolicyEngine { class PolicyEngine {
public: public:
PolicyEngine(); PolicyEngine();
~PolicyEngine(); virtual ~PolicyEngine();
// The value returned should be taken as a hint rather than an absolute // The value returned should be taken as a hint rather than an absolute
// status. It is computed during the last call to either SetLicense/ // status. It is computed during the last call to either SetLicense/
// UpdateLicense/OnTimerEvent/BeginDecryption and may be out of sync // UpdateLicense/OnTimerEvent/BeginDecryption and may be out of sync
// depending on the amount of time elapsed. The current decryption // depending on the amount of time elapsed. The current decryption
// status is not calculated to avoid overhead in the decryption path. // status is not calculated to avoid overhead in the decryption path.
inline bool can_decrypt() { return can_decrypt_; } virtual bool can_decrypt() { return can_decrypt_; }
// OnTimerEvent is called when a timer fires. It notifies the Policy Engine // OnTimerEvent is called when a timer fires. It notifies the Policy Engine
// that the timer has fired and that it should check whether any events have // that the timer has fired and that it should check whether any events have
// occurred since the last timer event. If so, it sets event_occurred to true // occurred since the last timer event. If so, it sets event_occurred to true
// and sets event to point to the event that occurred. If not, it sets // and sets event to point to the event that occurred. If not, it sets
// event_occurred to false. // event_occurred to false.
void OnTimerEvent(bool* event_occurred, CdmEventType* event); virtual void OnTimerEvent(bool* event_occurred, CdmEventType* event);
// SetLicense is used in handling the initial license response. It stores // SetLicense is used in handling the initial license response. It stores
// an exact copy of the policy information stored in the license. // an exact copy of the policy information stored in the license.
// The license state transitions to kLicenseStateCanPlay if the license // The license state transitions to kLicenseStateCanPlay if the license
// permits playback. // permits playback.
void SetLicense(const video_widevine_server::sdk::License& license); virtual void SetLicense(const video_widevine_server::sdk::License& license);
// Call this on first decrypt to set the start of playback. This is // Call this on first decrypt to set the start of playback.
// for cases where usage begins not when the license is received, virtual void BeginDecryption(void);
// but at the start of playback
void BeginDecryption(void);
// UpdateLicense is used in handling a license response for a renewal request. // UpdateLicense is used in handling a license response for a renewal request.
// The response may only contain any policy fields that have changed. In this // The response may only contain any policy fields that have changed. In this
// case an exact copy is not what we want to happen. We also will receive an // case an exact copy is not what we want to happen. We also will receive an
// updated license_start_time from the server. The license will transition to // updated license_start_time from the server. The license will transition to
// kLicenseStateCanPlay if the license permits playback. // kLicenseStateCanPlay if the license permits playback.
void UpdateLicense(const video_widevine_server::sdk::License& license); virtual void UpdateLicense(
const video_widevine_server::sdk::License& license);
CdmResponseType Query(CdmQueryMap* key_info); virtual CdmResponseType Query(CdmQueryMap* key_info);
const video_widevine_server::sdk::LicenseIdentification& license_id() { virtual const LicenseIdentification& license_id() { return license_id_; }
return license_id_;
}
bool IsLicenseDurationExpired(int64_t current_time);
bool IsPlaybackDurationExpired(int64_t current_time);
private: private:
typedef enum { typedef enum {
kLicenseStateInitial, kLicenseStateInitial,
kLicenseStateInitialPendingUsage,
kLicenseStateCanPlay, kLicenseStateCanPlay,
kLicenseStateNeedRenewal, kLicenseStateNeedRenewal,
kLicenseStateWaitingLicenseUpdate, kLicenseStateWaitingLicenseUpdate,
@@ -73,6 +68,11 @@ class PolicyEngine {
void Init(Clock* clock); void Init(Clock* clock);
bool IsLicenseDurationExpired(int64_t current_time);
int64_t GetLicenseDurationRemaining(int64_t current_time);
bool IsPlaybackDurationExpired(int64_t current_time);
int64_t GetPlaybackDurationRemaining(int64_t current_time);
bool IsRenewalDelayExpired(int64_t current_time); bool IsRenewalDelayExpired(int64_t current_time);
bool IsRenewalRecoveryDurationExpired(int64_t current_time); bool IsRenewalRecoveryDurationExpired(int64_t current_time);
bool IsRenewalRetryIntervalExpired(int64_t current_time); bool IsRenewalRetryIntervalExpired(int64_t current_time);

View File

@@ -53,9 +53,10 @@ class Properties {
static bool GetFactoryKeyboxPath(std::string* keybox); static bool GetFactoryKeyboxPath(std::string* keybox);
static bool GetOEMCryptoPath(std::string* library_name); static bool GetOEMCryptoPath(std::string* library_name);
static bool GetSecurityLevelDirectories(std::vector<std::string>* dirs); static bool GetSecurityLevelDirectories(std::vector<std::string>* dirs);
static const std::string GetSecurityLevel(const CdmSessionId& session_id); static bool GetSecurityLevel(const CdmSessionId& session_id,
static const std::vector<uint8_t> GetServiceCertificate( std::string* security_level);
const CdmSessionId& session_id); static bool GetServiceCertificate(const CdmSessionId& session_id,
std::string* service_certificate);
static bool UsePrivacyMode(const CdmSessionId& session_id); static bool UsePrivacyMode(const CdmSessionId& session_id);
static uint32_t GetSessionSharingId(const CdmSessionId& session_id); static uint32_t GetSessionSharingId(const CdmSessionId& session_id);

View File

@@ -28,11 +28,6 @@ typedef std::string CdmUsageInfoReleaseMessage;
typedef std::string CdmProvisioningRequest; typedef std::string CdmProvisioningRequest;
typedef std::string CdmProvisioningResponse; typedef std::string CdmProvisioningResponse;
// Types for shared host/cdm interface pairs used to shared vendor data.
typedef std::pair<std::string, std::string> StringPairs;
typedef std::vector<uint8_t> VectorBytes;
typedef std::pair<std::string, VectorBytes> VectorPairs;
enum CdmResponseType { enum CdmResponseType {
NO_ERROR, NO_ERROR,
UNKNOWN_ERROR, UNKNOWN_ERROR,

View File

@@ -33,6 +33,7 @@ CdmSession::CdmSession(const CdmClientPropertySet* cdm_client_property_set)
is_offline_(false), is_offline_(false),
is_release_(false), is_release_(false),
is_usage_update_needed_(false), is_usage_update_needed_(false),
is_initial_decryption_(true),
is_certificate_loaded_(false) { is_certificate_loaded_(false) {
if (cdm_client_property_set) { if (cdm_client_property_set) {
Properties::AddSessionPropertySet(session_id_, cdm_client_property_set); Properties::AddSessionPropertySet(session_id_, cdm_client_property_set);
@@ -64,6 +65,7 @@ CdmResponseType CdmSession::Init() {
crypto_session_.reset(session.release()); crypto_session_.reset(session.release());
license_received_ = false; license_received_ = false;
reinitialize_session_ = false; reinitialize_session_ = false;
is_initial_decryption_ = true;
return NO_ERROR; return NO_ERROR;
} }
@@ -313,6 +315,10 @@ CdmResponseType CdmSession::Decrypt(const CdmDecryptionParameters& params) {
CdmResponseType status = crypto_session_->Decrypt(params); CdmResponseType status = crypto_session_->Decrypt(params);
if (NO_ERROR == status) { if (NO_ERROR == status) {
if (is_initial_decryption_) {
policy_engine_.BeginDecryption();
is_initial_decryption_ = false;
}
if (!is_usage_update_needed_) { if (!is_usage_update_needed_) {
is_usage_update_needed_ = is_usage_update_needed_ =
!license_parser_.provider_session_token().empty(); !license_parser_.provider_session_token().empty();
@@ -515,8 +521,9 @@ void CdmSession::OnKeyReleaseEvent(const CdmKeySetId& key_set_id) {
} }
SecurityLevel CdmSession::GetRequestedSecurityLevel() { SecurityLevel CdmSession::GetRequestedSecurityLevel() {
if (Properties::GetSecurityLevel(session_id_) std::string security_level;
.compare(QUERY_VALUE_SECURITY_LEVEL_L3) == 0) { if (Properties::GetSecurityLevel(session_id_, &security_level) &&
security_level == QUERY_VALUE_SECURITY_LEVEL_L3) {
return kLevel3; return kLevel3;
} }

View File

@@ -193,10 +193,10 @@ bool CdmLicense::PrepareKeyRequest(const InitializationData& init_data,
} }
bool privacy_mode_enabled = Properties::UsePrivacyMode(session_id); bool privacy_mode_enabled = Properties::UsePrivacyMode(session_id);
std::vector<uint8_t> cert = Properties::GetServiceCertificate(session_id); std::string serialized_service_certificate;
std::string serialized_service_certificate(cert.begin(), cert.end()); if (!Properties::GetServiceCertificate(session_id,
&serialized_service_certificate) ||
if (serialized_service_certificate.empty()) serialized_service_certificate.empty())
serialized_service_certificate = service_certificate_; serialized_service_certificate = service_certificate_;
if (privacy_mode_enabled && serialized_service_certificate.empty()) { if (privacy_mode_enabled && serialized_service_certificate.empty()) {

View File

@@ -2,16 +2,16 @@
#include "policy_engine.h" #include "policy_engine.h"
#include <algorithm> #include <limits.h>
#include <map>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
#include "clock.h"
#include "log.h" #include "log.h"
#include "properties.h" #include "properties.h"
#include "string_conversions.h" #include "string_conversions.h"
#include "clock.h"
#include "wv_cdm_constants.h" #include "wv_cdm_constants.h"
namespace wvcdm { namespace wvcdm {
@@ -59,7 +59,6 @@ void PolicyEngine::OnTimerEvent(bool* event_occurred, CdmEventType* event) {
// Test to determine if renewal should be attempted. // Test to determine if renewal should be attempted.
switch (license_state_) { switch (license_state_) {
case kLicenseStateInitialPendingUsage:
case kLicenseStateCanPlay: { case kLicenseStateCanPlay: {
if (IsRenewalDelayExpired(current_time)) if (IsRenewalDelayExpired(current_time))
renewal_needed = true; renewal_needed = true;
@@ -115,11 +114,6 @@ void PolicyEngine::UpdateLicense(
policy_.MergeFrom(license.policy()); policy_.MergeFrom(license.policy());
if (!policy_.can_play()) {
license_state_ = kLicenseStateExpired;
return;
}
// some basic license validation // some basic license validation
if (license_state_ == kLicenseStateInitial) { if (license_state_ == kLicenseStateInitial) {
// license start time needs to be present in the initial response // license start time needs to be present in the initial response
@@ -158,20 +152,23 @@ void PolicyEngine::UpdateLicense(
policy_max_duration_seconds_ = policy_.license_duration_seconds(); policy_max_duration_seconds_ = policy_.license_duration_seconds();
} }
if (!policy_.can_play()) {
license_state_ = kLicenseStateExpired;
return;
}
if (IsLicenseDurationExpired(current_time)) return;
if (IsPlaybackDurationExpired(current_time)) return;
// Update state // Update state
if (license_state_ == kLicenseStateInitial) { license_state_ = kLicenseStateCanPlay;
license_state_ = kLicenseStateInitialPendingUsage; can_decrypt_ = true;
}
else {
license_state_ = kLicenseStateCanPlay;
can_decrypt_ = true;
}
} }
void PolicyEngine::BeginDecryption() { void PolicyEngine::BeginDecryption() {
if (playback_start_time_ == 0) { if (playback_start_time_ == 0) {
switch (license_state_) { switch (license_state_) {
case kLicenseStateInitialPendingUsage: case kLicenseStateCanPlay:
case kLicenseStateNeedRenewal: case kLicenseStateNeedRenewal:
case kLicenseStateWaitingLicenseUpdate: case kLicenseStateWaitingLicenseUpdate:
playback_start_time_ = clock_->GetCurrentTime(); playback_start_time_ = clock_->GetCurrentTime();
@@ -179,12 +176,7 @@ void PolicyEngine::BeginDecryption() {
if (policy_.renew_with_usage()) { if (policy_.renew_with_usage()) {
license_state_ = kLicenseStateNeedRenewal; license_state_ = kLicenseStateNeedRenewal;
} }
else {
license_state_ = kLicenseStateCanPlay;
can_decrypt_ = true;
}
break; break;
case kLicenseStateCanPlay:
case kLicenseStateInitial: case kLicenseStateInitial:
case kLicenseStateExpired: case kLicenseStateExpired:
default: default:
@@ -209,17 +201,10 @@ CdmResponseType PolicyEngine::Query(CdmQueryMap* key_info) {
QUERY_VALUE_TRUE : QUERY_VALUE_FALSE; QUERY_VALUE_TRUE : QUERY_VALUE_FALSE;
(*key_info)[QUERY_KEY_RENEW_ALLOWED] = policy_.can_renew() ? (*key_info)[QUERY_KEY_RENEW_ALLOWED] = policy_.can_renew() ?
QUERY_VALUE_TRUE : QUERY_VALUE_FALSE; QUERY_VALUE_TRUE : QUERY_VALUE_FALSE;
int64_t remaining_time = policy_max_duration_seconds_ + ss << GetLicenseDurationRemaining(current_time);
license_received_time_ - current_time;
if (remaining_time < 0)
remaining_time = 0;
ss << remaining_time;
(*key_info)[QUERY_KEY_LICENSE_DURATION_REMAINING] = ss.str(); (*key_info)[QUERY_KEY_LICENSE_DURATION_REMAINING] = ss.str();
remaining_time = policy_.playback_duration_seconds() + playback_start_time_ - ss.str("");
current_time; ss << GetPlaybackDurationRemaining(current_time);
if (remaining_time < 0)
remaining_time = 0;
ss << remaining_time;
(*key_info)[QUERY_KEY_PLAYBACK_DURATION_REMAINING] = ss.str(); (*key_info)[QUERY_KEY_PLAYBACK_DURATION_REMAINING] = ss.str();
(*key_info)[QUERY_KEY_RENEWAL_SERVER_URL] = policy_.renewal_server_url(); (*key_info)[QUERY_KEY_RENEWAL_SERVER_URL] = policy_.renewal_server_url();
@@ -240,6 +225,16 @@ bool PolicyEngine::IsLicenseDurationExpired(int64_t current_time) {
current_time; 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_received_time_ - current_time;
if (remaining_time < 0) remaining_time = 0;
return remaining_time;
}
bool PolicyEngine::IsPlaybackDurationExpired(int64_t current_time) { bool PolicyEngine::IsPlaybackDurationExpired(int64_t current_time) {
return (policy_.playback_duration_seconds() > 0) && return (policy_.playback_duration_seconds() > 0) &&
playback_start_time_ && playback_start_time_ &&
@@ -247,6 +242,17 @@ bool PolicyEngine::IsPlaybackDurationExpired(int64_t current_time) {
current_time; 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;
if (remaining_time < 0) remaining_time = 0;
return remaining_time;
}
bool PolicyEngine::IsRenewalDelayExpired(int64_t current_time) { bool PolicyEngine::IsRenewalDelayExpired(int64_t current_time) {
return policy_.can_renew() && return policy_.can_renew() &&
(policy_.renewal_delay_seconds() > 0) && (policy_.renewal_delay_seconds() > 0) &&

View File

@@ -60,27 +60,30 @@ const CdmClientPropertySet* Properties::GetCdmClientPropertySet(
return NULL; return NULL;
} }
const std::string Properties::GetSecurityLevel(const CdmSessionId& session_id) { bool Properties::GetSecurityLevel(const CdmSessionId& session_id,
std::string* security_level) {
const CdmClientPropertySet* property_set = const CdmClientPropertySet* property_set =
GetCdmClientPropertySet(session_id); GetCdmClientPropertySet(session_id);
if (NULL == property_set) { if (NULL == property_set) {
LOGE("Properties::GetSecurityLevel: cannot find property set for %s", LOGE("Properties::GetSecurityLevel: cannot find property set for %s",
session_id.c_str()); session_id.c_str());
return ""; return false;
} }
return property_set->security_level(); *security_level = property_set->security_level();
return true;
} }
const std::vector<uint8_t> Properties::GetServiceCertificate( bool Properties::GetServiceCertificate(const CdmSessionId& session_id,
const CdmSessionId& session_id) { std::string* service_certificate) {
const CdmClientPropertySet* property_set = const CdmClientPropertySet* property_set =
GetCdmClientPropertySet(session_id); GetCdmClientPropertySet(session_id);
if (NULL == property_set) { if (NULL == property_set) {
LOGE("Properties::GetServiceCertificate: cannot find property set for %s", LOGE("Properties::GetServiceCertificate: cannot find property set for %s",
session_id.c_str()); session_id.c_str());
return std::vector<uint8_t>(); return false;
} }
return property_set->service_certificate(); *service_certificate = property_set->service_certificate();
return true;
} }
bool Properties::UsePrivacyMode(const CdmSessionId& session_id) { bool Properties::UsePrivacyMode(const CdmSessionId& session_id) {

View File

@@ -34,7 +34,6 @@ wvcdm::KeyId g_key_id_unwrapped;
wvcdm::CdmKeySystem g_key_system; wvcdm::CdmKeySystem g_key_system;
std::string g_license_server; std::string g_license_server;
wvcdm::KeyId g_wrong_key_id; wvcdm::KeyId g_wrong_key_id;
int g_use_full_path = 0; // cannot use boolean in getopt_long
// This is an RSA certificate message from the provisioning server. // This is an RSA certificate message from the provisioning server.
// The client sends this certificate to a license server for device // The client sends this certificate to a license server for device
@@ -257,17 +256,14 @@ int main(int argc, char **argv) {
int show_usage = 0; int show_usage = 0;
static const struct option long_options[] = { static const struct option long_options[] = {
{ "use_full_path", no_argument, &g_use_full_path, 0 },
{ "keyid", required_argument, NULL, 'k' }, { "keyid", required_argument, NULL, 'k' },
{ "server", required_argument, NULL, 's' }, { "server", required_argument, NULL, 's' },
{ "vmodule", required_argument, NULL, 0 },
{ "v", required_argument, NULL, 0 },
{ NULL, 0, NULL, '\0' } { NULL, 0, NULL, '\0' }
}; };
int option_index = 0; int option_index = 0;
int opt = 0; int opt = 0;
while ((opt = getopt_long(argc, argv, "k:p:s:u", long_options, &option_index)) != -1) { while ((opt = getopt_long(argc, argv, "k:s:v", long_options, &option_index)) != -1) {
switch (opt) { switch (opt) {
case 'k': { case 'k': {
g_key_id_pssh.clear(); g_key_id_pssh.clear();
@@ -279,8 +275,15 @@ int main(int argc, char **argv) {
g_license_server.assign(optarg); g_license_server.assign(optarg);
break; break;
} }
case 'u': { case 'v': {
g_use_full_path = 1; // This option _may_ have already been consumed by wvcdm::InitLogging()
// above, depending on the platform-specific logging implementation.
// We only tell getopt about it so that it is not an error. We ignore
// the option here when seen.
// TODO: Stop passing argv to InitLogging, and instead set the log
// level here through the logging API. We should keep all command-line
// parsing at the application level, rather than split between various
// apps and various platform-specific logging implementations.
break; break;
} }
case '?': { case '?': {
@@ -305,10 +308,6 @@ int main(int argc, char **argv) {
std::cout << "configure the key id or pssh, in hex format" << std::endl; std::cout << "configure the key id or pssh, in hex format" << std::endl;
std::cout << std::setw(30) << std::left << " default keyid:"; std::cout << std::setw(30) << std::left << " default keyid:";
std::cout << g_key_id_pssh << std::endl; std::cout << g_key_id_pssh << std::endl;
std::cout << std::setw(30) << std::left << " --use_full_path";
std::cout << "specify server url is not a proxy server" << std::endl;
std::cout << std::endl;
return 0; return 0;
} }

View File

@@ -5,36 +5,33 @@
namespace { namespace {
const std::string kWidevineKeySystem = "com.widevine.alpha"; const std::string kWidevineKeySystem = "com.widevine.alpha";
// Youtube Content Protection license server data // Content Protection license server data
const std::string kYtCpLicenseServer = const std::string kCpLicenseServer =
"http://wv-ref-eme-player.appspot.com/proxy"; "http://wv-ref-eme-player.appspot.com/proxy";
const std::string kYtCpClientAuth = ""; const std::string kCpClientAuth = "";
const std::string kYtCpKeyId = const std::string kCpKeyId =
"000000427073736800000000" // blob size and pssh "00000042" // blob size
"EDEF8BA979D64ACEA3C827DCD51D21ED00000022" // Widevine system id "70737368" // "pssh"
"08011a0d7769646576696e655f7465737422" // pssh data (streaming) "00000000" // flags
"0f73747265616d696e675f636c697031"; "edef8ba979d64acea3c827dcd51d21ed" // Widevine system id
"00000022" // pssh data size
const std::string kYtCpOfflineKeyId = // pssh data:
"000000407073736800000000" // blob size and pssh "08011a0d7769646576696e655f746573"
"EDEF8BA979D64ACEA3C827DCD51D21ED00000020" // Widevine system id "74220f73747265616d696e675f636c69"
"08011a0d7769646576696e655f7465737422" //pssh data (offline) "7031";
"0d6f66666c696e655f636c697031"; const std::string kCpOfflineKeyId =
"00000040" // blob size
// Youtube license server data "70737368" // "pssh"
const std::string kYtLicenseServer = "00000000" // flags
"https://www.youtube.com/api/drm/" "edef8ba979d64acea3c827dcd51d21ed" // Widevine system id
"widevine?video_id=03681262dc412c06&source=YOUTUBE"; "00000020" // pssh data size
const std::string kYtClientAuth = ""; // pssh data:
const std::string kYtKeyId = "08011a0d7769646576696e655f746573"
"000000347073736800000000" // blob size and pssh "74220d6f66666c696e655f636c697031";
"EDEF8BA979D64ACEA3C827DCD51D21ED00000014" // Widevine system id
"0801121093789920E8D6520098577DF8F2DD5546"; // pssh data
// Google Play license server data // Google Play license server data
const std::string kGpLicenseServer = const std::string kGpLicenseServer =
"https://jmt17.google.com/video/license/GetCencLicense"; "https://jmt17.google.com/video/license/GetCencLicense";
// Test client authorization string. // Test client authorization string.
// NOTE: Append a userdata attribute to place a unique marker that the // NOTE: Append a userdata attribute to place a unique marker that the
// server team can use to track down specific requests during debugging // server team can use to track down specific requests during debugging
@@ -42,6 +39,16 @@ const std::string kGpLicenseServer =
// "<existing-client-auth-string>&userdata=jbmr2.dev" // "<existing-client-auth-string>&userdata=jbmr2.dev"
const std::string kGpClientAuth = const std::string kGpClientAuth =
"?source=YOUTUBE&video_id=EGHC6OHNbOo&oauth=ya.gtsqawidevine"; "?source=YOUTUBE&video_id=EGHC6OHNbOo&oauth=ya.gtsqawidevine";
const std::string kGpKeyId =
"00000034" // blob size
"70737368" // "pssh"
"00000000" // flags
"edef8ba979d64acea3c827dcd51d21ed" // Widevine system id
"00000014" // pssh data size
// pssh data:
"08011210e02562e04cd55351b14b3d74"
"8d36ed8e";
const std::string kGpOfflineKeyId = kGpKeyId;
const std::string kGpClientOfflineQueryParameters = const std::string kGpClientOfflineQueryParameters =
"&offline=true"; "&offline=true";
@@ -50,16 +57,16 @@ const std::string kGpClientOfflineRenewalQueryParameters =
const std::string kGpClientOfflineReleaseQueryParameters = const std::string kGpClientOfflineReleaseQueryParameters =
"&offline=true&release=true"; "&offline=true&release=true";
const std::string kGpKeyId =
"000000347073736800000000" // blob size and pssh
"edef8ba979d64acea3c827dcd51d21ed00000014" // Widevine system id
"08011210e02562e04cd55351b14b3d748d36ed8e"; // pssh data
// An invalid key id, expected to fail // An invalid key id, expected to fail
const std::string kWrongKeyId = const std::string kWrongKeyId =
"000000347073736800000000" // blob size and pssh "00000034" // blob size
"EDEF8BA979D64ACEA3C827DCD51D21ED00000014" // Widevine system id "70737368" // "pssh"
"0901121094889920E8D6520098577DF8F2DD5546"; // pssh data "00000000" // flags
"edef8ba979d64acea3c827dcd51d21ed" // Widevine system id
"00000014" // pssh data size
// pssh data:
"0901121094889920e8d6520098577df8"
"f2dd5546";
// URL of provisioning server (returned by GetProvisioningRequest()) // URL of provisioning server (returned by GetProvisioningRequest())
const std::string kProductionProvisioningServerUrl = const std::string kProductionProvisioningServerUrl =
@@ -67,22 +74,13 @@ const std::string kProductionProvisioningServerUrl =
"certificateprovisioning/v1/devicecertificates/create" "certificateprovisioning/v1/devicecertificates/create"
"?key=AIzaSyB-5OLKTx2iU5mko18DfdwK5611JIjbUhE"; "?key=AIzaSyB-5OLKTx2iU5mko18DfdwK5611JIjbUhE";
// Return production-rooted certificates that have test bit set,
// request_license_test uses this url.
const std::string kProductionTestProvisioningServerUrl =
"https://www.googleapis.com/"
"certificateprovisioning/v1exttest/devicecertificates/create"
"?key=AIzaSyB-5OLKTx2iU5mko18DfdwK5611JIjbUhE";
const std::string kServerSdkLicenseServer =
"http://kir03fcpg174.widevine.net/widevine/cgi-bin/drm.cgi";
const wvcdm::ConfigTestEnv::LicenseServerConfiguration license_servers[] = { const wvcdm::ConfigTestEnv::LicenseServerConfiguration license_servers[] = {
{ wvcdm::kGooglePlayServer, kGpLicenseServer, kGpClientAuth, kGpKeyId, { wvcdm::kGooglePlayServer, kGpLicenseServer,
kGpKeyId }, kGpClientAuth, kGpKeyId, kGpOfflineKeyId },
{ wvcdm::kYouTubeContentProtectionServer, kYtCpLicenseServer, { wvcdm::kContentProtectionServer, kCpLicenseServer,
kYtCpClientAuth, kYtCpKeyId, kYtCpOfflineKeyId } kCpClientAuth, kCpKeyId, kCpOfflineKeyId },
}; };
} // namespace } // namespace
namespace wvcdm { namespace wvcdm {

View File

@@ -9,7 +9,7 @@
namespace wvcdm { namespace wvcdm {
typedef enum { typedef enum {
kGooglePlayServer, kGooglePlayServer,
kYouTubeContentProtectionServer kContentProtectionServer,
} LicenseServerId; } LicenseServerId;
// Configures default test environment. // Configures default test environment.

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,12 @@
// Copyright 2013 Google Inc. All Rights Reserved. // Copyright 2013 Google Inc. All Rights Reserved.
// //
// Log - implemented using stdout. // Log - implemented using stdout.
//
#define LOG_BUF_SIZE 4096
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "log.h" #include "log.h"
namespace wvcdm { namespace wvcdm {
@@ -35,13 +34,13 @@ void Log(const char* file, int line, LogPriority level, const char* fmt, ...) {
} }
if (level > g_cutoff) return; if (level > g_cutoff) return;
va_list ap;
char buf[LOG_BUF_SIZE];
va_start(ap, fmt);
vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
va_end(ap);
printf("[%s:%s(%d)] ", severities[level], file, line); printf("[%s:%s(%d)] ", severities[level], file, line);
fputs(buf, stdout);
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
putc('\n', stdout); putc('\n', stdout);
} }

View File

@@ -9,9 +9,9 @@
#ifndef OEMCRYPTO_CENC_H_ #ifndef OEMCRYPTO_CENC_H_
#define OEMCRYPTO_CENC_H_ #define OEMCRYPTO_CENC_H_
#include<stdbool.h> #include <stdbool.h>
#include<stddef.h> #include <stddef.h>
#include<stdint.h> #include <stdint.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@@ -11,6 +11,7 @@
'product_name%': '"UndefinedProductName"', 'product_name%': '"UndefinedProductName"',
'buildinfo_data%': '"UndefinedBuildInfo"', 'buildinfo_data%': '"UndefinedBuildInfo"',
'oemcrypto_target%': '../oemcrypto/mock/oec_mock.gyp:oec_mock', 'oemcrypto_target%': '../oemcrypto/mock/oec_mock.gyp:oec_mock',
'oemcrypto_v8%': 'false',
'protobuf_source_dir%': '', 'protobuf_source_dir%': '',
'use_system_protobuf%': 'true', 'use_system_protobuf%': 'true',
'protoc_dir%': '/usr/bin', 'protoc_dir%': '/usr/bin',

View File

@@ -52,6 +52,7 @@
'target_name': 'protobuf', 'target_name': 'protobuf',
'type': 'static_library', 'type': 'static_library',
'toolsets': ['host'], 'toolsets': ['host'],
'includes': ['xcode_host.gypi'], # xcode workaround
'sources': [ 'sources': [
'<@(protobuf_lite_sources)', '<@(protobuf_lite_sources)',
@@ -89,6 +90,7 @@
'target_name': 'protoc', 'target_name': 'protoc',
'type': 'executable', 'type': 'executable',
'toolsets': ['host'], 'toolsets': ['host'],
'includes': ['xcode_host.gypi'], # xcode workaround
'sources': [ 'sources': [
'<(protobuf_source_dir)/src/google/protobuf/compiler/code_generator.cc', '<(protobuf_source_dir)/src/google/protobuf/compiler/code_generator.cc',
'<(protobuf_source_dir)/src/google/protobuf/compiler/command_line_interface.cc', '<(protobuf_source_dir)/src/google/protobuf/compiler/command_line_interface.cc',

15
third_party/xcode_host.gypi vendored Normal file
View File

@@ -0,0 +1,15 @@
# Copyright 2014 Google Inc. All Rights Reserved.
# Since the Xcode generator for gyp doesn't support host targets,
# the workaround is to add a special xcode_settings section to any
# target that must be built for the host. This file encapsulates
# those settings such that they can be included into any target.
{
'xcode_settings': {
'VALID_ARCHS': 'i386 x86_64',
'IPHONEOS_DEPLOYMENT_TARGET': '',
'TARGETED_DEVICE_FAMILY': '',
'SDKROOT': '',
},
}