Source release 17.1.2
This commit is contained in:
@@ -21,10 +21,12 @@
|
||||
#include "file_store.h"
|
||||
#include "license.h"
|
||||
#include "log.h"
|
||||
#include "message_dumper.h"
|
||||
#include "oec_device_features.h"
|
||||
#include "oec_test_data.h"
|
||||
#include "platform.h"
|
||||
#include "properties.h"
|
||||
#include "provisioning_holder.h"
|
||||
#include "test_printers.h"
|
||||
#include "test_sleep.h"
|
||||
#include "url_request.h"
|
||||
@@ -111,6 +113,11 @@ void show_menu(const char* prog_name, const std::string& extra_help_text) {
|
||||
<< " configure the provisioning server url, please include http[s]"
|
||||
<< " in the url" << std::endl
|
||||
<< std::endl;
|
||||
std::cout << " --server_version=N" << std::endl;
|
||||
std::cout << " specify the server version. Tests that are not expected "
|
||||
<< "to pass" << std::endl
|
||||
<< " on this server version will be skipped." << std::endl
|
||||
<< std::endl;
|
||||
|
||||
std::cout << " --qa_provisioning" << std::endl;
|
||||
std::cout << " use the QA provisioning cert and QA test keybox"
|
||||
@@ -135,48 +142,12 @@ void show_menu(const char* prog_name, const std::string& extra_help_text) {
|
||||
std::cout << " --test_data_path=<path>" << std::endl;
|
||||
std::cout << " Where to store test data for reboot tests." << std::endl;
|
||||
|
||||
std::cout << " --dump_golden_data" << std::endl;
|
||||
std::cout << " Dump the license request and response from the server."
|
||||
<< std::endl;
|
||||
|
||||
std::cout << extra_help_text << std::endl;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 response_string;
|
||||
size_t start = response.find(json_start_substr);
|
||||
|
||||
if (start == response.npos) {
|
||||
// Assume serialized protobuf message.
|
||||
result->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 result_string_size = end - start - json_start_substr.length();
|
||||
result->assign(response, start + json_start_substr.length(),
|
||||
result_string_size);
|
||||
}
|
||||
|
||||
if (result->empty()) {
|
||||
LOGE("ExtractSignedMessage: Response message is empty");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<ConfigTestEnv> WvCdmTestBase::default_config_;
|
||||
@@ -317,105 +288,12 @@ WvCdmTestBase::WvCdmTestBase()
|
||||
}
|
||||
|
||||
void WvCdmTestBase::Provision() {
|
||||
CdmProvisioningRequest prov_request;
|
||||
std::string provisioning_server_url;
|
||||
CdmCertificateType cert_type = kCertificateWidevine;
|
||||
std::string cert_authority;
|
||||
std::string cert, wrapped_key;
|
||||
|
||||
CdmSessionId session_id;
|
||||
const CdmCertificateType cert_type = kCertificateWidevine;
|
||||
std::unique_ptr<wvutil::FileSystem> file_system(CreateTestFileSystem());
|
||||
|
||||
if (config_.provisioning_server() == "fake") {
|
||||
LOGD("Using fake provisioning server.");
|
||||
|
||||
TestCdmEngine cdm_engine(file_system.get(),
|
||||
std::shared_ptr<EngineMetrics>(new EngineMetrics));
|
||||
FakeProvisioningServer server;
|
||||
CdmResponseType result = cdm_engine.GetProvisioningRequest(
|
||||
cert_type, cert_authority, server.service_certificate(), kLevelDefault,
|
||||
&prov_request, &provisioning_server_url);
|
||||
ASSERT_EQ(NO_ERROR, result);
|
||||
if (!binary_provisioning_) {
|
||||
std::vector<uint8_t> prov_request_v =
|
||||
wvutil::Base64SafeDecode(prov_request);
|
||||
prov_request = std::string(prov_request_v.begin(), prov_request_v.end());
|
||||
}
|
||||
std::string response;
|
||||
ASSERT_TRUE(server.MakeResponse(prov_request, &response))
|
||||
<< "Fake provisioning server could not provision";
|
||||
result = cdm_engine.HandleProvisioningResponse(response, kLevelDefault,
|
||||
&cert, &wrapped_key);
|
||||
EXPECT_EQ(NO_ERROR, result);
|
||||
} else {
|
||||
// TODO(fredgc): provision for different SPOIDs.
|
||||
TestCdmEngine cdm_engine(file_system.get(),
|
||||
std::shared_ptr<EngineMetrics>(new EngineMetrics));
|
||||
|
||||
CdmResponseType result = cdm_engine.GetProvisioningRequest(
|
||||
cert_type, cert_authority, config_.provisioning_service_certificate(),
|
||||
kLevelDefault, &prov_request, &provisioning_server_url);
|
||||
ASSERT_EQ(NO_ERROR, result);
|
||||
|
||||
if (binary_provisioning_) {
|
||||
prov_request = wvutil::Base64SafeEncodeNoPad(prov_request);
|
||||
}
|
||||
|
||||
LOGV("Provisioning request: req = %s", prov_request.c_str());
|
||||
|
||||
// Ignore URL provided by CdmEngine. Use ours, as configured
|
||||
// for test vs. production server.
|
||||
provisioning_server_url.assign(config_.provisioning_server());
|
||||
|
||||
// Make request.
|
||||
UrlRequest url_request(provisioning_server_url);
|
||||
if (!url_request.is_connected()) {
|
||||
LOGE("Failed to connect to provisioning server: url = %s",
|
||||
provisioning_server_url.c_str());
|
||||
}
|
||||
url_request.PostCertRequestInQueryString(prov_request);
|
||||
|
||||
// Receive and parse response.
|
||||
std::string http_message;
|
||||
ASSERT_TRUE(url_request.GetResponse(&http_message))
|
||||
<< "Failed to get provisioning response";
|
||||
LOGV("http_message: \n%s\n", http_message.c_str());
|
||||
|
||||
if (binary_provisioning_) {
|
||||
// extract provisioning response from received message
|
||||
// Extracts signed response from JSON string, result is serialized
|
||||
// protobuf.
|
||||
static const std::string kMessageStart = "\"signedResponse\": \"";
|
||||
static const std::string kMessageEnd = "\"";
|
||||
std::string protobuf_response;
|
||||
const bool extract_ok = ExtractSignedMessage(
|
||||
http_message, kMessageStart, kMessageEnd, &protobuf_response);
|
||||
ASSERT_TRUE(extract_ok) << "Failed to extract signed serialized "
|
||||
"response from JSON response";
|
||||
LOGV("Extracted response message: \n%s\n", protobuf_response.c_str());
|
||||
|
||||
ASSERT_FALSE(protobuf_response.empty())
|
||||
<< "Protobuf response is unexpectedly empty";
|
||||
|
||||
// base64 decode response to yield binary protobuf
|
||||
const std::vector<uint8_t> response_vec(
|
||||
wvutil::Base64SafeDecode(protobuf_response));
|
||||
ASSERT_FALSE(response_vec.empty())
|
||||
<< "Failed to decode base64 of response: response = "
|
||||
<< protobuf_response;
|
||||
|
||||
const std::string binary_protobuf_response(response_vec.begin(),
|
||||
response_vec.end());
|
||||
|
||||
ASSERT_EQ(NO_ERROR, cdm_engine.HandleProvisioningResponse(
|
||||
binary_protobuf_response, kLevelDefault, &cert,
|
||||
&wrapped_key));
|
||||
} else {
|
||||
ASSERT_EQ(NO_ERROR,
|
||||
cdm_engine.HandleProvisioningResponse(
|
||||
http_message, kLevelDefault, &cert, &wrapped_key));
|
||||
}
|
||||
}
|
||||
TestCdmEngine cdm_engine(file_system.get(),
|
||||
std::shared_ptr<EngineMetrics>(new EngineMetrics));
|
||||
ProvisioningHolder provisioner(&cdm_engine, config_);
|
||||
provisioner.Provision(cert_type, binary_provisioning_);
|
||||
}
|
||||
|
||||
// TODO(fredgc): Replace this with a pre-defined DRM certificate. We could do
|
||||
@@ -489,6 +367,9 @@ bool WvCdmTestBase::Initialize(int argc, const char* const argv[],
|
||||
} else if (arg.find("--gtest") == 0) {
|
||||
// gtest arguments will be passed to gtest by the main program.
|
||||
continue;
|
||||
} else if (arg == "--dump_golden_data") {
|
||||
default_config_->set_dump_golden_data(true);
|
||||
testing::AddGlobalTestEnvironment(new MessageDumper);
|
||||
} else {
|
||||
const auto index = arg.find('=');
|
||||
if (index == std::string::npos) {
|
||||
@@ -541,6 +422,8 @@ bool WvCdmTestBase::Initialize(int argc, const char* const argv[],
|
||||
}
|
||||
} else if (arg_prefix == "--test_data_path") {
|
||||
default_config_->set_test_data_path(arg_value);
|
||||
} else if (arg_prefix == "--server_version") {
|
||||
default_config_->set_server_version(atoi(arg_value.c_str()));
|
||||
} else {
|
||||
std::cerr << "Unknown argument " << arg_prefix << std::endl;
|
||||
show_usage = true;
|
||||
@@ -564,8 +447,12 @@ bool WvCdmTestBase::Initialize(int argc, const char* const argv[],
|
||||
<< std::endl;
|
||||
std::cout << "Default Renewal Server: " << default_config_->renewal_server()
|
||||
<< std::endl;
|
||||
std::cout << "Default KeyID: " << default_config_->key_id() << std::endl
|
||||
<< std::endl;
|
||||
std::cout << "Default KeyID: " << default_config_->key_id() << std::endl;
|
||||
if (default_config_->server_version() != 0) {
|
||||
std::cout << "Server Version: " << default_config_->server_version()
|
||||
<< std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
// Figure out which tests are appropriate for OEMCrypto, based on features
|
||||
// supported.
|
||||
|
||||
Reference in New Issue
Block a user