Support configurable policy in Widevine encryption
Bug: 13658473 Change-Id: I90bbaa2e34687e7456c9a247d51c64cd91782891
This commit is contained in:
parent
fe744f4724
commit
cdf0aa178d
|
@ -69,6 +69,7 @@ scoped_ptr<EncryptionKeySource> CreateEncryptionKeySource() {
|
||||||
encryption_key_source.reset(new WidevineEncryptionKeySource(
|
encryption_key_source.reset(new WidevineEncryptionKeySource(
|
||||||
FLAGS_key_server_url,
|
FLAGS_key_server_url,
|
||||||
FLAGS_content_id,
|
FLAGS_content_id,
|
||||||
|
FLAGS_policy,
|
||||||
signer.Pass(),
|
signer.Pass(),
|
||||||
FLAGS_crypto_period_duration == 0 ? kDisableKeyRotation : 0));
|
FLAGS_crypto_period_duration == 0 ? kDisableKeyRotation : 0));
|
||||||
} else if (FLAGS_enable_fixed_key_encryption) {
|
} else if (FLAGS_enable_fixed_key_encryption) {
|
||||||
|
|
|
@ -17,6 +17,10 @@ DEFINE_bool(enable_widevine_encryption,
|
||||||
"--aes_signing_iv) or RSA signing key (--rsa_signing_key_path).");
|
"--aes_signing_iv) or RSA signing key (--rsa_signing_key_path).");
|
||||||
DEFINE_string(key_server_url, "", "Key server url.");
|
DEFINE_string(key_server_url, "", "Key server url.");
|
||||||
DEFINE_string(content_id, "", "Content Id.");
|
DEFINE_string(content_id, "", "Content Id.");
|
||||||
|
DEFINE_string(policy,
|
||||||
|
"",
|
||||||
|
"The name of a stored policy, which specifies DRM content "
|
||||||
|
"rights.");
|
||||||
DEFINE_int32(max_sd_pixels,
|
DEFINE_int32(max_sd_pixels,
|
||||||
768 * 576,
|
768 * 576,
|
||||||
"If the video track has more pixels per frame than max_sd_pixels, "
|
"If the video track has more pixels per frame than max_sd_pixels, "
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
DECLARE_bool(enable_widevine_encryption);
|
DECLARE_bool(enable_widevine_encryption);
|
||||||
DECLARE_string(key_server_url);
|
DECLARE_string(key_server_url);
|
||||||
DECLARE_string(content_id);
|
DECLARE_string(content_id);
|
||||||
|
DECLARE_string(policy);
|
||||||
DECLARE_int32(max_sd_pixels);
|
DECLARE_int32(max_sd_pixels);
|
||||||
DECLARE_string(signer);
|
DECLARE_string(signer);
|
||||||
DECLARE_string(aes_signing_key);
|
DECLARE_string(aes_signing_key);
|
||||||
|
|
|
@ -180,7 +180,8 @@ Status SimpleHttpFetcher::FetchInternal(const std::string& method,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status_code != kHttpOK) {
|
if (status_code != kHttpOK) {
|
||||||
std::string error_message = "HTTP returns status " + base::IntToString(status_code);
|
std::string error_message =
|
||||||
|
"HTTP returns status " + base::IntToString(status_code);
|
||||||
LOG(ERROR) << error_message;
|
LOG(ERROR) << error_message;
|
||||||
return Status(error::HTTP_FAILURE, error_message);
|
return Status(error::HTTP_FAILURE, error_message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,11 +126,13 @@ class WidevineEncryptionKeySource::RefCountedEncryptionKeyMap
|
||||||
WidevineEncryptionKeySource::WidevineEncryptionKeySource(
|
WidevineEncryptionKeySource::WidevineEncryptionKeySource(
|
||||||
const std::string& server_url,
|
const std::string& server_url,
|
||||||
const std::string& content_id,
|
const std::string& content_id,
|
||||||
|
const std::string& policy,
|
||||||
scoped_ptr<RequestSigner> signer,
|
scoped_ptr<RequestSigner> signer,
|
||||||
int first_crypto_period_index)
|
int first_crypto_period_index)
|
||||||
: http_fetcher_(new SimpleHttpFetcher()),
|
: http_fetcher_(new SimpleHttpFetcher()),
|
||||||
server_url_(server_url),
|
server_url_(server_url),
|
||||||
content_id_(content_id),
|
content_id_(content_id),
|
||||||
|
policy_(policy),
|
||||||
signer_(signer.Pass()),
|
signer_(signer.Pass()),
|
||||||
key_rotation_enabled_(first_crypto_period_index >= 0),
|
key_rotation_enabled_(first_crypto_period_index >= 0),
|
||||||
crypto_period_count_(kDefaultCryptoPeriodCount),
|
crypto_period_count_(kDefaultCryptoPeriodCount),
|
||||||
|
@ -268,7 +270,7 @@ void WidevineEncryptionKeySource::FillRequest(const std::string& content_id,
|
||||||
|
|
||||||
base::DictionaryValue request_dict;
|
base::DictionaryValue request_dict;
|
||||||
request_dict.SetString("content_id", content_id_base64_string);
|
request_dict.SetString("content_id", content_id_base64_string);
|
||||||
request_dict.SetString("policy", "");
|
request_dict.SetString("policy", policy_);
|
||||||
|
|
||||||
// Build tracks.
|
// Build tracks.
|
||||||
base::ListValue* tracks = new base::ListValue();
|
base::ListValue* tracks = new base::ListValue();
|
||||||
|
|
|
@ -28,11 +28,13 @@ class WidevineEncryptionKeySource : public EncryptionKeySource {
|
||||||
public:
|
public:
|
||||||
/// @param server_url is the Widevine common encryption server url.
|
/// @param server_url is the Widevine common encryption server url.
|
||||||
/// @param content_id the unique id identify the content to be encrypted.
|
/// @param content_id the unique id identify the content to be encrypted.
|
||||||
|
/// @param policy specifies the DRM content rights.
|
||||||
/// @param signer signs the request message. It should not be NULL.
|
/// @param signer signs the request message. It should not be NULL.
|
||||||
/// @param first_crypto_period_index indicates the starting crypto period
|
/// @param first_crypto_period_index indicates the starting crypto period
|
||||||
/// index. Set it to kDisableKeyRotation to disable key rotation.
|
/// index. Set it to kDisableKeyRotation to disable key rotation.
|
||||||
WidevineEncryptionKeySource(const std::string& server_url,
|
WidevineEncryptionKeySource(const std::string& server_url,
|
||||||
const std::string& content_id,
|
const std::string& content_id,
|
||||||
|
const std::string& policy,
|
||||||
scoped_ptr<RequestSigner> signer,
|
scoped_ptr<RequestSigner> signer,
|
||||||
int first_crypto_period_index);
|
int first_crypto_period_index);
|
||||||
virtual ~WidevineEncryptionKeySource();
|
virtual ~WidevineEncryptionKeySource();
|
||||||
|
@ -89,6 +91,7 @@ class WidevineEncryptionKeySource : public EncryptionKeySource {
|
||||||
scoped_ptr<HttpFetcher> http_fetcher_;
|
scoped_ptr<HttpFetcher> http_fetcher_;
|
||||||
std::string server_url_;
|
std::string server_url_;
|
||||||
std::string content_id_;
|
std::string content_id_;
|
||||||
|
std::string policy_;
|
||||||
scoped_ptr<RequestSigner> signer_;
|
scoped_ptr<RequestSigner> signer_;
|
||||||
|
|
||||||
const bool key_rotation_enabled_;
|
const bool key_rotation_enabled_;
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
namespace {
|
namespace {
|
||||||
const char kServerUrl[] = "http://www.foo.com/getcontentkey";
|
const char kServerUrl[] = "http://www.foo.com/getcontentkey";
|
||||||
const char kContentId[] = "ContentFoo";
|
const char kContentId[] = "ContentFoo";
|
||||||
|
const char kPolicy[] = "PolicyFoo";
|
||||||
const char kSignerName[] = "SignerFoo";
|
const char kSignerName[] = "SignerFoo";
|
||||||
|
|
||||||
const char kMockSignature[] = "MockSignature";
|
const char kMockSignature[] = "MockSignature";
|
||||||
|
@ -32,7 +33,7 @@ const char kLicenseStatusTransientError[] = "INTERNAL_ERROR";
|
||||||
const char kLicenseStatusUnknownError[] = "UNKNOWN_ERROR";
|
const char kLicenseStatusUnknownError[] = "UNKNOWN_ERROR";
|
||||||
|
|
||||||
const char kExpectedRequestMessageFormat[] =
|
const char kExpectedRequestMessageFormat[] =
|
||||||
"{\"content_id\":\"%s\",\"drm_types\":[\"WIDEVINE\"],\"policy\":\"\","
|
"{\"content_id\":\"%s\",\"drm_types\":[\"WIDEVINE\"],\"policy\":\"%s\","
|
||||||
"\"tracks\":[{\"type\":\"SD\"},{\"type\":\"HD\"},{\"type\":\"AUDIO\"}]}";
|
"\"tracks\":[{\"type\":\"SD\"},{\"type\":\"HD\"},{\"type\":\"AUDIO\"}]}";
|
||||||
const char kExpectedSignedMessageFormat[] =
|
const char kExpectedSignedMessageFormat[] =
|
||||||
"{\"request\":\"%s\",\"signature\":\"%s\",\"signer\":\"%s\"}";
|
"{\"request\":\"%s\",\"signature\":\"%s\",\"signer\":\"%s\"}";
|
||||||
|
@ -135,6 +136,7 @@ class WidevineEncryptionKeySourceTest : public ::testing::Test {
|
||||||
widevine_encryption_key_source_.reset(new WidevineEncryptionKeySource(
|
widevine_encryption_key_source_.reset(new WidevineEncryptionKeySource(
|
||||||
kServerUrl,
|
kServerUrl,
|
||||||
kContentId,
|
kContentId,
|
||||||
|
kPolicy,
|
||||||
mock_request_signer_.PassAs<RequestSigner>(),
|
mock_request_signer_.PassAs<RequestSigner>(),
|
||||||
first_crypto_period_index));
|
first_crypto_period_index));
|
||||||
widevine_encryption_key_source_->set_http_fetcher(
|
widevine_encryption_key_source_->set_http_fetcher(
|
||||||
|
@ -175,7 +177,7 @@ TEST_F(WidevineEncryptionKeySourceTest, GenerateSignatureFailure) {
|
||||||
// verify the correct behavior on http failure.
|
// verify the correct behavior on http failure.
|
||||||
TEST_F(WidevineEncryptionKeySourceTest, HttpPostFailure) {
|
TEST_F(WidevineEncryptionKeySourceTest, HttpPostFailure) {
|
||||||
std::string expected_message = base::StringPrintf(
|
std::string expected_message = base::StringPrintf(
|
||||||
kExpectedRequestMessageFormat, Base64Encode(kContentId).c_str());
|
kExpectedRequestMessageFormat, Base64Encode(kContentId).c_str(), kPolicy);
|
||||||
EXPECT_CALL(*mock_request_signer_, GenerateSignature(expected_message, _))
|
EXPECT_CALL(*mock_request_signer_, GenerateSignature(expected_message, _))
|
||||||
.WillOnce(DoAll(SetArgPointee<1>(kMockSignature), Return(true)));
|
.WillOnce(DoAll(SetArgPointee<1>(kMockSignature), Return(true)));
|
||||||
|
|
||||||
|
@ -271,7 +273,7 @@ namespace {
|
||||||
|
|
||||||
const char kCryptoPeriodRequestMessageFormat[] =
|
const char kCryptoPeriodRequestMessageFormat[] =
|
||||||
"{\"content_id\":\"%s\",\"crypto_period_count\":%u,\"drm_types\":["
|
"{\"content_id\":\"%s\",\"crypto_period_count\":%u,\"drm_types\":["
|
||||||
"\"WIDEVINE\"],\"first_crypto_period_index\":%u,\"policy\":\"\","
|
"\"WIDEVINE\"],\"first_crypto_period_index\":%u,\"policy\":\"%s\","
|
||||||
"\"tracks\":[{\"type\":\"SD\"},{\"type\":\"HD\"},{\"type\":\"AUDIO\"}]}";
|
"\"tracks\":[{\"type\":\"SD\"},{\"type\":\"HD\"},{\"type\":\"AUDIO\"}]}";
|
||||||
|
|
||||||
const char kCryptoPeriodTrackFormat[] =
|
const char kCryptoPeriodTrackFormat[] =
|
||||||
|
@ -323,7 +325,8 @@ TEST_F(WidevineEncryptionKeySourceTest, KeyRotationTest) {
|
||||||
base::StringPrintf(kCryptoPeriodRequestMessageFormat,
|
base::StringPrintf(kCryptoPeriodRequestMessageFormat,
|
||||||
Base64Encode(kContentId).c_str(),
|
Base64Encode(kContentId).c_str(),
|
||||||
kCryptoPeriodCount,
|
kCryptoPeriodCount,
|
||||||
first_crypto_period_index);
|
first_crypto_period_index,
|
||||||
|
kPolicy);
|
||||||
EXPECT_CALL(*mock_request_signer_, GenerateSignature(expected_message, _))
|
EXPECT_CALL(*mock_request_signer_, GenerateSignature(expected_message, _))
|
||||||
.WillOnce(DoAll(SetArgPointee<1>(kMockSignature), Return(true)));
|
.WillOnce(DoAll(SetArgPointee<1>(kMockSignature), Return(true)));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue