1277 lines
43 KiB
C++
1277 lines
43 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 <queue>
|
|
|
|
#include <errno.h>
|
|
#include <getopt.h>
|
|
#include <unistd.h>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "clock.h"
|
|
#include "config_test_env.h"
|
|
#include "content_decryption_module.h"
|
|
#include "license_request.h"
|
|
#include "log.h"
|
|
#include "scoped_ptr.h"
|
|
#include "string_conversions.h"
|
|
#include "url_request.h"
|
|
#include "wv_cdm_common.h"
|
|
|
|
using wvcdm::scoped_ptr;
|
|
|
|
static const int kTestPolicyRenewalDelaySeconds = 60;
|
|
static const int kDelayWaitToForRenewalMessageSeconds = 2;
|
|
|
|
static double GetCurrentTime() {
|
|
struct timeval tv;
|
|
tv.tv_sec = tv.tv_usec = 0;
|
|
gettimeofday(&tv, NULL);
|
|
return tv.tv_sec + (tv.tv_usec / (1000.0 * 1000.0));
|
|
}
|
|
|
|
// 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 TestHost : public cdm::Host {
|
|
public:
|
|
// These structs are used to store the KeyMessages and KeyErrors passed to
|
|
// this class' objects.
|
|
struct 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;
|
|
|
|
virtual void SetTimer(int64_t delay_ms, void* context) OVERRIDE;
|
|
|
|
virtual double GetCurrentWallTimeInSeconds() OVERRIDE;
|
|
|
|
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 GetPlatformString(const std::string& name,
|
|
std::string* value) OVERRIDE;
|
|
|
|
virtual void SetPlatformString(const std::string& name,
|
|
const std::string& value) OVERRIDE;
|
|
|
|
// Methods only for this test.
|
|
void FastForwardTime(double seconds);
|
|
int KeyMessagesSize() const;
|
|
int KeyErrorsSize() const;
|
|
int NumTimers() 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 SetCdmPtr(cdm::ContentDecryptionModule* cdm);
|
|
|
|
private:
|
|
struct Timer {
|
|
Timer(double expiry_time, void* context)
|
|
: expiry_time(expiry_time), context(context) {}
|
|
|
|
bool operator<(const Timer& other) const {
|
|
// We want to reverse the order so that the smallest expiry times go to
|
|
// the top of the priority queue.
|
|
return expiry_time > other.expiry_time;
|
|
}
|
|
|
|
double expiry_time;
|
|
void* context;
|
|
};
|
|
|
|
double current_time_;
|
|
std::priority_queue<Timer> timers_;
|
|
|
|
std::vector<KeyMessage> key_messages_;
|
|
std::vector<KeyError> key_errors_;
|
|
|
|
bool has_new_key_message_;
|
|
bool has_new_key_error_;
|
|
|
|
std::map<std::string, std::string> platform_strings_;
|
|
|
|
cdm::ContentDecryptionModule* cdm_;
|
|
|
|
CORE_DISALLOW_COPY_AND_ASSIGN(TestHost);
|
|
};
|
|
|
|
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_(GetCurrentTime()),
|
|
has_new_key_message_(false),
|
|
has_new_key_error_(false),
|
|
cdm_(NULL) {
|
|
}
|
|
|
|
TestHost::~TestHost() {
|
|
if (cdm_)
|
|
cdm_->Destroy();
|
|
}
|
|
|
|
cdm::Buffer* TestHost::Allocate(int32_t capacity) {
|
|
return TestBuffer::Create(capacity);
|
|
}
|
|
|
|
void TestHost::SetTimer(int64_t delay_ms, void* context) {
|
|
double expiry_time = current_time_ + (delay_ms / 1000.0);
|
|
timers_.push(Timer(expiry_time, context));
|
|
}
|
|
|
|
double TestHost::GetCurrentWallTimeInSeconds() {
|
|
return current_time_;
|
|
}
|
|
|
|
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::FastForwardTime(double seconds) {
|
|
double goal_time = current_time_ + seconds;
|
|
while (current_time_ < goal_time) {
|
|
if (timers_.empty()) {
|
|
current_time_ = goal_time;
|
|
} else {
|
|
Timer t = timers_.top();
|
|
timers_.pop();
|
|
ASSERT_GE(t.expiry_time, current_time_);
|
|
current_time_ = t.expiry_time;
|
|
cdm_->TimerExpired(t.context);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TestHost::GetPlatformString(const std::string& name,
|
|
std::string* value) {
|
|
*value = platform_strings_[name];
|
|
}
|
|
|
|
void TestHost::SetPlatformString(const std::string& name,
|
|
const std::string& value) {
|
|
platform_strings_[name] = value;
|
|
}
|
|
|
|
int TestHost::KeyMessagesSize() const { return key_messages_.size(); }
|
|
|
|
int TestHost::KeyErrorsSize() const { return key_errors_.size(); }
|
|
|
|
int TestHost::NumTimers() const { return timers_.size(); }
|
|
|
|
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* cdm) {
|
|
if (cdm_) {
|
|
cdm_->Destroy();
|
|
}
|
|
cdm_ = cdm;
|
|
}
|
|
|
|
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;
|
|
|
|
void* GetCdmHost(int host_interface_version, void* user_data) {
|
|
if (host_interface_version != cdm::kHostInterfaceVersion)
|
|
return NULL;
|
|
return user_data;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
namespace wvcdm {
|
|
|
|
class WvCdmApiTest : public testing::Test {
|
|
public:
|
|
WvCdmApiTest() : cdm_(NULL) {}
|
|
~WvCdmApiTest() {}
|
|
|
|
protected:
|
|
virtual void SetUp() {
|
|
// Create the Host.
|
|
host_.reset(new TestHost());
|
|
|
|
// Set various parameters that the CDM will query.
|
|
host_->SetPlatformString("SecurityLevel", "L1");
|
|
host_->SetPlatformString("PrivacyOn", "False");
|
|
|
|
// Put a phony service certificate into persistent storage.
|
|
static const size_t kPrivacyCertSize = 256;
|
|
std::string cert(kPrivacyCertSize, '\0');
|
|
for (size_t i = 0; i < cert.size(); i++) {
|
|
cert[i] = i;
|
|
}
|
|
host_->SetPlatformString("ServiceCertificate", cert);
|
|
|
|
// Initialize the CDM module before creating a CDM instance.
|
|
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,
|
|
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) {
|
|
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);
|
|
|
|
// 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\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 = ⊂
|
|
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 = ⊂
|
|
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);
|
|
}
|
|
|
|
std::string key_msg_;
|
|
std::string session_id_;
|
|
std::string server_url_;
|
|
|
|
cdm::ContentDecryptionModule* cdm_; // owned by host_
|
|
scoped_ptr<TestHost> host_;
|
|
};
|
|
|
|
|
|
class DummyCDM : public cdm::ContentDecryptionModule {
|
|
public:
|
|
DummyCDM()
|
|
: timer_fired_(false),
|
|
last_context_(NULL) {}
|
|
|
|
virtual cdm::Status GenerateKeyRequest(const char*, int, const uint8_t*, int)
|
|
OVERRIDE {
|
|
return cdm::kSessionError;
|
|
}
|
|
|
|
virtual cdm::Status AddKey(const char*, int, const uint8_t*, int,
|
|
const uint8_t*, int) OVERRIDE {
|
|
return cdm::kSessionError;
|
|
}
|
|
|
|
virtual bool IsKeyValid(const uint8_t*, int) OVERRIDE {
|
|
return false;
|
|
}
|
|
|
|
virtual cdm::Status CancelKeyRequest(const char*, int) OVERRIDE {
|
|
return cdm::kSessionError;
|
|
}
|
|
|
|
virtual void TimerExpired(void* context) OVERRIDE {
|
|
timer_fired_ = true;
|
|
last_context_ = context;
|
|
}
|
|
|
|
virtual cdm::Status Decrypt(const cdm::InputBuffer&, cdm::DecryptedBlock*)
|
|
OVERRIDE {
|
|
return cdm::kSessionError;
|
|
}
|
|
|
|
virtual cdm::Status DecryptDecodeAndRenderFrame(const cdm::InputBuffer&)
|
|
OVERRIDE {
|
|
return cdm::kSessionError;
|
|
}
|
|
|
|
virtual cdm::Status DecryptDecodeAndRenderSamples(const cdm::InputBuffer&)
|
|
OVERRIDE {
|
|
return cdm::kSessionError;
|
|
}
|
|
|
|
virtual void Destroy() OVERRIDE {
|
|
delete this;
|
|
}
|
|
|
|
virtual cdm::Status GetProvisioningRequest(std::string*, std::string*)
|
|
OVERRIDE {
|
|
return cdm::kSessionError;
|
|
}
|
|
|
|
virtual cdm::Status HandleProvisioningResponse(std::string&) OVERRIDE {
|
|
return cdm::kSessionError;
|
|
}
|
|
|
|
bool TimerFired() const {
|
|
return timer_fired_;
|
|
}
|
|
|
|
void* LastTimerContext() const {
|
|
return last_context_;
|
|
}
|
|
|
|
void ResetTimerStatus() {
|
|
timer_fired_ = false;
|
|
last_context_ = NULL;
|
|
}
|
|
|
|
private:
|
|
bool timer_fired_;
|
|
void* last_context_;
|
|
};
|
|
|
|
TEST_F(WvCdmApiTest, TestHostTimer) {
|
|
// Validate that the TestHost timers are processed in the correct order.
|
|
// To do this, we replace the cdm with a dummy that only tracks timers.
|
|
DummyCDM* cdm = new DummyCDM();
|
|
|
|
// The old CDM is destroyed by SetCdmPtr.
|
|
cdm_ = cdm;
|
|
host_->SetCdmPtr(cdm);
|
|
|
|
const double kTimerDelaySeconds = 1.0;
|
|
const int64_t kTimerDelayMs = kTimerDelaySeconds * 1000;
|
|
void* kCtx1 = reinterpret_cast<void*>(0x1);
|
|
void* kCtx2 = reinterpret_cast<void*>(0x2);
|
|
|
|
host_->SetTimer(kTimerDelayMs * 1, kCtx1);
|
|
host_->SetTimer(kTimerDelayMs * 2, kCtx2);
|
|
|
|
host_->FastForwardTime(kTimerDelaySeconds);
|
|
EXPECT_TRUE(cdm->TimerFired());
|
|
EXPECT_EQ(kCtx1, cdm->LastTimerContext());
|
|
cdm->ResetTimerStatus();
|
|
|
|
host_->FastForwardTime(kTimerDelaySeconds);
|
|
EXPECT_TRUE(cdm->TimerFired());
|
|
EXPECT_EQ(kCtx2, cdm->LastTimerContext());
|
|
cdm->ResetTimerStatus();
|
|
|
|
host_->FastForwardTime(kTimerDelaySeconds);
|
|
EXPECT_FALSE(cdm->TimerFired());
|
|
}
|
|
|
|
// 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) {
|
|
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, 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);
|
|
// We expect that by the time we've added a key, the CDM has set a timer.
|
|
// Otherwise, it couldn't correctly handle renewal.
|
|
EXPECT_NE(0, host_->NumTimers());
|
|
|
|
host_->FastForwardTime(kTestPolicyRenewalDelaySeconds +
|
|
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;
|
|
|
|
// 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);
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
} // 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[] = {
|
|
{"keyid", required_argument, NULL, 'k'},
|
|
{"server", required_argument, NULL, 's'},
|
|
{NULL, 0, NULL, '\0'}};
|
|
|
|
int option_index = 0;
|
|
int opt = 0;
|
|
while ((opt = getopt_long(argc, argv, "k:s: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 'v': {
|
|
// 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;
|
|
}
|
|
case '?': {
|
|
show_usage = 1;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (show_usage) {
|
|
std::cout << std::endl;
|
|
std::cout << "usage: " << argv[0] << " [options]" << 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;
|
|
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();
|
|
}
|