Merge branch 'master' of https://widevine-partner.googlesource.com/media_cas_packager_sdk_source into moe_writing_branch_from_fcdd9fa38cb2674e34790e8360af4722a09a0927

This commit is contained in:
Widevine Buildbot
2018-10-22 20:36:36 +00:00
parent 76c914c7aa
commit b8b62e31d6
4 changed files with 62 additions and 20 deletions

BIN
example/wv_cas_ecm_example Normal file

Binary file not shown.

View File

@@ -0,0 +1,55 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2018 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.
////////////////////////////////////////////////////////////////////////////////
// Example of how to use the wv_cas_ecm library.
#include <string>
#include "gflags/gflags.h"
#include "glog/logging.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include "util/status.h"
#include "media_cas_packager_sdk/public/wv_cas_ecm.h"
const char kEvenKey[] = "even_content_key"; // 16 bytes
const char kEvenContentIv8Bytes[] = "evencont"; // 8 bytes
const char kOddKey[] = "odd_content_key."; // 16 bytes
const char kOddContentIv8Bytes[] = "oddcont."; // 8 bytes
const char kEntitlementKeyId[] = "ent_key_id......"; // 16 bytes
const char kEntitlementKey[] = "entitlement_key................."; // 32 bytes
int main(int argc, char **argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
widevine::cas::WvCasEcm wv_cas_ecm;
auto status = wv_cas_ecm.Initialize(/* content_iv_size= */ 16,
/* key_rotation_enabled= */ true,
/* crypto_mode= */ 1);
if (!status.ok()) {
LOG(FATAL) << "Failed to initialize WV CAS ECM, error: " << status;
}
std::string ecm;
status = wv_cas_ecm.GenerateEcm(
/* even_key= */ kEvenKey,
/* even_content_iv= */
absl::StrCat(kEvenContentIv8Bytes, kEvenContentIv8Bytes),
/* odd_key= */ kOddKey,
/* odd_content_iv= */
absl::StrCat(kOddContentIv8Bytes, kOddContentIv8Bytes),
/* entitlement_key_id= */ kEntitlementKeyId,
/* entitlement_key= */ kEntitlementKey, &ecm);
if (!status.ok()) {
LOG(FATAL) << "Failed to generate WV CAS ECM, error: " << status;
} else {
LOG(INFO) << "Generated WV CAS ECM (in hex): "
<< absl::BytesToHexString(ecm);
}
return 0;
}

Binary file not shown.

View File

@@ -38,8 +38,9 @@ class WvCasEcm {
// //
// Args: // Args:
// - |content_iv_size| iv size in bytes for encrypting the content, // - |content_iv_size| iv size in bytes for encrypting the content,
// only support 8 bytes now // only support 8 bytes or 16 bytes
// TODO(user): Double-check with jfore@ regarding only support 8 bytes. // When using 8 bytes content_iv, we assume additional 8 bytes of '\x00' are
// appended to the iv to form a 16 bytes AES IV when content is encrypted.
// - |key_rotation_enabled| whether key rotation is enabled, // - |key_rotation_enabled| whether key rotation is enabled,
// if this is 'true' only subsequent call to GenerateEcm will be allowed, // if this is 'true' only subsequent call to GenerateEcm will be allowed,
// if this is 'false' only subsequent call to GenerateSingleKeyEcm will // if this is 'false' only subsequent call to GenerateSingleKeyEcm will
@@ -47,7 +48,6 @@ class WvCasEcm {
// - |crypto_mode| crypto mode for encrypting content, // - |crypto_mode| crypto mode for encrypting content,
// kCryptoModeCbc = 0, kCryptoModeCtr = 1 // kCryptoModeCbc = 0, kCryptoModeCtr = 1
// only CTR is supported by Widevine CAS plugin for now // only CTR is supported by Widevine CAS plugin for now
// TODO(user): Check with jfore@ regarding supporting kCryptoModeCbc.
// //
// Returns: // Returns:
// - A status indicating whether there was any error during initialization // - A status indicating whether there was any error during initialization
@@ -62,10 +62,8 @@ class WvCasEcm {
// //
// Args: // Args:
// - |even_key| clear even content key // - |even_key| clear even content key
// - |even_wrapping_iv| iv used when encrypting |even_key| in the ECM
// - |even_content_iv| iv used along with |even_key| for encrypting content // - |even_content_iv| iv used along with |even_key| for encrypting content
// - |odd_key| clear odd content key // - |odd_key| clear odd content key
// - |odd_wrapping_iv| iv used when encrypting |odd_key| in the ECM
// - |odd_content_iv| iv used along with |odd_key| for encrypting content // - |odd_content_iv| iv used along with |odd_key| for encrypting content
// - |entitlement_key_id| key id for |entitlement_key| // - |entitlement_key_id| key id for |entitlement_key|
// - |entitlement_key| entitlement key used to encrypt even and odd keys // - |entitlement_key| entitlement key used to encrypt even and odd keys
@@ -77,15 +75,10 @@ class WvCasEcm {
// Note: // Note:
// - The same |entitlement_key| will be used to encrypt both |even_key| // - The same |entitlement_key| will be used to encrypt both |even_key|
// and |odd_key| in the ECM // and |odd_key| in the ECM
// - Currently, we only allow |even_content_iv| and |odd_content_iv| // - Size of |even_content_iv| and |odd_content_iv| must match
// to be of size 8 bytes, so we assume the encryptor would append suffix // |content_iv_size| set during initialization
// {'\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00'}
// to |even_content_iv| and |odd_content_iv| to obtain a 16 bytes IV
// before encrypting the content
util::Status GenerateEcm(const std::string& even_key, util::Status GenerateEcm(const std::string& even_key,
const std::string& even_wrapping_iv,
const std::string& even_content_iv, const std::string& odd_key, const std::string& even_content_iv, const std::string& odd_key,
const std::string& odd_wrapping_iv,
const std::string& odd_content_iv, const std::string& odd_content_iv,
const std::string& entitlement_key_id, const std::string& entitlement_key_id,
const std::string& entitlement_key, std::string* ecm); const std::string& entitlement_key, std::string* ecm);
@@ -95,7 +88,6 @@ class WvCasEcm {
// //
// Args: // Args:
// - |even_key| clear even content key // - |even_key| clear even content key
// - |even_wrapping_iv| iv used when encrypting |even_key| in the ECM
// - |even_content_iv| iv used along with |even_key| for encrypting content // - |even_content_iv| iv used along with |even_key| for encrypting content
// - |entitlement_key_id| key id for |entitlement_key| // - |entitlement_key_id| key id for |entitlement_key|
// - |entitlement_key| entitlement key used to encrypt even key // - |entitlement_key| entitlement key used to encrypt even key
@@ -105,14 +97,9 @@ class WvCasEcm {
// - A status indicating whether there was any error during processing // - A status indicating whether there was any error during processing
// //
// Note: // Note:
// // - Size of |even_content_iv| and |odd_content_iv| must match
// - Currently, we only allow |even_content_iv| // |content_iv_size| set during initialization
// to be of size 8 bytes, so we assume the encryptor would append suffix
// {'\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00'}
// to |even_content_iv| to obtain a 16 bytes IV
// before encrypting the content
util::Status GenerateSingleKeyEcm(const std::string& even_key, util::Status GenerateSingleKeyEcm(const std::string& even_key,
const std::string& even_wrapping_iv,
const std::string& even_content_iv, const std::string& even_content_iv,
const std::string& entitlement_key_id, const std::string& entitlement_key_id,
const std::string& entitlement_key, std::string* ecm); const std::string& entitlement_key, std::string* ecm);