Source release v3.5.0
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "cdm_engine.h"
|
||||
@@ -15,6 +16,7 @@
|
||||
#include "log.h"
|
||||
#include "oec_session_util.h"
|
||||
#include "../../oemcrypto/mock/src/oemcrypto_key_mock.h"
|
||||
#include "properties.h"
|
||||
#include "string_conversions.h"
|
||||
#include "url_request.h"
|
||||
#include "wv_cdm_constants.h"
|
||||
@@ -28,73 +30,32 @@ std::string g_provisioning_server;
|
||||
std::string g_license_service_certificate;
|
||||
std::string g_provisioning_service_certificate;
|
||||
|
||||
/*
|
||||
* Locate the portion of the server's response message that is between
|
||||
* the strings jason_start_substr and json_end_substr. Returns the string
|
||||
* through *result. If the start substring match fails, assume the entire
|
||||
* string represents a serialized protobuf mesaage and return true with
|
||||
* the entire string. If the end_substring match fails, return false with
|
||||
* an empty *result.
|
||||
*/
|
||||
bool ExtractSignedMessage(const std::string& response,
|
||||
const std::string& json_start_substr,
|
||||
const std::string& json_end_substr,
|
||||
std::string* result) {
|
||||
std::string b64_string;
|
||||
size_t start = response.find(json_start_substr);
|
||||
|
||||
if (start == response.npos) {
|
||||
// Assume web safe protobuf
|
||||
b64_string.assign(response);
|
||||
} else {
|
||||
// Assume JSON-wrapped protobuf
|
||||
size_t end = response.find(json_end_substr,
|
||||
start + json_start_substr.length());
|
||||
if (end == response.npos) {
|
||||
LOGE("ExtractSignedMessage cannot locate end substring");
|
||||
result->clear();
|
||||
return false;
|
||||
}
|
||||
size_t b64_string_size = end - start - json_start_substr.length();
|
||||
b64_string.assign(response, start + json_start_substr.length(),
|
||||
b64_string_size);
|
||||
}
|
||||
|
||||
if (b64_string.empty()) {
|
||||
LOGE("Response message is empty");
|
||||
result->clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
result->swap(b64_string);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
class WvGenericOperationsTest : public testing::Test {
|
||||
public:
|
||||
WvGenericOperationsTest() : crypto_session_(NULL) {}
|
||||
|
||||
virtual void SetUp() {
|
||||
::testing::Test::SetUp();
|
||||
|
||||
ConfigTestEnv config(kContentProtectionStagingPlusProv30);
|
||||
ConfigTestEnv config(kContentProtectionStagingLicense);
|
||||
Properties::set_provisioning_messages_are_binary(false);
|
||||
|
||||
g_provisioning_service_certificate.assign(
|
||||
config.provisioning_service_certificate());
|
||||
g_license_service_certificate.assign(config.license_service_certificate());
|
||||
g_provisioning_server.assign(config.provisioning_server());
|
||||
|
||||
cdm_engine_ = NULL;
|
||||
|
||||
// TODO(fredgc or gmorgan): This should be updated for provisioning 3.0
|
||||
// Load test keybox. This keybox will be used by any CryptoSession
|
||||
// created by the CDM under test.
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_LoadTestKeybox());
|
||||
|
||||
// Perform CdmEngine setup
|
||||
cdm_engine_ = new CdmEngine(&file_system_);
|
||||
cdm_engine_.reset(new CdmEngine(&file_system_));
|
||||
|
||||
Provision();
|
||||
|
||||
@@ -122,7 +83,7 @@ class WvGenericOperationsTest : public testing::Test {
|
||||
|
||||
virtual void TearDown() {
|
||||
oec_util_session_.close();
|
||||
if (cdm_engine_ != NULL) {
|
||||
if (cdm_engine_.get() != NULL) {
|
||||
cdm_engine_->CloseSession(session_id_);
|
||||
}
|
||||
// OEMCrypto_Terminate() will be performed during the test class's
|
||||
@@ -216,7 +177,7 @@ class WvGenericOperationsTest : public testing::Test {
|
||||
protected:
|
||||
|
||||
virtual void Provision() {
|
||||
LOGE("WvCdmEnginePreProvTest::Provision: url=%s",
|
||||
LOGE("WvGenericOperationsTest::Provision: url=%s",
|
||||
g_provisioning_server.c_str());
|
||||
CdmProvisioningRequest prov_request;
|
||||
std::string provisioning_server_url;
|
||||
@@ -229,7 +190,7 @@ class WvGenericOperationsTest : public testing::Test {
|
||||
cert_type, cert_authority, &prov_request,
|
||||
&provisioning_server_url));
|
||||
|
||||
LOGV("WvCdmEnginePreProvTest::Provision: req=%s", prov_request.c_str());
|
||||
LOGV("WvGenericOperationsTest::Provision: req=%s", prov_request.c_str());
|
||||
|
||||
// Ignore URL provided by CdmEngine. Use ours, as configured
|
||||
// for test vs. production server.
|
||||
@@ -241,28 +202,14 @@ class WvGenericOperationsTest : public testing::Test {
|
||||
bool ok = url_request.GetResponse(&http_message);
|
||||
EXPECT_TRUE(ok);
|
||||
|
||||
LOGV("WvCdmEnginePreProvTest::Provision: http_message: \n%s\n",
|
||||
LOGV("WvGenericOperationsTest::Provision: http_message: \n%s\n",
|
||||
http_message.c_str());
|
||||
|
||||
// extract provisioning response from received message
|
||||
// Extracts signed response from JSON string, decodes base64 signed response
|
||||
const std::string kMessageStart = "\"signedResponse\": \"";
|
||||
const std::string kMessageEnd = "\"";
|
||||
std::string base64_response;
|
||||
EXPECT_TRUE (ExtractSignedMessage(http_message, kMessageStart, kMessageEnd,
|
||||
&base64_response)) <<
|
||||
"Failed to extract signed serialized response from JSON response";
|
||||
|
||||
LOGV("WvCdmEnginePreProvTest::Provision: extracted response "
|
||||
"message: \n%s\n", base64_response.c_str());
|
||||
|
||||
ASSERT_EQ(NO_ERROR,
|
||||
cdm_engine_->HandleProvisioningResponse(base64_response,
|
||||
cdm_engine_->HandleProvisioningResponse(http_message,
|
||||
&cert, &wrapped_key));
|
||||
|
||||
ASSERT_EQ(NO_ERROR,
|
||||
cdm_engine_->SetServiceCertificate(
|
||||
g_license_service_certificate));
|
||||
cdm_engine_->SetServiceCertificate(g_license_service_certificate));
|
||||
}
|
||||
|
||||
// This CryptoSession object handles Initialization and Termination
|
||||
@@ -272,7 +219,7 @@ class WvGenericOperationsTest : public testing::Test {
|
||||
CryptoSession crypto_session_;
|
||||
|
||||
FileSystem file_system_;
|
||||
CdmEngine* cdm_engine_;
|
||||
std::unique_ptr<CdmEngine> cdm_engine_;
|
||||
std::string key_msg_;
|
||||
std::string session_id_;
|
||||
std::string server_url_;
|
||||
@@ -309,7 +256,7 @@ TEST_F(WvGenericOperationsTest, GenericEncryptNoKey) {
|
||||
cdm_sts = cdm_engine_->GenericEncrypt(session_id_, in_buffer, key_id, iv,
|
||||
wvcdm::kEncryptionAlgorithmAesCbc128,
|
||||
&out_buffer);
|
||||
EXPECT_EQ(KEY_ERROR_1, cdm_sts);
|
||||
EXPECT_EQ(NO_CONTENT_KEY_2, cdm_sts);
|
||||
}
|
||||
|
||||
TEST_F(WvGenericOperationsTest, GenericEncryptKeyNotAllowed) {
|
||||
|
||||
Reference in New Issue
Block a user