Files
ce_cdm/cdm/test/cdm_api_test.cpp
Joey Parrish aaa3c6192a Source release v2.1.2-0-773 + third_party libs
Change-Id: Ia07608577b65b301c22a8ff4bf7f743c2d3f9274
2014-06-10 13:37:04 -07:00

1554 lines
51 KiB
C++

// Copyright 2013 Google Inc. All Rights Reserved.
//
// This source file provides a basic set of unit tests for the Content
// Decryption Module (CDM). It exercises much of the API that will be
// required by the host application to get the license and keys for
// rendering protected content.
// Review the TestHost class below to observe how the CDM interfaces with
// the host application.
//
#include <set>
#include <errno.h>
#include <getopt.h>
#include <pthread.h>
#include <unistd.h>
#include "clock.h"
#include "config_test_env.h"
#include "content_decryption_module.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "license_request.h"
#include "log.h"
#include "scoped_ptr.h"
#include "string_conversions.h"
#include "url_request.h"
#include "wv_cdm_types.h"
#include "wv_cdm_common.h"
using ::testing::_;
using ::testing::AtLeast;
using ::testing::Invoke;
using ::testing::Return;
using wvcdm::scoped_ptr;
static const int kTestPolicyRenewalDelaySeconds = 60;
static const int kDelayWaitToForRenewalMessageSeconds = 2;
// Linux based get time for host.
// This can be tailored if required.
double GetCurrentTestTime() {
struct timeval tv;
tv.tv_sec = tv.tv_usec = 0;
gettimeofday(&tv, NULL);
return tv.tv_sec;
}
using wvcdm::StringPairs;
using wvcdm::VectorPairs;
// These classes below are naive implementation of the abstract classes defined
// in the CDM interface (content_decryptiom_module.h), which are used for tests
// only.
class TestBuffer : public cdm::Buffer {
public:
static TestBuffer* Create(uint32_t capacity);
virtual void Destroy() OVERRIDE;
virtual int32_t Capacity() const OVERRIDE;
virtual uint8_t* Data() OVERRIDE;
virtual void SetSize(int32_t size) OVERRIDE;
virtual int32_t Size() const OVERRIDE;
private:
// TestBuffer can only be created by calling Create().
explicit TestBuffer(uint32_t capacity);
// TestBuffer can only be destroyed by calling Destroy().
virtual ~TestBuffer();
uint8_t* buffer_;
int32_t capacity_;
int32_t size_;
CORE_DISALLOW_COPY_AND_ASSIGN(TestBuffer);
};
class TestHostFile {
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:
// These structs are used to store the KeyMessages and KeyErrors passed to
// this class' objects.
struct KeyMessage {
KeyMessage() {}
std::string session_id;
std::string message;
std::string default_url;
};
struct KeyError {
KeyError() : error_code(cdm::kUnknownError), system_code(0) {}
std::string session_id;
cdm::MediaKeyError error_code;
uint32_t system_code;
};
TestHost();
virtual ~TestHost();
// cdm::Host implementation.
virtual cdm::Buffer* Allocate(int32_t capacity) OVERRIDE;
MOCK_METHOD2(SetTimer, void(int64_t, void*));
virtual void DoSetTimer(int64_t delay_ms, void* context);
// Returns the current "global" time from the GetCurrentTestTime() function
// 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,
const char* message, int32_t message_length,
const char* default_url,
int32_t default_url_length) OVERRIDE;
virtual void SendKeyError(const char* session_id, int32_t session_id_length,
cdm::MediaKeyError error_code,
uint32_t system_code) OVERRIDE;
virtual void GetPrivateData(int32_t* instance,
GetPrivateInterface* get_interface) OVERRIDE;
virtual int GetPlatformString(const std::string& name,
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.
void SetCurrentTime(double current_time);
void FastForwardTimeForNextTimerEvent();
int KeyMessagesSize() const;
int KeyErrorsSize() const;
// Returns Key{Message,Error} (replace Message with Error for KeyError). It
// returns the most recent message passed to SendKeyMessage(). Another call
// to this method without a new SendKeyMessage() call will return an empty
// KeyMessage struct.
KeyMessage GetLastKeyMessage();
KeyError GetLastKeyError();
KeyMessage GetKeyMessage(int index) const;
KeyError GetKeyError(int index) const;
void* context() { return context_; }
void SetCdmPtr(cdm::ContentDecryptionModule* host_cdm_ptr);
virtual double GetCurrentTestTime();
uint32_t GetTickCount();
private:
// This is used in GetCurrentWallTimeInSeconds(). This field is used to
// control the "current time".
double current_time_;
bool current_time_is_set_;
std::vector<KeyMessage> key_messages_;
std::vector<KeyError> key_errors_;
bool has_new_key_message_;
bool has_new_key_error_;
void* context_;
int64_t delay_ms_;
cdm::ContentDecryptionModule* host_cdm_ptr_;
// 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);
};
class TestHostFactory {
public:
TestHost* GetTestHost();
private:
scoped_ptr<TestHost> test_host_;
};
TestBuffer* TestBuffer::Create(uint32_t capacity) {
return new TestBuffer(capacity);
}
void TestBuffer::Destroy() {
if (buffer_) {
delete[] buffer_;
buffer_ = NULL;
}
delete this;
}
int32_t TestBuffer::Capacity() const { return capacity_; }
uint8_t* TestBuffer::Data() { return buffer_; }
void TestBuffer::SetSize(int32_t size) { size_ = size; }
int32_t TestBuffer::Size() const { return size_; }
TestBuffer::TestBuffer(uint32_t capacity)
: buffer_(new uint8_t[capacity]), capacity_(capacity) {}
TestBuffer::~TestBuffer() {}
TestHost::TestHost()
: current_time_(::GetCurrentTestTime()),
current_time_is_set_(false),
has_new_key_message_(false),
has_new_key_error_(false),
context_(NULL),
delay_ms_(0),
host_cdm_ptr_(NULL) {
LoadPersistentValues();
}
TestHost::~TestHost() {}
cdm::Buffer* TestHost::Allocate(int32_t capacity) {
return TestBuffer::Create(capacity);
}
// SetTimer is a mock method mapping to DoSetTimer(). The cdm::Host
// calls back to the TimerExpired callback
// every delay_ms. Zero delay_ms means WV is requesting
// termination of timer services.
void TestHost::DoSetTimer(int64_t delay_ms, void* context) {
if (delay_ms == 0) {
simple_thread_.Stop();
return;
}
simple_thread_.Start(delay_ms, (void*)host_cdm_ptr_, context);
}
void TestHost::SendKeyMessage(const char* session_id, int32_t session_id_length,
const char* message, int32_t message_length,
const char* default_url,
int32_t default_url_length) {
KeyMessage key_message;
key_message.session_id.assign(session_id, session_id_length);
key_message.message.assign(message, message_length);
key_message.default_url.assign(default_url, default_url_length);
key_messages_.push_back(key_message);
has_new_key_message_ = true;
}
void TestHost::SendKeyError(const char* session_id, int32_t session_id_length,
cdm::MediaKeyError error_code,
uint32_t system_code) {
KeyError key_error;
key_error.session_id.assign(session_id, session_id_length);
key_error.error_code = error_code;
key_error.system_code = system_code;
key_errors_.push_back(key_error);
has_new_key_error_ = true;
}
void TestHost::SetCurrentTime(double current_time) {
current_time_is_set_ = true;
current_time_ = current_time;
}
void TestHost::FastForwardTimeForNextTimerEvent() {
current_time_is_set_ = true;
current_time_ += (delay_ms_ / 1000.0);
delay_ms_ = 0;
}
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,
const std::string& value) {
StringPairs sp(name, value);
platform_strings_set_.insert(sp);
return 1;
}
int TestHost::PersistPlatformString(const std::string& name,
const std::string& value) {
StringPairs sp(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::KeyErrorsSize() const { return key_errors_.size(); }
double TestHost::GetCurrentTestTime() {
current_time_is_set_ = true;
FastForwardTimeForNextTimerEvent();
return current_time_;
}
TestHost::KeyMessage TestHost::GetLastKeyMessage() {
if (!has_new_key_message_) {
LOGD("No NEW");
return KeyMessage();
}
if (key_messages_.empty()) {
LOGD("empty");
return KeyMessage();
}
LOGD("not empty");
has_new_key_message_ = false;
return key_messages_.back();
}
TestHost::KeyError TestHost::GetLastKeyError() {
if (!has_new_key_error_) return KeyError();
if (key_errors_.empty()) return KeyError();
has_new_key_error_ = false;
return key_errors_.back();
}
TestHost::KeyMessage TestHost::GetKeyMessage(int index) const {
return key_messages_[index];
}
TestHost::KeyError TestHost::GetKeyError(int index) const {
return key_errors_[index];
}
void TestHost::SetCdmPtr(cdm::ContentDecryptionModule* host_cdm_ptr) {
host_cdm_ptr_ = host_cdm_ptr;
}
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 {
public:
TestDecryptedBlock();
virtual ~TestDecryptedBlock();
virtual void SetDecryptedBuffer(cdm::Buffer* buffer) OVERRIDE;
virtual cdm::Buffer* DecryptedBuffer() OVERRIDE;
virtual void SetTimestamp(int64_t timestamp) OVERRIDE;
virtual int64_t Timestamp() const OVERRIDE;
private:
cdm::Buffer* buffer_;
int64_t timestamp_;
CORE_DISALLOW_COPY_AND_ASSIGN(TestDecryptedBlock);
};
TestDecryptedBlock::TestDecryptedBlock() : buffer_(NULL), timestamp_(0) {}
TestDecryptedBlock::~TestDecryptedBlock() {
if (buffer_) {
buffer_->Destroy();
buffer_ = NULL;
}
}
void TestDecryptedBlock::SetDecryptedBuffer(cdm::Buffer* buffer) {
if (buffer_) buffer_->Destroy();
buffer_ = buffer;
}
cdm::Buffer* TestDecryptedBlock::DecryptedBuffer() { return buffer_; }
void TestDecryptedBlock::SetTimestamp(int64_t timestamp) {
timestamp_ = timestamp;
}
int64_t TestDecryptedBlock::Timestamp() const { return timestamp_; }
namespace {
// Default license server, can be configured using --server command line option
// Default key id (pssh), can be configured using --keyid command line option
const char kKeySystemWidevine[] = "com.widevine.alpha";
std::string g_client_auth;
wvcdm::KeyId g_key_id;
wvcdm::CdmKeySystem g_key_system;
std::string g_license_server;
wvcdm::KeyId g_wrong_key_id;
int g_use_full_path = 0; // cannot use boolean in getopt_long
} // namespace
namespace wvcdm {
void* GetCdmHost(int host_interface_version, void* user_data);
class WvCdmApiTest : public testing::Test {
public:
WvCdmApiTest() : cdm_(NULL) {}
~WvCdmApiTest() {
if (cdm_) cdm_->Destroy();
}
protected:
virtual void SetUp() {
cdm_ = reinterpret_cast<cdm::ContentDecryptionModule*>(::CreateCdmInstance(
cdm::kCdmInterfaceVersion, kKeySystemWidevine,
strlen(kKeySystemWidevine), GetCdmHost, &host_factory_));
host_ = host_factory_.GetTestHost();
host_->SetCdmPtr(cdm_);
host_->SetPlatformString("SecurityLevel", "L1");
host_->SetPlatformString("PrivacyOn", "False");
host_->SetPlatformString("UsesServiceCertificates", "False");
// By default we allow the timer to fire twice; once
// 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;
VectorBytes cert(kPrivacyCertSize);
for (size_t i = 0; i < cert.size(); i++) {
cert[i] = i;
}
host_->SetPlatformByteArray("ServiceCertificate", cert);
INITIALIZE_CDM_MODULE();
}
void GenerateKeyRequest(const std::string& key_system,
const std::string& key_id) {
std::string init_data = key_id;
cdm::Status status = cdm_->GenerateKeyRequest(
NULL, 0, (const uint8_t*)init_data.data(), init_data.length());
// cdm::Host must handle the certificate provisioning request.
if (status == cdm::kNeedsDeviceCertificate) {
std::string provisioning_server_url;
std::string prov_request;
status = cdm_->GetProvisioningRequest(&prov_request,
&provisioning_server_url);
if (status == cdm::kSuccess) {
UrlRequest url_request(provisioning_server_url);
url_request.PostCertRequestInQueryString(prov_request);
std::string message;
bool ok = url_request.GetResponse(&message);
EXPECT_TRUE(ok);
if (ok) {
status = cdm_->HandleProvisioningResponse(message);
if (status == cdm::kSuccess) {
status = cdm_->GenerateKeyRequest(NULL, 0,
(const uint8_t*)init_data.data(), init_data.length());
}
}
}
}
EXPECT_EQ(cdm::kSuccess, status);
}
// posts a request and extracts the drm message from the response
std::string GetKeyRequestResponse(const std::string& server_url,
const std::string& client_auth,
int expected_response) {
// Use secure connection and chunk transfer coding.
UrlRequest url_request(server_url + client_auth);
if (!url_request.is_connected()) {
return "";
}
url_request.PostRequest(key_msg_);
std::string 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
// return 500; treat anything other than 200 as an invalid message.
int status_code = url_request.GetStatusCode(response);
int kHttpOk = 200;
if (expected_response == kHttpOk) {
EXPECT_EQ(kHttpOk, status_code);
} else {
EXPECT_NE(kHttpOk, status_code);
}
if (status_code != kHttpOk) {
return "";
} else {
std::string drm_msg;
LicenseRequest lic_request;
lic_request.GetDrmMessage(response, drm_msg);
LOGV("drm msg: %u bytes\r\n%s", drm_msg.size(),
HexEncode(reinterpret_cast<const uint8_t*>(drm_msg.data()),
drm_msg.size()).c_str());
return drm_msg;
}
}
void CancelKeyRequest(std::string session_id) {
cdm::Status status =
cdm_->CancelKeyRequest(session_id.data(), session_id.length());
EXPECT_EQ(cdm::kSuccess, status);
}
void AddKey(std::string& session_id, std::string& drm_msg) {
cdm::Status status =
cdm_->AddKey(session_id.data(), session_id.size(),
(const uint8_t*)drm_msg.data(), drm_msg.size(), NULL, 0);
EXPECT_EQ(cdm::kSuccess, status);
}
// Level 1 / Level 2 payload comes back in the cpu memory as cleartext.
void DecryptClearPayloadTest() {
typedef struct DecryptionData {
bool is_encrypted;
bool is_secure;
wvcdm::KeyId key_id;
std::vector<uint8_t> encrypt_data;
std::vector<uint8_t> iv;
size_t block_offset;
std::vector<uint8_t> decrypt_data;
} DecryptionData;
DecryptionData data;
data.is_encrypted = true;
data.is_secure = false;
// Key ID of key used to encrypt the test content.
// This is used by the secure layer to look up the content key
data.key_id = wvcdm::a2bs_hex("E02562E04CD55351B14B3D748D36ED8E");
// Dummy encrypted data.
data.encrypt_data = wvcdm::a2b_hex(
"3b2cbde084973539329bd5656da22d20396249bf4a18a51c38c4743360cc9fea"
"a1c78d53de1bd7e14dc5d256fd20a57178a98b83804258c239acd7aa38f2d7d2"
"eca614965b3d22049e19e236fc1800e60965d8b36415677bf2f843d50a6943c4"
"683c07c114a32f5e5fbc9939c483c3a1b2ecd3d82b554d649798866191724283"
"f0ab082eba2da79aaca5c4eaf186f9ee9a0c568f621f705a578f30e4e2ef7b96"
"5e14cc046ce6dbf272ee5558b098f332333e95fc879dea6c29bf34acdb649650"
"f08201b9e649960f2493fd7677cc3abf5ae70e5445845c947ba544456b431646"
"d95a133bff5f57614dda5e4446cd8837901d074149dadf4b775b5b07bb88ca20");
data.iv = wvcdm::a2b_hex("4cca615fc013102892f91efee936639b");
data.block_offset = 0;
// Expected decrypted data.
data.decrypt_data = wvcdm::a2b_hex(
"5a36c0b633b58faf22156d78fdfb608e54a8095788b2b0463ef78d030b4abf82"
"eff34b8d9b7b6352e7d72de991b599662aa475da355033620152e2356ebfadee"
"06172be9e1058fa177e223b9fdd191380cff53c3ea810c6fd852a1df4967b799"
"415179a2276ec388ef763bab89605b9c6952c28dc8d6bf86b03fabbb46b392a3"
"1dad15be602eeeeabb45070b3e25d6bb0217073b1fc44c9fe848594121fd6a91"
"304d605e21f69615e1b57db18312b6b948725724b74e91d8aea7371e99532469"
"1b358bdee873f1936b63efe83d190a53c2d21754d302d63ff285174023473755"
"58b938c2e3ca4c2ce48942da97f9e45797f2c074ac6004734e93784a48af6160");
cdm::InputBuffer buf;
buf.data = &data.encrypt_data[0];
buf.data_size = data.encrypt_data.size();
buf.key_id = (const uint8_t*)&data.key_id[0];
buf.key_id_size = data.key_id.length();
buf.iv = &data.iv[0];
buf.iv_size = data.iv.size();
buf.data_offset = 0;
cdm::SubsampleEntry sub(0, buf.data_size);
buf.subsamples = &sub;
buf.num_subsamples = 1;
buf.timestamp = 10;
TestDecryptedBlock output;
cdm::Status status = cdm_->Decrypt(buf, &output);
EXPECT_EQ(cdm::kSuccess, status);
EXPECT_EQ(0, memcmp(output.DecryptedBuffer()->Data(), &data.decrypt_data[0],
buf.data_size));
}
// Level 1 / Level 2 payload comes back in the cpu memory as cleartext.
void DecryptClearSubsampleTest() {
typedef struct DecryptionData {
bool is_encrypted;
bool is_secure;
wvcdm::KeyId key_id;
std::vector<uint8_t> encrypt_data;
std::vector<uint8_t> iv;
size_t block_offset;
std::vector<uint8_t> decrypt_data;
} DecryptionData;
DecryptionData data;
data.is_encrypted = true;
data.is_secure = false;
// Key ID of key used to encrypt the test content.
// This is used by the secure layer to look up the content key
data.key_id = wvcdm::a2bs_hex("E02562E04CD55351B14B3D748D36ED8E");
// Dummy encrypted data. This is a combination of clear and
// encrypted data.
data.encrypt_data = wvcdm::a2b_hex(
"5a36c0b633b58faf22156d78fdfb608e54a8095788b2b0463ef78d030b4abf82"
"3b2cbde084973539329bd5656da22d20396249bf4a18a51c38c4743360cc9fea"
"a1c78d53de1bd7e14dc5d256fd20a57178a98b83804258c239acd7aa38f2d7d2"
"5a36c0"
"eca614965b"
"58b938c2e3ca4c2ce4"
"3d22049e19e236fc1800e60965d8b36415677bf2f843d50a6943c4"
"683c07c114a32f5e5fbc9939c483c3a1b2ecd3d82b554d649798866191724283"
"f0ab082eba2da79aaca5c4eaf186f9ee9a0c568f621f705a578f30e4e2ef7b96"
"5e14cc046ce6dbf272ee5558b098f332333e95fc879dea6c29bf34acdb649650"
"f08201b9e649960f2493fd7677cc3abf5ae70e5445845c947ba544456b431646"
"d95a133bff5f57614dda5e4446cd8837901d074149dadf4b775b5b07bb88ca20");
data.iv = wvcdm::a2b_hex("4cca615fc013102892f91efee936639b");
data.block_offset = 0;
// Expected decrypted data.
data.decrypt_data = wvcdm::a2b_hex(
"5a36c0b633b58faf22156d78fdfb608e54a8095788b2b0463ef78d030b4abf82"
"5a36c0b633b58faf22156d78fdfb608e54a8095788b2b0463ef78d030b4abf82"
"eff34b8d9b7b6352e7d72de991b599662aa475da355033620152e2356ebfadee"
"5a36c0"
"06172be9e1"
"58b938c2e3ca4c2ce4"
"058fa177e223b9fdd191380cff53c3ea810c6fd852a1df4967b799"
"415179a2276ec388ef763bab89605b9c6952c28dc8d6bf86b03fabbb46b392a3"
"1dad15be602eeeeabb45070b3e25d6bb0217073b1fc44c9fe848594121fd6a91"
"304d605e21f69615e1b57db18312b6b948725724b74e91d8aea7371e99532469"
"1b358bdee873f1936b63efe83d190a53c2d21754d302d63ff285174023473755"
"58b938c2e3ca4c2ce48942da97f9e45797f2c074ac6004734e93784a48af6160");
cdm::InputBuffer buf;
buf.data = &data.encrypt_data[0];
buf.data_size = data.encrypt_data.size();
buf.key_id = (const uint8_t*) &data.key_id[0];
buf.key_id_size = data.key_id.length();
buf.iv = &data.iv[0];
buf.iv_size = data.iv.size();
buf.data_offset = 0;
std::vector<cdm::SubsampleEntry> sub;
sub.push_back(cdm::SubsampleEntry(32, 64));
sub.push_back(cdm::SubsampleEntry(3, 5));
sub.push_back(
cdm::SubsampleEntry(9,
data.encrypt_data.size() - (32 + 64 + 3 + 5 + 9)));
buf.subsamples = &sub[0];
buf.num_subsamples = sub.size();
buf.timestamp = 10;
TestDecryptedBlock output;
cdm::Status status = cdm_->Decrypt(buf, &output);
EXPECT_EQ(cdm::kSuccess, status);
EXPECT_EQ(
0,
memcmp(output.DecryptedBuffer()->Data(), &data.decrypt_data[0],
buf.data_size));
}
void DecryptClearSubsampleTestWithMissingSubsampleInfo() {
typedef struct DecryptionData {
bool is_encrypted;
bool is_secure;
wvcdm::KeyId key_id;
std::vector<uint8_t> encrypt_data;
std::vector<uint8_t> iv;
size_t block_offset;
std::vector<uint8_t> decrypt_data;
} DecryptionData;
DecryptionData data;
data.is_encrypted = true;
data.is_secure = false;
// Key ID of key used to encrypt the test content.
// This is used by the secure layer to look up the content key
data.key_id = wvcdm::a2bs_hex("E02562E04CD55351B14B3D748D36ED8E");
// Dummy encrypted data. This is a combination of clear and
// encrypted data.
data.encrypt_data = wvcdm::a2b_hex(
"5a36c0b633b58faf22156d78fdfb608e54a8095788b2b0463ef78d030b4abf82"
"3b2cbde084973539329bd5656da22d20396249bf4a18a51c38c4743360cc9fea"
"a1c78d53de1bd7e14dc5d256fd20a57178a98b83804258c239acd7aa38f2d7d2"
"5a36c0"
"eca614965b"
"58b938c2e3ca4c2ce4"
"3d22049e19e236fc1800e60965d8b36415677bf2f843d50a6943c4"
"683c07c114a32f5e5fbc9939c483c3a1b2ecd3d82b554d649798866191724283"
"f0ab082eba2da79aaca5c4eaf186f9ee9a0c568f621f705a578f30e4e2ef7b96"
"5e14cc046ce6dbf272ee5558b098f332333e95fc879dea6c29bf34acdb649650"
"f08201b9e649960f2493fd7677cc3abf5ae70e5445845c947ba544456b431646"
"d95a133bff5f57614dda5e4446cd8837901d074149dadf4b775b5b07bb88ca20");
data.iv = wvcdm::a2b_hex("4cca615fc013102892f91efee936639b");
data.block_offset = 0;
// Expected decrypted data.
data.decrypt_data = wvcdm::a2b_hex(
"5a36c0b633b58faf22156d78fdfb608e54a8095788b2b0463ef78d030b4abf82"
"5a36c0b633b58faf22156d78fdfb608e54a8095788b2b0463ef78d030b4abf82"
"eff34b8d9b7b6352e7d72de991b599662aa475da355033620152e2356ebfadee"
"5a36c0"
"06172be9e1"
"58b938c2e3ca4c2ce4"
"058fa177e223b9fdd191380cff53c3ea810c6fd852a1df4967b799"
"415179a2276ec388ef763bab89605b9c6952c28dc8d6bf86b03fabbb46b392a3"
"1dad15be602eeeeabb45070b3e25d6bb0217073b1fc44c9fe848594121fd6a91"
"304d605e21f69615e1b57db18312b6b948725724b74e91d8aea7371e99532469"
"1b358bdee873f1936b63efe83d190a53c2d21754d302d63ff285174023473755"
"58b938c2e3ca4c2ce48942da97f9e45797f2c074ac6004734e93784a48af6160");
cdm::InputBuffer buf;
buf.data = &data.encrypt_data[0];
buf.data_size = data.encrypt_data.size();
buf.key_id = (const uint8_t*)&data.key_id[0];
buf.key_id_size = data.key_id.length();
buf.iv = &data.iv[0];
buf.iv_size = data.iv.size();
buf.data_offset = 0;
std::vector<cdm::SubsampleEntry> sub;
sub.push_back(cdm::SubsampleEntry(32, 64));
sub.push_back(cdm::SubsampleEntry(3, 5));
sub.push_back(cdm::SubsampleEntry(
9, data.encrypt_data.size() - (32 + 64 + 3 + 5 + 9)));
//buf.subsamples = &sub[0];
//buf.num_subsamples = sub.size();
buf.timestamp = 10;
TestDecryptedBlock output;
cdm::Status status = cdm_->Decrypt(buf, &output);
EXPECT_EQ(cdm::kDecryptError, status);
buf.subsamples = &sub[0];
status = cdm_->Decrypt(buf, &output);
EXPECT_EQ(cdm::kDecryptError, status);
buf.num_subsamples = sub.size();
status = cdm_->Decrypt(buf, &output);
EXPECT_EQ(cdm::kSuccess, status);
EXPECT_EQ(0, memcmp(output.DecryptedBuffer()->Data(), &data.decrypt_data[0],
buf.data_size));
buf.subsamples = NULL;
status = cdm_->Decrypt(buf, &output);
EXPECT_EQ(cdm::kDecryptError, status);
}
// Level 1 passes encrypted payload straight through. By calling the
// CDM's DecryptDecodeAndRenderSamples, and/or DecryptDecodeAndRenderFrame,
// OEMCrypto_DecryptCTR will be told to use Direct Rendering.
void SecureDecryptLevel1Test() {
typedef struct DecryptionData {
bool is_encrypted;
bool is_secure;
wvcdm::KeyId key_id;
std::vector<uint8_t> encrypt_data;
std::vector<uint8_t> iv;
size_t block_offset;
std::vector<uint8_t> decrypt_data;
} DecryptionData;
DecryptionData data;
data.is_encrypted = true;
data.is_secure = false;
// Key ID of key used to encrypt the test content.
// This is used by the secure layer to look up the content key
data.key_id = wvcdm::a2bs_hex("E02562E04CD55351B14B3D748D36ED8E");
// Dummy encrypted data.
data.encrypt_data = wvcdm::a2b_hex(
"3b2cbde084973539329bd5656da22d20396249bf4a18a51c38c4743360cc9fea"
"a1c78d53de1bd7e14dc5d256fd20a57178a98b83804258c239acd7aa38f2d7d2"
"eca614965b3d22049e19e236fc1800e60965d8b36415677bf2f843d50a6943c4"
"683c07c114a32f5e5fbc9939c483c3a1b2ecd3d82b554d649798866191724283"
"f0ab082eba2da79aaca5c4eaf186f9ee9a0c568f621f705a578f30e4e2ef7b96"
"5e14cc046ce6dbf272ee5558b098f332333e95fc879dea6c29bf34acdb649650"
"f08201b9e649960f2493fd7677cc3abf5ae70e5445845c947ba544456b431646"
"d95a133bff5f57614dda5e4446cd8837901d074149dadf4b775b5b07bb88ca20");
data.iv = wvcdm::a2b_hex("4cca615fc013102892f91efee936639b");
data.block_offset = 0;
// Expected decrypted data.
data.decrypt_data = wvcdm::a2b_hex(
"5a36c0b633b58faf22156d78fdfb608e54a8095788b2b0463ef78d030b4abf82"
"eff34b8d9b7b6352e7d72de991b599662aa475da355033620152e2356ebfadee"
"06172be9e1058fa177e223b9fdd191380cff53c3ea810c6fd852a1df4967b799"
"415179a2276ec388ef763bab89605b9c6952c28dc8d6bf86b03fabbb46b392a3"
"1dad15be602eeeeabb45070b3e25d6bb0217073b1fc44c9fe848594121fd6a91"
"304d605e21f69615e1b57db18312b6b948725724b74e91d8aea7371e99532469"
"1b358bdee873f1936b63efe83d190a53c2d21754d302d63ff285174023473755"
"58b938c2e3ca4c2ce48942da97f9e45797f2c074ac6004734e93784a48af6160");
cdm::InputBuffer buf;
buf.data = &data.encrypt_data[0];
buf.data_size = data.encrypt_data.size();
buf.key_id = (const uint8_t*)&data.key_id[0];
buf.key_id_size = data.key_id.length();
buf.iv = &data.iv[0];
buf.iv_size = data.iv.size();
buf.data_offset = 0;
cdm::SubsampleEntry sub(0, buf.data_size);
buf.subsamples = &sub;
buf.num_subsamples = 1;
buf.timestamp = 10;
cdm::Status status;
status = cdm_->DecryptDecodeAndRenderSamples(buf);
EXPECT_EQ(cdm::kSuccess, status);
status = cdm_->DecryptDecodeAndRenderFrame(buf);
EXPECT_EQ(cdm::kSuccess, status);
}
// Level 1 passes encrypted payload straight through. By calling the
// CDM's DecryptDecodeAndRenderSamples, and/or DecryptDecodeAndRenderFrame,
// OEMCrypto_DecryptCTR will be told to use Direct Rendering.
void SecureDecryptLevel1MultipleSubsamplesTest() {
typedef struct DecryptionData {
bool is_encrypted;
bool is_secure;
wvcdm::KeyId key_id;
std::vector<uint8_t> encrypt_data;
std::vector<uint8_t> iv;
size_t block_offset;
std::vector<uint8_t> decrypt_data;
} DecryptionData;
DecryptionData data;
data.is_encrypted = true;
data.is_secure = false;
// Key ID of key used to encrypt the test content.
// This is used by the secure layer to look up the content key
data.key_id = wvcdm::a2bs_hex("E02562E04CD55351B14B3D748D36ED8E");
// Dummy encrypted data. This is a combination of clear and
// encrypted data.
data.encrypt_data = wvcdm::a2b_hex(
"5a36c0b633b58faf22156d78fdfb608e54a8095788b2b0463ef78d030b4abf82"
"3b2cbde084973539329bd5656da22d20396249bf4a18a51c38c4743360cc9fea"
"a1c78d53de1bd7e14dc5d256fd20a57178a98b83804258c239acd7aa38f2d7d2"
"5a36c0"
"eca614965b"
"58b938c2e3ca4c2ce4"
"3d22049e19e236fc1800e60965d8b36415677bf2f843d50a6943c4"
"683c07c114a32f5e5fbc9939c483c3a1b2ecd3d82b554d649798866191724283"
"f0ab082eba2da79aaca5c4eaf186f9ee9a0c568f621f705a578f30e4e2ef7b96"
"5e14cc046ce6dbf272ee5558b098f332333e95fc879dea6c29bf34acdb649650"
"f08201b9e649960f2493fd7677cc3abf5ae70e5445845c947ba544456b431646"
"d95a133bff5f57614dda5e4446cd8837901d074149dadf4b775b5b07bb88ca20");
data.iv = wvcdm::a2b_hex("4cca615fc013102892f91efee936639b");
data.block_offset = 0;
// Expected decrypted data.
data.decrypt_data = wvcdm::a2b_hex(
"5a36c0b633b58faf22156d78fdfb608e54a8095788b2b0463ef78d030b4abf82"
"5a36c0b633b58faf22156d78fdfb608e54a8095788b2b0463ef78d030b4abf82"
"eff34b8d9b7b6352e7d72de991b599662aa475da355033620152e2356ebfadee"
"5a36c0"
"06172be9e1"
"58b938c2e3ca4c2ce4"
"058fa177e223b9fdd191380cff53c3ea810c6fd852a1df4967b799"
"415179a2276ec388ef763bab89605b9c6952c28dc8d6bf86b03fabbb46b392a3"
"1dad15be602eeeeabb45070b3e25d6bb0217073b1fc44c9fe848594121fd6a91"
"304d605e21f69615e1b57db18312b6b948725724b74e91d8aea7371e99532469"
"1b358bdee873f1936b63efe83d190a53c2d21754d302d63ff285174023473755"
"58b938c2e3ca4c2ce48942da97f9e45797f2c074ac6004734e93784a48af6160");
cdm::InputBuffer buf;
buf.data = &data.encrypt_data[0];
buf.data_size = data.encrypt_data.size();
buf.key_id = (const uint8_t*)&data.key_id[0];
buf.key_id_size = data.key_id.length();
buf.iv = &data.iv[0];
buf.iv_size = data.iv.size();
buf.data_offset = 0;
std::vector<cdm::SubsampleEntry> sub;
sub.push_back(cdm::SubsampleEntry(32, 64));
sub.push_back(cdm::SubsampleEntry(3, 5));
sub.push_back(cdm::SubsampleEntry(
9, data.encrypt_data.size() - (32 + 64 + 3 + 5 + 9)));
buf.subsamples = &sub[0];
buf.num_subsamples = sub.size();
buf.timestamp = 10;
cdm::Status status;
status = cdm_->DecryptDecodeAndRenderSamples(buf);
EXPECT_EQ(cdm::kSuccess, status);
status = cdm_->DecryptDecodeAndRenderFrame(buf);
EXPECT_EQ(cdm::kSuccess, status);
}
void WithMissingSubsampleInfoTest() {
typedef struct DecryptionData {
bool is_encrypted;
bool is_secure;
wvcdm::KeyId key_id;
std::vector<uint8_t> encrypt_data;
std::vector<uint8_t> iv;
size_t block_offset;
std::vector<uint8_t> decrypt_data;
} DecryptionData;
DecryptionData data;
data.is_encrypted = true;
data.is_secure = false;
// Key ID of key used to encrypt the test content.
// This is used by the secure layer to look up the content key
data.key_id = wvcdm::a2bs_hex("E02562E04CD55351B14B3D748D36ED8E");
// Dummy encrypted data.
data.encrypt_data = wvcdm::a2b_hex(
"5a36c0b633b58faf22156d78fdfb608e54a8095788b2b0463ef78d030b4abf82"
"3b2cbde084973539329bd5656da22d20396249bf4a18a51c38c4743360cc9fea"
"a1c78d53de1bd7e14dc5d256fd20a57178a98b83804258c239acd7aa38f2d7d2"
"5a36c0"
"eca614965b"
"58b938c2e3ca4c2ce4"
"3d22049e19e236fc1800e60965d8b36415677bf2f843d50a6943c4"
"683c07c114a32f5e5fbc9939c483c3a1b2ecd3d82b554d649798866191724283"
"f0ab082eba2da79aaca5c4eaf186f9ee9a0c568f621f705a578f30e4e2ef7b96"
"5e14cc046ce6dbf272ee5558b098f332333e95fc879dea6c29bf34acdb649650"
"f08201b9e649960f2493fd7677cc3abf5ae70e5445845c947ba544456b431646"
"d95a133bff5f57614dda5e4446cd8837901d074149dadf4b775b5b07bb88ca20");
data.iv = wvcdm::a2b_hex("4cca615fc013102892f91efee936639b");
data.block_offset = 0;
// Expected decrypted data.
data.decrypt_data = wvcdm::a2b_hex(
"5a36c0b633b58faf22156d78fdfb608e54a8095788b2b0463ef78d030b4abf82"
"5a36c0b633b58faf22156d78fdfb608e54a8095788b2b0463ef78d030b4abf82"
"eff34b8d9b7b6352e7d72de991b599662aa475da355033620152e2356ebfadee"
"5a36c0"
"06172be9e1"
"58b938c2e3ca4c2ce4"
"058fa177e223b9fdd191380cff53c3ea810c6fd852a1df4967b799"
"415179a2276ec388ef763bab89605b9c6952c28dc8d6bf86b03fabbb46b392a3"
"1dad15be602eeeeabb45070b3e25d6bb0217073b1fc44c9fe848594121fd6a91"
"304d605e21f69615e1b57db18312b6b948725724b74e91d8aea7371e99532469"
"1b358bdee873f1936b63efe83d190a53c2d21754d302d63ff285174023473755"
"58b938c2e3ca4c2ce48942da97f9e45797f2c074ac6004734e93784a48af6160");
cdm::InputBuffer buf;
buf.data = &data.encrypt_data[0];
buf.data_size = data.encrypt_data.size();
buf.key_id = (const uint8_t*)&data.key_id[0];
buf.key_id_size = data.key_id.length();
buf.iv = &data.iv[0];
buf.iv_size = data.iv.size();
buf.data_offset = 0;
std::vector<cdm::SubsampleEntry> sub;
sub.push_back(cdm::SubsampleEntry(32, 64));
sub.push_back(cdm::SubsampleEntry(3, 5));
sub.push_back(cdm::SubsampleEntry(
9, data.encrypt_data.size() - (32 + 64 + 3 + 5 + 9)));
buf.timestamp = 10;
cdm::Status status;
status = cdm_->DecryptDecodeAndRenderSamples(buf);
EXPECT_EQ(cdm::kDecryptError, status);
status = cdm_->DecryptDecodeAndRenderFrame(buf);
EXPECT_EQ(cdm::kDecryptError, status);
buf.subsamples = &sub[0];
status = cdm_->DecryptDecodeAndRenderSamples(buf);
EXPECT_EQ(cdm::kDecryptError, status);
status = cdm_->DecryptDecodeAndRenderFrame(buf);
EXPECT_EQ(cdm::kDecryptError, status);
buf.num_subsamples = sub.size();
status = cdm_->DecryptDecodeAndRenderSamples(buf);
EXPECT_EQ(cdm::kSuccess, status);
status = cdm_->DecryptDecodeAndRenderFrame(buf);
EXPECT_EQ(cdm::kSuccess, status);
buf.subsamples = NULL;
status = cdm_->DecryptDecodeAndRenderSamples(buf);
EXPECT_EQ(cdm::kDecryptError, status);
status = cdm_->DecryptDecodeAndRenderFrame(buf);
EXPECT_EQ(cdm::kDecryptError, status);
}
void TimerTest(void* session_id) { host_->SetTimer(1000, session_id); }
std::string key_msg_;
std::string session_id_;
std::string server_url_;
cdm::ContentDecryptionModule* cdm_;
TestHostFactory host_factory_;
TestHost* host_;
};
// Note that these tests, BaseMessageTest, NormalDecryption and TimeTest,
// are dependent on getting back a license from the license server where the
// url for the license server is defined in the conf_test_env.cpp. If these
// tests fail immediately, verify that the license server URL is correct
// and works in your test environment.
TEST_F(WvCdmApiTest, DeviceCertificateTest) {
std::vector<uint8_t> value(0);
host_->PersistPlatformByteArray("DeviceCertificate", value);
GenerateKeyRequest(g_key_system, g_key_id); // It will have to provision -
// in here.
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);
CancelKeyRequest(session_id_);
}
TEST_F(WvCdmApiTest, BaseMessageTest) {
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);
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) {
GenerateKeyRequest(g_key_system, g_key_id);
TestHost::KeyMessage key_msg = host_->GetLastKeyMessage();
key_msg_ = key_msg.message;
std::string drm_msg = GetKeyRequestResponse(g_license_server,
g_client_auth, 200);
AddKey(key_msg.session_id, drm_msg);
DecryptClearPayloadTest();
}
TEST_F(WvCdmApiTest, NormalSubSampleDecryptionWithSubsampleInfo) {
GenerateKeyRequest(g_key_system, g_key_id);
TestHost::KeyMessage key_msg = host_->GetLastKeyMessage();
key_msg_ = key_msg.message;
std::string drm_msg = GetKeyRequestResponse(g_license_server,
g_client_auth, 200);
AddKey(key_msg.session_id, drm_msg);
DecryptClearSubsampleTest();
}
TEST_F(WvCdmApiTest, NormalSubSampleDecryptionWithMissingSubsampleInfo) {
GenerateKeyRequest(g_key_system, g_key_id);
TestHost::KeyMessage key_msg = host_->GetLastKeyMessage();
key_msg_ = key_msg.message;
std::string drm_msg = GetKeyRequestResponse(g_license_server,
g_client_auth, 200);
AddKey(key_msg.session_id, drm_msg);
DecryptClearSubsampleTestWithMissingSubsampleInfo();
}
TEST_F(WvCdmApiTest, TimeTest) {
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);
host_->SetCurrentTime(host_->GetCurrentTestTime() + kTestPolicyRenewalDelaySeconds);
sleep(kDelayWaitToForRenewalMessageSeconds);
// When the timer expired, we should have sent a renewal, so we can
// add this renewed key now, assuming things are working as expected.
TestHost::KeyMessage key_msg2 = host_->GetLastKeyMessage();
session_id_ = key_msg2.session_id;
key_msg_ = key_msg2.message;
drm_msg = GetKeyRequestResponse(key_msg2.default_url, g_client_auth, 200);
AddKey(key_msg2.session_id, drm_msg);
}
TEST_F(WvCdmApiTest, SecureDecryptionLevel1) {
GenerateKeyRequest(g_key_system, g_key_id);
TestHost::KeyMessage key_msg = host_->GetLastKeyMessage();
key_msg_ = key_msg.message;
std::string drm_msg = GetKeyRequestResponse(g_license_server,
g_client_auth, 200);
AddKey(key_msg.session_id, drm_msg);
SecureDecryptLevel1Test();
}
TEST_F(WvCdmApiTest, SecureDecryptionLevel1WithSubsampleInfo) {
GenerateKeyRequest(g_key_system, g_key_id);
TestHost::KeyMessage key_msg = host_->GetLastKeyMessage();
key_msg_ = key_msg.message;
std::string drm_msg = GetKeyRequestResponse(g_license_server,
g_client_auth, 200);
AddKey(key_msg.session_id, drm_msg);
SecureDecryptLevel1MultipleSubsamplesTest();
}
TEST_F(WvCdmApiTest, SecureDecryptionLevel1WithMissingSubsampleInfo) {
GenerateKeyRequest(g_key_system, g_key_id);
TestHost::KeyMessage key_msg = host_->GetLastKeyMessage();
key_msg_ = key_msg.message;
std::string drm_msg = GetKeyRequestResponse(g_license_server,
g_client_auth, 200);
AddKey(key_msg.session_id, drm_msg);
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
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
wvcdm::InitLogging(argc, argv);
wvcdm::ConfigTestEnv config(wvcdm::kGooglePlayServer);
g_client_auth.assign(config.client_auth());
g_key_system.assign(config.key_system());
g_wrong_key_id.assign(config.wrong_key_id());
// The following variables are configurable through command line options.
g_license_server.assign(config.license_server());
g_key_id.assign(config.key_id());
std::string license_server(g_license_server);
int show_usage = 0;
static const struct option long_options[] = {
{"use_full_path", no_argument, &g_use_full_path, 0},
{"keyid", required_argument, NULL, 'k'},
{"server", required_argument, NULL, 's'},
{"vmodule", required_argument, NULL, 0},
{"v", required_argument, NULL, 0},
{NULL, 0, NULL, '\0'}};
int option_index = 0;
int opt = 0;
while ((opt = getopt_long(argc, argv, "k:p:s:u:v", long_options,
&option_index)) != -1) {
switch (opt) {
case 'k': {
g_key_id.clear();
g_key_id.assign(optarg);
break;
}
case 's': {
g_license_server.clear();
g_license_server.assign(optarg);
break;
}
case 'u': {
g_use_full_path = 1;
break;
}
case '?': {
show_usage = 1;
break;
case 'v':
break;
}
}
}
if (show_usage) {
std::cout << 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
<< "configure the license server url, please include http[s] in the url"
<< std::endl;
std::cout << std::setw(30) << std::left << " ";
std::cout << "default: " << license_server << std::endl;
std::cout << std::setw(30) << std::left << " --keyid=<key_id>";
std::cout << "configure the key id or pssh, in hex format" << std::endl;
std::cout << std::setw(30) << std::left << " default keyid:";
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;
}
std::cout << std::endl;
std::cout << "Server: " << g_license_server << std::endl;
std::cout << "KeyID: " << g_key_id << std::endl << std::endl;
g_key_id = wvcdm::a2bs_hex(g_key_id);
config.set_license_server(g_license_server);
config.set_key_id(g_key_id);
return RUN_ALL_TESTS();
}