Source release v2.1.6-0-824 + third_party libs
Change-Id: If190f81154326aa7dc22d66009687f389146ddfd
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include "clock.h"
|
||||
#include "config_test_env.h"
|
||||
#include "content_decryption_module.h"
|
||||
#include "device_cert.h"
|
||||
#include "license_request.h"
|
||||
#include "log.h"
|
||||
#include "scoped_ptr.h"
|
||||
@@ -30,6 +31,7 @@ using wvcdm::scoped_ptr;
|
||||
|
||||
static const int kTestPolicyRenewalDelaySeconds = 60;
|
||||
static const int kDelayWaitToForRenewalMessageSeconds = 2;
|
||||
static const int kHttpOk = 200;
|
||||
|
||||
static double GetCurrentTime() {
|
||||
struct timeval tv;
|
||||
@@ -348,7 +350,6 @@ namespace {
|
||||
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;
|
||||
|
||||
@@ -375,14 +376,8 @@ class WvCdmApiTest : public testing::Test {
|
||||
// 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);
|
||||
std::string cert(kDeviceCert, sizeof(kDeviceCert));
|
||||
host_->SetPlatformString("DeviceCertificate", cert);
|
||||
|
||||
// Initialize the CDM module before creating a CDM instance.
|
||||
INITIALIZE_CDM_MODULE();
|
||||
@@ -396,62 +391,37 @@ class WvCdmApiTest : public testing::Test {
|
||||
host_->SetCdmPtr(cdm_);
|
||||
}
|
||||
|
||||
void GenerateKeyRequest(const std::string& key_system,
|
||||
const std::string& key_id) {
|
||||
|
||||
std::string init_data = key_id;
|
||||
|
||||
cdm::Status GenerateKeyRequest(const std::string& init_data) {
|
||||
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);
|
||||
return 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);
|
||||
std::string GetKeyRequestResponse(const TestHost::KeyMessage& key_msg) {
|
||||
std::string url;
|
||||
if (key_msg.default_url.empty()) {
|
||||
url = g_license_server + g_client_auth;
|
||||
} else {
|
||||
// Note that the client auth string is not appended when the CDM tells
|
||||
// us what URL to use.
|
||||
url = key_msg.default_url;
|
||||
}
|
||||
|
||||
UrlRequest url_request(url);
|
||||
EXPECT_TRUE(url_request.is_connected());
|
||||
if (!url_request.is_connected()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
url_request.PostRequest(key_msg_);
|
||||
url_request.PostRequest(key_msg.message);
|
||||
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);
|
||||
}
|
||||
EXPECT_EQ(kHttpOk, status_code);
|
||||
|
||||
if (status_code != kHttpOk) {
|
||||
return "";
|
||||
@@ -466,17 +436,32 @@ class WvCdmApiTest : public testing::Test {
|
||||
}
|
||||
}
|
||||
|
||||
void CancelKeyRequest(std::string session_id) {
|
||||
void ProcessKeyResponse() {
|
||||
TestHost::KeyMessage key_msg = host_->GetLastKeyMessage();
|
||||
EXPECT_TRUE(key_msg.default_url.empty());
|
||||
std::string drm_msg = GetKeyRequestResponse(key_msg);
|
||||
EXPECT_EQ(cdm::kSuccess, AddKey(key_msg.session_id, drm_msg));
|
||||
}
|
||||
|
||||
void ProcessKeyRenewalResponse() {
|
||||
TestHost::KeyMessage key_msg = host_->GetLastKeyMessage();
|
||||
EXPECT_FALSE(key_msg.default_url.empty());
|
||||
std::string drm_msg = GetKeyRequestResponse(key_msg);
|
||||
EXPECT_EQ(cdm::kSuccess, AddKey(key_msg.session_id, drm_msg));
|
||||
}
|
||||
|
||||
void CloseSession(const std::string& session_id) {
|
||||
cdm::Status status =
|
||||
cdm_->CancelKeyRequest(session_id.data(), session_id.length());
|
||||
cdm_->CloseSession(session_id.data(), session_id.length());
|
||||
EXPECT_EQ(cdm::kSuccess, status);
|
||||
}
|
||||
|
||||
void AddKey(std::string& session_id, std::string& drm_msg) {
|
||||
cdm::Status AddKey(const std::string& session_id,
|
||||
const 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);
|
||||
return status;
|
||||
}
|
||||
|
||||
// Level 1 / Level 2 payload comes back in the cpu memory as cleartext.
|
||||
@@ -960,10 +945,6 @@ class WvCdmApiTest : public testing::Test {
|
||||
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_;
|
||||
};
|
||||
@@ -989,7 +970,7 @@ class DummyCDM : public cdm::ContentDecryptionModule {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual cdm::Status CancelKeyRequest(const char*, int) OVERRIDE {
|
||||
virtual cdm::Status CloseSession(const char*, int) OVERRIDE {
|
||||
return cdm::kSessionError;
|
||||
}
|
||||
|
||||
@@ -1082,116 +1063,115 @@ TEST_F(WvCdmApiTest, TestHostTimer) {
|
||||
// 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_);
|
||||
// Clear any existing device cert.
|
||||
host_->SetPlatformString("DeviceCertificate", "");
|
||||
|
||||
ASSERT_EQ(cdm::kNeedsDeviceCertificate, GenerateKeyRequest(g_key_id));
|
||||
|
||||
// The Host must handle the certificate provisioning request.
|
||||
std::string server_url;
|
||||
std::string request;
|
||||
cdm::Status status = cdm_->GetProvisioningRequest(&request, &server_url);
|
||||
ASSERT_EQ(cdm::kSuccess, status);
|
||||
|
||||
UrlRequest url_request(server_url);
|
||||
url_request.PostCertRequestInQueryString(request);
|
||||
|
||||
std::string message;
|
||||
bool ok = url_request.GetResponse(&message);
|
||||
ASSERT_TRUE(ok);
|
||||
|
||||
status = cdm_->HandleProvisioningResponse(message);
|
||||
ASSERT_EQ(cdm::kSuccess, status);
|
||||
|
||||
// Now we are provisioned, so GKR should succeed.
|
||||
EXPECT_EQ(cdm::kSuccess, GenerateKeyRequest(g_key_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_);
|
||||
EXPECT_EQ(cdm::kSuccess, GenerateKeyRequest(g_key_id));
|
||||
ProcessKeyResponse();
|
||||
}
|
||||
|
||||
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);
|
||||
EXPECT_EQ(cdm::kSuccess, GenerateKeyRequest(g_key_id));
|
||||
ProcessKeyResponse();
|
||||
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);
|
||||
EXPECT_EQ(cdm::kSuccess, GenerateKeyRequest(g_key_id));
|
||||
ProcessKeyResponse();
|
||||
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);
|
||||
EXPECT_EQ(cdm::kSuccess, GenerateKeyRequest(g_key_id));
|
||||
ProcessKeyResponse();
|
||||
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);
|
||||
EXPECT_EQ(cdm::kSuccess, GenerateKeyRequest(g_key_id));
|
||||
ProcessKeyResponse();
|
||||
|
||||
// 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);
|
||||
ProcessKeyRenewalResponse();
|
||||
}
|
||||
|
||||
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);
|
||||
EXPECT_EQ(cdm::kSuccess, GenerateKeyRequest(g_key_id));
|
||||
ProcessKeyResponse();
|
||||
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);
|
||||
EXPECT_EQ(cdm::kSuccess, GenerateKeyRequest(g_key_id));
|
||||
ProcessKeyResponse();
|
||||
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);
|
||||
EXPECT_EQ(cdm::kSuccess, GenerateKeyRequest(g_key_id));
|
||||
ProcessKeyResponse();
|
||||
WithMissingSubsampleInfoTest();
|
||||
}
|
||||
|
||||
TEST_F(WvCdmApiTest, GenerateKeyRequestFailureSendsKeyError) {
|
||||
// Pass a bogus key id and expect failure.
|
||||
EXPECT_EQ(cdm::kSessionError, GenerateKeyRequest(""));
|
||||
// Expect the CDM to pass a key error back to the host.
|
||||
EXPECT_EQ(1, host_->KeyErrorsSize());
|
||||
}
|
||||
|
||||
TEST_F(WvCdmApiTest, AddKeyFailureSendsKeyError) {
|
||||
EXPECT_EQ(cdm::kSuccess, GenerateKeyRequest(g_key_id));
|
||||
|
||||
// Get the message and response.
|
||||
TestHost::KeyMessage key_msg = host_->GetLastKeyMessage();
|
||||
EXPECT_TRUE(key_msg.default_url.empty());
|
||||
std::string drm_msg = GetKeyRequestResponse(key_msg);
|
||||
|
||||
// Call AddKey with a bad session id and expect failure.
|
||||
EXPECT_EQ(cdm::kSessionError, AddKey("BLAH", drm_msg));
|
||||
|
||||
// Expect the CDM to pass a key error back to the host.
|
||||
EXPECT_EQ(1, host_->KeyErrorsSize());
|
||||
|
||||
// Call AddKey with a bad license and expect failure.
|
||||
EXPECT_EQ(cdm::kSessionError, AddKey(key_msg.session_id, "BLAH"));
|
||||
|
||||
// Expect the CDM to pass one more key error back to the host.
|
||||
EXPECT_EQ(2, host_->KeyErrorsSize());
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
@@ -1200,7 +1180,6 @@ int main(int argc, char** 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.
|
||||
|
||||
Reference in New Issue
Block a user