Sends signed provisioning request as query string instead of payload.
Bug: 8790775 Merge of https://widevine-internal-review.googlesource.com/#/c/5381/ from the Widevine CDM repository. Change-Id: I749303eee8162f37982f6dd5d83b6cf254b96847
This commit is contained in:
@@ -106,8 +106,8 @@ class CdmEngine : public TimerHandler {
|
||||
// Cancel all sessions
|
||||
bool CancelSessions();
|
||||
void CleanupProvisioningSession(const CdmSessionId& cdm_session_id);
|
||||
void ComposeJsonRequest(const std::string& message,
|
||||
CdmProvisioningRequest* request);
|
||||
void ComposeJsonRequestAsQueryString(const std::string& message,
|
||||
CdmProvisioningRequest* request);
|
||||
|
||||
bool ParseJsonResponse(const CdmProvisioningResponse& json_str,
|
||||
const std::string& start_substr,
|
||||
|
||||
@@ -333,17 +333,20 @@ void CdmEngine::CleanupProvisioningSession(const CdmSessionId& cdm_session_id) {
|
||||
}
|
||||
|
||||
/*
|
||||
* This function converts SignedProvisioningRequest into base64 format.
|
||||
* This function converts SignedProvisioningRequest into base64 string.
|
||||
* It then wraps it in JSON format expected by the Apiary frontend.
|
||||
* Apiary requires the base64 encoding to replace '+' with minus '-',
|
||||
* and '/' with underscore '_'; opposite to stubby's.
|
||||
*
|
||||
* Returns the JSON formated string in *request.
|
||||
* Returns the JSON formated string in *request. The JSON string will be
|
||||
* appended as a query parameter, i.e. signedRequest=<base 64 encoded
|
||||
* SignedProvisioningRequest>. All base64 '=' padding chars must be removed.
|
||||
*
|
||||
* The JSON formated request takes the following format:
|
||||
*
|
||||
* {'signedRequest':'base64 encoded message'}
|
||||
*
|
||||
* base64 encoded message
|
||||
*/
|
||||
void CdmEngine::ComposeJsonRequest(
|
||||
void CdmEngine::ComposeJsonRequestAsQueryString(
|
||||
const std::string& message,
|
||||
CdmProvisioningRequest* request) {
|
||||
|
||||
@@ -351,11 +354,14 @@ void CdmEngine::ComposeJsonRequest(
|
||||
std::vector<uint8_t> message_vector(message.begin(), message.end());
|
||||
std::string message_b64 = Base64SafeEncode(message_vector);
|
||||
|
||||
request->assign("{'signedRequest':'");
|
||||
request->append(message_b64);
|
||||
request->append("'}");
|
||||
|
||||
LOGD("json request:\r\n%s", request->c_str());
|
||||
// removes trailing '=' padding characters;
|
||||
// the encoded string can have at most 2 '=' padding chars, so start
|
||||
// searching at the end minus four characters
|
||||
size_t found_pos = message_b64.find("=", message_b64.size() - 4);
|
||||
if (std::string::npos != found_pos) {
|
||||
message_b64.resize(found_pos);
|
||||
}
|
||||
request->assign(message_b64);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -467,7 +473,7 @@ CdmResponseType CdmEngine::GetProvisioningRequest(
|
||||
signed_provisioning_msg.SerializeToString(&serialized_request);
|
||||
|
||||
// converts request into JSON string
|
||||
ComposeJsonRequest(serialized_request, request);
|
||||
ComposeJsonRequestAsQueryString(serialized_request, request);
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -103,27 +103,21 @@ bool UrlRequest::PostRequest(const std::string& data) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void UrlRequest::AppendData(const std::string& data) {
|
||||
request_.append(data);
|
||||
request_.append("\r\n"); // marks end of data
|
||||
}
|
||||
|
||||
bool UrlRequest::PostCertRequest(const std::string& data) {
|
||||
bool UrlRequest::PostCertRequestInQueryString(const std::string& data) {
|
||||
request_.assign("POST /");
|
||||
request_.append(socket_.resource_path());
|
||||
request_.append("&signedRequest=");
|
||||
request_.append(data);
|
||||
request_.append(" HTTP/1.1\r\n");
|
||||
request_.append("User-Agent: Widevine CDM v1.0\r\n");
|
||||
request_.append("Host: ");
|
||||
request_.append(socket_.domain_name());
|
||||
request_.append("\r\nAccept: */*");
|
||||
request_.append("\r\nContent-Type: application/json");
|
||||
request_.append("\r\nContent-Length: ");
|
||||
request_.append(UintToString(data.size()));
|
||||
request_.append("\r\nContent-Length: 0");
|
||||
request_.append("\r\n"); // empty line to terminate header
|
||||
request_.append("\r\n"); // terminates the request
|
||||
|
||||
AppendData(data);
|
||||
|
||||
socket_.Write(request_.c_str(), request_.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -17,12 +17,11 @@ class UrlRequest {
|
||||
~UrlRequest();
|
||||
|
||||
void AppendChunkToUpload(const std::string& data);
|
||||
void AppendData(const std::string& data);
|
||||
int GetResponse(std::string& response);
|
||||
int GetStatusCode(const std::string& response);
|
||||
bool is_connected() const { return is_connected_; }
|
||||
bool PostRequest(const std::string& data);
|
||||
bool PostCertRequest(const std::string& data);
|
||||
bool PostCertRequestInQueryString(const std::string& data);
|
||||
|
||||
private:
|
||||
static const unsigned int kHttpBufferSize = 4096;
|
||||
|
||||
@@ -115,14 +115,14 @@ class WvCdmRequestLicenseTest : public testing::Test {
|
||||
|
||||
// posts a request and extracts the drm message from the response
|
||||
std::string GetCertRequestResponse(const std::string& server_url,
|
||||
int expected_response) {
|
||||
int expected_response) {
|
||||
UrlRequest url_request(server_url, g_port);
|
||||
|
||||
if (!url_request.is_connected()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
url_request.PostCertRequest(key_msg_);
|
||||
url_request.PostCertRequestInQueryString(key_msg_);
|
||||
std::string response;
|
||||
int resp_bytes = url_request.GetResponse(response);
|
||||
if (resp_bytes) {
|
||||
|
||||
Reference in New Issue
Block a user