Update to support OEMCrypto v16 with ODK
This commit is contained in:
83
common/content_id_util.cc
Normal file
83
common/content_id_util.cc
Normal file
@@ -0,0 +1,83 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2019 Google LLC.
|
||||
//
|
||||
// This software is licensed under the terms defined in the Widevine Master
|
||||
// License Agreement. For a copy of this agreement, please contact
|
||||
// widevine-licensing@google.com.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include "common/content_id_util.h"
|
||||
|
||||
#include "glog/logging.h"
|
||||
#include "common/error_space.h"
|
||||
#include "common/status.h"
|
||||
#include "license_server_sdk/internal/parse_content_id.h"
|
||||
#include "protos/public/errors.pb.h"
|
||||
#include "protos/public/external_license.pb.h"
|
||||
#include "protos/public/license_protocol.pb.h"
|
||||
#include "protos/public/license_server_sdk.pb.h"
|
||||
#include "protos/public/widevine_pssh.pb.h"
|
||||
|
||||
namespace widevine {
|
||||
|
||||
Status GetContentIdFromExternalLicenseRequest(
|
||||
const ExternalLicenseRequest& external_license_request,
|
||||
std::string* content_id) {
|
||||
WidevinePsshData pssh_data;
|
||||
Status status = ParsePsshData(external_license_request, &pssh_data);
|
||||
*content_id = pssh_data.content_id();
|
||||
return OkStatus();
|
||||
}
|
||||
Status GetContentIdFromSignedExternalLicenseRequest(
|
||||
const SignedMessage& signed_message, std::string* content_id) {
|
||||
if (signed_message.type() != SignedMessage::EXTERNAL_LICENSE_REQUEST) {
|
||||
return Status(
|
||||
error_space, error::INVALID_ARGUMENT,
|
||||
"Unexpected SignedMessage Type. EXTERNAL_LICENSE_REQUEST expected");
|
||||
}
|
||||
ExternalLicenseRequest external_license_request;
|
||||
if (!external_license_request.ParseFromString(signed_message.msg())) {
|
||||
return Status(error_space, EXTERNAL_LICENSE_REQUEST_PARSE_ERROR,
|
||||
"Unable to parse into External License Request");
|
||||
}
|
||||
return GetContentIdFromExternalLicenseRequest(external_license_request,
|
||||
content_id);
|
||||
}
|
||||
|
||||
Status ParsePsshData(ExternalLicenseRequest external_license_request,
|
||||
WidevinePsshData* widevine_pssh_data) {
|
||||
if (!external_license_request.has_content_id()) {
|
||||
std::string error = "ExternalLicenseRequest does not include ContentId";
|
||||
LOG(ERROR) << error
|
||||
<< ", request = " << external_license_request.ShortDebugString();
|
||||
return Status(error_space, MISSING_CONTENT_ID, error);
|
||||
}
|
||||
ContentInfo content_info;
|
||||
Status status =
|
||||
ParseContentId(external_license_request.content_id(), &content_info);
|
||||
if (!status.ok()) {
|
||||
std::string error =
|
||||
"Unable to retrieve ContentId from ExternalLicenseRequest";
|
||||
LOG(ERROR) << error << ", status = " << status
|
||||
<< ", request = " << external_license_request.ShortDebugString();
|
||||
return Status(error_space, MISSING_CONTENT_ID, error);
|
||||
}
|
||||
switch (external_license_request.content_id().init_data().init_data_type()) {
|
||||
case LicenseRequest::ContentIdentification::InitData::WEBM:
|
||||
widevine_pssh_data->ParseFromString(
|
||||
content_info.content_info_entry(0).key_ids(0));
|
||||
break;
|
||||
default:
|
||||
*widevine_pssh_data =
|
||||
content_info.content_info_entry(0).pssh().widevine_data();
|
||||
break;
|
||||
}
|
||||
if (widevine_pssh_data->content_id().empty()) {
|
||||
std::string error =
|
||||
"Missing ContentId within Pssh data for ExternalLicenseRequest";
|
||||
LOG(ERROR) << error
|
||||
<< ", request = " << external_license_request.ShortDebugString();
|
||||
return Status(error_space, MISSING_CONTENT_ID, error);
|
||||
}
|
||||
return OkStatus();
|
||||
}
|
||||
} // namespace widevine
|
||||
Reference in New Issue
Block a user