Source release 18.7.0
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "certificate_provisioning.h"
|
||||
#include "license_holder.h"
|
||||
#include "log.h"
|
||||
#include "oec_device_features.h"
|
||||
#include "provisioning_holder.h"
|
||||
#include "test_base.h"
|
||||
#include "wv_cdm_types.h"
|
||||
@@ -135,6 +136,9 @@ class CoreIntegrationTest : public WvCdmTestBaseWithEngine {
|
||||
* different apps. Test using two different apps and origins.
|
||||
*/
|
||||
TEST_F(CoreIntegrationTest, ProvisioningStableSpoidTest) {
|
||||
if (wvoec::global_features.provisioning_method == OEMCrypto_DrmCertificate) {
|
||||
GTEST_SKIP() << "Device does not provision.";
|
||||
}
|
||||
std::string level;
|
||||
ASSERT_EQ(
|
||||
NO_ERROR,
|
||||
|
||||
@@ -94,7 +94,7 @@ void LicenseHolder::GenerateAndPostRenewalRequest(
|
||||
void LicenseHolder::FetchRenewal() {
|
||||
ASSERT_NE(renewal_in_flight_, nullptr) << "Failed for " << content_id();
|
||||
ASSERT_NO_FATAL_FAILURE(
|
||||
renewal_in_flight_->AssertOkResponse(&renewal_response_))
|
||||
renewal_in_flight_->AssertOkResponseWithRetry(&renewal_response_))
|
||||
<< "Renewal failed for " << content_id();
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ void LicenseHolder::GetKeyResponse(const CdmKeyRequest& key_request) {
|
||||
|
||||
std::string http_response;
|
||||
url_request.PostRequest(key_request.message);
|
||||
ASSERT_NO_FATAL_FAILURE(url_request.AssertOkResponse(&http_response))
|
||||
ASSERT_NO_FATAL_FAILURE(url_request.AssertOkResponseWithRetry(&http_response))
|
||||
<< "Failed for " << content_id();
|
||||
LicenseRequest license_request;
|
||||
license_request.GetDrmMessage(http_response, key_response_);
|
||||
|
||||
@@ -69,7 +69,7 @@ void ProvisioningHolder::Provision(CdmCertificateType cert_type,
|
||||
url_request.PostCertRequestInQueryString(request);
|
||||
|
||||
// Receive and parse response.
|
||||
ASSERT_NO_FATAL_FAILURE(url_request.AssertOkResponse(&response_))
|
||||
ASSERT_NO_FATAL_FAILURE(url_request.AssertOkResponseWithRetry(&response_))
|
||||
<< "Failed to fetch provisioning response. "
|
||||
<< DumpProvAttempt(request, response_, cert_type);
|
||||
|
||||
|
||||
@@ -329,9 +329,12 @@ void WvCdmTestBase::InstallTestRootOfTrust() {
|
||||
sizeof(test_keybox)));
|
||||
break;
|
||||
case wvoec::DeviceFeatures::LOAD_TEST_RSA_KEY:
|
||||
// Rare case: used by devices with baked in DRM cert.
|
||||
// Rare case: used by devices with baked in production DRM cert.
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_LoadTestRSAKey());
|
||||
break;
|
||||
case wvoec::DeviceFeatures::PRELOADED_RSA_KEY:
|
||||
// Rare case: used by devices with baked in test DRM cert.
|
||||
break;
|
||||
case wvoec::DeviceFeatures::TEST_PROVISION_30:
|
||||
// Can use oem certificate to install test rsa key.
|
||||
break;
|
||||
@@ -361,6 +364,10 @@ void WvCdmTestBase::Provision() {
|
||||
}
|
||||
|
||||
void WvCdmTestBase::EnsureProvisioned() {
|
||||
if (wvoec::global_features.provisioning_method == OEMCrypto_DrmCertificate) {
|
||||
LOGD("Device is preprovisioned.");
|
||||
return;
|
||||
}
|
||||
CdmSessionId session_id;
|
||||
std::unique_ptr<wvutil::FileSystem> file_system(CreateTestFileSystem());
|
||||
// OpenSession will check if a DRM certificate exists, while
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
#include "url_request.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
@@ -24,11 +26,15 @@ const int kConnectTimeoutMs = 15000;
|
||||
const int kWriteTimeoutMs = 12000;
|
||||
const int kReadTimeoutMs = 12000;
|
||||
constexpr int kHttpOk = 200;
|
||||
const std::vector<int> kRetryCodes = {502, 504};
|
||||
|
||||
const std::string kGoogleHeaderUpper("X-Google");
|
||||
const std::string kGoogleHeaderLower("x-google");
|
||||
const std::string kCrLf("\r\n");
|
||||
|
||||
constexpr unsigned kRetryCount = 3;
|
||||
constexpr unsigned kRetryIntervalSeconds = 1;
|
||||
|
||||
// Concatenate all chunks into one blob and returns the response with
|
||||
// header information.
|
||||
void ConcatenateChunkedResponse(const std::string http_response,
|
||||
@@ -127,13 +133,34 @@ bool UrlRequest::GetResponse(std::string* message) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void UrlRequest::AssertOkResponse(std::string* message) {
|
||||
void UrlRequest::AssertOkResponseWithRetry(std::string* message) {
|
||||
ASSERT_TRUE(message);
|
||||
ASSERT_TRUE(GetResponse(message));
|
||||
const int status_code = GetStatusCode(*message);
|
||||
ASSERT_EQ(kHttpOk, status_code) << "HTTP response from " << socket_.url()
|
||||
<< ": (" << message->size() << ") :\n"
|
||||
<< *message;
|
||||
int status_code = 0;
|
||||
for (unsigned i = 0; i < kRetryCount; i++) {
|
||||
*message = "";
|
||||
ASSERT_TRUE(GetResponse(message)) << "For attempt " << (i + 1);
|
||||
status_code = GetStatusCode(*message);
|
||||
// If we didn't get a retry status, then we're done.
|
||||
if (std::find(kRetryCodes.begin(), kRetryCodes.end(), status_code) ==
|
||||
kRetryCodes.end()) {
|
||||
ASSERT_EQ(kHttpOk, status_code) << "HTTP response from " << socket_.url()
|
||||
<< ": (" << message->size() << ") :\n"
|
||||
<< *message;
|
||||
return;
|
||||
}
|
||||
std::cerr << "Temporary failure HTTP response from " << socket_.url()
|
||||
<< ": (" << message->size() << ") :\n"
|
||||
<< *message << "\n"
|
||||
<< "Attempt " << (i + 1) << "\n";
|
||||
socket_.CloseSocket();
|
||||
is_connected_ = false;
|
||||
sleep(kRetryIntervalSeconds << i);
|
||||
Reconnect();
|
||||
SendRequestOnce();
|
||||
}
|
||||
GTEST_FAIL() << "HTTP response from " << socket_.url() << ": ("
|
||||
<< message->size() << ") :\n"
|
||||
<< *message;
|
||||
}
|
||||
|
||||
// static
|
||||
@@ -190,36 +217,35 @@ bool UrlRequest::GetDebugHeaderFields(
|
||||
|
||||
bool UrlRequest::PostRequestWithPath(const std::string& path,
|
||||
const std::string& data) {
|
||||
std::string request;
|
||||
request_.clear();
|
||||
|
||||
request.append("POST ");
|
||||
request.append(path);
|
||||
request.append(" HTTP/1.1\r\n");
|
||||
request_.append("POST ");
|
||||
request_.append(path);
|
||||
request_.append(" HTTP/1.1\r\n");
|
||||
|
||||
request.append("Host: ");
|
||||
request.append(socket_.domain_name());
|
||||
request.append("\r\n");
|
||||
request_.append("Host: ");
|
||||
request_.append(socket_.domain_name());
|
||||
request_.append("\r\n");
|
||||
|
||||
request.append("Connection: close\r\n");
|
||||
request.append("User-Agent: Widevine CDM v1.0\r\n");
|
||||
request.append("X-Return-Encrypted-Headers: request_and_response\r\n");
|
||||
request_.append("Connection: close\r\n");
|
||||
request_.append("User-Agent: Widevine CDM v1.0\r\n");
|
||||
request_.append("X-Return-Encrypted-Headers: request_and_response\r\n");
|
||||
|
||||
// buffer to store length of data as a string
|
||||
char data_size_buffer[32] = {0};
|
||||
snprintf(data_size_buffer, sizeof(data_size_buffer), "%zu", data.size());
|
||||
request_.append("Content-Length: ");
|
||||
request_.append(std::to_string(data.size()));
|
||||
request_.append("\r\n");
|
||||
|
||||
request.append("Content-Length: ");
|
||||
request.append(data_size_buffer); // appends size of data
|
||||
request.append("\r\n");
|
||||
request_.append("\r\n"); // empty line to terminate headers
|
||||
|
||||
request.append("\r\n"); // empty line to terminate headers
|
||||
|
||||
request.append(data);
|
||||
request_.append(data);
|
||||
return SendRequestOnce();
|
||||
}
|
||||
|
||||
bool UrlRequest::SendRequestOnce() {
|
||||
const int ret = socket_.WriteAndLogErrors(
|
||||
request.c_str(), static_cast<int>(request.size()), kWriteTimeoutMs);
|
||||
LOGV("HTTP request: (%zu): %s", request.size(), request.c_str());
|
||||
LOGV("HTTP request hex: %s", wvutil::b2a_hex(request).c_str());
|
||||
request_.c_str(), static_cast<int>(request_.size()), kWriteTimeoutMs);
|
||||
LOGV("HTTP request: (%zu): %s", request_.size(), request_.c_str());
|
||||
LOGV("HTTP request hex: %s", wvutil::b2a_hex(request_).c_str());
|
||||
return ret != -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,8 @@ class UrlRequest {
|
||||
bool GetResponse(std::string* message);
|
||||
static int GetStatusCode(const std::string& response);
|
||||
// Get the response, and expect the status is OK.
|
||||
void AssertOkResponse(std::string* message);
|
||||
// It will retry if the response code is in the 500 range.
|
||||
void AssertOkResponseWithRetry(std::string* message);
|
||||
|
||||
static bool GetDebugHeaderFields(
|
||||
const std::string& response,
|
||||
@@ -37,9 +38,11 @@ class UrlRequest {
|
||||
|
||||
private:
|
||||
bool PostRequestWithPath(const std::string& path, const std::string& data);
|
||||
bool SendRequestOnce();
|
||||
|
||||
bool is_connected_;
|
||||
HttpSocket socket_;
|
||||
std::string request_;
|
||||
|
||||
CORE_DISALLOW_COPY_AND_ASSIGN(UrlRequest);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user