* Reject session clobbering. [ Merge of http://go/wvgerrit/14634 ] This fixes a bug in I17de92b3e682c9c731f755e69466bdae7f560393 in which sessions can be clobbered by a forced session ID. This bug manifested in subtle test failures which involved repeatedly creating sessions. This was traced to OEMCrypto not being terminated, then upward to a leaked CryptoSession and CdmSession, and then finally to clobbered session IDs. To avoid the bug in future, first, reject duplicate session IDs. Second, change the OpenSession API to make forced IDs explicit. * Fix unit test namespaces. [ Merge of http://go/wvgerrit/14622 ] This fixes some odd errors that occur when linking multiple test suites into one executable. When two object files both contain a definition of wvcdm::MockCryptoSession, for example, one will win silently and cause the other's tests to misbehave and/or crash. The solution is to put all mocks into an anonymous namespace, since each wvcdm::(anonymous)::MockCryptoSession is separate. In order to avoid lots of repetitions of wvcdm:: in the anonymous namespaces, all anonymous namespaces in unit tests now live inside or the wvcdm namespace. This has been done even for tests which are not currently using mocks. * Move timer and timer_unittest to Android. [ Merge of http://go/wvgerrit/14619 ] These are not used anywhere else. Change-Id: I234f31e9b5c79061205728783596ebaff65e0aff
85 lines
2.8 KiB
C++
85 lines
2.8 KiB
C++
// Copyright 2013 Google Inc. All Rights Reserved.
|
|
|
|
#include "license_request.h"
|
|
#include "log.h"
|
|
|
|
namespace wvcdm {
|
|
|
|
namespace {
|
|
const std::string kTwoBlankLines("\r\n\r\n");
|
|
} // namespace
|
|
|
|
size_t LicenseRequest::FindHeaderEndPosition(
|
|
const std::string& response) const {
|
|
return response.find(kTwoBlankLines);
|
|
}
|
|
|
|
// This routine parses the license server's response message and
|
|
// extracts the drm message from the response header.
|
|
void LicenseRequest::GetDrmMessage(const std::string& response,
|
|
std::string& drm_msg) {
|
|
if (response.empty()) {
|
|
drm_msg.clear();
|
|
return;
|
|
}
|
|
|
|
// Extracts DRM message.
|
|
// Content-Length = GLS line + Header(s) + empty line + drm message;
|
|
// we use the empty line to locate the drm message, and compute
|
|
// the drm message length as below instead of using Content-Length
|
|
size_t header_end_pos = FindHeaderEndPosition(response);
|
|
if (header_end_pos != std::string::npos) {
|
|
header_end_pos += kTwoBlankLines.size(); // points to response body
|
|
|
|
drm_msg.clear();
|
|
// Messages from Google Play server add a GLS wrapper. These start
|
|
// with "GLS/1.0 <status>".
|
|
if (response.find("GLS/1.", header_end_pos) == header_end_pos) {
|
|
// For GLS messages, we should skip past the next blank line, and use
|
|
// what's left of the message.
|
|
size_t drm_msg_pos = response.find(kTwoBlankLines, header_end_pos);
|
|
if (drm_msg_pos != std::string::npos) {
|
|
drm_msg_pos += kTwoBlankLines.size(); // points to drm message
|
|
drm_msg = response.substr(drm_msg_pos);
|
|
} else {
|
|
LOGE("Message had GLS marker, but did not have extra blank line.");
|
|
drm_msg = response.substr(header_end_pos);
|
|
}
|
|
} else {
|
|
// For servers that do not use the GLS wrapper, we should just strip of
|
|
// the headers, and use the rest of the message.
|
|
drm_msg = response.substr(header_end_pos);
|
|
}
|
|
} else {
|
|
LOGE("response body not found");
|
|
}
|
|
}
|
|
|
|
// Returns heartbeat url in heartbeat_url.
|
|
// The heartbeat url is stored as meta data in the response message.
|
|
void LicenseRequest::GetHeartbeatUrl(const std::string& response,
|
|
std::string& heartbeat_url) {
|
|
if (response.empty()) {
|
|
heartbeat_url.clear();
|
|
return;
|
|
}
|
|
|
|
size_t header_end_pos = FindHeaderEndPosition(response);
|
|
if (header_end_pos != std::string::npos) {
|
|
header_end_pos += kTwoBlankLines.size(); // points to response body
|
|
|
|
heartbeat_url.clear();
|
|
size_t heartbeat_url_pos = response.find("Heartbeat-Url: ", header_end_pos);
|
|
if (heartbeat_url_pos != std::string::npos) {
|
|
heartbeat_url_pos += sizeof("Heartbeat-Url: ");
|
|
heartbeat_url.assign(response.substr(heartbeat_url_pos));
|
|
} else {
|
|
LOGE("heartbeat url not found");
|
|
}
|
|
} else {
|
|
LOGE("response body not found");
|
|
}
|
|
}
|
|
|
|
} // namespace wvcdm
|